Samples acceleration at 100 Hz for 10 seconds. At the end of the 10 seconds, turns on: - LED1 if the board stayed horizontal for most time - LED2 if the board stayed on the long edge for most time - LED3 if the board stayed on the short edge for most time
Dependencies: BSP_B-L475E-IOT01
Diff: main.cpp
- Revision:
- 1:164c6bd28b13
- Parent:
- 0:2ce95bf1286f
- Child:
- 2:52e9bb32964b
--- a/main.cpp Thu Dec 06 14:55:07 2018 +0000 +++ b/main.cpp Thu Dec 06 16:18:47 2018 +0000 @@ -57,14 +57,26 @@ led3 = led3_status; } +bool is_board_horizontal() { + return (pDataXYZ[2] < 1030 && pDataXYZ[2] > 950) || (pDataXYZ[2] < -950 && pDataXYZ[2] > -1030); +} + +bool is_board_vertical_short() { + return (pDataXYZ[0] < -950 && pDataXYZ[0] > -1030) || (pDataXYZ[0] < 1030 && pDataXYZ[0] > 950); +} + +bool is_board_vertical_long() { + return (pDataXYZ[1] < 1030 && pDataXYZ[1] > 950) || (pDataXYZ[1] < -950 && pDataXYZ[1] > -1030); +} + void write_positions_on_file() { int16_t pDataXYZ[3] = {0}; BSP_ACCELERO_AccGetXYZ(pDataXYZ); - if ((pDataXYZ[0] < -950 && pDataXYZ[0] > -1030) || (pDataXYZ[0] < 1030 && pDataXYZ[0] > 950)) { + if (is_board_vertical_short()) { fprintf(f, "%d\n", 0); - } else if ((pDataXYZ[1] < 1030 && pDataXYZ[1] > 950) || (pDataXYZ[1] < -950 && pDataXYZ[1] > -1030)) { + } else if (is_board_vertical_long()) { fprintf(f, "%d\n", 1); - } else if ((pDataXYZ[2] < 1030 && pDataXYZ[2] > 950) || (pDataXYZ[2] < -950 && pDataXYZ[2] > -1030)) { + } else if (is_board_horizontal()) { fprintf(f, "%d\n", 2); } else { fprintf(f, "%d\n", -1); @@ -103,6 +115,7 @@ toggle_led(0,0,1); } + printf("Press the restart button to sample again."); fflush(stdout); int err = fclose(f); printf("%s\n", (err < 0 ? "Fail :(" : "OK")); @@ -114,7 +127,7 @@ if (err < 0) { error("error: %s (%d)\n", strerror(-err), err); } - printf("Press the restart button to sample again."); + } void toggle() { @@ -125,18 +138,6 @@ printf("ACCELERO_Z = %d\n\n", pDataXYZ[2]); } -bool is_board_horizontal() { - return (pDataXYZ[2] < 1030 && pDataXYZ[2] > 950) || (pDataXYZ[2] < -950 && pDataXYZ[2] > -1030); -} - -bool is_board_vertical_short() { - return (pDataXYZ[0] < -950 && pDataXYZ[0] > -1030) || (pDataXYZ[0] < 1030 && pDataXYZ[0] > 950); -} - -bool is_board_vertical_long() { - return (pDataXYZ[1] < 1030 && pDataXYZ[1] > 950) || (pDataXYZ[1] < -950 && pDataXYZ[1] > -1030); -} - void ticker_attach() { queue.call(write_positions_on_file); seconds_passed++;