mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-11-08 13:33:42 +08:00
a82935f326
Integrate onroad views, configurable widgets, local settings, steering-profile contracts, Bluetooth and Android Auto with their device and runtime services. 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: Prabhaav Pillai <prabhaav@msu.edu> Co-authored-by: Shane Smiskol <shane@smiskol.com> 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: pharmacomaniac <blittle65@gmail.com> Co-authored-by: prabhaavp <prabhaav@msu.edu>
58 lines
1.9 KiB
Python
58 lines
1.9 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):
|
|
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)
|
|
self.service = ControllerService(self.owner, socket_path)
|
|
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:
|
|
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.
|
|
for press in presses:
|
|
self.owner.feed(press)
|
|
self.service.poll()
|
|
except Exception:
|
|
LOGGER.exception('Controller input stopped')
|
|
self.close()
|
|
|
|
def close(self):
|
|
if self._closed:
|
|
return
|
|
self._closed = True
|
|
try:
|
|
self.service.close()
|
|
finally:
|
|
try:
|
|
self.reader.close()
|
|
finally:
|
|
self.authority.close()
|