mirror of
https://github.com/meshtastic/firmware.git
synced 2025-04-26 09:59:01 +00:00
Introduce InputBroker
This commit is contained in:
parent
b832b82ec6
commit
f5004a66a1
@ -1,22 +1,28 @@
|
||||
#include "configuration.h"
|
||||
#include "CannedMessagePlugin.h"
|
||||
#include "MeshService.h"
|
||||
#include "main.h"
|
||||
#include "input/InputBroker.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
CannedMessagePlugin *cannedMessagePlugin;
|
||||
|
||||
CannedMessagePlugin::CannedMessagePlugin(
|
||||
Observable<const InputEvent *> *input)
|
||||
CannedMessagePlugin::CannedMessagePlugin()
|
||||
: SinglePortPlugin("canned", PortNum_TEXT_MESSAGE_APP),
|
||||
concurrency::OSThread("CannedMessagePlugin")
|
||||
{
|
||||
this->inputObserver.observe(input);
|
||||
if (true) // if module enabled
|
||||
{
|
||||
this->inputObserver.observe(inputBroker);
|
||||
}
|
||||
}
|
||||
|
||||
int CannedMessagePlugin::handleInputEvent(const InputEvent *event)
|
||||
{
|
||||
if (false) // test event->origin
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
bool validEvent = false;
|
||||
if (event->inputEvent == INPUT_EVENT_UP)
|
||||
{
|
||||
|
@ -40,8 +40,7 @@ class CannedMessagePlugin :
|
||||
CallbackObserver<CannedMessagePlugin, const InputEvent *>(
|
||||
this, &CannedMessagePlugin::handleInputEvent);
|
||||
public:
|
||||
CannedMessagePlugin(
|
||||
Observable<const InputEvent *> *input);
|
||||
CannedMessagePlugin();
|
||||
String getCurrentMessage();
|
||||
String getPrevMessage();
|
||||
String getNextMessage();
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "plugins/RoutingPlugin.h"
|
||||
#include "plugins/AdminPlugin.h"
|
||||
#include "plugins/CannedMessagePlugin.h"
|
||||
#include "plugins/input/InputBroker.h"
|
||||
#include "plugins/input/RotaryEncoderInterruptImpl1.h"
|
||||
#ifndef NO_ESP32
|
||||
#include "plugins/esp32/SerialPlugin.h"
|
||||
@ -22,6 +23,7 @@
|
||||
*/
|
||||
void setupPlugins()
|
||||
{
|
||||
inputBroker = new InputBroker();
|
||||
adminPlugin = new AdminPlugin();
|
||||
nodeInfoPlugin = new NodeInfoPlugin();
|
||||
positionPlugin = new PositionPlugin();
|
||||
@ -37,7 +39,7 @@ void setupPlugins()
|
||||
rotaryEncoderInterruptImpl1->init(
|
||||
22, 23, 21,
|
||||
INPUT_EVENT_UP, INPUT_EVENT_DOWN, INPUT_EVENT_SELECT);
|
||||
cannedMessagePlugin = new CannedMessagePlugin(rotaryEncoderInterruptImpl1);
|
||||
cannedMessagePlugin = new CannedMessagePlugin();
|
||||
|
||||
#ifndef NO_ESP32
|
||||
// Only run on an esp32 based device.
|
||||
|
@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#define INPUT_EVENT_NULL 0
|
||||
#define INPUT_EVENT_UP 17
|
||||
#define INPUT_EVENT_DOWN 18
|
||||
#define INPUT_EVENT_LEFT 19
|
||||
@ -9,5 +10,6 @@
|
||||
#define INPUT_EVENT_CANCEL 24
|
||||
|
||||
typedef struct _InputEvent {
|
||||
const char* origin;
|
||||
char inputEvent;
|
||||
} InputEvent;
|
17
src/plugins/input/InputBroker.cpp
Normal file
17
src/plugins/input/InputBroker.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
#include "InputBroker.h"
|
||||
|
||||
InputBroker *inputBroker;
|
||||
|
||||
InputBroker::InputBroker()
|
||||
{
|
||||
};
|
||||
|
||||
void InputBroker::registerOrigin(Observable<const InputEvent *> *origin)
|
||||
{
|
||||
this->inputEventObserver.observe(origin);
|
||||
}
|
||||
|
||||
int InputBroker::handleInputEvent(const InputEvent *event)
|
||||
{
|
||||
this->notifyObservers(event);
|
||||
}
|
19
src/plugins/input/InputBroker.h
Normal file
19
src/plugins/input/InputBroker.h
Normal file
@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
#include "Observer.h"
|
||||
#include "HardwareInput.h"
|
||||
|
||||
class InputBroker :
|
||||
public Observable<const InputEvent *>
|
||||
{
|
||||
CallbackObserver<InputBroker, const InputEvent *> inputEventObserver =
|
||||
CallbackObserver<InputBroker, const InputEvent *>(this, &InputBroker::handleInputEvent);
|
||||
|
||||
public:
|
||||
InputBroker();
|
||||
void registerOrigin(Observable<const InputEvent *> *origin);
|
||||
|
||||
protected:
|
||||
int handleInputEvent(const InputEvent *event);
|
||||
};
|
||||
|
||||
extern InputBroker *inputBroker;
|
@ -10,7 +10,7 @@ RotaryEncoderInterruptBase::RotaryEncoderInterruptBase(
|
||||
const char *name) :
|
||||
concurrency::OSThread(name)
|
||||
{
|
||||
|
||||
this->_originName = name;
|
||||
}
|
||||
|
||||
void RotaryEncoderInterruptBase::init(
|
||||
@ -43,26 +43,31 @@ void RotaryEncoderInterruptBase::init(
|
||||
|
||||
int32_t RotaryEncoderInterruptBase::runOnce()
|
||||
{
|
||||
InputEvent e;
|
||||
e.inputEvent = INPUT_EVENT_NULL;
|
||||
e.origin = this->_originName;
|
||||
|
||||
if (this->action == ROTARY_ACTION_PRESSED)
|
||||
{
|
||||
InputEvent e;
|
||||
DEBUG_MSG("Rotary event Press\n");
|
||||
e.inputEvent = this->_eventPressed;
|
||||
this->notifyObservers(&e);
|
||||
}
|
||||
else if (this->action == ROTARY_ACTION_CW)
|
||||
{
|
||||
DEBUG_MSG("Rotary event CW\n");
|
||||
InputEvent e;
|
||||
e.inputEvent = this->_eventCw;
|
||||
this->notifyObservers(&e);
|
||||
}
|
||||
else if (this->action == ROTARY_ACTION_CCW)
|
||||
{
|
||||
DEBUG_MSG("Rotary event CW\n");
|
||||
InputEvent e;
|
||||
e.inputEvent = this->_eventCcw;
|
||||
}
|
||||
|
||||
if (e.inputEvent != INPUT_EVENT_NULL)
|
||||
{
|
||||
this->notifyObservers(&e);
|
||||
}
|
||||
|
||||
this->action = ROTARY_ACTION_NONE;
|
||||
|
||||
return 30000;
|
||||
|
@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
//#include <Arduino.h>
|
||||
//#include "Observer.h"
|
||||
#include "SinglePortPlugin.h"
|
||||
|
||||
#include "SinglePortPlugin.h" // TODO: what header file to include?
|
||||
#include "HardwareInput.h"
|
||||
|
||||
enum RotaryEncoderInterruptBaseStateType
|
||||
@ -48,4 +47,5 @@ class RotaryEncoderInterruptBase :
|
||||
char _eventCw;
|
||||
char _eventCcw;
|
||||
char _eventPressed;
|
||||
const char *_originName;
|
||||
};
|
@ -1,4 +1,5 @@
|
||||
#include "RotaryEncoderInterruptImpl1.h"
|
||||
#include "InputBroker.h"
|
||||
|
||||
RotaryEncoderInterruptImpl1 *rotaryEncoderInterruptImpl1;
|
||||
|
||||
@ -18,6 +19,7 @@ void RotaryEncoderInterruptImpl1::init(
|
||||
RotaryEncoderInterruptImpl1::handleIntA,
|
||||
RotaryEncoderInterruptImpl1::handleIntB,
|
||||
RotaryEncoderInterruptImpl1::handleIntPressed);
|
||||
inputBroker->registerOrigin(this);
|
||||
}
|
||||
|
||||
void RotaryEncoderInterruptImpl1::handleIntA()
|
||||
|
Loading…
Reference in New Issue
Block a user