Initialise variables before usage / Cleanup (#315)

This commit is contained in:
Alessandro Gatti
2018-06-17 01:41:54 +02:00
committed by Ben V. Brown
parent 67066f218f
commit 030a714ff2

View File

@@ -885,8 +885,8 @@ void startMOVTask(void const *argument) {
int16_t datay[MOVFilter] = { 0 }; int16_t datay[MOVFilter] = { 0 };
int16_t dataz[MOVFilter] = { 0 }; int16_t dataz[MOVFilter] = { 0 };
uint8_t currentPointer = 0; uint8_t currentPointer = 0;
int16_t tx, ty, tz; int16_t tx = 0, ty = 0, tz = 0;
int32_t avgx, avgy, avgz; int32_t avgx = 0, avgy = 0, avgz = 0;
if (systemSettings.sensitivity > 9) if (systemSettings.sensitivity > 9)
systemSettings.sensitivity = 9; systemSettings.sensitivity = 9;
#if ACCELDEBUG #if ACCELDEBUG
@@ -913,11 +913,8 @@ void startMOVTask(void const *argument) {
datay[currentPointer] = (int32_t) ty; datay[currentPointer] = (int32_t) ty;
dataz[currentPointer] = (int32_t) tz; dataz[currentPointer] = (int32_t) tz;
currentPointer = (currentPointer + 1) % MOVFilter; currentPointer = (currentPointer + 1) % MOVFilter;
#if ACCELDEBUG
// Debug for Accel // calculate averages
avgx = avgy = avgz = 0;
for (uint8_t i = 0; i < MOVFilter; i++) { for (uint8_t i = 0; i < MOVFilter; i++) {
avgx += datax[i]; avgx += datax[i];
avgy += datay[i]; avgy += datay[i];
@@ -926,38 +923,35 @@ void startMOVTask(void const *argument) {
avgx /= MOVFilter; avgx /= MOVFilter;
avgy /= MOVFilter; avgy /= MOVFilter;
avgz /= MOVFilter; avgz /= MOVFilter;
//Sum the deltas
int32_t error = (abs(avgx - tx) + abs(avgy - ty) + abs(avgz - tz));
#if ACCELDEBUG
// Debug for Accel
lcd.setFont(1); lcd.setFont(1);
lcd.setCursor(0, 0); lcd.setCursor(0, 0);
lcd.printNumber(abs(avgx - (int32_t) tx), 5); lcd.printNumber(abs(avgx - (int32_t) tx), 5);
lcd.print(" "); lcd.print(" ");
lcd.printNumber(abs(avgy - (int32_t) ty), 5); lcd.printNumber(abs(avgy - (int32_t) ty), 5);
if ((abs(avgx - tx) + abs(avgy - ty) + abs(avgz - tz)) > max) if (error > max) {
max = (abs(avgx - tx) + abs(avgy - ty) + abs(avgz - tz)); max = (abs(avgx - tx) + abs(avgy - ty) + abs(avgz - tz));
}
lcd.setCursor(0, 8); lcd.setCursor(0, 8);
lcd.printNumber(max, 5); lcd.printNumber(max, 5);
lcd.print(" "); lcd.print(" ");
lcd.printNumber((abs(avgx - tx) + abs(avgy - ty) + abs(avgz - tz)), 5); lcd.printNumber((abs(avgx - tx) + abs(avgy - ty) + abs(avgz - tz)), 5);
lcd.refresh(); lcd.refresh();
if (HAL_GPIO_ReadPin(KEY_A_GPIO_Port, KEY_A_Pin) == GPIO_PIN_RESET) if (HAL_GPIO_ReadPin(KEY_A_GPIO_Port, KEY_A_Pin) == GPIO_PIN_RESET) {
max = 0; max = 0;
#endif
// calculate averages
avgx = avgy = avgz = 0;
for (uint8_t i = 0; i < MOVFilter; i++) {
avgx += datax[i];
avgy += datay[i];
avgz += dataz[i];
} }
avgx /= MOVFilter; #endif
avgy /= MOVFilter;
avgz /= MOVFilter;
// So now we have averages, we want to look if these are different by more // So now we have averages, we want to look if these are different by more
// than the threshold // than the threshold
//Sum the deltas
int32_t error = (abs(avgx - tx) + abs(avgy - ty) + abs(avgz - tz));
// If error has occurred then we update the tick timer // If error has occurred then we update the tick timer
if (error > threshold) { if (error > threshold) {
lastMovementTime = xTaskGetTickCount(); lastMovementTime = xTaskGetTickCount();