Merge pull request #1322 from meshtastic/inputbroker-v2

Fixes forward ported from 1.2 and renaming of pin names for more generic use.
This commit is contained in:
Thomas Göttgens 2022-03-26 10:22:34 +01:00 committed by GitHub
commit 596a889a1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 56 additions and 34 deletions

View File

@ -147,8 +147,12 @@ class ButtonThread : public concurrency::OSThread
static void userButtonPressed() static void userButtonPressed()
{ {
// DEBUG_MSG("press!\n"); // DEBUG_MSG("press!\n");
#ifdef BUTTON_PIN
if ((BUTTON_PIN != radioConfig.preferences.inputbroker_pin_press) || !radioConfig.preferences.canned_message_module_enabled) {
powerFSM.trigger(EVENT_PRESS); powerFSM.trigger(EVENT_PRESS);
} }
#endif
}
static void userButtonPressedLong() static void userButtonPressedLong()
{ {
// DEBUG_MSG("Long press!\n"); // DEBUG_MSG("Long press!\n");

View File

@ -279,6 +279,12 @@ void PowerFSM_setup()
powerFSM.add_transition(&stateON, &stateSHUTDOWN, EVENT_SHUTDOWN, NULL, "Shutdown"); powerFSM.add_transition(&stateON, &stateSHUTDOWN, EVENT_SHUTDOWN, NULL, "Shutdown");
powerFSM.add_transition(&stateSERIAL, &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(&stateDARK, &stateON, EVENT_BLUETOOTH_PAIR, NULL, "Bluetooth pairing");
powerFSM.add_transition(&stateON, &stateON, EVENT_BLUETOOTH_PAIR, NULL, "Bluetooth pairing"); powerFSM.add_transition(&stateON, &stateON, EVENT_BLUETOOTH_PAIR, NULL, "Bluetooth pairing");

View File

@ -20,6 +20,7 @@
#define EVENT_POWER_DISCONNECTED 14 #define EVENT_POWER_DISCONNECTED 14
#define EVENT_FIRMWARE_UPDATE 15 // We just received a new firmware update packet from the phone #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_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 Fsm powerFSM;
extern State statePOWER, stateSERIAL; extern State statePOWER, stateSERIAL;

View File

@ -1,4 +1,5 @@
#include "InputBroker.h" #include "InputBroker.h"
#include "PowerFSM.h" // needed for event trigger
InputBroker *inputBroker; InputBroker *inputBroker;
@ -13,6 +14,7 @@ void InputBroker::registerSource(Observable<const InputEvent *> *source)
int InputBroker::handleInputEvent(const InputEvent *event) int InputBroker::handleInputEvent(const InputEvent *event)
{ {
powerFSM.trigger(EVENT_INPUT);
this->notifyObservers(event); this->notifyObservers(event);
return 0; return 0;
} }

View File

@ -54,7 +54,7 @@ int32_t RotaryEncoderInterruptBase::runOnce()
} }
else if (this->action == ROTARY_ACTION_CCW) else if (this->action == ROTARY_ACTION_CCW)
{ {
DEBUG_MSG("Rotary event CW\n"); DEBUG_MSG("Rotary event CCW\n");
e.inputEvent = this->_eventCcw; e.inputEvent = this->_eventCcw;
} }
@ -84,7 +84,7 @@ void RotaryEncoderInterruptBase::intAHandler()
return; return;
} }
this->rotaryLevelA = currentLevelA; this->rotaryLevelA = currentLevelA;
intHandler( this->rotaryStateCCW = intHandler(
currentLevelA == HIGH, currentLevelA == HIGH,
this->rotaryLevelB, this->rotaryLevelB,
ROTARY_ACTION_CCW, ROTARY_ACTION_CCW,

View File

@ -17,15 +17,15 @@ void RotaryEncoderInterruptImpl1::init()
return; return;
} }
uint8_t pinA = radioConfig.preferences.rotary1_pin_a; uint8_t pinA = radioConfig.preferences.inputbroker_pin_a;
uint8_t pinB = radioConfig.preferences.rotary1_pin_b; uint8_t pinB = radioConfig.preferences.inputbroker_pin_b;
uint8_t pinPress = radioConfig.preferences.rotary1_pin_press; uint8_t pinPress = radioConfig.preferences.inputbroker_pin_press;
char eventCw = char eventCw =
static_cast<char>(radioConfig.preferences.rotary1_event_cw); static_cast<char>(radioConfig.preferences.inputbroker_event_cw);
char eventCcw = char eventCcw =
static_cast<char>(radioConfig.preferences.rotary1_event_ccw); static_cast<char>(radioConfig.preferences.inputbroker_event_ccw);
char eventPressed = char eventPressed =
static_cast<char>(radioConfig.preferences.rotary1_event_press); static_cast<char>(radioConfig.preferences.inputbroker_event_press);
//radioConfig.preferences.ext_notification_module_output //radioConfig.preferences.ext_notification_module_output
RotaryEncoderInterruptBase::init( RotaryEncoderInterruptBase::init(

View File

@ -125,7 +125,7 @@ extern const pb_msgdesc_t AdminMessage_msg;
#define AdminMessage_fields &AdminMessage_msg #define AdminMessage_fields &AdminMessage_msg
/* Maximum encoded size of messages (where known) */ /* Maximum encoded size of messages (where known) */
#define AdminMessage_size 608 #define AdminMessage_size 611
#ifdef __cplusplus #ifdef __cplusplus
} /* extern "C" */ } /* extern "C" */

