Skip to content

Commit

Permalink
Version 1.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
vishnumaiea committed Jun 13, 2021
1 parent 0e61517 commit 471cbd9
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 31 deletions.
34 changes: 31 additions & 3 deletions Changes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@


#

**+05:30 11:59:55 AM 13-06-2021, Sunday**

Ready for a next release with important bug fixes. **Version 1.1.2** 🎉

#

**+05:30 03:42:00 PM 11-06-2021, Friday**

When does a task start? - A task starts when the first `call()` is made 📋

When a task is resumed, should it respect the skip parameters? Currently, this is not respected. But what if I want to have that feature? One method is to disable the task and later enable it, instead of suspending and resuming. But this also causes every counter to freeze and thus you won't be able to read the sleep interval counters. You will have to manually and arbitrarily enable the task. But this assures that the skip parameters are respected.

Another method is to keep the task sleep mode to `PT_SLEEP_SUSPEND` and call `resume()` to the resume the task. But just before calling `resume()`, set `taskStarted` state variable to `false`. This is because it is the `taskStarted` flag that determines if an interval has to be skipped. This flag is set to `true` when you invoke `call()` for the first time (after a duration that is greater than the set skip interval).

So when we do the following for example, the skip intervals are respected.

```cpp
eioTask.taskStarted = false;
eioTask.resume();
```
#

**+05:30 09:46:25 PM 10-06-2021, Thursday**

