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:
8:a5c77b45008d
Parent:
7:3d5a8aea0b63
Child:
9:d2e39ee9fedd
--- a/main.cpp	Wed Feb 14 22:53:49 2018 +0000
+++ b/main.cpp	Mon Feb 19 05:11:42 2018 +0000
@@ -29,6 +29,7 @@
 */
 
 // Definitions
+#define SW_Ver          2.07    // For displaying software version
 #define LED_ON          0
 #define LED_OFF         1
 #define SCRN_TIME       10.0
@@ -48,7 +49,7 @@
 void StopHaptic(void const *n);
 void error_screen(void);
 void update_display(void);// Screen lables refreshed
-void update_data(void);   // Screen data(only)refreshed 
+void update_display_date(void);  // Screen data(only)refreshed 
 void Decrement_Age();
 void Set_Max_Bpm();
 void Set_Zone_Boundaries();
@@ -75,12 +76,14 @@
 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 BLE_On = 0;            // Initialize as BLE on
+char pass [20];              // Passcode
 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
+uint8_t 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
@@ -171,7 +174,7 @@
             }
             case 1: {// Panic Alert option
                 StartHaptic();
-                Screen_Num = 26;  //Change to screen 5
+                Screen_Num = 5;  //Change to screen 5
 #ifdef Debug    // in debug show debug/diagnostic screens                         
                 Screen_Num = 26;  //Change to screen 20
 #endif
@@ -181,7 +184,7 @@
             }
             case 2: {// Fall Alert option
                 StartHaptic();
-                Screen_Num = 1;  //Change to screen 1
+                Screen_Num = 71;  //Change to screen 71
                 update_display();
                 break;
             }
@@ -224,6 +227,24 @@
                 //Increment  alert index
                 break;
             }
+            case 9: {// HexiHeart About info1
+                    StartHaptic();
+                    Screen_Num = 11;  //Change to screen 11
+                    update_display();
+                    break;
+                }    
+            case 10: {// HexiHeart About info2
+                    StartHaptic();
+                    Screen_Num = 9;  //Change to screen 9
+                    update_display();
+                    break;
+                }    
+            case 11: {// HexiHeart About info3
+                    StartHaptic();
+                    Screen_Num = 10;  //Change to screen 9
+                    update_display();
+                    break;
+                } 
             case 20: {// Diagnostic/Debug Screens
                 StartHaptic();
                 Screen_Num = 5;  //Change to screen 5
@@ -288,6 +309,62 @@
                 update_display();
                 break;
             }
+            
+            case 41: {//Fall mode 0,1,2,3
+                StartHaptic();
+                Fall_Alert_Mode++;
+                if(Fall_Alert_Mode > 3){
+                Fall_Alert_Mode = 0;
+                }//endif
+                update_display();
+                __disable_irq();    // Disable all Interrupts
+                fall_config(10);  // reset sensor
+                wait(0.1);
+                fall_config(Fall_Alert_Mode);
+                wait(0.1);
+                __enable_irq();     // Enable all Interrupts
+                wait(0.3);
+                update_display();
+                break;
+            }    
+            case 42: {// F-Th adj
+                StartHaptic();
+                Fall_Thresh = Fall_Thresh + 0.05;
+                if(Fall_Thresh > 0.9){
+                Fall_Thresh = 0.9;
+                }//endif
+                update_display();
+                break;
+            }
+            case 43: {// I-Th adj
+                StartHaptic();
+                Impact_Thresh = Impact_Thresh + 0.1;
+                if(Impact_Thresh > 3.9){
+                Impact_Thresh = 3.9;
+                }//endif
+                update_display();
+                break;
+            }
+            case 44: {// M-Th adj
+                StartHaptic();
+                Movement_Thresh = Movement_Thresh + 5.0;
+                if(Movement_Thresh > 300.0){
+                Movement_Thresh = 300.0;
+                }//endif
+                update_display();
+                break;
+            }
+            
+            case 71: {// BLE
+                StartHaptic();
+                Screen_Num = 1; //Change to screen 1
+                update_display();
+                break;
+            }
+            case 72: {// BlueTooth on/off
+                // do nothing, wrong button or change to another screen number if you're making more BLE type screens
+                break;
+            }
             default: {
                 break;
             }
@@ -311,7 +388,7 @@
             }
             case 1: {// Panic Alert option
                 StartHaptic();
-                Screen_Num = 2;  //Change to screen 2
+                Screen_Num = 71;  //Change to screen 71
                 update_display();
                 break;
             }
@@ -356,6 +433,24 @@
                 //decriment alert index
                 break;
             }
+            case 9: {// HexiHeart About info1
+                    StartHaptic();
+                    Screen_Num = 10;  //Change to screen 10
+                    update_display();
+                    break;
+                }
+            case 10: {// HexiHeart About info2
+                    StartHaptic();
+                    Screen_Num = 11;  //Change to screen 11
+                    update_display();
+                    break;
+                }
+            case 11: {// HexiHeart About info3
+                    StartHaptic();
+                    Screen_Num = 9;  //Change to screen 9
+                    update_display();
+                    break;
+                }            
             case 20: {// Diagnostic/Debug Screens
                 StartHaptic();
                 Screen_Num = 26;  //Change to screen 1
@@ -429,6 +524,61 @@
                 update_display();
                 break;
             }
+            case 41: {//Fall mode 0,1,2,3
+                Fall_Alert_Mode--;
+                if(Fall_Alert_Mode > 3){// should be 0xff if decr from zero
+                Fall_Alert_Mode = 3;
+                }  //endif
+                update_display();
+                __disable_irq();    // Disable all Interrupts
+                fall_config(10);  // reset sensor
+                wait(0.1);
+                fall_config(Fall_Alert_Mode);
+                wait(0.1);
+                __enable_irq();     // Enable all Interrupts
+                wait(0.2);
+                update_display();
+                break;
+            }
+            case 42: {// F-Th adj
+                StartHaptic();
+                Fall_Thresh = Fall_Thresh - 0.05;
+                if(Fall_Thresh < 0.1){
+                Fall_Thresh = 0.1;
+                }//endif
+                update_display();
+                break;
+            }
+            case 43: {// I-Th adj
+                StartHaptic();
+                Impact_Thresh = Impact_Thresh - 0.1;
+                if(Impact_Thresh < 0.9){
+                Impact_Thresh = 0.9;
+                }//endif
+                update_display();
+                break;
+            }
+            case 44: {// M-Th adj
+                StartHaptic();
+                Movement_Thresh = Movement_Thresh - 5.0;
+                if(Movement_Thresh < 5.0){
+                Movement_Thresh = 5.0;
+                }//endif
+                update_display();
+                break;
+            }
+            
+            case 71: {// BLE
+                StartHaptic();
+                Screen_Num = 2; //Change to screen 2
+                update_display();
+                break;
+            }
+            case 72: {// BlueTooth on/off
+                // do nothing, wrong button or change to another screen number if you're making more BLE type screens
+                break;
+            }
+            
             default: {
                 break;
             }
