diff --git a/sunnypilot/controls/lib/custom_stock_longitudinal_controller/controllers.py b/sunnypilot/controls/lib/custom_stock_longitudinal_controller/controllers.py index 7b6a30ccc4..c2656db49a 100644 --- a/sunnypilot/controls/lib/custom_stock_longitudinal_controller/controllers.py +++ b/sunnypilot/controls/lib/custom_stock_longitudinal_controller/controllers.py @@ -41,6 +41,7 @@ class CustomStockLongitudinalControllerBase(ABC): self.m_tsc = 0 self.is_ready = False + self.is_ready_prev = False self.cruise_button = None self.speed = 0 self.speed_steady = 0 @@ -106,6 +107,8 @@ class CustomStockLongitudinalControllerBase(ABC): self.cruise_button = self.button_states[self.button_state](self) + self.is_ready_prev = self.is_ready + def update(self, CS: car.CarState, CC: car.CarControl) -> list[SendCan]: can_sends = [] diff --git a/sunnypilot/controls/lib/custom_stock_longitudinal_controller/states.py b/sunnypilot/controls/lib/custom_stock_longitudinal_controller/states.py index 6caef9556d..5cd246f794 100644 --- a/sunnypilot/controls/lib/custom_stock_longitudinal_controller/states.py +++ b/sunnypilot/controls/lib/custom_stock_longitudinal_controller/states.py @@ -15,9 +15,9 @@ class ButtonStateBase(ABC): self.timer = INACTIVE_TIMER def __call__(self, controller) -> int | None: - if not controller.is_ready: - self.timer = INACTIVE_TIMER + if not controller.is_ready and controller.is_ready_prev: controller.button_state = ButtonControlState.inactive + return None return self.handle(controller) @@ -30,11 +30,12 @@ class InactiveState(ButtonStateBase): def handle(self, controller) -> None: self.button_count = 0 - if controller.is_ready: - if self.timer > 0: - self.timer -= 1 - else: - controller.button_state = ButtonControlState.loading + if not controller.is_ready: + self.timer = INACTIVE_TIMER + elif self.timer > 0: + self.timer -= 1 + else: + controller.button_state = ButtonControlState.loading return None