From 38f55fa4e4eb91a582639c67ff97acb238fd5b55 Mon Sep 17 00:00:00 2001 From: Joel Murphy Date: Wed, 28 Feb 2024 13:52:52 -0500 Subject: [PATCH] Fixed bug when using Arduino Servo library There was a conflict arising from multiple use of timer between PulseSensor and Servo. Used the __has_include conditional to solve it. --- .../PulseSensor_Servo_Motor.ino | 1 - library.properties | 2 +- src/PulseSensorPlayground.cpp | 2 +- src/PulseSensorPlayground.h | 9 +++++++-- src/utility/PulseSensor.cpp | 3 --- src/utility/PulseSensor.h | 1 - src/utility/PulseSensorTimingStatistics.cpp | 4 +--- src/utility/SelectTimer.h | 1 - src/utility/TimerHandler.h | 11 +++++++---- 9 files changed, 17 insertions(+), 17 deletions(-) diff --git a/examples/PulseSensor_Servo_Motor/PulseSensor_Servo_Motor.ino b/examples/PulseSensor_Servo_Motor/PulseSensor_Servo_Motor.ino index 71d68fe..2899c0d 100644 --- a/examples/PulseSensor_Servo_Motor/PulseSensor_Servo_Motor.ino +++ b/examples/PulseSensor_Servo_Motor/PulseSensor_Servo_Motor.ino @@ -179,7 +179,6 @@ void loop() { pulseSensor.outputSample(); // write the latest analog value to the heart servo moveServo(pulseSensor.getLatestSample()); - (signal); } } } diff --git a/library.properties b/library.properties index 1022112..9cd5dcf 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=PulseSensor Playground -version=2.0.1 +version=2.1.0 author=Joel Murphy, Yury Gitman, Brad Needham maintainer=Joel Murphy, Yury Gitman sentence=Support at PulseSensor.com diff --git a/src/PulseSensorPlayground.cpp b/src/PulseSensorPlayground.cpp index b4df535..64fb77e 100644 --- a/src/PulseSensorPlayground.cpp +++ b/src/PulseSensorPlayground.cpp @@ -29,7 +29,7 @@ PulseSensorPlayground::PulseSensorPlayground(int numberOfSensors) { // Save a static pointer to our playground so the ISR can read it. -#if USE_HARDWARE_TIMER +#if USE_HARDWARE_TIMER OurThis = this; #endif diff --git a/src/PulseSensorPlayground.h b/src/PulseSensorPlayground.h index b4f04e2..ccb9e2b 100644 --- a/src/PulseSensorPlayground.h +++ b/src/PulseSensorPlayground.h @@ -18,6 +18,7 @@ #ifndef PULSE_SENSOR_PLAYGROUND_H #define PULSE_SENSOR_PLAYGROUND_H +#include /* SelectTimer.h will determine if the library supports hardware timer interrupts or not. If so, it will set @@ -28,11 +29,12 @@ */ #include "utility/SelectTimer.h" + /* Library version number */ -#define PULSESENSOR_PLAYGROUND_VERSION_STRING "v2.0.0" -#define PULSESENSOR_PLAYGROUND_VERSION_NUMBER 2 +#define PULSESENSOR_PLAYGROUND_VERSION_STRING "v2.1.0" +#define PULSESENSOR_PLAYGROUND_VERSION_NUMBER 210 /* If you wish to perform timing statistics on your non-interrupt Sketch: @@ -131,6 +133,8 @@ #define SAMPLE_RATE_500HZ 500 #define SAMPLES_PER_SERIAL_SAMPLE 10 + + class PulseSensorPlayground { public: /* @@ -432,6 +436,7 @@ vvvvvvvv THIS NEEDS MODIFICATION FOR V2 vvvvvvvv #endif /* + Sets up the sample timer interrupt for this Arduino Platform and the pause and resume routines. */ diff --git a/src/utility/PulseSensor.cpp b/src/utility/PulseSensor.cpp index 14520fa..84e6f56 100644 --- a/src/utility/PulseSensor.cpp +++ b/src/utility/PulseSensor.cpp @@ -13,9 +13,6 @@ This software is not intended for medical use. */ -// #ifndef PULSE_SENSOR_PLAYGROUND_H -// #define PULSE_SENSOR_PLAYGROUND_H -// #endif #include /* diff --git a/src/utility/PulseSensor.h b/src/utility/PulseSensor.h index 4e23f47..06d3123 100644 --- a/src/utility/PulseSensor.h +++ b/src/utility/PulseSensor.h @@ -15,7 +15,6 @@ */ #ifndef PULSE_SENSOR_H #define PULSE_SENSOR_H - #include class PulseSensor { diff --git a/src/utility/PulseSensorTimingStatistics.cpp b/src/utility/PulseSensorTimingStatistics.cpp index 6e3462a..a496a93 100644 --- a/src/utility/PulseSensorTimingStatistics.cpp +++ b/src/utility/PulseSensorTimingStatistics.cpp @@ -17,9 +17,7 @@ This software is not intended for medical use. */ -// #ifndef PULSE_SENSOR_PLAYGROUND_H -// #define PULSE_SENSOR_PLAYGROUND_H -// #endif + #include PulseSensorTimingStatistics::PulseSensorTimingStatistics( diff --git a/src/utility/SelectTimer.h b/src/utility/SelectTimer.h index d51797d..9e8fe19 100644 --- a/src/utility/SelectTimer.h +++ b/src/utility/SelectTimer.h @@ -62,7 +62,6 @@ #ifndef SELECT_TIMER_H #define SELECT_TIMER_H - #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_ARCH_ESP8266) diff --git a/src/utility/TimerHandler.h b/src/utility/TimerHandler.h index 9a8e6e9..5143fb2 100644 --- a/src/utility/TimerHandler.h +++ b/src/utility/TimerHandler.h @@ -46,7 +46,8 @@ the platform detected by PulseSensorPlaygroundSetupInterrupt(). */ #if defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__) || defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega16U4__) || defined(__AVR_ATtiny85__) - #if defined Servo_h + #if __has_include () +#warning "Detected Servo library in TimerHandler.h" #if defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__) #ifndef TIMER_VECTOR #define TIMER_VECTOR @@ -86,12 +87,14 @@ #endif #endif #endif + // #endif #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) - #if defined Servo_h + #if __has_include () +#warning "Detected Servo library in TimerHandler.h" #ifndef TIMER_VECTOR #define TIMER_VECTOR - ISR(TIMER1_COMPA_vect) + ISR(TIMER2_COMPA_vect) { DISABLE_PULSE_SENSOR_INTERRUPTS; // disable interrupts while we do this @@ -103,7 +106,7 @@ #else #ifndef TIMER_VECTOR #define TIMER_VECTOR - ISR(TIMER2_COMPA_vect) + ISR(TIMER1_COMPA_vect) { DISABLE_PULSE_SENSOR_INTERRUPTS; // disable interrupts while we do this