Modify the previous example to use NVStore for keeping track of how many times every different LED turned on This information must persist across system reboots! Print this information on STDout at every boot before running the application

Dependencies:   BSP_B-L475E-IOT01

Files at this revision

API Documentation at this revision

Comitter:
vicara
Date:
Thu Dec 06 16:38:26 2018 +0000
Parent:
1:288cdb94027a
Commit message:
fixed

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Thu Dec 06 15:54:33 2018 +0000
+++ b/main.cpp	Thu Dec 06 16:38:26 2018 +0000
@@ -66,14 +66,27 @@
     led3 = led3_status;
 }
 
+
+bool is_board_horizontal(int16_t pDataXYZ[3]) {
+    return (pDataXYZ[2] < 1030 && pDataXYZ[2] > 950) || (pDataXYZ[2] < -950 && pDataXYZ[2] > -1030);
+}
+
+bool is_board_vertical_short(int16_t pDataXYZ[3]) {
+    return (pDataXYZ[0] < -950  && pDataXYZ[0] > -1030) || (pDataXYZ[0] < 1030 && pDataXYZ[0] > 950);
+}
+
+bool is_board_vertical_long(int16_t pDataXYZ[3]) {
+    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(pDataXYZ)) {
             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(pDataXYZ)) {
             fprintf(f, "%d\n", 1);
-        } else if ((pDataXYZ[2] < 1030 && pDataXYZ[2] > 950) || (pDataXYZ[2] < -950 && pDataXYZ[2] > -1030)) {
+        } else if (is_board_horizontal(pDataXYZ)) {
              fprintf(f, "%d\n", 2);
         } else {
              fprintf(f, "%d\n", -1);
@@ -142,17 +155,7 @@
     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);