Fixes from cppcheck scan
This commit is contained in:
parent
d066f616b1
commit
7e62dbd1d8
3 changed files with 35 additions and 27 deletions
|
@ -15,7 +15,7 @@
|
||||||
*/
|
*/
|
||||||
class ISerial {
|
class ISerial {
|
||||||
public:
|
public:
|
||||||
ISerial(Module* mod);
|
explicit ISerial(Module* mod);
|
||||||
|
|
||||||
void begin(long);
|
void begin(long);
|
||||||
bool listen();
|
bool listen();
|
||||||
|
|
|
@ -9,6 +9,7 @@ Module::Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rs
|
||||||
_spi = &RADIOLIB_DEFAULT_SPI;
|
_spi = &RADIOLIB_DEFAULT_SPI;
|
||||||
_spiSettings = SPISettings(2000000, MSBFIRST, SPI_MODE0);
|
_spiSettings = SPISettings(2000000, MSBFIRST, SPI_MODE0);
|
||||||
_initInterface = true;
|
_initInterface = true;
|
||||||
|
ModuleSerial = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Module::Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE gpio) {
|
Module::Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE gpio) {
|
||||||
|
@ -20,9 +21,10 @@ Module::Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rs
|
||||||
_spi = &RADIOLIB_DEFAULT_SPI;
|
_spi = &RADIOLIB_DEFAULT_SPI;
|
||||||
_spiSettings = SPISettings(2000000, MSBFIRST, SPI_MODE0);
|
_spiSettings = SPISettings(2000000, MSBFIRST, SPI_MODE0);
|
||||||
_initInterface = true;
|
_initInterface = true;
|
||||||
|
ModuleSerial = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Module::Module(RADIOLIB_PIN_TYPE rx, RADIOLIB_PIN_TYPE tx, HardwareSerial* useSer, RADIOLIB_PIN_TYPE rst) {
|
Module::Module(RADIOLIB_PIN_TYPE rx, RADIOLIB_PIN_TYPE tx, HardwareSerial* serial, RADIOLIB_PIN_TYPE rst) {
|
||||||
_cs = RADIOLIB_NC;
|
_cs = RADIOLIB_NC;
|
||||||
_rx = rx;
|
_rx = rx;
|
||||||
_tx = tx;
|
_tx = tx;
|
||||||
|
@ -31,10 +33,10 @@ Module::Module(RADIOLIB_PIN_TYPE rx, RADIOLIB_PIN_TYPE tx, HardwareSerial* useSe
|
||||||
_initInterface = true;
|
_initInterface = true;
|
||||||
|
|
||||||
#ifdef RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED
|
#ifdef RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED
|
||||||
ModuleSerial = useSer;
|
ModuleSerial = serial;
|
||||||
#else
|
#else
|
||||||
ModuleSerial = new SoftwareSerial(_rx, _tx);
|
ModuleSerial = new SoftwareSerial(_rx, _tx);
|
||||||
(void)useSer;
|
(void)serial;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,6 +49,7 @@ Module::Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rs
|
||||||
_spi = &spi;
|
_spi = &spi;
|
||||||
_spiSettings = spiSettings;
|
_spiSettings = spiSettings;
|
||||||
_initInterface = false;
|
_initInterface = false;
|
||||||
|
ModuleSerial = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Module::Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE gpio, SPIClass& spi, SPISettings spiSettings) {
|
Module::Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE gpio, SPIClass& spi, SPISettings spiSettings) {
|
||||||
|
@ -58,9 +61,10 @@ Module::Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rs
|
||||||
_spi = &spi;
|
_spi = &spi;
|
||||||
_spiSettings = spiSettings;
|
_spiSettings = spiSettings;
|
||||||
_initInterface = false;
|
_initInterface = false;
|
||||||
|
ModuleSerial = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Module::Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE rx, RADIOLIB_PIN_TYPE tx, SPIClass& spi, SPISettings spiSettings, HardwareSerial* useSer) {
|
Module::Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE rx, RADIOLIB_PIN_TYPE tx, SPIClass& spi, SPISettings spiSettings, HardwareSerial* serial) {
|
||||||
_cs = cs;
|
_cs = cs;
|
||||||
_rx = rx;
|
_rx = rx;
|
||||||
_tx = tx;
|
_tx = tx;
|
||||||
|
@ -71,10 +75,10 @@ Module::Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rs
|
||||||
_initInterface = false;
|
_initInterface = false;
|
||||||
|
|
||||||
#ifdef RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED
|
#ifdef RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED
|
||||||
ModuleSerial = useSer;
|
ModuleSerial = serial;
|
||||||
#else
|
#else
|
||||||
ModuleSerial = new SoftwareSerial(_rx, _tx);
|
ModuleSerial = new SoftwareSerial(_rx, _tx);
|
||||||
(void)useSer;
|
(void)serial;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -259,18 +263,22 @@ void Module::SPItransfer(uint8_t cmd, uint8_t reg, uint8_t* dataOut, uint8_t* da
|
||||||
|
|
||||||
// send data or get response
|
// send data or get response
|
||||||
if(cmd == SPIwriteCommand) {
|
if(cmd == SPIwriteCommand) {
|
||||||
|
if(dataOut != NULL) {
|
||||||
for(size_t n = 0; n < numBytes; n++) {
|
for(size_t n = 0; n < numBytes; n++) {
|
||||||
_spi->transfer(dataOut[n]);
|
_spi->transfer(dataOut[n]);
|
||||||
RADIOLIB_VERBOSE_PRINT(dataOut[n], HEX);
|
RADIOLIB_VERBOSE_PRINT(dataOut[n], HEX);
|
||||||
RADIOLIB_VERBOSE_PRINT('\t');
|
RADIOLIB_VERBOSE_PRINT('\t');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else if (cmd == SPIreadCommand) {
|
} else if (cmd == SPIreadCommand) {
|
||||||
|
if(dataIn != NULL) {
|
||||||
for(size_t n = 0; n < numBytes; n++) {
|
for(size_t n = 0; n < numBytes; n++) {
|
||||||
dataIn[n] = _spi->transfer(0x00);
|
dataIn[n] = _spi->transfer(0x00);
|
||||||
RADIOLIB_VERBOSE_PRINT(dataIn[n], HEX);
|
RADIOLIB_VERBOSE_PRINT(dataIn[n], HEX);
|
||||||
RADIOLIB_VERBOSE_PRINT('\t');
|
RADIOLIB_VERBOSE_PRINT('\t');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
RADIOLIB_VERBOSE_PRINTLN();
|
RADIOLIB_VERBOSE_PRINTLN();
|
||||||
|
|
||||||
// release CS
|
// release CS
|
||||||
|
|
24
src/Module.h
24
src/Module.h
|
@ -21,18 +21,18 @@ class Module {
|
||||||
/*!
|
/*!
|
||||||
\brief UART-based module constructor.
|
\brief UART-based module constructor.
|
||||||
|
|
||||||
\param tx Arduino pin to be used as Tx pin for SoftwareSerial communication.
|
|
||||||
|
|
||||||
\param rx Arduino pin to be used as Rx pin for SoftwareSerial communication.
|
\param rx Arduino pin to be used as Rx pin for SoftwareSerial communication.
|
||||||
|
|
||||||
|
\param tx Arduino pin to be used as Tx pin for SoftwareSerial communication.
|
||||||
|
|
||||||
\param serial HardwareSerial to be used on platforms that do not support SoftwareSerial. Defaults to Serial1.
|
\param serial HardwareSerial to be used on platforms that do not support SoftwareSerial. Defaults to Serial1.
|
||||||
|
|
||||||
\param rst Arduino pin to be used as hardware reset for the module. Defaults to NC (unused).
|
\param rst Arduino pin to be used as hardware reset for the module. Defaults to NC (unused).
|
||||||
*/
|
*/
|
||||||
#ifdef RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED
|
#ifdef RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED
|
||||||
Module(RADIOLIB_PIN_TYPE tx, RADIOLIB_PIN_TYPE rx, HardwareSerial* serial = &RADIOLIB_HARDWARE_SERIAL_PORT, RADIOLIB_PIN_TYPE rst = RADIOLIB_NC);
|
Module(RADIOLIB_PIN_TYPE rx, RADIOLIB_PIN_TYPE tx, HardwareSerial* serial = &RADIOLIB_HARDWARE_SERIAL_PORT, RADIOLIB_PIN_TYPE rst = RADIOLIB_NC);
|
||||||
#else
|
#else
|
||||||
Module(RADIOLIB_PIN_TYPE tx, RADIOLIB_PIN_TYPE rx, HardwareSerial* serial = nullptr, RADIOLIB_PIN_TYPE rst = RADIOLIB_NC);
|
Module(RADIOLIB_PIN_TYPE rx, RADIOLIB_PIN_TYPE tx, HardwareSerial* serial = nullptr, RADIOLIB_PIN_TYPE rst = RADIOLIB_NC);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -408,18 +408,18 @@ class Module {
|
||||||
#ifndef RADIOLIB_GODMODE
|
#ifndef RADIOLIB_GODMODE
|
||||||
private:
|
private:
|
||||||
#endif
|
#endif
|
||||||
RADIOLIB_PIN_TYPE _cs;
|
RADIOLIB_PIN_TYPE _cs = RADIOLIB_NC;
|
||||||
RADIOLIB_PIN_TYPE _tx;
|
RADIOLIB_PIN_TYPE _tx = RADIOLIB_NC;
|
||||||
RADIOLIB_PIN_TYPE _rx;
|
RADIOLIB_PIN_TYPE _rx = RADIOLIB_NC;
|
||||||
RADIOLIB_PIN_TYPE _irq;
|
RADIOLIB_PIN_TYPE _irq = RADIOLIB_NC;
|
||||||
RADIOLIB_PIN_TYPE _rst;
|
RADIOLIB_PIN_TYPE _rst = RADIOLIB_NC;
|
||||||
|
|
||||||
bool _initInterface;
|
bool _initInterface = false;
|
||||||
SPIClass* _spi;
|
SPIClass* _spi = NULL;
|
||||||
SPISettings _spiSettings;
|
SPISettings _spiSettings;
|
||||||
|
|
||||||
bool _useRfSwitch = false;
|
bool _useRfSwitch = false;
|
||||||
RADIOLIB_PIN_TYPE _rxEn, _txEn;
|
RADIOLIB_PIN_TYPE _rxEn = RADIOLIB_NC, _txEn = RADIOLIB_NC;
|
||||||
|
|
||||||
uint32_t _ATtimeout = 15000;
|
uint32_t _ATtimeout = 15000;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue