mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-09-02 01:53:45 +08:00
Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d44645fc53 | |||
| 2f2692d515 | |||
| d7aa0f5002 | |||
| a763c93496 | |||
| cf0c41af96 | |||
| 34e35d49e1 | |||
| a5ec1b3f16 | |||
| b7c40b4c44 | |||
| 4033119fa0 | |||
| 7bb32de4b8 | |||
| 7419b2a0b0 | |||
| aa8a190f5a |
@@ -132,6 +132,7 @@ inline static std::unordered_map<std::string, ParamKeyAttributes> keys = {
|
|||||||
{"UptimeOnroad", {PERSISTENT, FLOAT, "0.0"}},
|
{"UptimeOnroad", {PERSISTENT, FLOAT, "0.0"}},
|
||||||
{"ChestnutActive", {CLEAR_ON_MANAGER_START | CLEAR_ON_OFFROAD_TRANSITION | CLEAR_ON_IGNITION_ON, BOOL}},
|
{"ChestnutActive", {CLEAR_ON_MANAGER_START | CLEAR_ON_OFFROAD_TRANSITION | CLEAR_ON_IGNITION_ON, BOOL}},
|
||||||
{"ChestnutLoading", {CLEAR_ON_MANAGER_START | CLEAR_ON_OFFROAD_TRANSITION | CLEAR_ON_IGNITION_ON, BOOL}},
|
{"ChestnutLoading", {CLEAR_ON_MANAGER_START | CLEAR_ON_OFFROAD_TRANSITION | CLEAR_ON_IGNITION_ON, BOOL}},
|
||||||
|
{"AuxPowerSave", {PERSISTENT | BACKUP, BOOL}},
|
||||||
{"Version", {PERSISTENT, STRING}},
|
{"Version", {PERSISTENT, STRING}},
|
||||||
|
|
||||||
// --- sunnypilot params --- //
|
// --- sunnypilot params --- //
|
||||||
|
|||||||
@@ -220,6 +220,7 @@ class UIState(UIStateSP):
|
|||||||
ChestnutState.UNCOMPILED if detected else ChestnutState.DISCONNECTED)
|
ChestnutState.UNCOMPILED if detected else ChestnutState.DISCONNECTED)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
self.chestnut_present = self.chestnut_present or detected
|
||||||
model_seen = self.sm.recv_frame["modelV2"] > self.started_frame
|
model_seen = self.sm.recv_frame["modelV2"] > self.started_frame
|
||||||
if not self.chestnut_present:
|
if not self.chestnut_present:
|
||||||
self.chestnut_state = ChestnutState.DISCONNECTED
|
self.chestnut_state = ChestnutState.DISCONNECTED
|
||||||
|
|||||||
@@ -1675,6 +1675,12 @@
|
|||||||
"widget": "toggle",
|
"widget": "toggle",
|
||||||
"title": "Onroad Uploads"
|
"title": "Onroad Uploads"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"key": "AuxPowerSave",
|
||||||
|
"widget": "toggle",
|
||||||
|
"title": "Disable Aux Port When Offroad",
|
||||||
|
"description": "Power off the aux USB-C port while offroad to save power. It powers back on automatically when you go onroad."
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"key": "MaxTimeOffroad",
|
"key": "MaxTimeOffroad",
|
||||||
"widget": "option",
|
"widget": "option",
|
||||||
|
|||||||
@@ -30,6 +30,10 @@ sections:
|
|||||||
- key: OnroadUploads
|
- key: OnroadUploads
|
||||||
widget: toggle
|
widget: toggle
|
||||||
title: Onroad Uploads
|
title: Onroad Uploads
|
||||||
|
- key: AuxPowerSave
|
||||||
|
widget: toggle
|
||||||
|
title: Disable Aux Port When Offroad
|
||||||
|
description: Power off the aux USB-C port while offroad to save power. It powers back on automatically when you go onroad.
|
||||||
- key: MaxTimeOffroad
|
- key: MaxTimeOffroad
|
||||||
widget: option
|
widget: option
|
||||||
title: Max Time Offroad
|
title: Max Time Offroad
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ from openpilot.selfdrive.selfdrived.alertmanager import set_offroad_alert
|
|||||||
from openpilot.common.hardware import HARDWARE, COMMA_HARDWARE
|
from openpilot.common.hardware import HARDWARE, COMMA_HARDWARE
|
||||||
from openpilot.common.basedir import BASEDIR
|
from openpilot.common.basedir import BASEDIR
|
||||||
from openpilot.common.hardware.usb import CHESTNUT_FW_VERSION, CHESTNUT_ROM_USB_IDS, CHESTNUT_USB_IDS, get_usb_state, get_usb_topology, set_usb_state
|
from openpilot.common.hardware.usb import CHESTNUT_FW_VERSION, CHESTNUT_ROM_USB_IDS, CHESTNUT_USB_IDS, get_usb_state, get_usb_topology, set_usb_state
|
||||||
|
from openpilot.system.hardware.chestnut.flash import VBUS_PATH
|
||||||
from openpilot.common.linux import LinuxSystemStats
|
from openpilot.common.linux import LinuxSystemStats
|
||||||
from openpilot.system.loggerd.config import get_available_percent
|
from openpilot.system.loggerd.config import get_available_percent
|
||||||
from openpilot.common.swaglog import cloudlog
|
from openpilot.common.swaglog import cloudlog
|
||||||
@@ -49,6 +50,10 @@ class Chestnut:
|
|||||||
self.attempts = 0
|
self.attempts = 0
|
||||||
self.last_attempt = 0.
|
self.last_attempt = 0.
|
||||||
self.flashed = False
|
self.flashed = False
|
||||||
|
self.vbus_on = None
|
||||||
|
self.params = Params()
|
||||||
|
self.powersave = False
|
||||||
|
self.last_offroad = None
|
||||||
|
|
||||||
def flash(self) -> None:
|
def flash(self) -> None:
|
||||||
ret = subprocess.run(["sudo", sys.executable, os.path.join(BASEDIR, "openpilot/system/hardware/chestnut/flash.py"), CHESTNUT_FW_VERSION],
|
ret = subprocess.run(["sudo", sys.executable, os.path.join(BASEDIR, "openpilot/system/hardware/chestnut/flash.py"), CHESTNUT_FW_VERSION],
|
||||||
@@ -56,9 +61,19 @@ class Chestnut:
|
|||||||
cloudlog.event("chestnut flash done", returncode=ret.returncode, output=ret.stdout[-1000:], error=ret.returncode != 0)
|
cloudlog.event("chestnut flash done", returncode=ret.returncode, output=ret.stdout[-1000:], error=ret.returncode != 0)
|
||||||
self.flashed = ret.returncode == 0
|
self.flashed = ret.returncode == 0
|
||||||
|
|
||||||
|
def set_vbus(self, on: bool) -> None:
|
||||||
|
if on == self.vbus_on:
|
||||||
|
return
|
||||||
|
subprocess.run(["sudo", "tee", VBUS_PATH], input=b"1" if on else b"0", stdout=subprocess.DEVNULL, check=False)
|
||||||
|
self.vbus_on = on
|
||||||
|
|
||||||
def update(self, offroad: bool, usb_state: list[dict]) -> None:
|
def update(self, offroad: bool, usb_state: list[dict]) -> None:
|
||||||
mismatch = any((d["vendorId"], d["productId"]) in CHESTNUT_USB_IDS + CHESTNUT_ROM_USB_IDS and
|
mismatch = any((d["vendorId"], d["productId"]) in CHESTNUT_USB_IDS + CHESTNUT_ROM_USB_IDS and
|
||||||
d["product"] != f"custom {CHESTNUT_FW_VERSION}-CLEAN" for d in usb_state)
|
d["product"] != f"custom {CHESTNUT_FW_VERSION}-CLEAN" for d in usb_state)
|
||||||
|
if offroad != self.last_offroad:
|
||||||
|
self.powersave = self.params.get_bool("AuxPowerSave")
|
||||||
|
self.last_offroad = offroad
|
||||||
|
self.set_vbus((not offroad or mismatch) or not self.powersave)
|
||||||
if not mismatch:
|
if not mismatch:
|
||||||
self.flashed = False
|
self.flashed = False
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user