Update pisugarx.py

This commit is contained in:
铲屎将军
2025-02-10 18:26:52 +08:00
parent beb8308969
commit a00d94b520

View File

@ -71,7 +71,7 @@ class PiSugarServer:
self.lowpower_shutdown = False self.lowpower_shutdown = False
self.lowpower_shutdown_level = 10 self.lowpower_shutdown_level = 10
self.max_charge_voltage_protection = False self.max_charge_voltage_protection = False
self.max_protection_voltage=4 self.max_protection_level=80
# Start the device connection in a background thread # Start the device connection in a background thread
self.connection_thread = threading.Thread( self.connection_thread = threading.Thread(
target=self._connect_device, daemon=True) target=self._connect_device, daemon=True)
@ -163,8 +163,9 @@ class PiSugarServer:
self.power_plugged = (self.i2creg[0x55] & 0b00010000) != 0 self.power_plugged = (self.i2creg[0x55] & 0b00010000) != 0
if self.max_charge_voltage_protection: if self.max_charge_voltage_protection:
battery_voltage = self.battery_voltage self.voltage_history.append(self.battery_voltage)
if (battery_voltage) > self.max_protection_voltage: self.battery_level = self.convert_battery_voltage_to_level()
if (self.battery_level) > self.max_protection_level:
self.set_battery_notallow_charging() self.set_battery_notallow_charging()
else: else:
self.set_battery_allow_charging() self.set_battery_allow_charging()
@ -178,8 +179,9 @@ class PiSugarServer:
(((high & 0b00111111) << 8) + low) * 0.26855 + 2600.0)/1000 (((high & 0b00111111) << 8) + low) * 0.26855 + 2600.0)/1000
self.power_plugged = self.i2creg[0xdd] == 0x1f self.power_plugged = self.i2creg[0xdd] == 0x1f
if self.max_charge_voltage_protection: if self.max_charge_voltage_protection:
battery_voltage = self.battery_voltage self.voltage_history.append(self.battery_voltage)
if (battery_voltage) > self.max_protection_voltage: self.battery_level = self.convert_battery_voltage_to_level()
if (self.battery_level) > self.max_protection_level:
self.set_battery_notallow_charging() self.set_battery_notallow_charging()
else: else:
self.set_battery_allow_charging() self.set_battery_allow_charging()