Reversion for IoT con

Dependencies:   MAX30205 max32630fthr USBDevice

Committer:
phonemacro
Date:
Tue May 15 19:13:28 2018 +0000
Revision:
0:f205abc96ff9
Child:
1:a61d9a05e76f
Initial Commit, v1.0000.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
phonemacro 0:f205abc96ff9 1 /*******************************************************************************
phonemacro 0:f205abc96ff9 2 * Copyright (C) 2018 Maxim Integrated Products, Inc., All Rights Reserved.
phonemacro 0:f205abc96ff9 3 *
phonemacro 0:f205abc96ff9 4 * Permission is hereby granted, free of charge, to any person obtaining a
phonemacro 0:f205abc96ff9 5 * copy of this software and associated documentation files (the "Software"),
phonemacro 0:f205abc96ff9 6 * to deal in the Software without restriction, including without limitation
phonemacro 0:f205abc96ff9 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
phonemacro 0:f205abc96ff9 8 * and/or sell copies of the Software, and to permit persons to whom the
phonemacro 0:f205abc96ff9 9 * Software is furnished to do so, subject to the following conditions:
phonemacro 0:f205abc96ff9 10 *
phonemacro 0:f205abc96ff9 11 * The above copyright notice and this permission notice shall be included
phonemacro 0:f205abc96ff9 12 * in all copies or substantial portions of the Software.
phonemacro 0:f205abc96ff9 13 *
phonemacro 0:f205abc96ff9 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
phonemacro 0:f205abc96ff9 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
phonemacro 0:f205abc96ff9 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
phonemacro 0:f205abc96ff9 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
phonemacro 0:f205abc96ff9 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
phonemacro 0:f205abc96ff9 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
phonemacro 0:f205abc96ff9 20 * OTHER DEALINGS IN THE SOFTWARE.
phonemacro 0:f205abc96ff9 21 *
phonemacro 0:f205abc96ff9 22 * Except as contained in this notice, the name of Maxim Integrated
phonemacro 0:f205abc96ff9 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
phonemacro 0:f205abc96ff9 24 * Products, Inc. Branding Policy.
phonemacro 0:f205abc96ff9 25 *
phonemacro 0:f205abc96ff9 26 * The mere transfer of this software does not imply any licenses
phonemacro 0:f205abc96ff9 27 * of trade secrets, proprietary technology, copyrights, patents,
phonemacro 0:f205abc96ff9 28 * trademarks, maskwork rights, or any other form of intellectual
phonemacro 0:f205abc96ff9 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
phonemacro 0:f205abc96ff9 30 * ownership rights.
phonemacro 0:f205abc96ff9 31 *******************************************************************************
phonemacro 0:f205abc96ff9 32 */
phonemacro 0:f205abc96ff9 33 #include "mbed.h"
phonemacro 0:f205abc96ff9 34 #include "max32630fthr.h"
phonemacro 0:f205abc96ff9 35 #include "USBSerial.h"
phonemacro 0:f205abc96ff9 36 #include "MAX30205.h"
phonemacro 0:f205abc96ff9 37
phonemacro 0:f205abc96ff9 38 MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3);
phonemacro 0:f205abc96ff9 39
phonemacro 0:f205abc96ff9 40 // Virtual serial port over USB
phonemacro 0:f205abc96ff9 41 USBSerial microUSB;
phonemacro 0:f205abc96ff9 42
phonemacro 0:f205abc96ff9 43 DigitalOut rLED(LED1);
phonemacro 0:f205abc96ff9 44 DigitalOut gLED(LED2);
phonemacro 0:f205abc96ff9 45 DigitalOut bLED(LED3);
phonemacro 0:f205abc96ff9 46
phonemacro 0:f205abc96ff9 47 //Get I2C instance
phonemacro 0:f205abc96ff9 48 I2C i2cBus(I2C1_SDA, I2C1_SCL);
phonemacro 0:f205abc96ff9 49
phonemacro 0:f205abc96ff9 50 //Get temp sensor instance
phonemacro 0:f205abc96ff9 51 MAX30205 bodyTempSensor(i2cBus, (0x90 >> 1));
phonemacro 0:f205abc96ff9 52
phonemacro 0:f205abc96ff9 53 // main() runs in its own thread in the OS
phonemacro 0:f205abc96ff9 54 // (note the calls to Thread::wait below for delays)
phonemacro 0:f205abc96ff9 55
phonemacro 0:f205abc96ff9 56 /**
phonemacro 0:f205abc96ff9 57 * @brief Sample main program for MAX30205
phonemacro 0:f205abc96ff9 58 * @version 1.0000.0
phonemacro 0:f205abc96ff9 59 *
phonemacro 0:f205abc96ff9 60 * @details Sample main program for MAX30205.
phonemacro 0:f205abc96ff9 61 * The prints are sent to the terminal window (9600, 8n1).
phonemacro 0:f205abc96ff9 62 * The program initially flashes yellow once, then it
phonemacro 0:f205abc96ff9 63 * blinks green if it's able to communicate with
phonemacro 0:f205abc96ff9 64 * the MAX30205, otherwise, it blinks red.
phonemacro 0:f205abc96ff9 65 * The temperature is read out every half second.
phonemacro 0:f205abc96ff9 66 * To run the program, drag and drop the .bin file into the
phonemacro 0:f205abc96ff9 67 * DAPLINK folder. After it finishes flashing, cycle the power or
phonemacro 0:f205abc96ff9 68 * reset the Pegasus after flashing by pressing the button on
phonemacro 0:f205abc96ff9 69 * the Pegasus next to the battery connector or the button
phonemacro 0:f205abc96ff9 70 * on the MAXREFDES100HDK.
phonemacro 0:f205abc96ff9 71 */
phonemacro 0:f205abc96ff9 72
phonemacro 0:f205abc96ff9 73 int main()
phonemacro 0:f205abc96ff9 74 {
phonemacro 0:f205abc96ff9 75 int32_t ret;
phonemacro 0:f205abc96ff9 76 uint16_t hystValue = 0;
phonemacro 0:f205abc96ff9 77 uint16_t temperatureValue;
phonemacro 0:f205abc96ff9 78 uint32_t expandTemperatureValue=0;
phonemacro 0:f205abc96ff9 79 float Celsius;
phonemacro 0:f205abc96ff9 80
phonemacro 0:f205abc96ff9 81 gLED = LED_ON;
phonemacro 0:f205abc96ff9 82 rLED = LED_ON; // init LED to yellow
phonemacro 0:f205abc96ff9 83 bLED = LED_OFF;
phonemacro 0:f205abc96ff9 84 wait(0.05);
phonemacro 0:f205abc96ff9 85
phonemacro 0:f205abc96ff9 86 printf("Example program for MAX20305.\r\n");
phonemacro 0:f205abc96ff9 87 ret = bodyTempSensor.readTHYST(hystValue);
phonemacro 0:f205abc96ff9 88 if (ret != 0) {
phonemacro 0:f205abc96ff9 89 printf("Communications to MAX20305 Failed: ret=%d, Thyst=0x%04X\r\n",ret, hystValue);
phonemacro 0:f205abc96ff9 90 rLED = LED_ON;
phonemacro 0:f205abc96ff9 91 }
phonemacro 0:f205abc96ff9 92
phonemacro 0:f205abc96ff9 93 while(true) {
phonemacro 0:f205abc96ff9 94 ret=bodyTempSensor.readTemperature(temperatureValue);
phonemacro 0:f205abc96ff9 95 if(!ret)
phonemacro 0:f205abc96ff9 96 {
phonemacro 0:f205abc96ff9 97 expandTemperatureValue = (uint32_t)temperatureValue;
phonemacro 0:f205abc96ff9 98 Celsius = bodyTempSensor.toCelsius(expandTemperatureValue);
phonemacro 0:f205abc96ff9 99 printf("The temperature is %f Celsius, ",Celsius);
phonemacro 0:f205abc96ff9 100 printf("%f Fahrenheit\r\n",bodyTempSensor.toFahrenheit(Celsius));
phonemacro 0:f205abc96ff9 101
phonemacro 0:f205abc96ff9 102 rLED = LED_OFF;
phonemacro 0:f205abc96ff9 103 gLED = !gLED; // blink the green red
phonemacro 0:f205abc96ff9 104 bLED = LED_OFF;
phonemacro 0:f205abc96ff9 105 } else {
phonemacro 0:f205abc96ff9 106 rLED = !rLED; // blink the LED red
phonemacro 0:f205abc96ff9 107 gLED = LED_OFF;
phonemacro 0:f205abc96ff9 108 bLED = LED_OFF;
phonemacro 0:f205abc96ff9 109 }
phonemacro 0:f205abc96ff9 110 wait(0.5);
phonemacro 0:f205abc96ff9 111
phonemacro 0:f205abc96ff9 112 }
phonemacro 0:f205abc96ff9 113
phonemacro 0:f205abc96ff9 114 }
phonemacro 0:f205abc96ff9 115