TaskSched
Public Member Functions | List of all members
Sched Class Reference

This class runs the scheduled tasks. More...

#include <TaskSched.h>

Public Member Functions

unsigned long getSize ()
 return the number of tasks in the run queue More...
 
 Sched ()
 
void begin ()
 
void addTask (Task *task)
 
void enable ()
 enable the scheduler More...
 
void disable ()
 disable the scheduler More...
 
bool isEnabled ()
 return true if the scheduler is enabled More...
 
const SimpleList< Task * > & getTasks () const
 
void run ()
 called perodically to check if a task should be scheduled More...
 

Detailed Description

This class runs the scheduled tasks.

Task* t = new Task(turnLedOn, 1000,true,20,"OnOff",true);
Task t1(turnLedOn, 100,false,20,"On1",false);
Task t2(turnLedOn, 2.0,false,20,"On2",false);
Represents a schedulable task.
Definition: TaskSched.h:80

It's kinda like the DTO in the Java world.

Definition at line 279 of file TaskSched.h.

Constructor & Destructor Documentation

◆ Sched()

Sched::Sched ( )

Constructor

Definition at line 238 of file TaskSched.cpp.

238  {
239 }

Member Function Documentation

◆ addTask()

void Sched::addTask ( Task task)
Example:
Task* t = new Task(turnLedOn, 1000,true,20,"OnOff",true);
Task t1(dummy, 100, false, 20, "On1", * false);
Task t2(dummy, 2.0, false, 20, "On2", * false);
scheduler.addTask(t);
scheduler.addTask(&t1);
scheduler.addTask(&t2);

Definition at line 244 of file TaskSched.cpp.

245 {
246 #ifdef DEBUG
247  Serial.printf("add called for task, %s %x\n",task->getName().c_str(),task);
248 #endif
249  tTasks.push_back(task);
250  return;
251 };
void push_back(const T &value)
Add a new element to the end of the list.
Definition: SimpleList.h:51
String getName() const
return string containing name of task
Definition: TaskSched.cpp:50

References Task::getName(), and SimpleList< T >::push_back().

◆ begin()

void Sched::begin ( )

used to start the scheduling. A call to begin will also enable the scheduler.

Sched scheduler;
scheduler.begin();
This class runs the scheduled tasks.
Definition: TaskSched.h:280
void begin()
Definition: TaskSched.cpp:241

Definition at line 241 of file TaskSched.cpp.

241  {
242  this->mSchedEnabled=true;
243 }

◆ disable()

void Sched::disable ( )

disable the scheduler

Definition at line 256 of file TaskSched.cpp.

256  {
257  this->mSchedEnabled=false;
258 }

◆ enable()

void Sched::enable ( )

enable the scheduler

Definition at line 253 of file TaskSched.cpp.

253  {
254  this->mSchedEnabled=true;
255 }

◆ getSize()

unsigned long Sched::getSize ( )

return the number of tasks in the run queue

Returns

Definition at line 233 of file TaskSched.cpp.

234 {
235  return tTasks.get_size();
236 }
size_t get_size() const
Get the number of elements in the list.
Definition: SimpleList.h:116

References SimpleList< T >::get_size().

◆ getTasks()

const SimpleList< Task * > & Sched::getTasks ( ) const

brief

Definition at line 290 of file TaskSched.cpp.

291 {
292  return tTasks;
293 }

◆ isEnabled()

bool Sched::isEnabled ( )

return true if the scheduler is enabled

Returns

Definition at line 259 of file TaskSched.cpp.

259  {
260  return this->mSchedEnabled;
261 }

◆ run()

void Sched::run ( )

called perodically to check if a task should be scheduled

Definition at line 265 of file TaskSched.cpp.

266 {
267  if(this->mSchedEnabled) {
268 #ifdef DEBUG
269  // Serial.println("Looking for tasks");
270 #endif
271  for (auto it = tTasks.begin(); it != tTasks.end(); ++it) {
272  // for (it = tTasks.begin(); it != tTasks.end(); ++it){
273  Task* currentTask = *it;
274 
275 #ifdef DEBUGR
276  Serial.printf("%s %d task=%x i=%d millis()=%ld Found name=%s, Is enabled? %d\n",__FILE__,__LINE__,currentTask,i++,millis(),currentTask->getName().c_str(),currentTask->isEnabled());
277  currentTask->showInit();
278 #endif
279  if(currentTask->isEnabled()) {
280  currentTask->runIt();
281  }
282  }
283  } else {
284 #ifdef DEBUG
285  Serial.println("Not enabled");
286 #endif
287  }
288 }
iterator begin() const
Get an iterator pointing to the beginning of the list.
Definition: SimpleList.h:273
iterator end() const
Get an iterator pointing to the end of the list.
Definition: SimpleList.h:280
void showInit()
display stuff
Definition: TaskSched.cpp:72
bool isEnabled() const
return true if task is enabled
Definition: TaskSched.cpp:124

References SimpleList< T >::begin(), SimpleList< T >::end(), Task::getName(), Task::isEnabled(), and Task::showInit().


The documentation for this class was generated from the following files: