From fcf05cc0bfea342285287990bcc4dbc51e5f1ca6 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Mon, 20 Feb 2017 19:27:20 +0100 Subject: battery example: warn if the charging above threshold MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- examples/battery | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'examples') diff --git a/examples/battery b/examples/battery index 118f64c..2b7c0fc 100644 --- a/examples/battery +++ b/examples/battery @@ -1,10 +1,11 @@ # -*- python -*- # This is a small example that inverts the colours when the -# battery's capacity is low. +# battery's capacity is low and discharging or is high and +# charging. -# Copyright © 2014 Mattias Andrée (maandree@member.fsf.org) +# Copyright © 2014, 2017 Mattias Andrée (maandree@member.fsf.org) # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -21,8 +22,10 @@ -# Invert the colours when the battery capacity is below this threshold. -threshold = 5 # percent +# Invert the colours when the battery capacity is below this threshold and the the battery is discharging. +low_threshold = 5 # percent +# Invert the colours when the battery capacity is above this threshold and the the battery is charging. +high_threshold = 90 # percent # Current status. @@ -98,7 +101,7 @@ def periodically(year, month, day, hour, minute, second, weekday, fade): global inverted (discharging, capacity) = get_capacity() - should_invert = discharging and (capacity <= threshold) + should_invert = capacity <= low_threshold if discharging else capacity >= high_threshold if should_invert ^ inverted: inverted = should_invert -- cgit v1.2.3-70-g09d2