Skip to content

Commit 27388fc

Browse files
authored
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()
2 parents eb58266 + 588a986 commit 27388fc

File tree

9 files changed

+32
-6
lines changed

9 files changed

+32
-6
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: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ static const uint8_t meshcore_logo [] PROGMEM = {
3434
0xe3, 0xe3, 0x8f, 0xff, 0x1f, 0xfc, 0x3c, 0x0e, 0x1f, 0xf8, 0xff, 0xf8, 0x70, 0x3c, 0x7f, 0xf8,
3535
};
3636

37-
void UITask::begin(DisplayDriver* display, NodePrefs* node_prefs) {
37+
void UITask::begin(DisplayDriver* display, SensorManager* sensors, NodePrefs* node_prefs) {
3838
_display = display;
39+
_sensors = sensors;
3940
_auto_off = millis() + AUTO_OFF_MILLIS;
4041
clearMsgPreview();
4142
_node_prefs = node_prefs;
@@ -72,6 +73,7 @@ void UITask::begin(DisplayDriver* display, NodePrefs* node_prefs) {
7273
_userButton->onShortPress([this]() { handleButtonShortPress(); });
7374
_userButton->onDoublePress([this]() { handleButtonDoublePress(); });
7475
_userButton->onTriplePress([this]() { handleButtonTriplePress(); });
76+
_userButton->onQuadruplePress([this]() { handleButtonQuadruplePress(); });
7577
_userButton->onLongPress([this]() { handleButtonLongPress(); });
7678
_userButton->onAnyPress([this]() { handleButtonAnyPress(); });
7779
#endif
@@ -383,6 +385,14 @@ void UITask::handleButtonTriplePress() {
383385
#endif
384386
}
385387

388+
void UITask::handleButtonQuadruplePress() {
389+
MESH_DEBUG_PRINTLN("UITask: quad press triggered");
390+
if (_sensors != NULL) {
391+
_sensors->toggleGps();
392+
}
393+
_need_refresh = true;
394+
}
395+
386396
void UITask::handleButtonLongPress() {
387397
MESH_DEBUG_PRINTLN("UITask: long press triggered");
388398
if (millis() - ui_started_at < 8000) { // long press in first 8 seconds since startup -> CLI/rescue

examples/companion_radio/UITask.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <MeshCore.h>
44
#include <helpers/ui/DisplayDriver.h>
5+
#include <helpers/SensorManager.h>
56
#include <stddef.h>
67

78
#ifdef PIN_BUZZER
@@ -24,6 +25,7 @@
2425
class UITask {
2526
DisplayDriver* _display;
2627
mesh::MainBoard* _board;
28+
SensorManager* _sensors;
2729
#ifdef PIN_BUZZER
2830
genericBuzzer buzzer;
2931
#endif
@@ -53,17 +55,18 @@ class UITask {
5355
void handleButtonShortPress();
5456
void handleButtonDoublePress();
5557
void handleButtonTriplePress();
58+
void handleButtonQuadruplePress();
5659
void handleButtonLongPress();
5760

5861

5962
public:
6063

61-
UITask(mesh::MainBoard* board) : _board(board), _display(NULL) {
64+
UITask(mesh::MainBoard* board) : _board(board), _display(NULL), _sensors(NULL) {
6265
_next_refresh = 0;
6366
ui_started_at = 0;
6467
_connected = false;
6568
}
66-
void begin(DisplayDriver* display, NodePrefs* node_prefs);
69+
void begin(DisplayDriver* display, SensorManager* sensors, NodePrefs* node_prefs);
6770

6871
void setHasConnection(bool connected) { _connected = connected; }
6972
bool hasDisplay() const { return _display != NULL; }

examples/companion_radio/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ void setup() {
186186
sensors.begin();
187187

188188
#ifdef DISPLAY_CLASS
189-
ui_task.begin(disp, the_mesh.getNodePrefs()); // still want to pass this in as dependency, as prefs might be moved
189+
ui_task.begin(disp, &sensors, the_mesh.getNodePrefs()); // still want to pass this in as dependency, as prefs might be moved
190190
#endif
191191
}
192192

src/helpers/SensorManager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,6 @@ class SensorManager {
2121
virtual const char* getSettingName(int i) const { return NULL; }
2222
virtual const char* getSettingValue(int i) const { return NULL; }
2323
virtual bool setSettingValue(const char* name, const char* value) { return false; }
24+
virtual bool getGpsStatus() { return false; }
25+
virtual bool toggleGps() { return false; }
2426
};
File renamed without changes.
File renamed without changes.

variants/t1000-e/target.h

Lines changed: 3 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,8 @@ 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 getGpsStatus() override { return gps_active; }
32+
bool toggleGps() override { gps_active ? sleep_gps() : start_gps(); return gps_active; }
3133
};
3234

3335
#ifdef DISPLAY_CLASS

0 commit comments

Comments
 (0)