From a00d94b5205a36d4a12c1c0531c6c6392febbf5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=93=B2=E5=B1=8E=E5=B0=86=E5=86=9B?= <37292630+wlmh110@users.noreply.github.com> Date: Mon, 10 Feb 2025 18:26:52 +0800 Subject: [PATCH] Update pisugarx.py --- pwnagotchi/plugins/default/pisugarx.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pwnagotchi/plugins/default/pisugarx.py b/pwnagotchi/plugins/default/pisugarx.py index 9d1a797f..6f972fda 100644 --- a/pwnagotchi/plugins/default/pisugarx.py +++ b/pwnagotchi/plugins/default/pisugarx.py @@ -71,7 +71,7 @@ class PiSugarServer: self.lowpower_shutdown = False self.lowpower_shutdown_level = 10 self.max_charge_voltage_protection = False - self.max_protection_voltage=4 + self.max_protection_level=80 # Start the device connection in a background thread self.connection_thread = threading.Thread( target=self._connect_device, daemon=True) @@ -163,8 +163,9 @@ class PiSugarServer: self.power_plugged = (self.i2creg[0x55] & 0b00010000) != 0 if self.max_charge_voltage_protection: - battery_voltage = self.battery_voltage - if (battery_voltage) > self.max_protection_voltage: + self.voltage_history.append(self.battery_voltage) + self.battery_level = self.convert_battery_voltage_to_level() + if (self.battery_level) > self.max_protection_level: self.set_battery_notallow_charging() else: self.set_battery_allow_charging() @@ -178,8 +179,9 @@ class PiSugarServer: (((high & 0b00111111) << 8) + low) * 0.26855 + 2600.0)/1000 self.power_plugged = self.i2creg[0xdd] == 0x1f if self.max_charge_voltage_protection: - battery_voltage = self.battery_voltage - if (battery_voltage) > self.max_protection_voltage: + self.voltage_history.append(self.battery_voltage) + self.battery_level = self.convert_battery_voltage_to_level() + if (self.battery_level) > self.max_protection_level: self.set_battery_notallow_charging() else: self.set_battery_allow_charging()