mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-11-10 14:33:42 +08:00
80fbb4f6db
Register vehicle controls, planner modes, UI actions and Galaxy services after their providers exist. Wire the shared runtime entrypoints and cover their combined behavior. Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> Co-authored-by: Daniel Koepping <elkoled@gmail.com> Co-authored-by: Danny <dannyirwin31@yahoo.com> Co-authored-by: DimitriChrysafis <Dimitri.chrysafis@gmail.com> Co-authored-by: Dom <168790843+firestar5683@users.noreply.github.com> Co-authored-by: Harald Schäfer <harald.the.engineer@gmail.com> Co-authored-by: Kacper Rączy <gfw.kra@gmail.com> Co-authored-by: Prabhaav Pillai <prabhaav@msu.edu> Co-authored-by: dirwin31 <83434411+dirwin31@users.noreply.github.com> Co-authored-by: firestarsdog <229254897+firestarsdog@users.noreply.github.com> Co-authored-by: stef <19478336+stefpi@users.noreply.github.com> Co-authored-by: whoisdomi <dcantu83@gmail.com> Co-authored-by: Intelli <contact@intelli.software> Co-authored-by: haraschax <6804392+haraschax@users.noreply.github.com> Co-authored-by: prabhaavp <prabhaav@msu.edu>
44 lines
2.2 KiB
Python
44 lines
2.2 KiB
Python
from openpilot.common.hardware import HARDWARE
|
|
from openpilot.starpilot.favorites.actions import SET_SPEED, mapped_actions
|
|
from openpilot.starpilot.favorites.layout_actions import layout_actions
|
|
from openpilot.starpilot.favorites.owner import FavoritesOwner
|
|
from openpilot.starpilot.galaxy.settings import SettingsGateway
|
|
|
|
|
|
class FavoritesGateway:
|
|
def __init__(self, params, context=None):
|
|
self.settings = SettingsGateway(params, context)
|
|
self.owner = FavoritesOwner(params, self.actions, lambda: True)
|
|
|
|
def close(self):
|
|
self.settings.close()
|
|
|
|
def actions(self):
|
|
context = self.settings.context.sample()
|
|
actions = mapped_actions(lambda page: self.settings._state(page, context), lambda _request: False,
|
|
lambda: self.settings._state("appearance", context), lambda _request: False)
|
|
# Galaxy only assigns slots; the device's own profile decides which layout a toggle edits.
|
|
profile = "compact" if HARDWARE.get_device_type() == "mici" else "large"
|
|
actions.update(layout_actions(self.settings.params, profile, lambda: False))
|
|
return actions
|
|
|
|
def snapshot(self):
|
|
return project_snapshot(self.owner.snapshot())
|
|
|
|
def save(self, payload, *, session_valid):
|
|
if type(payload) is not dict or set(payload) != {"revision", "slots"}:
|
|
raise ValueError("Invalid Quick Select request")
|
|
return project_snapshot(self.owner.save(payload["slots"], payload["revision"], authorized=session_valid))
|
|
|
|
|
|
def project_snapshot(snapshot):
|
|
return {
|
|
"slots": [{"enabled": slot.enabled, "show_onroad": slot.show_onroad, "key": slot.key, "label": slot.label[:32],
|
|
**({"value": slot.value} if slot.key == SET_SPEED else {})} for slot in snapshot.slots],
|
|
"states": [{"index": slot.index, "kind": slot.kind, "stateLabel": slot.state_label,
|
|
"available": slot.available, "reason": slot.reason} for slot in snapshot.slots],
|
|
"options": [{"key": option.key, "label": option.label, "kind": option.kind, "section": option.section,
|
|
"stateLabel": option.state_label, "available": option.available, "reason": option.reason} for option in snapshot.options],
|
|
"revision": snapshot.revision, "editable": snapshot.configurable, "valid": snapshot.valid,
|
|
}
|