Added Button up/down evts. Fixed crash on release

This commit is contained in:
P.M. Kuipers 2021-09-27 23:09:20 +02:00
parent 29954007e8
commit 411b0ef71a
2 changed files with 14 additions and 3 deletions

View File

@ -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)
{

View File

@ -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));
}
}