diff --git a/README.md b/README.md index cadd81a..f1dd381 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ example from the ## Modifications - A number of sample macros for things such as Blender, a MIDI drum kit, DaVinici Resolve, and more +- Sleep the display and LEDs to avoid burn-in - Support for HID consumer control codes - Support for mouse buttons - Support for sending MIDI notes diff --git a/__init__.py b/__init__.py deleted file mode 100644 index 1263249..0000000 --- a/__init__.py +++ /dev/null @@ -1,10 +0,0 @@ -import sys -import commands - -# backwards compatibility for the 2.x series: -sys.modules['keyboard'] = commands -sys.modules['mouse'] = commands -sys.modules['pause'] = commands -sys.modules['sleep'] = commands -sys.modules['midi'] = commands -sys.modules['consumer'] = commands diff --git a/code.py b/code.py index 104b307..ee8a528 100755 --- a/code.py +++ b/code.py @@ -46,12 +46,12 @@ def elapsed_seconds(): # Set the macro page (app) at the given index def set_app(index): global app_index, keys, screen, sleep_remaining + + macropad.keyboard.release_all() app_index = index sleep_remaining = apps[app_index].timeout screen.setTitle(apps[app_index].name) - macropad.keyboard.release_all() - keys = Keys(apps[app_index]) keys.addListener(hid) keys.addListener(screen) @@ -61,21 +61,13 @@ def set_app(index): screen.initialize() apps = App.load_all(MACRO_FOLDER) if not apps: - screen.setError('NO MACRO FILES FOUND') + screen.setTitle('NO MACRO FILES FOUND') while True: time.sleep(60.0) -set_app(app_index) - -try: # Test the USB HID connection - macropad.keyboard.release_all() -except OSError as err: - print(err) - screen.setError('NO USB CONNECTION') - while True: - time.sleep(60.0) - -# Prep before the run loop +# Load our first app page +screen.setTitle(' CONNECTING... ') +set_app(app_index) while True: # Input event loop macropad.encoder_switch_debounced.update() diff --git a/screen.py b/screen.py index eb84daa..255689c 100644 --- a/screen.py +++ b/screen.py @@ -6,15 +6,15 @@ class ScreenListener: MAX_LABELS = 12 - sleeping = False def __init__(self, macropad): + self.macropad = macropad self.display = macropad.display self.display.auto_refresh = False - self.sleeping = False def __del__(self): self.display = None + self.macropad = None def initialize(self): self.group = displayio.Group() @@ -37,7 +37,7 @@ def initialize(self): terminalio.FONT, text='', color=0x000000, - anchored_position=(self.display.width//2, -2), + anchored_position=(self.display.width//2, -1), anchor_point=(0.5, 0.0) ) ) @@ -74,18 +74,10 @@ def released(self, keys, index): self.resume() def sleep(self): - if self.sleeping: return - self.display.brightness = 0 - self.display.root_group = displayio.Group() - self.display.refresh() - self.sleeping = True + self.macropad.display_sleep = True def resume(self): - if not self.sleeping: return - self.display.brightness = 1 - self.display.root_group = self.group - self.display.refresh() - self.sleeping = False + self.macropad.display_sleep = False def highlight(self, key_index): if key_index >= ScreenListener.MAX_LABELS: return diff --git a/tests/test_screen.py b/tests/test_screen.py index 9fbf3af..0d39501 100644 --- a/tests/test_screen.py +++ b/tests/test_screen.py @@ -46,46 +46,6 @@ def test_initalize(self): self.assertIsInstance(screen.display.root_group[elementCount - 2], Rect) self.assertEqual(screen.display.root_group[elementCount - 1].color, 0x000000) - def test_sleep(self): - macropad = MockMacroPad() - screen = ScreenListener(macropad) - screen.initialize() - screen.sleep() - - self.assertEqual(len(screen.display.root_group), 0) - self.assertEqual(screen.display.brightness, 0) - - def test_sleep_twice(self): - macropad = MockMacroPad() - screen = ScreenListener(macropad) - screen.initialize() - screen.sleep() - screen.sleep() - - screen.display.refresh.assert_called_once() - - def test_resume(self): - macropad = MockMacroPad() - screen = ScreenListener(macropad) - screen.initialize() - screen.sleep() - screen.resume() - - self.assertEqual(len(screen.display.root_group), 14) - self.assertEqual(screen.display.brightness, 1) - - def test_resume_twice(self): - macropad = MockMacroPad() - screen = ScreenListener(macropad) - screen.initialize() - screen.sleep() - - screen.display.refresh.reset_mock() - screen.resume() - screen.resume() - - screen.display.refresh.assert_called_once() - def test_highlight(self): macropad = MockMacroPad() screen = ScreenListener(macropad)