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:
- 20:990951205fbd
- Parent:
- 19:87ab6daf98e5
- Child:
- 21:76237b62466b
diff -r 87ab6daf98e5 -r 990951205fbd main.cpp --- a/main.cpp Tue May 01 15:13:45 2018 +0000 +++ b/main.cpp Mon May 07 21:49:35 2018 +0000 @@ -562,12 +562,14 @@ } case 32: {//Turn on HR led blinking for manual demonstration hr_led.attach(&Led_Zone_Indicator, HR_LED_period); - break; + Heart_Rate_Mode = 1; + break; } case 33:{//Start heart rate simulation StartHaptic(); if(maxim == 0) { + Heart_Rate_Mode = 1; hr_led.attach(&Led_Zone_Indicator, HR_LED_period); hr_simulation.attach(&HR_Simulation, 5.0); } @@ -827,7 +829,8 @@ break; } case 32: {//End HR led used for manual demonstration - hr_led.detach(); + hr_led.detach(); + Heart_Rate_Mode = 0; RED_Led = LED_OFF; GRN_Led = LED_OFF; BLU_Led = LED_OFF; @@ -837,6 +840,7 @@ StartHaptic(); if(maxim == 0) { + Heart_Rate_Mode = 0; hr_simulation.detach(); simulation_stage = 0; hr_led.detach(); @@ -1671,7 +1675,23 @@ oled.Label((uint8_t *)text,25,80); // was "dF" at 18,80 if(Heart_Rate_Mode == 1) { - oled.Label((uint8_t *)"BPM",35,60); + sprintf(text,"%i",Heart_Rate); + if(Current_Zone == 1) { + textProperties.fontColor = COLOR_YELLOW; + oled.SetTextProperties(&textProperties); + } else if(Current_Zone == 2) { + textProperties.fontColor = COLOR_BLUE; + oled.SetTextProperties(&textProperties); + } else if(Current_Zone == 3) { + textProperties.fontColor = COLOR_GREEN; + oled.SetTextProperties(&textProperties); + } else if(Current_Zone == 4) { + textProperties.fontColor = COLOR_RED; + oled.SetTextProperties(&textProperties); + } + oled.Label((uint8_t *)text,35,60); + textProperties.fontColor = COLOR_WHITE; + oled.SetTextProperties(&textProperties); } break; } @@ -2812,28 +2832,34 @@ // Do nothing if no zone change } else if(Current_Zone == Target_Zone) { //Changed to target zone if(Target_Zone == LOWEST_ZONE || Prev_Zone > Target_Zone) { //must have entered from above + CLRWDT(); haptic = 1; wait(0.5); haptic = 0; wait(0.5); + CLRWDT(); haptic = 1; wait(0.5); haptic = 0; } else if(Target_Zone == HIGHEST_ZONE || Prev_Zone < Target_Zone) { //must have entered from below + CLRWDT(); haptic = 1; wait(0.5); haptic = 0; } } else if(Current_Zone != Target_Zone && Prev_Zone == Target_Zone) { if(Target_Zone == HIGHEST_ZONE || Current_Zone < Target_Zone) { //must have exited below + CLRWDT(); haptic = 1; wait(1); haptic = 0; } else if(Target_Zone == LOWEST_ZONE || Current_Zone > Target_Zone) { //must have exited above haptic = 1; + CLRWDT(); wait(1); haptic = 0; wait(1); + CLRWDT(); haptic = 1; wait(1); haptic = 0; @@ -2844,15 +2870,18 @@ if(Current_Zone == Prev_Zone) { //do nothing } else if(Current_Zone == Target_Zone) { + CLRWDT(); haptic = 1; wait(0.2); haptic = 0; wait(0.2); + CLRWDT(); haptic = 1; wait(0.2); haptic = 0; } else if(Current_Zone != Target_Zone && Prev_Zone == Target_Zone) { haptic = 1; + CLRWDT(); wait(1); haptic = 0; } @@ -4336,6 +4365,26 @@ oled.Label((uint8_t *)"AFP",3,0); //Display "AFP" at x,y textProperties.fontColor = COLOR_WHITE; oled.SetTextProperties(&textProperties); + if(Heart_Rate_Mode == 1) { + sprintf(text,"%i",Heart_Rate); + if(Current_Zone == 1) { + textProperties.fontColor = COLOR_YELLOW; + oled.SetTextProperties(&textProperties); + } else if(Current_Zone == 2) { + textProperties.fontColor = COLOR_BLUE; + oled.SetTextProperties(&textProperties); + } else if(Current_Zone == 3) { + textProperties.fontColor = COLOR_GREEN; + oled.SetTextProperties(&textProperties); + } else if(Current_Zone == 4) { + textProperties.fontColor = COLOR_RED; + oled.SetTextProperties(&textProperties); + } + oled.Label((uint8_t *)text,35,60); + textProperties.fontColor = COLOR_WHITE; + oled.SetTextProperties(&textProperties); + + } break; }// end case 0 @@ -4818,19 +4867,19 @@ { maxim = 1; maxReset(); - wait(0.05); + //wait(0.05); setLED1_PA(0xFF); setLED2_PA(0x33); setLED3_PA(0xFF); setPILOT_PA(0x19); - wait(0.05); + //wait(0.05); setSLOT(0x0300); setFIFO_CONFIG(0x06); setSPO2_CONFIG(0x42); - wait(0.05); + // wait(0.05); setPROX_INT_THR(0x14); clearFIFO(); - wait(0.05); + //wait(0.05); } void maxEnable(void) @@ -4860,9 +4909,7 @@ for(int i = 0; i < 100; i++) { hr_data[i] = readFIFO(); - //if(i % 3 == 1) // there seems to be a missing "{" here - // wait(0.01); // every third read wait 0.05s, this adds about 1.65s - } + } peak = isPeak(hr_data); @@ -4871,7 +4918,7 @@ if(hr >= HR_Zone1[0] && hr <= HR_Zone4[1]) { Heart_Rate = hr; - // update_display();//I don't think we need to update display here, let update_data do that + } Determine_Current_Zone();