Library for the Grove Earbud Heartrate Sensor
Dependents: BLE_Police_HRM_Earbud df-2014-salesforce-hrm-k64f BLE_HeartRate_ppm emoSound ... more
Diff: GroveEarbudSensor.cpp
- Revision:
- 11:30d8d0a456f3
- Parent:
- 10:db3dea613e09
- Child:
- 12:8687d42d6798
diff -r db3dea613e09 -r 30d8d0a456f3 GroveEarbudSensor.cpp --- a/GroveEarbudSensor.cpp Thu Dec 18 05:41:14 2014 +0000 +++ b/GroveEarbudSensor.cpp Wed Mar 11 20:27:28 2015 +0000 @@ -32,16 +32,44 @@ // constructor GroveEarbudSensor::GroveEarbudSensor(InterruptIn *rx,RawSerial *pc) { - _grove_earbud_sensor_instance = this; - this->m_rx = rx; - this->m_pc = pc; - this->m_sub = 0; - this->m_counter = 0; - this->m_data_effect = true; - this->m_cb_fn = NULL; - this->m_cb_data = NULL; - this->m_heartrate = HEARTRATE_OFF; - this->m_timer = new Timer(); + _grove_earbud_sensor_instance = this; + this->m_rx = rx; + this->m_pc = pc; + this->m_sub = 0; + this->m_counter = 0; + this->m_data_effect = true; + this->m_cb_fn = NULL; + this->m_cb_data = NULL; + this->m_heartrate = HEARTRATE_OFF; + this->m_timer = new Timer(); + this->m_internal_interrupt_instance = false; + + // register the interrupt handler + if (this->m_rx != NULL) this->m_rx->rise(&__grove_earbud_sensor_interrupt); + + // start the timer and initialize the summation array + if (this->m_timer != NULL) { + // start the timer + this->m_timer->start(); + + // initialize the summation array + this->initSummationArray(); + } + } + + // constructor + GroveEarbudSensor::GroveEarbudSensor(PinName interrupt_pin,RawSerial *pc) { + _grove_earbud_sensor_instance = this; + this->m_rx = new InterruptIn(interrupt_pin); + this->m_pc = pc; + this->m_sub = 0; + this->m_counter = 0; + this->m_data_effect = true; + this->m_cb_fn = NULL; + this->m_cb_data = NULL; + this->m_heartrate = HEARTRATE_OFF; + this->m_timer = new Timer(); + this->m_internal_interrupt_instance = true; // register the interrupt handler if (this->m_rx != NULL) this->m_rx->rise(&__grove_earbud_sensor_interrupt); @@ -59,6 +87,7 @@ // destructor GroveEarbudSensor::~GroveEarbudSensor() { if (this->m_timer != NULL) delete this->m_timer; + if (this->m_internal_interrupt_instance == true && this->m_rx != NULL) delete this->m_rx; } // initialize the summation array