From a72a9ef8263b7da45c71d114a53f7b685b9d106a Mon Sep 17 00:00:00 2001 From: deanlee Date: Sat, 8 Mar 2025 03:25:13 +0800 Subject: [PATCH] move set_ir_power to HARDWARE --- selfdrive/pandad/panda/peripheral.py | 16 +--------------- system/hardware/pc/hardware.py | 9 +++++++++ system/hardware/tici/hardware.py | 13 +++++++++++++ 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/selfdrive/pandad/panda/peripheral.py b/selfdrive/pandad/panda/peripheral.py index 4647e52b9ca072..7b3e386d3f1cda 100644 --- a/selfdrive/pandad/panda/peripheral.py +++ b/selfdrive/pandad/panda/peripheral.py @@ -14,20 +14,6 @@ SATURATE_IL = 1000 -def set_ir_power(percent: int): - if HARDWARE.get_device_type() in ("tici", "tizi"): - return - - clamped_percent = max(0, min(percent, 100)) - value = int((clamped_percent / 100) * 255) # Linear mapping from 0-100 to 0-255 - - # Write the value to the LED brightness files - with open("/sys/class/leds/led:torch_2/brightness", "w") as f: - f.write(f"{value}\n") - with open("/sys/class/leds/led:switch_2/brightness", "w") as f: - f.write(f"{value}\n") - - class HardwareReader: def __init__(self): self.voltage = 0 @@ -101,7 +87,7 @@ def process(self, sm): with self.lock: self.panda.set_ir_power(self.ir_pwr) - set_ir_power(self.ir_pwr) + HARDWARE.set_ir_power(self.ir_pwr) self.prev_ir_pwr = self.ir_pwr def send_state(self, pm): diff --git a/system/hardware/pc/hardware.py b/system/hardware/pc/hardware.py index 017a449c90912c..d52424aaeb9533 100644 --- a/system/hardware/pc/hardware.py +++ b/system/hardware/pc/hardware.py @@ -26,6 +26,15 @@ def get_imei(self, slot): def get_serial(self): return "cccccccc" + def get_voltage(self): + return 0 + + def get_current(self): + return 0 + + def set_ir_power(self, percent: int): + pass + def get_network_info(self): return None diff --git a/system/hardware/tici/hardware.py b/system/hardware/tici/hardware.py index 96b1ab93a2dd30..cb0598f977e8da 100644 --- a/system/hardware/tici/hardware.py +++ b/system/hardware/tici/hardware.py @@ -142,6 +142,19 @@ def get_current(self): with open("/sys/class/hwmon/hwmon1/curr1_input") as f: return int(f.read()) + def set_ir_power(self, percent: int): + if self.get_device_type() in ("tici", "tizi"): + return + + clamped_percent = max(0, min(percent, 100)) + value = int((clamped_percent / 100) * 255) # Linear mapping from 0-100 to 0-255 + + # Write the value to the LED brightness files + with open("/sys/class/leds/led:torch_2/brightness", "w") as f: + f.write(f"{value}\n") + with open("/sys/class/leds/led:switch_2/brightness", "w") as f: + f.write(f"{value}\n") + def get_network_type(self): try: primary_connection = self.nm.Get(NM, 'PrimaryConnection', dbus_interface=DBUS_PROPS, timeout=TIMEOUT)