Sog Yang / AS7000
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers AS7000.h Source File

AS7000.h

00001 #ifndef AS7000_H
00002 #define AS7000_H
00003 
00004 #include "mbed.h"
00005 #define AS7000Address 0x60
00006 //Register definitions
00007 #define AS7000_STARTUP  0x04 //4
00008 #define HR_ONLY         0x08 //8
00009 #define HR_ONLY_LEN     0x07 //7
00010 #define HR_REG          0x12 //18
00011 #define HR_LEN          21
00012 
00013 typedef struct{
00014   uint8_t  transaction_id;
00015   uint8_t  status;
00016   uint8_t  hreat_rate;
00017   uint8_t  signal_QA;
00018   uint16_t LED_current;
00019   uint8_t  SYNC;
00020   uint8_t  startup_flag;
00021   bool     contact_detected;
00022 }as7000_t;
00023 
00024 
00025 
00026 
00027 /** Class for operating AMS AS7000 sensor over I2C **/
00028 class AS7000 
00029 { 
00030 public: 
00031 
00032 /** Create AS7000 instance **/
00033     AS7000(PinName SDA, PinName SCL); 
00034     
00035     void gpio_init(void);
00036     void enable   (void);///< Heart Rate Sensor Enbable API,it include startup senario
00037     void startup  (void);
00038     void hr_only  (void);///< Hreat Rate Sensor sensing and data
00039     void update (void);
00040     as7000_t hrm;  
00041 
00042     
00043     private:    
00044         I2C _i2c;
00045         char rx,tx[2],address;
00046         char rawdata[22];
00047         char hreat_rate;
00048         char startup_flag;
00049         
00050 void readchar(char location){
00051     tx[0] = location;
00052     _i2c.write(address,tx,1,true);
00053     _i2c.read(address,&rx,1,false);
00054 }
00055 
00056 void writechar(char location, char value){
00057     tx[0] = location;
00058     tx[1] = value;
00059     _i2c.write(address,tx,2);
00060 }
00061     };
00062 #endif