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:
2:f02ac448ecd3
Parent:
1:e8eeddee2959
Child:
3:c15c22484205
diff -r e8eeddee2959 -r f02ac448ecd3 Counter.h
--- a/Counter.h	Mon Nov 12 19:01:53 2018 +0000
+++ b/Counter.h	Mon Nov 12 19:08:35 2018 +0000
@@ -1,14 +1,36 @@
+#ifndef COUNTER_H
+#define COUNTER_H
+
 #include "mbed.h"
 #include "FreescaleIAP.h"
 
+#ifndef MAX_LEN
 #define MAX_LEN 8
-//#define COUNTER_DEBUG
+#endif
+
+/**
+* Counter example
+*
+* @code
+* #include "mbed.h"
+* #include "Counter.h"
+* 
+* int main(void) {
+*     
+*     Counter ct;
+*     while (true) {
+*         ct.increment(rand()%MAX_LEN);
+*         wait(0.5);
+*     }
+* }
+* @endcode
+*/
 
 class Counter
 {
 private:
     int count[MAX_LEN];
-    int new_count;
+    int is_new_count;
     int address;
     #ifdef COUNTER_DEBUG
     /** Simple print function
@@ -16,7 +38,7 @@
     *   Prints all memory addresses in count array with values for debugging purposes.
     *
     */
-    void print_memory();
+    void print_memory(void);
     #endif
     /** Initialize count array
     *
@@ -24,7 +46,7 @@
     *   depending on whether it has been called before or not
     *
     */
-    void init();
+    void init(void);
     
 public:
 
@@ -41,14 +63,14 @@
     *   Writes current count array to Flash Memory
     *
     */
-    void memwrite();
+    void memwrite(void);
     
     /** Read from memory
     *
     *   Loads values of existiing count array from Flash Memory
     *
     */
-    void memread();
+    void memread(void);
     
     /** Increment count
     *
@@ -58,4 +80,6 @@
     *
     */
     void increment(int index);
-};
\ No newline at end of file
+};
+
+#endif
\ No newline at end of file