2018 revision to classic DataBus AVC code.

Dependencies:   LSM303DLM Servo SerialGraphicLCD L3G4200D IncrementalEncoder SimpleShell

Revision:
25:b8176ebb96c6
Parent:
15:35c40765f7c3
Child:
32:eb673f6f5734
--- a/Updater.h	Fri Dec 21 20:04:09 2018 +0000
+++ b/Updater.h	Fri Dec 21 20:38:55 2018 +0000
@@ -5,27 +5,29 @@
 #include "L3G4200D.h"
 
 /** Periodically reads sensor data
- * This class executes an update function at a configurable interval to read 
- * and update sensor data. The class makes use of EventQueue and Event for
- * task scheduling and runs events on the mbed_highprio_event_queue
+ * This class reads and updates sensor data. Intended to be called at a fixed
+ * interval.
+ * @code
+ * Updater *u = Updater::instance(); // beware of lifetime of this pointer
+ * Thread updaterThread(osPriorityRealtime, 512, 0, "updater");
+ * EventQueue *updaterQueue = mbed_highprio_event_queue();
+ * Event<void()> event(updaterQueue, callback(u, &Updater::update));
+ * event.period(20);
+ * event.post(); // if lifetime of u not correct, this will hard fault
+ * updaterThread.start(callback(updaterQueue, &EventQueue::dispatch_forever));  
+ *
  */
 class Updater: private mbed::NonCopyable<Updater> {
 public:
     /// Return singleton instance
     static Updater *instance();
     
-    /** Sets the interval for running updater()
-     * @param interval_ms is the interval in milliseconds
-     */
-    void setInterval(int interval_ms);
-
-    /** Start the updater running
-     * @note Makes use of RTOS EventQueue and Event. The function runs in an
-     * infinite loop so best to start in a separate thread or from main thread
-     * when done with everything else.
-     */
-    void start();
-  
+    /// Attach a callback handler run each time updater() is run
+    void attach(Callback<void()> cb);
+    
+    /// Update all sensors
+    void update(); 
+    
     /** Get gyro values
      * @return g array of x, y, and z gyro values
      * @return dt time since data last updated
@@ -39,11 +41,9 @@
 
 private:
     /// Basic constructor (singleton)
-    Updater() {}
+    Updater();
     
-    /// Update all sensors
-    void update(); 
-    
+    Callback<void()> _callback; // notification callback    
     Timer *t; // timer used to measure dt
     int _gyro[3]; // gyro raw
     int _ecount; // encoder count