Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: EthernetInterfacePlusHostname RdWebServer mbed-rtos mbed
Idler.cpp@6:8df79fe1afcd, 2015-09-03 (annotated)
- Committer:
- Bobty
- Date:
- Thu Sep 03 20:17:23 2015 +0000
- Revision:
- 6:8df79fe1afcd
- Parent:
- 5:910909f34907
Fixed an unforeseen problem with messages not aligned on RGB boundaries; Fixed potential hanging pointer problem in colourconverters; Changed Idle screen to a set of colourful snakes
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Bobty | 5:910909f34907 | 1 | |
| Bobty | 5:910909f34907 | 2 | #include "Idler.h" |
| Bobty | 5:910909f34907 | 3 | |
| Bobty | 5:910909f34907 | 4 | DigitalOut* Idler::_pStatusLed = NULL; |
| Bobty | 6:8df79fe1afcd | 5 | bool Idler::_isRunning = false; |
| Bobty | 5:910909f34907 | 6 | bool Idler::_isIdle = true; |
| Bobty | 5:910909f34907 | 7 | unsigned int Idler::_stepCount = 0; |
| Bobty | 5:910909f34907 | 8 | DrawingManager* Idler::_pDrawingManager = NULL; |
| Bobty | 5:910909f34907 | 9 | Ticker Idler::_idleTicker; |
| Bobty | 5:910909f34907 | 10 | Timer Idler::_idleTimer; |
| Bobty | 5:910909f34907 | 11 | |
| Bobty | 5:910909f34907 | 12 | const int IDLE_TIMEOUT = 10; // N seconds of no REST commands -> idle |
| Bobty | 5:910909f34907 | 13 | |
| Bobty | 5:910909f34907 | 14 | Idler::Idler(DigitalOut* pStatusLed, DrawingManager* pDrawingManager) |
| Bobty | 5:910909f34907 | 15 | { |
| Bobty | 5:910909f34907 | 16 | _pStatusLed = pStatusLed; |
| Bobty | 5:910909f34907 | 17 | _pDrawingManager = pDrawingManager; |
| Bobty | 5:910909f34907 | 18 | _idleTicker.attach(&tick, 0.1); |
| Bobty | 5:910909f34907 | 19 | } |
| Bobty | 5:910909f34907 | 20 | |
| Bobty | 6:8df79fe1afcd | 21 | void Idler::start() |
| Bobty | 6:8df79fe1afcd | 22 | { |
| Bobty | 6:8df79fe1afcd | 23 | _isRunning = true; |
| Bobty | 6:8df79fe1afcd | 24 | } |
| Bobty | 6:8df79fe1afcd | 25 | |
| Bobty | 5:910909f34907 | 26 | void Idler::tick() |
| Bobty | 5:910909f34907 | 27 | { |
| Bobty | 6:8df79fe1afcd | 28 | // Check if we are running |
| Bobty | 6:8df79fe1afcd | 29 | if (!_isRunning) |
| Bobty | 6:8df79fe1afcd | 30 | return; |
| Bobty | 6:8df79fe1afcd | 31 | |
| Bobty | 5:910909f34907 | 32 | // Check if idle |
| Bobty | 5:910909f34907 | 33 | if (!_isIdle) |
| Bobty | 5:910909f34907 | 34 | { |
| Bobty | 5:910909f34907 | 35 | // Check time since last notIdle |
| Bobty | 5:910909f34907 | 36 | if (_idleTimer.read() < IDLE_TIMEOUT) |
| Bobty | 5:910909f34907 | 37 | return; |
| Bobty | 5:910909f34907 | 38 | |
| Bobty | 5:910909f34907 | 39 | // Now idle again |
| Bobty | 5:910909f34907 | 40 | _idleTimer.stop(); |
| Bobty | 5:910909f34907 | 41 | _isIdle = true; |
| Bobty | 5:910909f34907 | 42 | } |
| Bobty | 5:910909f34907 | 43 | |
| Bobty | 5:910909f34907 | 44 | // Blink LED |
| Bobty | 5:910909f34907 | 45 | *_pStatusLed = !(*_pStatusLed); |
| Bobty | 5:910909f34907 | 46 | |
| Bobty | 5:910909f34907 | 47 | // Step through display |
| Bobty | 5:910909f34907 | 48 | _pDrawingManager->DisplayIdle(_stepCount); |
| Bobty | 5:910909f34907 | 49 | _stepCount++; |
| Bobty | 5:910909f34907 | 50 | } |
| Bobty | 5:910909f34907 | 51 | |
| Bobty | 5:910909f34907 | 52 | void Idler::notIdle() |
| Bobty | 5:910909f34907 | 53 | { |
| Bobty | 5:910909f34907 | 54 | _isIdle = false; |
| Bobty | 5:910909f34907 | 55 | *_pStatusLed = false; |
| Bobty | 5:910909f34907 | 56 | _idleTimer.reset(); |
| Bobty | 5:910909f34907 | 57 | _idleTimer.start(); |
| Bobty | 5:910909f34907 | 58 | _stepCount = 0; |
| Bobty | 5:910909f34907 | 59 | } |