diff --git a/kmk/extensions/__init__.py b/kmk/extensions/__init__.py index 1eba5e5..33eea68 100644 --- a/kmk/extensions/__init__.py +++ b/kmk/extensions/__init__.py @@ -49,3 +49,6 @@ class Extension: def on_powersave_disable(self, keyboard): raise NotImplementedError + + def deinit(self, keyboard): + pass diff --git a/kmk/extensions/rgb.py b/kmk/extensions/rgb.py index 6f71593..9c06466 100644 --- a/kmk/extensions/rgb.py +++ b/kmk/extensions/rgb.py @@ -249,6 +249,10 @@ class RGB(Extension): def on_powersave_disable(self, sandbox): self._do_update() + def deinit(self, sandbox): + for pixel in self.pixels: + pixel.deinit() + def set_hsv(self, hue, sat, val, index): ''' Takes HSV values and displays it on a single LED/Neopixel diff --git a/kmk/kmk_keyboard.py b/kmk/kmk_keyboard.py index e5a6f9c..44646ac 100644 --- a/kmk/kmk_keyboard.py +++ b/kmk/kmk_keyboard.py @@ -500,6 +500,20 @@ class KMKKeyboard: if debug.enabled: debug(f'Error in {ext}.powersave_disable: {err}') + def deinit(self) -> None: + for module in self.modules: + try: + module.deinit(self) + except Exception as err: + if debug.enabled: + debug(f'Error in {module}.deinit: {err}') + for ext in self.extensions: + try: + ext.deinit(self.sandbox) + except Exception as err: + if debug.enabled: + debug(f'Error in {ext}.deinit: {err}') + def go(self, hid_type=HIDModes.USB, secondary_hid_type=None, **kwargs) -> None: self._init(hid_type=hid_type, secondary_hid_type=secondary_hid_type, **kwargs) try: @@ -508,6 +522,7 @@ class KMKKeyboard: finally: debug('Unexpected error: cleaning up') self._deinit_hid() + self.deinit() def _init( self, diff --git a/kmk/modules/__init__.py b/kmk/modules/__init__.py index b616f07..dd587c3 100644 --- a/kmk/modules/__init__.py +++ b/kmk/modules/__init__.py @@ -41,3 +41,6 @@ class Module: def on_powersave_disable(self, keyboard): raise NotImplementedError + + def deinit(self, keyboard): + pass