Simple task manager which uses a Ticker

Committer:
Phlaphead
Date:
Fri Jan 14 20:04:13 2011 +0000
Revision:
1:e95b703c6ad7
Parent:
0:e381c3adaa04
Child:
2:3cb7f5770feb
added stop and isRunning methods

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Phlaphead 0:e381c3adaa04 1 #ifndef Task_h
Phlaphead 0:e381c3adaa04 2 #define Task_h
Phlaphead 0:e381c3adaa04 3
Phlaphead 0:e381c3adaa04 4 #include "mbed.h"
Phlaphead 0:e381c3adaa04 5
Phlaphead 0:e381c3adaa04 6 #define DEFAULT_INTERVAL 1000 //1ms
Phlaphead 0:e381c3adaa04 7
Phlaphead 1:e95b703c6ad7 8
Phlaphead 0:e381c3adaa04 9 class Task
Phlaphead 0:e381c3adaa04 10 {
Phlaphead 0:e381c3adaa04 11
Phlaphead 0:e381c3adaa04 12 public:
Phlaphead 0:e381c3adaa04 13
Phlaphead 0:e381c3adaa04 14 Task();
Phlaphead 0:e381c3adaa04 15 Task(int _interval);
Phlaphead 1:e95b703c6ad7 16
Phlaphead 0:e381c3adaa04 17 void start();
Phlaphead 0:e381c3adaa04 18 virtual void tick() = 0;
Phlaphead 1:e95b703c6ad7 19 void stop();
Phlaphead 1:e95b703c6ad7 20
Phlaphead 1:e95b703c6ad7 21 bool isRunning() { return running; }
Phlaphead 0:e381c3adaa04 22
Phlaphead 0:e381c3adaa04 23
Phlaphead 0:e381c3adaa04 24 protected:
Phlaphead 0:e381c3adaa04 25
Phlaphead 0:e381c3adaa04 26 void setInterval(int _interval) { interval = _interval; }
Phlaphead 0:e381c3adaa04 27
Phlaphead 0:e381c3adaa04 28
Phlaphead 0:e381c3adaa04 29 private:
Phlaphead 0:e381c3adaa04 30
Phlaphead 0:e381c3adaa04 31 Ticker ticker;
Phlaphead 0:e381c3adaa04 32 int interval;
Phlaphead 1:e95b703c6ad7 33 bool running;
Phlaphead 0:e381c3adaa04 34
Phlaphead 0:e381c3adaa04 35 void preTick();
Phlaphead 0:e381c3adaa04 36
Phlaphead 0:e381c3adaa04 37 };
Phlaphead 0:e381c3adaa04 38
Phlaphead 0:e381c3adaa04 39 #endif