Skip to content

Commit a72a9ef

Browse files
committed
move set_ir_power to HARDWARE
1 parent 5683dfe commit a72a9ef

File tree

3 files changed

+23
-15
lines changed

3 files changed

+23
-15
lines changed

Diff for: selfdrive/pandad/panda/peripheral.py

+1-15
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,6 @@
1414
SATURATE_IL = 1000
1515

1616

17-
def set_ir_power(percent: int):
18-
if HARDWARE.get_device_type() in ("tici", "tizi"):
19-
return
20-
21-
clamped_percent = max(0, min(percent, 100))
22-
value = int((clamped_percent / 100) * 255) # Linear mapping from 0-100 to 0-255
23-
24-
# Write the value to the LED brightness files
25-
with open("/sys/class/leds/led:torch_2/brightness", "w") as f:
26-
f.write(f"{value}\n")
27-
with open("/sys/class/leds/led:switch_2/brightness", "w") as f:
28-
f.write(f"{value}\n")
29-
30-
3117
class HardwareReader:
3218
def __init__(self):
3319
self.voltage = 0
@@ -101,7 +87,7 @@ def process(self, sm):
10187
with self.lock:
10288
self.panda.set_ir_power(self.ir_pwr)
10389

104-
set_ir_power(self.ir_pwr)
90+
HARDWARE.set_ir_power(self.ir_pwr)
10591
self.prev_ir_pwr = self.ir_pwr
10692

10793
def send_state(self, pm):

Diff for: system/hardware/pc/hardware.py

+9
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ def get_imei(self, slot):
2626
def get_serial(self):
2727
return "cccccccc"
2828

29+
def get_voltage(self):
30+
return 0
31+
32+
def get_current(self):
33+
return 0
34+
35+
def set_ir_power(self, percent: int):
36+
pass
37+
2938
def get_network_info(self):
3039
return None
3140

Diff for: system/hardware/tici/hardware.py

+13
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,19 @@ def get_current(self):
142142
with open("/sys/class/hwmon/hwmon1/curr1_input") as f:
143143
return int(f.read())
144144

145+
def set_ir_power(self, percent: int):
146+
if self.get_device_type() in ("tici", "tizi"):
147+
return
148+
149+
clamped_percent = max(0, min(percent, 100))
150+
value = int((clamped_percent / 100) * 255) # Linear mapping from 0-100 to 0-255
151+
152+
# Write the value to the LED brightness files
153+
with open("/sys/class/leds/led:torch_2/brightness", "w") as f:
154+
f.write(f"{value}\n")
155+
with open("/sys/class/leds/led:switch_2/brightness", "w") as f:
156+
f.write(f"{value}\n")
157+
145158
def get_network_type(self):
146159
try:
147160
primary_connection = self.nm.Get(NM, 'PrimaryConnection', dbus_interface=DBUS_PROPS, timeout=TIMEOUT)

0 commit comments

Comments
 (0)