Skip to content

Commit

Permalink
Fixed bug when using Arduino Servo library
Browse files Browse the repository at this point in the history
There was a conflict arising from multiple use of timer between PulseSensor and Servo.
Used the __has_include conditional to solve it.
  • Loading branch information
biomurph committed Feb 28, 2024
1 parent 142bdea commit 38f55fa
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ void loop() {
pulseSensor.outputSample();
// write the latest analog value to the heart servo
moveServo(pulseSensor.getLatestSample());
(signal);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/PulseSensorPlayground.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 7 additions & 2 deletions src/PulseSensorPlayground.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#ifndef PULSE_SENSOR_PLAYGROUND_H
#define PULSE_SENSOR_PLAYGROUND_H

#include <Arduino.h>
/*
SelectTimer.h will determine if the library supports
hardware timer interrupts or not. If so, it will set
Expand All @@ -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:
Expand Down Expand Up @@ -131,6 +133,8 @@
#define SAMPLE_RATE_500HZ 500
#define SAMPLES_PER_SERIAL_SAMPLE 10



class PulseSensorPlayground {
public:
/*
Expand Down Expand Up @@ -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.
*/
Expand Down
3 changes: 0 additions & 3 deletions src/utility/PulseSensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@

This software is not intended for medical use.
*/
// #ifndef PULSE_SENSOR_PLAYGROUND_H
// #define PULSE_SENSOR_PLAYGROUND_H
// #endif
#include <PulseSensorPlayground.h>

/*
Expand Down
1 change: 0 additions & 1 deletion src/utility/PulseSensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
#ifndef PULSE_SENSOR_H
#define PULSE_SENSOR_H

#include <Arduino.h>

class PulseSensor {
Expand Down
4 changes: 1 addition & 3 deletions src/utility/PulseSensorTimingStatistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@

This software is not intended for medical use.
*/
// #ifndef PULSE_SENSOR_PLAYGROUND_H
// #define PULSE_SENSOR_PLAYGROUND_H
// #endif

#include <PulseSensorPlayground.h>

PulseSensorTimingStatistics::PulseSensorTimingStatistics(
Expand Down
1 change: 0 additions & 1 deletion src/utility/SelectTimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 7 additions & 4 deletions src/utility/TimerHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 (<Servo.h>)
#warning "Detected Servo library in TimerHandler.h"
#if defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__)
#ifndef TIMER_VECTOR
#define TIMER_VECTOR
Expand Down Expand Up @@ -86,12 +87,14 @@
#endif
#endif
#endif
// #endif

#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
#if defined Servo_h
#if __has_include (<Servo.h>)
#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

Expand All @@ -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

Expand Down

0 comments on commit 38f55fa

Please sign in to comment.