Added support for display backlight control
This commit is contained in:
parent
5c7e9aeb19
commit
04c21c1863
62
clock.py
62
clock.py
|
@ -7,6 +7,17 @@ import traceback
|
|||
import copy
|
||||
import os
|
||||
|
||||
def is_arm():
|
||||
if (os.uname()[4][:3] == 'arm') or (os.uname()[4][:7] == 'aarch64'):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
if is_arm():
|
||||
# Do not forget to create udev rule:
|
||||
# echo 'SUBSYSTEM=="backlight",RUN+="/bin/chmod 666 /sys/class/backlight/%k/brightness /sys/class/backlight/%k/bl_power"' | sudo tee -a /etc/udev/rules.d/backlight-permissions.rules
|
||||
from rpi_backlight import Backlight
|
||||
|
||||
from kivy.config import Config
|
||||
#Config.set('graphics', 'width', '800')
|
||||
#Config.set('graphics', 'height', '480')
|
||||
|
@ -137,36 +148,6 @@ Builder.load_string('''
|
|||
on_value: root.display_brightness_slider_value(*args)
|
||||
value_track: True
|
||||
value_track_color: [1, 0, 0, 1]
|
||||
Label:
|
||||
text:"Wifi network"
|
||||
halign: "left"
|
||||
valign: "middle"
|
||||
text_size: self.size
|
||||
Label:
|
||||
text:"wifi name"
|
||||
halign: "left"
|
||||
valign: "middle"
|
||||
text_size: self.size
|
||||
Label:
|
||||
text:"Wifi password"
|
||||
halign: "left"
|
||||
valign: "middle"
|
||||
text_size: self.size
|
||||
Label:
|
||||
text:"wifi password"
|
||||
halign: "left"
|
||||
valign: "middle"
|
||||
text_size: self.size
|
||||
Label:
|
||||
text:"Calendar URL"
|
||||
halign: "left"
|
||||
valign: "middle"
|
||||
text_size: self.size
|
||||
Label:
|
||||
text:"calendar url"
|
||||
halign: "left"
|
||||
valign: "middle"
|
||||
text_size: self.size
|
||||
FloatLayout
|
||||
id: settings_menu_wake_up_sound
|
||||
size_hint: None, None
|
||||
|
@ -269,7 +250,6 @@ class MyClockWidget(FloatLayout):
|
|||
# - "set_alarm"
|
||||
# - "settings_menu"
|
||||
# - "settings_menu_wake_up_sound"
|
||||
# - "calendar"
|
||||
view = "clock"
|
||||
|
||||
# we need a dirty hack to sensure that radio button is always in sync with selected setting
|
||||
|
@ -285,10 +265,12 @@ class MyClockWidget(FloatLayout):
|
|||
vlc = vlc.Instance()
|
||||
player = vlc.media_player_new()
|
||||
|
||||
if (os.uname()[4][:3] == 'arm') or (os.uname()[4][:7] == 'aarch64'):
|
||||
is_arm = True
|
||||
is_arm = is_arm()
|
||||
|
||||
if is_arm:
|
||||
backlight = Backlight()
|
||||
else:
|
||||
is_arm = False
|
||||
backlight = None
|
||||
|
||||
def play_sound(self, source):
|
||||
alarm_settings = App.get_running_app().alarm_settings
|
||||
|
@ -309,6 +291,15 @@ class MyClockWidget(FloatLayout):
|
|||
alarm_settings = App.get_running_app().alarm_settings
|
||||
alarm_settings.alarm_playing = False
|
||||
|
||||
def set_backlight(self, x):
|
||||
offset = 3
|
||||
# 20 steps to from 1 to 100 - offset
|
||||
c = (100 - offset)**(1/20)
|
||||
|
||||
y = c**x + offset
|
||||
z = max(1, round(y))
|
||||
self.backlight.brightness = z
|
||||
|
||||
def hide_widget(self, widget, hide=True):
|
||||
if hasattr(widget, 'saved_attrs'):
|
||||
if not hide:
|
||||
|
@ -638,7 +629,8 @@ class MyClockWidget(FloatLayout):
|
|||
alarm_settings = App.get_running_app().alarm_settings
|
||||
|
||||
alarm_settings.display_brightness = int(args[1])
|
||||
print("Display brightness changed to " + str(alarm_settings.display_brightness))
|
||||
if self.is_arm:
|
||||
self.set_backlight(alarm_settings.display_brightness)
|
||||
|
||||
def on_alarm_button_pressed(self):
|
||||
alarm_settings = App.get_running_app().alarm_settings
|
||||
|
|
Loading…
Reference in New Issue