Simple task manager which uses a Ticker

Committer:
Phlaphead
Date:
Fri Jan 14 20:24:54 2011 +0000
Revision:
2:3cb7f5770feb
Parent:
1:e95b703c6ad7
Added documentation

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Phlaphead 0:e381c3adaa04 1
Phlaphead 0:e381c3adaa04 2 #include "Task.h"
Phlaphead 0:e381c3adaa04 3
Phlaphead 0:e381c3adaa04 4 Task::Task()
Phlaphead 0:e381c3adaa04 5 {
Phlaphead 0:e381c3adaa04 6 interval = DEFAULT_INTERVAL;
Phlaphead 0:e381c3adaa04 7 }
Phlaphead 0:e381c3adaa04 8
Phlaphead 0:e381c3adaa04 9 Task::Task(int _interval)
Phlaphead 0:e381c3adaa04 10 {
Phlaphead 0:e381c3adaa04 11 interval = _interval;
Phlaphead 0:e381c3adaa04 12 }
Phlaphead 0:e381c3adaa04 13
Phlaphead 0:e381c3adaa04 14 void Task::start()
Phlaphead 0:e381c3adaa04 15 {
Phlaphead 0:e381c3adaa04 16 ticker.attach_us(this, &Task::preTick, interval);
Phlaphead 1:e95b703c6ad7 17 running = true;
Phlaphead 0:e381c3adaa04 18 }
Phlaphead 0:e381c3adaa04 19
Phlaphead 0:e381c3adaa04 20
Phlaphead 0:e381c3adaa04 21 void Task::preTick()
Phlaphead 0:e381c3adaa04 22 {
Phlaphead 0:e381c3adaa04 23 this->tick();
Phlaphead 1:e95b703c6ad7 24 }
Phlaphead 1:e95b703c6ad7 25
Phlaphead 1:e95b703c6ad7 26 void Task::stop()
Phlaphead 1:e95b703c6ad7 27 {
Phlaphead 1:e95b703c6ad7 28 ticker.detach();
Phlaphead 1:e95b703c6ad7 29 running = false;
Phlaphead 1:e95b703c6ad7 30 }
Phlaphead 1:e95b703c6ad7 31