@@ -504,6 +654,12 @@
                 update_display();
                 break;
             }
+            case 22: {// Fall Debug
+                StartHaptic();
+                Screen_Num = 41;  //Change to screen 41
+                update_display();
+                break;
+            }
             case 26: {//Change to Heart Rate Config Screen
                 StartHaptic();
                 Screen_Num = 27;
@@ -546,6 +702,41 @@
                 update_display();
                 break;
             }
+            case 41: {// Fall-Mode adj
+                StartHaptic();
+                Screen_Num = 42;  //Change to screen 42
+                update_display();
+                break;
+            }       
+            case 42: {// F-Th adj
+                StartHaptic();
+                Screen_Num = 43;  //Change to screen 43
+                update_display();
+                break;
+            }
+            case 43: {// I-Th adj
+                StartHaptic();
+                Screen_Num = 44;  //Change to screen 44
+                update_display();
+                break;
+            }
+            case 44: {// M-Th adj
+                // do nothing for now
+                break;
+            }
+             case 71: {// BLE
+                StartHaptic();
+                Screen_Num = 72;  //Change to screen 72
+                update_display();
+                break;
+            }
+             case 72: {// BlueTooth on/off
+                StartHaptic();
+                BLE_On = !BLE_On;
+                update_display();
+                break;
+            }           
+            
             default: {
                 break;
             }
@@ -613,6 +804,24 @@
                 update_display();
                 break;
             }
+            case 9: {// About HexiHeart info1
+                    StartHaptic();
+                    Screen_Num = 5;  //Change to screen 5
+                    update_display();
+                    break;
+                }
+            case 10: {// HexiHeart About info2
+                    StartHaptic();
+                    Screen_Num = 5;  //Change to screen 5
+                    update_display();
+                    break;
+                }
+            case 11: {// HexiHeart About info3
+                    StartHaptic();
+                    Screen_Num = 5;  //Change to screen 5
+                    update_display();
+                    break;
+                }            
             case 20: {// Diagnostic/Debug Screens
                 StartHaptic();
                 Screen_Num = 0;  //Change to screen 0
@@ -691,6 +900,44 @@
                 update_display();
                 break;
             }
+            case 41: {// Fall mode screen
+                StartHaptic();
+                Screen_Num = 22;
+                update_display();
+                break;
+            }    
+            case 42: {// F-Th adj
+                StartHaptic();
+                Screen_Num = 41;  //Change to screen 41
+                update_display();
+                break;
+            }
+            case 43: {// I-Th adj
+                StartHaptic();
+                Screen_Num = 42;  //Change to screen 42
+                update_display();
+                break;
+            }
+            case 44: {// M-Th adj
+                StartHaptic();
+                Screen_Num = 43;  //Change to screen 43
+                update_display();
+                break;
+            }                  
+             case 71: {// BLE
+                StartHaptic();
+                Screen_Num = 0;  //Change to screen 0
+                update_display();
+                break;
+            }
+
+            case 72: {// BlueTooth on/off
+                StartHaptic();
+                Screen_Num = 71;  //Change to screen 71
+                update_display();
+                break;
+            }
+           
             default: {
                 break;
             }
@@ -714,7 +961,7 @@
 int main()
 {
 //   set_time(1256729737);  // Set RTC time to Wed, 28 Oct 2009 11:35:37
-   set_time(48*365*24*3600+61*24*3600+10*3600);  // Set RTC time to Mon, 19 Feb 2018 10:00
+   set_time(48*365*24*3600+61*24*3600+10*3600-4);  // Set RTC time to Mon, 19 Feb 2018 10:00
     OLED_PWR = 1;  // Turn on OLED power supply
     
     
@@ -726,7 +973,7 @@
 // **************  configure sensor modules  ******************
     //    accel.accel_config();   // configure sensor
  //   fall_config(1);         // configure sensor for fall detect
-     fall_config(3); // configure sensor for fall mode
+    fall_config(Fall_Alert_Mode); // configure sensor for current fall mode
 //    mag.mag_config();
     gyro.gyro_config();
 
@@ -737,7 +984,8 @@
     Led_clk2 = 0; // LEDs on docking station default to off, need to turn on with a 1
     Led_clk3 = 0; // LEDs on docking station default to off, need to turn on with a 1
     Non_Free_PWR = 1;   // Start with non-freescale sensors (Pres/Temp/Hum/Light)on
-    HR_PWR = 1;         // Start with Heart rate sensor powered on
+
+    HR_PWR = 0;         // Start with Heart rate sensor powered off
     
 // ***** Register callbacks/interupts to application functions *********
     kw40z_device.attach_buttonUp(&ButtonUp);
@@ -761,17 +1009,20 @@
     oled.SetTextProperties(&textProperties);
 
 // **************  Display spash screen  **********************
-
+    oled.FillScreen(COLOR_BLACK); // Clear screen
     oled.Label((uint8_t *)"Hexi",20,5); // Display white "Hexi" at x,y
     textProperties.fontColor = COLOR_RED;
     oled.SetTextProperties(&textProperties);
     oled.Label((uint8_t *)"Heart",45,5); // Display red "Heart" at x,y
 
 #ifdef Debug  // if this is non-production version - do this
-    strcpy((char *) text_1,"This is Debug Ver");
-    oled.Label((uint8_t *)text_1,0,60);  // text_1 at x,y
-    StartHaptic();
-#endif
+    strcpy((char *) text_1,"This is Debug");
+    oled.Label((uint8_t *)text_1,15,50);  // text_1 at x,y
+    sprintf(text_1," Ver:%2.2f  ",SW_Ver);
+    oled.Label((uint8_t *)text_1,30,70);// text_1 at x,y
+    StartHaptic(); 
+    #endif
+    
     textProperties.fontColor = COLOR_WHITE;
     oled.SetTextProperties(&textProperties);
     wait(3);  // wait 3 seconds
@@ -784,7 +1035,7 @@
     {
     Thread::wait(500);          // wait 0.5 sec each loop
     if(OLED_PWR==1){
- //       update_data();
+    update_display_date();     // refresh display date w/o updating entire display 
         }// end if
     i++;
     }// end while(i<20)
@@ -795,9 +1046,7 @@
     wait(0.01);          // BLIP led 1/10 sec each loop
     RED_Led = LED_OFF;    // Used only for diagnostic of wait command
     Led_clk3 = 0; 
-    Thread::wait(490);    // keep up the pace, at 0.5 sec (0.01s+0.49s) update date
-
-//    update_data();        // refresh display date w/o updating entire display 
+    Thread::wait(490);    // keep up the pace, at 0.5 sec (0.01s+0.49s) update date 
 
     } // end of while(true)
 
@@ -809,6 +1058,7 @@
     OLED_PWR = 1;  // make sure OLED power supply is on
     oled_text_properties_t textProperties = {0};  // Need these to change font color
     oled.GetTextProperties(&textProperties);      // Need these to change font color
+    __disable_irq();    // Disable all Interrupts
     switch(Screen_Num) {
         case 0: {// Main Screen
             HexiwearBattery battery;
@@ -824,7 +1074,7 @@
             } else {
             sprintf(text_1, "%i%%", (uint8_t)battery.readLevelPercent());
             }
-            oled.TextBox((uint8_t *)text_1,60,0,35,15); //show level value of battery originaly at  55,40,35,15
+            oled.TextBox((uint8_t *)text_1,60,0,35,15); //show level value of battery in a 35px by 15px text box at x=60, y=0
         
         textProperties.fontColor = COLOR_WHITE;
         oled.SetTextProperties(&textProperties);
@@ -838,7 +1088,11 @@
             oled.Label((uint8_t *)"Menu",60,80);  //Display "Menu" at x,y
             
             textProperties.fontColor = COLOR_GRAY;
+            if(BLE_On == 1){
+               textProperties.fontColor = COLOR_BLUE; 
+               }
             oled.SetTextProperties(&textProperties);
+            
             oled.Label((uint8_t *)"BT",40,80);  //Display "BT" at x,y
             textProperties.fontColor = COLOR_WHITE;
             oled.SetTextProperties(&textProperties);  
@@ -856,7 +1110,7 @@
                           
             Heat_Index_Calculation();
             sprintf(text,"%i",heat_index);
-            oled.TextBox((uint8_t *)text,3,80,15,15); 
+            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,"dF");oled.Label((uint8_t *)text,18,80);
             
             if(Heart_Rate_Mode == 1) {
@@ -976,6 +1230,73 @@
             oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
             break;
         }
+        
+        case 9: {// About HexiHeart info1
+                    oled.FillScreen(COLOR_BLACK); // Clear screen
+                    oled.Label((uint8_t *)"Hexi",20,1); // Display white "Hexi" at x,y
+                    textProperties.fontColor = COLOR_RED;
+                    oled.SetTextProperties(&textProperties);  
+                    oled.Label((uint8_t *)"Heart",45,0); // Display red "Heart" at x,y  
+                    textProperties.fontColor = COLOR_WHITE;
+                    oled.SetTextProperties(&textProperties);  
+                    oled.Label((uint8_t *)"Senior Proj",5,15); //
+                    oled.Label((uint8_t *)"Team Zeta E1.7",5,30); //
+                    oled.Label((uint8_t *)"Texas State Univ",0,45); //        
+                    oled.Label((uint8_t *)"+",85,15); // "*" at x,y
+                    oled.Label((uint8_t *)"-",85,60); // "*" at x,y
+                    oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y                  
+                        break;
+                }
+                        
+            case 10: {// About HexiHeart info2
+                    oled.FillScreen(COLOR_BLACK); // Clear screen
+                    oled.Label((uint8_t *)"Hexi",20,0); // Display white "Hexi" at x,y
+                    textProperties.fontColor = COLOR_RED;
+                    oled.SetTextProperties(&textProperties);  
+                    oled.Label((uint8_t *)"Heart",45,0); // Display red "Heart" at x,y  
+                    textProperties.fontColor = COLOR_WHITE;
+                    oled.SetTextProperties(&textProperties);  
+                    oled.Label((uint8_t *)"E2.7 Team Zeta",2,12); //
+                    oled.Label((uint8_t *)"Alex Song",5,25); //
+                    oled.Label((uint8_t *)"Jasmine Rounsav",5,38); // Jasmine Rounsaville is to long
+                    oled.Label((uint8_t *)"Issam Hichami",5,51); // 
+                    oled.Label((uint8_t *)"Neil Baker",5,64); //           
+
+                    oled.Label((uint8_t *)"+",85,15); // "*" at x,y
+                    oled.Label((uint8_t *)"-",85,60); // "*" at x,y
+                    oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y                  
+                        break;
+                }
+                    
+            case 11: {// About HexiHeart info3
+                    oled.FillScreen(COLOR_BLACK); // Clear screen
+                    oled.Label((uint8_t *)"Hexi",20,0); // Display white "Hexi" at x,y
+                    textProperties.fontColor = COLOR_RED;
+                    oled.SetTextProperties(&textProperties);  
+                    oled.Label((uint8_t *)"Heart",45,0); // Display red "Heart" at x,y  
+                // *********get screen alignment  **************
+                    oled_text_properties_t textProperties = {0};
+                    oled.GetTextProperties(&textProperties); 
+                // *********Set text color and screen alignment  **************
+                    textProperties.alignParam = OLED_TEXT_ALIGN_CENTER;
+                    oled.SetTextProperties(&textProperties);   
+  
+                    #ifdef Debug  // if this is non-production version - do this
+                        oled.Label((uint8_t *)"This is Debug",0,25);  // text_1 at X=10,y=25
+                        oled.Label((uint8_t *)"Ver of SW",0,40);  // text_1 at x=20,y=40
+                    #endif
+                    textProperties.fontColor = COLOR_WHITE;
+                    oled.SetTextProperties(&textProperties);  
+                    sprintf(text_1," SW_Ver:%2.2f  ",SW_Ver);
+                    oled.Label((uint8_t *)text_1,0,55);// text_1 at x=10,y
+                    textProperties.alignParam = OLED_TEXT_ALIGN_LEFT;
+                    oled.SetTextProperties(&textProperties);  
+                    oled.Label((uint8_t *)"+",85,15); // "*" at x,y
+                    oled.Label((uint8_t *)"-",85,60); // "*" at x,y
+                    oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y                  
+                        break;
+                }       
+        
 #ifdef Debug  // if this is non-production/debug version - do this
         case 20: {// Diagnostic/Debug Screens
             oled.FillScreen(COLOR_BLACK); // Clear screen
@@ -992,6 +1313,9 @@
             break;
         }
         case 21: {// Fall Alert Diagnostic Screen
+            if(Fall_Alert_Mode == 0){
+                fall_config(11); // turn accel sensor to active to take reading
+            }
             oled.FillScreen(COLOR_BLACK); // Clear screen
             textProperties.fontColor = COLOR_RED;
             oled.SetTextProperties(&textProperties);
@@ -999,14 +1323,19 @@
        //     oled.Label((uint8_t *)"Diagnostic",25,5); // Display at x,y
             textProperties.fontColor = COLOR_WHITE;
             oled.SetTextProperties(&textProperties);
+            gyro.acquire_gyro_data_dps(Gyro_Data);
+            Gyro_Mag = (abs(Gyro_Data[0])+abs(Gyro_Data[1])+abs(Gyro_Data[2]));
             accel.acquire_accel_data_g(Accel_Data);
-//                   gyro.acquire_gyro_data_g(Gyro_Data);
-            Accel_Mag = 2*sqrt(((Accel_Data[0]*Accel_Data[0])+(Accel_Data[1]*Accel_Data[1])+(Accel_Data[2]*Accel_Data[2])));
-            //                  Gyro_Mag = (abs(Gyro_Data[0])+abs(Gyro_Data[1])+abs(Gyro_Data[3]));
+            if(Fall_Alert_Mode == 0){
+                fall_config(12); // turn accel sensor to standby
+            }
+            Accel_Mag = 2*sqrt(((Accel_Data[0]*Accel_Data[0])+(Accel_Data[1]*Accel_Data[1])+(Accel_Data[2]*Accel_Data[2])));     
             sprintf(text_1," Accel:%2.2f g  ",Accel_Mag);
             oled.Label((uint8_t *)text_1,10,40);// text_1 at x,y
             sprintf(text_1," Gyro:%4.0f D/S  ",Gyro_Mag);
             oled.Label((uint8_t *)text_1,10,60);// text_1 at x,y
+            oled.Label((uint8_t *)"*",85,15); // "*" at x,y
+            oled.Label((uint8_t *)"*",85,60); // "*" at x,y
             oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
             break;
         }
