mirror of
https://github.com/jayofelony/pwnagotchi.git
synced 2025-07-01 18:37:27 -04:00
Add new default plugin (pisugar2) and defaults.
Added new requirement to pyproject.toml to make it work.
This commit is contained in:
@ -76,6 +76,9 @@ main.plugins.onlinehashcrack.email = ""
|
||||
main.plugins.onlinehashcrack.dashboard = ""
|
||||
main.plugins.onlinehashcrack.single_files = false
|
||||
|
||||
main.plugins.pisugar2.enabled = false
|
||||
main.plugins.pisugar2.sync_rtc_on_boot = false
|
||||
|
||||
main.plugins.pisugar3.enabled = false
|
||||
main.plugins.pisugar3.shutdown = 5
|
||||
|
||||
|
95
pwnagotchi/plugins/default/pisugar2.py
Normal file
95
pwnagotchi/plugins/default/pisugar2.py
Normal file
@ -0,0 +1,95 @@
|
||||
# Gets status of Pisugar2 - requires installing the PiSugar-Power-Manager
|
||||
# curl http://cdn.pisugar.com/release/Pisugar-power-manager.sh | sudo bash
|
||||
#
|
||||
# based on https://github.com/evilsocket/pwnagotchi/blob/master/pwnagotchi/plugins/default/ups_lite.py
|
||||
# https://www.tindie.com/products/pisugar/pisugar2-battery-for-raspberry-pi-zero/
|
||||
import logging
|
||||
|
||||
from pwnagotchi.ui.components import LabeledValue
|
||||
from pwnagotchi.ui.view import BLACK
|
||||
import pwnagotchi.ui.fonts as fonts
|
||||
import pwnagotchi.plugins as plugins
|
||||
import pwnagotchi
|
||||
import time
|
||||
from pisugar import *
|
||||
|
||||
class PiSugar(plugins.Plugin):
|
||||
__author__ = "10230718+tisboyo@users.noreply.github.com"
|
||||
__version__ = "0.0.1"
|
||||
__license__ = "GPL3"
|
||||
__description__ = "A plugin that will add a voltage indicator for the PiSugar 2"
|
||||
|
||||
def __init__(self):
|
||||
self.is_charging = False
|
||||
self.is_new_model = False
|
||||
self.options = dict()
|
||||
conn, event_conn = connect_tcp()
|
||||
self.ps = PiSugarServer(conn, event_conn)
|
||||
|
||||
def on_loaded(self):
|
||||
# Load here so it doesn't attempt to load if the plugin is not enabled
|
||||
|
||||
logging.info("[pisugar2] plugin loaded.")
|
||||
|
||||
if self.ps.get_battery_led_amount.value == 2:
|
||||
self.is_new_model = True
|
||||
else:
|
||||
self.is_new_model = False
|
||||
|
||||
if self.options["sync_rtc_on_boot"]:
|
||||
self.ps.rtc_rtc2pi()
|
||||
|
||||
def on_ui_setup(self, ui):
|
||||
ui.add_element(
|
||||
"bat",
|
||||
LabeledValue(
|
||||
color=BLACK,
|
||||
label="BAT",
|
||||
value="0%",
|
||||
position=(ui.width() / 2 + 15, 0),
|
||||
label_font=fonts.Bold,
|
||||
text_font=fonts.Medium,
|
||||
),
|
||||
)
|
||||
# display charging status
|
||||
if self.is_new_model:
|
||||
ui.add_element(
|
||||
"chg",
|
||||
LabeledValue(
|
||||
color=BLACK,
|
||||
label="",
|
||||
value="",
|
||||
position=(ui.width() / 2 - 12, 0),
|
||||
label_font=fonts.Bold,
|
||||
text_font=fonts.Bold,
|
||||
),
|
||||
)
|
||||
|
||||
def on_unload(self, ui):
|
||||
with ui._lock:
|
||||
ui.remove_element("bat")
|
||||
ui.remove_element("chg")
|
||||
|
||||
def on_ui_update(self, ui):
|
||||
capacity = int(self.ps.get_battery_level())
|
||||
logging.info("BATT GET VALUE IS : " + str(capacity))
|
||||
# new model use battery_power_plugged & battery_allow_charging to detect real charging status
|
||||
if self.is_new_model:
|
||||
if self.ps.get_battery_power_plugged().value and self.ps.get_battery_allow_charging().value:
|
||||
ui.set("chg", "CHG")
|
||||
if not self.is_charging:
|
||||
ui.update(force=True, new_data={"status": "Power!! I can feel it!"})
|
||||
self.is_charging = True
|
||||
else:
|
||||
ui.set("chg", "")
|
||||
self.is_charging = False
|
||||
|
||||
ui.set("bat", str(capacity) + "%")
|
||||
|
||||
if capacity <= self.options["shutdown"]:
|
||||
logging.info(
|
||||
f"[pisugar2] Empty battery (<= {self.options['shutdown']}): shutting down"
|
||||
)
|
||||
ui.update(force=True, new_data={"status": "Battery exhausted, bye ..."})
|
||||
time.sleep(3)
|
||||
pwnagotchi.shutdown()
|
@ -9,7 +9,7 @@ dependencies = [
|
||||
"PyYAML", "dbus-python", "file-read-backwards", "flask", "flask-cors",
|
||||
"flask-wtf", "gast", "gpiozero", "inky", "numpy", "pycryptodome", "pydrive2", "python-dateutil",
|
||||
"requests", "rpi-lgpio", "rpi_hardware_pwm", "scapy", "setuptools", "shimmy", "smbus", "smbus2",
|
||||
"spidev", "toml", "tweepy", "websockets",
|
||||
"spidev", "toml", "tweepy", "websockets", "pisugar",
|
||||
]
|
||||
|
||||
requires-python = ">=3.11"
|
||||
|
Reference in New Issue
Block a user