Rob Dobson / Mbed 2 deprecated SpideyWallWeb

Dependencies:   EthernetInterfacePlusHostname RdWebServer mbed-rtos mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Idler.cpp Source File

Idler.cpp

00001 
00002 #include "Idler.h"
00003 
00004 DigitalOut* Idler::_pStatusLed = NULL;
00005 bool Idler::_isRunning = false;
00006 bool Idler::_isIdle = true;
00007 unsigned int Idler::_stepCount = 0;
00008 DrawingManager* Idler::_pDrawingManager = NULL;
00009 Ticker Idler::_idleTicker;
00010 Timer Idler::_idleTimer;
00011 
00012 const int IDLE_TIMEOUT = 10; // N seconds of no REST commands -> idle
00013 
00014 Idler::Idler(DigitalOut* pStatusLed, DrawingManager* pDrawingManager)
00015 {
00016     _pStatusLed = pStatusLed;
00017     _pDrawingManager = pDrawingManager;
00018     _idleTicker.attach(&tick, 0.1);
00019 }
00020 
00021 void Idler::start()
00022 {
00023     _isRunning = true;
00024 }
00025 
00026 void Idler::tick()
00027 {
00028     // Check if we are running
00029     if (!_isRunning)
00030         return;
00031         
00032     // Check if idle
00033     if (!_isIdle)
00034     {
00035         // Check time since last notIdle
00036         if (_idleTimer.read() < IDLE_TIMEOUT)
00037             return;
00038         
00039         // Now idle again
00040         _idleTimer.stop();
00041         _isIdle = true;
00042     }
00043 
00044     // Blink LED
00045     *_pStatusLed = !(*_pStatusLed);
00046     
00047     // Step through display
00048     _pDrawingManager->DisplayIdle(_stepCount);
00049     _stepCount++;
00050 }
00051 
00052 void Idler::notIdle()
00053 {
00054     _isIdle = false;
00055     *_pStatusLed = false;
00056     _idleTimer.reset();
00057     _idleTimer.start();
00058     _stepCount = 0;
00059 }