diff --git a/src/buttontimer/buttontimer.cpp b/src/buttontimer/buttontimer.cpp index 2ca7c02..baa8831 100644 --- a/src/buttontimer/buttontimer.cpp +++ b/src/buttontimer/buttontimer.cpp @@ -111,8 +111,10 @@ void ButtonTimer::ThreadLoop() std::list longPressList; boost::optional valid; MutexLock(); + std::list 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) { diff --git a/src/mc-hid-server.cpp b/src/mc-hid-server.cpp index 410e226..329c90e 100644 --- a/src/mc-hid-server.cpp +++ b/src/mc-hid-server.cpp @@ -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)); } }