assignment

Dependencies:   BSP_B-L475E-IOT01

Files at this revision

API Documentation at this revision

Comitter:
alessioburatti
Date:
Thu Dec 06 17:48:37 2018 +0000
Parent:
27:bab23d82832b
Commit message:
done

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Thu Dec 06 16:48:01 2018 +0000
+++ b/main.cpp	Thu Dec 06 17:48:37 2018 +0000
@@ -54,6 +54,10 @@
 Ticker tTicker;
 Thread t;
 
+uint16_t horizontalKey = 10;
+uint16_t longVerticalKey = 11;
+uint16_t shortVerticalKey = 12;
+
 uint32_t horizontalCount;
 uint32_t longVerticalCount;
 uint32_t shortVerticalCount;
@@ -77,11 +81,11 @@
     led3 = 0;
 }
 
-void turnOnLedAndUpdateStore(DigitalOut * led, int key, uint32_t * currentCount) {
+void turnOnLedAndUpdateStore(DigitalOut * led, uint16_t key, uint32_t * currentCount) {
     *led = 1;
     NVStore &nvstore = NVStore::get_instance();
-    *currentCount++;
-    nvstore.set(key, sizeof(*currentCount), currentCount);
+    *currentCount = *currentCount + 1;
+    nvstore.set(key, sizeof(uint32_t), currentCount);
 }
 
 void toggleLed() {
@@ -110,11 +114,11 @@
     turnOffLeds();
     
     if (mostOccurentValue == HORIZONTAL_INDEX) {
-        turnOnLedAndUpdateStore(&led1, HORIZONTAL_INDEX, &horizontalCount);
+        turnOnLedAndUpdateStore(&led1, horizontalKey, &horizontalCount);
     } else if (mostOccurentValue == LONG_VERTICAL_INDEX) {
-        turnOnLedAndUpdateStore(&led2, LONG_VERTICAL_INDEX, &longVerticalCount);
+        turnOnLedAndUpdateStore(&led2, longVerticalKey, &longVerticalCount);
     } else if (mostOccurentValue == SHORT_VERTICAL_INDEX) {
-        turnOnLedAndUpdateStore(&led3, SHORT_VERTICAL_INDEX, &shortVerticalCount);
+        turnOnLedAndUpdateStore(&led3, shortVerticalKey, &shortVerticalCount);
     }
     
     fflush(stdout);
@@ -173,17 +177,17 @@
     
     rc = nvstore.init();
     
-    rc = nvstore.get(HORIZONTAL_INDEX, sizeof(horizontalCount), &horizontalCount, actual_len_bytes);
+    rc = nvstore.get(horizontalKey, sizeof(horizontalCount), &horizontalCount, actual_len_bytes);
     if (rc == NVSTORE_NOT_FOUND) {
         horizontalCount = 0;
         shortVerticalCount = 0;
         longVerticalCount = 0;
-        nvstore.set(HORIZONTAL_INDEX, sizeof(horizontalCount), &horizontalCount);
-        nvstore.set(SHORT_VERTICAL_INDEX, sizeof(shortVerticalCount), &shortVerticalCount);
-        nvstore.set(LONG_VERTICAL_INDEX, sizeof(longVerticalCount), &longVerticalCount);
+        nvstore.set(horizontalKey, sizeof(horizontalCount), &horizontalCount);
+        nvstore.set(shortVerticalKey, sizeof(shortVerticalCount), &shortVerticalCount);
+        nvstore.set(longVerticalKey, sizeof(longVerticalCount), &longVerticalCount);
     } else {
-        nvstore.get(SHORT_VERTICAL_INDEX, sizeof(shortVerticalCount), &shortVerticalCount, actual_len_bytes);
-        nvstore.get(LONG_VERTICAL_INDEX, sizeof(longVerticalCount), &longVerticalCount, actual_len_bytes);
+        nvstore.get(shortVerticalKey, sizeof(shortVerticalCount), &shortVerticalCount, actual_len_bytes);
+        nvstore.get(longVerticalKey, sizeof(longVerticalCount), &longVerticalCount, actual_len_bytes);
     }
     
     printf("Led 1: %d\nLed 2: %d\nLed 3: %d\n", horizontalCount, longVerticalCount, shortVerticalCount);