mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-06-23 12:12:07 +08:00
@@ -169,13 +169,13 @@ class PowerMonitoring:
|
||||
return disable_charging
|
||||
|
||||
# See if we need to shutdown
|
||||
def should_shutdown(self, pandaState, offroad_timestamp, started_seen, LEON):
|
||||
def should_shutdown(self, pandaState, offroad_timestamp, started_seen):
|
||||
if pandaState is None or offroad_timestamp is None:
|
||||
return False
|
||||
|
||||
now = sec_since_boot()
|
||||
panda_charging = (pandaState.pandaState.usbPowerMode != log.PandaState.UsbPowerMode.client)
|
||||
BATT_PERC_OFF = 10 if LEON else 3
|
||||
BATT_PERC_OFF = 10
|
||||
|
||||
should_shutdown = False
|
||||
# Wait until we have shut down charging before powering down
|
||||
|
||||
@@ -38,9 +38,9 @@ DISCONNECT_TIMEOUT = 5. # wait 5 seconds before going offroad after disconnect
|
||||
|
||||
prev_offroad_states: Dict[str, Tuple[bool, Optional[str]]] = {}
|
||||
|
||||
LEON = False
|
||||
last_eon_fan_val = None
|
||||
|
||||
|
||||
def read_tz(x):
|
||||
if x is None:
|
||||
return 0
|
||||
@@ -63,44 +63,24 @@ def read_thermal(thermal_config):
|
||||
|
||||
|
||||
def setup_eon_fan():
|
||||
global LEON
|
||||
|
||||
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
|
||||
except IOError:
|
||||
print("LEON detected")
|
||||
LEON = True
|
||||
bus.close()
|
||||
|
||||
|
||||
def set_eon_fan(val):
|
||||
global LEON, last_eon_fan_val
|
||||
global last_eon_fan_val
|
||||
|
||||
if last_eon_fan_val is None or last_eon_fan_val != val:
|
||||
bus = SMBus(7, force=True)
|
||||
if LEON:
|
||||
try:
|
||||
i = [0x1, 0x3 | 0, 0x3 | 0x08, 0x3 | 0x10][val]
|
||||
bus.write_i2c_block_data(0x3d, 0, [i])
|
||||
except IOError:
|
||||
# tusb320
|
||||
if val == 0:
|
||||
bus.write_i2c_block_data(0x67, 0xa, [0])
|
||||
#bus.write_i2c_block_data(0x67, 0x45, [1<<2])
|
||||
else:
|
||||
#bus.write_i2c_block_data(0x67, 0x45, [0])
|
||||
bus.write_i2c_block_data(0x67, 0xa, [0x20])
|
||||
bus.write_i2c_block_data(0x67, 0x8, [(val - 1) << 6])
|
||||
else:
|
||||
bus.write_byte_data(0x21, 0x04, 0x2)
|
||||
bus.write_byte_data(0x21, 0x03, (val*2)+1)
|
||||
bus.write_byte_data(0x21, 0x04, 0x4)
|
||||
try:
|
||||
i = [0x1, 0x3 | 0, 0x3 | 0x08, 0x3 | 0x10][val]
|
||||
bus.write_i2c_block_data(0x3d, 0, [i])
|
||||
except IOError:
|
||||
# tusb320
|
||||
if val == 0:
|
||||
bus.write_i2c_block_data(0x67, 0xa, [0])
|
||||
else:
|
||||
bus.write_i2c_block_data(0x67, 0xa, [0x20])
|
||||
bus.write_i2c_block_data(0x67, 0x8, [(val - 1) << 6])
|
||||
bus.close()
|
||||
last_eon_fan_val = val
|
||||
|
||||
@@ -400,7 +380,7 @@ def thermald_thread():
|
||||
msg.deviceState.chargingDisabled = power_monitor.should_disable_charging(pandaState, off_ts)
|
||||
|
||||
# Check if we need to shut down
|
||||
if power_monitor.should_shutdown(pandaState, off_ts, started_seen, LEON):
|
||||
if power_monitor.should_shutdown(pandaState, off_ts, started_seen):
|
||||
cloudlog.info(f"shutting device down, offroad since {off_ts}")
|
||||
# TODO: add function for blocking cloudlog instead of sleep
|
||||
time.sleep(10)
|
||||
|
||||
Reference in New Issue
Block a user