Lucas Lim / Mbed 2 deprecated HSP_Temperature_Barometer_CS3237

Dependencies:   mbed

Revision:
21:de62f413b500
Parent:
20:652f0bf256bd
--- a/main.cpp	Fri Aug 23 16:18:23 2019 +0000
+++ b/main.cpp	Sun Aug 25 08:26:00 2019 +0000
@@ -1,33 +1,29 @@
 #include "mbed.h"
 #include "MAX14720.h"
 #include "MAX30205.h"
-#include "MAX30101.h"
 #include "BMP280.h"
-#include "MAX30001.h"
-#include "QuadSpiInterface.h"
-#include "S25FS512.h"
+#include "USBSerial.h"
+//#include "MAX30001.h"
+//#include "QuadSpiInterface.h"
+//#include "S25FS512.h"
+//#include "MAX30101.h"
 
 //Define all I2C addresses
 #define MAX30205_I2C_SLAVE_ADDR_TOP (0x92)
 #define MAX30205_I2C_SLAVE_ADDR_BOTTOM (0x90)
 #define MAX14720_I2C_SLAVE_ADDR (0x54)
-#define MAX30101_I2C_SLAVE_ADDR (0xAE)
 #define BMP280_I2C_SLAVE_ADDR (0xEC)
-#define MAX30001_
+
 
 #define HVOUT_VOLTAGE 4500 // set to 4500 mV
 
+ // Define with Maxim VID and a Maxim assigned PID, set to version 0x0001 and non-blocking
+ USBSerial usbSerial(0x0b6a, 0x0100, 0x0001, false);
+ 
 // I2C Masters
 I2C i2c1(I2C1_SDA, I2C1_SCL);
 I2C i2c2(I2C2_SDA, I2C2_SCL);
 
-/// SPI Master 0 with SPI0_SS for use with MAX30001
-SPI spi(SPI0_MOSI, SPI0_MISO, SPI0_SCK, SPI0_SS); // used by MAX30001
-/// SPI Master 1
-QuadSpiInterface quadSpiInterface(SPI1_MOSI, SPI1_MISO, SPI1_SCK,
-                                  SPI1_SS); // used by S25FS512
-
-
 // Top local Temperature Sensor
 MAX30205 MAX30205_top(&i2c1, MAX30205_I2C_SLAVE_ADDR_TOP);
 
@@ -40,16 +36,8 @@
 //PMIC
 MAX14720 max14720(&i2c2,MAX14720_I2C_SLAVE_ADDR);
 
-// Optical Oximeter
-MAX30101 max30101(&i2c2, MAX30101_I2C_SLAVE_ADDR);
-
-/// External Flash
-S25FS512 s25fs512(&quadSpiInterface);
-
-/// ECG device
-MAX30001 max30001(&spi);
-InterruptIn max30001_InterruptB(P3_6);
-InterruptIn max30001_Interrupt2B(P4_5);
+///// External Flash
+//S25FS512 s25fs512(&quadSpiInterface);
 
 /// PWM used as fclk for the MAX30001
 PwmOut pwmout(P1_7);
@@ -57,9 +45,6 @@
 
 DigitalOut led(LED1);
 
