瀏覽代碼

Merge branch 'master' into v4.0.0_rc1

Anatoli Arkhipenko 3 月之前
父節點
當前提交
4ee4e2dee8

+ 287 - 0
.github/workflows/main.yml

@@ -0,0 +1,287 @@
+# This is the name of the workflow, visible on GitHub UI.
+name: TaskScheduler Examples Build
+
+# Controls when the action will run. 
+on:
+  # Triggers the workflow on push or pull request only for the main branch
+  push:
+    branches: [ main ]
+  pull_request:
+    branches: [ main ]
+  workflow_dispatch:
+
+# This is the list of jobs that will be run concurrently.
+# Since we use a build matrix, the actual number of jobs
+# started depends on how many configurations the matrix
+# will produce.
+jobs:
+  # This is the name of the job - can be whatever.
+  ArduinoIDE_AVR:
+    # Here we tell GitHub that the jobs must be determined
+    # dynamically depending on a matrix configuration.
+    strategy:
+      matrix:
+        # The matrix will produce one job for each configuration
+        # parameter of type `arduino-platform`, in this case, it
+        # is only 1.
+        arduino-platform: ["arduino:avr"]
+        # This is usually optional but we need to statically define the
+        # FQBN of the boards we want to test for each platform. In the
+        # future the CLI might automatically detect and download the 
+        # core needed to compile against a certain FQBN, at that point 
+        # the following `include` section will be useless.
+        include:
+          # This works like this: when the platformn is "arduino:avr",
+          # the variable `fqbn` is set to "arduino:avr:uno".
+          - arduino-platform: "arduino:avr"
+            fqbn: "arduino:avr:uno"
+#          - arduino-platform: "esp32:esp32"
+#            fqbn: "esp32:esp32:esp32"
+    # This is the platform GitHub will use to run our workflow,
+    # I picked ubuntu.
+    runs-on: ubuntu-latest
+
+    # This is the list of steps this job will run.
+    steps:
+      # First of all, we clone the repo using the `checkout` action.
+      - name: Checkout
+        uses: actions/checkout@main
+
+      # We use the `arduino/setup-arduino-cli` action to install and
+      # configure the Arduino CLI on the system.
+      - name: Setup Arduino CLI
+        uses: arduino/setup-arduino-cli@v1.1.1
+      
+      
+      # We then install the platform, which one will be determined
+      # dynamically by the build matrix.
+      - name: Install platform
+        run: |
+          arduino-cli core update-index
+          arduino-cli core install ${{ matrix.arduino-platform }}
+      - name: Install repo as library
+        run: |
+          mkdir -p "$HOME/Arduino/libraries"
+          ln -s "$PWD" "$HOME/Arduino/libraries/."
+      - name: Install required libraries
+        run: |
+          mkdir -p "$HOME/Arduino/libraries"
+          # Install QueueArray from Arduino Playground
+          wget -O queuearray.zip https://playground.arduino.cc/uploads/Code/QueueArray/index.zip
+          unzip queuearray.zip -d "$HOME/Arduino/libraries/"
+          # Install MemoryFree library from Arduino Library Manager
+          git clone https://github.com/McNeight/MemoryFree.git
+          cp -r MemoryFree "$HOME/Arduino/libraries/"
+    
+      # Finally, we compile the sketch, using the FQBN that was set
+      # in the build matrix.
+      - name: Scheduler_example00_Blink
+        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example00_Blink --warnings more
+      - name: Scheduler_example00_Blink_Namespace
+        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example00_Blink_Namespace --warnings more
+      - name: Scheduler_example01
+        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example01 --warnings more
+      - name: Scheduler_example02
+        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example02 --warnings more
+      - name: Scheduler_example03
+        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example03 --warnings more
+      - name: Scheduler_example04_StatusRequest
+        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example04_StatusRequest --warnings more
+      - name: Scheduler_example05_StatusRequest
+        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example05_StatusRequest --warnings more
+      - name: Scheduler_example06_IDLE
+        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example06_IDLE --warnings more
+      - name: Scheduler_example07_WDT
+        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example07_WDT --warnings more
+      - name: Scheduler_example08_LTS
+        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example08_LTS --warnings more
+      - name: Scheduler_example09_TimeCritical
+        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example09_TimeCritical --warnings more
+      - name: Scheduler_example10_Benchmark
+        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example10_Benchmark --warnings more
+      - name: Scheduler_example11_Priority
+        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example11_Priority --warnings more
+      - name: Scheduler_example12_Priority
+        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example12_Priority --warnings more
+      - name: Scheduler_example13_Micros
+        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example13_Micros --warnings more
+#      - name: Scheduler_example14_Yield
+#        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example14_Yield --warnings more
+#      - name: Scheduler_example15_STDFunction
+#        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example15_STDFunction --warnings more
+      - name: Scheduler_example16_Multitab
+        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example16_Multitab --warnings more
+      - name: Scheduler_example17_Timeout
+        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example17_Timeout --warnings more
+      - name: Scheduler_example18_StatusRequest_LTS_WDT_Timeout
+        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example18_StatusRequest_LTS_WDT_Timeout --warnings more
+      - name: Scheduler_example18_StatusRequest_LTS_WDT_Timeout
+        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example18_StatusRequest_LTS_WDT_Timeout --warnings more
+      - name: Scheduler_example19_Dynamic_Tasks
+        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example19_Dynamic_Tasks --warnings more
+      - name: Scheduler_example19_Dynamic_Tasks_SelfDestruct
+        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example19_Dynamic_Tasks_SelfDestruct --warnings more
+#      - name: Scheduler_example19_Dynamic_Tasks_stdQueue
+#        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example19_Dynamic_Tasks_stdQueue --warnings more
+      - name: Scheduler_example20_StatusRequest_LTS_WDT_Timeout_Object
+        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example20_StatusRequest_LTS_WDT_Timeout_Object --warnings more
+      - name: Scheduler_example21_OO_Callbacks
+        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example21_OO_Callbacks --warnings more
+      - name: Scheduler_example23_IDLE_Callback
+        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example23_IDLE_Callback --warnings more
+      - name: Scheduler_example24_CPU_LOAD
+        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example24_CPU_LOAD --warnings more
+      - name: Scheduler_example25_SCHEDULER_CHAIN
+        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example25_SCHEDULER_CHAIN --warnings more
+      - name: Scheduler_example26_SCHEDULING_OPTIONS
+        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example26_SCHEDULING_OPTIONS --warnings more
+#      - name: Scheduler_example27_PlatformIO
+#        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example27_PlatformIO --warnings more
+      - name: Scheduler_example28_Tickless
+        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example28_Tickless --warnings more
+
+  ArduinoIDE_ESP32:
+    strategy:
+      matrix:
+        include:
+          - arduino-platform: "esp32:esp32"
+            fqbn: "esp32:esp32:esp32"
+    runs-on: ubuntu-latest
+    steps:
+      - name: Checkout
+        uses: actions/checkout@main
+      - name: Setup Arduino CLI
+        uses: arduino/setup-arduino-cli@v1.1.1
+      - name: Install platform
+        run: |
+          arduino-cli core update-index
+          arduino-cli core install ${{ matrix.arduino-platform }}
+      - name: Install repo as library
+        run: |
+          mkdir -p "$HOME/Arduino/libraries"
+          ln -s "$PWD" "$HOME/Arduino/libraries/."
+      - name: Install required libraries
+        run: |
+          mkdir -p "$HOME/Arduino/libraries"
+          # Install QueueArray from Arduino Playground
+          wget -O queuearray.zip https://playground.arduino.cc/uploads/Code/QueueArray/index.zip
+          unzip queuearray.zip -d "$HOME/Arduino/libraries/"
+          # Install MemoryFree library from Arduino Library Manager
+          git clone https://github.com/McNeight/MemoryFree.git
+          cp -r MemoryFree "$HOME/Arduino/libraries/"
+          
+      - name: Scheduler_example00_Blink
+        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example00_Blink --warnings more
+      - name: Scheduler_example00_Blink_Namespace
+        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example00_Blink_Namespace --warnings more
+      - name: Scheduler_example01
+        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example01 --warnings more
+      - name: Scheduler_example02
+        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example02 --warnings more
+      - name: Scheduler_example03
+        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example03 --warnings more
+      - name: Scheduler_example04_StatusRequest
+        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example04_StatusRequest --warnings more
+      - name: Scheduler_example05_StatusRequest
+        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example05_StatusRequest --warnings more
+      - name: Scheduler_example06_IDLE
+        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example06_IDLE --warnings more
+#      - name: Scheduler_example07_WDT
+#        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example07_WDT --warnings more
+      - name: Scheduler_example08_LTS
+        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example08_LTS --warnings more
+      - name: Scheduler_example09_TimeCritical
+        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example09_TimeCritical --warnings more
+      - name: Scheduler_example10_Benchmark
+        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example10_Benchmark --warnings more
+      - name: Scheduler_example11_Priority
+        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example11_Priority --warnings more
+      - name: Scheduler_example12_Priority
+        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example12_Priority --warnings more
+      - name: Scheduler_example13_Micros
+        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example13_Micros --warnings more
+#      - name: Scheduler_example14_Yield
+#        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example14_Yield --warnings more
+      - name: Scheduler_example15_STDFunction
+        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example15_STDFunction --warnings more
+      - name: Scheduler_example16_Multitab
+        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example16_Multitab --warnings more
+      - name: Scheduler_example17_Timeout
+        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example17_Timeout --warnings more
+      - name: Scheduler_example18_StatusRequest_LTS_WDT_Timeout
+        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example18_StatusRequest_LTS_WDT_Timeout --warnings more
+      - name: Scheduler_example18_StatusRequest_LTS_WDT_Timeout
+        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example18_StatusRequest_LTS_WDT_Timeout --warnings more
+      - name: Scheduler_example19_Dynamic_Tasks
+        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example19_Dynamic_Tasks --warnings more
+      - name: Scheduler_example19_Dynamic_Tasks_SelfDestruct
+        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example19_Dynamic_Tasks_SelfDestruct --warnings more
+      - name: Scheduler_example19_Dynamic_Tasks_stdQueue
+        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example19_Dynamic_Tasks_stdQueue --warnings more
+      - name: Scheduler_example20_StatusRequest_LTS_WDT_Timeout_Object
+        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example20_StatusRequest_LTS_WDT_Timeout_Object --warnings more
+      - name: Scheduler_example21_OO_Callbacks
+        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example21_OO_Callbacks --warnings more
+      - name: Scheduler_example23_IDLE_Callback
+        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example23_IDLE_Callback --warnings more
+      - name: Scheduler_example24_CPU_LOAD
+        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example24_CPU_LOAD --warnings more
+      - name: Scheduler_example25_SCHEDULER_CHAIN
+        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example25_SCHEDULER_CHAIN --warnings more
+      - name: Scheduler_example26_SCHEDULING_OPTIONS
+        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example26_SCHEDULING_OPTIONS --warnings more
+#      - name: Scheduler_example27_PlatformIO
+#        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example27_PlatformIO --warnings more
+      - name: Scheduler_example28_Tickless
+        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example28_Tickless --warnings more
+
+  ArduinoIDE_ESP8266_ONLY:
+    strategy:
+      matrix:
+        include:
+          - arduino-platform: "esp8266:esp8266"
+            fqbn: "esp8266:esp8266:nodemcuv2"
+    runs-on: ubuntu-latest
+    steps:
+      - name: Checkout
+        uses: actions/checkout@main
+      - name: Setup Arduino CLI
+        uses: arduino/setup-arduino-cli@v1.1.1
+      - name: Install platform
+        run: |
+          arduino-cli core update-index --additional-urls https://arduino.esp8266.com/stable/package_esp8266com_index.json
+          arduino-cli core install ${{ matrix.arduino-platform }} --additional-urls https://arduino.esp8266.com/stable/package_esp8266com_index.json
+      - name: Install repo as library
+        run: |
+          mkdir -p "$HOME/Arduino/libraries"
+          ln -s "$PWD" "$HOME/Arduino/libraries/."
+      - name: Scheduler_example14_Yield
+        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./examples/Scheduler_example14_Yield --warnings more
+
+  PIO:
+    runs-on: ubuntu-latest
+    steps:
+      - name: Checkout
+        uses: actions/checkout@main
+      - name: Set up Python
+        uses: actions/setup-python@v4
+        with:
+          python-version: '3.x'
+      - name: Install PlatformIO
+        run: |
+          python -m pip install --upgrade pip
+          pip install platformio
+      - name: Install required libraries for PlatformIO
+        run: |
+          mkdir -p lib
+          # Install QueueArray from Arduino Playground
+          wget -O queuearray.zip https://playground.arduino.cc/uploads/Code/QueueArray/index.zip
+          unzip queuearray.zip -d lib/
+          # Install MemoryFree from GitHub
+          git clone https://github.com/McNeight/MemoryFree.git
+          cp -r MemoryFree lib/
+          
+      - name: Scheduler_example27_PlatformIO
+        run: |
+          cd examples/Scheduler_example27_PlatformIO
+          pio run -e esp32dev

