diff --git a/examples/companion_radio/Button.cpp b/examples/companion_radio/Button.cpp index ec1f0f69..f9e83dba 100644 --- a/examples/companion_radio/Button.cpp +++ b/examples/companion_radio/Button.cpp @@ -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; diff --git a/examples/companion_radio/Button.h b/examples/companion_radio/Button.h index 47c792bd..9df809b2 100644 --- a/examples/companion_radio/Button.h +++ b/examples/companion_radio/Button.h @@ -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; diff --git a/examples/companion_radio/UITask.cpp b/examples/companion_radio/UITask.cpp index ec2ccd8b..ec9994b2 100644 --- a/examples/companion_radio/UITask.cpp +++ b/examples/companion_radio/UITask.cpp @@ -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; @@ -67,6 +68,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 @@ -396,6 +398,25 @@ void UITask::handleButtonTriplePress() { #endif } +void UITask::handleButtonQuadruplePress() { + MESH_DEBUG_PRINTLN("UITask: quad press triggered"); + if (_sensors != NULL) { + // toggle GPS onn/off + int num = _sensors->getNumSettings(); + for (int i = 0; i < num; i++) { + if (strcmp(_sensors->getSettingName(i), "gps") == 0) { + if (strcmp(_sensors->getSettingValue(i), "1") == 0) { + _sensors->setSettingValue("gps", "0"); + } else { + _sensors->setSettingValue("gps", "1"); + } + break; + } + } + } + _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 diff --git a/examples/companion_radio/UITask.h b/examples/companion_radio/UITask.h index 2b64d686..77ef875f 100644 --- a/examples/companion_radio/UITask.h +++ b/examples/companion_radio/UITask.h @@ -2,6 +2,7 @@ #include #include +#include #include #ifdef PIN_BUZZER @@ -24,6 +25,7 @@ class UITask { DisplayDriver* _display; mesh::MainBoard* _board; + SensorManager* _sensors; #ifdef PIN_BUZZER genericBuzzer buzzer; #endif @@ -56,17 +58,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; } diff --git a/examples/companion_radio/main.cpp b/examples/companion_radio/main.cpp index b46cdaab..098baf99 100644 --- a/examples/companion_radio/main.cpp +++ b/examples/companion_radio/main.cpp @@ -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 } diff --git a/src/helpers/CustomSX1262.h b/src/helpers/CustomSX1262.h index 8c93d384..6d17c162 100644 --- a/src/helpers/CustomSX1262.h +++ b/src/helpers/CustomSX1262.h @@ -30,6 +30,12 @@ class CustomSX1262 : public SX1262 { #endif #endif int status = begin(LORA_FREQ, LORA_BW, LORA_SF, cr, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 8, tcxo); + // if radio init fails with -707/-706, try again with tcxo voltage set to 0.0f + if (status == RADIOLIB_ERR_SPI_CMD_FAILED || status == RADIOLIB_ERR_SPI_CMD_INVALID) { + #define SX126X_DIO3_TCXO_VOLTAGE (0.0f); + tcxo = SX126X_DIO3_TCXO_VOLTAGE; + status = begin(LORA_FREQ, LORA_BW, LORA_SF, cr, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 8, tcxo); + } if (status != RADIOLIB_ERR_NONE) { Serial.print("ERROR: radio init failed: "); Serial.println(status); diff --git a/variants/promicro/target.cpp b/variants/promicro/target.cpp index 2369bd7a..03a5a16a 100644 --- a/variants/promicro/target.cpp +++ b/variants/promicro/target.cpp @@ -2,9 +2,6 @@ #include "target.h" #include -#if ENV_INCLUDE_GPS -#endif - PromicroBoard board; 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); DISPLAY_CLASS display; #endif -#ifndef LORA_CR - #define LORA_CR 5 -#endif - bool radio_init() { rtc_clock.begin(Wire); -#ifdef SX126X_DIO3_TCXO_VOLTAGE - float tcxo = SX126X_DIO3_TCXO_VOLTAGE; -#else - float tcxo = 1.6f; -#endif - - SPI.setPins(P_LORA_MISO, P_LORA_SCLK, P_LORA_MOSI); - SPI.begin(); - radio.setRfSwitchPins(SX126X_RXEN, SX126X_TXEN); - int status = radio.begin(LORA_FREQ, LORA_BW, LORA_SF, LORA_CR, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 8, tcxo); - if (status == RADIOLIB_ERR_SPI_CMD_FAILED || status == RADIOLIB_ERR_SPI_CMD_INVALID) { - #define SX126X_DIO3_TCXO_VOLTAGE (0.0f); - tcxo = SX126X_DIO3_TCXO_VOLTAGE; - status = radio.begin(LORA_FREQ, LORA_BW, LORA_SF, LORA_CR, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 8, tcxo); - } - if (status != RADIOLIB_ERR_NONE) { - Serial.print("ERROR: radio init failed: "); - Serial.println(status); - return false; // fail - } - - radio.setCRC(1); - -#ifdef SX126X_CURRENT_LIMIT - radio.setCurrentLimit(SX126X_CURRENT_LIMIT); -#endif -#ifdef SX126X_DIO2_AS_RF_SWITCH - radio.setDio2AsRfSwitch(SX126X_DIO2_AS_RF_SWITCH); -#endif -#ifdef SX126X_RX_BOOSTED_GAIN - radio.setRxBoostedGainMode(SX126X_RX_BOOSTED_GAIN); -#endif - - return true; // success + return radio.std_init(&SPI); } uint32_t radio_get_rng_seed() { diff --git a/src/helpers/nrf52/T1000eBoard.cpp b/variants/t1000-e/T1000eBoard.cpp similarity index 100% rename from src/helpers/nrf52/T1000eBoard.cpp rename to variants/t1000-e/T1000eBoard.cpp diff --git a/src/helpers/nrf52/T1000eBoard.h b/variants/t1000-e/T1000eBoard.h similarity index 100% rename from src/helpers/nrf52/T1000eBoard.h rename to variants/t1000-e/T1000eBoard.h diff --git a/variants/t1000-e/target.h b/variants/t1000-e/target.h index 1b569481..855c4d67 100644 --- a/variants/t1000-e/target.h +++ b/variants/t1000-e/target.h @@ -3,7 +3,7 @@ #define RADIOLIB_STATIC_ONLY 1 #include #include -#include +#include "T1000eBoard.h" #include #include #include diff --git a/variants/thinknode_m1/target.cpp b/variants/thinknode_m1/target.cpp index 70b5c61e..19230232 100644 --- a/variants/thinknode_m1/target.cpp +++ b/variants/thinknode_m1/target.cpp @@ -18,41 +18,9 @@ ThinkNodeM1SensorManager sensors = ThinkNodeM1SensorManager(nmea); DISPLAY_CLASS display; #endif -#ifndef LORA_CR - #define LORA_CR 5 -#endif - bool radio_init() { rtc_clock.begin(Wire); - -#ifdef SX126X_DIO3_TCXO_VOLTAGE - float tcxo = SX126X_DIO3_TCXO_VOLTAGE; -#else - float tcxo = 1.6f; -#endif - - SPI.setPins(P_LORA_MISO, P_LORA_SCLK, P_LORA_MOSI); - SPI.begin(); - int status = radio.begin(LORA_FREQ, LORA_BW, LORA_SF, LORA_CR, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 8, tcxo); - if (status != RADIOLIB_ERR_NONE) { - Serial.print("ERROR: radio init failed: "); - Serial.println(status); - return false; // fail - } - - radio.setCRC(1); - -#ifdef SX126X_CURRENT_LIMIT - radio.setCurrentLimit(SX126X_CURRENT_LIMIT); -#endif -#ifdef SX126X_DIO2_AS_RF_SWITCH - radio.setDio2AsRfSwitch(SX126X_DIO2_AS_RF_SWITCH); -#endif -#ifdef SX126X_RX_BOOSTED_GAIN - radio.setRxBoostedGainMode(SX126X_RX_BOOSTED_GAIN); -#endif - - return true; // success + return radio.std_init(&SPI); } uint32_t radio_get_rng_seed() {