kopia lustrzana https://github.com/meshtastic/firmware
Radio Master 900 Bandit Nano Power output interpolation (#4057)
* DAC and DB values based on dBm using interpolation * Moved getDACandDB funtion Moved getDACandDB funtion up so it won't conflict with RF95_MAX_POWER * Added DAC output to LOG_INFO Added DAC output to LOG_INFO * Make Trunk Happypull/4064/head
rodzic
237944aaf0
commit
a2fb3d23a1
|
@ -17,6 +17,48 @@
|
|||
// if you set power to something higher than 17 or 20 you might fry your board.
|
||||
|
||||
#define POWER_DEFAULT 17 // How much power to use if the user hasn't set a power level
|
||||
#ifdef RADIOMASTER_900_BANDIT_NANO
|
||||
// Structure to hold DAC and DB values
|
||||
typedef struct {
|
||||
uint8_t dac;
|
||||
uint8_t db;
|
||||
} DACDB;
|
||||
|
||||
// Interpolation function
|
||||
DACDB interpolate(uint8_t dbm, uint8_t dbm1, uint8_t dbm2, DACDB val1, DACDB val2) {
|
||||
DACDB result;
|
||||
double fraction = (double)(dbm - dbm1) / (dbm2 - dbm1);
|
||||
result.dac = (uint8_t)(val1.dac + fraction * (val2.dac - val1.dac));
|
||||
result.db = (uint8_t)(val1.db + fraction * (val2.db - val1.db));
|
||||
return result;
|
||||
}
|
||||
|
||||
// Function to find the correct DAC and DB values based on dBm using interpolation
|
||||
DACDB getDACandDB(uint8_t dbm) {
|
||||
// Predefined values
|
||||
static const struct {
|
||||
uint8_t dbm;
|
||||
DACDB values;
|
||||
} dbmToDACDB[] = {
|
||||
{20, {168, 2}}, // 100mW
|
||||
{24, {148, 6}}, // 250mW
|
||||
{27, {128, 9}}, // 500mW
|
||||
{30, {90, 12}} // 1000mW
|
||||
};
|
||||
const int numValues = sizeof(dbmToDACDB) / sizeof(dbmToDACDB[0]);
|
||||
|
||||
// Find the interval dbm falls within and interpolate
|
||||
for (int i = 0; i < numValues - 1; i++) {
|
||||
if (dbm >= dbmToDACDB[i].dbm && dbm <= dbmToDACDB[i + 1].dbm) {
|
||||
return interpolate(dbm, dbmToDACDB[i].dbm, dbmToDACDB[i + 1].dbm, dbmToDACDB[i].values, dbmToDACDB[i + 1].values);
|
||||
}
|
||||
}
|
||||
|
||||
// Return a default value if no match is found and default to 100mW
|
||||
DACDB defaultValue = {168, 2};
|
||||
return defaultValue;
|
||||
}
|
||||
#endif
|
||||
|
||||
RF95Interface::RF95Interface(LockingArduinoHal *hal, RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst,
|
||||
RADIOLIB_PIN_TYPE busy)
|
||||
|
@ -52,6 +94,13 @@ bool RF95Interface::init()
|
|||
{
|
||||
RadioLibInterface::init();
|
||||
|
||||
#ifdef RADIOMASTER_900_BANDIT_NANO
|
||||
// DAC and DB values based on dBm using interpolation
|
||||
DACDB dacDbValues = getDACandDB(power);
|
||||
int8_t powerDAC = dacDbValues.dac;
|
||||
power = dacDbValues.db;
|
||||
#endif
|
||||
|
||||
if (power > RF95_MAX_POWER) // This chip has lower power limits than some
|
||||
power = RF95_MAX_POWER;
|
||||
|
||||
|
@ -67,7 +116,13 @@ bool RF95Interface::init()
|
|||
// enable PA
|
||||
#ifdef RF95_PA_EN
|
||||
#if defined(RF95_PA_DAC_EN)
|
||||
dacWrite(RF95_PA_EN, RF95_PA_LEVEL);
|
||||
#ifdef RADIOMASTER_900_BANDIT_NANO
|
||||
// Use calculated DAC value
|
||||
dacWrite(RF95_PA_EN, powerDAC);
|
||||
#else
|
||||
// Use Value set in /*/variant.h
|
||||
dacWrite(RF95_PA_EN, RF95_PA_LEVEL);
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
@ -107,6 +162,9 @@ bool RF95Interface::init()
|
|||
LOG_INFO("Frequency set to %f\n", getFreq());
|
||||
LOG_INFO("Bandwidth set to %f\n", bw);
|
||||
LOG_INFO("Power output set to %d\n", power);
|
||||
#ifdef RADIOMASTER_900_BANDIT_NANO
|
||||
LOG_INFO("DAC output set to %d\n", powerDAC);
|
||||
#endif
|
||||
|
||||
if (res == RADIOLIB_ERR_NONE)
|
||||
res = lora->setCRC(RADIOLIB_SX126X_LORA_CRC_ON);
|
||||
|
|
Ładowanie…
Reference in New Issue