Add initial project setup with VSCode configurations and main functionality for serial communication
This commit is contained in:
		
						commit
						110b0daebb
					
				
							
								
								
									
										0
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
								
								
									
										3
									
								
								.vscode/arduino.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								.vscode/arduino.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1,3 @@ | ||||
| { | ||||
|     "port": "COM3" | ||||
| } | ||||
							
								
								
									
										18
									
								
								.vscode/c_cpp_properties.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								.vscode/c_cpp_properties.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -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 | ||||
| } | ||||
							
								
								
									
										24
									
								
								.vscode/launch.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								.vscode/launch.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -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 | ||||
|         } | ||||
|       ] | ||||
|     } | ||||
|   ] | ||||
| } | ||||
							
								
								
									
										59
									
								
								.vscode/settings.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										59
									
								
								.vscode/settings.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -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 | ||||
| } | ||||
							
								
								
									
										56
									
								
								main.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										56
									
								
								main.py
									
									
									
									
									
										Normal file
									
								
							| @ -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() | ||||
							
								
								
									
										21
									
								
								main/main.ino
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								main/main.ino
									
									
									
									
									
										Normal file
									
								
							| @ -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
 | ||||
|     } | ||||
| } | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user