TaskSched
|
Represents a schedulable task. More...
#include <TaskSched.h>
Public Types | |
typedef void(* | TaskCallback) (Task *) |
typedef void(* | VoidCallback) () |
Public Member Functions | |
Task (TaskCallback func, unsigned long interval=5000, bool enabled=false, int iterations=0, const char *name="Unk", bool runImmediately=false) | |
Constructs a new Task. More... | |
Task (VoidCallback func, unsigned long interval=5000, bool enabled=false, int iterations=0, const char *name="Unk", bool runImmediately=false) | |
bool | isFirstIteration () |
return true if this is the first iteration More... | |
bool | isLastIteration () |
return true if this is the last iteration More... | |
bool | fRunImmediately () |
return true if the run immediately flag is set More... | |
void | restart () |
restart the task with the original parameters, Enable is not restored More... | |
void | enable () |
enable the task More... | |
void | disable () |
disable the task More... | |
bool | isEnabled () const |
return true if task is enabled More... | |
void | setCallback (const TaskCallback &callback) |
Sets a new callback function for the task. More... | |
void | setCallback (const VoidCallback &callback) |
Sets a new callback function for the task. More... | |
void | setName (String) |
give the task a new name More... | |
void | showInit () |
display stuff More... | |
String | getName () const |
return string containing name of task More... | |
unsigned long | getIterationCount () const |
return the iteration count, that is the number of iterations that the task has been run More... | |
void | setInterval (unsigned long newInterval) |
function to set a new interval More... | |
void | setIterations (unsigned long newIterations) |
function to set a new iterations value More... | |
void | setImmediately (bool) |
function to set the run immediately flag More... | |
String | showTaskInfo () const |
function that displays task info More... | |
unsigned long | getInterval (void) const |
return the task interval More... | |
bool | getRunImmediately (void) const |
return the run immediately flag More... | |
unsigned long | getLastStartTime (void) const |
return the last start time flag More... | |
Static Public Member Functions | |
static String | formatMS (unsigned long milliseconds) |
return a string with a formatted time More... | |
Friends | |
class | Sched |
Represents a schedulable task.
Define a new Task.
func | Function to be called at regular intervals. |
interval | Time between calls to func, specified in milliseconds or seconds. If interval is a floating-point value, it's interpreted as seconds; otherwise, it's treated as milliseconds. |
enabled | Flag to indicate whether the task should start in an enabled state (true) or disabled state (false). |
iterations | Number of times the task will be executed. Set to 0 for infinite iterations. |
name | A descriptive string name for the task. |
runImmediately | Boolean flag determining whether to run the callback immediately (true) or wait for the interval to expire (false). Output:
450 Task On2, Enabled? 0, Diff 00:15.735, Interval 00:02.000, RI 1
450 Task On1, Enabled? 0, Diff 00:15.735, Interval 00:00.100, RI 0
450 Task On, Enabled? 1, Diff 00:01.721, Interval 00:01.000, RI 0
Task(TaskCallback func, unsigned long interval=5000, bool enabled=false, int iterations=0, const char *name="Unk", bool runImmediately=false) Constructs a new Task. Definition: TaskSched.cpp:7 |
The Task class encapsulates a function to be called at regular intervals, along with parameters controlling its execution.
Definition at line 80 of file TaskSched.h.
typedef void(* Task::TaskCallback) (Task *) |
Definition at line 92 of file TaskSched.h.
typedef void(* Task::VoidCallback) () |
Definition at line 93 of file TaskSched.h.
Task::Task | ( | TaskCallback | func, |
unsigned long | interval = 5000 , |
||
bool | enabled = false , |
||
int | iterations = 0 , |
||
const char * | name = "Unk" , |
||
bool | runImmediately = false |
||
) |
Constructs a new Task.
T | Type of the interval (can be integral or floating-point) |
func | Function to be called at regular intervals |
interval | Time between calls to func (in milliseconds if integral, seconds if floating-point) |
enabled | Flag to indicate whether the task should start in an enabled state |
iterations | Number of times the task will be executed (0 for infinite) |
name | A descriptive name for the task |
runImmediately | Whether to run the callback immediately or wait for the interval |
Definition at line 7 of file TaskSched.cpp.
References InitialState::mEnabled, InitialState::mInterval, InitialState::mIterations, and InitialState::mRunImmediately.
Task::Task | ( | VoidCallback | func, |
unsigned long | interval = 5000 , |
||
bool | enabled = false , |
||
int | iterations = 0 , |
||
const char * | name = "Unk" , |
||
bool | runImmediately = false |
||
) |
Definition at line 25 of file TaskSched.cpp.
References InitialState::mEnabled, InitialState::mInterval, InitialState::mIterations, and InitialState::mRunImmediately.
void Task::disable | ( | ) |
disable the task
Definition at line 66 of file TaskSched.cpp.
void Task::enable | ( | ) |
enable the task
Definition at line 128 of file TaskSched.cpp.
|
static |
return a string with a formatted time
Definition at line 87 of file TaskSched.cpp.
Referenced by showInit(), and showTaskInfo().
bool Task::fRunImmediately | ( | ) |
return true if the run immediately flag is set
unsigned long Task::getInterval | ( | void | ) | const |
return the task interval
Definition at line 183 of file TaskSched.cpp.
Referenced by showTaskInfo().
unsigned long Task::getIterationCount | ( | ) | const |
return the iteration count, that is the number of iterations that the task has been run
Definition at line 193 of file TaskSched.cpp.
unsigned long Task::getLastStartTime | ( | void | ) | const |
return the last start time flag
Definition at line 188 of file TaskSched.cpp.
Referenced by showTaskInfo().
String Task::getName | ( | ) | const |
return string containing name of task
Definition at line 50 of file TaskSched.cpp.
Referenced by Sched::addTask(), Sched::run(), and showTaskInfo().
bool Task::getRunImmediately | ( | void | ) | const |
return the run immediately flag
Definition at line 178 of file TaskSched.cpp.
Referenced by showTaskInfo().
bool Task::isEnabled | ( | ) | const |
return true if task is enabled
Definition at line 124 of file TaskSched.cpp.
Referenced by Sched::run(), and showTaskInfo().
bool Task::isFirstIteration | ( | ) |
bool Task::isLastIteration | ( | ) |
void Task::restart | ( | ) |
restart the task with the original parameters, Enable is not restored
Definition at line 137 of file TaskSched.cpp.
References InitialState::mInterval, InitialState::mIterations, and InitialState::mRunImmediately.
void Task::setCallback | ( | const TaskCallback & | callback | ) |
Sets a new callback function for the task.
callback | The new callback function |
Definition at line 154 of file TaskSched.cpp.
void Task::setCallback | ( | const VoidCallback & | callback | ) |
Sets a new callback function for the task.
callback | The new callback function |
Definition at line 149 of file TaskSched.cpp.
void Task::setImmediately | ( | bool | newImmediately | ) |
function to set the run immediately flag
Definition at line 163 of file TaskSched.cpp.
void Task::setInterval | ( | unsigned long | newInterval | ) |
function to set a new interval
Definition at line 173 of file TaskSched.cpp.
void Task::setIterations | ( | unsigned long | newIterations | ) |
function to set a new iterations value
Definition at line 168 of file TaskSched.cpp.
void Task::setName | ( | String | newName | ) |
give the task a new name
Definition at line 159 of file TaskSched.cpp.
void Task::showInit | ( | ) |
display stuff
Definition at line 72 of file TaskSched.cpp.
References formatMS().
Referenced by Sched::run().
String Task::showTaskInfo | ( | ) | const |
function that displays task info
Definition at line 102 of file TaskSched.cpp.
References formatMS(), getInterval(), getLastStartTime(), getName(), getRunImmediately(), and isEnabled().
|
friend |
Definition at line 88 of file TaskSched.h.