c
Dependencies: BSP_B-L475E-IOT01
Revision 1:32ac16f1945a, committed 2018-12-07
- Comitter:
- lucaspennati
- Date:
- Fri Dec 07 12:01:49 2018 +0000
- Parent:
- 0:ba1f47c7fdd2
- Commit message:
- a
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r ba1f47c7fdd2 -r 32ac16f1945a main.cpp --- a/main.cpp Thu Dec 06 14:48:01 2018 +0000 +++ b/main.cpp Fri Dec 07 12:01:49 2018 +0000 @@ -76,23 +76,23 @@ static FILE *file; volatile int counter = 0; -int maximum( int a, int b, int c ) { - int max = ( a < b ) ? b : a; - return ( ( max < c ) ? c : max ); -} - -void readSensors() { +void getDataFromSensors() { int16_t pDataXYZ[3] = {0}; BSP_ACCELERO_AccGetXYZ(pDataXYZ); - if(pDataXYZ[2] > 900 || pDataXYZ[2] < -900) { //Horizontal State - fprintf(file, "%d\n", 1); - } else if(pDataXYZ[1] > 900 || pDataXYZ[1] < -900) { //Long Edge State - fprintf(file, "%d\n", 2); - } else if(pDataXYZ[0] > 900 || pDataXYZ[0] < -900) { // Short Edge State - fprintf(file, "%d\n", 3); - } else { // all other positions - fprintf(file, "%d\n", 4); - } + + bool isHorizontal = pDataXYZ[2] > 900 || pDataXYZ[2] < -900; + bool isOnLongEdge = pDataXYZ[1] > 900 || pDataXYZ[1] < -900; + bool isOnShortEdge = pDataXYZ[0] > 900 || pDataXYZ[0] < -900; + + if(isHorizontal) { + fprintf(file, "%d\n", 1); + } else if(isOnLongEdge) { + fprintf(file, "%d\n", 2); + } else if(isOnShortEdge) { + fprintf(file, "%d\n", 3); + } else { + fprintf(file, "%d\n", 4); + } fflush(file); fflush(stdout); } @@ -118,17 +118,20 @@ countLed3 += 1; } } - int maxLed = maximum(countLed1, countLed2, countLed3); - printf("MAX LED = %d\n", maxLed); - if(maxLed == countLed1) { + + bool isLed1 = led1 >= led2 && led1 >= led3; + bool isLed2 = led2 >= led1 && led2 >= led3; + bool isLed3 = led3 >= led1 && led3 >= led2; + + if(isLed1) { led1 = 1; led2 = 0; led3 = 0; - } else if (maxLed == countLed2) { + } else if (isLed2) { led1 = 0; led2 = 1; led3 = 0; - } else if (maxLed == countLed3) { + } else if (isLed3) { led1 = 0; led2 = 0; led3 = 1; @@ -149,8 +152,8 @@ printf("Mbed OS filesystem example done!\n"); } -void turnOnLed() { - queue.call(readSensors); +void toggleLed() { + queue.call(getDataFromSensors); counter += 1; if(counter == 1000) { toggle_led.detach(); @@ -202,7 +205,7 @@ } } - toggle_led.attach(&turnOnLed, 0.01); + toggle_led.attach(&toggleLed, 0.01); }