View File

@ -171,12 +171,13 @@ typedef struct _RadioConfig_UserPreferences {
bool is_lora_tx_disabled; bool is_lora_tx_disabled;
bool is_power_saving; bool is_power_saving;
bool rotary1_enabled; bool rotary1_enabled;
uint32_t rotary1_pin_a; uint32_t inputbroker_pin_a;
uint32_t rotary1_pin_b; uint32_t inputbroker_pin_b;
uint32_t rotary1_pin_press; uint32_t inputbroker_pin_press;
InputEventChar rotary1_event_cw; InputEventChar inputbroker_event_cw;
InputEventChar rotary1_event_ccw; InputEventChar inputbroker_event_ccw;
InputEventChar rotary1_event_press; InputEventChar inputbroker_event_press;
bool updown1_enabled;
bool canned_message_module_enabled; bool canned_message_module_enabled;
char canned_message_module_allow_input_source[16]; char canned_message_module_allow_input_source[16];
bool canned_message_module_send_bell; bool canned_message_module_send_bell;
@ -227,9 +228,9 @@ extern "C" {
/* Initializer values for message structs */ /* Initializer values for message structs */
#define RadioConfig_init_default {false, RadioConfig_UserPreferences_init_default} #define RadioConfig_init_default {false, RadioConfig_UserPreferences_init_default}
#define RadioConfig_UserPreferences_init_default {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "", "", 0, _RegionCode_MIN, _ChargeCurrent_MIN, 0, _Role_MIN, 0, 0, 0, 0, 0, 0, 0, 0, "", 0, _GpsCoordinateFormat_MIN, 0, 0, 0, 0, 0, {0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, _RadioConfig_UserPreferences_TelemetrySensorType_MIN, 0, 0, 0, 0, 0, 0, 0, 0, "", "", 0, 0, 0, 0, 0, 0, _InputEventChar_MIN, _InputEventChar_MIN, _InputEventChar_MIN, 0, "", 0, 0, 0, 0} #define RadioConfig_UserPreferences_init_default {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "", "", 0, _RegionCode_MIN, _ChargeCurrent_MIN, 0, _Role_MIN, 0, 0, 0, 0, 0, 0, 0, 0, "", 0, _GpsCoordinateFormat_MIN, 0, 0, 0, 0, 0, {0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, _RadioConfig_UserPreferences_TelemetrySensorType_MIN, 0, 0, 0, 0, 0, 0, 0, 0, "", "", 0, 0, 0, 0, 0, 0, _InputEventChar_MIN, _InputEventChar_MIN, _InputEventChar_MIN, 0, 0, "", 0, 0, 0, 0}
#define RadioConfig_init_zero {false, RadioConfig_UserPreferences_init_zero} #define RadioConfig_init_zero {false, RadioConfig_UserPreferences_init_zero}
#define RadioConfig_UserPreferences_init_zero {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "", "", 0, _RegionCode_MIN, _ChargeCurrent_MIN, 0, _Role_MIN, 0, 0, 0, 0, 0, 0, 0, 0, "", 0, _GpsCoordinateFormat_MIN, 0, 0, 0, 0, 0, {0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, _RadioConfig_UserPreferences_TelemetrySensorType_MIN, 0, 0, 0, 0, 0, 0, 0, 0, "", "", 0, 0, 0, 0, 0, 0, _InputEventChar_MIN, _InputEventChar_MIN, _InputEventChar_MIN, 0, "", 0, 0, 0, 0} #define RadioConfig_UserPreferences_init_zero {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "", "", 0, _RegionCode_MIN, _ChargeCurrent_MIN, 0, _Role_MIN, 0, 0, 0, 0, 0, 0, 0, 0, "", 0, _GpsCoordinateFormat_MIN, 0, 0, 0, 0, 0, {0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, _RadioConfig_UserPreferences_TelemetrySensorType_MIN, 0, 0, 0, 0, 0, 0, 0, 0, "", "", 0, 0, 0, 0, 0, 0, _InputEventChar_MIN, _InputEventChar_MIN, _InputEventChar_MIN, 0, 0, "", 0, 0, 0, 0}
/* Field tags (for use in manual encoding/decoding) */ /* Field tags (for use in manual encoding/decoding) */
#define RadioConfig_UserPreferences_position_broadcast_secs_tag 1 #define RadioConfig_UserPreferences_position_broadcast_secs_tag 1
@ -303,12 +304,13 @@ extern "C" {
#define RadioConfig_UserPreferences_is_lora_tx_disabled_tag 157 #define RadioConfig_UserPreferences_is_lora_tx_disabled_tag 157
#define RadioConfig_UserPreferences_is_power_saving_tag 158 #define RadioConfig_UserPreferences_is_power_saving_tag 158
#define RadioConfig_UserPreferences_rotary1_enabled_tag 160 #define RadioConfig_UserPreferences_rotary1_enabled_tag 160
#define RadioConfig_UserPreferences_rotary1_pin_a_tag 161 #define RadioConfig_UserPreferences_inputbroker_pin_a_tag 161
#define RadioConfig_UserPreferences_rotary1_pin_b_tag 162 #define RadioConfig_UserPreferences_inputbroker_pin_b_tag 162
#define RadioConfig_UserPreferences_rotary1_pin_press_tag 163 #define RadioConfig_UserPreferences_inputbroker_pin_press_tag 163
#define RadioConfig_UserPreferences_rotary1_event_cw_tag 164 #define RadioConfig_UserPreferences_inputbroker_event_cw_tag 164
#define RadioConfig_UserPreferences_rotary1_event_ccw_tag 165 #define RadioConfig_UserPreferences_inputbroker_event_ccw_tag 165
#define RadioConfig_UserPreferences_rotary1_event_press_tag 166 #define RadioConfig_UserPreferences_inputbroker_event_press_tag 166
#define RadioConfig_UserPreferences_updown1_enabled_tag 167
#define RadioConfig_UserPreferences_canned_message_module_enabled_tag 170 #define RadioConfig_UserPreferences_canned_message_module_enabled_tag 170
#define RadioConfig_UserPreferences_canned_message_module_allow_input_source_tag 171 #define RadioConfig_UserPreferences_canned_message_module_allow_input_source_tag 171
#define RadioConfig_UserPreferences_canned_message_module_send_bell_tag 173 #define RadioConfig_UserPreferences_canned_message_module_send_bell_tag 173
@ -396,12 +398,13 @@ X(a, STATIC, SINGULAR, STRING, mqtt_password, 156) \
X(a, STATIC, SINGULAR, BOOL, is_lora_tx_disabled, 157) \ X(a, STATIC, SINGULAR, BOOL, is_lora_tx_disabled, 157) \
X(a, STATIC, SINGULAR, BOOL, is_power_saving, 158) \ X(a, STATIC, SINGULAR, BOOL, is_power_saving, 158) \
X(a, STATIC, SINGULAR, BOOL, rotary1_enabled, 160) \ X(a, STATIC, SINGULAR, BOOL, rotary1_enabled, 160) \
X(a, STATIC, SINGULAR, UINT32, rotary1_pin_a, 161) \ X(a, STATIC, SINGULAR, UINT32, inputbroker_pin_a, 161) \
X(a, STATIC, SINGULAR, UINT32, rotary1_pin_b, 162) \ X(a, STATIC, SINGULAR, UINT32, inputbroker_pin_b, 162) \
X(a, STATIC, SINGULAR, UINT32, rotary1_pin_press, 163) \ X(a, STATIC, SINGULAR, UINT32, inputbroker_pin_press, 163) \
X(a, STATIC, SINGULAR, UENUM, rotary1_event_cw, 164) \ X(a, STATIC, SINGULAR, UENUM, inputbroker_event_cw, 164) \
X(a, STATIC, SINGULAR, UENUM, rotary1_event_ccw, 165) \ X(a, STATIC, SINGULAR, UENUM, inputbroker_event_ccw, 165) \
X(a, STATIC, SINGULAR, UENUM, rotary1_event_press, 166) \ X(a, STATIC, SINGULAR, UENUM, inputbroker_event_press, 166) \
X(a, STATIC, SINGULAR, BOOL, updown1_enabled, 167) \
X(a, STATIC, SINGULAR, BOOL, canned_message_module_enabled, 170) \ X(a, STATIC, SINGULAR, BOOL, canned_message_module_enabled, 170) \
X(a, STATIC, SINGULAR, STRING, canned_message_module_allow_input_source, 171) \ X(a, STATIC, SINGULAR, STRING, canned_message_module_allow_input_source, 171) \
X(a, STATIC, SINGULAR, BOOL, canned_message_module_send_bell, 173) \ X(a, STATIC, SINGULAR, BOOL, canned_message_module_send_bell, 173) \
@ -419,8 +422,8 @@ extern const pb_msgdesc_t RadioConfig_UserPreferences_msg;
#define RadioConfig_UserPreferences_fields &RadioConfig_UserPreferences_msg #define RadioConfig_UserPreferences_fields &RadioConfig_UserPreferences_msg
/* Maximum encoded size of messages (where known) */ /* Maximum encoded size of messages (where known) */
#define RadioConfig_size 605 #define RadioConfig_size 608
#define RadioConfig_UserPreferences_size 602 #define RadioConfig_UserPreferences_size 605
#ifdef __cplusplus #ifdef __cplusplus
} /* extern "C" */ } /* extern "C" */

View File

@ -1,5 +1,6 @@
#include "configuration.h" #include "configuration.h"
#include "CannedMessageModule.h" #include "CannedMessageModule.h"
#include "PowerFSM.h" // neede for button bypass
#include "MeshService.h" #include "MeshService.h"
#include "FSCommon.h" #include "FSCommon.h"
#include "mesh/generated/cannedmessages.pb.h" #include "mesh/generated/cannedmessages.pb.h"
@ -140,9 +141,14 @@ int CannedMessageModule::handleInputEvent(const InputEvent *event)
if (event->inputEvent == static_cast<char>(InputEventChar_KEY_SELECT)) if (event->inputEvent == static_cast<char>(InputEventChar_KEY_SELECT))
{ {
DEBUG_MSG("Canned message event Select\n"); DEBUG_MSG("Canned message event Select\n");
// when inactive, call the onebutton shortpress instead. Activate Module only on up/down
if ((this->runState == CANNED_MESSAGE_RUN_STATE_INACTIVE) || (this->runState == CANNED_MESSAGE_RUN_STATE_DISABLED)) {
powerFSM.trigger(EVENT_PRESS);
}else{
this->runState = CANNED_MESSAGE_RUN_STATE_ACTION_SELECT; this->runState = CANNED_MESSAGE_RUN_STATE_ACTION_SELECT;
validEvent = true; validEvent = true;
} }
}
if (validEvent) if (validEvent)
{ {