Member Functions
List of all member functions with their input parameters and return types.
Constructors & Destructor
This is the simplest method to create a ptScheduler object.
Parameters :
interval_1
: Time in microseconds. The task mode is set toPT_MODE_ONESHOT
and other values to their defaults. An array will be dynamically allocated to hold the interval value and the pointersequenceList
is updated with the address of this location.sequenceLength
is set to 1. You can not add more intervals to this list later.
Return : Nothing
This is the same as the previous one but we can explicitly specify the task mode. You can not add more intervals to this list later.
Parameters :
_mode
: Any of the two supported task modes.interval_1
: Time in microseconds.
Return : Nothing
Create a task with an arbitrary number of intervals. You first have to create an array of interval values something like below,
then pass the address to the constructor like below,
Parameters :
mode
: Any of the two supported modes.sequencePtr
: Address of array of intervals.sequenceLen
: Number of intervals in the array. This value should be less than or equal to the number of values in the array.
Return : Nothing
The destructor does nothing.
Parameters : None
Return : Nothing
reset()
reset()
This function resets all status variables and counters to their default values. But no user-defined values will be reset, such as the intervals, repetitions, skip time etc. After resetting, it will also enable the task allowing you to start fresh.
Parameters : None
Return : Nothing
enable()
enable()
This function enables a task by setting the taskEnabled
status variable to true
. Only enabled tasks can run.
Parameters : None
Return : Nothing
disable()
disable()
This function disables a task by setting the taskEnabled
status variable to false
and also resetting task variables other than user-defined ones. Only enabled tasks can run.
Parameters : None
Return : Nothing
suspend()
suspend()
Suspending a task means it will no longer return true
even if the intervals are elapsed. But some of the counter variables will continue to increment. A task remains in suspended mode until we manually resume it with resume()
. In suspended mode, suspendedIntervalCounter
will continue to increment for every interval passed. If you have multiple intervals, each of them will cause suspendedIntervalCounter
to increment in a round-robin fashion. You can use this counter to resume the task at a later point using the resume()
function.
Parameters : None
Return : Nothing
resume()
resume()
Resumes a suspended task. This has no effect on a disabled task.
Parameters : None
Return : Nothing
call()
call()
This is the main task invocation function. You should enclose this function inside any conditional statements to run the block of code under it. If it is time to run a task, call()
will return true
, and otherwise false
.
Parameters : None
Return :
true
: Run the code blockfalse
: Skip the code block
setInterval()
setInterval()
Use this function if you need to change the first interval on the list after creating the object.
Parameters :
value
: Time in microseconds
Return :
true
: Setting interval was successful.false
: Setting interval was unsuccessful. It can only fail if thesequenceLength
was 0.
setSequenceRepetition
()
setSequenceRepetition
()
This sets the repetition of a task. After the specified number of sequence repetitions are executed, the task will enter sleep mode. The sleep mode is determined by what you have set with setSleepMode()
.
Parameters :
value
: Number of repetitions (positive integer). If you set it to 0, the sequence will repeat indefinitely. Any values greater than 0 will create a finite repetition task.
Return :
true
: Setting repetitions was successful.false
: Setting repetitions was unsuccessful. This can only fail if thetaskMode
is invalid.
setSkipInterval()
setSkipInterval()
This calculates the skip time from the interval values. For example, if the interval is 1000 us, setting setSkipInterval(5)
will produce a skip time of 5 * 1000 = 5000 us. If you have multiple intervals, each of the intervals will be added up to value
times. The final value is assigned to skipTime
and the flags skipIntervalSet
and skipTimeSet
are set to true
.
Parameters :
value
: Number of intervals to skip (positive integer). A value of 0 resetsskipTime
value.
Return :
true
: Setting skip interval was successful.false
: Setting skip interval was unsuccessful. This can only fail ifsequenceLength
was 0.
setSkipSequence()
setSkipSequence()
This calculates the skip time from the sequence values. A sequence is a set of one or more interval values. The skip time is calculated as value * (sum of intervals in the sequence list)
. The final value is assigned to skipTime
and the flags skipSequenceSet
and skipTimeSet
are set to true
.
Parameters :
value
: Number of sequences to skip (positive integer). A value of 0 resetsskipTime
value.
Return :
true
: Setting skip iteration was successful.false
: Setting skip iteration was unsuccessful. This can only fail ifsequenceLength
was 0.
setSkipTime()
setSkipTime()
This directly sets the skipTime
and the skipTimeSet
flag.
Parameters :
value
: Time in microseconds
Return :
true
: Setting skip time was successful.false
: Setting skip time was unsuccessful. This can only fail ifintervalCount
was 0.
setTaskMode()
setTaskMode()
Sets the task mode.
Parameters :
mode
: One of the two supported modes.
Return :
true
: Setting task mode was successful.false
: Setting task mode was unsuccessful. This can only fail if the input value was invalid. In case of error, theinputError
is set totrue
.
setSleepMode()
setSleepMode()
Sets the sleep mode. A task enters into sleep mode after completing the specified number of repetitions. The values can be, PT_SLEEP_DISABLE
for disabling the task (reset all states and counters) or PT_SLEEP_SUSPEND
for suspending the task.
Parameters :
mode
: One of the two supported modes –PT_SLEEP_DISABLE
,PT_SLEEP_SUSPEND
Return :
true
: Setting sleep mode was successful.false
: Setting sleep mode was unsuccessful. This can only fail if the input value was invalid. In case of error, theinputError
is set totrue
.
isInputError()
isInputError()
If any of the user inputs are invalid, the inputError
flag is set. This function will return the value of inputError
and also reset it.
Parameters : None
Return :
true
:inputError
is true.false
: No input error.
printStats()
printStats()
Prints all the status variables, flags and counters to the serial port. Useful for debugging.
Parameters : None
Return : Nothing
getTimeElapsed()
getTimeElapsed()
This calculates the elapsed time and stores the value to elapsedTime
. This function is created to deal with overflow events.
Last updated