mirror of
https://github.com/meshtastic/firmware.git
synced 2025-12-30 14:40:40 +00:00
Finish config transition
This commit is contained in:
@@ -1,17 +1,14 @@
|
||||
#include "configuration.h"
|
||||
#include "RotaryEncoderInterruptBase.h"
|
||||
#include "configuration.h"
|
||||
|
||||
RotaryEncoderInterruptBase::RotaryEncoderInterruptBase(
|
||||
const char *name) :
|
||||
concurrency::OSThread(name)
|
||||
RotaryEncoderInterruptBase::RotaryEncoderInterruptBase(const char *name) : concurrency::OSThread(name)
|
||||
{
|
||||
this->_originName = name;
|
||||
}
|
||||
|
||||
void RotaryEncoderInterruptBase::init(
|
||||
uint8_t pinA, uint8_t pinB, uint8_t pinPress,
|
||||
char eventCw, char eventCcw, char eventPressed,
|
||||
// std::function<void(void)> onIntA, std::function<void(void)> onIntB, std::function<void(void)> onIntPress) :
|
||||
uint8_t pinA, uint8_t pinB, uint8_t pinPress, char eventCw, char eventCcw, char eventPressed,
|
||||
// std::function<void(void)> onIntA, std::function<void(void)> onIntB, std::function<void(void)> onIntPress) :
|
||||
void (*onIntA)(), void (*onIntB)(), void (*onIntPress)())
|
||||
{
|
||||
this->_pinA = pinA;
|
||||
@@ -24,42 +21,34 @@ void RotaryEncoderInterruptBase::init(
|
||||
pinMode(this->_pinA, INPUT_PULLUP);
|
||||
pinMode(this->_pinB, INPUT_PULLUP);
|
||||
|
||||
// attachInterrupt(pinPress, onIntPress, RISING);
|
||||
// attachInterrupt(pinPress, onIntPress, RISING);
|
||||
attachInterrupt(pinPress, onIntPress, RISING);
|
||||
attachInterrupt(this->_pinA, onIntA, CHANGE);
|
||||
attachInterrupt(this->_pinB, onIntB, CHANGE);
|
||||
|
||||
this->rotaryLevelA = digitalRead(this->_pinA);
|
||||
this->rotaryLevelB = digitalRead(this->_pinB);
|
||||
DEBUG_MSG("Rotary initialized (%d, %d, %d)\n",
|
||||
this->_pinA, this->_pinB, pinPress);
|
||||
DEBUG_MSG("Rotary initialized (%d, %d, %d)\n", this->_pinA, this->_pinB, pinPress);
|
||||
}
|
||||
|
||||
|
||||
int32_t RotaryEncoderInterruptBase::runOnce()
|
||||
{
|
||||
InputEvent e;
|
||||
e.inputEvent = InputEventChar_KEY_NONE;
|
||||
e.inputEvent = ModuleConfig_CannedMessageConfig_InputEventChar_KEY_NONE;
|
||||
e.source = this->_originName;
|
||||
|
||||
if (this->action == ROTARY_ACTION_PRESSED)
|
||||
{
|
||||
if (this->action == ROTARY_ACTION_PRESSED) {
|
||||
DEBUG_MSG("Rotary event Press\n");
|
||||
e.inputEvent = this->_eventPressed;
|
||||
}
|
||||
else if (this->action == ROTARY_ACTION_CW)
|
||||
{
|
||||
} else if (this->action == ROTARY_ACTION_CW) {
|
||||
DEBUG_MSG("Rotary event CW\n");
|
||||
e.inputEvent = this->_eventCw;
|
||||
}
|
||||
else if (this->action == ROTARY_ACTION_CCW)
|
||||
{
|
||||
} else if (this->action == ROTARY_ACTION_CCW) {
|
||||
DEBUG_MSG("Rotary event CCW\n");
|
||||
e.inputEvent = this->_eventCcw;
|
||||
}
|
||||
|
||||
if (e.inputEvent != InputEventChar_KEY_NONE)
|
||||
{
|
||||
if (e.inputEvent != ModuleConfig_CannedMessageConfig_InputEventChar_KEY_NONE) {
|
||||
this->notifyObservers(&e);
|
||||
}
|
||||
|
||||
@@ -68,7 +57,6 @@ int32_t RotaryEncoderInterruptBase::runOnce()
|
||||
return 30000; // TODO: technically this can be MAX_INT
|
||||
}
|
||||
|
||||
|
||||
void RotaryEncoderInterruptBase::intPressHandler()
|
||||
{
|
||||
this->action = ROTARY_ACTION_PRESSED;
|
||||
@@ -79,66 +67,47 @@ void RotaryEncoderInterruptBase::intAHandler()
|
||||
{
|
||||
// CW rotation (at least on most common rotary encoders)
|
||||
int currentLevelA = digitalRead(this->_pinA);
|
||||
if (this->rotaryLevelA == currentLevelA)
|
||||
{
|
||||
if (this->rotaryLevelA == currentLevelA) {
|
||||
return;
|
||||
}
|
||||
this->rotaryLevelA = currentLevelA;
|
||||
this->rotaryStateCCW = intHandler(
|
||||
currentLevelA == HIGH,
|
||||
this->rotaryLevelB,
|
||||
ROTARY_ACTION_CCW,
|
||||
this->rotaryStateCCW);
|
||||
this->rotaryStateCCW = intHandler(currentLevelA == HIGH, this->rotaryLevelB, ROTARY_ACTION_CCW, this->rotaryStateCCW);
|
||||
}
|
||||
|
||||
void RotaryEncoderInterruptBase::intBHandler()
|
||||
{
|
||||
// CW rotation (at least on most common rotary encoders)
|
||||
int currentLevelB = digitalRead(this->_pinB);
|
||||
if (this->rotaryLevelB == currentLevelB)
|
||||
{
|
||||
if (this->rotaryLevelB == currentLevelB) {
|
||||
return;
|
||||
}
|
||||
this->rotaryLevelB = currentLevelB;
|
||||
this->rotaryStateCW = intHandler(
|
||||
currentLevelB == HIGH,
|
||||
this->rotaryLevelA,
|
||||
ROTARY_ACTION_CW,
|
||||
this->rotaryStateCW);
|
||||
this->rotaryStateCW = intHandler(currentLevelB == HIGH, this->rotaryLevelA, ROTARY_ACTION_CW, this->rotaryStateCW);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Rotary action implementation.
|
||||
* We assume, the following pin setup:
|
||||
* A --||
|
||||
* GND --||]========
|
||||
* GND --||]========
|
||||
* B --||
|
||||
*
|
||||
*
|
||||
* @return The new state for rotary pin.
|
||||
*/
|
||||
RotaryEncoderInterruptBaseStateType RotaryEncoderInterruptBase::intHandler(
|
||||
bool actualPinRaising,
|
||||
int otherPinLevel,
|
||||
RotaryEncoderInterruptBaseActionType action,
|
||||
RotaryEncoderInterruptBaseStateType state)
|
||||
RotaryEncoderInterruptBaseStateType RotaryEncoderInterruptBase::intHandler(bool actualPinRaising, int otherPinLevel,
|
||||
RotaryEncoderInterruptBaseActionType action,
|
||||
RotaryEncoderInterruptBaseStateType state)
|
||||
{
|
||||
RotaryEncoderInterruptBaseStateType newState =
|
||||
state;
|
||||
if (actualPinRaising && (otherPinLevel == LOW))
|
||||
{
|
||||
if (state == ROTARY_EVENT_CLEARED)
|
||||
{
|
||||
RotaryEncoderInterruptBaseStateType newState = state;
|
||||
if (actualPinRaising && (otherPinLevel == LOW)) {
|
||||
if (state == ROTARY_EVENT_CLEARED) {
|
||||
newState = ROTARY_EVENT_OCCURRED;
|
||||
if ((this->action != ROTARY_ACTION_PRESSED)
|
||||
&& (this->action != action))
|
||||
{
|
||||
if ((this->action != ROTARY_ACTION_PRESSED) && (this->action != action)) {
|
||||
this->action = action;
|
||||
DEBUG_MSG("Rotary action\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (!actualPinRaising && (otherPinLevel == HIGH))
|
||||
{
|
||||
} else if (!actualPinRaising && (otherPinLevel == HIGH)) {
|
||||
// Logic to prevent bouncing.
|
||||
newState = ROTARY_EVENT_CLEARED;
|
||||
}
|
||||
|
||||
@@ -1,45 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include "SinglePortModule.h" // TODO: what header file to include?
|
||||
#include "InputBroker.h"
|
||||
#include "SinglePortModule.h" // TODO: what header file to include?
|
||||
|
||||
enum RotaryEncoderInterruptBaseStateType
|
||||
{
|
||||
ROTARY_EVENT_OCCURRED,
|
||||
ROTARY_EVENT_CLEARED
|
||||
};
|
||||
enum RotaryEncoderInterruptBaseStateType { ROTARY_EVENT_OCCURRED, ROTARY_EVENT_CLEARED };
|
||||
|
||||
enum RotaryEncoderInterruptBaseActionType
|
||||
{
|
||||
ROTARY_ACTION_NONE,
|
||||
ROTARY_ACTION_PRESSED,
|
||||
ROTARY_ACTION_CW,
|
||||
ROTARY_ACTION_CCW
|
||||
};
|
||||
enum RotaryEncoderInterruptBaseActionType { ROTARY_ACTION_NONE, ROTARY_ACTION_PRESSED, ROTARY_ACTION_CW, ROTARY_ACTION_CCW };
|
||||
|
||||
class RotaryEncoderInterruptBase :
|
||||
public Observable<const InputEvent *>,
|
||||
private concurrency::OSThread
|
||||
class RotaryEncoderInterruptBase : public Observable<const InputEvent *>, private concurrency::OSThread
|
||||
{
|
||||
public:
|
||||
explicit RotaryEncoderInterruptBase(
|
||||
const char *name);
|
||||
void init(
|
||||
uint8_t pinA, uint8_t pinB, uint8_t pinPress,
|
||||
char eventCw, char eventCcw, char eventPressed,
|
||||
// std::function<void(void)> onIntA, std::function<void(void)> onIntB, std::function<void(void)> onIntPress);
|
||||
void (*onIntA)(), void (*onIntB)(), void (*onIntPress)());
|
||||
explicit RotaryEncoderInterruptBase(const char *name);
|
||||
void init(uint8_t pinA, uint8_t pinB, uint8_t pinPress, char eventCw, char eventCcw, char eventPressed,
|
||||
// std::function<void(void)> onIntA, std::function<void(void)> onIntB, std::function<void(void)> onIntPress);
|
||||
void (*onIntA)(), void (*onIntB)(), void (*onIntPress)());
|
||||
void intPressHandler();
|
||||
void intAHandler();
|
||||
void intBHandler();
|
||||
|
||||
protected:
|
||||
virtual int32_t runOnce() override;
|
||||
RotaryEncoderInterruptBaseStateType intHandler(
|
||||
bool actualPinRaising,
|
||||
int otherPinLevel,
|
||||
RotaryEncoderInterruptBaseActionType action,
|
||||
RotaryEncoderInterruptBaseStateType state);
|
||||
RotaryEncoderInterruptBaseStateType intHandler(bool actualPinRaising, int otherPinLevel,
|
||||
RotaryEncoderInterruptBaseActionType action,
|
||||
RotaryEncoderInterruptBaseStateType state);
|
||||
|
||||
volatile RotaryEncoderInterruptBaseStateType rotaryStateCW = ROTARY_EVENT_CLEARED;
|
||||
volatile RotaryEncoderInterruptBaseStateType rotaryStateCCW = ROTARY_EVENT_CLEARED;
|
||||
@@ -50,8 +33,8 @@ class RotaryEncoderInterruptBase :
|
||||
private:
|
||||
uint8_t _pinA = 0;
|
||||
uint8_t _pinB = 0;
|
||||
char _eventCw = InputEventChar_KEY_NONE;
|
||||
char _eventCcw = InputEventChar_KEY_NONE;
|
||||
char _eventPressed = InputEventChar_KEY_NONE;
|
||||
char _eventCw = ModuleConfig_CannedMessageConfig_InputEventChar_KEY_NONE;
|
||||
char _eventCcw = ModuleConfig_CannedMessageConfig_InputEventChar_KEY_NONE;
|
||||
char _eventPressed = ModuleConfig_CannedMessageConfig_InputEventChar_KEY_NONE;
|
||||
const char *_originName;
|
||||
};
|
||||
|
||||
@@ -3,37 +3,26 @@
|
||||
|
||||
RotaryEncoderInterruptImpl1 *rotaryEncoderInterruptImpl1;
|
||||
|
||||
RotaryEncoderInterruptImpl1::RotaryEncoderInterruptImpl1() :
|
||||
RotaryEncoderInterruptBase(
|
||||
"rotEnc1")
|
||||
{
|
||||
}
|
||||
RotaryEncoderInterruptImpl1::RotaryEncoderInterruptImpl1() : RotaryEncoderInterruptBase("rotEnc1") {}
|
||||
|
||||
void RotaryEncoderInterruptImpl1::init()
|
||||
{
|
||||
if (!radioConfig.preferences.rotary1_enabled)
|
||||
{
|
||||
if (!moduleConfig.payloadVariant.canned_message.rotary1_enabled) {
|
||||
// Input device is disabled.
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t pinA = radioConfig.preferences.inputbroker_pin_a;
|
||||
uint8_t pinB = radioConfig.preferences.inputbroker_pin_b;
|
||||
uint8_t pinPress = radioConfig.preferences.inputbroker_pin_press;
|
||||
char eventCw =
|
||||
static_cast<char>(radioConfig.preferences.inputbroker_event_cw);
|
||||
char eventCcw =
|
||||
static_cast<char>(radioConfig.preferences.inputbroker_event_ccw);
|
||||
char eventPressed =
|
||||
static_cast<char>(radioConfig.preferences.inputbroker_event_press);
|
||||
uint8_t pinA = moduleConfig.payloadVariant.canned_message.inputbroker_pin_a;
|
||||
uint8_t pinB = moduleConfig.payloadVariant.canned_message.inputbroker_pin_b;
|
||||
uint8_t pinPress = moduleConfig.payloadVariant.canned_message.inputbroker_pin_press;
|
||||
char eventCw = static_cast<char>(moduleConfig.payloadVariant.canned_message.inputbroker_event_cw);
|
||||
char eventCcw = static_cast<char>(moduleConfig.payloadVariant.canned_message.inputbroker_event_ccw);
|
||||
char eventPressed = static_cast<char>(moduleConfig.payloadVariant.canned_message.inputbroker_event_press);
|
||||
|
||||
//radioConfig.preferences.ext_notification_module_output
|
||||
RotaryEncoderInterruptBase::init(
|
||||
pinA, pinB, pinPress,
|
||||
eventCw, eventCcw, eventPressed,
|
||||
RotaryEncoderInterruptImpl1::handleIntA,
|
||||
RotaryEncoderInterruptImpl1::handleIntB,
|
||||
RotaryEncoderInterruptImpl1::handleIntPressed);
|
||||
// moduleConfig.payloadVariant.canned_message.ext_notification_module_output
|
||||
RotaryEncoderInterruptBase::init(pinA, pinB, pinPress, eventCw, eventCcw, eventPressed,
|
||||
RotaryEncoderInterruptImpl1::handleIntA, RotaryEncoderInterruptImpl1::handleIntB,
|
||||
RotaryEncoderInterruptImpl1::handleIntPressed);
|
||||
inputBroker->registerSource(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,18 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "SinglePortModule.h" // TODO: what header file to include?
|
||||
#include "InputBroker.h"
|
||||
#include "SinglePortModule.h" // TODO: what header file to include?
|
||||
|
||||
class UpDownInterruptBase :
|
||||
public Observable<const InputEvent *>
|
||||
class UpDownInterruptBase : public Observable<const InputEvent *>
|
||||
{
|
||||
public:
|
||||
explicit UpDownInterruptBase(
|
||||
const char *name);
|
||||
void init(
|
||||
uint8_t pinDown, uint8_t pinUp, uint8_t pinPress,
|
||||
char eventDown, char eventUp, char eventPressed,
|
||||
void (*onIntDown)(), void (*onIntUp)(), void (*onIntPress)());
|
||||
explicit UpDownInterruptBase(const char *name);
|
||||
void init(uint8_t pinDown, uint8_t pinUp, uint8_t pinPress, char eventDown, char eventUp, char eventPressed,
|
||||
void (*onIntDown)(), void (*onIntUp)(), void (*onIntPress)());
|
||||
void intPressHandler();
|
||||
void intDownHandler();
|
||||
void intUpHandler();
|
||||
@@ -20,8 +16,8 @@ class UpDownInterruptBase :
|
||||
private:
|
||||
uint8_t _pinDown = 0;
|
||||
uint8_t _pinUp = 0;
|
||||
char _eventDown = InputEventChar_KEY_NONE;
|
||||
char _eventUp = InputEventChar_KEY_NONE;
|
||||
char _eventPressed = InputEventChar_KEY_NONE;
|
||||
char _eventDown = ModuleConfig_CannedMessageConfig_InputEventChar_KEY_NONE;
|
||||
char _eventUp = ModuleConfig_CannedMessageConfig_InputEventChar_KEY_NONE;
|
||||
char _eventPressed = ModuleConfig_CannedMessageConfig_InputEventChar_KEY_NONE;
|
||||
const char *_originName;
|
||||
};
|
||||
|
||||
@@ -3,38 +3,26 @@
|
||||
|
||||
UpDownInterruptImpl1 *upDownInterruptImpl1;
|
||||
|
||||
UpDownInterruptImpl1::UpDownInterruptImpl1() :
|
||||
UpDownInterruptBase(
|
||||
"upDown1")
|
||||
{
|
||||
}
|
||||
UpDownInterruptImpl1::UpDownInterruptImpl1() : UpDownInterruptBase("upDown1") {}
|
||||
|
||||
void UpDownInterruptImpl1::init()
|
||||
{
|
||||
|
||||
if (!radioConfig.preferences.updown1_enabled)
|
||||
{
|
||||
if (!moduleConfig.payloadVariant.canned_message.updown1_enabled) {
|
||||
// Input device is disabled.
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t pinUp = radioConfig.preferences.inputbroker_pin_a;
|
||||
uint8_t pinDown = radioConfig.preferences.inputbroker_pin_b;
|
||||
uint8_t pinPress = radioConfig.preferences.inputbroker_pin_press;
|
||||
uint8_t pinUp = moduleConfig.payloadVariant.canned_message.inputbroker_pin_a;
|
||||
uint8_t pinDown = moduleConfig.payloadVariant.canned_message.inputbroker_pin_b;
|
||||
uint8_t pinPress = moduleConfig.payloadVariant.canned_message.inputbroker_pin_press;
|
||||
|
||||
char eventDown =
|
||||
static_cast<char>(InputEventChar_KEY_DOWN);
|
||||
char eventUp =
|
||||
static_cast<char>(InputEventChar_KEY_UP);
|
||||
char eventPressed =
|
||||
static_cast<char>(InputEventChar_KEY_SELECT);
|
||||
char eventDown = static_cast<char>(ModuleConfig_CannedMessageConfig_InputEventChar_KEY_DOWN);
|
||||
char eventUp = static_cast<char>(ModuleConfig_CannedMessageConfig_InputEventChar_KEY_UP);
|
||||
char eventPressed = static_cast<char>(ModuleConfig_CannedMessageConfig_InputEventChar_KEY_SELECT);
|
||||
|
||||
UpDownInterruptBase::init(
|
||||
pinDown, pinUp, pinPress,
|
||||
eventDown, eventUp, eventPressed,
|
||||
UpDownInterruptImpl1::handleIntDown,
|
||||
UpDownInterruptImpl1::handleIntUp,
|
||||
UpDownInterruptImpl1::handleIntPressed);
|
||||
UpDownInterruptBase::init(pinDown, pinUp, pinPress, eventDown, eventUp, eventPressed, UpDownInterruptImpl1::handleIntDown,
|
||||
UpDownInterruptImpl1::handleIntUp, UpDownInterruptImpl1::handleIntPressed);
|
||||
inputBroker->registerSource(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "configuration.h"
|
||||
#include "kbI2cBase.h"
|
||||
#include "configuration.h"
|
||||
#include <Wire.h>
|
||||
|
||||
KbI2cBase::KbI2cBase(const char *name) : concurrency::OSThread(name)
|
||||
@@ -10,40 +10,39 @@ KbI2cBase::KbI2cBase(const char *name) : concurrency::OSThread(name)
|
||||
int32_t KbI2cBase::runOnce()
|
||||
{
|
||||
InputEvent e;
|
||||
e.inputEvent = InputEventChar_KEY_NONE;
|
||||
e.inputEvent = ModuleConfig_CannedMessageConfig_InputEventChar_KEY_NONE;
|
||||
e.source = this->_originName;
|
||||
|
||||
Wire.requestFrom(CARDKB_ADDR, 1);
|
||||
|
||||
while(Wire.available()) {
|
||||
|
||||
while (Wire.available()) {
|
||||
char c = Wire.read();
|
||||
switch(c) {
|
||||
switch (c) {
|
||||
case 0x1b: // ESC
|
||||
e.inputEvent = InputEventChar_KEY_CANCEL;
|
||||
e.inputEvent = ModuleConfig_CannedMessageConfig_InputEventChar_KEY_CANCEL;
|
||||
break;
|
||||
case 0x08: // Back
|
||||
e.inputEvent = InputEventChar_KEY_BACK;
|
||||
e.inputEvent = ModuleConfig_CannedMessageConfig_InputEventChar_KEY_BACK;
|
||||
break;
|
||||
case 0xb5: // Up
|
||||
e.inputEvent = InputEventChar_KEY_UP;
|
||||
e.inputEvent = ModuleConfig_CannedMessageConfig_InputEventChar_KEY_UP;
|
||||
break;
|
||||
case 0xb6: // Down
|
||||
e.inputEvent = InputEventChar_KEY_DOWN;
|
||||
e.inputEvent = ModuleConfig_CannedMessageConfig_InputEventChar_KEY_DOWN;
|
||||
break;
|
||||
case 0xb4: // Left
|
||||
e.inputEvent = InputEventChar_KEY_LEFT;
|
||||
e.inputEvent = ModuleConfig_CannedMessageConfig_InputEventChar_KEY_LEFT;
|
||||
break;
|
||||
case 0xb7: // Right
|
||||
e.inputEvent = InputEventChar_KEY_RIGHT;
|
||||
e.inputEvent = ModuleConfig_CannedMessageConfig_InputEventChar_KEY_RIGHT;
|
||||
break;
|
||||
case 0x0d: // Enter
|
||||
e.inputEvent = InputEventChar_KEY_SELECT;
|
||||
e.inputEvent = ModuleConfig_CannedMessageConfig_InputEventChar_KEY_SELECT;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (e.inputEvent != InputEventChar_KEY_NONE)
|
||||
{
|
||||
if (e.inputEvent != ModuleConfig_CannedMessageConfig_InputEventChar_KEY_NONE) {
|
||||
this->notifyObservers(&e);
|
||||
}
|
||||
return 500;
|
||||
|
||||
Reference in New Issue
Block a user