commit 110b0daebb01d7ef20ccadce30e3fa2d45f44513 Author: ZareMate <0.zaremate@gmail.com> Date: Mon Jan 13 12:12:09 2025 +0100 Add initial project setup with VSCode configurations and main functionality for serial communication diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/.vscode/arduino.json b/.vscode/arduino.json new file mode 100644 index 0000000..0a1ed01 --- /dev/null +++ b/.vscode/arduino.json @@ -0,0 +1,3 @@ +{ + "port": "COM3" +} \ No newline at end of file diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..a3d4300 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,18 @@ +{ + "configurations": [ + { + "name": "windows-gcc-x64", + "includePath": [ + "${workspaceFolder}/**" + ], + "compilerPath": "C:/msys64/ucrt64/bin/gcc.exe", + "cStandard": "${default}", + "cppStandard": "${default}", + "intelliSenseMode": "windows-gcc-x64", + "compilerArgs": [ + "" + ] + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..e62909d --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,24 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "C/C++ Runner: Debug Session", + "type": "cppdbg", + "request": "launch", + "args": [], + "stopAtEntry": false, + "externalConsole": true, + "cwd": "d:/Documents/Gitea/ESP32-discord", + "program": "d:/Documents/Gitea/ESP32-discord/build/Debug/outDebug", + "MIMode": "gdb", + "miDebuggerPath": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..bb879da --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,59 @@ +{ + "C_Cpp_Runner.cCompilerPath": "gcc", + "C_Cpp_Runner.cppCompilerPath": "g++", + "C_Cpp_Runner.debuggerPath": "gdb", + "C_Cpp_Runner.cStandard": "", + "C_Cpp_Runner.cppStandard": "", + "C_Cpp_Runner.msvcBatchPath": "C:/Program Files/Microsoft Visual Studio/VR_NR/Community/VC/Auxiliary/Build/vcvarsall.bat", + "C_Cpp_Runner.useMsvc": false, + "C_Cpp_Runner.warnings": [ + "-Wall", + "-Wextra", + "-Wpedantic", + "-Wshadow", + "-Wformat=2", + "-Wcast-align", + "-Wconversion", + "-Wsign-conversion", + "-Wnull-dereference" + ], + "C_Cpp_Runner.msvcWarnings": [ + "/W4", + "/permissive-", + "/w14242", + "/w14287", + "/w14296", + "/w14311", + "/w14826", + "/w44062", + "/w44242", + "/w14905", + "/w14906", + "/w14263", + "/w44265", + "/w14928" + ], + "C_Cpp_Runner.enableWarnings": true, + "C_Cpp_Runner.warningsAsError": false, + "C_Cpp_Runner.compilerArgs": [], + "C_Cpp_Runner.linkerArgs": [], + "C_Cpp_Runner.includePaths": [], + "C_Cpp_Runner.includeSearch": [ + "*", + "**/*" + ], + "C_Cpp_Runner.excludeSearch": [ + "**/build", + "**/build/**", + "**/.*", + "**/.*/**", + "**/.vscode", + "**/.vscode/**" + ], + "C_Cpp_Runner.useAddressSanitizer": false, + "C_Cpp_Runner.useUndefinedSanitizer": false, + "C_Cpp_Runner.useLeakSanitizer": false, + "C_Cpp_Runner.showCompilationTime": false, + "C_Cpp_Runner.useLinkTimeOptimization": false, + "C_Cpp_Runner.msvcSecureNoWarnings": false +} \ No newline at end of file diff --git a/START.lnk b/START.lnk new file mode 100644 index 0000000..5e39ac4 Binary files /dev/null and b/START.lnk differ diff --git a/main.py b/main.py new file mode 100644 index 0000000..67963ba --- /dev/null +++ b/main.py @@ -0,0 +1,56 @@ +import serial +import time +import keyboard +import serial.tools.list_ports as list_ports + +def get_serial_port(): + ports = list(list_ports.comports()) + if not ports: + print("No serial ports found. Please connect a device.") + return None + print("Available Ports:") + for i, port in enumerate(ports): + print(f"{i}: {port.device}") + choice = int(input("Select a port by number: ")) + return ports[choice].device + +def main(): + port = get_serial_port() + if not port: + return + + try: + ser = serial.Serial(port, 115200, timeout=1) + time.sleep(2) # Wait for the connection to initialize + print("Listening for commands...") + + while True: + try: + if ser.in_waiting > 0: + line = ser.readline().decode('utf-8').strip() + print(f"Received: {line}") + + if line == "mute": + keyboard.send('ctrl+shift+f16') + elif line == "deafen": + keyboard.send('ctrl+shift+f15') + else: + print(f"Unknown command: {line}") + + time.sleep(0.1) + except KeyboardInterrupt: + print("Exiting program.") + break + except Exception as e: + print(f"Error during execution: {e}") + break + + except serial.SerialException as e: + print(f"Could not open serial port: {e}") + finally: + if 'ser' in locals() and ser.is_open: + ser.close() + print("Serial connection closed.") + +if __name__ == "__main__": + main() diff --git a/main/main.ino b/main/main.ino new file mode 100644 index 0000000..e10fc57 --- /dev/null +++ b/main/main.ino @@ -0,0 +1,21 @@ +void setup() +{ + pinMode(16, INPUT_PULLUP); // D16 for "mute" button + pinMode(17, INPUT_PULLUP); // D17 for "deafen" button + Serial.begin(115200); +} + +void loop() +{ + // ...existing code... + if (digitalRead(16) == LOW) + { // Button on D16 pressed + Serial.println("mute"); + delay(200); // Debounce delay + } + if (digitalRead(17) == LOW) + { // Button on D17 pressed + Serial.println("deafen"); + delay(200); // Debounce delay + } +} diff --git a/start.ps1 b/start.ps1 new file mode 100644 index 0000000..1c8f3b1 --- /dev/null +++ b/start.ps1 @@ -0,0 +1,8 @@ +# Activate the virtual environment +& .venv\Scripts\activate + +# Run the Python script +python main.py + +# Deactivate the virtual environment +deactivate \ No newline at end of file