3#define PQRST_H_LOADED 1
11#define DOXYGEN_INCLUDE 0
18#if !defined(PQRST_SELF_QUEUE) || DOXYGEN_INCLUDE
26#define PQRST_SELF_QUEUE 0
29#if !defined(PQRST_TASK_PRIORITIES) || DOXYGEN_INCLUDE
43#define PQRST_TASK_PRIORITIES 0
46#if !defined(PQRST_TASK_IDENT) || DOXYGEN_INCLUDE
56#define PQRST_TASK_IDENT 0
59#if !defined(PQRST_WITH_SLEEPER) || DOXYGEN_INCLUDE
66#define PQRST_WITH_SLEEPER 0
90#if !ARDUINO && !defined(MS_FMT)
97#include <avr/pgmspace.h>
105#define PQRST_NEXT_UNQUEUED_ reinterpret_cast<Task*>(1)
184 virtual void start(
void);
192 TaskQueue* queue(
void)
const {
return queue_; };
236#if PQRST_TASK_PRIORITIES
448#if PQRST_WITH_SLEEPER
523 void signal_to_task1(
Task*,
int);
525 ModularTimeMinder modtime_minder_;
527#if PQRST_WITH_SLEEPER
531 Task*
volatile interrupting_task_;
539 bool queue_is_valid_p(
void)
const;
546 unsigned int size(
bool inc_maintenance=
false)
const;
566#if PQRST_WITH_SLEEPER
599 ms_t modtime(
ms_t t)
const {
return t ^ modtime_minder_.fix_; };
A task which runs a supplied function at a given time.
Definition: pqrst.h:370
FunctionTask(run_task_t, ms_t cadence=0, int repeats=-1)
Construct a task which will run the supplied function at a later time.
Definition: pqrst.cpp:1515
void run(ms_t)
Run a single iteration of the loop.
Definition: pqrst.cpp:1548
A Task which will automatically reschedule itself after it is run.
Definition: pqrst.h:303
int get_repeats(void) const
Returns the number of repeats still to do.
Definition: pqrst.h:340
void run_task(ms_t)
Run the task, additionally rescheduling it.
Definition: pqrst.cpp:1466
ms_t get_cadence(void) const
Return the interval between loop runs.
Definition: pqrst.h:333
ms_t set_cadence(ms_t)
Set the scheduling cadence.
Definition: pqrst.cpp:1422
virtual void run(ms_t)=0
Run a single iteration of the loop.
int set_repeats(int n)
Set the repeat-count of the loop.
Definition: pqrst.cpp:1438
LoopTask(ms_t cadence, int repeats=-1)
Construct a looping task.
Definition: pqrst.cpp:1406
There are a few ‘maintenance tasks’ on the queue, placed there by the queueing system.
Definition: pqrst.h:281
bool user_task_p(void) const
Indicates whether this is a user task or a maintenance task.
Definition: pqrst.h:297
friend class ModularTimeMinder
Definition: pqrst.h:282
A sleeper task is one which will run only when a given condition is true.
Definition: pqrst.h:460
virtual Awakening wake_me(void) const =0
Indicate whether the task is ready to be woken.
Awakening
An indication of how the task should be scheduled, when it is woken.
Definition: pqrst.h:472
@ WAKE
Wake and schedule due at the current time (like TaskQueue::push_after(0))
Definition: pqrst.h:473
@ KEEP_SLEEPING
Keep sleeping; do not awaken.
Definition: pqrst.h:472
@ WAKE_IMMEDIATELY
Wake and schedule immediately (like TaskQueue::push_immediately)
Definition: pqrst.h:474
SleeperTask(void)
Definition: pqrst.h:465
A Task represents a block of code to be executed at some point in the future.
Definition: pqrst.h:140
Task()
Construct a task.
Definition: pqrst.cpp:999
void set_task_ident(const char *ident_string)
Set the identification string for a task.
Definition: pqrst.h:261
unsigned char get_priority(void) const
Return the priority of the task.
Definition: pqrst.cpp:1305
void run_at(ms_t t, Task *T=nullptr)
Push a new task onto the queue, due at a given time.
Definition: pqrst.cpp:1086
static const PROGMEM char *const pqrst_version
Reports the PQRST version and compilation options.
Definition: pqrst.h:148
const char * get_task_ident(void) const
Retrieve the identification string.
Definition: pqrst.h:270
bool set_task_slippy(bool)
Set a task to be ‘slippy’.
Definition: pqrst.cpp:277
void run_after(ms_t t, Task *T=nullptr)
Push a new Task onto the queue, due some (non-negative) interval after the queue's current reference ...
Definition: pqrst.cpp:1111
ms_t get_duration(void) const
Return the task's expected duration.
Definition: pqrst.cpp:1338
bool before(const Task *) const
Impose an ordering on tasks.
Definition: pqrst.cpp:212
virtual bool user_task_p(void) const
True if this is a ‘user task’, as opposed to a maintenance task.
Definition: pqrst.h:250
bool is_enqueued_p(void) const
Return true if the task is currently scheduled on a queue.
Definition: pqrst.h:232
virtual ~Task()
Definition: pqrst.h:181
bool get_task_slippy(void) const
Determine whether a task is ‘slippy’.
Definition: pqrst.cpp:295
ms_t ready_after(void) const
Return the interval until the Task is next ready, relative to the queue reference time.
Definition: pqrst.cpp:712
ms_t cancel(void)
Cancel this task.
Definition: pqrst.cpp:1140
void set_priority(unsigned char)
Set the priority of the task.
Definition: pqrst.cpp:1288
ms_t uncancel(void)
Uncancel a task.
Definition: pqrst.cpp:1174
virtual void signal(int signal, ms_t t)
Receive a signal.
Definition: pqrst.cpp:1223
void run_immediately(Task *T=nullptr)
Push a task onto the queue, due immediately.
Definition: pqrst.cpp:1125
virtual void run_task(ms_t)
Run this task; this is the method which is actually called when a task is due to be run.
Definition: pqrst.cpp:1241
virtual void run(ms_t t)=0
Runs one step of the task.
virtual void start(void)
Start the task immediately.
Definition: pqrst.cpp:1062
void set_duration(ms_t)
Set the duration of the task.
Definition: pqrst.cpp:1322
A priority queue of Tasks.
Definition: pqrst.h:517
int lateness(ms_t) const
Return the interval between the given time and the queue's ‘reference time’.
Definition: pqrst.cpp:769
void push_immediately_interrupting(Task *)
Push the given task on the queue, in a way functionally equivalent to push_immediately,...
Definition: pqrst.cpp:526
void push_at(Task *, ms_t)
Push the given task onto the queue, due at time t.
Definition: pqrst.cpp:365
void push_immediately(Task *)
Push the given task on the queue, due immediately (in particular, at the current reference time).
Definition: pqrst.cpp:496
bool is_empty(void) const
Return true if the task queue is empty.
Definition: pqrst.cpp:301
void push_after(Task *, ms_t)
Push the given task onto the queue, due some (non-negative) interval after the current reference time...
Definition: pqrst.cpp:470
void add_sleeper(SleeperTask *w)
Add a sleeping task.
Definition: pqrst.h:579
void clear_sleeper(void)
Clear the sleeper task.
Definition: pqrst.h:585
void remove(Task *)
Remove from the queue an element which is == to the given Task.
Definition: pqrst.cpp:626
void traverse_queue(traverse_queue_cb_t, int max=-1)
Traverse the queue.
Definition: pqrst.cpp:829
ms_t next_due_after(void) const
Return the interval between the queue reference time and the due-time of the task at the head of the ...
Definition: pqrst.cpp:729
void dump_queue_contents(void)
Dump the queue.
Definition: pqrst.cpp:888
void initialise(ms_t start_reftime=0)
Initialise, or reinitialise, a TaskQueue.
Definition: pqrst.cpp:145
void remove_all_tasks(void)
Discard all of the tasks from the queue, without running them.
Definition: pqrst.cpp:907
TaskQueue(void)
Creates a new TaskQueue.
Definition: pqrst.cpp:107
unsigned int size(bool inc_maintenance=false) const
Return the number of user tasks currently in the queue.
Definition: pqrst.cpp:322
void signal(int, ms_t)
Pass the given integer on to each task in the queue.
Definition: pqrst.cpp:806
bool run_ready(ms_t)
If the head task in the queue is ready at the given time (ie, its due time is at or before that time)...
Definition: pqrst.cpp:670
void(* run_task_t)(ms_t t)
The type of the function which can be supplied to a FunctionTask.
Definition: pqrst.h:360
uint32_t ms_t
The Arduino supports a time type of unsigned long, which is a 4-byte unsigned integer on that platfor...
Definition: pqrst.h:84
const ms_t TIME_NEVER
TIME_NEVER is a time which will never happen.
Definition: pqrst.h:120
TaskQueue Queue
The global TaskQueue.
Definition: pqrst.cpp:1555
void(* traverse_queue_cb_t)(ms_t due, const char *ident, const Task *T)
The type of the callback for TaskQueue::traverse_queue.
Definition: pqrst.h:398