mirror of
https://github.com/meshcore-dev/MeshCore.git
synced 2026-03-30 19:15:49 +00:00
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:
@@ -50,9 +50,12 @@ void Button::update() {
|
||||
triggerEvent(SHORT_PRESS);
|
||||
} else if (_clickCount == 2) {
|
||||
triggerEvent(DOUBLE_PRESS);
|
||||
} else if (_clickCount >= 3) {
|
||||
} else if (_clickCount == 3) {
|
||||
triggerEvent(TRIPLE_PRESS);
|
||||
} else if (_clickCount >= 4) {
|
||||
triggerEvent(QUADRUPLE_PRESS);
|
||||
}
|
||||
|
||||
_clickCount = 0;
|
||||
_state = IDLE;
|
||||
}
|
||||
@@ -116,6 +119,9 @@ void Button::triggerEvent(EventType event) {
|
||||
case TRIPLE_PRESS:
|
||||
if (_onTriplePress) _onTriplePress();
|
||||
break;
|
||||
case QUADRUPLE_PRESS:
|
||||
if (_onQuadruplePress) _onQuadruplePress();
|
||||
break;
|
||||
case LONG_PRESS:
|
||||
if (_onLongPress) _onLongPress();
|
||||
break;
|
||||
|
||||
@@ -16,6 +16,7 @@ public:
|
||||
SHORT_PRESS,
|
||||
DOUBLE_PRESS,
|
||||
TRIPLE_PRESS,
|
||||
QUADRUPLE_PRESS,
|
||||
LONG_PRESS,
|
||||
ANY_PRESS
|
||||
};
|
||||
@@ -32,6 +33,7 @@ public:
|
||||
void onShortPress(EventCallback callback) { _onShortPress = callback; }
|
||||
void onDoublePress(EventCallback callback) { _onDoublePress = callback; }
|
||||
void onTriplePress(EventCallback callback) { _onTriplePress = callback; }
|
||||
void onQuadruplePress(EventCallback callback) { _onQuadruplePress = callback; }
|
||||
void onLongPress(EventCallback callback) { _onLongPress = callback; }
|
||||
void onAnyPress(EventCallback callback) { _onAnyPress = callback; }
|
||||
|
||||
@@ -68,6 +70,7 @@ private:
|
||||
EventCallback _onShortPress = nullptr;
|
||||
EventCallback _onDoublePress = nullptr;
|
||||
EventCallback _onTriplePress = nullptr;
|
||||
EventCallback _onQuadruplePress = nullptr;
|
||||
EventCallback _onLongPress = nullptr;
|
||||
EventCallback _onAnyPress = nullptr;
|
||||
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
void UITask::begin(DisplayDriver* display, NodePrefs* node_prefs) {
|
||||
void UITask::begin(DisplayDriver* display, SensorManager* sensors, NodePrefs* node_prefs) {
|
||||
_display = display;
|
||||
_sensors = sensors;
|
||||
_auto_off = millis() + AUTO_OFF_MILLIS;
|
||||
clearMsgPreview();
|
||||
_node_prefs = node_prefs;
|
||||
@@ -72,6 +73,7 @@ void UITask::begin(DisplayDriver* display, NodePrefs* node_prefs) {
|
||||
_userButton->onShortPress([this]() { handleButtonShortPress(); });
|
||||
_userButton->onDoublePress([this]() { handleButtonDoublePress(); });
|
||||
_userButton->onTriplePress([this]() { handleButtonTriplePress(); });
|
||||
_userButton->onQuadruplePress([this]() { handleButtonQuadruplePress(); });
|
||||
_userButton->onLongPress([this]() { handleButtonLongPress(); });
|
||||
_userButton->onAnyPress([this]() { handleButtonAnyPress(); });
|
||||
#endif
|
||||
@@ -383,6 +385,14 @@ void UITask::handleButtonTriplePress() {
|
||||
#endif
|
||||
}
|
||||
|
||||
void UITask::handleButtonQuadruplePress() {
|
||||
MESH_DEBUG_PRINTLN("UITask: quad press triggered");
|
||||
if (_sensors != NULL) {
|
||||
_sensors->toggleGps();
|
||||
}
|
||||
_need_refresh = true;
|
||||
}
|
||||
|
||||
void UITask::handleButtonLongPress() {
|
||||
MESH_DEBUG_PRINTLN("UITask: long press triggered");
|
||||
if (millis() - ui_started_at < 8000) { // long press in first 8 seconds since startup -> CLI/rescue
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <MeshCore.h>
|
||||
#include <helpers/ui/DisplayDriver.h>
|
||||
#include <helpers/SensorManager.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#ifdef PIN_BUZZER
|
||||
@@ -24,6 +25,7 @@
|
||||
class UITask {
|
||||
DisplayDriver* _display;
|
||||
mesh::MainBoard* _board;
|
||||
SensorManager* _sensors;
|
||||
#ifdef PIN_BUZZER
|
||||
genericBuzzer buzzer;
|
||||
#endif
|
||||
@@ -53,17 +55,18 @@ class UITask {
|
||||
void handleButtonShortPress();
|
||||
void handleButtonDoublePress();
|
||||
void handleButtonTriplePress();
|
||||
void handleButtonQuadruplePress();
|
||||
void handleButtonLongPress();
|
||||
|
||||
|
||||
public:
|
||||
|
||||
UITask(mesh::MainBoard* board) : _board(board), _display(NULL) {
|
||||
UITask(mesh::MainBoard* board) : _board(board), _display(NULL), _sensors(NULL) {
|
||||
_next_refresh = 0;
|
||||
ui_started_at = 0;
|
||||
_connected = false;
|
||||
}
|
||||
void begin(DisplayDriver* display, NodePrefs* node_prefs);
|
||||
void begin(DisplayDriver* display, SensorManager* sensors, NodePrefs* node_prefs);
|
||||
|
||||
void setHasConnection(bool connected) { _connected = connected; }
|
||||
bool hasDisplay() const { return _display != NULL; }
|
||||
|
||||
@@ -186,7 +186,7 @@ void setup() {
|
||||
sensors.begin();
|
||||
|
||||
#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
|
||||
}
|
||||
|
||||
|
||||
@@ -21,4 +21,6 @@ public:
|
||||
virtual const char* getSettingName(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 getGpsStatus() { return false; }
|
||||
virtual bool toggleGps() { return false; }
|
||||
};
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#define RADIOLIB_STATIC_ONLY 1
|
||||
#include <RadioLib.h>
|
||||
#include <helpers/RadioLibWrappers.h>
|
||||
#include <helpers/nrf52/T1000eBoard.h>
|
||||
#include "T1000eBoard.h"
|
||||
#include <helpers/CustomLR1110Wrapper.h>
|
||||
#include <helpers/ArduinoHelpers.h>
|
||||
#include <helpers/SensorManager.h>
|
||||
@@ -28,6 +28,8 @@ public:
|
||||
const char* getSettingName(int i) const override;
|
||||
const char* getSettingValue(int i) const 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
|
||||
|
||||
Reference in New Issue
Block a user