diff --git a/apps/home/main.py b/apps/home/main.py index a8fdc11..67ebdb5 100644 --- a/apps/home/main.py +++ b/apps/home/main.py @@ -71,11 +71,11 @@ def draw_wifi(back_colour, rssi, connected, connecting, win_wifi): def backlight_adjust(): if ugfx.backlight() == 0: ugfx.power_mode(ugfx.POWER_ON) - l = pyb.ADC(16).read() - if (l > 90): - ugfx.backlight(100) - elif (l > 20): - ugfx.backlight(70) + l = onboard.get_light() + + lum_percent = int(l * 100 / 4096) + if (lum_percent > 30): + ugfx.backlight(lum_percent) else: ugfx.backlight(30) @@ -298,11 +298,9 @@ def home_main(): inactivity_limit = 120 else: inactivity_limit = 30 - if battery_percent > 120: #if charger plugged in - if ugfx.backlight() == 0: - ugfx.power_mode(ugfx.POWER_ON) - ugfx.backlight(100) - elif inactivity > inactivity_limit: + + # If charger is not plugged in and we're inactive, turn screen off + if battery_percent < 120 and inactivity > inactivity_limit: low_power() else: backlight_adjust()