aboutsummaryrefslogtreecommitdiff
path: root/examples/Scheduler_example04_StatusRequest
diff options
context:
space:
mode:
authorAnatoli Arkhipenko <arkhipenko@hotmail.com>2015-12-23 17:04:21 -0500
committerAnatoli Arkhipenko <arkhipenko@hotmail.com>2015-12-23 17:12:06 -0500
commit965f1b768d3d0675e2483ca62fa6d0565c389a31 (patch)
tree8bae4e1eee8275efaab252b35cb26c6a304fb015 /examples/Scheduler_example04_StatusRequest
parent42d8d776e3fdb3c48700a3d88c8615dbf81da23f (diff)
Version 2.0.0 support for layered task prioritizationv2.0.0
* _TASK_PRIORITY - support for layered task prioritization
Diffstat (limited to 'examples/Scheduler_example04_StatusRequest')
-rw-r--r--examples/Scheduler_example04_StatusRequest/Scheduler_example04_StatusRequest.ino88
1 files changed, 88 insertions, 0 deletions
diff --git a/examples/Scheduler_example04_StatusRequest/Scheduler_example04_StatusRequest.ino b/examples/Scheduler_example04_StatusRequest/Scheduler_example04_StatusRequest.ino
new file mode 100644
index 0000000..22f1dbc
--- /dev/null
+++ b/examples/Scheduler_example04_StatusRequest/Scheduler_example04_StatusRequest.ino
@@ -0,0 +1,88 @@
+/** This test demonstrates interaction between three simple tasks via StatusRequest object.
+ * Task T1 runs every 5 seconds and signals completion of a status request st.
+ * Tasks T2 and T3 are waiting on the same request (st)
+ * Task T3 does not renew its interest in status request st, so it is only invoked once (first iteration)
+ * Task T2 is invoked every time st completes, because it renews its interest in status of status request object st every iteration of T1
+ */
+
+#define _TASK_SLEEP_ON_IDLE_RUN
+#define _TASK_STATUS_REQUEST
+#include <TaskScheduler.h>
+
+StatusRequest st;
+
+Scheduler ts;
+
+// Callback methods prototypes
+void Callback1();
+void Disable1();
+void Callback2();
+void Callback3();
+void PrepareStatus();
+
+// Tasks
+Task t1(5000, TASK_ONCE, &Callback1, &ts, true, NULL, &Disable1);
+Task t2(&Callback2, &ts);
+Task t3(&Callback3, &ts);
+
+/** T1 callback
+ * T1 just signals completion of st every 5 seconds
+ */
+void Callback1() {
+ Serial.println("T1: Signaling completion of ST");
+ st.signalComplete();
+}
+
+/** T1 On Disable callback
+ * This callback renews the status request and restarts T1 delayed to run again in 5 seconds
+ */
+void Disable1() {
+ PrepareStatus();
+ t1.restartDelayed();
+}
+
+/** T2 callback
+ * Invoked when status request st completes
+ */
+void Callback2() {
+ Serial.println("T2: Invoked due to completion of ST");
+}
+
+
+/** T3 callback
+ * Invoked when status request st completes.
+ * This is only run once since T3 does not renew its interest in the status request st after first iteration
+ */
+ void Callback3() {
+ Serial.println("T3: Invoked due to completion of ST");
+
+}
+
+/** Prepare Status request st for another iteration
+ *
+ */
+void PrepareStatus() {
+ st.setWaiting(); // set the statusrequest object for waiting
+ t2.waitFor(&st); // request tasks 1 & 2 to wait on the object st
+}
+
+
+/** Main Arduino code
+ * Not much to do here. Just init Serial and set the initial status request
+ */
+void setup() {
+
+ Serial.begin(115200);
+ Serial.println("TaskScheduler: Status Request Test 1. Simple Test.");
+
+ PrepareStatus();
+ t3.waitFor(&st);
+
+ t1.delay();
+}
+
+void loop() {
+
+ ts.execute();
+
+} \ No newline at end of file