Example host software for the Maxim Integrated MAX30205 Human Body Temperature Sensor. Hosted on the MAX32630FTHR. (v.1.0000.0)

Dependencies:   MAX30205 USBDevice max32630fthr

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /*******************************************************************************
00002 * Copyright (C) 2018 Maxim Integrated Products, Inc., All Rights Reserved.
00003 *
00004 * Permission is hereby granted, free of charge, to any person obtaining a
00005 * copy of this software and associated documentation files (the "Software"),
00006 * to deal in the Software without restriction, including without limitation
00007 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00008 * and/or sell copies of the Software, and to permit persons to whom the
00009 * Software is furnished to do so, subject to the following conditions:
00010 *
00011 * The above copyright notice and this permission notice shall be included
00012 * in all copies or substantial portions of the Software.
00013 *
00014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00015 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00016 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00017 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
00018 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00019 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00020 * OTHER DEALINGS IN THE SOFTWARE.
00021 *
00022 * Except as contained in this notice, the name of Maxim Integrated
00023 * Products, Inc. shall not be used except as stated in the Maxim Integrated
00024 * Products, Inc. Branding Policy.
00025 *
00026 * The mere transfer of this software does not imply any licenses
00027 * of trade secrets, proprietary technology, copyrights, patents,
00028 * trademarks, maskwork rights, or any other form of intellectual
00029 * property whatsoever. Maxim Integrated Products, Inc. retains all
00030 * ownership rights.
00031 *******************************************************************************
00032 */
00033 #include "mbed.h"
00034 #include "max32630fthr.h"
00035 #include "USBSerial.h"
00036 #include "MAX30205.h"
00037 
00038 MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3);
00039 
00040 // Virtual serial port over USB
00041 USBSerial microUSB; 
00042 
00043 DigitalOut rLED(LED1);
00044 DigitalOut gLED(LED2);
00045 DigitalOut bLED(LED3);
00046 
00047 //Get I2C instance
00048 I2C i2cBus(I2C1_SDA, I2C1_SCL);
00049  
00050 //Get temp sensor instance
00051 MAX30205 bodyTempSensor(i2cBus, (0x90 >> 1));
00052 
00053 // main() runs in its own thread in the OS
00054 // (note the calls to Thread::wait below for delays)
00055 
00056 /**
00057 * @brief Sample main program for MAX30205
00058 * @version 1.0000.0
00059 *
00060 * @details Sample main program for MAX30205.
00061 * The prints are sent to the terminal window (9600, 8n1).
00062 * The program initially flashes yellow once, then it
00063 * blinks green if it's able to communicate with
00064 * the MAX30205, otherwise, it blinks red.
00065 * The temperature is read out every half second.
00066 * To run the program, drag and drop the .bin file into the 
00067 * DAPLINK folder. After it finishes flashing, cycle the power or 
00068 * reset the Pegasus after flashing by pressing the button on
00069 * the Pegasus next to the battery connector or the button
00070 * on the MAXREFDES100HDK.
00071 */
00072 
00073 int main()
00074 {
00075     int32_t ret;
00076     uint16_t hystValue = 0;
00077     uint16_t temperatureValue;
00078     uint32_t expandTemperatureValue=0;
00079     float Celsius;
00080 
00081     gLED = LED_ON;
00082     rLED = LED_ON;  // init LED to yellow
00083     bLED = LED_OFF;
00084     wait(0.05);
00085     
00086     printf("Example program for MAX20305.\r\n");
00087     ret = bodyTempSensor.readTHYST(hystValue);
00088     if (ret != 0) {
00089         printf("Communications to MAX20305 Failed: ret=%d, Thyst=0x%04X\r\n",ret, hystValue);
00090         rLED = LED_ON;
00091     }
00092  
00093     while(true) {
00094         ret=bodyTempSensor.readTemperature(temperatureValue);
00095         if(!ret)
00096         {
00097             expandTemperatureValue = (uint32_t)temperatureValue;
00098             Celsius = bodyTempSensor.toCelsius(expandTemperatureValue);
00099             printf("The temperature is %f Celsius, ",Celsius);
00100             printf("%f Fahrenheit\r\n",bodyTempSensor.toFahrenheit(Celsius));
00101 
00102             rLED = LED_OFF;
00103             gLED = !gLED;  // blink the green red
00104             bLED = LED_OFF;
00105         } else {
00106             rLED = !rLED;  // blink the LED red
00107             gLED = LED_OFF;
00108             bLED = LED_OFF;
00109         }
00110         wait(0.5);
00111     
00112     }
00113 
00114 }
00115