From 2db8f143eb6733af2a6c7bc4393f4564ce0eac36 Mon Sep 17 00:00:00 2001 From: Sam Keating-Fry Date: Sat, 29 Aug 2020 14:40:44 +0100 Subject: [PATCH] Display UPS-Lite charging status MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace the '%' in the battery indicator with '⚡' when the UPS-Lite is connected to an external power source. Suggestions welcome for a different character as '⚡' is a little hard to read on e-ink displays. --- pwnagotchi/plugins/default/ups_lite.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/pwnagotchi/plugins/default/ups_lite.py b/pwnagotchi/plugins/default/ups_lite.py index 482472f..3df7685 100644 --- a/pwnagotchi/plugins/default/ups_lite.py +++ b/pwnagotchi/plugins/default/ups_lite.py @@ -7,6 +7,8 @@ # For Raspberry Pi Zero Ups Power Expansion Board with Integrated Serial Port S3U4 # https://www.ebay.de/itm/For-Raspberry-Pi-Zero-Ups-Power-Expansion-Board-with-Integrated-Serial-Port-S3U4/323873804310 # https://www.aliexpress.com/item/32888533624.html +# +# To display external power supply status you need to bridge the necessary pins on the UPS-Lite board. See instructions in the UPS-Lite repo. import logging import struct @@ -15,6 +17,7 @@ from pwnagotchi.ui.view import BLACK import pwnagotchi.ui.fonts as fonts import pwnagotchi.plugins as plugins import pwnagotchi +import RPi.GPIO as GPIO # TODO: add enable switch in config.yml an cleanup all to the best place @@ -43,6 +46,17 @@ class UPS: except: return 0.0 + def charging(self): + try: + GPIO.setmode(GPIO.BCM) + GPIO.setup(4, GPIO.IN) + if (GPIO.input(4) == GPIO.HIGH): + return '⚡' + if (GPIO.input(4) == GPIO.LOW): + return '%' + except: + return '%' + class UPSLite(plugins.Plugin): __author__ = 'evilsocket@gmail.com' @@ -66,7 +80,8 @@ class UPSLite(plugins.Plugin): def on_ui_update(self, ui): capacity = self.ups.capacity() - ui.set('ups', "%2i%%" % capacity) + charging = self.ups.charging() + ui.set('ups', "%2i%s" % (capacity, charging)) if capacity <= self.options['shutdown']: logging.info('[ups_lite] Empty battery (<= %s%%): shuting down' % self.options['shutdown']) ui.update(force=True, new_data={'status': 'Battery exhausted, bye ...'})