From 7dc7f4d76c01358ed02197b597dbd13175bd6a02 Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 6 Jul 2020 08:53:05 +0200 Subject: [PATCH] [SX127x] Changed shaping datatype to uint8_t --- src/modules/SX127x/SX1272.cpp | 26 +++++++++++++------------- src/modules/SX127x/SX1272.h | 6 +++--- src/modules/SX127x/SX1278.cpp | 26 +++++++++++++------------- src/modules/SX127x/SX1278.h | 6 +++--- src/modules/SX127x/SX127x.cpp | 6 +++--- src/modules/SX127x/SX127x.h | 3 ++- 6 files changed, 37 insertions(+), 36 deletions(-) diff --git a/src/modules/SX127x/SX1272.cpp b/src/modules/SX127x/SX1272.cpp index 4384fd54..411c3ab3 100644 --- a/src/modules/SX127x/SX1272.cpp +++ b/src/modules/SX127x/SX1272.cpp @@ -257,7 +257,7 @@ int16_t SX1272::setGain(uint8_t gain) { return(state); } -int16_t SX1272::setDataShaping(float sh) { +int16_t SX1272::setDataShaping(uint8_t sh) { // check active modem if(getActiveModem() != SX127X_FSK_OOK) { return(ERR_WRONG_MODEM); @@ -270,21 +270,21 @@ int16_t SX1272::setDataShaping(float sh) { // set mode to standby int16_t state = SX127x::standby(); + RADIOLIB_ASSERT(state); // set data shaping - sh *= 10.0; - if(abs(sh - 0.0) <= 0.001) { - state |= _mod->SPIsetRegValue(SX127X_REG_OP_MODE, SX1272_NO_SHAPING, 4, 3); - } else if(abs(sh - 3.0) <= 0.001) { - state |= _mod->SPIsetRegValue(SX127X_REG_OP_MODE, SX1272_FSK_GAUSSIAN_0_3, 4, 3); - } else if(abs(sh - 5.0) <= 0.001) { - state |= _mod->SPIsetRegValue(SX127X_REG_OP_MODE, SX1272_FSK_GAUSSIAN_0_5, 4, 3); - } else if(abs(sh - 10.0) <= 0.001) { - state |= _mod->SPIsetRegValue(SX127X_REG_OP_MODE, SX1272_FSK_GAUSSIAN_1_0, 4, 3); - } else { - return(ERR_INVALID_DATA_SHAPING); + switch(sh) { + case RADIOLIB_SHAPING_NONE: + return(_mod->SPIsetRegValue(SX127X_REG_OP_MODE, SX1272_NO_SHAPING, 4, 3)); + case RADIOLIB_SHAPING_0_3: + return(_mod->SPIsetRegValue(SX127X_REG_OP_MODE, SX1272_FSK_GAUSSIAN_0_3, 4, 3)); + case RADIOLIB_SHAPING_0_5: + return(_mod->SPIsetRegValue(SX127X_REG_OP_MODE, SX1272_FSK_GAUSSIAN_0_5, 4, 3)); + case RADIOLIB_SHAPING_1_0: + return(_mod->SPIsetRegValue(SX127X_REG_OP_MODE, SX1272_FSK_GAUSSIAN_1_0, 4, 3)); + default: + return(ERR_INVALID_DATA_SHAPING); } - return(state); } int16_t SX1272::setDataShapingOOK(uint8_t sh) { diff --git a/src/modules/SX127x/SX1272.h b/src/modules/SX127x/SX1272.h index e47e7fed..6aba8259 100644 --- a/src/modules/SX127x/SX1272.h +++ b/src/modules/SX127x/SX1272.h @@ -222,14 +222,14 @@ class SX1272: public SX127x { int16_t setGain(uint8_t gain); /*! - \brief Sets Gaussian filter bandwidth-time product that will be used for data shaping. - Allowed values are 0.3, 0.5 or 1.0. Set to 0 to disable data shaping. Only available in FSK mode with FSK modulation. + \brief Sets Gaussian filter bandwidth-time product that will be used for data shaping. Only available in FSK mode with FSK modulation. + Allowed values are RADIOLIB_SHAPING_0_3, RADIOLIB_SHAPING_0_5 or RADIOLIB_SHAPING_1_0. Set to RADIOLIB_SHAPING_NONE to disable data shaping. \param sh Gaussian shaping bandwidth-time product that will be used for data shaping \returns \ref status_codes */ - int16_t setDataShaping(float sh) override; + int16_t setDataShaping(uint8_t sh) override; /*! \brief Sets filter cutoff frequency that will be used for data shaping. diff --git a/src/modules/SX127x/SX1278.cpp b/src/modules/SX127x/SX1278.cpp index 8e70be39..ae2933a5 100644 --- a/src/modules/SX127x/SX1278.cpp +++ b/src/modules/SX127x/SX1278.cpp @@ -329,7 +329,7 @@ int16_t SX1278::setGain(uint8_t gain) { return(state); } -int16_t SX1278::setDataShaping(float sh) { +int16_t SX1278::setDataShaping(uint8_t sh) { // check active modem if(getActiveModem() != SX127X_FSK_OOK) { return(ERR_WRONG_MODEM); @@ -342,21 +342,21 @@ int16_t SX1278::setDataShaping(float sh) { // set mode to standby int16_t state = SX127x::standby(); + RADIOLIB_ASSERT(state); // set data shaping - sh *= 10.0; - if(abs(sh - 0.0) <= 0.001) { - state |= _mod->SPIsetRegValue(SX127X_REG_PA_RAMP, SX1278_NO_SHAPING, 6, 5); - } else if(abs(sh - 3.0) <= 0.001) { - state |= _mod->SPIsetRegValue(SX127X_REG_PA_RAMP, SX1278_FSK_GAUSSIAN_0_3, 6, 5); - } else if(abs(sh - 5.0) <= 0.001) { - state |= _mod->SPIsetRegValue(SX127X_REG_PA_RAMP, SX1278_FSK_GAUSSIAN_0_5, 6, 5); - } else if(abs(sh - 10.0) <= 0.001) { - state |= _mod->SPIsetRegValue(SX127X_REG_PA_RAMP, SX1278_FSK_GAUSSIAN_1_0, 6, 5); - } else { - return(ERR_INVALID_DATA_SHAPING); + switch(sh) { + case RADIOLIB_SHAPING_NONE: + return(_mod->SPIsetRegValue(SX127X_REG_OP_MODE, SX1278_NO_SHAPING, 6, 5)); + case RADIOLIB_SHAPING_0_3: + return(_mod->SPIsetRegValue(SX127X_REG_OP_MODE, SX1278_FSK_GAUSSIAN_0_3, 6, 5)); + case RADIOLIB_SHAPING_0_5: + return(_mod->SPIsetRegValue(SX127X_REG_OP_MODE, SX1278_FSK_GAUSSIAN_0_5, 6, 5)); + case RADIOLIB_SHAPING_1_0: + return(_mod->SPIsetRegValue(SX127X_REG_OP_MODE, SX1278_FSK_GAUSSIAN_1_0, 6, 5)); + default: + return(ERR_INVALID_DATA_SHAPING); } - return(state); } int16_t SX1278::setDataShapingOOK(uint8_t sh) { diff --git a/src/modules/SX127x/SX1278.h b/src/modules/SX127x/SX1278.h index c7e5d5b5..5ee20cc8 100644 --- a/src/modules/SX127x/SX1278.h +++ b/src/modules/SX127x/SX1278.h @@ -231,14 +231,14 @@ class SX1278: public SX127x { int16_t setGain(uint8_t gain); /*! - \brief Sets Gaussian filter bandwidth-time product that will be used for data shaping. - Allowed values are 0.3, 0.5 or 1.0. Set to 0 to disable data shaping. Only available in FSK mode with FSK modulation. + \brief Sets Gaussian filter bandwidth-time product that will be used for data shaping. Only available in FSK mode with FSK modulation. + Allowed values are RADIOLIB_SHAPING_0_3, RADIOLIB_SHAPING_0_5 or RADIOLIB_SHAPING_1_0. Set to RADIOLIB_SHAPING_NONE to disable data shaping. \param sh Gaussian shaping bandwidth-time product that will be used for data shaping \returns \ref status_codes */ - int16_t setDataShaping(float sh) override; + int16_t setDataShaping(uint8_t sh) override; /*! \brief Sets filter cutoff frequency that will be used for data shaping. diff --git a/src/modules/SX127x/SX127x.cpp b/src/modules/SX127x/SX127x.cpp index 79c2ab65..9f1f4ad0 100644 --- a/src/modules/SX127x/SX127x.cpp +++ b/src/modules/SX127x/SX127x.cpp @@ -912,11 +912,11 @@ int16_t SX127x::setEncoding(uint8_t encoding) { // set encoding switch(encoding) { - case 0: + case RADIOLIB_ENCODING_NRZ: return(_mod->SPIsetRegValue(SX127X_REG_PACKET_CONFIG_1, SX127X_DC_FREE_NONE, 6, 5)); - case 1: + case RADIOLIB_ENCODING_MANCHESTER: return(_mod->SPIsetRegValue(SX127X_REG_PACKET_CONFIG_1, SX127X_DC_FREE_MANCHESTER, 6, 5)); - case 2: + case RADIOLIB_ENCODING_WHITENING: return(_mod->SPIsetRegValue(SX127X_REG_PACKET_CONFIG_1, SX127X_DC_FREE_WHITENING, 6, 5)); default: return(ERR_INVALID_ENCODING); diff --git a/src/modules/SX127x/SX127x.h b/src/modules/SX127x/SX127x.h index 1a318c33..efc5eb50 100644 --- a/src/modules/SX127x/SX127x.h +++ b/src/modules/SX127x/SX127x.h @@ -893,8 +893,9 @@ class SX127x: public PhysicalLayer { /*! \brief Sets transmission encoding. Only available in FSK mode. + Allowed values are RADIOLIB_ENCODING_NRZ, RADIOLIB_ENCODING_MANCHESTER and RADIOLIB_ENCODING_WHITENING. - \param encoding Encoding to be used. Set to 0 for NRZ, 1 for Manchester and 2 for whitening. + \param encoding Encoding to be used. \returns \ref status_codes */