mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-12-02 05:13:41 +08:00
f67edb6529
- The input worker never parsed its settings on an install where CarControlAssignments had never been saved, so no scroll, stalk press or nudge reached the comma until a Wheel Controls row was changed. It now starts from the defaults. - Saved assignments are used on either model: a Model 3 and a Model Y have the same controls. Before, a document saved on the other model gave no controls and locked every Wheel Controls row. - Speed sync no longer waits for the Tesla's own speed to change after unanswered requests once the comma's speed is on the other side of the Tesla's (the Tesla had been at its own lowest or highest set speed). - The UI restarts a stopped input worker after a wait that grows from 2 s to 30 s, instead of at most three times a drive. A first start that fails is retried on the same wait, not every frame. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
73 lines
2.6 KiB
Python
73 lines
2.6 KiB
Python
import logging
|
|
import time
|
|
|
|
from openpilot.starpilot.controllers.input import InputReader
|
|
from openpilot.starpilot.controllers.owner import ControllerOwner
|
|
from openpilot.starpilot.controllers.transport import ControllerService
|
|
from openpilot.starpilot.galaxy.settings import LiveContextSource
|
|
|
|
LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
class ControllerRuntime:
|
|
def __init__(self, params, *, actions, favorites, invoke_favorite, authority=None, reader=None, socket_path=None,
|
|
vehicle=lambda: None, messages=lambda: None, input_capture=lambda: None, speed_actions=None, keyed_actions=None):
|
|
self.authority = authority if authority is not None else LiveContextSource(params)
|
|
self.reader = reader if reader is not None else InputReader()
|
|
self.owner = ControllerOwner(params, parked=self.authority.parked, actions=actions, favorites=favorites,
|
|
invoke_favorite=invoke_favorite)
|
|
from openpilot.starpilot.controllers.tesla_receiver import TeslaReceiver
|
|
self.tesla = TeslaReceiver(params, actions, vehicle, messages=messages, speed_actions=speed_actions,
|
|
keyed_actions=keyed_actions)
|
|
self.service = ControllerService(self.owner, socket_path)
|
|
self.input_capture = input_capture
|
|
self._closed = False
|
|
self._next_warm = 0.0
|
|
self._warm_until = time.monotonic() + 2.0
|
|
try:
|
|
self.service.start()
|
|
except (OSError, RuntimeError):
|
|
LOGGER.exception('Controller input could not start')
|
|
self.close()
|
|
|
|
def poll(self):
|
|
if self._closed:
|
|
return
|
|
try:
|
|
self.tesla.poll()
|
|
except Exception:
|
|
LOGGER.exception('Tesla input stopped')
|
|
self.tesla.fail()
|
|
try:
|
|
now = time.monotonic()
|
|
if now >= self._next_warm:
|
|
self.authority.parked()
|
|
self._next_warm = now + (0.1 if now < self._warm_until else 1.0)
|
|
presses = self.reader.poll(time.monotonic_ns())
|
|
self.owner.set_devices(self.reader.devices())
|
|
self.owner.tick()
|
|
# Process input before configuration so queued presses cannot activate a new binding.
|
|
capture = self.input_capture()
|
|
for press in presses:
|
|
if capture is None:
|
|
self.owner.feed(press)
|
|
else:
|
|
self.owner.feed(press, capture=capture)
|
|
self.service.poll()
|
|
except Exception:
|
|
LOGGER.exception('Controller input stopped')
|
|
self.close()
|
|
|
|
def close(self):
|
|
if self._closed:
|
|
return
|
|
self._closed = True
|
|
self.tesla.close()
|
|
try:
|
|
self.service.close()
|
|
finally:
|
|
try:
|
|
self.reader.close()
|
|
finally:
|
|
self.authority.close()
|