1111import os
1212import displayio
1313import terminalio
14+ import time
1415from adafruit_display_shapes .rect import Rect
1516from adafruit_display_text import label
1617from adafruit_macropad import MacroPad
@@ -48,51 +49,50 @@ def switch(self):
4849
4950
5051# INITIALIZATION -----------------------
51-
52- macropad = MacroPad ()
53- macropad .display .auto_refresh = False
54- macropad .pixels .auto_write = False
55-
56- # Set up displayio group with all the labels
57- group = displayio .Group ()
58- for key_index in range (12 ):
59- x = key_index % 3
60- y = key_index // 3
61- group .append (label .Label (terminalio .FONT , text = '' , color = 0xFFFFFF ,
62- anchored_position = ((macropad .display .width - 1 ) * x / 2 ,
63- macropad .display .height - 1 -
64- (3 - y ) * 12 ),
65- anchor_point = (x / 2 , 1.0 )))
66- group .append (Rect (0 , 0 , macropad .display .width , 12 , fill = 0xFFFFFF ))
67- group .append (label .Label (terminalio .FONT , text = '' , color = 0x000000 ,
68- anchored_position = (macropad .display .width // 2 , - 2 ),
69- anchor_point = (0.5 , 0.0 )))
70- macropad .display .show (group )
71-
72- # Load all the macro key setups from .py files in MACRO_FOLDER
73- apps = []
74- files = os .listdir (MACRO_FOLDER )
75- files .sort ()
76- for filename in files :
77- if filename .endswith ('.py' ):
78- try :
79- module = __import__ (MACRO_FOLDER + '/' + filename [:- 3 ])
80- apps .append (App (module .app ))
81- except (SyntaxError , ImportError , AttributeError , KeyError , NameError ,
82- IndexError , TypeError ) as err :
52+ if True :
53+ macropad = MacroPad ()
54+ macropad .display .auto_refresh = False
55+ macropad .pixels .auto_write = False
56+
57+ # Set up displayio group with all the labels
58+ group = displayio .Group ()
59+ for key_index in range (12 ):
60+ x = key_index % 3
61+ y = key_index // 3
62+ group .append (label .Label (terminalio .FONT , text = '' , color = 0xFFFFFF ,
63+ anchored_position = ((macropad .display .width - 1 ) * x / 2 ,
64+ macropad .display .height - 1 -
65+ (3 - y ) * 12 ),
66+ anchor_point = (x / 2 , 1.0 )))
67+ group .append (Rect (0 , 0 , macropad .display .width , 12 , fill = 0xFFFFFF ))
68+ group .append (label .Label (terminalio .FONT , text = '' , color = 0x000000 ,
69+ anchored_position = (macropad .display .width // 2 , - 2 ),
70+ anchor_point = (0.5 , 0.0 )))
71+ macropad .display .show (group )
72+
73+ # Load all the macro key setups from .py files in MACRO_FOLDER
74+ apps = []
75+ files = os .listdir (MACRO_FOLDER )
76+ files .sort ()
77+ for filename in files :
78+ if filename .endswith ('.py' ):
79+ try :
80+ module = __import__ (MACRO_FOLDER + '/' + filename [:- 3 ])
81+ apps .append (App (module .app ))
82+ except (SyntaxError , ImportError , AttributeError , KeyError , NameError ,
83+ IndexError , TypeError ) as err :
84+ pass
85+
86+ if not apps :
87+ group [13 ].text = 'NO MACRO FILES FOUND'
88+ macropad .display .refresh ()
89+ while True :
8390 pass
8491
85- if not apps :
86- group [13 ].text = 'NO MACRO FILES FOUND'
87- macropad .display .refresh ()
88- while True :
89- pass
90-
91- last_position = None
92- last_encoder_switch = macropad .encoder_switch_debounced .pressed
93- app_index = 0
94- apps [app_index ].switch ()
95-
92+ last_position = None
93+ last_encoder_switch = macropad .encoder_switch_debounced .pressed
94+ app_index = 0
95+ apps [app_index ].switch ()
9696
9797# MAIN LOOP ----------------------------
9898
@@ -128,6 +128,15 @@ def switch(self):
128128
129129 sequence = apps [app_index ].macros [key_number ][2 ]
130130 if pressed :
131+ # the sequence is arbitrary-length
132+ # each item in the sequence is either
133+ # an integer (e.g., Keycode.KEYPAD_MINUS),
134+ # a floating point value (e.g., 0.20)
135+ # or a string.
136+ # Positive Integers ==> key pressed
137+ # Negative Integers ==> key released
138+ # Float ==> sleep in seconds
139+ # String ==> each key in string pressed & released
131140 if key_number < 12 : # No pixel for encoder button
132141 macropad .pixels [key_number ] = 0xFFFFFF
133142 macropad .pixels .show ()
@@ -137,6 +146,8 @@ def switch(self):
137146 macropad .keyboard .press (item )
138147 else :
139148 macropad .keyboard .release (- item )
149+ elif isinstance (item , float ):
150+ time .sleep (item )
140151 else :
141152 macropad .keyboard_layout .write (item )
142153 else :
0 commit comments