+ 1 - 1
examples/Scheduler_example14_Yield/Scheduler_example14_Yield.ino

@@ -228,7 +228,7 @@ void ntpCheck() {
 /**
  * Send NTP packet to NTP server
  */
-unsigned long sendNTPpacket(IPAddress & address)
+void sendNTPpacket(IPAddress & address)
 {
   Serial.print(millis());
   Serial.println(F(": sendNTPpacket."));

+ 1 - 1
examples/Scheduler_example19_Dynamic_Tasks/Scheduler_example19_Dynamic_Tasks.ino

@@ -17,7 +17,7 @@
 #include <TaskScheduler.h>
 #include <QueueArray.h>
 
-int freeMemory();
+// int freeMemory();
 
 #if defined (ARDUINO_ARCH_AVR)
 #include <MemoryFree.h>

+ 1 - 1
examples/Scheduler_example19_Dynamic_Tasks_SelfDestruct/Scheduler_example19_Dynamic_Tasks_SelfDestruct.ino

@@ -17,7 +17,7 @@
 #define _TASK_SELF_DESTRUCT     // Enable tasks to "self-destruct" after disable
 #include <TaskScheduler.h>
 
-int freeMemory();
+// int freeMemory();
 
 #if defined (ARDUINO_ARCH_AVR)
 #include <MemoryFree.h>

+ 1 - 1
examples/Scheduler_example19_Dynamic_Tasks_stdQueue/Scheduler_example19_Dynamic_Tasks_stdQueue.ino

@@ -19,7 +19,7 @@
 
 #include <queue>
 
-int freeMemory();
+// int freeMemory();
 
 #if defined (ARDUINO_ARCH_AVR)
 #include <MemoryFree.h>

+ 1 - 0
examples/Scheduler_example21_OO_Callbacks/Ticker.cpp

@@ -16,5 +16,6 @@ bool Ticker::Callback() {
 
   iMeasure->setWaiting(numberSensors); // Set the StatusRequest to wait for 1 to 10 signals.
   iCalc->waitFor(iMeasure);
+  return true;
 }
 

+ 14 - 0
src/TaskScheduler.h

@@ -640,6 +640,10 @@ void Task::set(unsigned long aInterval, long aIterations, TaskCallback aCallback
     setInterval(aInterval);
     iSetIterations = aIterations;
     iIterations = aIterations;
+#ifdef _TASK_THREAD_SAFE
+    iMutex = iMutex - 1;
+#endif  // _TASK_THREAD_SAFE
+
 }
 
 /** Sets number of iterations for the task
@@ -647,8 +651,16 @@ void Task::set(unsigned long aInterval, long aIterations, TaskCallback aCallback
  * @param aIterations - number of iterations, use -1 for no limit
  */
 void Task::setIterations(long aIterations) {
+#ifdef _TASK_THREAD_SAFE
+    iMutex = iMutex + 1;
+#endif  // _TASK_THREAD_SAFE
+
     iSetIterations = aIterations;
     iIterations = aIterations;
+
+#ifdef _TASK_THREAD_SAFE
+    iMutex = iMutex - 1;
+#endif  // _TASK_THREAD_SAFE
 }
 
 #ifndef _TASK_OO_CALLBACKS
@@ -1515,7 +1527,9 @@ bool Scheduler::execute() {
 #ifdef _TASK_SLEEP_ON_IDLE_RUN
     unsigned long tFinish;
     unsigned long tStart;
+#ifdef _TASK_TIMECRITICAL
     unsigned long tIdleStart = 0;
+#endif  // _TASK_TIMECRITICAL
 #endif  // _TASK_SLEEP_ON_IDLE_RUN