tici power saving (#20644)
* start power saving * set power save in thermald Co-authored-by: Comma Device <device@comma.ai>pull/20663/head
parent
4e06665f55
commit
b0bd123445
|
@ -105,3 +105,7 @@ class HardwareBase:
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def set_screen_brightness(self, percentage):
|
def set_screen_brightness(self, percentage):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def set_power_save(self, enabled):
|
||||||
|
pass
|
||||||
|
|
|
@ -352,3 +352,6 @@ class Android(HardwareBase):
|
||||||
def set_screen_brightness(self, percentage):
|
def set_screen_brightness(self, percentage):
|
||||||
with open("/sys/class/leds/lcd-backlight/brightness", "w") as f:
|
with open("/sys/class/leds/lcd-backlight/brightness", "w") as f:
|
||||||
f.write(str(int(percentage * 2.55)))
|
f.write(str(int(percentage * 2.55)))
|
||||||
|
|
||||||
|
def set_power_save(self, enabled):
|
||||||
|
pass
|
||||||
|
|
|
@ -79,3 +79,6 @@ class Pc(HardwareBase):
|
||||||
|
|
||||||
def set_screen_brightness(self, percentage):
|
def set_screen_brightness(self, percentage):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def set_power_save(self, enabled):
|
||||||
|
pass
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from smbus2 import SMBus
|
||||||
|
|
||||||
from cereal import log
|
from cereal import log
|
||||||
from selfdrive.hardware.base import HardwareBase, ThermalConfig
|
from selfdrive.hardware.base import HardwareBase, ThermalConfig
|
||||||
|
@ -27,6 +28,14 @@ NetworkStrength = log.DeviceState.NetworkStrength
|
||||||
MM_MODEM_ACCESS_TECHNOLOGY_UMTS = 1 << 5
|
MM_MODEM_ACCESS_TECHNOLOGY_UMTS = 1 << 5
|
||||||
MM_MODEM_ACCESS_TECHNOLOGY_LTE = 1 << 14
|
MM_MODEM_ACCESS_TECHNOLOGY_LTE = 1 << 14
|
||||||
|
|
||||||
|
AMP_I2C_BUS = 0
|
||||||
|
AMP_ADDRESS = 0x10
|
||||||
|
|
||||||
|
def write_amplifier_reg(reg, val, offset, mask):
|
||||||
|
with SMBus(AMP_I2C_BUS) as bus:
|
||||||
|
v = bus.read_byte_data(AMP_ADDRESS, reg, force=True)
|
||||||
|
v = (v & (~mask)) | ((val << offset) & mask)
|
||||||
|
bus.write_byte_data(AMP_ADDRESS, reg, v, force=True)
|
||||||
|
|
||||||
class Tici(HardwareBase):
|
class Tici(HardwareBase):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -191,3 +200,12 @@ class Tici(HardwareBase):
|
||||||
f.write(str(int(percentage * 10.23)))
|
f.write(str(int(percentage * 10.23)))
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def set_power_save(self, enabled):
|
||||||
|
# amplifier, 100mW at idle
|
||||||
|
write_amplifier_reg(0x51, 0b0 if enabled else 0b1, 7, 0b10000000)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
import sys
|
||||||
|
Tici().set_power_save(bool(int(sys.argv[1])))
|
||||||
|
|
|
@ -25,8 +25,6 @@ from selfdrive.version import get_git_branch, terms_version, training_version
|
||||||
|
|
||||||
FW_SIGNATURE = get_expected_signature()
|
FW_SIGNATURE = get_expected_signature()
|
||||||
|
|
||||||
DISABLE_LTE_ONROAD = os.path.exists("/persist/disable_lte_onroad") or TICI
|
|
||||||
|
|
||||||
ThermalStatus = log.DeviceState.ThermalStatus
|
ThermalStatus = log.DeviceState.ThermalStatus
|
||||||
NetworkType = log.DeviceState.NetworkType
|
NetworkType = log.DeviceState.NetworkType
|
||||||
NetworkStrength = log.DeviceState.NetworkStrength
|
NetworkStrength = log.DeviceState.NetworkStrength
|
||||||
|
@ -348,12 +346,14 @@ def thermald_thread():
|
||||||
|
|
||||||
# Handle offroad/onroad transition
|
# Handle offroad/onroad transition
|
||||||
should_start = all(startup_conditions.values())
|
should_start = all(startup_conditions.values())
|
||||||
if should_start:
|
if should_start != should_start_prev or (count == 0):
|
||||||
if not should_start_prev:
|
params.put_bool("IsOffroad", not should_start)
|
||||||
params.delete("IsOffroad")
|
HARDWARE.set_power_save(not should_start)
|
||||||
if TICI and DISABLE_LTE_ONROAD:
|
if TICI:
|
||||||
os.system("sudo systemctl stop --no-block lte")
|
fxn = "stop" if should_start else "start"
|
||||||
|
os.system(f"sudo systemctl {fxn} --no-block lte")
|
||||||
|
|
||||||
|
if should_start:
|
||||||
off_ts = None
|
off_ts = None
|
||||||
if started_ts is None:
|
if started_ts is None:
|
||||||
started_ts = sec_since_boot()
|
started_ts = sec_since_boot()
|
||||||
|
@ -362,11 +362,6 @@ def thermald_thread():
|
||||||
if startup_conditions["ignition"] and (startup_conditions != startup_conditions_prev):
|
if startup_conditions["ignition"] and (startup_conditions != startup_conditions_prev):
|
||||||
cloudlog.event("Startup blocked", startup_conditions=startup_conditions)
|
cloudlog.event("Startup blocked", startup_conditions=startup_conditions)
|
||||||
|
|
||||||
if should_start_prev or (count == 0):
|
|
||||||
params.put_bool("IsOffroad", True)
|
|
||||||
if TICI and DISABLE_LTE_ONROAD:
|
|
||||||
os.system("sudo systemctl start --no-block lte")
|
|
||||||
|
|
||||||
started_ts = None
|
started_ts = None
|
||||||
if off_ts is None:
|
if off_ts is None:
|
||||||
off_ts = sec_since_boot()
|
off_ts = sec_since_boot()
|
||||||
|
|
Loading…
Reference in New Issue