Library for the Grove Earbud Heartrate Sensor
Dependents: BLE_Police_HRM_Earbud df-2014-salesforce-hrm-k64f BLE_HeartRate_ppm emoSound ... more
Revision 11:30d8d0a456f3, committed 2015-03-11
- Comitter:
- ansond
- Date:
- Wed Mar 11 20:27:28 2015 +0000
- Parent:
- 10:db3dea613e09
- Child:
- 12:8687d42d6798
- Commit message:
- added secondary constructor to internalize the InterruptIn() parameter if desired.
Changed in this revision
GroveEarbudSensor.cpp | Show annotated file Show diff for this revision Revisions of this file |
GroveEarbudSensor.h | Show annotated file Show diff for this revision Revisions of this file |
--- 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
--- a/GroveEarbudSensor.h Thu Dec 18 05:41:14 2014 +0000 +++ b/GroveEarbudSensor.h Wed Mar 11 20:27:28 2015 +0000 @@ -106,6 +106,7 @@ GroveEarbudSensorCallback *m_cb_fn; void *m_cb_data; Timer *m_timer; + bool m_internal_interrupt_instance; public: /** @@ -116,6 +117,13 @@ GroveEarbudSensor(InterruptIn *rx,RawSerial *pc = NULL); /** + constructor for internalized InterruptIn usage + @param rx interrupt_pin InterruptIn pin name + @param pc input RawSerial instance for debugging (if NULL, no debugging output will occur in the library) + */ + GroveEarbudSensor(PinName interrupt_pin,RawSerial *pc = NULL); + + /** Default destructor */ virtual ~GroveEarbudSensor();