Files
sunnypilot/common/gpio.py
Adeeb Shihadeh 59134c05d6 pandad: better handling of internal panda failures (#23755)
* reset internal panda

* recover

* internal dfu

Co-authored-by: Comma Device <device@comma.ai>
2022-04-26 11:02:40 -07:00

15 lines
470 B
Python

def gpio_init(pin: int, output: bool) -> None:
try:
with open(f"/sys/class/gpio/gpio{pin}/direction", 'wb') as f:
f.write(b"out" if output else b"in")
except Exception as e:
print(f"Failed to set gpio {pin} direction: {e}")
def gpio_set(pin: int, high: bool) -> None:
try:
with open(f"/sys/class/gpio/gpio{pin}/value", 'wb') as f:
f.write(b"1" if high else b"0")
except Exception as e:
print(f"Failed to set gpio {pin} value: {e}")