tici power saving (#20644)

* start power saving

* set power save in thermald

Co-authored-by: Comma Device <device@comma.ai>
albatross
Adeeb Shihadeh 2021-04-12 01:40:58 -07:00 committed by GitHub
parent 4e06665f55
commit b0bd123445
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 12 deletions

View File

@ -105,3 +105,7 @@ class HardwareBase:
@abstractmethod
def set_screen_brightness(self, percentage):
pass
@abstractmethod
def set_power_save(self, enabled):
pass

View File

@ -352,3 +352,6 @@ class Android(HardwareBase):
def set_screen_brightness(self, percentage):
with open("/sys/class/leds/lcd-backlight/brightness", "w") as f:
f.write(str(int(percentage * 2.55)))
def set_power_save(self, enabled):
pass

View File

@ -79,3 +79,6 @@ class Pc(HardwareBase):
def set_screen_brightness(self, percentage):
pass
def set_power_save(self, enabled):
pass

View File

@ -1,6 +1,7 @@
import os
import subprocess
from pathlib import Path
from smbus2 import SMBus
from cereal import log
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_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):
def __init__(self):
@ -191,3 +200,12 @@ class Tici(HardwareBase):
f.write(str(int(percentage * 10.23)))
except Exception:
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])))

View File

@ -25,8 +25,6 @@ from selfdrive.version import get_git_branch, terms_version, training_version
FW_SIGNATURE = get_expected_signature()
DISABLE_LTE_ONROAD = os.path.exists("/persist/disable_lte_onroad") or TICI
ThermalStatus = log.DeviceState.ThermalStatus
NetworkType = log.DeviceState.NetworkType
NetworkStrength = log.DeviceState.NetworkStrength
@ -348,12 +346,14 @@ def thermald_thread():
# Handle offroad/onroad transition
should_start = all(startup_conditions.values())
if should_start:
if not should_start_prev:
params.delete("IsOffroad")
if TICI and DISABLE_LTE_ONROAD:
os.system("sudo systemctl stop --no-block lte")
if should_start != should_start_prev or (count == 0):
params.put_bool("IsOffroad", not should_start)
HARDWARE.set_power_save(not should_start)
if TICI:
fxn = "stop" if should_start else "start"
os.system(f"sudo systemctl {fxn} --no-block lte")
if should_start:
off_ts = None
if started_ts is None:
started_ts = sec_since_boot()
@ -362,11 +362,6 @@ def thermald_thread():
if startup_conditions["ignition"] and (startup_conditions != startup_conditions_prev):
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
if off_ts is None:
off_ts = sec_since_boot()