[SX128x] Changed shaping datatype to uint8_t

This commit is contained in:
jgromes 2020-07-06 08:53:12 +02:00
parent 7dc7f4d76c
commit be346eb6aa
2 changed files with 24 additions and 20 deletions

View file

@ -56,7 +56,7 @@ int16_t SX128x::begin(float freq, float bw, uint8_t sf, uint8_t cr, int8_t power
return(state); return(state);
} }
int16_t SX128x::beginGFSK(float freq, uint16_t br, float freqDev, int8_t power, uint16_t preambleLength, float dataShaping) { int16_t SX128x::beginGFSK(float freq, uint16_t br, float freqDev, int8_t power, uint16_t preambleLength, uint8_t dataShaping) {
// set module properties // set module properties
_mod->init(RADIOLIB_USE_SPI); _mod->init(RADIOLIB_USE_SPI);
Module::pinMode(_mod->getIrq(), INPUT); Module::pinMode(_mod->getIrq(), INPUT);
@ -115,7 +115,7 @@ int16_t SX128x::beginGFSK(float freq, uint16_t br, float freqDev, int8_t power,
return(state); return(state);
} }
int16_t SX128x::beginBLE(float freq, uint16_t br, float freqDev, int8_t power, float dataShaping) { int16_t SX128x::beginBLE(float freq, uint16_t br, float freqDev, int8_t power, uint8_t dataShaping) {
// set module properties // set module properties
_mod->init(RADIOLIB_USE_SPI); _mod->init(RADIOLIB_USE_SPI);
Module::pinMode(_mod->getIrq(), INPUT); Module::pinMode(_mod->getIrq(), INPUT);
@ -163,7 +163,7 @@ int16_t SX128x::beginBLE(float freq, uint16_t br, float freqDev, int8_t power, f
return(state); return(state);
} }
int16_t SX128x::beginFLRC(float freq, uint16_t br, uint8_t cr, int8_t power, uint16_t preambleLength, float dataShaping) { int16_t SX128x::beginFLRC(float freq, uint16_t br, uint8_t cr, int8_t power, uint16_t preambleLength, uint8_t dataShaping) {
// set module properties // set module properties
_mod->init(RADIOLIB_USE_SPI); _mod->init(RADIOLIB_USE_SPI);
Module::pinMode(_mod->getIrq(), INPUT); Module::pinMode(_mod->getIrq(), INPUT);
@ -815,23 +815,26 @@ int16_t SX128x::setFrequencyDeviation(float freqDev) {
return(setModulationParams(_br, _modIndex, _shaping)); return(setModulationParams(_br, _modIndex, _shaping));
} }
int16_t SX128x::setDataShaping(float dataShaping) { int16_t SX128x::setDataShaping(uint8_t sh) {
// check active modem // check active modem
uint8_t modem = getPacketType(); uint8_t modem = getPacketType();
if(!((modem == SX128X_PACKET_TYPE_GFSK) || (modem == SX128X_PACKET_TYPE_BLE) || (modem == SX128X_PACKET_TYPE_FLRC))) { if(!((modem == SX128X_PACKET_TYPE_GFSK) || (modem == SX128X_PACKET_TYPE_BLE) || (modem == SX128X_PACKET_TYPE_FLRC))) {
return(ERR_WRONG_MODEM); return(ERR_WRONG_MODEM);
} }
// check allowed values // set data shaping
dataShaping *= 10.0; switch(sh) {
if(abs(dataShaping - 0.0) <= 0.001) { case RADIOLIB_SHAPING_NONE:
_shaping = SX128X_BLE_GFSK_BT_OFF; _shaping = SX128X_BLE_GFSK_BT_OFF;
} else if(abs(dataShaping - 5.0) <= 0.001) { break;
_shaping = SX128X_BLE_GFSK_BT_0_5; case RADIOLIB_SHAPING_0_5:
} else if(abs(dataShaping - 10.0) <= 0.001) { _shaping = SX128X_BLE_GFSK_BT_0_5;
_shaping = SX128X_BLE_GFSK_BT_1_0; break;
} else { case RADIOLIB_SHAPING_1_0:
return(ERR_INVALID_DATA_SHAPING); _shaping = SX128X_BLE_GFSK_BT_1_0;
break;
default:
return(ERR_INVALID_DATA_SHAPING);
} }
// update modulation parameters // update modulation parameters

View file

@ -385,11 +385,11 @@ class SX128x: public PhysicalLayer {
\parma preambleLength FSK preamble length in bits. Defaults to 16 bits. \parma preambleLength FSK preamble length in bits. Defaults to 16 bits.
\param dataShaping Time-bandwidth product of the Gaussian filter to be used for shaping. Defaults to 0.5. \param dataShaping Time-bandwidth product of the Gaussian filter to be used for shaping. Defaults to RADIOLIB_SHAPING_0_5.
\returns \ref status_codes \returns \ref status_codes
*/ */
int16_t beginGFSK(float freq = 2400.0, uint16_t br = 800, float freqDev = 400.0, int8_t power = 10, uint16_t preambleLength = 16, float dataShaping = 0.5); int16_t beginGFSK(float freq = 2400.0, uint16_t br = 800, float freqDev = 400.0, int8_t power = 10, uint16_t preambleLength = 16, uint8_t dataShaping = RADIOLIB_SHAPING_0_5);
/*! /*!
\brief Initialization method for BLE modem. \brief Initialization method for BLE modem.
@ -406,7 +406,7 @@ class SX128x: public PhysicalLayer {
\returns \ref status_codes \returns \ref status_codes
*/ */
int16_t beginBLE(float freq = 2400.0, uint16_t br = 800, float freqDev = 400.0, int8_t power = 10, float dataShaping = 0.5); int16_t beginBLE(float freq = 2400.0, uint16_t br = 800, float freqDev = 400.0, int8_t power = 10, uint8_t dataShaping = RADIOLIB_SHAPING_0_5);
/*! /*!
\brief Initialization method for FLRC modem. \brief Initialization method for FLRC modem.
@ -425,7 +425,7 @@ class SX128x: public PhysicalLayer {
\returns \ref status_codes \returns \ref status_codes
*/ */
int16_t beginFLRC(float freq = 2400.0, uint16_t br = 650, uint8_t cr = 3, int8_t power = 10, uint16_t preambleLength = 16, float dataShaping = 0.5); int16_t beginFLRC(float freq = 2400.0, uint16_t br = 650, uint8_t cr = 3, int8_t power = 10, uint16_t preambleLength = 16, uint8_t dataShaping = RADIOLIB_SHAPING_0_5);
/*! /*!
\brief Reset method. Will reset the chip to the default state using RST pin. \brief Reset method. Will reset the chip to the default state using RST pin.
@ -637,13 +637,14 @@ class SX128x: public PhysicalLayer {
int16_t setFrequencyDeviation(float freqDev) override; int16_t setFrequencyDeviation(float freqDev) override;
/*! /*!
\brief Sets time-bandwidth product of Gaussian filter applied for shaping. Allowed values are 0.5 and 1.0. Set to 0 to disable shaping. \brief Sets time-bandwidth product of Gaussian filter applied for shaping.
Allowed values are RADIOLIB_SHAPING_0_5 or RADIOLIB_SHAPING_1_0. Set to RADIOLIB_SHAPING_NONE to disable data shaping.
\param sh Time-bandwidth product of Gaussian filter to be set. \param sh Time-bandwidth product of Gaussian filter to be set.
\returns \ref status_codes \returns \ref status_codes
*/ */
int16_t setDataShaping(float dataShaping) override; int16_t setDataShaping(uint8_t sh) override;
/*! /*!
\brief Sets FSK/FLRC sync word in the form of array of up to 5 bytes (FSK). For FLRC modem, the sync word must be exactly 4 bytes long \brief Sets FSK/FLRC sync word in the form of array of up to 5 bytes (FSK). For FLRC modem, the sync word must be exactly 4 bytes long