Found a bug 🐞 in the `oneshot()` and `spanning()` routines (lines 261 and 364). When checking for skip parameters, the conditional statement had two instances of `skipIntervalSet`. One should have been `skipIterationSet`. Due to this, `setSkipIteration()` was not working for iterated tasks. FIXED ✅ [Issue #2](https://github.com/vishnumaiea/ptScheduler/issues/2#issue-919728782)

#

**+05:30 04:16:52 PM 10-06-2021, Thursday**
Expand All @@ -22,17 +50,17 @@

**+05:30 12:39:54 AM 08-12-2020, Tuesday**

I have to implement a new "counter only" mode. It will simply increment a counter (`intervalCounter`) without any other overheads.
I have to implement a new "counter only" mode. It will simply increment a counter (`intervalCounter`) without any other overheads 💡

#

**+05:30 09:20:43 PM 06-12-2020, Sunday**

Changed `time_ms_t` type to `uint64_t` from `int64_t`. This is because the `millis()` function returns unsigned value always, and we do not use negative interval values. So why waste that extra half? Also, I just came to notice that my code is already overflow safe. For example looks the code below,
Changed `time_ms_t` type to `uint64_t` from `int64_t`. This is because the `millis()` function returns unsigned value always, and we do not use negative interval values. So why waste that extra half? Also, I just came to notice that the code is already overflow safe. For example look at the code below,

elapsedTime = millis() - entryTime;

Assume `millis()` was overflown and the current value is now 100. Entry time was saved before the overflow event. So it should have a large value. Let it be 4294967280 which is 15 less than the max value of a 32-bit unsigned value which is 4294967295. So the result would be 184 which is actually the correct time elapsed. Why 184 but not 185 is because one increment was taken for incrementing to 0.
Assume `millis()` was overflown and the current value is now 100. Entry time was saved before the overflow event. So it should have a large value. Let it be 4294967280 which is 15 less than the max value of a 32-bit unsigned value which is 4294967295. So the result would be 184, which is actually the correct time elapsed. Why 184 but not 185 is because one increment was taken for incrementing to 0.

#

Expand Down
4 changes: 2 additions & 2 deletions examples/Basic/Basic.ino
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
// periodic tasks without using delay() or millis() routines.

// Author : Vishnu Mohanan (@vishnumaiea)
// Version : 1.1.1
// Version : 1.1.2
// License : MIT
// Source : https://github.com/vishnumaiea/ptScheduler

// Last modified : +05:30 15:37:52 PM 10-06-2021, Thursday
// Last modified : +05:30 11:58:55 AM 13-06-2021, Sunday

//=======================================================================//
//description
Expand Down
6 changes: 3 additions & 3 deletions examples/Hello-World/Hello-World.ino
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
// periodic tasks without using delay() or millis() routines.

// Author : Vishnu Mohanan (@vishnumaiea)
// Version : 1.1.1
// Version : 1.1.2
// License : MIT
// Source : https://github.com/vishnumaiea/ptScheduler

// Last modified : +05:30 15:38:02 PM 10-06-2021, Thursday
// Last modified : +05:30 11:58:59 AM 13-06-2021, Sunday

//=======================================================================//
//description
Expand All @@ -27,7 +27,7 @@
//globals

//create tasks
ptScheduler sayHello = ptScheduler(1000); //Equal, Periodic, Oneshot
ptScheduler sayHello(1000); //Equal, Periodic, Oneshot

//=======================================================================//
//setup function runs once
Expand Down
42 changes: 30 additions & 12 deletions examples/Test/Test.ino
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
// periodic tasks without using delay() or millis() routines.

// Author : Vishnu Mohanan (@vishnumaiea)
// Version : 1.1.1
// Version : 1.1.2
// License : MIT
// Source : https://github.com/vishnumaiea/ptScheduler

// Last modified : +05:30 15:38:12 PM 10-06-2021, Thursday
// Last modified : +05:30 11:59:03 AM 13-06-2021, Sunday

//=======================================================================//
//description
Expand Down Expand Up @@ -59,6 +59,9 @@ void setup() {

eioTask.setIteration(1);
eioTask.setSleepMode(PT_SLEEP_SUSPEND);
eioTask.setSkipIteration(3);
// eioTask.setSkipTime(1000);
eioTask.suspend();

eisTask.setIteration(5);
eisTask.setSleepMode(PT_SLEEP_SUSPEND);
Expand All @@ -70,8 +73,17 @@ void setup() {
//=======================================================================//

void loop() {
// uisFunction();
if (Serial.available() > 0) {
String inputString = Serial.readString();
if (inputString == "1") {
// eioTask.taskStarted = false;
// eioTask.enable();
// eioTask.resume();
eioTask.reset();
}
}
eioFunction();
// epoFunction();
}

//=======================================================================//
Expand Down Expand Up @@ -148,9 +160,15 @@ void eioFunction() {
}
else if (plot.call()) {
Serial.println("0");
if (eioTask.intervalCounter == 10) {
eioTask.resume();
}
// if (eioTask.intervalCounter == 5) {
// eioTask.resume();
// }
// if (eioTask.intervalCounter == 10) {
// eioTask.resume();
// }
// if (eioTask.intervalCounter == 12) {
// eioTask.resume();
// }
}
}

Expand All @@ -161,16 +179,16 @@ void epoFunction() {
if (epoTask.call()) {
Serial.println("3");

if ((epoTask.intervalCounter >= 5) && (epoTask.intervalCounter <= 10)) {
epoTask.suspend();
}
// if ((epoTask.intervalCounter >= 5) && (epoTask.intervalCounter <= 10)) {
// epoTask.suspend();
// }
}
else if (plot.call()) {
Serial.println("0");

if (epoTask.intervalCounter > 10) {
epoTask.resume();
}
// if (epoTask.intervalCounter > 10) {
// epoTask.resume();
// }
}
}

Expand Down
4 changes: 2 additions & 2 deletions library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ptScheduler",
"keywords": "timer, scheduler, tasks, delay",
"keywords": "timer, timing, scheduler, tasks, delay",
"description": "Arduino library for writing non-blocking periodic tasks without using delay or millis routines.",
"repository":
{
Expand All @@ -13,7 +13,7 @@
"url": "https://github.com/vishnumaiea",
"maintainer": true
},
"version": "1.1.1",
"version": "1.1.2",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*"
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=ptScheduler
version=1.1.1
version=1.1.2
author=Vishnu Mohanan
maintainer=Vishnu Mohanan
sentence=Arduino library for writing non-blocking periodic tasks without using delay or millis routines.
Expand Down
22 changes: 18 additions & 4 deletions src/ptScheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
// periodic tasks without using delay() or millis() routines.

// Author : Vishnu Mohanan (@vishnumaiea)
// Version : 1.1.1
// Version : 1.1.2
// License : MIT
// Source : https://github.com/vishnumaiea/ptScheduler

// Last modified : +05:30 16:13:45 PM 10-06-2021, Thursday
// Last modified : +05:30 11:59:07 AM 13-06-2021, Sunday

//=======================================================================//

Expand Down Expand Up @@ -258,7 +258,7 @@ bool ptScheduler::call() {
bool ptScheduler::spanning() {
if (taskEnabled) {
//if an execution cycle has not started, yet skip for the time set.
if ((!taskStarted) && (skipIntervalSet || skipIntervalSet || skipTimeSet)) {
if ((!taskStarted) && (skipIntervalSet || skipIterationSet || skipTimeSet)) {
if (entryTime == 0) { //this is one way to find if an exe cycle not started
entryTime = millis();
return false;
Expand Down Expand Up @@ -317,7 +317,12 @@ bool ptScheduler::spanning() {
}
//when an iteration has completed
// printStats();

//when a task suspends itself, it also resets the execution counter.
//because of this, when you resume a suspended task the next time,
//the number of iterations are executed once again.
executionCounter = 0; //so that we can start a new iteration

// intervalCounter = 0;
taskRunState = false;
taskRunning = false;
Expand Down Expand Up @@ -361,7 +366,7 @@ bool ptScheduler::oneshot() {
if (taskEnabled) {
//if an execution cycle has not started, yet skip for the time set
if ((!taskStarted)) {
if (skipIntervalSet || skipIntervalSet || skipTimeSet) {
if (skipIntervalSet || skipIterationSet || skipTimeSet) {
if (entryTime == 0) { //this is one way to find if an exe cycle not started
entryTime = millis();
return false;
Expand Down Expand Up @@ -397,7 +402,16 @@ bool ptScheduler::oneshot() {
//interval counter run and you can resume the task when you need.
suspend();
}
//when a task suspends itself, it also resets the execution counter.
//because of this, when you resume a suspended task the next time,
//the number of iterations are executed once again. a side effect of this
//is that, when you suspend a task before an iteration is completed, this
//will cause the task to start a new iteration when you resume it next time.
//you may want the actual iteration to resume. if that's the requirement,
//save the execution counter value before suspending and reload it before
//resuming.
executionCounter = 0;

iterationEnded = true;
sleepIntervalCounter = 0;
return false;
Expand Down
8 changes: 4 additions & 4 deletions src/ptScheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
// periodic tasks without using delay() or millis() routines.

// Author : Vishnu Mohanan (@vishnumaiea)
// Version : 1.1.1
// Version : 1.1.2
// License : MIT
// Source : https://github.com/vishnumaiea/ptScheduler

// Last modified : +05:30 15:38:47 PM 10-06-2021, Thursday
// Last modified : +05:30 11:59:11 AM 13-06-2021, Sunday

//=======================================================================//
//includes
Expand Down Expand Up @@ -86,8 +86,8 @@ class ptScheduler {
void disable(); //block a task from running and reset all state variables and counters
void suspend(); //block a task from running but without resetting anything. interval counter will still run.
void resume(); //resume a suspended task
bool oneshot();
bool spanning();
bool oneshot(); //logic for oneshot tasks
bool spanning(); //logic for spanning tasks
bool call(); //the task invokation call
bool setInterval (time_ms_t value); //dynamically set task interval
bool setInterval (time_ms_t value_1, time_ms_t value_2); //update two interval values. only for tasks instantiated with >= intervals
Expand Down

0 comments on commit 471cbd9

Please sign in to comment.