Small fixes

This commit is contained in:
Admar Schoonen 2023-04-10 15:25:34 +02:00
parent 6556adb5e3
commit 6863e89977
1 changed files with 27 additions and 7 deletions

View File

@ -166,7 +166,7 @@ Builder.load_string('''
text_size: self.size
Slider:
id: reading_light_brightness_slider
min: 0
min: 1
max: 20
value: 1
on_value: root.reading_light_brightness_slider_value(*args)
@ -288,7 +288,6 @@ class MyClockWidget(FloatLayout):
light_state = "off" # "off", "reading", "sunrise" or "on"
intensity = 0
intensity_prev = None
# view can be one of the following strings:
# - "clock"
@ -312,6 +311,8 @@ class MyClockWidget(FloatLayout):
is_arm = is_arm()
intensity_prev = None
rgbw_prev = None
if is_arm:
backlight = Backlight()
else:
@ -511,6 +512,23 @@ class MyClockWidget(FloatLayout):
else:
print(self.light_state + ", t: " + str(self.seconds_to_next_alarm) + ", i: " + str(self.intensity))
def set_leds(self):
if self.intensity_prev != self.intensity:
self.intensity_prev = self.intensity
if self.is_arm:
led_color = self.intensity_to_rgbw(self.intensity)
if self.rgbw_prev != led_color.rgbw:
self.rgbw_prev = led_color.rgbw
print(self.light_state + ", t: " + str(self.seconds_to_next_alarm) + ", i: " + str(self.intensity) + ", rgbw: " + str(led_color.rgbw))
pixels.fill(led_color.rgbw)
pixels.show()
else:
# On non-arm rgbw_colorspace_converter and hsluv are not available; fake rgbw by setting w component to scaled value of intensity
rgbw = [0, 0, 0, round(self.intensity * 255)]
if self.rgbw_prev != rgbw:
self.rgbw_prev = rgbw
print(self.light_state + ", t: " + str(self.seconds_to_next_alarm) + ", i: " + str(self.intensity) + ", rgbw: " + str(rgbw))
def sunrise(self):
alarm_settings = App.get_running_app().alarm_settings
@ -519,14 +537,16 @@ class MyClockWidget(FloatLayout):
return
if self.seconds_to_next_alarm < 0.1:
self.light_state = "on"
intensity = (1.0 - self.seconds_to_next_alarm / alarm_settings.seconds_to_sunrise) * (alarm_settings.wake_up_brightness / 20.0)
intensity = (alarm_settings.wake_up_brightness / 20.0)
new_state = "on"
else:
intensity = (1.0 - self.seconds_to_next_alarm / alarm_settings.seconds_to_sunrise) * (alarm_settings.wake_up_brightness / 20.0)
new_state = "sunrise"
# only adjust intensity if new intensity is higher than current intesity, to avoid dimming light when reading mode is on
if self.intensity < intensity:
self.intensity = intensity
self.light_state = "sunrise"
self.light_state = new_state
def process_led_state(self):
alarm_settings = App.get_running_app().alarm_settings
@ -741,7 +761,7 @@ class MyClockWidget(FloatLayout):
alarm_settings = App.get_running_app().alarm_settings
alarm_settings.reading_light_brightness = int(args[1])
if (self.light_state == "reading") or (self.light_state == "sunrise"):
if (self.light_state == "reading"):
self.intensity = alarm_settings.reading_light_brightness / 20.0
print("Reading light brightness changed to " + str(alarm_settings.reading_light_brightness))