From e52fe99f03bb717792cabf6006a50fce1d2bc951 Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 20 May 2024 19:56:47 +0200 Subject: [PATCH] [CC1101] Rework power check to not use constexpr --- src/modules/CC1101/CC1101.cpp | 39 ++++++++--------------------------- 1 file changed, 9 insertions(+), 30 deletions(-) diff --git a/src/modules/CC1101/CC1101.cpp b/src/modules/CC1101/CC1101.cpp index 09e07b27..73006578 100644 --- a/src/modules/CC1101/CC1101.cpp +++ b/src/modules/CC1101/CC1101.cpp @@ -589,7 +589,7 @@ int16_t CC1101::checkOutputPower(int8_t power, int8_t* clipped) { } int16_t CC1101::checkOutputPower(int8_t power, int8_t* clipped, uint8_t* raw) { - constexpr int8_t allowedPwrs[8] = { -30, -20, -15, -10, 0, 5, 7, 10 }; + const int8_t allowedPwrs[8] = { -30, -20, -15, -10, 0, 5, 7, 10 }; if(clipped) { if(power <= -30) { @@ -608,7 +608,7 @@ int16_t CC1101::checkOutputPower(int8_t power, int8_t* clipped, uint8_t* raw) { // if just a check occurs (and not requesting the raw power value), return now if(!raw) { - for(int i = 0; i < 8; i++) { + for(int i = 0; i < sizeof(allowedPwrs); i++) { if(allowedPwrs[i] == power) { return(RADIOLIB_ERR_NONE); } @@ -642,35 +642,14 @@ int16_t CC1101::checkOutputPower(int8_t power, int8_t* clipped, uint8_t* raw) { {0xCB, 0xC8, 0xCB, 0xC7}, {0xC2, 0xC0, 0xC2, 0xC0}}; - switch(power) { - case allowedPwrs[0]: // -30 - *raw = paTable[0][f]; - break; - case allowedPwrs[1]: // -20 - *raw = paTable[1][f]; - break; - case allowedPwrs[2]: // -15 - *raw = paTable[2][f]; - break; - case allowedPwrs[3]: // -10 - *raw = paTable[3][f]; - break; - case allowedPwrs[4]: // 0 - *raw = paTable[4][f]; - break; - case allowedPwrs[5]: // 5 - *raw = paTable[5][f]; - break; - case allowedPwrs[6]: // 7 - *raw = paTable[6][f]; - break; - case allowedPwrs[7]: // 10 - *raw = paTable[7][f]; - break; - default: - return(RADIOLIB_ERR_INVALID_OUTPUT_POWER); + for(uint8_t i = 0; i < sizeof(allowedPwrs); i++) { + if(power == allowedPwrs[i]) { + *raw = paTable[i][f]; + return(RADIOLIB_ERR_NONE); + } } - return(RADIOLIB_ERR_NONE); + + return(RADIOLIB_ERR_INVALID_OUTPUT_POWER); } int16_t CC1101::setSyncWord(uint8_t* syncWord, uint8_t len, uint8_t maxErrBits, bool requireCarrierSense) {