Skip to content

Commit 6835f94

Browse files
committed
Support Update
Added support for ESP8266
1 parent f88bd42 commit 6835f94

3 files changed

Lines changed: 41 additions & 6 deletions

File tree

src/PulseSensorPlayground.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,12 @@ bool PulseSensorPlayground::setupInterrupt(){
496496
result = true;
497497
#endif
498498

499+
#if defined(ARDUINO_ARCH_ESP8266)
500+
ESP8266Timer sampleTimer;
501+
sampleTimer.setFrequency(500,onInterrupt);
502+
sampleTimer.restartTimer();
503+
#endif
504+
499505
#if defined(ARDUINO_SAMD_ZERO) || defined(ARDUINO_ARCH_SAMD)
500506
sampleTimer.attachInterrupt(SAMPLE_RATE_500HZ, onInterrupt);
501507
result = true;
@@ -575,6 +581,11 @@ bool PulseSensorPlayground::enableInterrupt(){
575581
result = true;
576582
#endif
577583

584+
#if defined(ARDUINO_ARCH_ESP8266)
585+
sampleTimer.restartTimer();
586+
result = true;
587+
#endif
588+
578589
#if defined(ARDUINO_ARCH_SAM)
579590
sampleTimer.start(2000);
580591
result = true;
@@ -652,6 +663,11 @@ bool PulseSensorPlayground::disableInterrupt(){
652663
result = true;
653664
#endif
654665

666+
#if defined(ARDUINO_ARCH_ESP8266)
667+
sampleTimer.stopTimer();
668+
result = true;
669+
#endif
670+
655671
#if defined(ARDUINO_ARCH_SAM)
656672
sampleTimer.stop();
657673
result = true;

src/utility/SelectTimer.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
Any board with RP2040
3939
4040
ARDUINO_NRF52_ADAFRUIT
41-
nRF52840 Bluetooth
41+
nRF52840 Bluetooth Family
4242
Adafruit and Seeed nRF52 boards (non EMBED boards yet!)
4343
4444
ARDUINO_ARCH_ESP32
@@ -52,6 +52,10 @@
5252
ATSAMD51 Core-M4
5353
Adafruit Meather M4
5454
55+
ARDUINO_ARCH_ESP8266
56+
ESP8266 Family
57+
Adafruit Feather Huzzah
58+
5559
5660
*/
5761

@@ -61,7 +65,7 @@
6165

6266
#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_RENESAS) || defined(ARDUINO_ARCH_RP2040)\
6367
|| defined(ARDUINO_SAM_DUE) || defined(ARDUINO_NRF52_ADAFRUIT) || defined(ARDUINO_ARCH_ESP32)\
64-
|| defined(ARDUINO_SAMD_ZERO) || defined(ARDUINO_ARCH_SAMD)
68+
|| defined(ARDUINO_SAMD_ZERO) || defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_ESP8266)
6569
#define USE_HARDWARE_TIMER true
6670
// #warning "Using hardware timer to sample PulseSensor."
6771
#else
@@ -70,12 +74,12 @@
7074
#endif
7175

7276
// Macros to link to interrupt disable/enable only if they exist
73-
#ifndef ARDUINO_ARCH_AVR
74-
#define DISABLE_PULSE_SENSOR_INTERRUPTS
75-
#define ENABLE_PULSE_SENSOR_INTERRUPTS
76-
#else
77+
#if defined ARDUINO_ARCH_AVR
7778
#define DISABLE_PULSE_SENSOR_INTERRUPTS cli()
7879
#define ENABLE_PULSE_SENSOR_INTERRUPTS sei()
80+
#else
81+
#define DISABLE_PULSE_SENSOR_INTERRUPTS
82+
#define ENABLE_PULSE_SENSOR_INTERRUPTS
7983
#endif
8084

8185
#endif // SELECT_TIMER include guard

src/utility/TimerHandler.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,21 @@
181181
}
182182
#endif
183183

184+
#if defined(ARDUINO_ARCH_ESP8266)
185+
/*
186+
If you are using ESP8266, include the TimerInterrupt library
187+
https://github.com/khoih-prog/ESP8266TimerInterrupt
188+
*/
189+
#define USING_TIM_DIV16 true
190+
#include "ESP8266TimerInterrupt.h"
191+
192+
void IRAM_ATTR onInterrupt(){
193+
PulseSensorPlayground::OurThis->onSampleTime();
194+
}
195+
ESP8266Timer sampleTimer;
196+
197+
#endif
198+
184199
#if defined(ARDUINO_SAMD_ZERO) || defined(ARDUINO_ARCH_SAMD)
185200
// These define's must be placed at the beginning before #include "SAMDTimerInterrupt.h"
186201
// _TIMERINTERRUPT_LOGLEVEL_ from 0 to 4

0 commit comments

Comments
 (0)