@@ -1017,21 +1346,39 @@
             oled.Label((uint8_t *)"Fall Debug",15,5); // Display at x,y
             textProperties.fontColor = COLOR_GREEN;
             oled.SetTextProperties(&textProperties);
-            sprintf(text_1," %1.1f g  ",Fall_Thresh);
+            sprintf(text_1," %i ",Fall_Alert_Mode);
             oled.Label((uint8_t *)text_1,35,20);// text_1 at x,y
-            sprintf(text_1," %2.1f g  ",Impact_Thresh);
+            textProperties.fontColor = COLOR_GRAY;
+            if(Fall_Alert_Mode == 1 || Fall_Alert_Mode == 3){
+            textProperties.fontColor = COLOR_GREEN;
+            }
+            oled.SetTextProperties(&textProperties);
+            sprintf(text_1," %1.2f g  ",Fall_Thresh);
             oled.Label((uint8_t *)text_1,35,35);// text_1 at x,y
+            textProperties.fontColor = COLOR_GRAY;
+            if(Fall_Alert_Mode == 2 || Fall_Alert_Mode == 3){
+            textProperties.fontColor = COLOR_GREEN;
+            }
+            oled.SetTextProperties(&textProperties);
+            sprintf(text_1," %2.2f g  ",Impact_Thresh);
+            oled.Label((uint8_t *)text_1,35,50);// text_1 at x,y
+            textProperties.fontColor = COLOR_GRAY;
+            if(Fall_Alert_Mode == 3){
+            //textProperties.fontColor = COLOR_GREEN;
+            }
+            oled.SetTextProperties(&textProperties);
             sprintf(text_1," %3.0f D/S  ",Movement_Thresh);
-            oled.Label((uint8_t *)text_1,35,50);// text_1 at x,y
+            oled.Label((uint8_t *)text_1,35,65);// text_1 at x,y
             textProperties.fontColor = COLOR_WHITE;
             oled.SetTextProperties(&textProperties);
-            oled.Label((uint8_t *)"F-Th:",5,20); // "*" at x,y
-            oled.Label((uint8_t *)"I-Th:",5,35); // "*" at x,y
-            oled.Label((uint8_t *)"M-Th:",5,50); // "*" at x,y
+            oled.Label((uint8_t *)"Mode:",5,20); // "*" at x,y
+            oled.Label((uint8_t *)"F-Th:",5,35); // "*" at x,y
+            oled.Label((uint8_t *)"I-Th:",5,50); // "*" at x,y
+            oled.Label((uint8_t *)"M-Th:",5,65); // "*" at x,y
             oled.Label((uint8_t *)"*",85,15); // "*" at x,y
             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.Label((uint8_t *)" Enter ",59,80);  //Display at x,y
             break;
         }
         case 23: {// Heart Rate Diagnostic Screen
@@ -1092,7 +1439,7 @@
         /* Format the value */
             sprintf(text,"%i",sample_ftemp);
         
-        /* Display time reading in 35px by 15px textbox at(x=55, y=40) */
+        /* Display temp reading in 15px by 15px textbox at(x=55, y=40) */
             oled.TextBox((uint8_t *)text,55,40,15,15); //Increase textbox for more digits
         
         /* Display Units */
@@ -1102,7 +1449,7 @@
         /* Format the value */
             sprintf(text,"%i",sample_humid);
         
-        /* Display time reading in 35px by 15px textbox at(x=55, y=40) */
+        /* Display Hum reading in 15px by 15px textbox at(x=55, y=57) */
             oled.TextBox((uint8_t *)text,55,57,15,15); //Increase textbox for more digits
         
         /* Display Units */
@@ -1117,7 +1464,7 @@
         /* Format the value */
             sprintf(text,"%i",heat_index);
         
-        /* Display time reading in 35px by 15px textbox at(x=55, y=40) */
+        /* Display HI reading in 15px by 15px textbox at(x=55, y=23) */
             oled.TextBox((uint8_t *)text,55,23,15,15); //Increase textbox for more digits
         
         /* Display Units */
@@ -1388,15 +1735,118 @@
             oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
             oled.Label((uint8_t *)"Next",60,80);  //Display "Next" at x,y
             break;
+        }  
+        case 41: { //Fall mode
+            oled.FillScreen(COLOR_BLACK);
+            oled.Label((uint8_t *)"Adj Fall Mode", 10, 5);
+            sprintf(display_buff, "%u", Fall_Alert_Mode); //Convert int to char array for displaying mode
+            oled.Label((uint8_t *)"Mode:", 5, 30);
+            oled.Label((uint8_t *)"+",85,15); // "*" at x,y
+            oled.Label((uint8_t *)"-",85,60); // "*" at x,y
+            oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
+            oled.Label((uint8_t *)"Next",60,80);  //Display "Next" at x,y
+            textProperties.fontColor = COLOR_GREEN;
+            oled.SetTextProperties(&textProperties);
+            oled.Label((uint8_t *)display_buff,43,30); // Display at x,y
+            textProperties.fontColor = COLOR_WHITE;
+            oled.SetTextProperties(&textProperties);
+            break;
+        }
+        case 42: { //Fall Thresh
+            oled.FillScreen(COLOR_BLACK);
+            oled.Label((uint8_t *)"Adj F-Th", 10, 5);
+            sprintf(display_buff, "%2.2f g", Fall_Thresh); //Convert int to char array for displaying mode
+            oled.Label((uint8_t *)"F_Th:", 5, 30);
+            oled.Label((uint8_t *)"+",85,15); // "*" at x,y
+            oled.Label((uint8_t *)"-",85,60); // "*" at x,y
+            oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
+            oled.Label((uint8_t *)"Next",60,80);  //Display "Next" at x,y
+            textProperties.fontColor = COLOR_GREEN;
+            oled.SetTextProperties(&textProperties);
+            oled.Label((uint8_t *)display_buff,43,30); // Display at x,y
+            textProperties.fontColor = COLOR_WHITE;
+            oled.SetTextProperties(&textProperties);
+            break;
+        }
+        case 43: { //Impact Thresh
+            oled.FillScreen(COLOR_BLACK);
+            oled.Label((uint8_t *)"Adj I-Th", 10, 5);
+            sprintf(display_buff, "%2.2f g", Impact_Thresh); //Convert int to char array for displaying mode
+            oled.Label((uint8_t *)"I_Th:", 5, 30);
+            oled.Label((uint8_t *)"+",85,15); // "*" at x,y
+            oled.Label((uint8_t *)"-",85,60); // "*" at x,y
+            oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
+            oled.Label((uint8_t *)"Next",60,80);  //Display "Next" at x,y
+            textProperties.fontColor = COLOR_GREEN;
+            oled.SetTextProperties(&textProperties);
+            oled.Label((uint8_t *)display_buff,43,30); // Display at x,y
+            textProperties.fontColor = COLOR_WHITE;
+            oled.SetTextProperties(&textProperties);
+            break;
+        }
+        case 44: { //Motion Thresh
+            oled.FillScreen(COLOR_BLACK);
+            oled.Label((uint8_t *)"Adj M-Th", 10, 5);
+            sprintf(display_buff, "%4.0f D/S", Movement_Thresh); //Convert int to char array for displaying mode
+            oled.Label((uint8_t *)"M_Th:", 5, 30);
+            oled.Label((uint8_t *)"+",85,15); // "*" at x,y
+            oled.Label((uint8_t *)"-",85,60); // "*" at x,y
+            oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
+  //          oled.Label((uint8_t *)"Next",60,80);  //Display "Next" at x,y
+            textProperties.fontColor = COLOR_GREEN;
+            oled.SetTextProperties(&textProperties);
+            oled.Label((uint8_t *)display_buff,43,30); // Display at x,y
+            textProperties.fontColor = COLOR_WHITE;
+            oled.SetTextProperties(&textProperties);
+            break;
         }
 #endif  // end of non-production/debug version code
