Member Functions

List of all member functions with their input parameters and return types.

Constructors & Destructor

ptScheduler (time_us_t interval_1);

This is the simplest method to create a ptScheduler object.

Parameters :

  1. interval_1 : Time in microseconds. The task mode is set to PT_MODE_ONESHOT and other values to their defaults. An array will be dynamically allocated to hold the interval value and the pointer sequenceList 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

ptScheduler (uint8_t _mode, time_us_t interval_1);

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 :

  1. _mode : Any of the two supported task modes.

  2. interval_1 : Time in microseconds.

Return : Nothing

ptScheduler (uint8_t mode, time_us_t* sequencePtr, uint8_t sequenceLen);

Create a task with an arbitrary number of intervals. You first have to create an array of interval values something like below,

time_us_t intervalArray[] = {1000000, 2000000, 3000000, 2500000, 4000000}; 

then pass the address to the constructor like below,

ptScheduler oneshotTask = ptScheduler (PT_MODE_ONESHOT, intervalArray, 3);

Parameters :

  1. mode : Any of the two supported modes.

  2. sequencePtr : Address of array of intervals.

  3. 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

~ptScheduler();

The destructor does nothing.

Parameters : None

Return : Nothing

reset()

void 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()

void enable();

This function enables a task by setting the taskEnabled status variable to true. Only enabled tasks can run.

Parameters : None

Return : Nothing

disable()

void 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()

void 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()

void resume();

Resumes a suspended task. This has no effect on a disabled task.

Parameters : None

Return : Nothing

call()

bool 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 :

  1. true : Run the code block

  2. false : Skip the code block

setInterval()

bool setInterval (time_us_t value);

Use this function if you need to change the first interval on the list after creating the object.

Parameters :

  1. value : Time in microseconds

Return :

  1. true : Setting interval was successful.

  2. false : Setting interval was unsuccessful. It can only fail if the sequenceLength was 0.

setSequenceRepetition()

bool setSequenceRepetition (int32_t value);

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 :

  1. 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 :

  1. true : Setting repetitions was successful.

  2. false : Setting repetitions was unsuccessful. This can only fail if the taskMode is invalid.

setSkipInterval()

bool setSkipInterval (uint32_t value);

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 :

  1. value : Number of intervals to skip (positive integer). A value of 0 resets skipTime value.

Return :

  1. true : Setting skip interval was successful.

  2. false : Setting skip interval was unsuccessful. This can only fail if sequenceLength was 0.

setSkipSequence()

bool setSkipSequence (uint32_t value);

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 :

  1. value : Number of sequences to skip (positive integer). A value of 0 resets skipTime value.

Return :

  1. true : Setting skip iteration was successful.

  2. false : Setting skip iteration was unsuccessful. This can only fail if sequenceLength was 0.

setSkipTime()

bool setSkipTime (time_us_t value);

This directly sets the skipTime and the skipTimeSet flag.

Parameters :

  1. value : Time in microseconds

Return :

  1. true : Setting skip time was successful.

  2. false : Setting skip time was unsuccessful. This can only fail if intervalCount was 0.

setTaskMode()

bool setTaskMode (uint8_t mode);

Sets the task mode.

Parameters :

  1. mode : One of the two supported modes.

Return :

  1. true : Setting task mode was successful.

  2. false : Setting task mode was unsuccessful. This can only fail if the input value was invalid. In case of error, the inputError is set to true.

setSleepMode()

bool setSleepMode (uint8_t mode);

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 :

  1. mode : One of the two supported modes – PT_SLEEP_DISABLE, PT_SLEEP_SUSPEND

Return :

  1. true : Setting sleep mode was successful.

  2. false : Setting sleep mode was unsuccessful. This can only fail if the input value was invalid. In case of error, the inputError is set to true.

isInputError()

bool 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 :

  1. true : inputError is true.

  2. false : No input error.

printStats()

void printStats();

Prints all the status variables, flags and counters to the serial port. Useful for debugging.

Parameters : None

Return : Nothing

getTimeElapsed()

void getTimeElapsed();

This calculates the elapsed time and stores the value to elapsedTime. This function is created to deal with overflow events.

Last updated