Merge branch 'master' into dev

This commit is contained in:
geeksville
2020-09-15 21:13:24 -07:00
7 changed files with 54 additions and 16 deletions

View File

@@ -251,7 +251,7 @@ static void drawGPScoordinates(OLEDDisplay *display, int16_t x, int16_t y, const
displayLine = "No GPS Lock";
display->drawString(x + (SCREEN_WIDTH - (display->getStringWidth(displayLine))) / 2, y, displayLine);
} else {
char coordinateLine[20];
char coordinateLine[22];
sprintf(coordinateLine, "%f %f", gps->getLatitude() * 1e-7, gps->getLongitude() * 1e-7);
display->drawString(x + (SCREEN_WIDTH - (display->getStringWidth(coordinateLine))) / 2, y, coordinateLine);
}

View File

@@ -3,9 +3,11 @@
#include "RadioLibRF95.h"
#include <configuration.h>
#define MAX_POWER 17
#define MAX_POWER 20
// if we use 20 we are limited to 1% duty cycle or hw might overheat. For continuous operation set a limit of 17
#define POWER_DEFAULT 17 // How much power to use if the user hasn't set a power level
RF95Interface::RF95Interface(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, SPIClass &spi)
: RadioLibInterface(cs, irq, rst, 0, spi)
{
@@ -32,9 +34,15 @@ bool RF95Interface::init()
RadioLibInterface::init();
applyModemConfig();
if (power == 0)
power = POWER_DEFAULT;
if (power > MAX_POWER) // This chip has lower power limits than some
power = MAX_POWER;
limitPower();
iface = lora = new RadioLibRF95(&module);
#ifdef RF95_TCXO

View File

@@ -106,7 +106,7 @@ bool RadioInterface::init()
* djb2 by Dan Bernstein.
* http://www.cse.yorku.ca/~oz/hash.html
*/
unsigned long hash(char *str)
unsigned long hash(const char *str)
{
unsigned long hash = 5381;
int c;
@@ -117,8 +117,6 @@ unsigned long hash(char *str)
return hash;
}
#define POWER_DEFAULT 17
/**
* Pull our channel settings etc... from protobufs to the dumb interface settings
*/
@@ -128,8 +126,6 @@ void RadioInterface::applyModemConfig()
// No Sync Words in LORA mode
power = channelSettings.tx_power;
if (power == 0)
power = POWER_DEFAULT;
// If user has manually specified a channel num, then use that, otherwise generate one by hashing the name
int channel_num = (channelSettings.channel_num ? channelSettings.channel_num - 1 : hash(channelSettings.name)) % NUM_CHANNELS;
@@ -139,6 +135,25 @@ void RadioInterface::applyModemConfig()
power);
}
/**
* Some regulatory regions limit xmit power.
* This function should be called by subclasses after setting their desired power. It might lower it
*/
void RadioInterface::limitPower()
{
uint8_t maxPower = 255; // No limit
#ifdef HW_VERSION_JP
maxPower = 13; // See https://github.com/meshtastic/Meshtastic-device/issues/346
#endif
if (power > maxPower) {
DEBUG_MSG("Lowering transmit power because of regulatory limits\n");
power = maxPower;
}
DEBUG_MSG("Set radio: final power level=%d\n", power);
}
ErrorCode SimRadio::send(MeshPacket *p)
{
DEBUG_MSG("SimRadio.send\n");

View File

@@ -119,6 +119,12 @@ class RadioInterface : protected concurrency::NotifiedWorkerThread
virtual void loop() {} // Idle processing
/**
* Some regulatory regions limit xmit power.
* This function should be called by subclasses after setting their desired power. It might lower it
*/
void limitPower();
/**
* Convert our modemConfig enum into wf, sf, etc...
*

View File

@@ -37,8 +37,15 @@ bool SX1262Interface::init()
bool useRegulatorLDO = false; // Seems to depend on the connection to pin 9/DCC_SW - if an inductor DCDC?
applyModemConfig();
if (power == 0)
power = 22;
if (power > 22) // This chip has lower power limits than some
power = 22;
limitPower();
int res = lora.begin(freq, bw, sf, cr, syncWord, power, currentLimit, preambleLength, tcxoVoltage, useRegulatorLDO);
DEBUG_MSG("SX1262 init result %d\n", res);