Git Product home page Git Product logo

end2endzone / softtimers Goto Github PK

View Code? Open in Web Editor NEW
14.0 3.0 0.0 573 KB

A collection of software timers that allows one to properly time multiple events and know when each "timer" expires meaning that an action is required. The library aims at greatly simplifying multitask complexity.

License: MIT License

Batchfile 30.55% PowerShell 1.32% C++ 34.19% CMake 4.78% Shell 21.36% Python 7.80%
arduino non-blocking timing timers

softtimers's People

Contributors

end2endzone avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

softtimers's Issues

Add new example: limit the quantity of printed messages

Create a new example to show that the class can be used to limit the number of printed messages per time.

The example should be a sketch that prints the state of a button. The state should be printed at every loop. However, the code should also verify if the time has timed out to know if the message can actually be printed. Timer should be reset each time a new message is printed.

Build on GitHub Actions

The library CI build service should be migrated to GitHub Actions now that Travis CI is not free anymore.

error: invalid conversion from 'long unsigned int (*)()' to 'SoftTimer::CounterFunctionPointer {aka unsigned int (*)()}' [-fpermissive]

I got this error running a slightly modified version of one of your examples running it on an 8266. Hard to see how my small mods could have caused this. Here's more of the compiler ouput <D:\David\MyDocuments\Arduino\libraries\SoftTimers\src/SoftTimers.h: In constructor 'SoftTimerMillis::SoftTimerMillis()':

D:\David\MyDocuments\Arduino\libraries\SoftTimers\src/SoftTimers.h:122:40: error: invalid conversion from 'long unsigned int ()()' to 'SoftTimer::CounterFunctionPointer {aka unsigned int ()()}' [-fpermissive]

SoftTimerMillis() : SoftTimer(&millis)

                                    ^

D:\David\MyDocuments\Arduino\libraries\SoftTimers\src/SoftTimers.h:36:3: error: initializing argument 1 of 'SoftTimer::SoftTimer(SoftTimer::CounterFunctionPointer)' [-fpermissive]

SoftTimer(CounterFunctionPointer iCntFuncPtr);

^
D:\David\MyDocuments\Arduino\libraries\SoftTimers\src/SoftTimers.h: In constructor 'SoftTimerMicros::SoftTimerMicros()':

D:\David\MyDocuments\Arduino\libraries\SoftTimers\src/SoftTimers.h:131:40: error: invalid conversion from 'long unsigned int ()()' to 'SoftTimer::CounterFunctionPointer {aka unsigned int ()()}' [-fpermissive]

SoftTimerMicros() : SoftTimer(&micros)

D:\David\MyDocuments\Arduino\libraries\SoftTimers\src/SoftTimers.h:36:3: error: initializing argument 1 of 'SoftTimer::SoftTimer(SoftTimer::CounterFunctionPointer)' [-fpermissive]

SoftTimer(CounterFunctionPointer iCntFuncPtr);>

Here's the code
<#include <SoftTimers.h>
#include "Arduino_DebugUtils.h"

// My libraries
#include "boardconfig.h"

/**************************************************

  • Wait 1 second, turn on a LED for 0.3 second.
    **************************************************/
    SoftTimer delayTimer; //millisecond timer
    SoftTimer ledTimer; //millisecond timer

void setup() {
pinMode(ledPin, OUTPUT);

Serial.begin(115200);

//update timers
delayTimer.setTimeOutTime(1000); // 1 second.
ledTimer.setTimeOutTime(2000); // 2 second.

//start counting now
delayTimer.reset();
ledTimer.reset();
}

void loop() {
if (!delayTimer.hasTimedOut())
{
Serial.println("waiting...");

//reset LED timer so that is does not time out before delayTimer
ledTimer.reset();

}

//did we waited long enough ?
else if (delayTimer.hasTimedOut() && !ledTimer.hasTimedOut())
{
Serial.println("turning LED ON...");

//turn ON the LED
digitalWrite(ledPin, HIGH);

}

//should the LED be turned OFF ?
else if (delayTimer.hasTimedOut() && ledTimer.hasTimedOut())
{
Serial.println("turning LED OFF...");

//turn OFF the LED
digitalWrite(ledPin, LOW);

//restart both timers
delayTimer.reset();
ledTimer.reset();

}
}>
and
</*

  • Board config library
    */
    #ifndef BOARDCONFIG_H
    #define BD_VER 1 // set to board version being targetted
    #ifndef D5
    #if defined(ESP8266)
    #define D0 (16)
    #define D1 (5)
    #define D2 (4)
    #define D3 (0)
    #define D4 (2)
    #define D5 (14)
    #define D6 (12)
    #define D7 (13)
    #define D8 (15)
    #define TX (1)
    #define RX (3)
    #elif defined(ESP32)
    #define D5 (18)
    #define D6 (19)
    #define D7 (23)
    #define D8 (5)
    #define TX (1)
    #endif
    #endif

if BD_VER == 1

const int sclPin = D1;
const int sdaPin = D2;
const int fanPin = D3;
const int ledPin = D4;
const int piezoPin = D5;
const int thPin = D6;
const int h2oPin = D7;
const int adcPin = A0;

elif BD_VER == 2

const int sclPin = D1;
const int sdaPin = D2;
const int fanPin = D3;
const int ledPin = D4;
const int swrxPin = D5;
const int swtxPin = D6;
const int openPin = D7;
const int dirPin = D8;
const int adcPin = A0;

else

const int ledPin = D0;
const int sclPin = D1;
const int sdaPin = D2;
const int fanPin = D3;
const int fanspdPin = D4;
const int swrxPin = D5;
const int swtxPin = D6;
const int openPin = D7;
const int dirPin = D8;
const int adcPin = A0; //Connected to fault output of switch to fan
#endif //BD_VER logic
#endif BOARDCONFIG_H>

Running unit tests on 64 bit Linux

When running unit test on a 64 bit Linux platform, the following unit tests is failing and shows the following output:

[ RUN      ] TestSoftTimers.testMicrosOverflow
/home/runner/work/SoftTimers/SoftTimers/test/TestSoftTimers.cpp:100: Failure
Value of: t.hasTimedOut()
  Actual: true
Expected: false
Unexpected timeout! getElapsedTime() returns 18446744069414584627. micros() returns 53
[  FAILED  ] TestSoftTimers.testMicrosOverflow (0 ms)

This is because unsigned long is 64 bit on Linux 64 bit. The win32Arduino unit test library used to define the return type of millis and micros functions as uint32_t which was forcing 32 bits even on 64 bit systems. Following the correction for #5, both functions return type is now unsigned long (which is matching the official Arduino.h definition) but this creates issues with unit tests.

Unit tests must be corrected to run without errors in both 32 bit and 64 platforms.

Related to issue #5.

compile error - basic example

getting a compile error:

Invalid conversion from 'void ()(uint8_t, unsigned int, long unsigned int)' {aka 'void ()(unsigned char, unsigned int, long unsigned int)'} to 'anyrtttl::ToneFuncPtr' {aka 'void (*)(unsigned char, short unsigned int, unsigned int)'} [-fpermissive]
ToneFuncPtr _tone = &tone;

when trying to compile the basic example, pulled latest from arduino ide, v 2.2.0

Refactor build process to use Arduino CLI instead of Arduino IDE

Latest version of Arduino IDE does not include the command line build tool. This change is breaking continuous integration scripts on AppVeyor and Github Actions.

The solution is to use Arduino CLI instead and continue building this library from the command line.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.