Optical Sensor for Heart Rate Monitor IC
Diff: BH1790GLC.h
- Revision:
- 3:11ba607ded8d
- Parent:
- 2:eb95a49c8a29
--- a/BH1790GLC.h Sat Dec 07 19:41:58 2019 +0000 +++ b/BH1790GLC.h Mon Dec 16 20:43:53 2019 +0000 @@ -22,7 +22,104 @@ /** Example: @code +#include "mbed.h" +#include "BH1790GLC.h" +BH1790GLC myBH1790GLC ( I2C_SDA, I2C_SCL, BH1790GLC::BH1790GLC_ADDRESS, 400000 ); +Serial pc ( USBTX, USBRX ); + +DigitalOut myled ( LED1 ); +Ticker newReading; + + +//@brief Variables. +uint32_t myState = 0; + +//@brief FUNCTION PROTOTYPES +void changeDATA ( void ); + + + +//@brief FUNCTION FOR APPLICATION MAIN ENTRY. +int main() +{ + BH1790GLC::BH1790GLC_data_t BH1790GLC_data; + BH1790GLC::BH1790GLC_status_t aux; + + pc.baud ( 115200 ); + + myled = 1; + wait(3); + myled = 0; + + // Get Manufacturer IDs + aux = myBH1790GLC.BH1790GLC_GetManufacturerID ( &BH1790GLC_data ); + + // Get part IDs + aux = myBH1790GLC.BH1790GLC_GetPartID ( &BH1790GLC_data ); + pc.printf( "Manufacturer ID: %x (0xE0) | Part ID: %x (0x0D)\r\n", BH1790GLC_data.manufacturer_id, BH1790GLC_data.part_id ); + + + // Performs a software reset + aux = myBH1790GLC.BH1790GLC_SoftReset (); + + // Configure the system control setting + BH1790GLC_data.rdy = BH1790GLC::MEAS_CONTROL1_RDY_OSC_BLOCK_ACTIVE; + BH1790GLC_data.led_lighting_freq = BH1790GLC::MEAS_CONTROL1_LED_LIGHTING_FREQ_64HZ_MODE; + BH1790GLC_data.rcycle = BH1790GLC::MEAS_CONTROL1_RCYCLE_32HZ_MODE; + + // Configure the measurement control setting + BH1790GLC_data.led_en = BH1790GLC::MEAS_CONTROL2_LED_EN_0; + BH1790GLC_data.led_on_time = BH1790GLC::MEAS_CONTROL2_LED_ON_TIME_0_6_MS_MODE; + BH1790GLC_data.led_current = BH1790GLC::MEAS_CONTROL2_LED_CURRENT_1_MA_MODE; + + // Start measurement + aux = myBH1790GLC.BH1790GLC_StartMeasurement ( BH1790GLC_data ); + + newReading.attach( &changeDATA, 1 ); // the address of the function to be attached ( changeDATA ) and the interval ( 1s ) + + // Let the callbacks take care of everything + while(1) { + sleep(); + + myled = 1; + + if ( myState == 1 ) { + // Get the raw DATAOUT values: DATAOUT_LEDOFF and DATAOUT_LEDON + aux = myBH1790GLC.BH1790GLC_GetRawDataOut ( &BH1790GLC_data ); + + // Transmit result over the UART + pc.printf( "LED OFF: %x | LED ON: %x\r\n", BH1790GLC_data.dataOut_LED_OFF, BH1790GLC_data.dataOut_LED_ON ); + + myState = 0; // Reset the variable + } + + myled = 0; + } +} + + +// @brief changeDATA ( void ) +// +// @details It changes myState variable +// +// @param[in] N/A +// +// @param[out] N/A. +// +// +// @return N/A. +// +// +// @author Manuel Caballero +// @date 07/December/2019 +// @version 07/December/2019 The ORIGIN +// @pre N/A +// @warning N/A. +void changeDATA ( void ) +{ + myState = 1; +} @endcode */ @@ -208,52 +305,52 @@ /** * @brief INTERNAL CONSTANTS */ - typedef enum { - BH1790GLC_SUCCESS = 0U, /*!< I2C communication success */ - BH1790GLC_FAILURE = 1U, /*!< I2C communication failure */ - I2C_SUCCESS = 0U /*!< I2C communication was fine */ - } BH1790GLC_status_t; + typedef enum { + BH1790GLC_SUCCESS = 0U, /*!< I2C communication success */ + BH1790GLC_FAILURE = 1U, /*!< I2C communication failure */ + I2C_SUCCESS = 0U /*!< I2C communication was fine */ + } BH1790GLC_status_t; - /** Create an BH1790GLC object connected to the specified I2C pins. - * - * @param sda I2C data pin - * @param scl I2C clock pin - * @param addr I2C slave address - * @param freq I2C frequency - */ - BH1790GLC ( PinName sda, PinName scl, uint32_t addr, uint32_t freq ); + /** Create an BH1790GLC object connected to the specified I2C pins. + * + * @param sda I2C data pin + * @param scl I2C clock pin + * @param addr I2C slave address + * @param freq I2C frequency + */ + BH1790GLC ( PinName sda, PinName scl, uint32_t addr, uint32_t freq ); - /** Delete BH1790GLC object. - */ - ~BH1790GLC(); + /** Delete BH1790GLC object. + */ + ~BH1790GLC(); - /** It gets the manufacturer ID. - */ - BH1790GLC_status_t BH1790GLC_GetManufacturerID ( BH1790GLC_data_t* myManufacturerID ); + /** It gets the manufacturer ID. + */ + BH1790GLC_status_t BH1790GLC_GetManufacturerID ( BH1790GLC_data_t* myManufacturerID ); - /** It gets the part ID. - */ - BH1790GLC_status_t BH1790GLC_GetPartID ( BH1790GLC_data_t* myPartID ); + /** It gets the part ID. + */ + BH1790GLC_status_t BH1790GLC_GetPartID ( BH1790GLC_data_t* myPartID ); - /** It performs a soft reset. - */ - BH1790GLC_status_t BH1790GLC_SoftReset ( void ); + /** It performs a soft reset. + */ + BH1790GLC_status_t BH1790GLC_SoftReset ( void ); - /** It triggers a new measurement sample. - */ - BH1790GLC_status_t BH1790GLC_StartMeasurement ( BH1790GLC_data_t myConfData ); + /** It triggers a new measurement sample. + */ + BH1790GLC_status_t BH1790GLC_StartMeasurement ( BH1790GLC_data_t myConfData ); - /** It gets the DATAOUT ( DATAOUT_LEDOFF and DATAOUT_LEDON data ). Raw data value. - */ - BH1790GLC_status_t BH1790GLC_GetRawDataOut ( BH1790GLC_data_t* myRawDataOut ); + /** It gets the DATAOUT ( DATAOUT_LEDOFF and DATAOUT_LEDON data ). Raw data value. + */ + BH1790GLC_status_t BH1790GLC_GetRawDataOut ( BH1790GLC_data_t* myRawDataOut ); - private: - I2C _i2c; - uint32_t _BH1790GLC_Addr; - }; +private: + I2C _i2c; + uint32_t _BH1790GLC_Addr; +}; #endif