File tree Expand file tree Collapse file tree 3 files changed +19
-3
lines changed Expand file tree Collapse file tree 3 files changed +19
-3
lines changed Original file line number Diff line number Diff line change 55
66namespace xbot ::driver::input {
77
8- bool Input::Update (bool new_active) {
8+ bool Input::Update (bool new_active, uint32_t predate ) {
99 if (invert) {
1010 new_active = !new_active;
1111 }
1212 bool expected = !new_active;
1313 if (active.compare_exchange_strong (expected, new_active)) {
14- const uint32_t now = xbot::service::system::getTimeMicros ();
14+ const uint32_t now = xbot::service::system::getTimeMicros () - predate ;
1515 if (new_active) {
1616 active_since = now;
1717 }
@@ -22,6 +22,15 @@ bool Input::Update(bool new_active) {
2222 return false ;
2323}
2424
25+ void Input::InjectPress (bool long_press) {
26+ InjectPress (input_service.GetPressDelay (long_press));
27+ }
28+
29+ void Input::InjectPress (uint32_t duration) {
30+ Update (true , duration);
31+ Update (false );
32+ }
33+
2534void InputDriver::AddInput (Input* input) {
2635 if (inputs_head_ == nullptr ) {
2736 inputs_head_ = input;
Original file line number Diff line number Diff line change @@ -33,7 +33,10 @@ struct Input {
3333 return active;
3434 }
3535
36- bool Update (bool new_active);
36+ bool Update (bool new_active, uint32_t predate = 0 );
37+
38+ void InjectPress (bool long_press = false );
39+ void InjectPress (uint32_t duration);
3740
3841 uint32_t ActiveDuration (const uint32_t now) const {
3942 return now - active_since;
Original file line number Diff line number Diff line change @@ -32,6 +32,10 @@ class InputService : public InputServiceBase {
3232
3333 etl::pair<uint16_t , uint32_t > GetEmergencyReasons (uint32_t now);
3434
35+ uint32_t GetPressDelay (bool long_press = false ) {
36+ return long_press ? LongPressTime.value : DebounceTime.value ;
37+ }
38+
3539 private:
3640 MUTEX_DECL (mutex_);
3741
You can’t perform that action at this time.
0 commit comments