update Code
This commit is contained in:
parent
3c47103b39
commit
a641fad56c
119 changed files with 10997 additions and 5 deletions
|
@ -0,0 +1,18 @@
|
|||
//This file is intentionally left blank.
|
||||
//
|
||||
//Arduino IDE plays some dirty tricks on the main sketch .ino file:
|
||||
//it rearranges #includes, blindly creates forward definitions,
|
||||
//includes every file in the project that does not have .c or .cpp
|
||||
//file extension.
|
||||
//
|
||||
//Usually it all turns well if you have only one source file and you are either
|
||||
//inexperienced or really expert C++ Arduino programmer.
|
||||
//For the folks with the middle ground skills level, when you want
|
||||
//to split your code into several .cpp files, it is best to leave
|
||||
//this main sketch empty.
|
||||
//
|
||||
//It doesn't matter where you define the void loop() and void setup().
|
||||
//Just make sure there is exactly one definition of each.
|
||||
//
|
||||
//And if you want to use standard Arduino functions
|
||||
//like digitalWrite or the Serial object - just add #include<Arduino.h>.
|
|
@ -0,0 +1,31 @@
|
|||
#include <Arduino.h>
|
||||
#include "header.hpp"
|
||||
|
||||
|
||||
//Declare the functions we want to use before we are ready to define them
|
||||
void t1Callback();
|
||||
|
||||
|
||||
// Tasks
|
||||
Task t1(2000, 10, &t1Callback, &runner, true); //adding task to the chain on creation
|
||||
Task t3(5000, TASK_FOREVER, &t3Callback);
|
||||
|
||||
|
||||
void t1Callback() {
|
||||
Serial.print("t1: ");
|
||||
Serial.println(millis());
|
||||
|
||||
if (t1.isFirstIteration()) {
|
||||
runner.addTask(t3);
|
||||
t3.enable();
|
||||
Serial.println("t1: enabled t3 and added to the chain");
|
||||
}
|
||||
|
||||
if (t1.isLastIteration()) {
|
||||
t3.disable();
|
||||
runner.deleteTask(t3);
|
||||
t2.setInterval(500);
|
||||
Serial.println("t1: disable t3 and delete it from the chain. t2 interval set to 500");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
// Test the same as example#2:
|
||||
// Initially only tasks 1 and 2 are enabled
|
||||
// Task1 runs every 2 seconds 10 times and then stops
|
||||
// Task2 runs every 3 seconds indefinitely
|
||||
// Task1 enables Task3 at its first run
|
||||
// Task3 run every 5 seconds
|
||||
// loop() runs every 1 second (a default scheduler delay, if no shorter tasks' interval is detected)
|
||||
// Task1 disables Task3 on its last iteration and changed Task2 to run every 1/2 seconds
|
||||
// Because Task2 interval is shorter than Scheduler default tick, loop() executes ecery 1/2 seconds now
|
||||
// At the end Task2 is the only task running every 1/2 seconds
|
||||
|
||||
|
||||
//Header that declares all shared objects between .cpp files
|
||||
#include "header.hpp"
|
||||
|
||||
#include <Arduino.h> //for Serial and delay
|
||||
|
||||
Scheduler runner; //Let the scheduler live here, in the main file, ok?
|
||||
|
||||
|
||||
//Pretend, that the t2 task is a special task,
|
||||
//that needs to live in file2 object file.
|
||||
void t2Callback() {
|
||||
Serial.print("t2: ");
|
||||
Serial.println(millis());
|
||||
}
|
||||
Task t2(3000, TASK_FOREVER, &t2Callback, &runner, true);
|
||||
|
||||
//Lets define t3Callback here. We are going to use it in file1
|
||||
//for Task 1.
|
||||
void t3Callback() {
|
||||
Serial.print("t3: ");
|
||||
Serial.println(millis());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void setup () {
|
||||
Serial.begin(115200);
|
||||
delay(5000);
|
||||
Serial.println("Scheduler TEST (multi-tab)");
|
||||
|
||||
runner.startNow(); // set point-in-time for scheduling start
|
||||
}
|
||||
|
||||
|
||||
void loop () {
|
||||
runner.execute();
|
||||
|
||||
// Serial.println("Loop ticks at: ");
|
||||
// Serial.println(millis());
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
//This is the place to declare every single function
|
||||
//and global variable that is going to be reused between cpp files.
|
||||
|
||||
|
||||
//We are going to use the TaskScheduler, but only the declarations part.
|
||||
//Remember to put customization macros before the #include:
|
||||
#define _TASK_SLEEP_ON_IDLE_RUN
|
||||
#include <TaskSchedulerDeclarations.h>
|
||||
|
||||
//Let the runner object be a global, single instance shared between object files.
|
||||
extern Scheduler runner;
|
||||
extern Task t2; //the t2 is defined in file2, but we need to access it from file1.
|
||||
|
||||
//This function needs to be shared (between file2 and file1).
|
||||
void t3Callback();
|
|
@ -0,0 +1,20 @@
|
|||
//This is the only .cpp file that gets the #include<TaskScheduler.h>.
|
||||
//Without it, the linker would not find necessary TaskScheduler's compiled code.
|
||||
//
|
||||
//Remember to put customization macros here as well.
|
||||
//
|
||||
//And don't import any common headers (here: header.hpp)
|
||||
//
|
||||
//Really. This file needs to be short. All stuff is in TaskScheduler.h.
|
||||
|
||||
// #define _TASK_TIMECRITICAL // Enable monitoring scheduling overruns
|
||||
#define _TASK_SLEEP_ON_IDLE_RUN // Enable 1 ms SLEEP_IDLE powerdowns between tasks if no callback methods were invoked during the pass
|
||||
// #define _TASK_STATUS_REQUEST // Compile with support for StatusRequest functionality - triggering tasks on status change events in addition to time only
|
||||
// #define _TASK_WDT_IDS // Compile with support for wdt control points and task ids
|
||||
// #define _TASK_LTS_POINTER // Compile with support for local task storage pointer
|
||||
// #define _TASK_PRIORITY // Support for layered scheduling priority
|
||||
// #define _TASK_MICRO_RES // Support for microsecond resolution
|
||||
// #define _TASK_STD_FUNCTION // Support for std::function (ESP8266 ONLY)
|
||||
// #define _TASK_DEBUG // Make all methods and variables public for debug purposes
|
||||
|
||||
#include <TaskScheduler.h>
|
Loading…
Add table
Add a link
Reference in a new issue