Skip to content

Commit

Permalink
Merge pull request #1313 from meshtastic/1.2-fix-rotary-encoder
Browse files Browse the repository at this point in the history
Rotary Encoder Update
  • Loading branch information
caveman99 committed Mar 21, 2022
2 parents d81c1c0 + aca9524 commit e09aafa
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 5 deletions.
6 changes: 6 additions & 0 deletions src/PowerFSM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,12 @@ void PowerFSM_setup()
powerFSM.add_transition(&stateON, &stateSHUTDOWN, EVENT_SHUTDOWN, NULL, "Shutdown");
powerFSM.add_transition(&stateSERIAL, &stateSHUTDOWN, EVENT_SHUTDOWN, NULL, "Shutdown");

// Inputbroker
powerFSM.add_transition(&stateLS, &stateON, EVENT_INPUT, NULL, "Input Device");
powerFSM.add_transition(&stateNB, &stateON, EVENT_INPUT, NULL, "Input Device");
powerFSM.add_transition(&stateDARK, &stateON, EVENT_INPUT, NULL, "Input Device");
powerFSM.add_transition(&stateON, &stateON, EVENT_INPUT, NULL, "Input Device"); // restarts the sleep timer

powerFSM.add_transition(&stateDARK, &stateON, EVENT_BLUETOOTH_PAIR, NULL, "Bluetooth pairing");
powerFSM.add_transition(&stateON, &stateON, EVENT_BLUETOOTH_PAIR, NULL, "Bluetooth pairing");

Expand Down
1 change: 1 addition & 0 deletions src/PowerFSM.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define EVENT_POWER_DISCONNECTED 14
#define EVENT_FIRMWARE_UPDATE 15 // We just received a new firmware update packet from the phone
#define EVENT_SHUTDOWN 16 //force a full shutdown now (not just sleep)
#define EVENT_INPUT 17 // input broker wants something, we need to wake up and enable screen

extern Fsm powerFSM;
extern State statePOWER, stateSERIAL;
Expand Down
2 changes: 2 additions & 0 deletions src/input/InputBroker.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "InputBroker.h"
#include "PowerFSM.h" // needed for event trigger

InputBroker *inputBroker;

Expand All @@ -13,6 +14,7 @@ void InputBroker::registerSource(Observable<const InputEvent *> *source)

int InputBroker::handleInputEvent(const InputEvent *event)
{
powerFSM.trigger(EVENT_INPUT);
this->notifyObservers(event);
return 0;
}
4 changes: 2 additions & 2 deletions src/input/RotaryEncoderInterruptBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ int32_t RotaryEncoderInterruptBase::runOnce()
}
else if (this->action == ROTARY_ACTION_CCW)
{
DEBUG_MSG("Rotary event CW\n");
DEBUG_MSG("Rotary event CCW\n");
e.inputEvent = this->_eventCcw;
}

Expand Down Expand Up @@ -84,7 +84,7 @@ void RotaryEncoderInterruptBase::intAHandler()
return;
}
this->rotaryLevelA = currentLevelA;
intHandler(
this->rotaryStateCCW = intHandler(
currentLevelA == HIGH,
this->rotaryLevelB,
ROTARY_ACTION_CCW,
Expand Down
6 changes: 5 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,11 @@ class ButtonThread : public OSThread
static void userButtonPressed()
{
// DEBUG_MSG("press!\n");
powerFSM.trigger(EVENT_PRESS);
#ifdef BUTTON_PIN
if ((BUTTON_PIN != radioConfig.preferences.rotary1_pin_press) || !radioConfig.preferences.canned_message_plugin_enabled) {
powerFSM.trigger(EVENT_PRESS);
}
#endif
}
static void userButtonPressedLong()
{
Expand Down
10 changes: 8 additions & 2 deletions src/plugins/CannedMessagePlugin.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "configuration.h"
#include "CannedMessagePlugin.h"
#include "PowerFSM.h" // neede for button bypass
#include "MeshService.h"

// TODO: reuse defined from Screen.cpp
Expand Down Expand Up @@ -111,8 +112,13 @@ int CannedMessagePlugin::handleInputEvent(const InputEvent *event)
if (event->inputEvent == static_cast<char>(InputEventChar_KEY_SELECT))
{
DEBUG_MSG("Canned message event Select\n");
this->runState = CANNED_MESSAGE_RUN_STATE_ACTION_SELECT;
validEvent = true;
// when inactive, call the onebutton shortpress instead. Activate Module only on up/down
if (this->runState == CANNED_MESSAGE_RUN_STATE_INACTIVE) {
powerFSM.trigger(EVENT_PRESS);
}else{
this->runState = CANNED_MESSAGE_RUN_STATE_ACTION_SELECT;
validEvent = true;
}
}

if (validEvent)
Expand Down

0 comments on commit e09aafa

Please sign in to comment.