mirror of
https://github.com/meshtastic/firmware.git
synced 2025-12-30 06:31:01 +00:00
Add CardKB, FACES and RAK14004 support to inputbroker/cannedmessages
This commit is contained in:
27
src/input/cardKbI2cImpl.cpp
Normal file
27
src/input/cardKbI2cImpl.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
#include "cardKbI2cImpl.h"
|
||||
#include "InputBroker.h"
|
||||
|
||||
CardKbI2cImpl *cardKbI2cImpl;
|
||||
|
||||
CardKbI2cImpl::CardKbI2cImpl() :
|
||||
KbI2cBase("cardKB")
|
||||
{
|
||||
}
|
||||
|
||||
void CardKbI2cImpl::init()
|
||||
{
|
||||
if (cardkb_found != CARDKB_ADDR)
|
||||
{
|
||||
// Input device is not detected.
|
||||
return;
|
||||
}
|
||||
|
||||
DEBUG_MSG("registerSource\n");
|
||||
inputBroker->registerSource(this);
|
||||
}
|
||||
|
||||
void CardKbI2cImpl::handlePressed()
|
||||
{
|
||||
DEBUG_MSG("handlePressed\n");
|
||||
cardKbI2cImpl->PressHandler();
|
||||
}
|
||||
21
src/input/cardKbI2cImpl.h
Normal file
21
src/input/cardKbI2cImpl.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
#include "kbI2cBase.h"
|
||||
#include "main.h"
|
||||
|
||||
/**
|
||||
* @brief The idea behind this class to have static methods for the event handlers.
|
||||
* Check attachInterrupt() at RotaryEncoderInteruptBase.cpp
|
||||
* Technically you can have as many rotary encoders hardver attached
|
||||
* to your device as you wish, but you always need to have separate event
|
||||
* handlers, thus you need to have a RotaryEncoderInterrupt implementation.
|
||||
*/
|
||||
class CardKbI2cImpl :
|
||||
public KbI2cBase
|
||||
{
|
||||
public:
|
||||
CardKbI2cImpl();
|
||||
void init();
|
||||
static void handlePressed();
|
||||
};
|
||||
|
||||
extern CardKbI2cImpl *cardKbI2cImpl;
|
||||
25
src/input/facesKbI2cImpl.cpp
Normal file
25
src/input/facesKbI2cImpl.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#include "facesKbI2cImpl.h"
|
||||
#include "InputBroker.h"
|
||||
|
||||
FacesKbI2cImpl *facesKbI2cImpl;
|
||||
|
||||
FacesKbI2cImpl::FacesKbI2cImpl() :
|
||||
KbI2cBase("facesKB")
|
||||
{
|
||||
}
|
||||
|
||||
void FacesKbI2cImpl::init()
|
||||
{
|
||||
if (faceskb_found != FACESKB_ADDR)
|
||||
{
|
||||
// Input device is not detected.
|
||||
return;
|
||||
}
|
||||
|
||||
inputBroker->registerSource(this);
|
||||
}
|
||||
|
||||
void FacesKbI2cImpl::handlePressed()
|
||||
{
|
||||
facesKbI2cImpl->PressHandler();
|
||||
}
|
||||
21
src/input/facesKbI2cImpl.h
Normal file
21
src/input/facesKbI2cImpl.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
#include "kbI2cBase.h"
|
||||
#include "main.h"
|
||||
|
||||
/**
|
||||
* @brief The idea behind this class to have static methods for the event handlers.
|
||||
* Check attachInterrupt() at RotaryEncoderInteruptBase.cpp
|
||||
* Technically you can have as many rotary encoders hardver attached
|
||||
* to your device as you wish, but you always need to have separate event
|
||||
* handlers, thus you need to have a RotaryEncoderInterrupt implementation.
|
||||
*/
|
||||
class FacesKbI2cImpl :
|
||||
public KbI2cBase
|
||||
{
|
||||
public:
|
||||
FacesKbI2cImpl();
|
||||
void init();
|
||||
static void handlePressed();
|
||||
};
|
||||
|
||||
extern FacesKbI2cImpl *facesKbI2cImpl;
|
||||
50
src/input/kbI2cBase.cpp
Normal file
50
src/input/kbI2cBase.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
#include "configuration.h"
|
||||
#include "kbI2cBase.h"
|
||||
#include <Wire.h>
|
||||
|
||||
KbI2cBase::KbI2cBase(const char *name) : concurrency::OSThread(name)
|
||||
{
|
||||
this->_originName = name;
|
||||
}
|
||||
|
||||
int32_t KbI2cBase::runOnce()
|
||||
{
|
||||
InputEvent e;
|
||||
e.inputEvent = InputEventChar_KEY_NONE;
|
||||
e.source = this->_originName;
|
||||
|
||||
Wire.requestFrom(CARDKB_ADDR, 1);
|
||||
|
||||
while(Wire.available()) {
|
||||
char c = Wire.read();
|
||||
switch(c) {
|
||||
case 0x1b: // ESC
|
||||
e.inputEvent = InputEventChar_KEY_CANCEL;
|
||||
break;
|
||||
case 0x08: // Back
|
||||
e.inputEvent = InputEventChar_KEY_BACK;
|
||||
break;
|
||||
case 0xb5: // Up
|
||||
e.inputEvent = InputEventChar_KEY_UP;
|
||||
break;
|
||||
case 0xb6: // Down
|
||||
e.inputEvent = InputEventChar_KEY_DOWN;
|
||||
break;
|
||||
case 0xb4: // Left
|
||||
e.inputEvent = InputEventChar_KEY_LEFT;
|
||||
break;
|
||||
case 0xb7: // Right
|
||||
e.inputEvent = InputEventChar_KEY_RIGHT;
|
||||
break;
|
||||
case 0x0d: // Enter
|
||||
e.inputEvent = InputEventChar_KEY_SELECT;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (e.inputEvent != InputEventChar_KEY_NONE)
|
||||
{
|
||||
this->notifyObservers(&e);
|
||||
}
|
||||
return 500;
|
||||
}
|
||||
19
src/input/kbI2cBase.h
Normal file
19
src/input/kbI2cBase.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include "SinglePortModule.h" // TODO: what header file to include?
|
||||
#include "InputBroker.h"
|
||||
|
||||
class KbI2cBase :
|
||||
public Observable<const InputEvent *>,
|
||||
private concurrency::OSThread
|
||||
{
|
||||
public:
|
||||
explicit KbI2cBase(const char *name);
|
||||
void PressHandler();
|
||||
|
||||
protected:
|
||||
virtual int32_t runOnce() override;
|
||||
|
||||
private:
|
||||
const char *_originName;
|
||||
};
|
||||
Reference in New Issue
Block a user