2018 revision to classic DataBus AVC code.

Dependencies:   LSM303DLM Servo SerialGraphicLCD L3G4200D IncrementalEncoder SimpleShell

Committer:
shimniok
Date:
Fri Dec 21 20:38:55 2018 +0000
Revision:
25:b8176ebb96c6
Parent:
15:35c40765f7c3
Child:
32:eb673f6f5734
Extracted eventqueue from Updater, implemented callback

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shimniok 11:8ec858b7c6d1 1 #ifndef __UPDATER_H
shimniok 11:8ec858b7c6d1 2 #define __UPDATER_H
shimniok 11:8ec858b7c6d1 3
shimniok 11:8ec858b7c6d1 4 #include "mbed.h"
shimniok 11:8ec858b7c6d1 5 #include "L3G4200D.h"
shimniok 11:8ec858b7c6d1 6
shimniok 15:35c40765f7c3 7 /** Periodically reads sensor data
shimniok 25:b8176ebb96c6 8 * This class reads and updates sensor data. Intended to be called at a fixed
shimniok 25:b8176ebb96c6 9 * interval.
shimniok 25:b8176ebb96c6 10 * @code
shimniok 25:b8176ebb96c6 11 * Updater *u = Updater::instance(); // beware of lifetime of this pointer
shimniok 25:b8176ebb96c6 12 * Thread updaterThread(osPriorityRealtime, 512, 0, "updater");
shimniok 25:b8176ebb96c6 13 * EventQueue *updaterQueue = mbed_highprio_event_queue();
shimniok 25:b8176ebb96c6 14 * Event<void()> event(updaterQueue, callback(u, &Updater::update));
shimniok 25:b8176ebb96c6 15 * event.period(20);
shimniok 25:b8176ebb96c6 16 * event.post(); // if lifetime of u not correct, this will hard fault
shimniok 25:b8176ebb96c6 17 * updaterThread.start(callback(updaterQueue, &EventQueue::dispatch_forever));
shimniok 25:b8176ebb96c6 18 *
shimniok 15:35c40765f7c3 19 */
shimniok 12:3cd91e150d9c 20 class Updater: private mbed::NonCopyable<Updater> {
shimniok 11:8ec858b7c6d1 21 public:
shimniok 14:1dd83e626153 22 /// Return singleton instance
shimniok 11:8ec858b7c6d1 23 static Updater *instance();
shimniok 14:1dd83e626153 24
shimniok 25:b8176ebb96c6 25 /// Attach a callback handler run each time updater() is run
shimniok 25:b8176ebb96c6 26 void attach(Callback<void()> cb);
shimniok 25:b8176ebb96c6 27
shimniok 25:b8176ebb96c6 28 /// Update all sensors
shimniok 25:b8176ebb96c6 29 void update();
shimniok 25:b8176ebb96c6 30
shimniok 14:1dd83e626153 31 /** Get gyro values
shimniok 14:1dd83e626153 32 * @return g array of x, y, and z gyro values
shimniok 14:1dd83e626153 33 * @return dt time since data last updated
shimniok 14:1dd83e626153 34 */
shimniok 13:5566df1250f1 35 void gyro(int g[3], float& dt);
shimniok 14:1dd83e626153 36
shimniok 14:1dd83e626153 37 /** Get encoder count
shimniok 14:1dd83e626153 38 * @return encoder count since last call
shimniok 14:1dd83e626153 39 */
shimniok 14:1dd83e626153 40 int encoder();
shimniok 14:1dd83e626153 41
shimniok 11:8ec858b7c6d1 42 private:
shimniok 14:1dd83e626153 43 /// Basic constructor (singleton)
shimniok 25:b8176ebb96c6 44 Updater();
shimniok 14:1dd83e626153 45
shimniok 25:b8176ebb96c6 46 Callback<void()> _callback; // notification callback
shimniok 14:1dd83e626153 47 Timer *t; // timer used to measure dt
shimniok 14:1dd83e626153 48 int _gyro[3]; // gyro raw
shimniok 14:1dd83e626153 49 int _ecount; // encoder count
shimniok 13:5566df1250f1 50 float _dt;
shimniok 15:35c40765f7c3 51 int _interval;
shimniok 11:8ec858b7c6d1 52 int thisTime;
shimniok 11:8ec858b7c6d1 53 int lastTime;
shimniok 11:8ec858b7c6d1 54 };
shimniok 11:8ec858b7c6d1 55
shimniok 11:8ec858b7c6d1 56 #endif