Maxim Integrated's IoT development kit

Dependencies:   MAX30101 MAX30003 MAX113XX_Pixi MAX30205 max32630fthr USBDevice

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers max30205_app.cpp Source File

max30205_app.cpp

00001 /*
00002  * max30205_app.c
00003  *
00004  *  Created on: Jun 20, 2018
00005  *      Author: Mahir.Ozturk
00006  */
00007 #include <mbed.h>
00008 #include "max30205_app.h"
00009 #include "MAX30205.h"
00010 
00011 bool max30205_config(MAX30205 &temp_sensor){
00012 
00013     int rc = 0;
00014 
00015     MAX30205::Configuration_u temp_cfg;
00016     temp_cfg.all = 0;
00017     temp_cfg.bits.shutdown = 1;     // Shutdown mode
00018     temp_cfg.bits.comp_int = 1;     // Interrupt mode
00019     temp_cfg.bits.os_polarity = 0;  // Active low OS
00020     temp_cfg.bits.fault_queue = 1;  // Two faults for OS condition
00021     temp_cfg.bits.data_format = 0;  // Normal data format
00022     temp_cfg.bits.timeout = 0;      // I2C timeout reset enabled
00023     temp_cfg.bits.one_shot = 0;     // Start with one-shot = 0
00024 
00025     rc = temp_sensor.writeConfiguration(temp_cfg);  // Write config to MAX30205
00026 
00027     return rc;
00028 }
00029 
00030 void max30205_reader_task(struct max30205_reader_task_args *args)
00031 {
00032     MAX30205 max30205_temp_sensor(args->i2cBus, 0x48);  /* New MAX30205 on i2cBus */
00033 
00034     int rc = max30205_config(max30205_temp_sensor);   // Configure sensor, return 0 on success
00035 
00036     MAX30205::Configuration_u temp_cfg;
00037     uint16_t rawTemperatureRead;
00038     float temperature;
00039 
00040     temp_cfg.all = 0;
00041 
00042     printf("Starting MAX30205 Temperature Demo Application...\r\n");
00043 
00044     while (1) {
00045         if (rc == 0) {
00046             /* Send one-shot cmd to begin conversion */
00047             temp_cfg.bits.one_shot = 1;
00048             rc = max30205_temp_sensor.writeConfiguration(temp_cfg);
00049 
00050             Thread::wait(50);
00051 
00052             /* Read the temperature data */
00053             rc = max30205_temp_sensor.readTemperature(rawTemperatureRead);
00054 
00055             /* Convert temp data to Celsius */
00056             temperature = max30205_temp_sensor.toCelsius(rawTemperatureRead);
00057 
00058             bleGattAttrWrite(args->gatt, (uint8_t *)&temperature, sizeof(temperature));
00059             printf("Temperature is %2.3f deg. C\r\n", temperature);
00060 
00061             Thread::wait(args->notify_period_sec * 1000);
00062 
00063         } else {
00064             printf("Something went wrong, check the I2C bus and power connections...\r\n");
00065 
00066             return;
00067         }
00068     }
00069 }
00070 
00071