|
5 | 5 |
|
6 | 6 | namespace xbot::driver::input { |
7 | 7 |
|
8 | | -bool Input::Update(bool new_active) { |
| 8 | +bool Input::Update(bool new_active, uint32_t predate) { |
9 | 9 | if (invert) { |
10 | 10 | new_active = !new_active; |
11 | 11 | } |
12 | 12 | bool expected = !new_active; |
13 | 13 | 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; |
15 | 15 | if (new_active) { |
16 | 16 | active_since = now; |
| 17 | + input_service.OnInputChanged(*this, true, 0); |
| 18 | + } else { |
| 19 | + const uint32_t duration = ActiveDuration(now); |
| 20 | + if (emergency_reason != 0 && duration >= emergency_delay_ms * 1'000) { |
| 21 | + emergency_pending = true; |
| 22 | + } |
| 23 | + input_service.OnInputChanged(*this, false, duration); |
17 | 24 | } |
18 | | - input_service.OnInputChanged(*this, new_active, ActiveDuration(now)); |
19 | 25 | chEvtBroadcastFlags(&mower_events, MowerEvents::INPUTS_CHANGED); |
20 | 26 | return true; |
21 | 27 | } |
22 | 28 | return false; |
23 | 29 | } |
24 | 30 |
|
| 31 | +bool Input::GetAndClearPendingEmergency() { |
| 32 | + bool only_if_pending = true; |
| 33 | + return emergency_pending.compare_exchange_strong(only_if_pending, false); |
| 34 | +} |
| 35 | + |
| 36 | +void Input::InjectPress(bool long_press) { |
| 37 | + InjectPress(input_service.GetPressDelay(long_press)); |
| 38 | +} |
| 39 | + |
| 40 | +void Input::InjectPress(uint32_t duration) { |
| 41 | + Update(true, duration); |
| 42 | + Update(false); |
| 43 | +} |
| 44 | + |
25 | 45 | void InputDriver::AddInput(Input* input) { |
26 | 46 | if (inputs_head_ == nullptr) { |
27 | 47 | inputs_head_ = input; |
|
0 commit comments