Skip to content

Commit 3d21acf

Browse files
Format code with Google coding-style
1 parent 2d17bff commit 3d21acf

File tree

4 files changed

+26
-27
lines changed

4 files changed

+26
-27
lines changed

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
### Advantages of the VirtualDelay library:
2-
- The delay is virtual, during the delay, the code execution is continued
3-
- We can use multiple delays sequentially in a loop.
4-
- We can use multiple delays simultaneously and independent of each other.
5-
- The delay time can set in micro-seconds or milli-seconds.
6-
- No hardware timers are used
7-
- The library is timer-rollover safe
8-
9-
See the article http://www.avdweb.nl/arduino/libraries/virtualdelay.html
1+
### Advantages of the VirtualDelay library:
2+
- The delay is virtual, during the delay, the code execution is continued
3+
- We can use multiple delays sequentially in a loop.
4+
- We can use multiple delays simultaneously and independent of each other.
5+
- The delay time can set in micro-seconds or milli-seconds.
6+
- No hardware timers are used
7+
- The library is timer-rollover safe
8+
9+
See the article http://www.avdweb.nl/arduino/libraries/virtualdelay.html

avdweb_VirtualDelay.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ set timeOut _____|_____________________
3232
VirtualDelay::VirtualDelay(unsigned long (*timerFunctionPtr)())
3333
: timerFunctionPtr(timerFunctionPtr) {}
3434

35-
void VirtualDelay::start(signed long delay) // 0...2^31
35+
void VirtualDelay::start(signed long delay) // 0...2^31
3636
{
3737
if (!running) {
3838
running = 1;
@@ -41,15 +41,16 @@ void VirtualDelay::start(signed long delay) // 0...2^31
4141
}
4242

4343
bool VirtualDelay::elapsed() {
44-
if (running) { // if((signed long)(*timerFunctionPtr)() >= timeOut) // bug,
45-
// not equal to:
46-
if ((signed long)((*timerFunctionPtr)() - timeOut) >=
47-
0) // fix rollover bug:
48-
// https://arduino.stackexchange.com/questions/12587/how-can-i-handle-the-millis-rollover/12588#12588
49-
{
44+
if (running) {
45+
// bug
46+
// if((signed long)(*timerFunctionPtr)() >= timeOut)
47+
// not the same as
48+
if ((signed long)((*timerFunctionPtr)() - timeOut) >= 0) {
49+
// fix rollover bug:
50+
// https://arduino.stackexchange.com/questions/12587/how-can-i-handle-the-millis-rollover/12588#12588
5051
running = 0;
51-
return 1; //pulse = 1
52+
return 1; // timer is elapsed
5253
}
5354
}
54-
return 0; //pulse = 0
55+
return 0; // still in delay timer
5556
}

keywords.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ avdweb_VirtualDelay KEYWORD1
1414

1515
start KEYWORD2
1616
elapsed KEYWORD2
17+
DO_ONCE KEYWORD2
1718

1819
#######################################
1920
# Instances (KEYWORD2)

testOneShot/testOneShot.ino

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,12 @@
44

55
VirtualDelay delay1;
66

7-
void setup()
8-
{ Serial.begin(9600);
9-
Serial << "\ntestOneShot 2s\n";
7+
void setup() {
8+
Serial.begin(9600);
9+
Serial << "\ntestOneShot 2s\n";
1010
}
1111

12-
void loop()
13-
{ DO_ONCE(delay1.start(2000)) // do only one time in the loop
14-
if(delay1.elapsed()) Serial << millis() << "ms" ;
12+
void loop() {
13+
DO_ONCE(delay1.start(2000)) // do only one time in the loop
14+
if (delay1.elapsed()) Serial << millis() << "ms";
1515
}
16-
17-
18-

0 commit comments

Comments
 (0)