Skip to content
This repository was archived by the owner on Jan 29, 2023. It is now read-only.

Commit dd0de64

Browse files
authored
v1.6.0 to optimize code, etc.
### Releases v1.6.0 1. Add example [ISR_16_Timers_Array_OneShot](examples/ISR_16_Timers_Array_OneShot) to demo how to use `one-shot ISR-based timer` 2. Add example [multiFileProject](examples/multiFileProject) to demo for multiple-file project 3. Optimize code by using passing by `reference` instead of by `value`
1 parent 69d84f6 commit dd0de64

10 files changed

+176
-187
lines changed

CONTRIBUTING.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Arduino IDE version: v1.8.19
3030
ESP8266 Core Version v3.0.2
3131
ESP8266_NODEMCU
3232
OS: Ubuntu 20.04 LTS
33-
Linux xy-Inspiron-3593 5.4.0-94-generic #106-Ubuntu SMP Thu Jan 6 23:58:14 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
33+
Linux xy-Inspiron-3593 5.13.0-35-generic #40~20.04.1-Ubuntu SMP Mon Mar 7 09:18:32 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
3434
3535
Context:
3636
I encountered a crash while trying to use the Timer Interrupt.
@@ -50,3 +50,4 @@ There are usually some outstanding feature requests in the [existing issues list
5050
### Sending Pull Requests
5151

5252
Pull Requests with changes and fixes are also welcome!
53+

README.md

+93-130
Large diffs are not rendered by default.

changelog.md

+7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
---
1111

1212
* [Changelog](#changelog)
13+
* [Releases v1.6.0](#releases-v160)
1314
* [Releases v1.5.0](#releases-v150)
1415
* [Releases v1.4.1](#releases-v141)
1516
* [Releases v1.4.0](#releases-v140)
@@ -25,6 +26,12 @@
2526

2627
## Changelog
2728

29+
### Releases v1.6.0
30+
31+
1. Add example [ISR_16_Timers_Array_OneShot](examples/ISR_16_Timers_Array_OneShot) to demo how to use `one-shot ISR-based timer`
32+
2. Add example [multiFileProject](examples/multiFileProject) to demo for multiple-file project
33+
3. Optimize code by using passing by `reference` instead of by `value`
34+
2835
### Releases v1.5.0
2936

3037
1. Fix `multiple-definitions` linker error. Drop `src_cpp` and `src_h` directories

library.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ESP8266TimerInterrupt",
3-
"version": "1.5.0",
3+
"version": "1.6.0",
44
"keywords": "timing, device, control, timer, interrupt, timer-interrupt, hardware, isr, isr-based, hardware-timer, isr-timer, isr-based-timer, mission-critical, accuracy, precise, non-blocking, long-timer, esp8266, multi-isr-based-timers",
55
"description": "This library enables you to use Interrupt from Hardware Timers on an ESP8266-based board. It now supports 16 ISR-based timers, while consuming only 1 Hardware Timer. Timers' interval is very long (ulong millisecs). The most important feature is they're ISR-based timers. Therefore, their executions are not blocked by bad-behaving functions or tasks. This important feature is absolutely necessary for mission-critical tasks. These hardware timers, using interrupt, still work even if other functions are blocking. Moreover, they are much more precise (certainly depending on clock frequency accuracy) than other software timers using millis() or micros(). That's necessary if you need to measure some data requiring better accuracy.",
66
"authors":
@@ -26,5 +26,5 @@
2626
"frameworks": "*",
2727
"platforms": "espressif8266",
2828
"examples": "examples/*/*/*.ino",
29-
"headers": ["ESP8266TimerInterrupt.h", "ESP8266TimerInterrupt.hpp", "ESP8266_ISR_Timer.h"]
29+
"headers": ["ESP8266TimerInterrupt.h", "ESP8266_ISR_Timer.h", "ESP8266_ISR_Timer.hpp"]
3030
}

library.properties

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
name=ESP8266TimerInterrupt
2-
version=1.5.0
2+
version=1.6.0
33
author=Khoi Hoang <[email protected]>
44
maintainer=Khoi Hoang <[email protected]>
55
sentence=This library enables you to use Interrupt from Hardware Timers on an ESP8266-based board.
6-
paragraph=These ESP8266 Hardware Timers, using Interrupt, still work even if other functions are blocking. Moreover, they are much more precise (certainly depending on clock frequency accuracy) than other software timers using millis() or micros(). That is mandatory if you need to measure some data requiring better accuracy. It now supports 16 ISR-based Timers, while consuming only 1 Hardware Timer. Timers interval is very long (ulong millisecs). The most important feature is they are ISR-based Timers. Therefore, their executions are not blocked by bad-behaving functions or tasks. This important feature is absolutely necessary for mission-critical tasks.
6+
paragraph=These ESP8266 Hardware Timers, using Interrupt, still work even if other functions are blocking. Moreover, they are much more precise (certainly depending on clock frequency accuracy) than other software timers using millis() or micros(). That's mandatory if you need to measure some data requiring better accuracy. It now supports 16 ISR-based Timers, while consuming only 1 Hardware Timer. Timers' interval is very long (ulong millisecs). The most important feature is they're ISR-based Timers. Therefore, their executions are not blocked by bad-behaving functions or tasks. This important feature is absolutely necessary for mission-critical tasks.
77
category=Device Control
88
url=https://github.com/khoih-prog/ESP8266TimerInterrupt
99
architectures=esp8266
1010
repository=https://github.com/khoih-prog/ESP8266TimerInterrupt
1111
license=MIT
12-
includes=ESP8266TimerInterrupt.h,ESP8266_ISR_Timer.hpp,ESP8266_ISR_Timer.h
12+
includes=ESP8266TimerInterrupt.h,ESP8266_ISR_Timer.h,ESP8266_ISR_Timer.hpp

src/ESP8266TimerInterrupt.h

+14-11
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
Based on BlynkTimer.h
2424
Author: Volodymyr Shymanskyy
2525
26-
Version: 1.5.0
26+
Version: 1.6.0
2727
2828
Version Modified By Date Comments
2929
------- ----------- ---------- -----------
@@ -38,6 +38,7 @@
3838
1.4.0 K.Hoang 01/06/2021 Add complex examples. Fix compiler errors due to conflict to some libraries.
3939
1.4.1 K.Hoang 22/11/2021 Tested with core v3.0.2. Add instructions in README.md
4040
1.5.0 K.Hoang 18/01/2022 Fix `multiple-definitions` linker error. Fix bug and add more accurate but shorter timer
41+
1.6.0 K.Hoang 13/02/2022 Add example to demo how to use one-shot ISR-based timers. Optimize code
4142
*****************************************************************************************************************************/
4243

4344
#pragma once
@@ -50,14 +51,16 @@
5051
#endif
5152

5253
#ifndef ESP8266_TIMER_INTERRUPT_VERSION
53-
#define ESP8266_TIMER_INTERRUPT_VERSION "ESP8266TimerInterrupt v1.5.0"
54-
#endif
54+
#define ESP8266_TIMER_INTERRUPT_VERSION "ESP8266TimerInterrupt v1.6.0"
55+
5556

56-
#define ESP8266_TIMER_INTERRUPT_VERSION_MAJOR 1
57-
#define ESP8266_TIMER_INTERRUPT_VERSION_MINOR 5
58-
#define ESP8266_TIMER_INTERRUPT_VERSION_PATCH 0
57+
#define ESP8266_TIMER_INTERRUPT_VERSION_MAJOR 1
58+
#define ESP8266_TIMER_INTERRUPT_VERSION_MINOR 6
59+
#define ESP8266_TIMER_INTERRUPT_VERSION_PATCH 0
5960

60-
#define ESP8266_TIMER_INTERRUPT_VERSION_INT 1005000
61+
#define ESP8266_TIMER_INTERRUPT_VERSION_INT 1006000
62+
63+
#endif
6164

6265
#ifndef TIMER_INTERRUPT_DEBUG
6366
#define TIMER_INTERRUPT_DEBUG 0
@@ -143,7 +146,7 @@ class ESP8266TimerInterrupt
143146

144147
// frequency (in hertz) and duration (in milliseconds). Duration = 0 or not specified => run indefinitely
145148
// No params and duration now. To be addes in the future by adding similar functions here or to esp32-hal-timer.c
146-
bool setFrequency(float frequency, timer_callback callback)
149+
bool setFrequency(const float& frequency, const timer_callback& callback)
147150
{
148151
bool isOKFlag = true;
149152
float minFreq = (float) TIM_CLOCK_FREQ / MAX_ESP8266_COUNT;
@@ -187,19 +190,19 @@ class ESP8266TimerInterrupt
187190

188191
// interval (in microseconds) and duration (in milliseconds). Duration = 0 or not specified => run indefinitely
189192
// No params and duration now. To be addes in the future by adding similar functions here or to esp32-hal-timer.c
190-
bool setInterval(unsigned long interval, timer_callback callback)
193+
bool setInterval(const unsigned long& interval, const timer_callback& callback)
191194
{
192195
return setFrequency((float) (1000000.0f / interval), callback);
193196
}
194197

195-
bool attachInterrupt(float frequency, timer_callback callback)
198+
bool attachInterrupt(const float& frequency, const timer_callback& callback)
196199
{
197200
return setFrequency(frequency, callback);
198201
}
199202

200203
// interval (in microseconds) and duration (in milliseconds). Duration = 0 or not specified => run indefinitely
201204
// No params and duration now. To be addes in the future by adding similar functions here or to esp32-hal-timer.c
202-
bool attachInterruptInterval(unsigned long interval, timer_callback callback)
205+
bool attachInterruptInterval(const unsigned long& interval, const timer_callback& callback)
203206
{
204207
return setFrequency( (float) ( 1000000.0f / interval), callback);
205208
}

src/ESP8266_ISR_Timer-Impl.h

+18-17
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
Based on BlynkTimer.h
2424
Author: Volodymyr Shymanskyy
2525
26-
Version: 1.5.0
26+
Version: 1.6.0
2727
2828
Version Modified By Date Comments
2929
------- ----------- ---------- -----------
@@ -38,6 +38,7 @@
3838
1.4.0 K.Hoang 01/06/2021 Add complex examples. Fix compiler errors due to conflict to some libraries.
3939
1.4.1 K.Hoang 22/11/2021 Tested with core v3.0.2. Add instructions in README.md
4040
1.5.0 K.Hoang 18/01/2022 Fix `multiple-definitions` linker error. Fix bug and add more accurate but shorter timer
41+
1.6.0 K.Hoang 13/02/2022 Add example to demo how to use one-shot ISR-based timers. Optimize code
4142
*****************************************************************************************************************************/
4243

4344
#pragma once
@@ -147,7 +148,7 @@ void IRAM_ATTR ESP8266_ISR_Timer::run()
147148

148149
// find the first available slot
149150
// return -1 if none found
150-
int IRAM_ATTR ESP8266_ISR_Timer::findFirstFreeSlot()
151+
int8_t IRAM_ATTR ESP8266_ISR_Timer::findFirstFreeSlot()
151152
{
152153
// all slots are used
153154
if (numTimers >= MAX_NUMBER_TIMERS)
@@ -169,7 +170,7 @@ int IRAM_ATTR ESP8266_ISR_Timer::findFirstFreeSlot()
169170
}
170171

171172

172-
int IRAM_ATTR ESP8266_ISR_Timer::setupTimer(unsigned long d, void* f, void* p, bool h, unsigned n)
173+
int8_t IRAM_ATTR ESP8266_ISR_Timer::setupTimer(const unsigned long& d, void* f, void* p, bool h, const unsigned& n)
173174
{
174175
int freeTimer;
175176

@@ -204,37 +205,37 @@ int IRAM_ATTR ESP8266_ISR_Timer::setupTimer(unsigned long d, void* f, void* p, b
204205
}
205206

206207

207-
int IRAM_ATTR ESP8266_ISR_Timer::setTimer(unsigned long d, timer_callback f, unsigned n)
208+
int IRAM_ATTR ESP8266_ISR_Timer::setTimer(const unsigned long& d, const timer_callback& f, const unsigned& n)
208209
{
209210
return setupTimer(d, (void *)f, NULL, false, n);
210211
}
211212

212-
int IRAM_ATTR ESP8266_ISR_Timer::setTimer(unsigned long d, timer_callback_p f, void* p, unsigned n)
213+
int IRAM_ATTR ESP8266_ISR_Timer::setTimer(const unsigned long& d, const timer_callback_p& f, void* p, const unsigned& n)
213214
{
214215
return setupTimer(d, (void *)f, p, true, n);
215216
}
216217

217-
int IRAM_ATTR ESP8266_ISR_Timer::setInterval(unsigned long d, timer_callback f)
218+
int IRAM_ATTR ESP8266_ISR_Timer::setInterval(const unsigned long& d, const timer_callback& f)
218219
{
219220
return setupTimer(d, (void *)f, NULL, false, TIMER_RUN_FOREVER);
220221
}
221222

222-
int IRAM_ATTR ESP8266_ISR_Timer::setInterval(unsigned long d, timer_callback_p f, void* p)
223+
int IRAM_ATTR ESP8266_ISR_Timer::setInterval(const unsigned long& d, const timer_callback_p& f, void* p)
223224
{
224225
return setupTimer(d, (void *)f, p, true, TIMER_RUN_FOREVER);
225226
}
226227

227-
int IRAM_ATTR ESP8266_ISR_Timer::setTimeout(unsigned long d, timer_callback f)
228+
int IRAM_ATTR ESP8266_ISR_Timer::setTimeout(const unsigned long& d, const timer_callback& f)
228229
{
229230
return setupTimer(d, (void *)f, NULL, false, TIMER_RUN_ONCE);
230231
}
231232

232-
int IRAM_ATTR ESP8266_ISR_Timer::setTimeout(unsigned long d, timer_callback_p f, void* p)
233+
int IRAM_ATTR ESP8266_ISR_Timer::setTimeout(const unsigned long& d, const timer_callback_p& f, void* p)
233234
{
234235
return setupTimer(d, (void *)f, p, true, TIMER_RUN_ONCE);
235236
}
236237

237-
bool IRAM_ATTR ESP8266_ISR_Timer::changeInterval(unsigned numTimer, unsigned long d)
238+
bool IRAM_ATTR ESP8266_ISR_Timer::changeInterval(const unsigned& numTimer, const unsigned long& d)
238239
{
239240
if (numTimer >= MAX_NUMBER_TIMERS)
240241
{
@@ -252,7 +253,7 @@ bool IRAM_ATTR ESP8266_ISR_Timer::changeInterval(unsigned numTimer, unsigned lon
252253
return false;
253254
}
254255

255-
void IRAM_ATTR ESP8266_ISR_Timer::deleteTimer(unsigned timerId)
256+
void IRAM_ATTR ESP8266_ISR_Timer::deleteTimer(const unsigned& timerId)
256257
{
257258
if (timerId >= MAX_NUMBER_TIMERS)
258259
{
@@ -279,7 +280,7 @@ void IRAM_ATTR ESP8266_ISR_Timer::deleteTimer(unsigned timerId)
279280

280281

281282
// function contributed by [email protected]
282-
void IRAM_ATTR ESP8266_ISR_Timer::restartTimer(unsigned numTimer)
283+
void IRAM_ATTR ESP8266_ISR_Timer::restartTimer(const unsigned& numTimer)
283284
{
284285
if (numTimer >= MAX_NUMBER_TIMERS)
285286
{
@@ -290,7 +291,7 @@ void IRAM_ATTR ESP8266_ISR_Timer::restartTimer(unsigned numTimer)
290291
}
291292

292293

293-
bool IRAM_ATTR ESP8266_ISR_Timer::isEnabled(unsigned numTimer)
294+
bool IRAM_ATTR ESP8266_ISR_Timer::isEnabled(const unsigned& numTimer)
294295
{
295296
if (numTimer >= MAX_NUMBER_TIMERS)
296297
{
@@ -301,7 +302,7 @@ bool IRAM_ATTR ESP8266_ISR_Timer::isEnabled(unsigned numTimer)
301302
}
302303

303304

304-
void IRAM_ATTR ESP8266_ISR_Timer::enable(unsigned numTimer)
305+
void IRAM_ATTR ESP8266_ISR_Timer::enable(const unsigned& numTimer)
305306
{
306307
if (numTimer >= MAX_NUMBER_TIMERS)
307308
{
@@ -312,7 +313,7 @@ void IRAM_ATTR ESP8266_ISR_Timer::enable(unsigned numTimer)
312313
}
313314

314315

315-
void IRAM_ATTR ESP8266_ISR_Timer::disable(unsigned numTimer)
316+
void IRAM_ATTR ESP8266_ISR_Timer::disable(const unsigned& numTimer)
316317
{
317318
if (numTimer >= MAX_NUMBER_TIMERS)
318319
{
@@ -346,7 +347,7 @@ void IRAM_ATTR ESP8266_ISR_Timer::disableAll()
346347
}
347348
}
348349

349-
void IRAM_ATTR ESP8266_ISR_Timer::toggle(unsigned numTimer)
350+
void IRAM_ATTR ESP8266_ISR_Timer::toggle(const unsigned& numTimer)
350351
{
351352
if (numTimer >= MAX_NUMBER_TIMERS)
352353
{
@@ -357,7 +358,7 @@ void IRAM_ATTR ESP8266_ISR_Timer::toggle(unsigned numTimer)
357358
}
358359

359360

360-
unsigned IRAM_ATTR ESP8266_ISR_Timer::getNumTimers()
361+
int8_t IRAM_ATTR ESP8266_ISR_Timer::getNumTimers()
361362
{
362363
return numTimers;
363364
}

src/ESP8266_ISR_Timer.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
Based on BlynkTimer.h
2424
Author: Volodymyr Shymanskyy
2525
26-
Version: 1.5.0
26+
Version: 1.6.0
2727
2828
Version Modified By Date Comments
2929
------- ----------- ---------- -----------
@@ -38,6 +38,7 @@
3838
1.4.0 K.Hoang 01/06/2021 Add complex examples. Fix compiler errors due to conflict to some libraries.
3939
1.4.1 K.Hoang 22/11/2021 Tested with core v3.0.2. Add instructions in README.md
4040
1.5.0 K.Hoang 18/01/2022 Fix `multiple-definitions` linker error. Fix bug and add more accurate but shorter timer
41+
1.6.0 K.Hoang 13/02/2022 Add example to demo how to use one-shot ISR-based timers. Optimize code
4142
*****************************************************************************************************************************/
4243

4344
#pragma once

0 commit comments

Comments
 (0)