firmware/src/input/kbI2cBase.cpp

57 lines
1.7 KiB
C++
Raw Normal View History

#include "kbI2cBase.h"
2022-05-07 10:31:21 +00:00
#include "configuration.h"
#include <Wire.h>
extern uint8_t cardkb_found;
extern uint8_t faceskb_found;
KbI2cBase::KbI2cBase(const char *name) : concurrency::OSThread(name)
{
this->_originName = name;
}
int32_t KbI2cBase::runOnce()
{
if ((cardkb_found != CARDKB_ADDR) && (faceskb_found != CARDKB_ADDR)){
// Input device is not detected.
return INT32_MAX;
}
InputEvent e;
e.inputEvent = ModuleConfig_CannedMessageConfig_InputEventChar_NONE;
e.source = this->_originName;
Wire.requestFrom(CARDKB_ADDR, 1);
2022-05-07 10:31:21 +00:00
while (Wire.available()) {
char c = Wire.read();
2022-05-07 10:31:21 +00:00
switch (c) {
case 0x1b: // ESC
e.inputEvent = ModuleConfig_CannedMessageConfig_InputEventChar_CANCEL;
break;
case 0x08: // Back
e.inputEvent = ModuleConfig_CannedMessageConfig_InputEventChar_BACK;
break;
case 0xb5: // Up
e.inputEvent = ModuleConfig_CannedMessageConfig_InputEventChar_UP;
break;
case 0xb6: // Down
e.inputEvent = ModuleConfig_CannedMessageConfig_InputEventChar_DOWN;
break;
case 0xb4: // Left
e.inputEvent = ModuleConfig_CannedMessageConfig_InputEventChar_LEFT;
break;
case 0xb7: // Right
e.inputEvent = ModuleConfig_CannedMessageConfig_InputEventChar_RIGHT;
break;
case 0x0d: // Enter
e.inputEvent = ModuleConfig_CannedMessageConfig_InputEventChar_SELECT;
break;
}
}
if (e.inputEvent != ModuleConfig_CannedMessageConfig_InputEventChar_NONE) {
this->notifyObservers(&e);
}
return 500;
}