mirror of
https://gitee.com/dashuaibran/jyker
synced 2025-11-04 13:29:41 +08:00
33 lines
655 B
C++
33 lines
655 B
C++
#include "button_base.h"
|
|
|
|
void ButtonBase::Tick(uint32_t _timeElapseMillis)
|
|
{
|
|
timer += _timeElapseMillis;
|
|
bool pinIO = ReadButtonPinIO(id);
|
|
|
|
if (lastPinIO != pinIO)
|
|
{
|
|
if (pinIO)
|
|
{
|
|
OnEventFunc(UP);
|
|
if (timer - pressTime > longPressTime)
|
|
OnEventFunc(LONG_PRESS);
|
|
else
|
|
OnEventFunc(CLICK);
|
|
} else
|
|
{
|
|
OnEventFunc(DOWN);
|
|
pressTime = timer;
|
|
}
|
|
|
|
lastPinIO = pinIO;
|
|
}
|
|
}
|
|
|
|
void ButtonBase::SetOnEventListener(void (* _callback)(Event))
|
|
{
|
|
lastPinIO = ReadButtonPinIO(id);
|
|
|
|
OnEventFunc = _callback;
|
|
}
|