Merge pull request #404 from fdlamotte/t1000_gps_toggle

Gps toggle on 4 clicks

Will merge, but I'll do a refactor of the gpsToggle()
This commit is contained in:
ripplebiz 2025-06-20 13:36:56 +10:00 committed by GitHub
commit 27388fcf2a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 32 additions and 6 deletions

View file

@ -50,9 +50,12 @@ void Button::update() {
triggerEvent(SHORT_PRESS); triggerEvent(SHORT_PRESS);
} else if (_clickCount == 2) { } else if (_clickCount == 2) {
triggerEvent(DOUBLE_PRESS); triggerEvent(DOUBLE_PRESS);
} else if (_clickCount >= 3) { } else if (_clickCount == 3) {
triggerEvent(TRIPLE_PRESS); triggerEvent(TRIPLE_PRESS);
} else if (_clickCount >= 4) {
triggerEvent(QUADRUPLE_PRESS);
} }
_clickCount = 0; _clickCount = 0;
_state = IDLE; _state = IDLE;
} }
@ -116,6 +119,9 @@ void Button::triggerEvent(EventType event) {
case TRIPLE_PRESS: case TRIPLE_PRESS:
if (_onTriplePress) _onTriplePress(); if (_onTriplePress) _onTriplePress();
break; break;
case QUADRUPLE_PRESS:
if (_onQuadruplePress) _onQuadruplePress();
break;
case LONG_PRESS: case LONG_PRESS:
if (_onLongPress) _onLongPress(); if (_onLongPress) _onLongPress();
break; break;

View file

@ -16,6 +16,7 @@ public:
SHORT_PRESS, SHORT_PRESS,
DOUBLE_PRESS, DOUBLE_PRESS,
TRIPLE_PRESS, TRIPLE_PRESS,
QUADRUPLE_PRESS,
LONG_PRESS, LONG_PRESS,
ANY_PRESS ANY_PRESS
}; };
@ -32,6 +33,7 @@ public:
void onShortPress(EventCallback callback) { _onShortPress = callback; } void onShortPress(EventCallback callback) { _onShortPress = callback; }
void onDoublePress(EventCallback callback) { _onDoublePress = callback; } void onDoublePress(EventCallback callback) { _onDoublePress = callback; }
void onTriplePress(EventCallback callback) { _onTriplePress = callback; } void onTriplePress(EventCallback callback) { _onTriplePress = callback; }
void onQuadruplePress(EventCallback callback) { _onQuadruplePress = callback; }
void onLongPress(EventCallback callback) { _onLongPress = callback; } void onLongPress(EventCallback callback) { _onLongPress = callback; }
void onAnyPress(EventCallback callback) { _onAnyPress = callback; } void onAnyPress(EventCallback callback) { _onAnyPress = callback; }
@ -68,6 +70,7 @@ private:
EventCallback _onShortPress = nullptr; EventCallback _onShortPress = nullptr;
EventCallback _onDoublePress = nullptr; EventCallback _onDoublePress = nullptr;
EventCallback _onTriplePress = nullptr; EventCallback _onTriplePress = nullptr;
EventCallback _onQuadruplePress = nullptr;
EventCallback _onLongPress = nullptr; EventCallback _onLongPress = nullptr;
EventCallback _onAnyPress = nullptr; EventCallback _onAnyPress = nullptr;

View file

