Skip to content

Commit 8765b3d

Browse files
committed
Gps toggle on 4 clicks
1 parent b3184eb commit 8765b3d

File tree

8 files changed

+28
-2
lines changed

8 files changed

+28
-2
lines changed

examples/companion_radio/Button.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,12 @@ void Button::update() {
5050
triggerEvent(SHORT_PRESS);
5151
} else if (_clickCount == 2) {
5252
triggerEvent(DOUBLE_PRESS);
53-
} else if (_clickCount >= 3) {
53+
} else if (_clickCount == 3) {
5454
triggerEvent(TRIPLE_PRESS);
55+
} else if (_clickCount >= 4) {
56+
triggerEvent(QUADRUPLE_PRESS);
5557
}
58+
5659
_clickCount = 0;
5760
_state = IDLE;
5861
}
@@ -116,6 +119,9 @@ void Button::triggerEvent(EventType event) {
116119
case TRIPLE_PRESS:
117120
if (_onTriplePress) _onTriplePress();
118121
break;
122+
case QUADRUPLE_PRESS:
123+
if (_onQuadruplePress) _onQuadruplePress();
124+
break;
119125
case LONG_PRESS:
120126
if (_onLongPress) _onLongPress();
121127
break;

examples/companion_radio/Button.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class Button {
1616
SHORT_PRESS,
1717
DOUBLE_PRESS,
1818
TRIPLE_PRESS,
19+
QUADRUPLE_PRESS,
1920
LONG_PRESS,
2021
ANY_PRESS
2122
};
@@ -32,6 +33,7 @@ class Button {
3233
void onShortPress(EventCallback callback) { _onShortPress = callback; }
3334
void onDoublePress(EventCallback callback) { _onDoublePress = callback; }
3435
void onTriplePress(EventCallback callback) { _onTriplePress = callback; }
36+
void onQuadruplePress(EventCallback callback) { _onQuadruplePress = callback; }
3537
void onLongPress(EventCallback callback) { _onLongPress = callback; }
3638
void onAnyPress(EventCallback callback) { _onAnyPress = callback; }
3739

@@ -68,6 +70,7 @@ class Button {
6870
EventCallback _onShortPress = nullptr;
6971
EventCallback _onDoublePress = nullptr;
7072
EventCallback _onTriplePress = nullptr;
73+
EventCallback _onQuadruplePress = nullptr;
7174
EventCallback _onLongPress = nullptr;
7275
EventCallback _onAnyPress = nullptr;
7376

examples/companion_radio/UITask.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ void UITask::begin(DisplayDriver* display, NodePrefs* node_prefs) {
7272
_userButton->onShortPress([this]() { handleButtonShortPress(); });
7373
_userButton->onDoublePress([this]() { handleButtonDoublePress(); });
7474
_userButton->onTriplePress([this]() { handleButtonTriplePress(); });
75+
_userButton->onQuadruplePress([this]() { handleButtonQuadruplePress(); });
7576
_userButton->onLongPress([this]() { handleButtonLongPress(); });
7677
_userButton->onAnyPress([this]() { handleButtonAnyPress(); });
7778
#endif
@@ -383,6 +384,12 @@ void UITask::handleButtonTriplePress() {
383384
#endif
384385
}
385386

387+
void UITask::handleButtonQuadruplePress() {
388+
MESH_DEBUG_PRINTLN("UITask: quad press triggered");
389+
_board->toggleGps();
390+
_need_refresh = true;
391+
}
392+
386393
void UITask::handleButtonLongPress() {
387394
MESH_DEBUG_PRINTLN("UITask: long press triggered");
388395
if (millis() - ui_started_at < 8000) { // long press in first 8 seconds since startup -> CLI/rescue

examples/companion_radio/UITask.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class UITask {
5353
void handleButtonShortPress();
5454
void handleButtonDoublePress();
5555
void handleButtonTriplePress();
56+
void handleButtonQuadruplePress();
5657
void handleButtonLongPress();
5758

5859

src/MeshCore.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class MainBoard {
4141
virtual void onAfterTransmit() { }
4242
virtual void reboot() = 0;
4343
virtual void powerOff() { /* no op */ }
44+
virtual bool toggleGps() { return false; } // could be a board_toggle depending on the board features ...
4445
virtual uint8_t getStartupReason() const = 0;
4546
virtual bool startOTAUpdate(const char* id, char reply[]) { return false; } // not supported
4647
};

src/helpers/nrf52/T1000eBoard.cpp renamed to variants/t1000-e/T1000eBoard.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <Arduino.h>
22
#include "T1000eBoard.h"
33
#include <Wire.h>
4+
#include "target.h"
45

56
#include <bluefruit.h>
67

@@ -26,6 +27,10 @@ void T1000eBoard::begin() {
2627
delay(10); // give sx1262 some time to power up
2728
}
2829

30+
bool T1000eBoard::toggleGps() {
31+
return sensors.toggle_gps();
32+
}
33+
2934
#if 0
3035
static BLEDfu bledfu;
3136

src/helpers/nrf52/T1000eBoard.h renamed to variants/t1000-e/T1000eBoard.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ class T1000eBoard : public mesh::MainBoard {
6666
return 0;
6767
}
6868

69+
virtual bool toggleGps() override;
70+
6971
void powerOff() override {
7072
#ifdef HAS_GPS
7173
digitalWrite(GPS_VRTC_EN, LOW);

variants/t1000-e/target.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#define RADIOLIB_STATIC_ONLY 1
44
#include <RadioLib.h>
55
#include <helpers/RadioLibWrappers.h>
6-
#include <helpers/nrf52/T1000eBoard.h>
6+
#include "T1000eBoard.h"
77
#include <helpers/CustomLR1110Wrapper.h>
88
#include <helpers/ArduinoHelpers.h>
99
#include <helpers/SensorManager.h>
@@ -28,6 +28,7 @@ class T1000SensorManager: public SensorManager {
2828
const char* getSettingName(int i) const override;
2929
const char* getSettingValue(int i) const override;
3030
bool setSettingValue(const char* name, const char* value) override;
31+
bool toggle_gps() { gps_active ? stop_gps() : start_gps(); return gps_active;}
3132
};
3233

3334
#ifdef DISPLAY_CLASS

0 commit comments

Comments
 (0)