The HexiHeart is a demo project product that takes advantage of many of the onboard Hexiwear sensors and capabilities to create a multifunctional fitness and safety watch.
Dependencies: FXAS21002 FXOS8700 Hexi_KW40Z Hexi_OLED_SSD1351 MAXIM W25Q64FVSSIG HTU21D MPL3115A2 TSL2561
Fork of HexiHeart_Alex by
Diff: main.cpp
- Revision:
- 5:e1431272be79
- Parent:
- 4:0803151bc5e4
- Child:
- 6:84e3ba00b995
--- a/main.cpp Mon Feb 12 19:31:23 2018 +0000 +++ b/main.cpp Tue Feb 13 05:36:04 2018 +0000 @@ -13,7 +13,7 @@ #include "FXOS8700.h" // 3D Accelorometer & Mag #include "FXAS21002.h" // 3-Axis Gyroscope #include "Hexi_OLED_SSD1351.h" // OLED fuctions - // Non-Freescale HTU21D - combo temperature and Humidity +#include "HTU21D.h" // Non-Freescale HTU21D - combo temperature and Humidity #include "W25Q64FV.h" // W25Q64FVSSIG Serial Flash // Non-Freescale MPL3115A2 - pressure sensor #include "Hexi_Battery/hexi_battery.h" // Battery status @@ -64,7 +64,7 @@ void Enable_Heart_Rate(); void Disable_Heart_Rate(); void Led_Zone_Indicator(); - +void Heat_Index_Calculation(); void fall_config(uint8_t); void fall_detect(void); void fall_det_end(void); @@ -74,20 +74,21 @@ // ***************** Global variables *********************** char text_1[20]; // Text buffer - Do we need more? char display_buff[30]; //Buffer for conversion to char to display +char text[20]; // Text Buffer for dynamic value displayed bool Led_Zones = 1; bool HR_Enable = 0; bool OLED_ON = 1; // Turn OLED power on/off bool Fall_Alert = 1; // Initialize as no active alert -bool Panic_Alert = 0; // Initialize as no active alert -bool Fall_Alert_Mode = 1; // Initialize with fall alert mode on -bool Heart_Rate_Mode = 0; // Initialize with Heart rate off +bool Panic_Alert = 0; // Initialize as no active alert +bool Fall_Alert_Mode = 1; // Initialize with fall alert mode on +bool Heart_Rate_Mode = 0; // Initialize with Heart rate off float Accel_Mag=0.0; // Vector magnitude calculated from sensor data float Accel_Data[3]; // Accel Data from sensor -float Gyro_Mag=0.0; // Vector magnitude calculated from sensor data -float Gyro_Data[3]; // Gyro data from sensor -float Fall_Thresh=0.5; // Initialize Fall detect Threshold -float Impact_Thresh=3.0; // Initialize Impact detect Threshold -float Movement_Thresh=50.0; // Initialize Movement detect Threshold +float Gyro_Mag=0.0; // Vector magnitude calculated from sensor data +float Gyro_Data[3]; // Gyro data from sensor +float Fall_Thresh=0.5; // Initialize Fall detect Threshold +float Impact_Thresh=3.0; // Initialize Impact detect Threshold +float Movement_Thresh=50.0; // Initialize Movement detect Threshold uint8_t Current_Zone = 1; uint8_t Prev_Zone = 1; uint8_t Heart_Rate = 100; @@ -103,12 +104,17 @@ uint8_t HR_Zone2[2] = {HR_Zone1[1] + 1, Max_Bpm * .70}; //Heart Rate Zone 2 uint8_t HR_Zone3[2] = {HR_Zone2[1] + 1, Max_Bpm * .80}; //Heart Rate Zone 3 uint8_t HR_Zone4[2] = {HR_Zone3[1] + 1, Max_Bpm}; //Heart Rate Zone 4 +int sample_ftemp; +int sample_humid; +int heat_index; + // ***************** Define pins ***************************** FXAS21002 gyro(PTC11,PTC10); // Gyroscope SSD1351 oled(PTB22,PTB21,PTC13,PTB20,PTE6, PTD15); // SSD1351 OLED Driver (MOSI,SCLK,POWER,CS,RST,DC) FXOS8700 accel(PTC11, PTC10); // Accelorometer FXOS8700 mag(PTC11, PTC10); // Mag (same chip as Accel) //MAX30101 heart(PTB1, PTB0); //Heart Rate Chip +HTU21D temphumid(PTB1,PTB0); // HTU21D Sensor // initialize I2C bus for FXOS8700, FXAS-Gyro, MPL-Pressure I2C i2c_bus1(PTC11, PTC10); // (SDA, SCL) @@ -122,11 +128,12 @@ DigitalOut Led_clk3(PTA14); DigitalOut OLED_PWR(PTC13); // this pin turns on/off 15V to OLED display -DigitalOut Non_Free_PWR(PTB13); // this pin turns on/off non-freescale sensors (Pres/Temp/Hum/Light) +DigitalOut Non_Free_PWR(PTB13); // this pin turns on/off non-freescale sensors (Pres/Temp/Hum/Light) +DigitalOut powerEN (PTB12); // Power Enable HTU21D Sensor DigitalOut HR_PWR(PTA29); // this pin turns on/off Heart rate sensor -//DigitalIn Sw1(PTA12); //Switch 'T1' on docking station AND Led_clk1!! -//DigitalIn Sw2(PTA13); //Switch 'T2' on docking station AND Led_clk2!! -DigitalIn Sw3(PTA15); //Switch 'T3' on docking station +//DigitalIn Sw1(PTA12); //Switch 'T1' on docking station AND Led_clk1!! +//DigitalIn Sw2(PTA13); //Switch 'T2' on docking station AND Led_clk2!! +DigitalIn Sw3(PTA15); //Switch 'T3' on docking station /* Instantiate the Hexi KW40Z Driver (UART TX, UART RX) */ @@ -706,6 +713,8 @@ int main() { OLED_PWR = 1; // Turn on OLED power supply + + oled.FillScreen(COLOR_BLACK); // Clear screen // ***************** Local variables *********************** // float accel_data[3]; float accel_rms=0.0; @@ -776,6 +785,7 @@ }// end if i++; }// end while(i<20) + // wait(10); // wait 10 sec each loop, was orig half sec RED_Led = LED_ON; // Used only for diagnostic of wait command Led_clk3 = 1; // Used only for diagnostic of wait command @@ -819,9 +829,15 @@ oled.Label((uint8_t *)"Batt",35,0); // Display "Batt" at x,y oled.Label((uint8_t *)"Date",35,20); // Display "Date" at x,y oled.Label((uint8_t *)"Time",35,40); // Display "Time" at x,y - oled.Label((uint8_t *)"H.I.",10,80); // Display "H.I." at x,y +// oled.Label((uint8_t *)"H.I.",10,80); // Display "H.I." at x,y oled.Label((uint8_t *)"BT",40,80); //Display "BT" at x,y oled.Label((uint8_t *)"Menu",60,80); //Display "Menu" at x,y + + Heat_Index_Calculation(); + sprintf(text,"%i",heat_index); + oled.TextBox((uint8_t *)text,5,80,15,15); + strcpy((char *) text,"dF");oled.Label((uint8_t *)text,18,80); + if(Heart_Rate_Mode == 1) { oled.Label((uint8_t *)"BPM",35,60); // Display "H.I." at x,y } @@ -1034,6 +1050,58 @@ oled.Label((uint8_t *)"*",85,60); // "*" at x,y oled.Label((uint8_t *)" Back ",9,80); // Display "Back" at x,y // oled.Label((uint8_t *)" Enter ",59,80); //Display at x,y + + + + oled_text_properties_t textProperties = {0}; + oled.GetTextProperties(&textProperties); + + strcpy((char *) text,"Temp."); + oled.Label((uint8_t *)text,5,40); + strcpy((char *) text,"Humidity"); + oled.Label((uint8_t *)text,5,57); + strcpy((char *) text,"H.I."); + oled.Label((uint8_t *)text,5,23); + + /* Set text properties to white and right aligned for the dynamic text */ + textProperties.fontColor = COLOR_GREEN; + textProperties.alignParam = OLED_TEXT_ALIGN_RIGHT; + oled.SetTextProperties(&textProperties); + + /* Format the value */ + sprintf(text,"%i",sample_ftemp); + + /* Display time reading in 35px by 15px textbox at(x=55, y=40) */ + oled.TextBox((uint8_t *)text,55,40,15,15); //Increase textbox for more digits + + /* Display Units */ + strcpy((char *) text,"dF"); + oled.Label((uint8_t *)text,71,40); + + /* Format the value */ + sprintf(text,"%i",sample_humid); + + /* Display time reading in 35px by 15px textbox at(x=55, y=40) */ + oled.TextBox((uint8_t *)text,55,57,15,15); //Increase textbox for more digits + + /* Display Units */ + strcpy((char *) text,"%"); + oled.Label((uint8_t *)text,71,57); + + /* Set text properties to white and right aligned for the dynamic text */ + textProperties.fontColor = COLOR_BLUE; + textProperties.alignParam = OLED_TEXT_ALIGN_RIGHT; + oled.SetTextProperties(&textProperties); + + /* Format the value */ + sprintf(text,"%i",heat_index); + + /* Display time reading in 35px by 15px textbox at(x=55, y=40) */ + oled.TextBox((uint8_t *)text,55,23,15,15); //Increase textbox for more digits + + /* Display Units */ + strcpy((char *) text,"dF");oled.Label((uint8_t *)text,71,23); + break; } case 26: {//Heart Rate Config Option @@ -1665,6 +1733,29 @@ } } }//end of Led_Zone_Indicator + +/***************************************************************************** +Name: Heat_Index_Calculation() +Purpose: Calculates the heat index using the temperature and humidity sensors +Inputs: None +Returns: None +******************************************************************************/ +void Heat_Index_Calculation(){ + sample_ftemp = temphumid.sample_ftemp(); + + sample_humid = temphumid.sample_humid(); + + heat_index = -42.379 + + 2.04901523 * sample_ftemp + + 10.14333127 * sample_humid - + 0.22475541 * sample_ftemp * sample_humid - + 0.00683783 * sample_ftemp * sample_ftemp - + 0.05481717 * sample_humid * sample_humid + + 0.00122874 * sample_ftemp * sample_ftemp * sample_humid + + 0.00085282 * sample_ftemp * sample_humid * sample_humid - + 0.00000199 * sample_ftemp * sample_ftemp * sample_humid * sample_humid; +} + /***************************************************************************** Name: fall_detect() Purpose: Interupt rutine called when accelerometer IC has detected a free-fall >= 0.5g