Icon update + prepare for smoother led transitions
BIN
alarm_off.png
Before Width: | Height: | Size: 7.8 KiB After Width: | Height: | Size: 7.3 KiB |
79
clock.py
|
@ -289,7 +289,11 @@ class MyClockWidget(FloatLayout):
|
|||
seconds_to_next_alarm = 0
|
||||
|
||||
light_state = "off" # "off", "reading", "sunrise" or "on"
|
||||
intensity = 0
|
||||
intensity_target = 0
|
||||
intensity_prev = 0
|
||||
intensity_curr = 0
|
||||
intensity_target_prev = None
|
||||
rgbw_prev = None
|
||||
|
||||
# view can be one of the following strings:
|
||||
# - "clock"
|
||||
|
@ -314,8 +318,6 @@ class MyClockWidget(FloatLayout):
|
|||
|
||||
is_arm = is_arm()
|
||||
|
||||
intensity_prev = None
|
||||
rgbw_prev = None
|
||||
if is_arm:
|
||||
backlight = Backlight()
|
||||
else:
|
||||
|
@ -442,10 +444,10 @@ class MyClockWidget(FloatLayout):
|
|||
alarm_settings = App.get_running_app().alarm_settings
|
||||
|
||||
if alarm_settings.alarm_playing:
|
||||
source = 'playing.png'
|
||||
source = 'media_playing.png'
|
||||
rgb = [1.0, 1.0, 1.0]
|
||||
else:
|
||||
source = 'stopped.png'
|
||||
source = 'media_stopped.png'
|
||||
rgb = [1.0, 1.0, 1.0]
|
||||
|
||||
play_button = self.ids["play_button"]
|
||||
|
@ -485,7 +487,6 @@ class MyClockWidget(FloatLayout):
|
|||
self.draw_list_curr_frame.append(["canvas.clear()", settings_button])
|
||||
with settings_button.canvas:
|
||||
self.draw_list_curr_frame.append(["Color", settings_button.canvas, rgb[0], rgb[1], rgb[2]])
|
||||
# Rectangle(size=settings_button.size, pos=settings_button.pos, source=source)
|
||||
self.draw_list_curr_frame.append(["Rectangle", settings_button.canvas, settings_button.size, settings_button.pos, source])
|
||||
|
||||
def intensity_to_rgbw(self, intensity):
|
||||
|
@ -496,7 +497,6 @@ class MyClockWidget(FloatLayout):
|
|||
|
||||
h = max(0, min(75, (75 - 12) * intensity + 12))
|
||||
s = max(0, min(100, 250 - 250 * intensity))
|
||||
# s = max(0, min(100, 100 - 100 * intensity))
|
||||
l = 100 * intensity
|
||||
|
||||
rgb = hsluv_to_rgb([h, s, l])
|
||||
|
@ -505,32 +505,21 @@ class MyClockWidget(FloatLayout):
|
|||
return led_color
|
||||
|
||||
def set_leds(self):
|
||||
if self.intensity_prev != self.intensity:
|
||||
self.intensity_prev = self.intensity
|
||||
if self.intensity_prev != self.intensity_curr:
|
||||
self.intensity_prev = self.intensity_curr
|
||||
if self.is_arm:
|
||||
led_color = self.intensity_to_rgbw(self.intensity)
|
||||
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:
|
||||
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)
|
||||
led_color = self.intensity_to_rgbw(self.intensity_curr)
|
||||
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))
|
||||
print(self.light_state + ", t: " + str(self.seconds_to_next_alarm) + ", i: " + str(self.intensity_curr) + ", 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)]
|
||||
# On non-arm rgbw_colorspace_converter and hsluv are not available; fake rgbw by setting w component to scaled value of intensity_curr
|
||||
rgbw = [0, 0, 0, round(self.intensity_curr * 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))
|
||||
print(self.light_state + ", t: " + str(self.seconds_to_next_alarm) + ", i: " + str(self.intensity_curr) + ", rgbw: " + str(rgbw))
|
||||
|
||||
def sunrise(self):
|
||||
alarm_settings = App.get_running_app().alarm_settings
|
||||
|
@ -540,15 +529,15 @@ class MyClockWidget(FloatLayout):
|
|||
return
|
||||
|
||||
if self.seconds_to_next_alarm < 0.1:
|
||||
intensity = (alarm_settings.wake_up_brightness / 20.0)
|
||||
intensity_target = (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)
|
||||
intensity_target = (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
|
||||
# only adjust intensity_target if new intensity_target is higher than current intesity, to avoid dimming light when reading mode is on
|
||||
if self.intensity_target < intensity_target:
|
||||
self.intensity_target = intensity_target
|
||||
self.light_state = new_state
|
||||
|
||||
def process_led_state(self):
|
||||
|
@ -558,11 +547,22 @@ class MyClockWidget(FloatLayout):
|
|||
self.sunrise()
|
||||
else:
|
||||
if (self.light_state == "off"):
|
||||
self.intensity = 0
|
||||
self.intensity_target = 0
|
||||
elif (self.light_state == "reading"):
|
||||
self.intensity = alarm_settings.reading_light_brightness / 20.0
|
||||
self.intensity_target = alarm_settings.reading_light_brightness / 20.0
|
||||
elif (self.light_state == "on"):
|
||||
self.intensity = alarm_settings.wake_up_brightness / 20.0
|
||||
self.intensity_target = alarm_settings.wake_up_brightness / 20.0
|
||||
|
||||
step = self.intensity_target - self.intensity_curr
|
||||
stepsize = 0.01
|
||||
|
||||
if step > stepsize:
|
||||
step = stepsize
|
||||
elif step < -stepsize:
|
||||
step = -stepsize
|
||||
|
||||
#self.intensity_curr = self.intensity_curr + stepsize
|
||||
self.intensity_curr = self.intensity_target
|
||||
|
||||
def check_play_sound(self):
|
||||
alarm_settings = App.get_running_app().alarm_settings
|
||||
|
@ -765,7 +765,7 @@ class MyClockWidget(FloatLayout):
|
|||
|
||||
alarm_settings.reading_light_brightness = int(args[1])
|
||||
if (self.light_state == "reading"):
|
||||
self.intensity = alarm_settings.reading_light_brightness / 20.0
|
||||
self.intensity_target = alarm_settings.reading_light_brightness / 20.0
|
||||
print("Reading light brightness changed to " + str(alarm_settings.reading_light_brightness))
|
||||
|
||||
def display_brightness_slider_value(self, *args):
|
||||
|
@ -780,21 +780,21 @@ class MyClockWidget(FloatLayout):
|
|||
|
||||
if self.light_state == "off":
|
||||
self.light_state = "reading"
|
||||
self.intensity = alarm_settings.reading_light_brightness / 20.0
|
||||
self.intensity_target = alarm_settings.reading_light_brightness / 20.0
|
||||
elif self.light_state == "reading":
|
||||
self.light_state = "off"
|
||||
self.intensity = 0
|
||||
self.intensity_target = 0
|
||||
elif self.light_state == "sunrise":
|
||||
# allow enabling reading mode when sunrise has not yet reached that level
|
||||
if self.intensity < alarm_settings.reading_light_brightness / 20.0:
|
||||
if self.intensity_target < alarm_settings.reading_light_brightness / 20.0:
|
||||
self.light_state = "reading"
|
||||
self.intensity = alarm_settings.reading_light_brightness / 20.0
|
||||
self.intensity_target = alarm_settings.reading_light_brightness / 20.0
|
||||
else:
|
||||
self.light_state = "off"
|
||||
|
||||
elif self.light_state == "on":
|
||||
self.light_state = "reading"
|
||||
self.intensity = 0
|
||||
self.intensity_target = 0
|
||||
if alarm_settings.alarm_playing:
|
||||
self.stop_sound()
|
||||
|
||||
|
@ -828,7 +828,6 @@ class MyClockWidget(FloatLayout):
|
|||
|
||||
def on_touch_up(self, touch):
|
||||
self.grabbed = ""
|
||||
print("light button move init reset")
|
||||
self.light_button_move_init = []
|
||||
alarm_settings = App.get_running_app().alarm_settings
|
||||
|
||||
|
|
BIN
light_off.png
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 8.2 KiB |
BIN
light_on.png
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 18 KiB |
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 19 KiB |
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 20 KiB |
After Width: | Height: | Size: 7.7 KiB |
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 7.9 KiB |