+
+        case 71: {// BLE
+            oled.FillScreen(COLOR_BLACK); // Clear screen
+            oled.Label((uint8_t *)"BLUETOOTH",5,5); // Display at x,y
+            oled.Label((uint8_t *)" Enter ",59,80);  //Display at x,y
+            textProperties.fontColor = COLOR_WHITE;
+            oled.SetTextProperties(&textProperties);
+            oled.Label((uint8_t *)"*",85,15); // "*" at x,y
+            oled.Label((uint8_t *)"*",85,60); // "*" at x,y
+            oled.Label((uint8_t *)" Back ",9,80); // Display "Back" at x,y
+            break;
+        }
+
+        case 72: {// BlueTooth on/off
+            oled.FillScreen(COLOR_BLACK); // Clear screen
+            oled.Label((uint8_t *)"BLUETOOTH",5,5); // Display at x,y
+            if (BLE_On == 1) {
+                strcpy((char *) text,"PAIR CODE");
+                oled.TextBox((uint8_t *)text,5,25,85,18);
+                /* Display Bond Pass Key in a 85px by 18px textbox at x=5,y=25 */
+                
+/* This part was not compiling
+                sprintf(text,"%d", kw40z_device.GetPassKey());
+                oled.TextBox((uint8_t *)text,0,40,95,18);
+*/        
+                oled.TextBox((uint8_t *)"Passkey",5,40,85,18); //show passkey in a 85px by 18px text box at x=5, y=40
+            } else {
+                oled.Label((uint8_t *)" Off ",40,40);
+            }
+  //          oled.Label((uint8_t *)"*",85,15); // "*" at x,y
+  //          oled.Label((uint8_t *)"*",85,60); // "*" at x,y
+            oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
+            oled.Label((uint8_t *)"Toggle",60,80);  //Display "Toggle" at x,y
+            break;
+        }
+
+
         default: {
             Error_Num=1;
             error_screen(); // Clear screen
             break;
         }
-    }
-}
+    }//end of switch
+    __enable_irq();     // Enable all Interrupts
+}// end upday_display()
+
 void error_screen(void)
 {
     oled.FillScreen(COLOR_RED); // Clear screen
@@ -1416,7 +1866,10 @@
 ******************************************************************************/
 void StartHaptic(void)
 {
-    hapticTimer.start(30);  // was originaly 50
+    hapticTimer.start(30);  // was originaly 50, then 30 
+    /* this 30 value seems to not work after Neil added a global 
+    __disable_irq() and __enable_irq() for the update_display() functions on 2/18/18
+    */
     haptic = 1;
 }
 
@@ -1426,8 +1879,9 @@
 Inputs: An int representing the duration of the vibration
 Returns: None
 ******************************************************************************/
+
 void StartHaptic(int x)
-{
+{   
     hapticTimer.start(x);
     haptic = 1;
 }
@@ -1795,11 +2249,10 @@
          
 //__disable_irq();    // Disable all Interrupts
 //    oled.Label((uint8_t *)" Fall Detected ",05,70); // Display at x,y 
- 
     update_display();
             Accel_Mag = 2*sqrt(((Accel_Data_Event[0]*Accel_Data_Event[0])+(Accel_Data_Event[1]*Accel_Data_Event[1])+(Accel_Data_Event[2]*Accel_Data_Event[2])));
             sprintf(text_1,"Free-Fall:%2.2fg",Accel_Mag);
-            oled.Label((uint8_t *)text_1,10,5);// text_1 at x,y
+            oled.Label((uint8_t *)text_1,2,5);// text_1 at x,y
 
     BLU_Led = LED_ON;  // LEDs default to on, need to turn off
     Led_clk2 = 1;  // Turn LED2 on docking station on
@@ -1818,7 +2271,7 @@
     haptic = 0;         // Turn off Haptic
     BLU_Led = LED_OFF;  // Turn off HexiHeart Blue LED
     Led_clk2 = 0;       // Turn off LED2 on docking station on
-    oled.Label((uint8_t *)"                         ",05,70); // clear display at x,y
+ //   oled.Label((uint8_t *)"                         ",05,70); // clear display at x,y
     Accel_INT1.fall(&fall_detect); // Accel sensor's int#1 calls interupt routine
 }    //end fall_det_end interupt routine
 
@@ -1841,9 +2294,9 @@
     //        update_display();
             
             accel.acquire_accel_data_g(Accel_Data);
-             Accel_Mag = 2*sqrt(((Accel_Data_Event[0]*Accel_Data_Event[0])+(Accel_Data_Event[1]*Accel_Data_Event[1])+(Accel_Data_Event[2]*Accel_Data_Event[2])));
+            Accel_Mag = 2*sqrt(((Accel_Data_Event[0]*Accel_Data_Event[0])+(Accel_Data_Event[1]*Accel_Data_Event[1])+(Accel_Data_Event[2]*Accel_Data_Event[2])));
             sprintf(text_1,"Impact:%2.2fg",Accel_Mag);
-            oled.Label((uint8_t *)text_1,10,20);// text_1 at x,y
+            oled.Label((uint8_t *)text_1,3,20);// text_1 at x,y
  
          Led_clk3 = 1;  // Turn LED2 on docking station on
  }// end if     
@@ -1857,26 +2310,24 @@
 Returns: None
 ******************************************************************************/
       
