Skip to content

Commit

Permalink
Support Update
Browse files Browse the repository at this point in the history
Added support for ESP8266
  • Loading branch information
biomurph committed Jan 5, 2024
1 parent f88bd42 commit 6835f94
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 6 deletions.
16 changes: 16 additions & 0 deletions src/PulseSensorPlayground.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,12 @@ bool PulseSensorPlayground::setupInterrupt(){
result = true;
#endif

#if defined(ARDUINO_ARCH_ESP8266)
ESP8266Timer sampleTimer;
sampleTimer.setFrequency(500,onInterrupt);
sampleTimer.restartTimer();
#endif

#if defined(ARDUINO_SAMD_ZERO) || defined(ARDUINO_ARCH_SAMD)
sampleTimer.attachInterrupt(SAMPLE_RATE_500HZ, onInterrupt);
result = true;
Expand Down Expand Up @@ -575,6 +581,11 @@ bool PulseSensorPlayground::enableInterrupt(){
result = true;
#endif

#if defined(ARDUINO_ARCH_ESP8266)
sampleTimer.restartTimer();
result = true;
#endif

#if defined(ARDUINO_ARCH_SAM)
sampleTimer.start(2000);
result = true;
Expand Down Expand Up @@ -652,6 +663,11 @@ bool PulseSensorPlayground::disableInterrupt(){
result = true;
#endif

#if defined(ARDUINO_ARCH_ESP8266)
sampleTimer.stopTimer();
result = true;
#endif

#if defined(ARDUINO_ARCH_SAM)
sampleTimer.stop();
result = true;
Expand Down
16 changes: 10 additions & 6 deletions src/utility/SelectTimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
Any board with RP2040

ARDUINO_NRF52_ADAFRUIT
nRF52840 Bluetooth
nRF52840 Bluetooth Family
Adafruit and Seeed nRF52 boards (non EMBED boards yet!)

ARDUINO_ARCH_ESP32
Expand All @@ -52,6 +52,10 @@
ATSAMD51 Core-M4
Adafruit Meather M4

ARDUINO_ARCH_ESP8266
ESP8266 Family
Adafruit Feather Huzzah


*/

Expand All @@ -61,7 +65,7 @@

#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_RENESAS) || defined(ARDUINO_ARCH_RP2040)\
|| defined(ARDUINO_SAM_DUE) || defined(ARDUINO_NRF52_ADAFRUIT) || defined(ARDUINO_ARCH_ESP32)\
|| defined(ARDUINO_SAMD_ZERO) || defined(ARDUINO_ARCH_SAMD)
|| defined(ARDUINO_SAMD_ZERO) || defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_ESP8266)
#define USE_HARDWARE_TIMER true
// #warning "Using hardware timer to sample PulseSensor."
#else
Expand All @@ -70,12 +74,12 @@
#endif

// Macros to link to interrupt disable/enable only if they exist
#ifndef ARDUINO_ARCH_AVR
#define DISABLE_PULSE_SENSOR_INTERRUPTS
#define ENABLE_PULSE_SENSOR_INTERRUPTS
#else
#if defined ARDUINO_ARCH_AVR
#define DISABLE_PULSE_SENSOR_INTERRUPTS cli()
#define ENABLE_PULSE_SENSOR_INTERRUPTS sei()
#else
#define DISABLE_PULSE_SENSOR_INTERRUPTS
#define ENABLE_PULSE_SENSOR_INTERRUPTS
#endif

#endif // SELECT_TIMER include guard
15 changes: 15 additions & 0 deletions src/utility/TimerHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,21 @@
}
#endif

#if defined(ARDUINO_ARCH_ESP8266)
/*
If you are using ESP8266, include the TimerInterrupt library
https://github.com/khoih-prog/ESP8266TimerInterrupt
*/
#define USING_TIM_DIV16 true
#include "ESP8266TimerInterrupt.h"

void IRAM_ATTR onInterrupt(){
PulseSensorPlayground::OurThis->onSampleTime();
}
ESP8266Timer sampleTimer;

#endif

#if defined(ARDUINO_SAMD_ZERO) || defined(ARDUINO_ARCH_SAMD)
// These define's must be placed at the beginning before #include "SAMDTimerInterrupt.h"
// _TIMERINTERRUPT_LOGLEVEL_ from 0 to 4
Expand Down

0 comments on commit 6835f94

Please sign in to comment.