mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-08-22 00:33:48 +08:00
Move thermald hardware calls into HW abstraction layer (#2630)
* abstracted away hardware calls * oopsie * remove bugs * remove bugs #2 * fix unit test * removed print Co-authored-by: Comma Device <device@comma.ai>
This commit is contained in:
@@ -48,6 +48,30 @@ class Pc(HardwareBase):
|
||||
def get_network_strength(self, network_type):
|
||||
return NetworkStrength.unknown
|
||||
|
||||
def get_battery_capacity(self):
|
||||
return 100
|
||||
|
||||
def get_battery_status(self):
|
||||
return ""
|
||||
|
||||
def get_battery_current(self):
|
||||
return 0
|
||||
|
||||
def get_battery_voltage(self):
|
||||
return 0
|
||||
|
||||
def get_battery_charging(self):
|
||||
return True
|
||||
|
||||
def set_battery_charging(self, on):
|
||||
pass
|
||||
|
||||
def get_usb_present(self):
|
||||
return False
|
||||
|
||||
def get_current_power_draw(self):
|
||||
return 0
|
||||
|
||||
|
||||
if EON:
|
||||
HARDWARE = cast(HardwareBase, Android())
|
||||
|
||||
@@ -300,3 +300,32 @@ class Android(HardwareBase):
|
||||
network_strength = max(network_strength, ns)
|
||||
|
||||
return network_strength
|
||||
|
||||
def get_battery_capacity(self):
|
||||
return self.read_param_file("/sys/class/power_supply/battery/capacity", int, 100)
|
||||
|
||||
def get_battery_status(self):
|
||||
# This does not correspond with actual charging or not.
|
||||
# If a USB cable is plugged in, it responds with 'Charging', even when charging is disabled
|
||||
return self.read_param_file("/sys/class/power_supply/battery/status", lambda x: x.strip(), '')
|
||||
|
||||
def get_battery_current(self):
|
||||
return self.read_param_file("/sys/class/power_supply/battery/current_now", int)
|
||||
|
||||
def get_battery_voltage(self):
|
||||
return self.read_param_file("/sys/class/power_supply/battery/voltage_now", int)
|
||||
|
||||
def get_battery_charging(self):
|
||||
# This does correspond with actually charging
|
||||
return self.read_param_file("/sys/class/power_supply/battery/charge_type", lambda x: x.strip() != "N/A", True)
|
||||
|
||||
def set_battery_charging(self, on):
|
||||
with open('/sys/class/power_supply/battery/charging_enabled', 'w') as f:
|
||||
f.write(f"{1 if on else 0}\n")
|
||||
|
||||
def get_usb_present(self):
|
||||
return self.read_param_file("/sys/class/power_supply/usb/present", lambda x: bool(int(x)), False)
|
||||
|
||||
def get_current_power_draw(self):
|
||||
# We don't have a good direct way to measure this on android
|
||||
return None
|
||||
|
||||
@@ -8,6 +8,14 @@ class HardwareBase:
|
||||
cmdline = f.read()
|
||||
return {kv[0]: kv[1] for kv in [s.split('=') for s in cmdline.split(' ')] if len(kv) == 2}
|
||||
|
||||
@staticmethod
|
||||
def read_param_file(path, parser, default=0):
|
||||
try:
|
||||
with open(path) as f:
|
||||
return parser(f.read())
|
||||
except Exception:
|
||||
return default
|
||||
|
||||
@abstractmethod
|
||||
def get_sound_card_online(self):
|
||||
pass
|
||||
@@ -39,3 +47,35 @@ class HardwareBase:
|
||||
@abstractmethod
|
||||
def get_network_strength(self, network_type):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_battery_capacity(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_battery_status(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_battery_current(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_battery_voltage(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_battery_charging(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def set_battery_charging(self, on):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_usb_present(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_current_power_draw(self):
|
||||
pass
|
||||
|
||||
@@ -57,3 +57,29 @@ class Tici(HardwareBase):
|
||||
|
||||
def get_network_strength(self, network_type):
|
||||
return NetworkStrength.unknown
|
||||
|
||||
# We don't have a battery, so let's use some sane constants
|
||||
def get_battery_capacity(self):
|
||||
return 100
|
||||
|
||||
def get_battery_status(self):
|
||||
return ""
|
||||
|
||||
def get_battery_current(self):
|
||||
return 0
|
||||
|
||||
def get_battery_voltage(self):
|
||||
return 0
|
||||
|
||||
def get_battery_charging(self):
|
||||
return True
|
||||
|
||||
def set_battery_charging(self, on):
|
||||
pass
|
||||
|
||||
def get_usb_present(self):
|
||||
# Not sure if relevant on tici, but the file exists
|
||||
return self.read_param_file("/sys/class/power_supply/usb/present", lambda x: bool(int(x)), False)
|
||||
|
||||
def get_current_power_draw(self):
|
||||
return (self.read_param_file("/sys/class/hwmon/hwmon1/power1_input", int) / 1e6)
|
||||
|
||||
Reference in New Issue
Block a user