-
 void fall_config(uint8_t Num){ 
 // use case switches here to configure for 
-switch(Num) {
-                case 0: {// configure as normal (or maybe sleep)
+switch(Num) {           
+                case 0: {// put in standby
                   char d[2]; 
                     d[0] = FXOS8700_CTRL_REG1;                     //Puts device in Standby mode
                     d[1] = 0x00; 
-                    i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2);
+                    i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2);                  
                     
-                    d[0] = FXOS8700_CTRL_REG1;                     //Puts device back into active mode
-                    d[1] = 0x01;
-                    i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d, 2);
+                    /*For lowest power ~8uA, set ODR-12.5Hz,(low-pwr accel mode) or 2uA in standby mode */
                     oled.Label((uint8_t *)" Mode 0 ",30,60); // Display "mode" at x,y
-                    break;
-                }
-                case 1: {// configure for free-fall int
-                    StartHaptic();  // for debug
+                    oled.Label((uint8_t *)" No Int",30,75); // Display "mode" at x,y 
+                    break;      
+                }// end of case 0
+                
+                case 1: {// configure for free-fall int only
                     char d[2]; 
-                    d[0] = FXOS8700_CTRL_REG1;                      //Config reg1
+                    d[0] = 0x2a;                                       //0x2a Config reg1
                     d[1] = 0x00;                                    //Put device in Standby mode
                     if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
                         oled.Label((uint8_t *)" Step1 error ",30,05); // Display "error" at x,y                  
@@ -1884,19 +2335,19 @@
                     }//end if
                     
                     d[0] = 0x0e;                                    //XYZ_DATA_CFG (set full-scall range)
-                    d[1] = 0b00000000;                              //Set data to default range of +/-2g for full range (2x0.488mg/LSB), High-pass filter off
+                    d[1] = 0b00000001;                              //Set data to default range of +/-2g for full range (2x0.488mg/LSB), High-pass filter off
                     if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
                         oled.Label((uint8_t *)" Step1a error ",30,05); // Display "error" at x,y      
                         wait(3.0); // display for 3 seconds
                     }//end if
- 
-                    d[0] = 0x0a;                                    //TRIG_CFG (address of trigger config reg)
+ /*
+                    d[0] = 0x0a;                                    //TRIG_CFG (address of FIFO trigger config reg)
                     d[1] = 0b00000100;                              //Trigger on freefall
                     if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
                         oled.Label((uint8_t *)" Step2 error ",30,05); // Display "error" at x,y      
                         wait(3.0); // display for 3 seconds
                     }//end if
-                    
+ */                   
                     d[0] = 0x15;                                    //A_FFMT_CFG (address of Free fall trigger config reg), write in Standby only
                     d[1] = 0b00111000;                              //set to freefall, and look at all axis.
                     if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
@@ -1939,7 +2390,7 @@
                         oled.Label((uint8_t *)" Step8 error ",30,05); // Display "error" at x,y 
                         wait(3.0); // display for 3 seconds
                     }//end if            
-                 
+                    
                     d[0] = 0x2e;                                    //CTRL_REG5 (Int routing reg), write in Standby only
                     d[1] = 0b00000100;                              // Make FFMT int output on pin INT1(PTC1)
                     if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
@@ -1947,7 +2398,7 @@
                         wait(3.0); // display for 3 seconds
                     }//end if                  
                     
-                    d[0] = FXOS8700_CTRL_REG1;                     //CTRL_REG1, write in Standby only except for bit[0]
+                    d[0] = 0x2a;                         //0x2a Config reg1, write in Standby only except for bit[0]
                     d[1] = 0b00011001;                    //Auto-Sleep mode on set to 50Hz, ODR set to 100Hz Puts device back into Active mode 
                     if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
                         oled.Label((uint8_t *)" Step10 error ",30,05); // Display "error" at x,y 
@@ -1955,16 +2406,13 @@
                     }//end if  
                     
                     //oled.FillScreen(COLOR_BLACK); // Clear screen
-                    oled.Label((uint8_t *)" Mode 1 ",30,60); // Display "mode" at x,y   
-                    GRN_Led = LED_ON;  // LEDs default to on, need to turn on     
+                    oled.Label((uint8_t *)" Mode 1 ",30,60); // Display "mode" at x,y
+                    oled.Label((uint8_t *)"  FF ",30,75); // Display "mode" at x,y    
+                        
                     break;
                 }// end of case 1
                 
-                 //  case 2 was an attempt at using vector-mag int for free-fall  
-                               
-                 case 3: {// configure FFMT for free-fall event AND config for vector impact
-
-                    StartHaptic();  // for debug
+                case 2: {// configure for vector impact only
                     char d[2]; 
                     
                     d[0] = FXOS8700_CTRL_REG1;                      //Config reg1 0x2a
@@ -1980,14 +2428,114 @@
                         oled.Label((uint8_t *)" Step1a error ",30,05); // Display "error" at x,y      
                         wait(3.0); // display for 3 seconds
                     }//end if
- 
-                    d[0] = 0x0a;                                    //TRIG_CFG (address of trigger config reg)
+ /*
+                    d[0] = 0x0a;                                    //TRIG_CFG (address of FIFO trigger config reg)
                     d[1] = 0b00000110;                              //Trigger on freefall and on Vector
                     if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
                         oled.Label((uint8_t *)" Step2 error ",30,05); // Display "error" at x,y      
                         wait(3.0); // display for 3 seconds
                     }//end if
+ */                                      
+                    d[0] = 0x5f;                                    //A_VECM_CFG (address of Vector config reg), write in Standby only
+                    d[1] = 0b00111000;                              //Use reference values, don't update ref, enable.
+                    if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
+                        oled.Label((uint8_t *)" Step3 error ",30,05); // Display "error" at x,y 
+                        wait(3.0); // display for 3 seconds
+                    }//end if
+                       
+                    d[0] = 0x60;                                    //A_VECM_MSB (address of Vector threshold reg), write in Active or Standby
+                    d[1] = 0b00000111;                                //set impact threshold to less than 1g for now                   
+  //                 d[1] = uint8_t((1000*Impact_Thresh/0.488)/256);        //set MSB Impact threshold - Resolution is 0.488mg/LSB so 0.5g=1024.6 => MSB=0b00000100 LSB=0b00000000 
+                    if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
+                        oled.Label((uint8_t *)" Step4a error ",30,05); // Display "error" at x,y 
+                        wait(3.0); // display for 3 seconds
+                    }//end if  
+           
+                    d[0] = 0x61;                                    //A_VECM_LSB (address of Vector threshold reg), write in Active or Standby
+                    d[1] = 0b00000011;                                //set impact threshold to less than 1g for now                   
+  //                 d[1] = uint8_t(256*((1000*Impact_Thresh/0.488)%256));  //set MSB Impact threshold - Resolution 0.488mg/LSB so 0.5g=1024.6 => MSB=0b00000100 LSB=0b00000000 
+                    if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
+                        oled.Label((uint8_t *)" Step4b error ",30,05); // Display "error" at x,y 
+                        wait(3.0); // display for 3 seconds
+                    }//end if             
+                     
+                    d[0] = 0x62;                                    //A_VECM_COUNT (address of Vector debounce counter), write in Active or Standby
+                    d[1] = 0b00000110;                              //with ODR at 100Hz, should equal ??mS debounce time or ??mS in Sleep
+                    if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
+                        oled.Label((uint8_t *)" Step5 error ",30,05); // Display "error" at x,y 
+                        wait(3.0); // display for 3 seconds
+                    }//end if 
+                           
+                   // Registers 0x63 - 0x68 are vector reference values which I'm leaving set to 0 because we want absolute measurements    
+                                  
+                    d[0] = 0x2b;                                    //CTRL_REG2 (address of control reg), write in Standby only
+                    d[1] = 0b00001101;                              //Turns Auto-Sleep mode on and low-noise, low power
+                    if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
+                        oled.Label((uint8_t *)" Step6 error ",30,05); // Display "error" at x,y 
+                        wait(3.0); // display for 3 seconds
+                    }//end if    
                     
