mirror of
https://github.com/jayofelony/pwnagotchi.git
synced 2025-07-01 18:37:27 -04:00
Added optional rotation/fixed display setting
Added optional fixed display parameter Signed-off-by: Jeroen Oudshoorn <oudshoorn.jeroen@gmail.com>
This commit is contained in:
@ -2,7 +2,6 @@
|
|||||||
# wget https://cdn.pisugar.com/release/pisugar-power-manager.sh
|
# wget https://cdn.pisugar.com/release/pisugar-power-manager.sh
|
||||||
# bash pisugar-power-manager.sh -c release
|
# bash pisugar-power-manager.sh -c release
|
||||||
|
|
||||||
|
|
||||||
# https://www.tindie.com/stores/pisugar/
|
# https://www.tindie.com/stores/pisugar/
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
@ -18,10 +17,13 @@ from flask import render_template_string
|
|||||||
|
|
||||||
class PiSugar(plugins.Plugin):
|
class PiSugar(plugins.Plugin):
|
||||||
__author__ = "jayofelony"
|
__author__ = "jayofelony"
|
||||||
__version__ = "1.0"
|
__version__ = "1.2"
|
||||||
__license__ = "GPL3"
|
__license__ = "GPL3"
|
||||||
__description__ = ("A plugin that will add a voltage indicator for the PiSugar batteries."
|
__description__ = (
|
||||||
"This plugin will also have a web configuration in the future, just like the Power Manager.")
|
"A plugin that will add a voltage indicator for the PiSugar batteries. "
|
||||||
|
"Rotation of battery status can be enabled or disabled via configuration. "
|
||||||
|
"Additionally, when rotation is disabled, you can choose which metric to display."
|
||||||
|
)
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._agent = None
|
self._agent = None
|
||||||
@ -32,10 +34,25 @@ class PiSugar(plugins.Plugin):
|
|||||||
self.ready = False
|
self.ready = False
|
||||||
self.lasttemp = 69
|
self.lasttemp = 69
|
||||||
self.drot = 0 # display rotation
|
self.drot = 0 # display rotation
|
||||||
self.nextDChg = 0 # last time display changed, rotate on updates after 5 seconds
|
self.nextDChg = 0 # last time display changed
|
||||||
|
self.rotation_enabled = True # default rotation enabled
|
||||||
|
self.default_display = "voltage" # default display option
|
||||||
|
|
||||||
def on_loaded(self):
|
def on_loaded(self):
|
||||||
logging.info("[PiSugarX] plugin loaded.")
|
logging.info("[PiSugarX] plugin loaded.")
|
||||||
|
# Read rotation option from configuration
|
||||||
|
cfg = pwnagotchi.config['main']['plugins']['pisugarx']
|
||||||
|
self.rotation_enabled = cfg.get('rotation', True)
|
||||||
|
self.default_display = cfg.get('default_display', 'voltage').lower()
|
||||||
|
|
||||||
|
# Validate default_display
|
||||||
|
valid_displays = ['voltage', 'percentage', 'temp']
|
||||||
|
if self.default_display not in valid_displays:
|
||||||
|
logging.warning(f"[PiSugarX] Invalid default_display '{self.default_display}'. Using 'voltage'.")
|
||||||
|
self.default_display = 'voltage'
|
||||||
|
|
||||||
|
logging.info(f"[PiSugarX] Rotation is {'enabled' if self.rotation_enabled else 'disabled'}.")
|
||||||
|
logging.info(f"[PiSugarX] Default display (when rotation disabled): {self.default_display}")
|
||||||
|
|
||||||
def on_ready(self, agent):
|
def on_ready(self, agent):
|
||||||
self.ready = True
|
self.ready = True
|
||||||
@ -48,8 +65,7 @@ class PiSugar(plugins.Plugin):
|
|||||||
def on_internet_available(self, agent):
|
def on_internet_available(self, agent):
|
||||||
self._agent = agent
|
self._agent = agent
|
||||||
self.ps.rtc_web()
|
self.ps.rtc_web()
|
||||||
"""
|
|
||||||
WORK IN PROGRESS
|
|
||||||
def on_webhook(self, path, request):
|
def on_webhook(self, path, request):
|
||||||
if not self.ready:
|
if not self.ready:
|
||||||
ret = "<html><head><title>PiSugarX not ready</title></head><body><h1>PiSugarX not ready</h1></body></html>"
|
ret = "<html><head><title>PiSugarX not ready</title></head><body><h1>PiSugarX not ready</h1></body></html>"
|
||||||
@ -169,7 +185,7 @@ class PiSugar(plugins.Plugin):
|
|||||||
ret += "<body><h1>%s</h1></body></html>" % repr(e)
|
ret += "<body><h1>%s</h1></body></html>" % repr(e)
|
||||||
logging.error("[PiSugarX] error: %s" % repr(e))
|
logging.error("[PiSugarX] error: %s" % repr(e))
|
||||||
return render_template_string(ret), 404
|
return render_template_string(ret), 404
|
||||||
"""
|
|
||||||
def on_ui_setup(self, ui):
|
def on_ui_setup(self, ui):
|
||||||
ui.add_element(
|
ui.add_element(
|
||||||
"bat",
|
"bat",
|
||||||
@ -191,16 +207,20 @@ class PiSugar(plugins.Plugin):
|
|||||||
capacity = int(self.ps.get_battery_level())
|
capacity = int(self.ps.get_battery_level())
|
||||||
voltage = self.ps.get_battery_voltage()
|
voltage = self.ps.get_battery_voltage()
|
||||||
temp = self.ps.get_temperature()
|
temp = self.ps.get_temperature()
|
||||||
|
|
||||||
if temp != self.lasttemp:
|
if temp != self.lasttemp:
|
||||||
logging.debug(f"[PiSugar3] ({capacity}%, {voltage}V, {temp}°C)")
|
logging.debug(f"[PiSugar3] ({capacity}%, {voltage:.2f}V, {temp}°C)")
|
||||||
self.lasttemp = temp
|
self.lasttemp = temp
|
||||||
# new model use battery_power_plugged & battery_allow_charging to detect real charging status
|
|
||||||
|
# If it's a new model and charging is detected
|
||||||
if self.is_new_model:
|
if self.is_new_model:
|
||||||
if self.ps.get_battery_power_plugged() and self.ps.get_battery_allow_charging():
|
if self.ps.get_battery_power_plugged() and self.ps.get_battery_allow_charging():
|
||||||
ui._state._state['bat'].label = "CHG"
|
ui._state._state['bat'].label = "CHG"
|
||||||
ui.update(force=True, new_data={"status": "Power!! I can feel it!"})
|
ui.update(force=True, new_data={"status": "Power!! I can feel it!"})
|
||||||
ui._state._state['bat'].label = "BAT"
|
ui._state._state['bat'].label = "BAT"
|
||||||
|
|
||||||
|
# If rotation is enabled, cycle through voltage, percentage, and temp
|
||||||
|
if self.rotation_enabled:
|
||||||
if time.time() > self.nextDChg:
|
if time.time() > self.nextDChg:
|
||||||
self.drot = (self.drot + 1) % 3
|
self.drot = (self.drot + 1) % 3
|
||||||
self.nextDChg = time.time() + 5
|
self.nextDChg = time.time() + 5
|
||||||
@ -211,6 +231,15 @@ class PiSugar(plugins.Plugin):
|
|||||||
ui.set('bat', f"{capacity}%")
|
ui.set('bat', f"{capacity}%")
|
||||||
else: # show battery temperature
|
else: # show battery temperature
|
||||||
ui.set('bat', f"{temp}°C")
|
ui.set('bat', f"{temp}°C")
|
||||||
|
else:
|
||||||
|
# Rotation disabled, show only the selected default display
|
||||||
|
if self.default_display == 'voltage':
|
||||||
|
ui.set('bat', f"{voltage:.2f}V")
|
||||||
|
elif self.default_display in ['percentage', 'percent']:
|
||||||
|
ui.set('bat', f"{capacity}%")
|
||||||
|
elif self.default_display == 'temp':
|
||||||
|
ui.set('bat', f"{temp}°C")
|
||||||
|
|
||||||
if self.ps.get_battery_charging() is not None:
|
if self.ps.get_battery_charging() is not None:
|
||||||
if capacity <= self.ps.get_battery_safe_shutdown_level():
|
if capacity <= self.ps.get_battery_safe_shutdown_level():
|
||||||
logging.info(
|
logging.info(
|
||||||
|
Reference in New Issue
Block a user