![](/media/cache/profiles/2012_sf_avc_095.jpg.50x50_q85.jpg)
2018 revision to classic DataBus AVC code.
Dependencies: LSM303DLM Servo SerialGraphicLCD L3G4200D IncrementalEncoder SimpleShell
Diff: Updater.cpp
- Revision:
- 25:b8176ebb96c6
- Parent:
- 15:35c40765f7c3
- Child:
- 26:2dc31a801cc8
--- a/Updater.cpp Fri Dec 21 20:04:09 2018 +0000 +++ b/Updater.cpp Fri Dec 21 20:38:55 2018 +0000 @@ -2,6 +2,14 @@ #include "pinouts.h" #include "IncrementalEncoder.h" +Updater::Updater() { + thisTime = 0; + lastTime = 0; + t = new Timer; + t->start(); + _callback = 0; +} + Updater *Updater::instance() { static Updater instance; @@ -10,34 +18,15 @@ } -void Updater::setInterval(int interval_ms) -{ - _interval = interval_ms; - return; -} - +void Updater::attach(Callback<void()> cb) { + _callback = cb; -void Updater::start() -{ - Timer timer; - - thisTime = 0; - lastTime = 0; - t = &timer; - t->start(); - - EventQueue *queue = mbed_highprio_event_queue(); - Event<void()> event(queue, callback(this, &Updater::update)); - event.period(_interval); - event.post(); - queue->dispatch_forever(); return; } void Updater::update() { - static DigitalOut led2(LED2); static L3G4200D gyro(I2CSDA, I2CSCL); // TODO parameterize static IncrementalEncoder enc(ALEFT); @@ -64,7 +53,9 @@ //history[now].y = history[prev].y + history[now].dist * cos(r); // Convert this into some kind of status message/event thingy - led2 = !led2; + + if (_callback) + _callback(); return; }