diff --git a/ConfigDemoAll.py b/ConfigDemoAll.py index ab4325e..66fb38d 100644 --- a/ConfigDemoAll.py +++ b/ConfigDemoAll.py @@ -12,6 +12,7 @@ # Serial port settings SERIAL_PORT = "/dev/ttyUSB0" BAUD_RATE = 115200 +UART_NEWLINE = "\n" # non-standard, default is \r\n LENGTH = 10 REPEAT = 5 diff --git a/ConfigDemoAll.py b/ConfigDemoAll.py index ab4325e..66fb38d 100644 --- a/ConfigDemoAll.py +++ b/ConfigDemoAll.py @@ -12,6 +12,7 @@ # Serial port settings SERIAL_PORT = "/dev/ttyUSB0" BAUD_RATE = 115200 +UART_NEWLINE = "\n" # non-standard, default is \r\n LENGTH = 10 REPEAT = 5 diff --git a/FaultycatModules/__pycache__/ConfigBoard.cpython-310.pyc b/FaultycatModules/__pycache__/ConfigBoard.cpython-310.pyc new file mode 100644 index 0000000..d777226 --- /dev/null +++ b/FaultycatModules/__pycache__/ConfigBoard.cpython-310.pyc Binary files differ diff --git a/ConfigDemoAll.py b/ConfigDemoAll.py index ab4325e..66fb38d 100644 --- a/ConfigDemoAll.py +++ b/ConfigDemoAll.py @@ -12,6 +12,7 @@ # Serial port settings SERIAL_PORT = "/dev/ttyUSB0" BAUD_RATE = 115200 +UART_NEWLINE = "\n" # non-standard, default is \r\n LENGTH = 10 REPEAT = 5 diff --git a/FaultycatModules/__pycache__/ConfigBoard.cpython-310.pyc b/FaultycatModules/__pycache__/ConfigBoard.cpython-310.pyc new file mode 100644 index 0000000..d777226 --- /dev/null +++ b/FaultycatModules/__pycache__/ConfigBoard.cpython-310.pyc Binary files differ diff --git a/FaultycatModules/__pycache__/UART.cpython-310.pyc b/FaultycatModules/__pycache__/UART.cpython-310.pyc new file mode 100644 index 0000000..1ba748d --- /dev/null +++ b/FaultycatModules/__pycache__/UART.cpython-310.pyc Binary files differ diff --git a/ConfigDemoAll.py b/ConfigDemoAll.py index ab4325e..66fb38d 100644 --- a/ConfigDemoAll.py +++ b/ConfigDemoAll.py @@ -12,6 +12,7 @@ # Serial port settings SERIAL_PORT = "/dev/ttyUSB0" BAUD_RATE = 115200 +UART_NEWLINE = "\n" # non-standard, default is \r\n LENGTH = 10 REPEAT = 5 diff --git a/FaultycatModules/__pycache__/ConfigBoard.cpython-310.pyc b/FaultycatModules/__pycache__/ConfigBoard.cpython-310.pyc new file mode 100644 index 0000000..d777226 --- /dev/null +++ b/FaultycatModules/__pycache__/ConfigBoard.cpython-310.pyc Binary files differ diff --git a/FaultycatModules/__pycache__/UART.cpython-310.pyc b/FaultycatModules/__pycache__/UART.cpython-310.pyc new file mode 100644 index 0000000..1ba748d --- /dev/null +++ b/FaultycatModules/__pycache__/UART.cpython-310.pyc Binary files differ diff --git a/FaultycatModules/__pycache__/Worker.cpython-310.pyc b/FaultycatModules/__pycache__/Worker.cpython-310.pyc new file mode 100644 index 0000000..aa9c364 --- /dev/null +++ b/FaultycatModules/__pycache__/Worker.cpython-310.pyc Binary files differ diff --git a/ConfigDemoAll.py b/ConfigDemoAll.py index ab4325e..66fb38d 100644 --- a/ConfigDemoAll.py +++ b/ConfigDemoAll.py @@ -12,6 +12,7 @@ # Serial port settings SERIAL_PORT = "/dev/ttyUSB0" BAUD_RATE = 115200 +UART_NEWLINE = "\n" # non-standard, default is \r\n LENGTH = 10 REPEAT = 5 diff --git a/FaultycatModules/__pycache__/ConfigBoard.cpython-310.pyc b/FaultycatModules/__pycache__/ConfigBoard.cpython-310.pyc new file mode 100644 index 0000000..d777226 --- /dev/null +++ b/FaultycatModules/__pycache__/ConfigBoard.cpython-310.pyc Binary files differ diff --git a/FaultycatModules/__pycache__/UART.cpython-310.pyc b/FaultycatModules/__pycache__/UART.cpython-310.pyc new file mode 100644 index 0000000..1ba748d --- /dev/null +++ b/FaultycatModules/__pycache__/UART.cpython-310.pyc Binary files differ diff --git a/FaultycatModules/__pycache__/Worker.cpython-310.pyc b/FaultycatModules/__pycache__/Worker.cpython-310.pyc new file mode 100644 index 0000000..aa9c364 --- /dev/null +++ b/FaultycatModules/__pycache__/Worker.cpython-310.pyc Binary files differ diff --git a/__pycache__/ConfigBaudBrute.cpython-310.pyc b/__pycache__/ConfigBaudBrute.cpython-310.pyc new file mode 100644 index 0000000..6e81194 --- /dev/null +++ b/__pycache__/ConfigBaudBrute.cpython-310.pyc Binary files differ diff --git a/ConfigDemoAll.py b/ConfigDemoAll.py index ab4325e..66fb38d 100644 --- a/ConfigDemoAll.py +++ b/ConfigDemoAll.py @@ -12,6 +12,7 @@ # Serial port settings SERIAL_PORT = "/dev/ttyUSB0" BAUD_RATE = 115200 +UART_NEWLINE = "\n" # non-standard, default is \r\n LENGTH = 10 REPEAT = 5 diff --git a/FaultycatModules/__pycache__/ConfigBoard.cpython-310.pyc b/FaultycatModules/__pycache__/ConfigBoard.cpython-310.pyc new file mode 100644 index 0000000..d777226 --- /dev/null +++ b/FaultycatModules/__pycache__/ConfigBoard.cpython-310.pyc Binary files differ diff --git a/FaultycatModules/__pycache__/UART.cpython-310.pyc b/FaultycatModules/__pycache__/UART.cpython-310.pyc new file mode 100644 index 0000000..1ba748d --- /dev/null +++ b/FaultycatModules/__pycache__/UART.cpython-310.pyc Binary files differ diff --git a/FaultycatModules/__pycache__/Worker.cpython-310.pyc b/FaultycatModules/__pycache__/Worker.cpython-310.pyc new file mode 100644 index 0000000..aa9c364 --- /dev/null +++ b/FaultycatModules/__pycache__/Worker.cpython-310.pyc Binary files differ diff --git a/__pycache__/ConfigBaudBrute.cpython-310.pyc b/__pycache__/ConfigBaudBrute.cpython-310.pyc new file mode 100644 index 0000000..6e81194 --- /dev/null +++ b/__pycache__/ConfigBaudBrute.cpython-310.pyc Binary files differ diff --git a/__pycache__/functions.cpython-310.pyc b/__pycache__/functions.cpython-310.pyc new file mode 100644 index 0000000..11e06e0 --- /dev/null +++ b/__pycache__/functions.cpython-310.pyc Binary files differ diff --git a/ConfigDemoAll.py b/ConfigDemoAll.py index ab4325e..66fb38d 100644 --- a/ConfigDemoAll.py +++ b/ConfigDemoAll.py @@ -12,6 +12,7 @@ # Serial port settings SERIAL_PORT = "/dev/ttyUSB0" BAUD_RATE = 115200 +UART_NEWLINE = "\n" # non-standard, default is \r\n LENGTH = 10 REPEAT = 5 diff --git a/FaultycatModules/__pycache__/ConfigBoard.cpython-310.pyc b/FaultycatModules/__pycache__/ConfigBoard.cpython-310.pyc new file mode 100644 index 0000000..d777226 --- /dev/null +++ b/FaultycatModules/__pycache__/ConfigBoard.cpython-310.pyc Binary files differ diff --git a/FaultycatModules/__pycache__/UART.cpython-310.pyc b/FaultycatModules/__pycache__/UART.cpython-310.pyc new file mode 100644 index 0000000..1ba748d --- /dev/null +++ b/FaultycatModules/__pycache__/UART.cpython-310.pyc Binary files differ diff --git a/FaultycatModules/__pycache__/Worker.cpython-310.pyc b/FaultycatModules/__pycache__/Worker.cpython-310.pyc new file mode 100644 index 0000000..aa9c364 --- /dev/null +++ b/FaultycatModules/__pycache__/Worker.cpython-310.pyc Binary files differ diff --git a/__pycache__/ConfigBaudBrute.cpython-310.pyc b/__pycache__/ConfigBaudBrute.cpython-310.pyc new file mode 100644 index 0000000..6e81194 --- /dev/null +++ b/__pycache__/ConfigBaudBrute.cpython-310.pyc Binary files differ diff --git a/__pycache__/functions.cpython-310.pyc b/__pycache__/functions.cpython-310.pyc new file mode 100644 index 0000000..11e06e0 --- /dev/null +++ b/__pycache__/functions.cpython-310.pyc Binary files differ diff --git a/__pycache__/scope.cpython-310.pyc b/__pycache__/scope.cpython-310.pyc new file mode 100644 index 0000000..7a4ebe0 --- /dev/null +++ b/__pycache__/scope.cpython-310.pyc Binary files differ diff --git a/ConfigDemoAll.py b/ConfigDemoAll.py index ab4325e..66fb38d 100644 --- a/ConfigDemoAll.py +++ b/ConfigDemoAll.py @@ -12,6 +12,7 @@ # Serial port settings SERIAL_PORT = "/dev/ttyUSB0" BAUD_RATE = 115200 +UART_NEWLINE = "\n" # non-standard, default is \r\n LENGTH = 10 REPEAT = 5 diff --git a/FaultycatModules/__pycache__/ConfigBoard.cpython-310.pyc b/FaultycatModules/__pycache__/ConfigBoard.cpython-310.pyc new file mode 100644 index 0000000..d777226 --- /dev/null +++ b/FaultycatModules/__pycache__/ConfigBoard.cpython-310.pyc Binary files differ diff --git a/FaultycatModules/__pycache__/UART.cpython-310.pyc b/FaultycatModules/__pycache__/UART.cpython-310.pyc new file mode 100644 index 0000000..1ba748d --- /dev/null +++ b/FaultycatModules/__pycache__/UART.cpython-310.pyc Binary files differ diff --git a/FaultycatModules/__pycache__/Worker.cpython-310.pyc b/FaultycatModules/__pycache__/Worker.cpython-310.pyc new file mode 100644 index 0000000..aa9c364 --- /dev/null +++ b/FaultycatModules/__pycache__/Worker.cpython-310.pyc Binary files differ diff --git a/__pycache__/ConfigBaudBrute.cpython-310.pyc b/__pycache__/ConfigBaudBrute.cpython-310.pyc new file mode 100644 index 0000000..6e81194 --- /dev/null +++ b/__pycache__/ConfigBaudBrute.cpython-310.pyc Binary files differ diff --git a/__pycache__/functions.cpython-310.pyc b/__pycache__/functions.cpython-310.pyc new file mode 100644 index 0000000..11e06e0 --- /dev/null +++ b/__pycache__/functions.cpython-310.pyc Binary files differ diff --git a/__pycache__/scope.cpython-310.pyc b/__pycache__/scope.cpython-310.pyc new file mode 100644 index 0000000..7a4ebe0 --- /dev/null +++ b/__pycache__/scope.cpython-310.pyc Binary files differ diff --git a/functions.py b/functions.py index ee6bb8a..2891868 100644 --- a/functions.py +++ b/functions.py @@ -86,6 +86,10 @@ if not hasattr(config, "UART_OUTPUT_ENABLED"): config.UART_OUTPUT_ENABLED = False # Default to disabled return config.UART_OUTPUT_ENABLED + elif name == "uart_newline": + if not hasattr(config, "UART_NEWLINE"): + config.UART_NEWLINE = "\r\n" # Default value if not set + return config.UART_NEWLINE elif name.startswith("trigger_"): if "_value" in name: index = int(name.split('_')[1]) @@ -526,43 +530,32 @@ return None def send_uart_message(message): - """Send a message via UART from anywhere in the application""" - if not app_instance: - log_message("[UART] Not sent - No app instance") - return False - - if not hasattr(app_instance, 'serial_connection') or not app_instance.serial_connection.is_open: - log_message("[UART] Not sent - UART disconnected") - return False - + """Send exactly one raw UART character, using the configured newline if set.""" try: - # Ensure message ends with newline if it's not empty - if message and not message.endswith('\n'): - message += '\n' - - # Send the message - app_instance.serial_connection.write(message.encode('utf-8')) - log_message(f"[UART] Sent: {message.strip()}") + conn = getattr(app_instance, "serial_connection", None) + if not conn or not conn.is_open: + log_message("[UART] Not sent - UART disconnected") + return False + + # Skip newline removal if the configuration is blank + if config.UART_NEWLINE: + if message.endswith(config.UART_NEWLINE): + message = message[: -len(config.UART_NEWLINE)] + # Append exactly one instance of the configured newline + message += config.UART_NEWLINE + + # Send only the raw character(s) + raw = message.encode("utf-8") + conn.write(raw) + conn.flush() + + log_message(f"[UART] Sent raw: {repr(raw)}") return True + except Exception as e: - log_message(f"[UART TX ERROR] {str(e)}") + log_message(f"[UART TX ERROR] {e}") return False -def flush_uart_buffer(): - """Flush UART buffers and clear app_instance.serial_buffer.""" - conn = getattr(app_instance, "serial_connection", None) - if not conn or not conn.is_open: - log_message("[UART] Flush skipped - No connection") - return False - try: - conn.reset_input_buffer() - conn.reset_output_buffer() - app_instance.serial_buffer = "" - log_message("[UART] Buffers flushed") - return True - except Exception as e: - log_message(f"[UART FLUSH ERROR] {e}") - return False def read_uart_buffer(): """Read data into app_instance.serial_buffer and return it.""" diff --git a/ConfigDemoAll.py b/ConfigDemoAll.py index ab4325e..66fb38d 100644 --- a/ConfigDemoAll.py +++ b/ConfigDemoAll.py @@ -12,6 +12,7 @@ # Serial port settings SERIAL_PORT = "/dev/ttyUSB0" BAUD_RATE = 115200 +UART_NEWLINE = "\n" # non-standard, default is \r\n LENGTH = 10 REPEAT = 5 diff --git a/FaultycatModules/__pycache__/ConfigBoard.cpython-310.pyc b/FaultycatModules/__pycache__/ConfigBoard.cpython-310.pyc new file mode 100644 index 0000000..d777226 --- /dev/null +++ b/FaultycatModules/__pycache__/ConfigBoard.cpython-310.pyc Binary files differ diff --git a/FaultycatModules/__pycache__/UART.cpython-310.pyc b/FaultycatModules/__pycache__/UART.cpython-310.pyc new file mode 100644 index 0000000..1ba748d --- /dev/null +++ b/FaultycatModules/__pycache__/UART.cpython-310.pyc Binary files differ diff --git a/FaultycatModules/__pycache__/Worker.cpython-310.pyc b/FaultycatModules/__pycache__/Worker.cpython-310.pyc new file mode 100644 index 0000000..aa9c364 --- /dev/null +++ b/FaultycatModules/__pycache__/Worker.cpython-310.pyc Binary files differ diff --git a/__pycache__/ConfigBaudBrute.cpython-310.pyc b/__pycache__/ConfigBaudBrute.cpython-310.pyc new file mode 100644 index 0000000..6e81194 --- /dev/null +++ b/__pycache__/ConfigBaudBrute.cpython-310.pyc Binary files differ diff --git a/__pycache__/functions.cpython-310.pyc b/__pycache__/functions.cpython-310.pyc new file mode 100644 index 0000000..11e06e0 --- /dev/null +++ b/__pycache__/functions.cpython-310.pyc Binary files differ diff --git a/__pycache__/scope.cpython-310.pyc b/__pycache__/scope.cpython-310.pyc new file mode 100644 index 0000000..7a4ebe0 --- /dev/null +++ b/__pycache__/scope.cpython-310.pyc Binary files differ diff --git a/functions.py b/functions.py index ee6bb8a..2891868 100644 --- a/functions.py +++ b/functions.py @@ -86,6 +86,10 @@ if not hasattr(config, "UART_OUTPUT_ENABLED"): config.UART_OUTPUT_ENABLED = False # Default to disabled return config.UART_OUTPUT_ENABLED + elif name == "uart_newline": + if not hasattr(config, "UART_NEWLINE"): + config.UART_NEWLINE = "\r\n" # Default value if not set + return config.UART_NEWLINE elif name.startswith("trigger_"): if "_value" in name: index = int(name.split('_')[1]) @@ -526,43 +530,32 @@ return None def send_uart_message(message): - """Send a message via UART from anywhere in the application""" - if not app_instance: - log_message("[UART] Not sent - No app instance") - return False - - if not hasattr(app_instance, 'serial_connection') or not app_instance.serial_connection.is_open: - log_message("[UART] Not sent - UART disconnected") - return False - + """Send exactly one raw UART character, using the configured newline if set.""" try: - # Ensure message ends with newline if it's not empty - if message and not message.endswith('\n'): - message += '\n' - - # Send the message - app_instance.serial_connection.write(message.encode('utf-8')) - log_message(f"[UART] Sent: {message.strip()}") + conn = getattr(app_instance, "serial_connection", None) + if not conn or not conn.is_open: + log_message("[UART] Not sent - UART disconnected") + return False + + # Skip newline removal if the configuration is blank + if config.UART_NEWLINE: + if message.endswith(config.UART_NEWLINE): + message = message[: -len(config.UART_NEWLINE)] + # Append exactly one instance of the configured newline + message += config.UART_NEWLINE + + # Send only the raw character(s) + raw = message.encode("utf-8") + conn.write(raw) + conn.flush() + + log_message(f"[UART] Sent raw: {repr(raw)}") return True + except Exception as e: - log_message(f"[UART TX ERROR] {str(e)}") + log_message(f"[UART TX ERROR] {e}") return False -def flush_uart_buffer(): - """Flush UART buffers and clear app_instance.serial_buffer.""" - conn = getattr(app_instance, "serial_connection", None) - if not conn or not conn.is_open: - log_message("[UART] Flush skipped - No connection") - return False - try: - conn.reset_input_buffer() - conn.reset_output_buffer() - app_instance.serial_buffer = "" - log_message("[UART] Buffers flushed") - return True - except Exception as e: - log_message(f"[UART FLUSH ERROR] {e}") - return False def read_uart_buffer(): """Read data into app_instance.serial_buffer and return it.""" diff --git a/glitch-o-bolt.py b/glitch-o-bolt.py index ba3d95f..43f3a02 100644 --- a/glitch-o-bolt.py +++ b/glitch-o-bolt.py @@ -194,37 +194,40 @@ await asyncio.sleep(0.1) # Check 10 times per secon async def on_key(self, event: events.Key) -> None: - """Handles input with proper newline preservation""" - if event.key == "enter" and self.input_field.has_focus: - text_to_send = self.input_field.value - - # Preserve exact input (don't strip) but ensure newline - if not text_to_send.endswith('\n'): - text_to_send += '\n' - - # Check if serial_connection exists and is open - serial_connection = getattr(self, 'serial_connection', None) - if serial_connection is not None and serial_connection.is_open: - try: - # Send raw bytes exactly as entered - await asyncio.get_event_loop().run_in_executor( - None, - lambda: serial_connection.write(text_to_send.encode('utf-8')) - ) - - # Echo to console with prefix - display_text = f"> {text_to_send.rstrip()}" - functions.add_text(display_text) - - except Exception as e: - functions.log_message(f"[UART TX ERROR] {str(e)}") - functions.add_text(">> Failed to send") - else: - functions.add_text(">> Not sent - UART disconnected") - - self.input_field.value = "" + """Handles input with proper newline preservation.""" + # Prevent Textual default handling immediately + if event.key == "enter": event.prevent_default() + if self.input_field.has_focus: + text_to_send = self.input_field.value + + # Skip empty input + if not text_to_send: + return + + serial_connection = getattr(self, "serial_connection", None) + if serial_connection and serial_connection.is_open: + try: + # Send exactly once via executor + await asyncio.get_event_loop().run_in_executor( + None, + lambda: functions.send_uart_message(text_to_send) + ) + + # Echo to console once + display_text = f"> {text_to_send.rstrip()}" + functions.add_text(display_text) + + except Exception as e: + functions.log_message(f"[UART TX ERROR] {str(e)}") + functions.add_text(">> Failed to send") + else: + functions.add_text(">> Not sent - UART disconnected") + + # Clear after handling + self.input_field.value = "" + async def on_serial_data_message(self, message: SerialDataMessage) -> None: """Display serial data exactly as received""" if hasattr(functions, 'text_area'):