diff --git a/include/gamepad/controller.hpp b/include/gamepad/controller.hpp index 858a45c..b4ef6f4 100644 --- a/include/gamepad/controller.hpp +++ b/include/gamepad/controller.hpp @@ -42,6 +42,7 @@ class Button { uint32_t last_update_time = pros::millis(); mutable EventHandler<> onPressEvent {}; + uint32_t last_long_press_time = 0; mutable EventHandler<> onLongPressEvent {}; mutable EventHandler<> onReleaseEvent {}; }; diff --git a/src/gamepad/controller.cpp b/src/gamepad/controller.cpp index 33e1412..0ab9851 100644 --- a/src/gamepad/controller.cpp +++ b/src/gamepad/controller.cpp @@ -46,9 +46,11 @@ void Button::update(const bool is_held) { if (this->rising_edge) { this->onPressEvent.fire(); - } else if (this->is_pressed && this->time_held >= this->long_press_threshold) { + } else if (this->is_pressed && this->time_held >= this->long_press_threshold && + this->last_long_press_time > pros::millis() - this->time_held) { TODO("change onLongPress handling if onPress is present") this->onLongPressEvent.fire(); + this->last_long_press_time = pros::millis(); } else if (this->falling_edge) { this->onReleaseEvent.fire(); }