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 Hexiwear_zeta

Revision:
15:330794a9f347
Parent:
14:c3b080cdf36b
Child:
16:537ef0c72084
--- a/main.cpp	Wed Apr 11 01:46:49 2018 +0000
+++ b/main.cpp	Wed Apr 11 02:23:07 2018 +0000
@@ -236,9 +236,9 @@
 uint8_t Reset_Count = 0;
 uint8_t Current_Zone = 1;
 uint8_t Prev_Zone = 1;
-uint8_t Heart_Rate = 100;
+uint8_t Heart_Rate = 0;
 uint8_t *HR_return;
-uint8_t Age = 50;            // Initialize age
+uint8_t Age = 25;            // Initialize age
 uint8_t Max_Bpm = 220 - Age;      // Initialize Max BPM
 uint8_t Screen_Num = 0;      // Initialize to main screen
 uint8_t Error_Num = 0;         // Error num for debug
@@ -248,7 +248,7 @@
 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 heat_index;                  // used in Heat index calc
+uint8_t heat_index;                  // used in Heat index calc
 int hi_calc;                    // used in Heat index calc
 int adjustment;                 // used in Heat index calc
 // slow changing variables
@@ -1023,6 +1023,12 @@
                 update_display();
                 break;
             }
+            case 31: {
+                StartHaptic();
+                Screen_Num = 32;
+                update_display();
+                break;
+            }
             case 32: {
                 StartHaptic();
                 Screen_Num = 33;
@@ -1033,6 +1039,7 @@
                 StartHaptic();
                 Screen_Num = 7;
                 update_display();
+                break;
             } 
             case 41: {// Fall-Mode adj
                 StartHaptic();
@@ -1627,11 +1634,13 @@
                       
             Heat_Index_Calculation();
             sprintf(text,"%i",heat_index);
-            oled.TextBox((uint8_t *)text,3,80,15,15); //show HI in a 15px by 15px text box at x=3, y=80
-            strcpy((char *) text,"F");oled.Label((uint8_t *)text,22,80); // was "dF" at 18,80
+            oled.Label((uint8_t *)text,3,80);// HI at x,y
+            //oled.TextBox((uint8_t *)text,3,80); //show HI in a 15px by 15px text box at x=3, y=80
+            strcpy((char *) text,"F");
+            oled.Label((uint8_t *)text,25,80); // was "dF" at 18,80
             
             if(Heart_Rate_Mode == 1) {
-                oled.Label((uint8_t *)"BPM",35,60); // Display "H.I." at x,y
+                oled.Label((uint8_t *)"BPM",35,60); 
             }
             break;
         }
@@ -2682,7 +2691,6 @@
 void Enable_Heart_Rate()
 {
     Heart_Rate_Mode = true;
-    Heart_Rate_Vibrations();
 }
 
 /*****************************************************************************
@@ -2693,8 +2701,7 @@
 ******************************************************************************/
 void Disable_Heart_Rate()
 {
-    Heart_Rate_Mode = false;
-    Heart_Rate_Vibrations();
+    Heart_Rate_Mode = false;  
 }
 
 /*****************************************************************************
@@ -2719,6 +2726,7 @@
     } else {
         //error reading, don't change anything
     }
+    Heart_Rate_Vibrations();
 
 
 }
@@ -2730,22 +2738,38 @@
 ******************************************************************************/
 void Heart_Rate_Vibrations()
 {
-    if(Heart_Rate_Mode == true) {
+    
         if(HR_Vibration == 1) {
             //All Pre-loaded vibrations enabled
             if(Current_Zone == Prev_Zone) {
                 // 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
-                    StartHaptic(ENTER_ABOVE);
+                    haptic = 1;
+                    wait(0.5);
+                    haptic = 0;
+                    wait(0.5);
+                    haptic = 1;
+                    wait(0.5);
+                    haptic = 0;
                 } else if(Target_Zone == HIGHEST_ZONE || Prev_Zone < Target_Zone) { //must have entered from below
-                    StartHaptic(ENTER_BELOW);
+                    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
-                    StartHaptic(EXIT_BELOW);
+                    haptic  = 1;
+                    wait(1);
+                    haptic = 0;
                 } else if(Target_Zone == LOWEST_ZONE || Current_Zone > Target_Zone) { //must have exited above
-                    StartHaptic(EXIT_ABOVE);
+                    haptic = 1;
+                    wait(1);
+                    haptic = 0;
+                    wait(1);
+                    haptic = 1;
+                    wait(1);
+                    haptic = 0;
                 }
             }
         } else if(HR_Vibration == 2) {
@@ -2753,15 +2777,17 @@
             if(Current_Zone == Prev_Zone) {
                 //do nothing
             } else if(Current_Zone == Target_Zone) {
-                StartHaptic(VIB_OPT_2);
-                wait(0.1);
-                StartHaptic(VIB_OPT_2);
+                haptic = 1;
+                wait(0.2);
+                haptic = 0;
+                wait(0.2);
+                haptic = 1;
+                wait(0.2);
+                haptic = 0;
             } else if(Current_Zone != Target_Zone && Prev_Zone == Target_Zone) {
-                StartHaptic(VIB_OPT_2);
-                wait(0.1);
-                StartHaptic(VIB_OPT_2);
-                wait(0.1);
-                StartHaptic(VIB_OPT_2);
+                haptic = 1;
+                wait(1);
+                haptic = 0; 
             }
 
         } else  if(HR_Vibration == 3) {
@@ -2771,7 +2797,7 @@
             //Error, can only be choices 1-3
             error_screen();
         }
-    }
+    
 }
 
 /*****************************************************************************
@@ -2789,6 +2815,7 @@
     } else {
         Heart_Rate += 1;
     }
+    Determine_Current_Zone();
 }
 
 /*****************************************************************************
@@ -2806,7 +2833,8 @@
     } else {
         Heart_Rate -= 1;
     }
-}  // end of Decrement_Heart_Rate
+    Determine_Current_Zone();
+} 
 
 void Led_Zone_Indicator()
 {
@@ -4201,8 +4229,9 @@
             
             Heat_Index_Calculation();
             sprintf(text,"%i",heat_index);
-            oled.TextBox((uint8_t *)text,3,80,15,15); //show HI in a 15px by 15px text box at x=3, y=80
- 
+            //oled.TextBox((uint8_t *)text,3,80,15,15); //show HI in a 15px by 15px text box at x=3, y=80
+            oled.Label((uint8_t *)text,3,80);// HI at x,y
+            
             textProperties.fontColor = COLOR_GRAY;
             if(Fall_Alert == 1){
                 textProperties.fontColor = COLOR_GREEN; // is Fall protection on?