Implement timed blacking out of display
This commit is contained in:
parent
b5cf50b819
commit
026a2f8a3d
@ -65,19 +65,23 @@ class Oled(Extension):
|
|||||||
device_address=0x3C,
|
device_address=0x3C,
|
||||||
brightness=0.8,
|
brightness=0.8,
|
||||||
brightness_step=0.1,
|
brightness_step=0.1,
|
||||||
portrait: bool = False,
|
dim_time = 30,
|
||||||
|
off_time = 60,
|
||||||
):
|
):
|
||||||
displayio.release_displays()
|
displayio.release_displays()
|
||||||
self.rotation = 180 if flip else 0
|
self.rotation = 180 if flip else 0
|
||||||
#if portrait: self.rotation = self.rotation + 90
|
|
||||||
self._views = views.data
|
self._views = views.data
|
||||||
self._width = width if not portrait else height
|
self._width = width
|
||||||
self._height = height if not portrait else width
|
self._height = height
|
||||||
self._prevLayers = 0
|
self._prevLayers = 0
|
||||||
self._device_address = device_address
|
self._device_address = device_address
|
||||||
self._brightness = brightness
|
self._brightness = brightness
|
||||||
self._brightness_step = brightness_step
|
self._brightness_step = brightness_step
|
||||||
self._timer_start = ticks_ms()
|
self._timer_start = ticks_ms()
|
||||||
|
self._dark = False
|
||||||
|
self._go_dark = False
|
||||||
|
self._dim_time_ms = dim_time * 1000
|
||||||
|
self._off_time_ms = off_time * 1000
|
||||||
gc.collect()
|
gc.collect()
|
||||||
|
|
||||||
make_key(
|
make_key(
|
||||||
@ -87,8 +91,9 @@ class Oled(Extension):
|
|||||||
names=('OLED_BRD',), on_press=self._oled_brd, on_release=handler_passthrough
|
names=('OLED_BRD',), on_press=self._oled_brd, on_release=handler_passthrough
|
||||||
)
|
)
|
||||||
|
|
||||||
def render_oled(self, layer):
|
def render_oled(self, layer, *args, **kwargs):
|
||||||
splash = displayio.Group()
|
splash = displayio.Group()
|
||||||
|
splash.hidden = False if not self._dark else True
|
||||||
|
|
||||||
for view in self._views:
|
for view in self._views:
|
||||||
if view[3] == layer or view[3] is None:
|
if view[3] == layer or view[3] is None:
|
||||||
@ -145,10 +150,13 @@ class Oled(Extension):
|
|||||||
if sandbox.active_layers[0] != self._prevLayers:
|
if sandbox.active_layers[0] != self._prevLayers:
|
||||||
self._prevLayers = sandbox.active_layers[0]
|
self._prevLayers = sandbox.active_layers[0]
|
||||||
self.updateOLED(sandbox)
|
self.updateOLED(sandbox)
|
||||||
|
elif self._dark != self._go_dark:
|
||||||
|
self._dark = self._go_dark
|
||||||
|
self.updateOLED(sandbox)
|
||||||
return
|
return
|
||||||
|
|
||||||
def after_matrix_scan(self, sandbox):
|
def after_matrix_scan(self, keyboard):
|
||||||
if sandbox.matrix_update or sandbox.secondary_matrix_update:
|
if keyboard.matrix_update or keyboard.secondary_matrix_update:
|
||||||
self.timer_time_reset()
|
self.timer_time_reset()
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -157,6 +165,7 @@ class Oled(Extension):
|
|||||||
|
|
||||||
def after_hid_send(self, sandbox):
|
def after_hid_send(self, sandbox):
|
||||||
self.dim()
|
self.dim()
|
||||||
|
return
|
||||||
|
|
||||||
def on_powersave_enable(self, sandbox):
|
def on_powersave_enable(self, sandbox):
|
||||||
self._display.brightness = (
|
self._display.brightness = (
|
||||||
@ -190,11 +199,11 @@ class Oled(Extension):
|
|||||||
self._timer_start = ticks_ms()
|
self._timer_start = ticks_ms()
|
||||||
|
|
||||||
def dim(self):
|
def dim(self):
|
||||||
if not check_deadline(ticks_ms(), self._timer_start, 30000):
|
if not check_deadline(ticks_ms(), self._timer_start, self._off_time_ms):
|
||||||
if self._display.brightness > 0.1:
|
self._go_dark = True
|
||||||
self._display.brightness = 0.1
|
elif not check_deadline(ticks_ms(), self._timer_start, self._dim_time_ms):
|
||||||
elif not check_deadline(ticks_ms(), self._timer_start, 10000):
|
if self._display.brightness > 0.2:
|
||||||
if self._display.brightness > 0.5:
|
self._display.brightness = 0.2
|
||||||
self._display.brightness = 0.5
|
else:
|
||||||
else: self._display.brightness = (self._brightness)
|
self._display.brightness = (self._brightness)
|
||||||
return
|
self._go_dark = False
|
Loading…
x
Reference in New Issue
Block a user