Newer
Older
glitch-o-bolt / ConfigDemoAll.py
  1. ######
  2. # LEAVE THESE IMPORTS!
  3. ######
  4. import functions
  5. import random
  6. from textual.widgets import Log
  7.  
  8. ######
  9. # config values (you can edit these to fit your environment and use case)
  10. ######
  11.  
  12. # Serial port settings
  13. SERIAL_PORT = "/dev/ttyUSB0"
  14. BAUD_RATE = 115200
  15.  
  16. LENGTH = 10
  17. REPEAT = 5
  18. DELAY = 100
  19.  
  20. ###
  21. # ^ = pullup, v = pulldown
  22. ###
  23. triggers = [
  24. ["^", True], #0
  25. ["-", False], #1
  26. ["v", True], #2
  27. ["-", False], #3
  28. ["-", False], #4
  29. ["-", False], #5
  30. ["-", False], #6
  31. ["-", False], #7
  32. ]
  33.  
  34. ###
  35. # name, enabled, string to match in output, function to run
  36. # if string is blank ("") doesnt show toggle, just run button
  37. ###
  38. conditions = [
  39. ["No01", False, "WillNeverMatch01", ""],
  40. ["No02", False, "WillNeverMatch02", ""],
  41. ["Heigh", False, "", "get_scroll_height"],
  42. ["AllTg", False, "", "toggle_all"],
  43. ["Trigr", False, "", "change_all_triggers"],
  44. ["Value", False, "", "random_values"],
  45. ['9600', False, '', 'change_baud_9600'],
  46. ['11520', False, '', 'change_baud_115200'],
  47. ]
  48.  
  49. ######
  50. # Custom functions for conditions to trigger
  51. ######
  52.  
  53. def get_scroll_height():
  54. if functions.app_instance:
  55. text_widget = functions.app_instance.query_one(".scrollable_log", Log) # Find the scrollable text area
  56. height = text_widget.scrollable_content_region.height # Get its height
  57. # Ensure the text is a string and append it to the Log widget
  58. random_number = random.randint(1, 100)
  59. new_text = f"[CONDITION] Scrollable height: {height} and Random Number: {random_number}"
  60. functions.add_text(new_text)
  61. functions.log_message(new_text) # Log the value
  62. else:
  63. functions.log_message("App instance not set!") # Debugging in case it's called too early
  64.  
  65. def toggle_all():
  66. TriggersStatus = functions.get_trigger_value(0)
  67. if TriggersStatus is True:
  68. for i in range(8):
  69. functions.set_trigger_value(i, False)
  70. for i in range( len(conditions) ):
  71. functions.set_condition_value(i, False)
  72. else:
  73. for i in range(8):
  74. functions.set_trigger_value(i, True)
  75. for i in range( len(conditions) ):
  76. functions.set_condition_value(i, True)
  77.  
  78. def change_all_triggers():
  79. for i in range(8):
  80. current_symbol = functions.get_trigger_string(i)
  81. cycle = ["^", "v", "-"]
  82. next_symbol = cycle[(cycle.index(current_symbol) + 1) % len(cycle)]
  83. functions.set_trigger_string(i, next_symbol)
  84.  
  85. def random_values():
  86. functions.glitching_switch(False)
  87.  
  88. OrigLen = functions.get_config_value("length")
  89. OrigRep = functions.get_config_value("repeat")
  90. OrigDel = functions.get_config_value("delay")
  91.  
  92. NewLen = random.randint(1, 100)
  93. NewRep = random.randint(1, 100)
  94. NewDel = random.randint(1, 100)
  95.  
  96. functions.set_config_value("length", NewLen)
  97. functions.set_config_value("repeat", NewRep)
  98. functions.set_config_value("delay", NewDel)
  99.  
  100. functions.add_text(f"[UPDATED] length ({OrigLen} -> {NewLen}), repeat ({OrigRep} -> {NewRep}), delay ({OrigDel} -> {NewDel})")
  101.  
  102. def change_baud_9600():
  103. functions.change_baudrate(9600)
  104. functions.set_uart_switch()
  105.  
  106. def change_baud_115200():
  107. functions.change_baudrate(115200)
  108. functions.set_uart_switch(False)
Buy Me A Coffee