Skip to content

Commit

Permalink
fix implicit conversion from float to double warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
MatejFranceskin committed Jan 15, 2025
1 parent 4f1d367 commit f3276c2
Show file tree
Hide file tree
Showing 36 changed files with 320 additions and 320 deletions.
42 changes: 21 additions & 21 deletions src/modules/CC1101/CC1101.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ int16_t CC1101::transmit(const uint8_t* data, size_t len, uint8_t addr) {

int16_t CC1101::receive(uint8_t* data, size_t len) {
// calculate timeout (500 ms + 400 full max-length packets at current bit rate)
RadioLibTime_t timeout = 500 + (1.0/(this->bitRate))*(RADIOLIB_CC1101_MAX_PACKET_LENGTH*400.0);
RadioLibTime_t timeout = 500 + (1.0f/(this->bitRate))*(RADIOLIB_CC1101_MAX_PACKET_LENGTH*400.0f);

// start reception
int16_t state = startReceive();
Expand Down Expand Up @@ -360,9 +360,9 @@ int16_t CC1101::readData(uint8_t* data, size_t len) {
int16_t CC1101::setFrequency(float freq) {
// check allowed frequency range
#if RADIOLIB_CHECK_PARAMS
if(!(((freq >= 300.0) && (freq <= 348.0)) ||
((freq >= 387.0) && (freq <= 464.0)) ||
((freq >= 779.0) && (freq <= 928.0)))) {
if(!(((freq >= 300.0f) && (freq <= 348.0f)) ||
((freq >= 387.0f) && (freq <= 464.0f)) ||
((freq >= 779.0f) && (freq <= 928.0f)))) {
return(RADIOLIB_ERR_INVALID_FREQUENCY);
}
#endif
Expand All @@ -372,7 +372,7 @@ int16_t CC1101::setFrequency(float freq) {

//set carrier frequency
uint32_t base = 1;
uint32_t FRF = (freq * (base << 16)) / 26.0;
uint32_t FRF = (freq * (base << 16)) / 26.0f;
int16_t state = SPIsetRegValue(RADIOLIB_CC1101_REG_FREQ2, (FRF & 0xFF0000) >> 16, 7, 0);
state |= SPIsetRegValue(RADIOLIB_CC1101_REG_FREQ1, (FRF & 0x00FF00) >> 8, 7, 0);
state |= SPIsetRegValue(RADIOLIB_CC1101_REG_FREQ0, FRF & 0x0000FF, 7, 0);
Expand All @@ -386,15 +386,15 @@ int16_t CC1101::setFrequency(float freq) {
}

int16_t CC1101::setBitRate(float br) {
RADIOLIB_CHECK_RANGE(br, 0.025, 600.0, RADIOLIB_ERR_INVALID_BIT_RATE);
RADIOLIB_CHECK_RANGE(br, 0.025f, 600.0f, RADIOLIB_ERR_INVALID_BIT_RATE);

// set mode to standby
SPIsendCommand(RADIOLIB_CC1101_CMD_IDLE);

// calculate exponent and mantissa values
uint8_t e = 0;
uint8_t m = 0;
getExpMant(br * 1000.0, 256, 28, 14, e, m);
getExpMant(br * 1000.0f, 256, 28, 14, e, m);

// set bit rate value
int16_t state = SPIsetRegValue(RADIOLIB_CC1101_REG_MDMCFG4, e, 3, 0);
Expand All @@ -415,16 +415,16 @@ int16_t CC1101::setBitRateTolerance(uint8_t brt) {
}

int16_t CC1101::setRxBandwidth(float rxBw) {
RADIOLIB_CHECK_RANGE(rxBw, 58.0, 812.0, RADIOLIB_ERR_INVALID_RX_BANDWIDTH);
RADIOLIB_CHECK_RANGE(rxBw, 58.0f, 812.0f, RADIOLIB_ERR_INVALID_RX_BANDWIDTH);

// set mode to standby
SPIsendCommand(RADIOLIB_CC1101_CMD_IDLE);

// calculate exponent and mantissa values
for(int8_t e = 3; e >= 0; e--) {
for(int8_t m = 3; m >= 0; m --) {
float point = (RADIOLIB_CC1101_CRYSTAL_FREQ * 1000000.0)/(8 * (m + 4) * ((uint32_t)1 << e));
if(fabs((rxBw * 1000.0) - point) <= 1000) {
float point = (RADIOLIB_CC1101_CRYSTAL_FREQ * 1000000.0f)/(8 * (m + 4) * ((uint32_t)1 << e));
if(fabs((rxBw * 1000.0f - point) <= 1000.0f)) {
// set Rx channel filter bandwidth
return(SPIsetRegValue(RADIOLIB_CC1101_REG_MDMCFG4, (e << 6) | (m << 4), 7, 4));
}
Expand Down Expand Up @@ -456,13 +456,13 @@ int16_t CC1101::autoSetRxBandwidth() {
int16_t CC1101::setFrequencyDeviation(float freqDev) {
// set frequency deviation to lowest available setting (required for digimodes)
float newFreqDev = freqDev;
if(freqDev < 0.0) {
newFreqDev = 1.587;
if(freqDev < 0.0f) {
newFreqDev = 1.587f;
}

// check range unless 0 (special value)
if (freqDev != 0) {
RADIOLIB_CHECK_RANGE(newFreqDev, 1.587, 380.8, RADIOLIB_ERR_INVALID_FREQUENCY_DEVIATION);
RADIOLIB_CHECK_RANGE(newFreqDev, 1.587f, 380.8f, RADIOLIB_ERR_INVALID_FREQUENCY_DEVIATION);
}

// set mode to standby
Expand All @@ -471,7 +471,7 @@ int16_t CC1101::setFrequencyDeviation(float freqDev) {
// calculate exponent and mantissa values
uint8_t e = 0;
uint8_t m = 0;
getExpMant(newFreqDev * 1000.0, 8, 17, 7, e, m);
getExpMant(newFreqDev * 1000.0f, 8, 17, 7, e, m);

// set frequency deviation value
int16_t state = SPIsetRegValue(RADIOLIB_CC1101_REG_DEVIATN, (e << 4), 6, 4);
Expand Down Expand Up @@ -500,7 +500,7 @@ int16_t CC1101::getFrequencyDeviation(float *freqDev) {
//
// freqDev = (fXosc / 2^17) * (8 + m) * 2^e
//
*freqDev = (1000.0 / (uint32_t(1) << 17)) - (8 + m) * (uint32_t(1) << e);
*freqDev = (1000.0f / (uint32_t(1) << 17)) - (8 + m) * (uint32_t(1) << e);

return(RADIOLIB_ERR_NONE);
}
Expand Down Expand Up @@ -564,13 +564,13 @@ int16_t CC1101::checkOutputPower(int8_t power, int8_t* clipped, uint8_t* raw) {

// round to the known frequency settings
uint8_t f;
if(this->frequency < 374.0) {
if(this->frequency < 374.0f) {
// 315 MHz
f = 0;
} else if(this->frequency < 650.5) {
} else if(this->frequency < 650.5f) {
// 434 MHz
f = 1;
} else if(this->frequency < 891.5) {
} else if(this->frequency < 891.5f) {
// 868 MHz
f = 2;
} else {
Expand Down Expand Up @@ -723,9 +723,9 @@ float CC1101::getRSSI() {

if(!this->directModeEnabled) {
if(this->rawRSSI >= 128) {
rssi = (((float)this->rawRSSI - 256.0)/2.0) - 74.0;
rssi = (((float)this->rawRSSI - 256.0f)/2.0f) - 74.0f;
} else {
rssi = (((float)this->rawRSSI)/2.0) - 74.0;
rssi = (((float)this->rawRSSI)/2.0f) - 74.0f;
}
} else {
uint8_t rawRssi = SPIreadRegister(RADIOLIB_CC1101_REG_RSSI);
Expand Down Expand Up @@ -1070,7 +1070,7 @@ int16_t CC1101::directMode(bool sync) {

void CC1101::getExpMant(float target, uint16_t mantOffset, uint8_t divExp, uint8_t expMax, uint8_t& exp, uint8_t& mant) {
// get table origin point (exp = 0, mant = 0)
float origin = (mantOffset * RADIOLIB_CC1101_CRYSTAL_FREQ * 1000000.0)/((uint32_t)1 << divExp);
float origin = (mantOffset * RADIOLIB_CC1101_CRYSTAL_FREQ * 1000000.0f)/((uint32_t)1 << divExp);

// iterate over possible exponent values
for(int8_t e = expMax; e >= 0; e--) {
Expand Down
2 changes: 1 addition & 1 deletion src/modules/CC1101/CC1101.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// CC1101 physical layer properties
#define RADIOLIB_CC1101_FREQUENCY_STEP_SIZE 396.7285156
#define RADIOLIB_CC1101_MAX_PACKET_LENGTH 64
#define RADIOLIB_CC1101_CRYSTAL_FREQ 26.0
#define RADIOLIB_CC1101_CRYSTAL_FREQ 26.0f
#define RADIOLIB_CC1101_DIV_EXPONENT 16

// CC1101 SPI commands
Expand Down
10 changes: 5 additions & 5 deletions src/modules/LLCC68/LLCC68.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ int16_t LLCC68::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t sync
}

int16_t LLCC68::setBandwidth(float bw) {
RADIOLIB_CHECK_RANGE(bw, 100.0, 510.0, RADIOLIB_ERR_INVALID_BANDWIDTH);
RADIOLIB_CHECK_RANGE(bw, 100.0f, 510.0f, RADIOLIB_ERR_INVALID_BANDWIDTH);
return(SX1262::setBandwidth(bw));
}

Expand Down Expand Up @@ -95,14 +95,14 @@ int16_t LLCC68::checkDataRate(DataRate_t dr) {
// select interpretation based on active modem
uint8_t modem = this->getPacketType();
if(modem == RADIOLIB_SX126X_PACKET_TYPE_GFSK) {
RADIOLIB_CHECK_RANGE(dr.fsk.bitRate, 0.6, 300.0, RADIOLIB_ERR_INVALID_BIT_RATE);
RADIOLIB_CHECK_RANGE(dr.fsk.freqDev, 0.6, 200.0, RADIOLIB_ERR_INVALID_FREQUENCY_DEVIATION);
RADIOLIB_CHECK_RANGE(dr.fsk.bitRate, 0.6f, 300.0f, RADIOLIB_ERR_INVALID_BIT_RATE);
RADIOLIB_CHECK_RANGE(dr.fsk.freqDev, 0.6f, 200.0f, RADIOLIB_ERR_INVALID_FREQUENCY_DEVIATION);
return(RADIOLIB_ERR_NONE);

} else if(modem == RADIOLIB_SX126X_PACKET_TYPE_LORA) {
RADIOLIB_CHECK_RANGE(dr.lora.bandwidth, 100.0, 510.0, RADIOLIB_ERR_INVALID_BANDWIDTH);
RADIOLIB_CHECK_RANGE(dr.lora.bandwidth, 100.0f, 510.0f, RADIOLIB_ERR_INVALID_BANDWIDTH);
RADIOLIB_CHECK_RANGE(dr.lora.codingRate, 5, 8, RADIOLIB_ERR_INVALID_CODING_RATE);
uint8_t bw_div2 = dr.lora.bandwidth / 2 + 0.01;
uint8_t bw_div2 = dr.lora.bandwidth / 2 + 0.01f;
switch (bw_div2) {
case 62: // 125.0:
RADIOLIB_CHECK_RANGE(dr.lora.spreadingFactor, 5, 9, RADIOLIB_ERR_INVALID_SPREADING_FACTOR);
Expand Down
2 changes: 1 addition & 1 deletion src/modules/LR11x0/LR1110.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ int16_t LR1110::setFrequency(float freq) {
}

int16_t LR1110::setFrequency(float freq, bool skipCalibration, float band) {
RADIOLIB_CHECK_RANGE(freq, 150.0, 960.0, RADIOLIB_ERR_INVALID_FREQUENCY);
RADIOLIB_CHECK_RANGE(freq, 150.0f, 960.0f, RADIOLIB_ERR_INVALID_FREQUENCY);

// check if we need to recalibrate image
int16_t state;
Expand Down
10 changes: 5 additions & 5 deletions src/modules/LR11x0/LR1120.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ LR1120::LR1120(Module* mod) : LR11x0(mod) {

int16_t LR1120::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, float tcxoVoltage) {
// execute common part
int16_t state = LR11x0::begin(bw, sf, cr, syncWord, preambleLength, tcxoVoltage, freq > 1000.0);
int16_t state = LR11x0::begin(bw, sf, cr, syncWord, preambleLength, tcxoVoltage, freq > 1000.0f);
RADIOLIB_ASSERT(state);

// configure publicly accessible settings
Expand Down Expand Up @@ -52,9 +52,9 @@ int16_t LR1120::setFrequency(float freq) {

int16_t LR1120::setFrequency(float freq, bool skipCalibration, float band) {
#if RADIOLIB_CHECK_PARAMS
if(!(((freq >= 150.0) && (freq <= 960.0)) ||
((freq >= 1900.0) && (freq <= 2200.0)) ||
((freq >= 2400.0) && (freq <= 2500.0)))) {
if(!(((freq >= 150.0f) && (freq <= 960.0f)) ||
((freq >= 1900.0f) && (freq <= 2200.0f)) ||
((freq >= 2400.0f) && (freq <= 2500.0f)))) {
return(RADIOLIB_ERR_INVALID_FREQUENCY);
}
#endif
Expand All @@ -70,7 +70,7 @@ int16_t LR1120::setFrequency(float freq, bool skipCalibration, float band) {
state = LR11x0::setRfFrequency((uint32_t)(freq*1000000.0f));
RADIOLIB_ASSERT(state);
this->freqMHz = freq;
this->highFreq = (freq > 1000.0);
this->highFreq = (freq > 1000.0f);
return(RADIOLIB_ERR_NONE);
}

Expand Down
Loading

0 comments on commit f3276c2

Please sign in to comment.