the function

pull/26463/head
Shane Smiskol 3 years ago
parent bce5b81596
commit ad2c74a402
  1. 29
      selfdrive/car/__init__.py

@ -1,5 +1,6 @@
# functions common among cars # functions common among cars
import capnp import capnp
from typing import List, Optional
from cereal import car from cereal import car
from common.numpy_fast import clip from common.numpy_fast import clip
@ -20,16 +21,24 @@ def apply_hysteresis(val: float, val_steady: float, hyst_gap: float) -> float:
return val_steady return val_steady
def create_button_events(cur_but: int, prev_but: int, buttons_dict: Dict[int, capnp.lib.capnp._EnumModule], def create_button_events(cur_button: int, prev_button: int, buttons_dict: Dict[int, capnp.lib.capnp._EnumModule],
unpressed: int = 0) -> capnp.lib.capnp._DynamicStructBuilder: unpressed: int = 0, init: Optional[int] = None) -> List[capnp.lib.capnp._DynamicStructBuilder]:
if cur_but != unpressed: events = []
be = car.CarState.ButtonEvent(pressed=True) # initializing, don't add any events
but = cur_but # TODO: if it's possible to go from init to NOT unpressed, we want to check that as well
else: if (init is not None and prev_button == init) or cur_button == prev_button:
be = car.CarState.ButtonEvent(pressed=False) return events
but = prev_but
be.type = buttons_dict.get(but, ButtonType.unknown) if cur_button != prev_button:
return be for pressed, btn in ((False, prev_button), (True, cur_button)):
if btn == unpressed:
continue
be = car.CarState.ButtonEvent(pressed=pressed)
be.type = buttons_dict.get(btn, ButtonType.unknown)
events.append(be)
return events
def gen_empty_fingerprint(): def gen_empty_fingerprint():

Loading…
Cancel
Save