Newer
Older
glitch-o-bolt / ConfigBaudBrute.py
  1. ######
  2. # LEAVE THESE IMPORTS!
  3. ######
  4. import functions
  5.  
  6. ######
  7. # config values (you can edit these to fit your environment and use case)
  8. ######
  9.  
  10. # Serial port settings
  11. SERIAL_PORT = "/dev/ttyUSB0"
  12. BAUD_RATE = 9600
  13.  
  14. ###
  15. # name, enabled, string to match in output, function to run
  16. # if string is blank ("") doesnt show toggle, just run button
  17. ###
  18. conditions = [
  19. ["Next", False, "", "uart_up"],
  20. ["Prev", False, "", "uart_down"],
  21. ]
  22.  
  23. ######
  24. # Custom functions for conditions to trigger
  25. ######
  26.  
  27. baud_rates = [300, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, 115200, 128000, 256000]
  28.  
  29.  
  30. def uart_up():
  31. current_baud = functions.get_config_value("baud_rate")
  32. # Find the index of the current baud rate
  33. try:
  34. index = baud_rates.index(current_baud)
  35. except ValueError:
  36. # If current baud rate is not in the list, start from the lowest
  37. index = -1
  38. # Get the next higher baud rate (wrapping around if at the end)
  39. new_index = (index + 1) % len(baud_rates)
  40. new_baud = baud_rates[new_index]
  41. functions.change_baudrate(new_baud)
  42. functions.add_text(f"\n[Rate Up] {new_baud}")
  43.  
  44. def uart_down():
  45. current_baud = functions.get_config_value("baud_rate")
  46. # Find the index of the current baud rate
  47. try:
  48. index = baud_rates.index(current_baud)
  49. except ValueError:
  50. # If current baud rate is not in the list, start from the highest
  51. index = len(baud_rates)
  52. # Get the next lower baud rate (wrapping around if at the start)
  53. new_index = (index - 1) % len(baud_rates)
  54. new_baud = baud_rates[new_index]
  55. functions.change_baudrate(new_baud)
  56. functions.add_text(f"\n[Rate Down] {new_baud}")
Buy Me A Coffee