Skip to content

Commit

Permalink
move set_ir_power to HARDWARE
Browse files Browse the repository at this point in the history
  • Loading branch information
deanlee committed Mar 7, 2025
1 parent 5683dfe commit a72a9ef
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
16 changes: 1 addition & 15 deletions selfdrive/pandad/panda/peripheral.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
9 changes: 9 additions & 0 deletions system/hardware/pc/hardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 13 additions & 0 deletions system/hardware/tici/hardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a72a9ef

Please sign in to comment.