[CC1101] Rework power check to not use constexpr

pull/1105/head
jgromes 2024-05-20 19:56:47 +02:00
rodzic 90627325d3
commit e52fe99f03
1 zmienionych plików z 9 dodań i 30 usunięć

Wyświetl plik

@ -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) {