Skip to content

Commit cdca6fa

Browse files
committed
Merge branch 'dev' into analog-button
2 parents ee68401 + 61301da commit cdca6fa

File tree

11 files changed

+47
-80
lines changed

11 files changed

+47
-80
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: 22 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;
@@ -67,6 +68,7 @@ void UITask::begin(DisplayDriver* display, NodePrefs* node_prefs) {
6768
_userButton->onShortPress([this]() { handleButtonShortPress(); });
6869
_userButton->onDoublePress([this]() { handleButtonDoublePress(); });
6970
_userButton->onTriplePress([this]() { handleButtonTriplePress(); });
71+
_userButton->onQuadruplePress([this]() { handleButtonQuadruplePress(); });
7072
_userButton->onLongPress([this]() { handleButtonLongPress(); });
7173
_userButton->onAnyPress([this]() { handleButtonAnyPress(); });
7274
#endif
@@ -396,6 +398,25 @@ void UITask::handleButtonTriplePress() {
396398
#endif
397399
}
398400

401+
void UITask::handleButtonQuadruplePress() {
402+
MESH_DEBUG_PRINTLN("UITask: quad press triggered");
403+
if (_sensors != NULL) {
404+
// toggle GPS onn/off
405+
int num = _sensors->getNumSettings();
406+
for (int i = 0; i < num; i++) {
407+
if (strcmp(_sensors->getSettingName(i), "gps") == 0) {
408+
if (strcmp(_sensors->getSettingValue(i), "1") == 0) {
409+
_sensors->setSettingValue("gps", "0");
410+
} else {
411+
_sensors->setSettingValue("gps", "1");
412+
}
413+
break;
414+
}
415+
}
416+
}
417+
_need_refresh = true;
418+
}
419+
399420
void UITask::handleButtonLongPress() {
400421
MESH_DEBUG_PRINTLN("UITask: long press triggered");
401422
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
@@ -56,17 +58,18 @@ class UITask {
5658
void handleButtonShortPress();
5759
void handleButtonDoublePress();
5860
void handleButtonTriplePress();
61+
void handleButtonQuadruplePress();
5962
void handleButtonLongPress();
6063

6164

6265
public:
6366

64-
UITask(mesh::MainBoard* board) : _board(board), _display(NULL) {
67+
UITask(mesh::MainBoard* board) : _board(board), _display(NULL), _sensors(NULL) {
6568
_next_refresh = 0;
6669
ui_started_at = 0;
6770
_connected = false;
6871
}
69-
void begin(DisplayDriver* display, NodePrefs* node_prefs);
72+
void begin(DisplayDriver* display, SensorManager* sensors, NodePrefs* node_prefs);
7073

7174
void setHasConnection(bool connected) { _connected = connected; }
7275
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/CustomSX1262.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ class CustomSX1262 : public SX1262 {
3030
#endif
3131
#endif
3232
int status = begin(LORA_FREQ, LORA_BW, LORA_SF, cr, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 8, tcxo);
33+
// if radio init fails with -707/-706, try again with tcxo voltage set to 0.0f
34+
if (status == RADIOLIB_ERR_SPI_CMD_FAILED || status == RADIOLIB_ERR_SPI_CMD_INVALID) {
35+
#define SX126X_DIO3_TCXO_VOLTAGE (0.0f);
36+
tcxo = SX126X_DIO3_TCXO_VOLTAGE;
37+
status = begin(LORA_FREQ, LORA_BW, LORA_SF, cr, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 8, tcxo);
38+
}
3339
if (status != RADIOLIB_ERR_NONE) {
3440
Serial.print("ERROR: radio init failed: ");
3541
Serial.println(status);

variants/promicro/target.cpp

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
#include "target.h"
33
#include <helpers/ArduinoHelpers.h>
44

5-
#if ENV_INCLUDE_GPS
6-
#endif
7-
85
PromicroBoard board;
96

107
RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI);
@@ -25,47 +22,10 @@ AutoDiscoverRTCClock rtc_clock(fallback_clock);
2522
DISPLAY_CLASS display;
2623
#endif
2724

28-
#ifndef LORA_CR
29-
#define LORA_CR 5
30-
#endif
31-
3225
bool radio_init() {
3326
rtc_clock.begin(Wire);
3427

35-
#ifdef SX126X_DIO3_TCXO_VOLTAGE
36-
float tcxo = SX126X_DIO3_TCXO_VOLTAGE;
37-
#else
38-
float tcxo = 1.6f;
39-
#endif
40-
41-
SPI.setPins(P_LORA_MISO, P_LORA_SCLK, P_LORA_MOSI);
42-
SPI.begin();
43-
radio.setRfSwitchPins(SX126X_RXEN, SX126X_TXEN);
44-
int status = radio.begin(LORA_FREQ, LORA_BW, LORA_SF, LORA_CR, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 8, tcxo);
45-
if (status == RADIOLIB_ERR_SPI_CMD_FAILED || status == RADIOLIB_ERR_SPI_CMD_INVALID) {
46-
#define SX126X_DIO3_TCXO_VOLTAGE (0.0f);
47-
tcxo = SX126X_DIO3_TCXO_VOLTAGE;
48-
status = radio.begin(LORA_FREQ, LORA_BW, LORA_SF, LORA_CR, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 8, tcxo);
49-
}
50-
if (status != RADIOLIB_ERR_NONE) {
51-
Serial.print("ERROR: radio init failed: ");
52-
Serial.println(status);
53-
return false; // fail
54-
}
55-
56-
radio.setCRC(1);
57-
58-
#ifdef SX126X_CURRENT_LIMIT
59-
radio.setCurrentLimit(SX126X_CURRENT_LIMIT);
60-
#endif
61-
#ifdef SX126X_DIO2_AS_RF_SWITCH
62-
radio.setDio2AsRfSwitch(SX126X_DIO2_AS_RF_SWITCH);
63-
#endif
64-
#ifdef SX126X_RX_BOOSTED_GAIN
65-
radio.setRxBoostedGainMode(SX126X_RX_BOOSTED_GAIN);
66-
#endif
67-
68-
return true; // success
28+
return radio.std_init(&SPI);
6929
}
7030

7131
uint32_t radio_get_rng_seed() {
File renamed without changes.
File renamed without changes.

variants/t1000-e/target.h

Lines changed: 1 addition & 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>

0 commit comments

Comments
 (0)