Skip to content

Commit 9fae7e2

Browse files
committed
Rename header to .hpp to ensure editors recognize it as C++
Reformat all C++ source files
1 parent 732185e commit 9fae7e2

File tree

10 files changed

+430
-427
lines changed

10 files changed

+430
-427
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ only been tested with the SAMD-based boards; the toolchain for the MegaAVR-based
1010

1111
Include the library and create a *TimerSet* instance.
1212
```cpp
13-
#include <arduino-timer-cpp17.h>
13+
#include <arduino-timer-cpp17.hpp>
1414

1515
auto timerset = Timers::create_default();
1616
```
@@ -158,7 +158,7 @@ Timers::TimerHandle reschedule_at(Timers::TimerHandle handle, Timers::Timepoint
158158
159159
### Installation
160160
161-
Copy **src/arduino-timer-cpp17.h** into your project folder.
161+
Copy **src/arduino-timer-cpp17.hpp** into your project folder.
162162
163163
### Examples
164164
@@ -167,7 +167,7 @@ Found in the [**examples**](examples) folder.
167167
The simplest example, blinking an LED every second *(from examples/blink)*:
168168
169169
```cpp
170-
#include <arduino-timer-cpp17.h>
170+
#include <arduino-timer-cpp17.hpp>
171171
172172
auto timerset = Timers::create_default(); // create a timerset with default settings
173173

examples/blink/blink.ino

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,22 @@
55
*
66
*/
77

8-
#include <arduino-timer-cpp17.h>
8+
#include <arduino-timer-cpp17.hpp>
99

1010
auto timerset = Timers::create_default(); // create a TimerSet with default settings
1111

1212
Timers::HandlerResult toggle_led() {
13-
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); // toggle the LED
14-
return Timers::TimerStatus::repeat;
13+
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); // toggle the LED
14+
return Timers::TimerStatus::repeat;
1515
}
1616

1717
void setup() {
18-
pinMode(LED_BUILTIN, OUTPUT); // set LED pin to OUTPUT
18+
pinMode(LED_BUILTIN, OUTPUT); // set LED pin to OUTPUT
1919

20-
// call the toggle_led function every 1000 millis (1 second)
21-
timerset.every(1000, toggle_led);
20+
// call the toggle_led function every 1000 millis (1 second)
21+
timerset.every(1000, toggle_led);
2222
}
2323

2424
void loop() {
25-
timerset.tick_and_delay(); // tick the timer
25+
timerset.tick_and_delay(); // tick the timer
2626
}

examples/blink_micros/blink_micros.ino

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,22 @@
55
*
66
*/
77

8-
#include <arduino-timer-cpp17.h>
8+
#include <arduino-timer-cpp17.hpp>
99

1010
Timers::TimerSet<1, Timers::Clock::micros> timerset; // create a TimerSet with 1 timer and microsecond clock
1111

1212
Timers::HandlerResult toggle_led() {
13-
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); // toggle the LED
14-
return Timers::TimerStatus::repeat;
13+
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); // toggle the LED
14+
return Timers::TimerStatus::repeat;
1515
}
1616

1717
void setup() {
18-
pinMode(LED_BUILTIN, OUTPUT); // set LED pin to OUTPUT
18+
pinMode(LED_BUILTIN, OUTPUT); // set LED pin to OUTPUT
1919

20-
// call the toggle_led function every 1000000 micros (1 second)
21-
timerset.every(1000000, toggle_led);
20+
// call the toggle_led function every 1000000 micros (1 second)
21+
timerset.every(1000000, toggle_led);
2222
}
2323

2424
void loop() {
25-
timerset.tick_and_delay(); // tick the timer
25+
timerset.tick_and_delay(); // tick the timer
2626
}

examples/blink_print/blink_print.ino

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,32 @@
66
*
77
*/
88

9-
#include <arduino-timer-cpp17.h>
9+
#include <arduino-timer-cpp17.hpp>
1010

1111
auto timerset = Timers::create_default(); // create a TimerSet with default settings
1212

1313
Timers::HandlerResult toggle_led() {
14-
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); // toggle the LED
15-
return Timers::TimerStatus::repeat;
14+
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); // toggle the LED
15+
return Timers::TimerStatus::repeat;
1616
}
1717

1818
Timers::HandlerResult print_message() {
19-
Serial.print("print_message: Called at: ");
20-
Serial.println(millis());
21-
return Timers::TimerStatus::repeat;
19+
Serial.print("print_message: Called at: ");
20+
Serial.println(millis());
21+
return Timers::TimerStatus::repeat;
2222
}
2323

2424
void setup() {
25-
Serial.begin(9600);
26-
pinMode(LED_BUILTIN, OUTPUT); // set LED pin to OUTPUT
25+
Serial.begin(9600);
26+
pinMode(LED_BUILTIN, OUTPUT); // set LED pin to OUTPUT
2727

28-
// call the toggle_led function every 500 millis (half second)
29-
timerset.every(500, toggle_led);
28+
// call the toggle_led function every 500 millis (half second)
29+
timerset.every(500, toggle_led);
3030

31-
// call the print_message function every 1000 millis (1 second)
32-
timerset.every(1000, print_message);
31+
// call the print_message function every 1000 millis (1 second)
32+
timerset.every(1000, print_message);
3333
}
3434

3535
void loop() {
36-
timerset.tick_and_delay(); // tick the timer
36+
timerset.tick_and_delay(); // tick the timer
3737
}

examples/full/full.ino

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*/
1212

13-
#include <arduino-timer-cpp17.h>
13+
#include <arduino-timer-cpp17.hpp>
1414

1515
auto timerset = Timers::create_default(); // create a TimerSet with default settings
1616
Timers::TimerSet<> default_timerset; // same as above
@@ -22,66 +22,66 @@ Timers::TimerSet<1, Timers::Clock::micros> microtimerset;
2222
Timers::TimerSet<16, Timers::Clock::millis> t_timerset;
2323

2424
Timers::HandlerResult toggle_led() {
25-
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); // toggle the LED
26-
return Timers::TimerStatus::repeat;
25+
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); // toggle the LED
26+
return Timers::TimerStatus::repeat;
2727
}
2828

2929
Timers::HandlerResult print_message(const char *message) {
30-
Serial.print("print_message: ");
31-
Serial.println(message);
32-
return Timers::TimerStatus::repeat;
30+
Serial.print("print_message: ");
31+
Serial.println(message);
32+
return Timers::TimerStatus::repeat;
3333
}
3434

3535
size_t repeat_count = 1;
3636
Timers::HandlerResult repeat_x_times(size_t limit) {
37-
Serial.print("repeat_x_times: ");
38-
Serial.print(repeat_count);
39-
Serial.print("/");
40-
Serial.println(limit);
37+
Serial.print("repeat_x_times: ");
38+
Serial.print(repeat_count);
39+
Serial.print("/");
40+
Serial.println(limit);
4141

42-
// remove this task after limit reached
43-
return ++repeat_count <= limit ? Timers::TimerStatus::repeat : Timers::TimerStatus::completed;
42+
// remove this task after limit reached
43+
return ++repeat_count <= limit ? Timers::TimerStatus::repeat : Timers::TimerStatus::completed;
4444
}
4545

4646
void setup() {
47-
Serial.begin(9600);
48-
pinMode(LED_BUILTIN, OUTPUT); // set LED pin to OUTPUT
47+
Serial.begin(9600);
48+
pinMode(LED_BUILTIN, OUTPUT); // set LED pin to OUTPUT
4949

50-
// call the toggle_led function every 500 millis (half second)
51-
timerset.every(500, toggle_led);
50+
// call the toggle_led function every 500 millis (half second)
51+
timerset.every(500, toggle_led);
5252

53-
// call the repeat_x_times function every 1000 millis (1 second)
54-
timerset.every(1000, [](){ return repeat_x_times(10); });
53+
// call the repeat_x_times function every 1000 millis (1 second)
54+
timerset.every(1000, [](){ return repeat_x_times(10); });
5555

56-
// call the print_message function every 1000 millis (1 second),
57-
// passing it an argument string
58-
t_timerset.every(1000, [](){ return print_message("called every second"); });
56+
// call the print_message function every 1000 millis (1 second),
57+
// passing it an argument string
58+
t_timerset.every(1000, [](){ return print_message("called every second"); });
5959

60-
// call the print_message function in five seconds
61-
t_timerset.in(5000, [](){ return print_message("delayed five seconds"); });
60+
// call the print_message function in five seconds
61+
t_timerset.in(5000, [](){ return print_message("delayed five seconds"); });
6262

63-
// call the print_message function in fifteen seconds by scheduling and then rescheduling
64-
auto resched_timer = t_timerset.in(5000, [](){ return print_message("delayed fifteen seconds"); });
65-
t_timerset.reschedule_in(resched_timer, 15000);
63+
// call the print_message function in fifteen seconds by scheduling and then rescheduling
64+
auto resched_timer = t_timerset.in(5000, [](){ return print_message("delayed fifteen seconds"); });
65+
t_timerset.reschedule_in(resched_timer, 15000);
6666

67-
// call the print_message function at time + 10 seconds
68-
t_timerset.at(millis() + 10000, [](){ return print_message("call at millis() + 10 seconds"); });
67+
// call the print_message function at time + 10 seconds
68+
t_timerset.at(millis() + 10000, [](){ return print_message("call at millis() + 10 seconds"); });
6969

70-
// call the toggle_led function every 500 millis (half-second)
71-
auto timer = timerset.every(500, toggle_led);
72-
timerset.cancel(timer); // this task is now cancelled, and will not run
70+
// call the toggle_led function every 500 millis (half-second)
71+
auto timer = timerset.every(500, toggle_led);
72+
timerset.cancel(timer); // this task is now cancelled, and will not run
7373

74-
// call print_message in 2 seconds, but with microsecond clock
75-
microtimerset.in(2000000, [](){ return print_message("delayed two seconds using microseconds"); });
74+
// call print_message in 2 seconds, but with microsecond clock
75+
microtimerset.in(2000000, [](){ return print_message("delayed two seconds using microseconds"); });
7676

77-
if (!microtimerset.in(5000, [](){ return print_message("never printed"); })) {
78-
/* this fails because we created microtimerset with only 1 concurrent timer slot */
79-
Serial.println("Failed to add microsecond event - timer full");
80-
}
77+
if (!microtimerset.in(5000, [](){ return print_message("never printed"); })) {
78+
/* this fails because we created microtimerset with only 1 concurrent timer slot */
79+
Serial.println("Failed to add microsecond event - timer full");
80+
}
8181
}
8282

8383
void loop() {
84-
timerset.tick();
85-
t_timerset.tick();
86-
microtimerset.tick();
84+
timerset.tick();
85+
t_timerset.tick();
86+
microtimerset.tick();
8787
}

extras/tests/rollover-generic/rollover-generic.ino

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
2-
Test timer rollover handling
3-
*/
2+
Test timer rollover handling
3+
*/
44

5-
#include <arduino-timer-cpp17.h>
5+
#include <arduino-timer-cpp17.hpp>
66

77
Timers::Timepoint wrapping_millis();
88

@@ -21,16 +21,18 @@ Timers::Timepoint wrapping_millis()
2121

2222
void setup() {
2323
pinMode(LED_BUILTIN, OUTPUT);
24-
_timerset.every(1, [](){
25-
++_millis; // increase _millis every millisecond
26-
return Timers::TimerStatus::repeat;
27-
});
24+
_timerset.every(1, []()
25+
{
26+
++_millis; // increase _millis every millisecond
27+
return Timers::TimerStatus::repeat;
28+
});
2829

2930
// should blink the LED every second, regardless of wrapping
30-
timerset.every(1000, [](){
31-
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
32-
return Timers::TimerStatus::repeat;
33-
});
31+
timerset.every(1000, []()
32+
{
33+
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
34+
return Timers::TimerStatus::repeat;
35+
});
3436
}
3537

3638
void loop() {

extras/tests/rollover/rollover.ino

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/*
2-
Test timer rollover handling
3-
*/
2+
Test timer rollover handling
3+
*/
44

55
#include <util/atomic.h>
6-
#include <arduino-timer-cpp17.h>
6+
#include <arduino-timer-cpp17.hpp>
77

88
auto timerset = Timers::create_default();
99

@@ -18,10 +18,11 @@ void set_millis(unsigned long ms)
1818

1919
void setup() {
2020
pinMode(LED_BUILTIN, OUTPUT);
21-
timerset.every(1000, [](){
22-
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
23-
return Timers::TimerStatus::repeat;
24-
});
21+
timerset.every(1000, []()
22+
{
23+
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
24+
return Timers::TimerStatus::repeat;
25+
});
2526
}
2627

2728
void loop() {

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ paragraph=Simple non-blocking timer library for calling functions in / at / ever
88
category=Timing
99
url=https://github.com/kpfleming/arduino-timer-cpp17
1010
architectures=*
11-
includes=arduino-timer-cpp17.h
11+
includes=arduino-timer-cpp17.hpp

0 commit comments

Comments
 (0)