+                    d[0] = 0x2c;                                    //CTRL_REG3 (address of Int control reg), write in Standby only
+                    d[1] = 0b00000100;                              //Vector will wake chip from sleep, int are active high
+  //                  d[1] = 0b00001000;                              //FFMT will wake chip from sleep, int are active high
+                    if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
+                        oled.Label((uint8_t *)" Step7 error ",30,05); // Display "error" at x,y 
+                        wait(3.0); // display for 3 seconds
+                    }//end if    
+                        
+                    d[0] = 0x2d;                                    //CTRL_REG4 (address of Int enable reg), write in Standby only
+                    d[1] = 0b00000010;                              // Vector int enabled
+ //                   d[1] = 0b00000100;                              // FFMT int enabled 
+                    if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
+                        oled.Label((uint8_t *)" Step8 error ",30,05); // Display "error" at x,y 
+                        wait(3.0); // display for 3 seconds
+                    }//end if            
+                    wait(0.2);  // people have had a problem here and needed a delay
+                    d[0] = 0x2e;                                    //CTRL_REG5 (Int routing reg), write in Standby only
+                    d[1] = 0b00000100;                              // Make FFMT int output on pin INT1(PTC1) and Vector on INT2(PTD13)
+                    if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
+                        oled.Label((uint8_t *)" Step9 error ",30,05); // Display "error" at x,y 
+                        wait(3.0); // display for 3 seconds
+                    }//end if                  
+                    
+                    d[0] = FXOS8700_CTRL_REG1;                     //CTRL_REG1, write in Standby only except for bit[0]
+                    d[1] = 0b00011001;                              //Auto-Sleep mode on set to 50Hz, ODR set to 100Hz Puts device back into Active mode 
+                    if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
+                        oled.Label((uint8_t *)" Step10 error ",30,05); // Display "error" at x,y 
+                        wait(3.0); // display for 3 seconds
+                    }//end if  
+                    
+                    //oled.FillScreen(COLOR_BLACK); // Clear screen
+                    oled.Label((uint8_t *)" Mode 2 ",30,60); // Display "mode" at x,y   
+                    oled.Label((uint8_t *)"Imp ",30,75); // Display "mode" at x,y 
+                    break;
+                }// end of case 2    
+                               
+                 case 3: {// configure FFMT for free-fall event AND config for vector impact
+
+                    char d[2]; 
+                    
+                    d[0] = 0x2a;                                    //0x2a Config reg1,  
+                    d[1] = 0x00;                                    //Put device in Standby mode
+                    if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
+                        oled.Label((uint8_t *)" Step1 error ",30,05); // Display "error" at x,y                  
+                        wait(3.0); // display for 3 seconds
+                    }//end if 
+ 
+                    d[0] = 0x0e;                                    //XYZ_DATA_CFG (set full-scall range)
+                    d[1] = 0b00000001;                              //Set data to +/-4g for full range (0.488mg/LSB), High-pass filter off
+                    if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
+                        oled.Label((uint8_t *)" Step1a error ",30,05); // Display "error" at x,y      
+                        wait(3.0); // display for 3 seconds
+                    }//end if
+ /*
+                    d[0] = 0x0a;                                    //TRIG_CFG (address of FIFO trigger config reg)
+                    d[1] = 0b00000110;                              //Trigger on freefall and on Vector
+                    if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
+                        oled.Label((uint8_t *)" Step2 error ",30,05); // Display "error" at x,y      
+                        wait(3.0); // display for 3 seconds
+                    }//end if
+  */                  
                     d[0] = 0x15;                                    //A_FFMT_CFG (address of Free fall trigger config reg), write in Standby only
                     d[1] = 0b00111000;                              //set to freefall, and look at all axis.
                     if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
@@ -2018,7 +2566,7 @@
                     }//end if
                        
                     d[0] = 0x60;                                    //A_VECM_MSB (address of Vector threshold reg), write in Active or Standby
-                    d[1] = 0b00001111;                                //set impact threshold to less than 1g for now                   
+                    d[1] = 0b00000111;                                //set impact threshold to less than 1g for now                   
   //                 d[1] = uint8_t((1000*Impact_Thresh/0.488)/256);        //set MSB Impact threshold - Resolution is 0.488mg/LSB so 0.5g=1024.6 => MSB=0b00000100 LSB=0b00000000 
                     if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
                         oled.Label((uint8_t *)" Step4a error ",30,05); // Display "error" at x,y 
@@ -2062,7 +2610,8 @@
                         oled.Label((uint8_t *)" Step8 error ",30,05); // Display "error" at x,y 
                         wait(3.0); // display for 3 seconds
                     }//end if            
-                 
+                    wait(0.2);  // people have had a problem here and needed a delay
+                    
                     d[0] = 0x2e;                                    //CTRL_REG5 (Int routing reg), write in Standby only
                     d[1] = 0b00000100;                              // Make FFMT int output on pin INT1(PTC1) and Vector on INT2(PTD13)
                     if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
@@ -2070,7 +2619,7 @@
                         wait(3.0); // display for 3 seconds
                     }//end if                  
                     
-                    d[0] = FXOS8700_CTRL_REG1;                     //CTRL_REG1, write in Standby only except for bit[0]
+                    d[0] = 0x2a;                          //0x2a Config reg1, write in Standby only except for bit[0]
                     d[1] = 0b00011001;                    //Auto-Sleep mode on set to 50Hz, ODR set to 100Hz Puts device back into Active mode 
                     if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
                         oled.Label((uint8_t *)" Step10 error ",30,05); // Display "error" at x,y 
@@ -2078,25 +2627,60 @@
                     }//end if  
                     
                     //oled.FillScreen(COLOR_BLACK); // Clear screen
