From 5dfac57a8f910c224b96c01216624146f13728fe Mon Sep 17 00:00:00 2001 From: Thibault Date: Tue, 9 Aug 2016 12:26:23 +0100 Subject: [PATCH] Improve homescreen backlighting to depend on external light Instead of relying on what power remains in the battery, rely instead on the external lighting to adapt the brightness of the screen. Note that this might need a bit more fine-tuning. --- apps/home/main.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) 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()