From 51eb51feedba3098d5895cd5696ebdcea90722cf Mon Sep 17 00:00:00 2001 From: VladelfPv Date: Thu, 2 Apr 2026 09:36:09 +0300 Subject: [PATCH 1/4] -A new way to determine the current capacity SX126X -Redefining the power setting method SX126X -A new way to display power on the screen --- examples/companion_radio/ui-new/UITask.cpp | 26 +++++++++++++++++----- src/helpers/radiolib/CustomSX1262.h | 12 ++++++++++ src/helpers/radiolib/CustomSX1262Wrapper.h | 11 +++++++++ src/helpers/radiolib/CustomSX1268.h | 12 ++++++++++ src/helpers/radiolib/CustomSX1268Wrapper.h | 11 +++++++++ 5 files changed, 67 insertions(+), 5 deletions(-) diff --git a/examples/companion_radio/ui-new/UITask.cpp b/examples/companion_radio/ui-new/UITask.cpp index 265532be0b..226ab3164f 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 60000 // 60 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; @@ -265,7 +267,7 @@ class HomeScreen : public UIScreen { // tx power, noise floor display.setCursor(0, 42); - sprintf(tmp, "TX: %ddBm", _node_prefs->tx_power_dbm); + sprintf(tmp, "TX: %ddBm", radio_driver.getPower()); display.print(tmp); display.setCursor(0, 53); sprintf(tmp, "Noise floor: %d", radio_driver.getNoiseFloor()); @@ -604,13 +606,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 +779,20 @@ void UITask::loop() { next_backlight_btn_check = millis() + 300; } #endif +#if defined(PIN_POWER_BTN) + static unsigned long lastSwitchCheck = 0; + static uint8_t lastSwitchPower = 0; + + // Проверяем переключатель раз в 500 мс + if (millis() - lastSwitchCheck > 500) { + uint8_t newPower = board.getSwitchPower(); + if (newPower != lastSwitchPower) { + radio_driver.setPower(newPower); + lastSwitchPower = newPower; + } + lastSwitchCheck = millis(); + } +#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(); } From 463123dc003c96594ca0e0546babc9350607e2cb Mon Sep 17 00:00:00 2001 From: VladelfPv Date: Fri, 3 Apr 2026 19:32:22 +0300 Subject: [PATCH 2/4] -Added PIN_POWER_BTN button for switching 10dBm and 20dBm power -The battery value in volts is displayed on the screen --- examples/companion_radio/ui-new/UITask.cpp | 25 +++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/examples/companion_radio/ui-new/UITask.cpp b/examples/companion_radio/ui-new/UITask.cpp index 265532be0b..0d67c6f2c1 100644 --- a/examples/companion_radio/ui-new/UITask.cpp +++ b/examples/companion_radio/ui-new/UITask.cpp @@ -263,10 +263,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); 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); @@ -777,6 +784,22 @@ void UITask::loop() { next_backlight_btn_check = millis() + 300; } #endif +#if defined(PIN_POWER_BTN) + 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; + } +#endif if (c != 0 && curr) { curr->handleInput(c); From 3840506d84c93787c544b79a0102cae27fb635d4 Mon Sep 17 00:00:00 2001 From: VladelfPv Date: Fri, 3 Apr 2026 19:39:41 +0300 Subject: [PATCH 3/4] backlight time update --- examples/companion_radio/ui-new/UITask.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/companion_radio/ui-new/UITask.cpp b/examples/companion_radio/ui-new/UITask.cpp index da79b9c701..2a50c52ef2 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 60000 // 60 seconds + #define AUTO_OFF_MILLIS 15000 // 15 seconds #endif #define BOOT_SCREEN_MILLIS 3000 // 3 seconds From 90142c74477265b08d5a3e3145e85f8304716e2f Mon Sep 17 00:00:00 2001 From: VladelfPv Date: Sun, 5 Apr 2026 11:31:21 +0300 Subject: [PATCH 4/4] Update UITask.cpp --- examples/companion_radio/ui-new/UITask.cpp | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/examples/companion_radio/ui-new/UITask.cpp b/examples/companion_radio/ui-new/UITask.cpp index 2a50c52ef2..aa70e6b86e 100644 --- a/examples/companion_radio/ui-new/UITask.cpp +++ b/examples/companion_radio/ui-new/UITask.cpp @@ -801,18 +801,6 @@ void UITask::loop() { MESH_DEBUG_PRINTLN("INFO: %d dBm", newPower); } next_power_chck = millis() + 300; -======= - static unsigned long lastSwitchCheck = 0; - static uint8_t lastSwitchPower = 0; - - // Проверяем переключатель раз в 500 мс - if (millis() - lastSwitchCheck > 500) { - uint8_t newPower = board.getSwitchPower(); - if (newPower != lastSwitchPower) { - radio_driver.setPower(newPower); - lastSwitchPower = newPower; - } - lastSwitchCheck = millis(); >>>>>>> 51eb51feedba3098d5895cd5696ebdcea90722cf } #endif