-                    oled.Label((uint8_t *)" Mode 3 ",30,60); // Display "mode" at x,y   
-          //          GRN_Led = LED_ON;  // LEDs default to on, need to turn on  
- 
-
+                    oled.Label((uint8_t *)" Mode 3 ",30,60); // Display "mode" at x,y
+                    oled.Label((uint8_t *)"FF & Imp",30,75); // Display "mode" at x,y    
                     break;
                 }// end of case 3
                        
                 case 10: {// reset IC 
                   char d[2]; 
+                    d[0] = 0x2a;                          //0x2a Config reg1
+                    d[1] = 0x00;                                    //Put device in Standby mode
+                    if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
+                        oled.Label((uint8_t *)" Step1 error ",30,05); // Display "error" at x,y                  
+                        wait(3.0); // display for 3 seconds
+                    }//end if
+                       
                     d[0] = 0x2b;                                //CTRL_REG2 
                     d[1] = 0b01000000;                          // set bit to force reset of FXOS8700 
                     if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
                         oled.Label((uint8_t *)" Reset error ",30,05); // Display "error" at x,y 
                         wait(3.0); // display for 3 seconds
                     }//end if    
-                    oled.Label((uint8_t *)" reset ",30,60); // Display "reset" at x,y
+                    oled.Label((uint8_t *)" Reset ",30,45); // Display "reset" at x,y
                     break;
                 }// end case 10      
                 
+                case 11: {// wake for read, was in stanby
+                  char d[2];
+                    d[0] = FXOS8700_CTRL_REG1;                     //Puts device in Standby mode just in case
+                    d[1] = 0x00; 
+                    i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2); 
+                      
+                    d[0] = 0x0e;                                    //XYZ_DATA_CFG (set full-scall range)
+                    d[1] = 0b00000001;                              //Set data to +/-4g for full range (0.488mg/LSB), High-pass filter off
+                    i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2);  
+                                               
+                    /*For lowest power ~8uA, set ODR-12.5Hz,(low-pwr accel mode) or 2uA in standby mode */        
+                    d[0] = 0x2a;                          //0x2a Config reg1, write in Standby only except for bit[0]
+                    d[1] = 0b00011001;                    //Auto-Sleep mode on set to 50Hz, ODR set to 100Hz Puts device back into Active mode 
+                    i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d, 2);
+                    break;
+                }// end of case 11 
+                
+                case 12: {// put into standby
+                  char d[2]; 
+                    d[0] = FXOS8700_CTRL_REG1;                     //Puts device in Standby mode
+                    d[1] = 0x00; 
+                    i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2);                  
+                    
+                    /*For lowest power ~8uA, set ODR-12.5Hz,(low-pwr accel mode) or 2uA in standby mode */
+                    
+
+                    break;
+                }// end of case 11             
+                
+                
                 default: {
                     oled.Label((uint8_t *)" Mode ? ",30,60); // Display "mode" at x,y
                     // unknown config
@@ -2106,3 +2690,98 @@
 
 }// end Fall_config
 
+/*****************************************************************************
+Name: update_display_date
+Purpose: Updating display data without updating any data labels.  This keeps
+measurements and time values current while reducing screen flicker.
+******************************************************************************/
+void update_display_date(void)
+{
+    oled_text_properties_t textProperties = {0};  // Need these to change font color
+    oled.GetTextProperties(&textProperties);      // Need these to change font color
+    __disable_irq();    // Disable all Interrupts
+    
+        switch(Screen_Num) {
+    case 0: {// Main Screen
+            HexiwearBattery battery;
+            battery.sensorOn();  
+            if (battery.isBatteryCharging()) {
+            textProperties.fontColor = COLOR_GREEN;
+            oled.SetTextProperties(&textProperties);  
+                     
+            sprintf(text_1, "%i%%+", (uint8_t)battery.readLevelPercent());
+  //          Screen_Timer.attach(&timout_timer,(SCRN_TIME));// Reset/restart ticker timer for OLED while fully charged
+            } else {
+            sprintf(text_1, "%i%%", (uint8_t)battery.readLevelPercent());
+            }
+            oled.TextBox((uint8_t *)text_1,60,0,35,15); //show level value of battery in a 35px by 15px text box at x=60, y=0
+
+            textProperties.fontColor = COLOR_WHITE;
+            oled.SetTextProperties(&textProperties);  
+           
+// added real time and date information            
+            char buffer[32];
+            time_t seconds = time(NULL);
+            strftime(buffer,32, "%a,%d %m %Y.%H:%M:%S\r", localtime(&seconds));
+//        sprintf(text_1,"%c%c/%c%c/%c%c%c%c ",buffer[7],buffer[8],buffer[4],buffer[5],buffer[10],buffer[11],buffer[12],buffer[13]);
+//        oled.Label((uint8_t *)text_1,20,20);// Date at x,y
+            sprintf(text_1,"%c%c:%c%c:%c%c ",buffer[15],buffer[16],buffer[18],buffer[19],buffer[21],buffer[22]);
+            oled.Label((uint8_t *)text_1,25,40);// Time at x,y
+   
+            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
+            break;
+        }// end case 0
+                     
+            case 21: {// Fall Alert Diagnostic Screen
+            if(Fall_Alert_Mode == 0){
+                fall_config(11); // turn accel sensor to active to take reading
+            }
+            textProperties.fontColor = COLOR_WHITE;
+            oled.SetTextProperties(&textProperties);
+            gyro.acquire_gyro_data_dps(Gyro_Data);
+            Gyro_Mag = (abs(Gyro_Data[0])+abs(Gyro_Data[1])+abs(Gyro_Data[2]));
+            sprintf(text_1," %4.0f D/S  ",Gyro_Mag);
+            oled.Label((uint8_t *)text_1,42,60);// text_1 at x,y
+            
+            accel.acquire_accel_data_g(Accel_Data);
+            if(Fall_Alert_Mode == 0){
+                fall_config(12); // turn accel sensor back to standby
+            }
+            Accel_Mag = 2*sqrt(((Accel_Data[0]*Accel_Data[0])+(Accel_Data[1]*Accel_Data[1])+(Accel_Data[2]*Accel_Data[2])));
+            sprintf(text_1," %2.2f g  ",Accel_Mag);
+            oled.Label((uint8_t *)text_1,44,40);// text_1 at x,y
+            if(Accel_Mag > Fall_Thresh + 0.1 && Led_clk2 == 1){// are we stuck in limbo?
+            fall_det_end(); 
+            }
+            break;
+        }//end case 21       
+            
+            default: {
+                    // do nothing for other screens
+             break;
+                } 
+    }// end switch   
+    __enable_irq();     // Enable all Interrupts 
+}// end of update_display_date
+
+
+/*****************************************************************************
+Name: BLUETOOTH
+Purpose: HexiHeart Connecction
+Inputs: None
+Returns: None
+******************************************************************************/
+
+
+void txTask(void)
+{
+
+    while (true) {
+        /*Notify Hexiwear App that it is running Sensor Tag mode*/
+ /*    This part was not compiling   
+      kw40z_device.SendSetApplicationMode(GUI_CURRENT_APP_SENSOR_TAG);
+ */     
+    }
+}
\ No newline at end of file