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