-//Serial 
-Serial pc(USBTX, USBRX);
-InterruptIn Button(SW1);
 
 void turnOff()
 {
@@ -81,37 +66,6 @@
     // Initialise the BMP280
     bmp280_pres.init(BMP280::OVERSAMPLING_X16_P, BMP280::OVERSAMPLING_X2_T, BMP280::FILT_4, BMP280::NORMAL_MODE, BMP280::T_62_5);
 
-    // MAX30001
-    printf("Init MAX30001 callbacks, interrupts...\n");
-    fflush(stdout);
-    max30001_InterruptB.disable_irq();
-    max30001_Interrupt2B.disable_irq();
-    max30001_InterruptB.mode(PullUp);
-    max30001_InterruptB.fall(&MAX30001::Mid_IntB_Handler);
-    max30001_Interrupt2B.mode(PullUp);
-    max30001_Interrupt2B.fall(&MAX30001::Mid_Int2B_Handler);
-    max30001_InterruptB.enable_irq();
-    max30001_Interrupt2B.enable_irq();
-    max30001.AllowInterrupts(1);
-    // Configuring the FCLK for the ECG, set to 32.768KHZ
-    printf("Init MAX30001 PWM...\n");
-    fflush(stdout);
-    //pwmout.period_us(31);      
-    //pwmout.write(0.5);          // 0-1 is 0-100%, 0.5 = 50% duty cycle.
-    max30001.FCLK_MaximOnly();    // mbed does not provide the resolution necessary, so for now we have a specific solution...
-    max30001.sw_rst(); // Do a software reset of the MAX30001
-    max30001.INT_assignment(MAX30001::MAX30001_INT_B,    MAX30001::MAX30001_NO_INT,   MAX30001::MAX30001_NO_INT,  //  en_enint_loc,      en_eovf_loc,   en_fstint_loc,
-                                     MAX30001::MAX30001_INT_2B,   MAX30001::MAX30001_INT_2B,   MAX30001::MAX30001_NO_INT,  //  en_dcloffint_loc,  en_bint_loc,   en_bovf_loc,
-                                     MAX30001::MAX30001_INT_2B,   MAX30001::MAX30001_INT_2B,   MAX30001::MAX30001_NO_INT,  //  en_bover_loc,      en_bundr_loc,  en_bcgmon_loc,
-                                     MAX30001::MAX30001_INT_B,    MAX30001::MAX30001_NO_INT,   MAX30001::MAX30001_NO_INT,  //  en_pint_loc,       en_povf_loc,   en_pedge_loc,
-                                     MAX30001::MAX30001_INT_2B,   MAX30001::MAX30001_INT_B,    MAX30001::MAX30001_NO_INT,  //  en_lonint_loc,     en_rrint_loc,  en_samp_loc,
-                                     MAX30001::MAX30001_INT_ODNR, MAX30001::MAX30001_INT_ODNR);                            //  intb_Type,         int2b_Type)
-    max30001.onDataAvailable(&StreamPacketUint32);
-
-
-
-    // Use the POR configuration register values
-    
     //Temperature sensor variables
     uint16_t rawTemp_top;
     uint16_t rawTemp_bottom ;
@@ -122,24 +76,6 @@
     char bmp280_rawData = 0;
     float Temp_degC, Press_Pa, Press_Bar;
     
-    //optical sensor variables
-    uint8_t fifo_waterlevel_mark;
-    uint8_t sample_avg;
-    uint8_t sample_rate;
-    uint8_t pulse_width;
-    uint8_t fifo_waterlevel_mark1;
-    uint8_t sample_avg1;
-    uint8_t sample_rate1;
-    uint8_t pulse_width1;
-    uint8_t fifo_waterlevel_mark2;
-    uint8_t sample_avg2;
-    uint8_t sample_rate2;
-    uint8_t pulse_width2;
-    uint8_t red_led_current, green_led_current;
-    uint8_t ir_led_current;
-    uint8_t slot_1, slot_2, slot_3, slot_4;
-    
-    wait(2);
     
     //Endless loop
     while(1) 
@@ -160,42 +96,18 @@
         fahrenheit_top = MAX30205_top.toFahrenheit(celsius_top);
         fahrenheit_bottom = MAX30205_bottom.toFahrenheit(celsius_bottom);
         
-        
         /* Barometric Sensor Settings */
     
         Press_Bar = Press_Pa / 100000;
-        
-        /* Optical Sensor settings */
-        
-        
 
         /* Printing various sensor values */
-        pc.printf("***** MAX30205 Temperature Sensor Reading *****\n\r");
-        pc.printf("Top Temperature: %.2f\370 C\n\rBottom Temperature: %.2f\370 C \n\rTop Temperature in Farenheit: %.2f\370 F\n\rBottom Temperature in Farenheit %.2f\370 F\n\n\r", celsius_top, celsius_bottom, fahrenheit_top, fahrenheit_bottom);
-        
-        pc.printf("***** BMP280 Barometric Sensor Reading *****\n\r");
-        pc.printf("Temp_degC : %.2f , Press_Bar is %.2f , Press_pa is %.2f\n\n\r",Temp_degC, Press_Bar, Press_Pa);
-        
-        max30101.HRmode_init(fifo_waterlevel_mark1,sample_avg1,sample_rate1,pulse_width1,red_led_current);             
-        pc.printf("***** MAX30101 Optical Sensor Reading [HR mode]*****\n\r");
-        pc.printf("Optical Sensor Value [fifo_waterlevel_mark: %d]\n\rOptical Sensor Value[sample_avg: %d]\n\rOptical Sensor Value[pulse_width: %d]\n\n\r", fifo_waterlevel_mark,sample_avg,pulse_width);
-        max30101.HRmode_stop();
+        usbSerial.printf("***** MAX30205 Temperature Sensor Reading *****\n\r");
+        usbSerial.printf("Top Temperature: %.2f\370 C\n\rBottom Temperature: %.2f\370 C \n\rTop Temperature in Farenheit: %.2f\370 F\n\rBottom Temperature in Farenheit %.2f\370 F\n\n\r", celsius_top, celsius_bottom, fahrenheit_top, fahrenheit_bottom);
         
-        max30101.SpO2mode_init(fifo_waterlevel_mark, sample_avg, sample_rate, pulse_width, red_led_current, ir_led_current);
-        pc.printf("***** MAX30101 Optical Sensor Reading [SpO2 mode]*****\n\r");
-        pc.printf("Optical Sensor Value [fifo_waterlevel_mark: %d]\n\rOptical Sensor Value[sample_avg: %d]\n\rOptical Sensor Value[pulse_width: %d]\n\n\r", fifo_waterlevel_mark,sample_avg,pulse_width);
-        max30101.SpO2mode_stop();
+        usbSerial.printf("***** BMP280 Barometric Sensor Reading *****\n\r");
+        usbSerial.printf("Temp_degC : %.2f , Press_Bar is %.2f , Press_pa is %.2f\n\n\r",Temp_degC, Press_Bar, Press_Pa);
         
- //       max30101.Multimode_init(fifo_waterlevel_mark2,sample_avg2,sample_rate2,pulse_width2,red_led_current, ir_led_current,green_led_current,slot_1,slot_2,slot_3,slot_4);
-//        wait(0.5);
-//        
-//        pc.printf("***** MAX30101 Optical Sensor Reading [Multi mode]*****\n\r");
-//        pc.printf("Optical Sensor Value [fifo_waterlevel_mark: %d]\n\rOptical Sensor Value[sample_avg: %d]\n\rOptical Sensor Value[pulse_width: %d]\n\rslot1: %d, slot2: %d, slot3: %d, slot4: %d\n\n\r", fifo_waterlevel_mark,sample_avg,pulse_width, slot_1, slot_2, slot_3, slot_4);
-//        
-    
-        //pc.printf("***** ECG Sensor Reading *****\n\r");
-        
-        pc.printf("-------------------------------------------------\n\n\n\r");
+        usbSerial.printf("-------------------------------------------------\n\n\n\r");
 
         wait(0.2);