Add deinit method to modules and extensions
This commit is contained in:
parent
55b3a3a9b1
commit
adff02e88a
@ -49,3 +49,6 @@ class Extension:
|
|||||||
|
|
||||||
def on_powersave_disable(self, keyboard):
|
def on_powersave_disable(self, keyboard):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
def deinit(self, keyboard):
|
||||||
|
pass
|
||||||
|
@ -249,6 +249,10 @@ class RGB(Extension):
|
|||||||
def on_powersave_disable(self, sandbox):
|
def on_powersave_disable(self, sandbox):
|
||||||
self._do_update()
|
self._do_update()
|
||||||
|
|
||||||
|
def deinit(self, sandbox):
|
||||||
|
for pixel in self.pixels:
|
||||||
|
pixel.deinit()
|
||||||
|
|
||||||
def set_hsv(self, hue, sat, val, index):
|
def set_hsv(self, hue, sat, val, index):
|
||||||
'''
|
'''
|
||||||
Takes HSV values and displays it on a single LED/Neopixel
|
Takes HSV values and displays it on a single LED/Neopixel
|
||||||
|
@ -500,6 +500,20 @@ class KMKKeyboard:
|
|||||||
if debug.enabled:
|
if debug.enabled:
|
||||||
debug(f'Error in {ext}.powersave_disable: {err}')
|
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:
|
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)
|
self._init(hid_type=hid_type, secondary_hid_type=secondary_hid_type, **kwargs)
|
||||||
try:
|
try:
|
||||||
@ -508,6 +522,7 @@ class KMKKeyboard:
|
|||||||
finally:
|
finally:
|
||||||
debug('Unexpected error: cleaning up')
|
debug('Unexpected error: cleaning up')
|
||||||
self._deinit_hid()
|
self._deinit_hid()
|
||||||
|
self.deinit()
|
||||||
|
|
||||||
def _init(
|
def _init(
|
||||||
self,
|
self,
|
||||||
|
@ -41,3 +41,6 @@ class Module:
|
|||||||
|
|
||||||
def on_powersave_disable(self, keyboard):
|
def on_powersave_disable(self, keyboard):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
def deinit(self, keyboard):
|
||||||
|
pass
|
||||||
|
Loading…
Reference in New Issue
Block a user