From cdf7e43ab1212bd91271c4f2ff029c32e87f739c Mon Sep 17 00:00:00 2001 From: atomiclama Date: Fri, 16 Dec 2016 13:23:22 +0000 Subject: [PATCH 1/2] cppcheck warning removal --- src/main/fc/fc_msp.c | 8 ++------ src/main/fc/fc_tasks.c | 4 ++-- src/main/io/ledstrip.c | 10 ++++------ 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/main/fc/fc_msp.c b/src/main/fc/fc_msp.c index 50d9e9e45..81a74c5e4 100755 --- a/src/main/fc/fc_msp.c +++ b/src/main/fc/fc_msp.c @@ -215,9 +215,8 @@ static void serializeNames(sbuf_t *dst, const char *s) static const box_t *findBoxByActiveBoxId(uint8_t activeBoxId) { uint8_t boxIndex; - const box_t *candidate; for (boxIndex = 0; boxIndex < sizeof(boxes) / sizeof(box_t); boxIndex++) { - candidate = &boxes[boxIndex]; + const box_t *candidate = &boxes[boxIndex]; if (candidate->boxId == activeBoxId) { return candidate; } @@ -228,9 +227,8 @@ static const box_t *findBoxByActiveBoxId(uint8_t activeBoxId) static const box_t *findBoxByPermenantId(uint8_t permenantId) { uint8_t boxIndex; - const box_t *candidate; for (boxIndex = 0; boxIndex < sizeof(boxes) / sizeof(box_t); boxIndex++) { - candidate = &boxes[boxIndex]; + const box_t *candidate = &boxes[boxIndex]; if (candidate->permanentId == permenantId) { return candidate; } @@ -1381,7 +1379,6 @@ static mspResult_e mspFcProcessInCommand(uint8_t cmdMSP, sbuf_t *src) #ifdef USE_SERVOS if (dataSize != 1 + sizeof(servoParam_t)) { return MSP_RESULT_ERROR; - break; } i = sbufReadU8(src); if (i >= MAX_SUPPORTED_SERVOS) { @@ -1535,7 +1532,6 @@ static mspResult_e mspFcProcessInCommand(uint8_t cmdMSP, sbuf_t *src) case MSP_SET_TRANSPONDER_CONFIG: if (dataSize != sizeof(masterConfig.transponderData)) { return MSP_RESULT_ERROR; - break; } for (unsigned int i = 0; i < sizeof(masterConfig.transponderData); i++) { masterConfig.transponderData[i] = sbufReadU8(src); diff --git a/src/main/fc/fc_tasks.c b/src/main/fc/fc_tasks.c index cb04a8f23..18ca4bbe2 100644 --- a/src/main/fc/fc_tasks.c +++ b/src/main/fc/fc_tasks.c @@ -110,8 +110,8 @@ static void taskHandleSerial(timeUs_t currentTimeUs) static void taskUpdateBattery(timeUs_t currentTimeUs) { #if defined(USE_ADC) || defined(USE_ESC_SENSOR) - static uint32_t vbatLastServiced = 0; if (feature(FEATURE_VBAT) || feature(FEATURE_ESC_SENSOR)) { + static uint32_t vbatLastServiced = 0; if (cmp32(currentTimeUs, vbatLastServiced) >= VBATINTERVAL) { vbatLastServiced = currentTimeUs; updateBattery(); @@ -119,8 +119,8 @@ static void taskUpdateBattery(timeUs_t currentTimeUs) } #endif - static uint32_t ibatLastServiced = 0; if (feature(FEATURE_CURRENT_METER) || feature(FEATURE_ESC_SENSOR)) { + static uint32_t ibatLastServiced = 0; const int32_t ibatTimeSinceLastServiced = cmp32(currentTimeUs, ibatLastServiced); if (ibatTimeSinceLastServiced >= IBATINTERVAL) { diff --git a/src/main/io/ledstrip.c b/src/main/io/ledstrip.c index 7fa0ce919..5d2c93dcd 100644 --- a/src/main/io/ledstrip.c +++ b/src/main/io/ledstrip.c @@ -568,13 +568,11 @@ static void applyLedBatteryLayer(bool updateNow, timeUs_t *timer) { static bool flash = false; - int state; int timerDelayUs = HZ_TO_US(1); if (updateNow) { - state = getBatteryState(); - switch (state) { + switch (getBatteryState()) { case BATTERY_OK: flash = true; timerDelayUs = HZ_TO_US(1); @@ -605,11 +603,10 @@ static void applyLedRssiLayer(bool updateNow, timeUs_t *timer) { static bool flash = false; - int state; int timerDelay = HZ_TO_US(1); if (updateNow) { - state = (rssi * 100) / 1023; + int state = (rssi * 100) / 1023; if (state > 50) { flash = true; @@ -634,11 +631,12 @@ static void applyLedRssiLayer(bool updateNow, timeUs_t *timer) #ifdef GPS static void applyLedGpsLayer(bool updateNow, timeUs_t *timer) { - static uint8_t gpsFlashCounter = 0; + static uint8_t gpsPauseCounter = 0; const uint8_t blinkPauseLength = 4; if (updateNow) { + static uint8_t gpsFlashCounter = 0; if (gpsPauseCounter > 0) { gpsPauseCounter--; } else if (gpsFlashCounter >= GPS_numSat) { From ae5b3ae30c2881c5def189c4286e66913399101b Mon Sep 17 00:00:00 2001 From: atomiclama Date: Mon, 19 Dec 2016 07:43:42 +0000 Subject: [PATCH 2/2] Changes from code review. --- src/main/fc/fc_msp.c | 6 ++---- src/main/io/ledstrip.c | 24 ++++++++++++------------ 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/main/fc/fc_msp.c b/src/main/fc/fc_msp.c index 81a74c5e4..53d17e493 100755 --- a/src/main/fc/fc_msp.c +++ b/src/main/fc/fc_msp.c @@ -214,8 +214,7 @@ static void serializeNames(sbuf_t *dst, const char *s) static const box_t *findBoxByActiveBoxId(uint8_t activeBoxId) { - uint8_t boxIndex; - for (boxIndex = 0; boxIndex < sizeof(boxes) / sizeof(box_t); boxIndex++) { + for (uint8_t boxIndex = 0; boxIndex < sizeof(boxes) / sizeof(box_t); boxIndex++) { const box_t *candidate = &boxes[boxIndex]; if (candidate->boxId == activeBoxId) { return candidate; @@ -226,8 +225,7 @@ static const box_t *findBoxByActiveBoxId(uint8_t activeBoxId) static const box_t *findBoxByPermenantId(uint8_t permenantId) { - uint8_t boxIndex; - for (boxIndex = 0; boxIndex < sizeof(boxes) / sizeof(box_t); boxIndex++) { + for (uint8_t boxIndex = 0; boxIndex < sizeof(boxes) / sizeof(box_t); boxIndex++) { const box_t *candidate = &boxes[boxIndex]; if (candidate->permanentId == permenantId) { return candidate; diff --git a/src/main/io/ledstrip.c b/src/main/io/ledstrip.c index 5d2c93dcd..a67db84ff 100644 --- a/src/main/io/ledstrip.c +++ b/src/main/io/ledstrip.c @@ -608,23 +608,23 @@ static void applyLedRssiLayer(bool updateNow, timeUs_t *timer) if (updateNow) { int state = (rssi * 100) / 1023; - if (state > 50) { - flash = true; - timerDelay = HZ_TO_US(1); - } else if (state > 20) { - flash = !flash; - timerDelay = HZ_TO_US(2); - } else { - flash = !flash; - timerDelay = HZ_TO_US(8); - } + if (state > 50) { + flash = true; + timerDelay = HZ_TO_US(1); + } else if (state > 20) { + flash = !flash; + timerDelay = HZ_TO_US(2); + } else { + flash = !flash; + timerDelay = HZ_TO_US(8); + } } *timer += timerDelay; if (!flash) { - hsvColor_t *bgc = getSC(LED_SCOLOR_BACKGROUND); - applyLedHsv(LED_MOV_FUNCTION(LED_FUNCTION_RSSI), bgc); + hsvColor_t *bgc = getSC(LED_SCOLOR_BACKGROUND); + applyLedHsv(LED_MOV_FUNCTION(LED_FUNCTION_RSSI), bgc); } }