@@ -161,11 +161,10 @@ def _keys_and_pixels(order=None):
161161 self ._sine_wave_sample = None
162162
163163 # 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
169168
170169 # Define MIDI:
171170 self ._midi = adafruit_midi .MIDI (
@@ -292,9 +291,9 @@ def keys(self):
292291 macropad = MacroPad()
293292
294293 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 )
298297 """
299298 return self ._keys
300299
@@ -380,6 +379,8 @@ def keyboard(self):
380379 if macropad.encoder_switch:
381380 macropad.keyboard.send(macropad.Keycode.A)
382381 """
382+ if self ._keyboard is None :
383+ self ._keyboard = Keyboard (usb_hid .devices )
383384 return self ._keyboard
384385
385386 @property
@@ -402,6 +403,10 @@ def keyboard_layout(self):
402403 if macropad.encoder_switch:
403404 macropad.keyboard_layout.write("Hello World")
404405 """
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 )
405410 return self ._keyboard_layout
406411
407412 @property
@@ -421,6 +426,8 @@ def consumer_control(self):
421426 if macropad.encoder_switch:
422427 macropad.consumer_control.send(macropad.ConsumerControlCode.VOLUME_DECREMENT)
423428 """
429+ if self ._consumer_control is None :
430+ self ._consumer_control = ConsumerControl (usb_hid .devices )
424431 return self ._consumer_control
425432
426433 @property
@@ -441,6 +448,8 @@ def mouse(self):
441448 if macropad.encoder_switch:
442449 macropad.mouse.click(macropad.Mouse.LEFT_BUTTON)
443450 """
451+ if self ._mouse is None :
452+ self ._mouse = Mouse (usb_hid .devices )
444453 return self ._mouse
445454
446455 @property
@@ -748,9 +757,9 @@ def display_text(
748757 text_lines = macropad.display_text(title="MacroPad Info")
749758
750759 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)
754763 text_lines[1].text = "Rotary encoder {}".format(macropad.encoder)
755764 text_lines[2].text = "Encoder switch: {}".format(macropad.encoder_switch)
756765 text_lines.show()
0 commit comments