mirror of
https://github.com/meshtastic/firmware.git
synced 2025-04-28 10:42:08 +00:00
Use init() instead of constructor.
This commit is contained in:
parent
fbd5b8b721
commit
b832b82ec6
@ -33,7 +33,8 @@ void setupPlugins()
|
|||||||
new RemoteHardwarePlugin();
|
new RemoteHardwarePlugin();
|
||||||
new ReplyPlugin();
|
new ReplyPlugin();
|
||||||
rotaryEncoderInterruptImpl1 =
|
rotaryEncoderInterruptImpl1 =
|
||||||
new RotaryEncoderInterruptImpl1(
|
new RotaryEncoderInterruptImpl1();
|
||||||
|
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(rotaryEncoderInterruptImpl1);
|
||||||
|
@ -7,12 +7,17 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
RotaryEncoderInterruptBase::RotaryEncoderInterruptBase(
|
RotaryEncoderInterruptBase::RotaryEncoderInterruptBase(
|
||||||
const char *name,
|
const char *name) :
|
||||||
|
concurrency::OSThread(name)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void RotaryEncoderInterruptBase::init(
|
||||||
uint8_t pinA, uint8_t pinB, uint8_t pinPress,
|
uint8_t pinA, uint8_t pinB, uint8_t pinPress,
|
||||||
char eventCw, char eventCcw, char eventPressed,
|
char eventCw, char eventCcw, char eventPressed,
|
||||||
// std::function<void(void)> onIntA, std::function<void(void)> onIntB, std::function<void(void)> onIntPress) :
|
// std::function<void(void)> onIntA, std::function<void(void)> onIntB, std::function<void(void)> onIntPress) :
|
||||||
void (*onIntA)(), void (*onIntB)(), void (*onIntPress)()) :
|
void (*onIntA)(), void (*onIntB)(), void (*onIntPress)())
|
||||||
concurrency::OSThread(name)
|
|
||||||
{
|
{
|
||||||
this->_pinA = pinA;
|
this->_pinA = pinA;
|
||||||
this->_pinB = pinB;
|
this->_pinB = pinB;
|
||||||
@ -20,20 +25,22 @@ RotaryEncoderInterruptBase::RotaryEncoderInterruptBase(
|
|||||||
this->_eventCcw = eventCcw;
|
this->_eventCcw = eventCcw;
|
||||||
this->_eventPressed = eventPressed;
|
this->_eventPressed = eventPressed;
|
||||||
|
|
||||||
// TODO: make pins configurable
|
|
||||||
pinMode(pinPress, INPUT_PULLUP);
|
pinMode(pinPress, INPUT_PULLUP);
|
||||||
pinMode(this->_pinA, INPUT_PULLUP);
|
pinMode(this->_pinA, INPUT_PULLUP);
|
||||||
pinMode(this->_pinB, INPUT_PULLUP);
|
pinMode(this->_pinB, INPUT_PULLUP);
|
||||||
|
|
||||||
// attachInterrupt(pinPress, onIntPress, RISING);
|
// attachInterrupt(pinPress, onIntPress, RISING);
|
||||||
attachInterrupt(pinPress, onIntPress, RISING);
|
attachInterrupt(pinPress, onIntPress, RISING);
|
||||||
attachInterrupt(this->_pinA, onIntA, CHANGE);
|
attachInterrupt(this->_pinA, onIntA, CHANGE);
|
||||||
attachInterrupt(this->_pinB, onIntB, CHANGE);
|
attachInterrupt(this->_pinB, onIntB, CHANGE);
|
||||||
|
|
||||||
this->rotaryLevelA = digitalRead(this->_pinA);
|
this->rotaryLevelA = digitalRead(this->_pinA);
|
||||||
this->rotaryLevelB = digitalRead(this->_pinB);
|
this->rotaryLevelB = digitalRead(this->_pinB);
|
||||||
DEBUG_MSG("Rotary initialized (%d, %d, %d)\n",
|
DEBUG_MSG("Rotary initialized (%d, %d, %d)\n",
|
||||||
this->_pinA, this->_pinB, pinPress);
|
this->_pinA, this->_pinB, pinPress);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int32_t RotaryEncoderInterruptBase::runOnce()
|
int32_t RotaryEncoderInterruptBase::runOnce()
|
||||||
{
|
{
|
||||||
if (this->action == ROTARY_ACTION_PRESSED)
|
if (this->action == ROTARY_ACTION_PRESSED)
|
||||||
|
@ -24,7 +24,8 @@ class RotaryEncoderInterruptBase :
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RotaryEncoderInterruptBase(
|
RotaryEncoderInterruptBase(
|
||||||
const char *name,
|
const char *name);
|
||||||
|
void init(
|
||||||
uint8_t pinA, uint8_t pinB, uint8_t pinPress,
|
uint8_t pinA, uint8_t pinB, uint8_t pinPress,
|
||||||
char eventCw, char eventCcw, char eventPressed,
|
char eventCw, char eventCcw, char eventPressed,
|
||||||
// std::function<void(void)> onIntA, std::function<void(void)> onIntB, std::function<void(void)> onIntPress);
|
// std::function<void(void)> onIntA, std::function<void(void)> onIntB, std::function<void(void)> onIntPress);
|
||||||
|
@ -2,17 +2,22 @@
|
|||||||
|
|
||||||
RotaryEncoderInterruptImpl1 *rotaryEncoderInterruptImpl1;
|
RotaryEncoderInterruptImpl1 *rotaryEncoderInterruptImpl1;
|
||||||
|
|
||||||
RotaryEncoderInterruptImpl1::RotaryEncoderInterruptImpl1(
|
RotaryEncoderInterruptImpl1::RotaryEncoderInterruptImpl1() :
|
||||||
uint8_t pinA, uint8_t pinB, uint8_t pinPress,
|
|
||||||
char eventCw, char eventCcw, char eventPressed) :
|
|
||||||
RotaryEncoderInterruptBase(
|
RotaryEncoderInterruptBase(
|
||||||
"rotEnc1",
|
"rotEnc1")
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void RotaryEncoderInterruptImpl1::init(
|
||||||
|
uint8_t pinA, uint8_t pinB, uint8_t pinPress,
|
||||||
|
char eventCw, char eventCcw, char eventPressed)
|
||||||
|
{
|
||||||
|
RotaryEncoderInterruptBase::init(
|
||||||
pinA, pinB, pinPress,
|
pinA, pinB, pinPress,
|
||||||
eventCw, eventCcw, eventPressed,
|
eventCw, eventCcw, eventPressed,
|
||||||
RotaryEncoderInterruptImpl1::handleIntA,
|
RotaryEncoderInterruptImpl1::handleIntA,
|
||||||
RotaryEncoderInterruptImpl1::handleIntB,
|
RotaryEncoderInterruptImpl1::handleIntB,
|
||||||
RotaryEncoderInterruptImpl1::handleIntPressed)
|
RotaryEncoderInterruptImpl1::handleIntPressed);
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RotaryEncoderInterruptImpl1::handleIntA()
|
void RotaryEncoderInterruptImpl1::handleIntA()
|
||||||
|
@ -1,11 +1,19 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "RotaryEncoderInterruptBase.h"
|
#include "RotaryEncoderInterruptBase.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 RotaryEncoderInterruptImpl1 :
|
class RotaryEncoderInterruptImpl1 :
|
||||||
public RotaryEncoderInterruptBase
|
public RotaryEncoderInterruptBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RotaryEncoderInterruptImpl1(
|
RotaryEncoderInterruptImpl1();
|
||||||
|
void init(
|
||||||
uint8_t pinA, uint8_t pinB, uint8_t pinPress,
|
uint8_t pinA, uint8_t pinB, uint8_t pinPress,
|
||||||
char eventCw, char eventCcw, char eventPressed);
|
char eventCw, char eventCcw, char eventPressed);
|
||||||
static void handleIntA();
|
static void handleIntA();
|
||||||
|
Loading…
Reference in New Issue
Block a user