move from constructing keypress abstract with handler into setting the handler so that it can be set by the UI.
This commit is contained in:
parent
5ed9fcc3d0
commit
160114f54c
5 changed files with 19 additions and 15 deletions
|
@ -1,5 +1,8 @@
|
|||
#include "KeyPressAbstract.hpp"
|
||||
|
||||
KeyPressAbstract::KeyPressAbstract(
|
||||
std::function<bool(KeyPressAbstract::KeyEvent)> aKeyEventHandler)
|
||||
: mKeyEventHandler(std::move(aKeyEventHandler)) {}
|
||||
KeyPressAbstract::KeyPressAbstract() {}
|
||||
|
||||
void KeyPressAbstract::RegisterKeyPressHandler(
|
||||
std::function<bool(KeyPressAbstract::KeyEvent)> aKeyEventHandler) {
|
||||
mKeyEventHandler = std::move(aKeyEventHandler);
|
||||
}
|
|
@ -47,10 +47,12 @@ public:
|
|||
const KeyId mId;
|
||||
const Type mType;
|
||||
};
|
||||
/// @brief When Constructing pass a callable to be ran for Handling
|
||||
/// KeyEvents
|
||||
/// @param aKeyEventHandler
|
||||
KeyPressAbstract(std::function<bool(KeyEvent)> aKeyEventHandler);
|
||||
|
||||
KeyPressAbstract();
|
||||
|
||||
/// @brief Register a SINGLE handler to be used for proccessing keys
|
||||
/// @param aKeyEventHandler - Callable the Handles KeyEvent
|
||||
void RegisterKeyPressHandler(std::function<bool(KeyEvent)> aKeyEventHandler);
|
||||
|
||||
protected:
|
||||
/// @brief Function ment to be called regularly to allow
|
||||
|
|
|
@ -13,7 +13,7 @@ HardwareSimulator::HardwareSimulator()
|
|||
mBattery(std::make_shared<BatterySimulator>()),
|
||||
mDisplay(SDLDisplay::getInstance()),
|
||||
mWifiHandler(std::make_shared<wifiHandlerSim>()),
|
||||
mKeys(std::make_shared<KeyPressSim>([](auto keypress) { return true; })) {
|
||||
mKeys(std::make_shared<KeyPressSim>()) {
|
||||
mHardwareStatusTitleUpdate = std::thread([this] {
|
||||
int dataToShow = 0;
|
||||
while (true) {
|
||||
|
|
|
@ -3,9 +3,8 @@
|
|||
|
||||
#include <memory>
|
||||
|
||||
KeyPressSim::KeyPressSim(
|
||||
std::function<bool(KeyPressAbstract::KeyEvent)> aKeyHandler)
|
||||
: KeyPressAbstract(std::move(aKeyHandler)), mKeyGrabberThread([this] {
|
||||
KeyPressSim::KeyPressSim()
|
||||
: mKeyGrabberThread([this] {
|
||||
while (true) {
|
||||
HandleKeyPresses();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||
|
@ -35,9 +34,9 @@ void KeyPressSim::GrabKeys() {
|
|||
void KeyPressSim::HandleKeyPresses() {
|
||||
std::lock_guard lock(mQueueGaurd);
|
||||
while (!mKeyEventQueue.empty()) {
|
||||
printf(mKeyEventQueue.front().mType == KeyEvent::Type::Release ? "release"
|
||||
: "press");
|
||||
mKeyEventHandler(mKeyEventQueue.front());
|
||||
if (mKeyEventHandler) {
|
||||
mKeyEventHandler(mKeyEventQueue.front());
|
||||
}
|
||||
mKeyEventQueue.pop();
|
||||
}
|
||||
};
|
||||
|
|
|
@ -10,7 +10,7 @@ class KeyPressSim : public KeyPressAbstract {
|
|||
public:
|
||||
static constexpr auto MaxQueueableKeyEvents = 3;
|
||||
|
||||
KeyPressSim(std::function<bool(KeyPressAbstract::KeyEvent)> aKeyHandler);
|
||||
KeyPressSim();
|
||||
|
||||
void GrabKeys();
|
||||
void HandleKeyPresses() override;
|
||||
|
|
Loading…
Add table
Reference in a new issue