Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 33 additions & 6 deletions examples/companion_radio/ui-new/UITask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -31,6 +31,8 @@

#include "icons.h"

extern CustomSX1262Wrapper radio_driver;

class SplashScreen : public UIScreen {
UITask* _task;
unsigned long dismiss_after;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 12 additions & 0 deletions src/helpers/radiolib/CustomSX1262.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
};
11 changes: 11 additions & 0 deletions src/helpers/radiolib/CustomSX1262Wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
12 changes: 12 additions & 0 deletions src/helpers/radiolib/CustomSX1268.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
};
11 changes: 11 additions & 0 deletions src/helpers/radiolib/CustomSX1268Wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down