Merge pull request #26 from tyfiero/Raspberry-Pi-button-compatibility-(Thanks-Thea!!!)
Raspberry pi button compatibility (thanks Thea!!!)
This commit is contained in:
commit
9667866797
|
@ -23,6 +23,7 @@ import tempfile
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from interpreter import interpreter # Just for code execution. Maybe we should let people do from interpreter.computer import run?
|
from interpreter import interpreter # Just for code execution. Maybe we should let people do from interpreter.computer import run?
|
||||||
from utils.kernel import put_kernel_messages_into_queue
|
from utils.kernel import put_kernel_messages_into_queue
|
||||||
|
from utils.get_system_info import get_system_info
|
||||||
from stt import stt_wav
|
from stt import stt_wav
|
||||||
|
|
||||||
from utils.logs import setup_logging
|
from utils.logs import setup_logging
|
||||||
|
@ -42,6 +43,9 @@ WS_URL = os.getenv('SERVER_URL')
|
||||||
if not WS_URL:
|
if not WS_URL:
|
||||||
raise ValueError("The environment variable SERVER_URL is not set. Please set it to proceed.")
|
raise ValueError("The environment variable SERVER_URL is not set. Please set it to proceed.")
|
||||||
|
|
||||||
|
# Specify OS
|
||||||
|
current_platform = get_system_info()
|
||||||
|
|
||||||
# Initialize PyAudio
|
# Initialize PyAudio
|
||||||
p = pyaudio.PyAudio()
|
p = pyaudio.PyAudio()
|
||||||
|
|
||||||
|
@ -190,6 +194,7 @@ async def websocket_communication(WS_URL):
|
||||||
result = interpreter.computer.run(language, code)
|
result = interpreter.computer.run(language, code)
|
||||||
send_queue.put(result)
|
send_queue.put(result)
|
||||||
|
|
||||||
|
|
||||||
except:
|
except:
|
||||||
# traceback.print_exc()
|
# traceback.print_exc()
|
||||||
logger.info(f"Connecting to `{WS_URL}`...")
|
logger.info(f"Connecting to `{WS_URL}`...")
|
||||||
|
@ -205,9 +210,30 @@ if __name__ == "__main__":
|
||||||
if os.getenv('CODE_RUNNER') == "device":
|
if os.getenv('CODE_RUNNER') == "device":
|
||||||
asyncio.create_task(put_kernel_messages_into_queue(send_queue))
|
asyncio.create_task(put_kernel_messages_into_queue(send_queue))
|
||||||
|
|
||||||
# Keyboard listener for spacebar press/release
|
|
||||||
listener = keyboard.Listener(on_press=on_press, on_release=on_release)
|
#If Raspberry Pi, add the button listener, otherwise use the spacebar
|
||||||
listener.start()
|
if current_platform.startswith("raspberry-pi"):
|
||||||
|
logger.info("Raspberry Pi detected, using button on GPIO pin 15")
|
||||||
|
# Use GPIO pin 15
|
||||||
|
pindef = ["gpiochip4", "15"] # gpiofind PIN15
|
||||||
|
print("PINDEF", pindef)
|
||||||
|
|
||||||
|
# HACK: needs passwordless sudo
|
||||||
|
process = await asyncio.create_subprocess_exec("sudo", "gpiomon", "-brf", *pindef, stdout=asyncio.subprocess.PIPE)
|
||||||
|
while True:
|
||||||
|
line = await process.stdout.readline()
|
||||||
|
if line:
|
||||||
|
line = line.decode().strip()
|
||||||
|
if "FALLING" in line:
|
||||||
|
toggle_recording(False)
|
||||||
|
elif "RISING" in line:
|
||||||
|
toggle_recording(True)
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
# Keyboard listener for spacebar press/release
|
||||||
|
listener = keyboard.Listener(on_press=on_press, on_release=on_release)
|
||||||
|
listener.start()
|
||||||
|
|
||||||
asyncio.run(main())
|
asyncio.run(main())
|
||||||
p.terminate()
|
p.terminate()
|
|
@ -1,3 +1,5 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
### Import Environment Variables from .env
|
### Import Environment Variables from .env
|
||||||
if [ ! -f ".env" ]; then
|
if [ ! -f ".env" ]; then
|
||||||
echo "Error: .env file does not exist. To create one, see .env.example for an example."
|
echo "Error: .env file does not exist. To create one, see .env.example for an example."
|
||||||
|
@ -5,11 +7,12 @@ if [ ! -f ".env" ]; then
|
||||||
fi
|
fi
|
||||||
set -a; source .env; set +a
|
set -a; source .env; set +a
|
||||||
|
|
||||||
|
|
||||||
### SETUP
|
### SETUP
|
||||||
|
|
||||||
# if using local models, install the models / executables
|
# if using local models, install the models / executables
|
||||||
|
|
||||||
if [[ "$ALL_LOCAL" == "True" ]]; then
|
if [[ "$ALL_LOCAL" == "True" ]]; then
|
||||||
|
curl -OL "${WHISPER_MODEL_URL}${WHISPER_MODEL_NAME}" --output-dir ${WHISPER_RUST_PATH}
|
||||||
OS=$(uname -s)
|
OS=$(uname -s)
|
||||||
ARCH=$(uname -m)
|
ARCH=$(uname -m)
|
||||||
if [ "$OS" = "Darwin" ]; then
|
if [ "$OS" = "Darwin" ]; then
|
||||||
|
@ -52,7 +55,7 @@ fi
|
||||||
|
|
||||||
SERVER_PORT=$(echo $SERVER_URL | grep -oE "[0-9]+")
|
SERVER_PORT=$(echo $SERVER_URL | grep -oE "[0-9]+")
|
||||||
if [ -n "$SERVER_PORT" ]; then
|
if [ -n "$SERVER_PORT" ]; then
|
||||||
lsof -ti tcp:$SERVER_PORT | xargs kill
|
lsof -ti tcp:$SERVER_PORT | xargs kill 2>/dev/null || true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
### START
|
### START
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
import os
|
||||||
|
import platform
|
||||||
|
|
||||||
|
|
||||||
|
def get_system_info():
|
||||||
|
system = platform.system()
|
||||||
|
|
||||||
|
if system == "Linux":
|
||||||
|
# Attempt to identify specific Linux distribution
|
||||||
|
distro = "linux" # Default to generic 'linux'
|
||||||
|
try:
|
||||||
|
with open("/etc/os-release") as f:
|
||||||
|
os_release_info = f.read().lower()
|
||||||
|
if "ubuntu" in os_release_info:
|
||||||
|
return "raspberry-pi-ubuntu"
|
||||||
|
elif "raspbian" in os_release_info:
|
||||||
|
return "raspberry-pi-os"
|
||||||
|
except FileNotFoundError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
# Check for Raspberry Pi hardware
|
||||||
|
try:
|
||||||
|
with open("/proc/device-tree/model") as f:
|
||||||
|
model_info = f.read()
|
||||||
|
if "Raspberry Pi" in model_info:
|
||||||
|
if distro == "ubuntu":
|
||||||
|
return "raspberry-pi-ubuntu"
|
||||||
|
return "raspberry-pi"
|
||||||
|
except FileNotFoundError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
return distro
|
||||||
|
elif system == "Darwin":
|
||||||
|
return "darwin"
|
||||||
|
elif system == "Windows":
|
||||||
|
return "windows"
|
||||||
|
else:
|
||||||
|
return "unknown"
|
|
@ -32,11 +32,12 @@ def custom_filter(message):
|
||||||
end = message.find('}TO_INTERPRETER}', start)
|
end = message.find('}TO_INTERPRETER}', start)
|
||||||
return message[start:end]
|
return message[start:end]
|
||||||
# Check for USB mention
|
# Check for USB mention
|
||||||
elif 'USB' in message:
|
# elif 'USB' in message:
|
||||||
return message
|
# return message
|
||||||
# Check for network related keywords
|
# # Check for network related keywords
|
||||||
elif any(keyword in message for keyword in ['network', 'IP', 'internet', 'LAN', 'WAN', 'router', 'switch']) and "networkStatusForFlags" not in message:
|
# elif any(keyword in message for keyword in ['network', 'IP', 'internet', 'LAN', 'WAN', 'router', 'switch']) and "networkStatusForFlags" not in message:
|
||||||
return message
|
|
||||||
|
# return message
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue