@@ -161,11 +161,10 @@ def _keys_and_pixels(order=None):
161
161
self ._sine_wave_sample = None
162
162
163
163
# Define HID:
164
- self ._keyboard = Keyboard (usb_hid .devices )
165
- # This will need to be updated if we add more keyboard layouts. Currently there is only US.
166
- self ._keyboard_layout = KeyboardLayoutUS (self ._keyboard )
167
- self ._consumer_control = ConsumerControl (usb_hid .devices )
168
- self ._mouse = Mouse (usb_hid .devices )
164
+ self ._keyboard = None
165
+ self ._keyboard_layout = None
166
+ self ._consumer_control = None
167
+ self ._mouse = None
169
168
170
169
# Define MIDI:
171
170
self ._midi = adafruit_midi .MIDI (
@@ -292,9 +291,9 @@ def keys(self):
292
291
macropad = MacroPad()
293
292
294
293
while True:
295
- event = macropad.keys.events.get()
296
- if event :
297
- print(event )
294
+ key_event = macropad.keys.events.get()
295
+ if key_event :
296
+ print(key_event )
298
297
"""
299
298
return self ._keys
300
299
@@ -380,6 +379,8 @@ def keyboard(self):
380
379
if macropad.encoder_switch:
381
380
macropad.keyboard.send(macropad.Keycode.A)
382
381
"""
382
+ if self ._keyboard is None :
383
+ self ._keyboard = Keyboard (usb_hid .devices )
383
384
return self ._keyboard
384
385
385
386
@property
@@ -402,6 +403,10 @@ def keyboard_layout(self):
402
403
if macropad.encoder_switch:
403
404
macropad.keyboard_layout.write("Hello World")
404
405
"""
406
+ if self ._keyboard is None :
407
+ self ._keyboard = Keyboard (usb_hid .devices )
408
+ # This will need to be updated if we add more keyboard layouts. Currently there is only US.
409
+ self ._keyboard_layout = KeyboardLayoutUS (self ._keyboard )
405
410
return self ._keyboard_layout
406
411
407
412
@property
@@ -421,6 +426,8 @@ def consumer_control(self):
421
426
if macropad.encoder_switch:
422
427
macropad.consumer_control.send(macropad.ConsumerControlCode.VOLUME_DECREMENT)
423
428
"""
429
+ if self ._consumer_control is None :
430
+ self ._consumer_control = ConsumerControl (usb_hid .devices )
424
431
return self ._consumer_control
425
432
426
433
@property
@@ -441,6 +448,8 @@ def mouse(self):
441
448
if macropad.encoder_switch:
442
449
macropad.mouse.click(macropad.Mouse.LEFT_BUTTON)
443
450
"""
451
+ if self ._mouse is None :
452
+ self ._mouse = Mouse (usb_hid .devices )
444
453
return self ._mouse
445
454
446
455
@property
@@ -748,9 +757,9 @@ def display_text(
748
757
text_lines = macropad.display_text(title="MacroPad Info")
749
758
750
759
while True:
751
- event = macropad.keys.events.get()
752
- if event :
753
- text_lines[0].text = "Key {} pressed!".format(event .key_number)
760
+ key_event = macropad.keys.events.get()
761
+ if key_event :
762
+ text_lines[0].text = "Key {} pressed!".format(key_event .key_number)
754
763
text_lines[1].text = "Rotary encoder {}".format(macropad.encoder)
755
764
text_lines[2].text = "Encoder switch: {}".format(macropad.encoder_switch)
756
765
text_lines.show()
0 commit comments