Simple counter class, non-volatile between resets and power on/off.

Simple Counter class, used to store count array in non-volatile flash memory between resets and power on/off.

Revision:
3:c15c22484205
Parent:
2:f02ac448ecd3
Child:
4:bb12605080d5
diff -r f02ac448ecd3 -r c15c22484205 Counter.cpp
--- a/Counter.cpp	Mon Nov 12 19:08:35 2018 +0000
+++ b/Counter.cpp	Fri Nov 16 14:51:40 2018 +0000
@@ -12,8 +12,7 @@
 #ifdef COUNTER_DEBUG
     debug_out.printf("Constructing Object...\r\n");
 #endif
-    for(int i=0; i<MAX_LEN; i++)
-        count[i] = 0;
+    memset(&counter, 0, MAX_LEN);
     this->init();
 }
 
@@ -77,4 +76,21 @@
 #endif
     count[party_id]++;
     memwrite();
+}
+
+void Counter::decrement(int party_id)
+{
+#ifdef COUNTER_DEBUG
+    debug_out.printf("Decrementing %d\r\n", party_id);
+#endif
+    count[party_id]--;
+    memwrite();
+}
+
+void Counter::clear(){
+    #ifdef COUNTER_DEBUG
+        debug_out.printf("Clearing stored values\r\n");
+    #endif
+    memset(&counter, 0, MAX_LEN);
+    memwrite();
 }
\ No newline at end of file