mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-12-02 07:13:40 +08:00
prep for mainline kernel (#39481)
This commit is contained in:
committed by
firestar5683
parent
79ccd9aa4b
commit
aa2b969c65
@@ -58,6 +58,27 @@ def get_default_route_iface():
|
||||
routes = [(int(route[6]), route[0]) for line in f.readlines()[1:] if (route := line.split())[1] == "00000000" and int(route[3], 16) & 0x1]
|
||||
return min(routes)[1] if routes else None
|
||||
|
||||
_hwmon: dict[str, tuple[Path | None, float]] = {}
|
||||
|
||||
|
||||
def hwmon(name: str) -> Path | None:
|
||||
"""Probe order can change sysfs indices between kernel versions."""
|
||||
now = time.monotonic()
|
||||
path, last_scan = _hwmon.get(name, (None, -10.0))
|
||||
if path is not None or now - last_scan < 10.0:
|
||||
return path
|
||||
for entry in sorted(Path('/sys/class/hwmon').glob('hwmon*/name')):
|
||||
try:
|
||||
if entry.read_text().strip() == name:
|
||||
path = entry.parent
|
||||
break
|
||||
except OSError:
|
||||
continue
|
||||
_hwmon[name] = (path, now)
|
||||
return path
|
||||
|
||||
|
||||
|
||||
class HardwareComma(HardwareBase):
|
||||
"""
|
||||
This platform covers the Snapdragon 845-based comma devices:
|
||||
@@ -101,11 +122,11 @@ class HardwareComma(HardwareBase):
|
||||
return self.get_cmdline()['androidboot.serialno']
|
||||
|
||||
def get_voltage(self):
|
||||
with open("/sys/class/hwmon/hwmon1/in1_input") as f:
|
||||
with open((hwmon('ina231') or Path('/sys/class/hwmon/hwmon1')) / 'in1_input') as f:
|
||||
return int(f.read())
|
||||
|
||||
def get_current(self):
|
||||
with open("/sys/class/hwmon/hwmon1/curr1_input") as f:
|
||||
with open((hwmon('ina231') or Path('/sys/class/hwmon/hwmon1')) / 'curr1_input') as f:
|
||||
return int(f.read())
|
||||
|
||||
def set_ir_power(self, percent: int):
|
||||
@@ -248,7 +269,7 @@ class HardwareComma(HardwareBase):
|
||||
return self.get_modem_state().get('temperatures', [])
|
||||
|
||||
def get_current_power_draw(self):
|
||||
return (self.read_param_file("/sys/class/hwmon/hwmon1/power1_input", int) / 1e6)
|
||||
return (self.read_param_file((hwmon('ina231') or Path('/sys/class/hwmon/hwmon1')) / 'power1_input', int) / 1e6)
|
||||
|
||||
def get_som_power_draw(self):
|
||||
return (self.read_param_file("/sys/class/power_supply/bms/voltage_now", int) * self.read_param_file("/sys/class/power_supply/bms/current_now", int) / 1e12)
|
||||
|
||||
Reference in New Issue
Block a user