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@5:910909f34907, 2015-09-01 (annotated)
- Committer:
- Bobty
- Date:
- Tue Sep 01 15:53:52 2015 +0000
- Revision:
- 5:910909f34907
- Child:
- 6:8df79fe1afcd
Added an idle handler so there is something to show when nothing is being sent over HTTP
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 | 5:910909f34907 | 5 | bool Idler::_isIdle = true; |
| Bobty | 5:910909f34907 | 6 | unsigned int Idler::_stepCount = 0; |
| Bobty | 5:910909f34907 | 7 | DrawingManager* Idler::_pDrawingManager = NULL; |
| Bobty | 5:910909f34907 | 8 | Ticker Idler::_idleTicker; |
| Bobty | 5:910909f34907 | 9 | Timer Idler::_idleTimer; |
| Bobty | 5:910909f34907 | 10 | |
| Bobty | 5:910909f34907 | 11 | const int IDLE_TIMEOUT = 10; // N seconds of no REST commands -> idle |
| Bobty | 5:910909f34907 | 12 | |
| Bobty | 5:910909f34907 | 13 | Idler::Idler(DigitalOut* pStatusLed, DrawingManager* pDrawingManager) |
| Bobty | 5:910909f34907 | 14 | { |
| Bobty | 5:910909f34907 | 15 | _pStatusLed = pStatusLed; |
| Bobty | 5:910909f34907 | 16 | _pDrawingManager = pDrawingManager; |
| Bobty | 5:910909f34907 | 17 | _idleTicker.attach(&tick, 0.1); |
| Bobty | 5:910909f34907 | 18 | } |
| Bobty | 5:910909f34907 | 19 | |
| Bobty | 5:910909f34907 | 20 | void Idler::tick() |
| Bobty | 5:910909f34907 | 21 | { |
| Bobty | 5:910909f34907 | 22 | // Check if idle |
| Bobty | 5:910909f34907 | 23 | if (!_isIdle) |
| Bobty | 5:910909f34907 | 24 | { |
| Bobty | 5:910909f34907 | 25 | // Check time since last notIdle |
| Bobty | 5:910909f34907 | 26 | if (_idleTimer.read() < IDLE_TIMEOUT) |
| Bobty | 5:910909f34907 | 27 | return; |
| Bobty | 5:910909f34907 | 28 | |
| Bobty | 5:910909f34907 | 29 | // Now idle again |
| Bobty | 5:910909f34907 | 30 | _idleTimer.stop(); |
| Bobty | 5:910909f34907 | 31 | _isIdle = true; |
| Bobty | 5:910909f34907 | 32 | } |
| Bobty | 5:910909f34907 | 33 | |
| Bobty | 5:910909f34907 | 34 | // Blink LED |
| Bobty | 5:910909f34907 | 35 | *_pStatusLed = !(*_pStatusLed); |
| Bobty | 5:910909f34907 | 36 | |
| Bobty | 5:910909f34907 | 37 | // Step through display |
| Bobty | 5:910909f34907 | 38 | _pDrawingManager->DisplayIdle(_stepCount); |
| Bobty | 5:910909f34907 | 39 | _stepCount++; |
| Bobty | 5:910909f34907 | 40 | } |
| Bobty | 5:910909f34907 | 41 | |
| Bobty | 5:910909f34907 | 42 | void Idler::notIdle() |
| Bobty | 5:910909f34907 | 43 | { |
| Bobty | 5:910909f34907 | 44 | _isIdle = false; |
| Bobty | 5:910909f34907 | 45 | *_pStatusLed = false; |
| Bobty | 5:910909f34907 | 46 | _idleTimer.reset(); |
| Bobty | 5:910909f34907 | 47 | _idleTimer.start(); |
| Bobty | 5:910909f34907 | 48 | _stepCount = 0; |
| Bobty | 5:910909f34907 | 49 | } |