Gps toggle on 4 clicks

This commit is contained in:
Florent de Lamotte 2025-06-18 11:52:16 +02:00
parent b3184eb94c
commit 8765b3d040
8 changed files with 28 additions and 2 deletions

View file

@ -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;

View file

@ -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;

View file

@ -72,6 +72,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 +384,12 @@ void UITask::handleButtonTriplePress() {
#endif
}
void UITask::handleButtonQuadruplePress() {
MESH_DEBUG_PRINTLN("UITask: quad press triggered");
_board->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

View file

@ -53,6 +53,7 @@ class UITask {
void handleButtonShortPress();
void handleButtonDoublePress();
void handleButtonTriplePress();
void handleButtonQuadruplePress();
void handleButtonLongPress();

View file

@ -41,6 +41,7 @@ public:
virtual void onAfterTransmit() { }
virtual void reboot() = 0;
virtual void powerOff() { /* no op */ }
virtual bool toggleGps() { return false; } // could be a board_toggle depending on the board features ...
virtual uint8_t getStartupReason() const = 0;
virtual bool startOTAUpdate(const char* id, char reply[]) { return false; } // not supported
};

View file

@ -1,6 +1,7 @@
#include <Arduino.h>
#include "T1000eBoard.h"
#include <Wire.h>
#include "target.h"
#include <bluefruit.h>
@ -26,6 +27,10 @@ void T1000eBoard::begin() {
delay(10); // give sx1262 some time to power up
}
bool T1000eBoard::toggleGps() {
return sensors.toggle_gps();
}
#if 0
static BLEDfu bledfu;

View file

@ -66,6 +66,8 @@ public:
return 0;
}
virtual bool toggleGps() override;
void powerOff() override {
#ifdef HAS_GPS
digitalWrite(GPS_VRTC_EN, LOW);

View file

@ -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,7 @@ 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 toggle_gps() { gps_active ? stop_gps() : start_gps(); return gps_active;}
};
#ifdef DISPLAY_CLASS