Added Button up/down evts. Fixed crash on release
This commit is contained in:
parent
29954007e8
commit
411b0ef71a
|
@ -111,8 +111,10 @@ void ButtonTimer::ThreadLoop()
|
|||
std::list<uint8_t> longPressList;
|
||||
boost::optional<bool> valid;
|
||||
MutexLock();
|
||||
std::list<uint8_t> removeList;
|
||||
// list through all the items
|
||||
|
||||
//FIXED: Do not alter press registry while iterating through it - that causes segfaults
|
||||
for( auto const& itm : pressRegistry)
|
||||
{
|
||||
if(now - (itm.second) >= shortpressMinTime && pressState[itm.first] == false) // if the shortpresstime wa exceeded and the value is false
|
||||
|
@ -123,8 +125,9 @@ void ButtonTimer::ThreadLoop()
|
|||
}
|
||||
else if(pressHold[itm.first] == false)
|
||||
{
|
||||
removeList.push_back(itm.first);
|
||||
// release debounce lock from longpress
|
||||
pressRegistry.erase(itm.first);
|
||||
// pressRegistry.erase(itm.first); will be done later
|
||||
pressHold.erase(itm.first);
|
||||
}
|
||||
}
|
||||
|
@ -135,6 +138,12 @@ void ButtonTimer::ThreadLoop()
|
|||
}
|
||||
|
||||
}
|
||||
// remove all items slated for removal from the pressRegistry
|
||||
for( auto const& gpio: removeList)
|
||||
{
|
||||
pressRegistry.erase(gpio);
|
||||
}
|
||||
|
||||
|
||||
for (auto const& gpio : shortPressList)
|
||||
{
|
||||
|
|
|
@ -222,12 +222,14 @@ void HidServer::onBtChange(uint8_t gpio, GpioEdge edge, bool level)
|
|||
{
|
||||
if(edge == GpioEdge::Rising){
|
||||
this->btnTimer->RegisterPress((uint8_t)gpio);
|
||||
// clog << kLogDebug << " (Button down : " << getBtnName((uint8_t)gpio) << ")" << endl;
|
||||
clog << kLogDebug << " (Button down : " << getBtnName((uint8_t)gpio) << ")" << endl;
|
||||
ButtonDown(getBtnName(gpio));
|
||||
}
|
||||
else
|
||||
{
|
||||
this->btnTimer->RegisterRelease((uint8_t)gpio);
|
||||
// clog << kLogDebug << " (Button up : " << getBtnName((uint8_t)gpio) << ")" << endl;
|
||||
clog << kLogDebug << " (Button up : " << getBtnName((uint8_t)gpio) << ")" << endl;
|
||||
ButtonUp(getBtnName(gpio));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user