34 auto result = callbacks.insert({pin, {callback,
false, 0}});
40 std::bind(&ButtonHandler::periodicButtonValueCheck,
this, pin),
49 return callbacks.erase(pin) != 0;
56ButtonHandler::ButtonHandler()
62void ButtonHandler::periodicButtonValueCheck(miosix::GpioPin pin)
65 if (callbacks.find(pin) == callbacks.end())
70 bool& wasPressed = std::get<1>(callbacks[pin]);
71 unsigned int& pressedTicks = std::get<2>(callbacks[pin]);
76 const bool isNowPressed = !pin.value();
81 if (!wasPressed && callback)
90 if (pressedTicks >= VERY_LONG_PRESS_TICKS)
92 else if (pressedTicks >= LONG_PRESS_TICKS)
102 wasPressed = isNowPressed;
bool start() override
Start the thread associated with this active object.
void stop() override
Signals the runner thread to terminate and joins the thread.
size_t addTask(function_t function, uint32_t periodMs, Policy policy=Policy::RECOVER, int64_t startTick=Kernel::getOldTick())
Add a millisecond-period task function to the scheduler with an auto generated ID.
This file includes all the types the logdecoder script will decode.
@ PRESSED
The button is pressed.
@ LONG_PRESS
The button is released before VERY_LONG_PRESS_TICKS.
@ SHORT_PRESS
The button is released before LONG_PRESS_TICKS.
@ VERY_LONG_PRESS
The button is released after VERY_LONG_PRESS_TICKS.