diff --git a/examples/companion_radio/ui-new/UITask.cpp b/examples/companion_radio/ui-new/UITask.cpp index 265532be0b..aa70e6b86e 100644 --- a/examples/companion_radio/ui-new/UITask.cpp +++ b/examples/companion_radio/ui-new/UITask.cpp @@ -7,7 +7,7 @@ #endif #ifndef AUTO_OFF_MILLIS - #define AUTO_OFF_MILLIS 15000 // 15 seconds + #define AUTO_OFF_MILLIS 15000 // 15 seconds #endif #define BOOT_SCREEN_MILLIS 3000 // 3 seconds @@ -31,6 +31,8 @@ #include "icons.h" +extern CustomSX1262Wrapper radio_driver; + class SplashScreen : public UIScreen { UITask* _task; unsigned long dismiss_after; @@ -263,10 +265,17 @@ class HomeScreen : public UIScreen { sprintf(tmp, "BW: %03.2f CR: %d", _node_prefs->bw, _node_prefs->cr); display.print(tmp); - // tx power, noise floor + // tx power display.setCursor(0, 42); - sprintf(tmp, "TX: %ddBm", _node_prefs->tx_power_dbm); + sprintf(tmp, "TX: %ddBm", radio_driver.getPower()); + display.print(tmp); + + // battery voltage + display.setCursor(84, 42); + sprintf(tmp, "%03.2fV", (float)board.getBattMilliVolts() / 1000.0f); display.print(tmp); + + // noise floor display.setCursor(0, 53); sprintf(tmp, "Noise floor: %d", radio_driver.getNoiseFloor()); display.print(tmp); @@ -604,13 +613,13 @@ void UITask::notify(UIEventType t) { switch(t){ case UIEventType::contactMessage: // gemini's pick - buzzer.play("MsgRcv3:d=4,o=6,b=200:32e,32g,32b,16c7"); + buzzer.play("MsgRcv3:d=4,o=7,b=200:32d#,32d#,32d#,16d"); break; case UIEventType::channelMessage: - buzzer.play("kerplop:d=16,o=6,b=120:32g#,32c#"); + buzzer.play("kerplop:d=16,o=7,b=120:32d#,32d#"); break; case UIEventType::ack: - buzzer.play("ack:d=32,o=8,b=120:c"); + buzzer.play("ack:d=32,o=7,b=120:d#"); break; case UIEventType::roomMessage: case UIEventType::newContactMessage: @@ -777,6 +786,24 @@ void UITask::loop() { next_backlight_btn_check = millis() + 300; } #endif +#if defined(PIN_POWER_BTN) +<<<<<<< HEAD + static unsigned long next_power_chck = 0; + static uint8_t _lastSwitchPower = 0xFF; + + if (millis() > next_power_chck) { + uint8_t newPower = digitalRead(PIN_POWER_BTN) == HIGH ? 20 : 10; + if (newPower != _lastSwitchPower && !radio_driver.isChannelActive()) { + _lastSwitchPower = newPower; + radio_driver.setPower(newPower); + _node_prefs->tx_power_dbm = newPower; + _next_refresh = 0; + MESH_DEBUG_PRINTLN("INFO: %d dBm", newPower); + } + next_power_chck = millis() + 300; +>>>>>>> 51eb51feedba3098d5895cd5696ebdcea90722cf + } +#endif if (c != 0 && curr) { curr->handleInput(c); diff --git a/src/helpers/radiolib/CustomSX1262.h b/src/helpers/radiolib/CustomSX1262.h index ad20122902..e0d0e55f68 100644 --- a/src/helpers/radiolib/CustomSX1262.h +++ b/src/helpers/radiolib/CustomSX1262.h @@ -9,6 +9,15 @@ class CustomSX1262 : public SX1262 { public: CustomSX1262(Module *mod) : SX1262(mod) { } + // A new way to get current power + uint8_t getTxPower() const { return _txPower; } + + // Redefining the power setting method + int16_t setOutputPower(int8_t power) override { + _txPower = power; // saving + return SX1262::setOutputPower(power); // calling the parent + } + #ifdef RP2040_PLATFORM bool std_init(SPIClassRP2040* spi = NULL) #else @@ -97,4 +106,7 @@ class CustomSX1262 : public SX1262 { readRegister(RADIOLIB_SX126X_REG_RX_GAIN, &rxGain, 1); return (rxGain == RADIOLIB_SX126X_RX_GAIN_BOOSTED); } + + private: + uint8_t _txPower = 0; }; \ No newline at end of file diff --git a/src/helpers/radiolib/CustomSX1262Wrapper.h b/src/helpers/radiolib/CustomSX1262Wrapper.h index 6499deb296..777f013e45 100644 --- a/src/helpers/radiolib/CustomSX1262Wrapper.h +++ b/src/helpers/radiolib/CustomSX1262Wrapper.h @@ -11,6 +11,17 @@ class CustomSX1262Wrapper : public RadioLibWrapper { public: CustomSX1262Wrapper(CustomSX1262& radio, mesh::MainBoard& board) : RadioLibWrapper(radio, board) { } + + // Sets the power, returns the value true if successful + bool setPower(int8_t power) { + return ((CustomSX1262 *)_radio)->setOutputPower(power) == RADIOLIB_ERR_NONE; + } + + // A new way to get current power + uint8_t getPower() const { + return ((CustomSX1262 *)_radio)->getTxPower(); + } + bool isReceivingPacket() override { return ((CustomSX1262 *)_radio)->isReceiving(); } diff --git a/src/helpers/radiolib/CustomSX1268.h b/src/helpers/radiolib/CustomSX1268.h index cc541e49f3..406bec1579 100644 --- a/src/helpers/radiolib/CustomSX1268.h +++ b/src/helpers/radiolib/CustomSX1268.h @@ -9,6 +9,15 @@ class CustomSX1268 : public SX1268 { public: CustomSX1268(Module *mod) : SX1268(mod) { } + // A new way to get current power + uint8_t getTxPower() const { return _txPower; } + + // Redefining the power setting method + int16_t setOutputPower(int8_t power) override { + _txPower = power; // saving + return SX1268::setOutputPower(power); // calling the parent + } + #ifdef RP2040_PLATFORM bool std_init(SPIClassRP2040* spi = NULL) #else @@ -89,4 +98,7 @@ class CustomSX1268 : public SX1268 { readRegister(RADIOLIB_SX126X_REG_RX_GAIN, &rxGain, 1); return (rxGain == RADIOLIB_SX126X_RX_GAIN_BOOSTED); } + + private: + uint8_t _txPower = 0; }; \ No newline at end of file diff --git a/src/helpers/radiolib/CustomSX1268Wrapper.h b/src/helpers/radiolib/CustomSX1268Wrapper.h index 54c37ee8aa..ca07d87a5d 100644 --- a/src/helpers/radiolib/CustomSX1268Wrapper.h +++ b/src/helpers/radiolib/CustomSX1268Wrapper.h @@ -11,6 +11,17 @@ class CustomSX1268Wrapper : public RadioLibWrapper { public: CustomSX1268Wrapper(CustomSX1268& radio, mesh::MainBoard& board) : RadioLibWrapper(radio, board) { } + + // Sets the power, returns the value true if successful + bool setPower(int8_t power) { + return ((CustomSX1268 *)_radio)->setOutputPower(power) == RADIOLIB_ERR_NONE; + } + + // A new way to get current power + uint8_t getPower() const { + return ((CustomSX1268 *)_radio)->getTxPower(); + } + bool isReceivingPacket() override { return ((CustomSX1268 *)_radio)->isReceiving(); }