openpilot/scripts/get_fan_control_type.py
William aef01f4bdf
Shebang Fix (#1477)
* Shebang Fix

Per George's "I'd merge a PR replacing the 4 python3.7 with python3" on Discord. George updated Python to 3.8.2 for webcam tools, which broke manager from launching. Instead of chasing the exact version, it seems more reasonable to fall back to 3.

* More Python3.7's
2020-05-08 18:08:11 -07:00

42 lines
944 B
Python
Executable file

#!/usr/bin/env python3
import os
from smbus2 import SMBus
def setup_fan():
os.system("echo 2 > /sys/module/dwc3_msm/parameters/otg_switch")
bus = SMBus(7, force=True)
try:
bus.write_byte_data(0x21, 0x10, 0xf) # mask all interrupts
bus.write_byte_data(0x21, 0x03, 0x1) # set drive current and global interrupt disable
bus.write_byte_data(0x21, 0x02, 0x2) # needed?
bus.write_byte_data(0x21, 0x04, 0x4) # manual override source
print("OP detected")
return False
except IOError:
print("LEON detected")
return True
bus.close()
def get_fan_type():
if not setup_fan():
return
bus = SMBus(7, force=True)
try:
# alternate type
bus.write_i2c_block_data(0x3d, 0, [0x1])
print("Alternate type detected")
return
except IOError:
# tusb320 type
print("tusb320 type detected")
bus.close()
def main(gctx=None):
get_fan_type()
if __name__ == "__main__":
main()