@ -34,8 +34,9 @@ static const uint8_t meshcore_logo [] PROGMEM = {
0xe3, 0xe3, 0x8f, 0xff, 0x1f, 0xfc, 0x3c, 0x0e, 0x1f, 0xf8, 0xff, 0xf8, 0x70, 0x3c, 0x7f, 0xf8, 0xe3, 0xe3, 0x8f, 0xff, 0x1f, 0xfc, 0x3c, 0x0e, 0x1f, 0xf8, 0xff, 0xf8, 0x70, 0x3c, 0x7f, 0xf8,
}; };
void UITask::begin(DisplayDriver* display, NodePrefs* node_prefs) { void UITask::begin(DisplayDriver* display, SensorManager* sensors, NodePrefs* node_prefs) {
_display = display; _display = display;
_sensors = sensors;
_auto_off = millis() + AUTO_OFF_MILLIS; _auto_off = millis() + AUTO_OFF_MILLIS;
clearMsgPreview(); clearMsgPreview();
_node_prefs = node_prefs; _node_prefs = node_prefs;
@ -72,6 +73,7 @@ void UITask::begin(DisplayDriver* display, NodePrefs* node_prefs) {
_userButton->onShortPress([this]() { handleButtonShortPress(); }); _userButton->onShortPress([this]() { handleButtonShortPress(); });
_userButton->onDoublePress([this]() { handleButtonDoublePress(); }); _userButton->onDoublePress([this]() { handleButtonDoublePress(); });
_userButton->onTriplePress([this]() { handleButtonTriplePress(); }); _userButton->onTriplePress([this]() { handleButtonTriplePress(); });
_userButton->onQuadruplePress([this]() { handleButtonQuadruplePress(); });
_userButton->onLongPress([this]() { handleButtonLongPress(); }); _userButton->onLongPress([this]() { handleButtonLongPress(); });
_userButton->onAnyPress([this]() { handleButtonAnyPress(); }); _userButton->onAnyPress([this]() { handleButtonAnyPress(); });
#endif #endif
@ -383,6 +385,14 @@ void UITask::handleButtonTriplePress() {
#endif #endif
} }
void UITask::handleButtonQuadruplePress() {
MESH_DEBUG_PRINTLN("UITask: quad press triggered");
if (_sensors != NULL) {
_sensors->toggleGps();
}
_need_refresh = true;
}
void UITask::handleButtonLongPress() { void UITask::handleButtonLongPress() {
MESH_DEBUG_PRINTLN("UITask: long press triggered"); MESH_DEBUG_PRINTLN("UITask: long press triggered");
if (millis() - ui_started_at < 8000) { // long press in first 8 seconds since startup -> CLI/rescue if (millis() - ui_started_at < 8000) { // long press in first 8 seconds since startup -> CLI/rescue

View file

@ -2,6 +2,7 @@
#include <MeshCore.h> #include <MeshCore.h>
#include <helpers/ui/DisplayDriver.h> #include <helpers/ui/DisplayDriver.h>
#include <helpers/SensorManager.h>
#include <stddef.h> #include <stddef.h>
#ifdef PIN_BUZZER #ifdef PIN_BUZZER
@ -24,6 +25,7 @@
class UITask { class UITask {
DisplayDriver* _display; DisplayDriver* _display;
mesh::MainBoard* _board; mesh::MainBoard* _board;
SensorManager* _sensors;
#ifdef PIN_BUZZER #ifdef PIN_BUZZER
genericBuzzer buzzer; genericBuzzer buzzer;
#endif #endif
@ -53,17 +55,18 @@ class UITask {
void handleButtonShortPress(); void handleButtonShortPress();
void handleButtonDoublePress(); void handleButtonDoublePress();
void handleButtonTriplePress(); void handleButtonTriplePress();
void handleButtonQuadruplePress();
void handleButtonLongPress(); void handleButtonLongPress();
public: public:
UITask(mesh::MainBoard* board) : _board(board), _display(NULL) { UITask(mesh::MainBoard* board) : _board(board), _display(NULL), _sensors(NULL) {
_next_refresh = 0; _next_refresh = 0;
ui_started_at = 0; ui_started_at = 0;
_connected = false; _connected = false;
} }
void begin(DisplayDriver* display, NodePrefs* node_prefs); void begin(DisplayDriver* display, SensorManager* sensors, NodePrefs* node_prefs);
void setHasConnection(bool connected) { _connected = connected; } void setHasConnection(bool connected) { _connected = connected; }
bool hasDisplay() const { return _display != NULL; } bool hasDisplay() const { return _display != NULL; }

View file

@ -186,7 +186,7 @@ void setup() {
sensors.begin(); sensors.begin();
#ifdef DISPLAY_CLASS #ifdef DISPLAY_CLASS
ui_task.begin(disp, the_mesh.getNodePrefs()); // still want to pass this in as dependency, as prefs might be moved ui_task.begin(disp, &sensors, the_mesh.getNodePrefs()); // still want to pass this in as dependency, as prefs might be moved
#endif #endif
} }

View file

@ -21,4 +21,6 @@ public:
virtual const char* getSettingName(int i) const { return NULL; } virtual const char* getSettingName(int i) const { return NULL; }
virtual const char* getSettingValue(int i) const { return NULL; } virtual const char* getSettingValue(int i) const { return NULL; }
virtual bool setSettingValue(const char* name, const char* value) { return false; } virtual bool setSettingValue(const char* name, const char* value) { return false; }
virtual bool getGpsStatus() { return false; }
virtual bool toggleGps() { return false; }
}; };

View file

@ -3,7 +3,7 @@
#define RADIOLIB_STATIC_ONLY 1 #define RADIOLIB_STATIC_ONLY 1
#include <RadioLib.h> #include <RadioLib.h>
#include <helpers/RadioLibWrappers.h> #include <helpers/RadioLibWrappers.h>
#include <helpers/nrf52/T1000eBoard.h> #include "T1000eBoard.h"
#include <helpers/CustomLR1110Wrapper.h> #include <helpers/CustomLR1110Wrapper.h>
#include <helpers/ArduinoHelpers.h> #include <helpers/ArduinoHelpers.h>
#include <helpers/SensorManager.h> #include <helpers/SensorManager.h>
@ -28,6 +28,8 @@ public:
const char* getSettingName(int i) const override; const char* getSettingName(int i) const override;
const char* getSettingValue(int i) const override; const char* getSettingValue(int i) const override;
bool setSettingValue(const char* name, const char* value) override; bool setSettingValue(const char* name, const char* value) override;
bool getGpsStatus() override { return gps_active; }
bool toggleGps() override { gps_active ? sleep_gps() : start_gps(); return gps_active; }
}; };
#ifdef DISPLAY_CLASS #ifdef DISPLAY_CLASS