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

Files at this revision

API Documentation at this revision

Comitter:
nbaker
Date:
Tue May 01 15:13:45 2018 +0000
Parent:
18:1f28eca85e3f
Child:
20:990951205fbd
Commit message:
v2.16 - Cast rolling average calculations as float to reduce rounding error. removed two screens from diagnostic because we don't use them.; Changed FAP to AFP in two locations.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Mon Apr 16 12:33:00 2018 +0000
+++ b/main.cpp	Tue May 01 15:13:45 2018 +0000
@@ -8,7 +8,8 @@
 Issam Hichami       - https://www.linkedin.com/in/issam-hichami-06878aa3/
 Neil Baker          - https://www.linkedin.com/in/neil-baker-41602a23/
 You can find more about Team Zeta here: https://os.mbed.com/teams/Hexiwear_zeta/
- ****** Program layout********
+
+******Basic Program layout********
 Declarations
 Up Button routines
 Down Button routines
@@ -20,7 +21,11 @@
 Display data screen update routines
 
 **************   Versions  ****************
-v2.15 - added display screens 41 and 42 back in.
+v2.16 - Cast rolling average calculations as float to reduce rounding error. 
+removed two screens from diagnostic because we don't use them.
+Changed FAP to AFP in two locations.  
+
+v2.15 - added display screens 41 and 42 back in. 
 
 v2.14 - Retasked hr_led Ticker to turn off heart rate zone LEDs thereby preventing the 
 system from having to spend half its time in a wait state. added HR screen #7 to  
@@ -77,16 +82,16 @@
 
 
 /* General  Definitions */
-#define SW_Ver          2.15    // For displaying software version
+#define SW_Ver          2.16    // For displaying software version
 #define LED_ON          0
 #define LED_OFF         1
 #define SCRN_TIME       10.0    // Set OLED screen turn off time to 10.0 seconds
 #define WDT_TIME        2.0     // Set Watch Dog timer to 1.5 seconds (1.5s reset in certain subroutines)
-#define MAX_AVE_NUM     10       // maximum averaging depth of rolling average for batt, temp and humid
+#define MAX_AVE_NUM     10.0f       // maximum averaging depth of rolling average for batt, temp and humid
 #define Debug           1       // If "Debug" is defined, our code will compile for debug.  Comment out for Production code.
 
-#define FXOS8700_I2C_ADDRESS_ (0x1E<<1) //pins SA0,SA1=0 
-#define FXAS21002_I2C_ADDRESS_ 0x40      //
+#define FXOS8700_I2C_ADDRESS_ (0x1E<<1) //I2C address, pins SA0,SA1=0 
+#define FXAS21002_I2C_ADDRESS_ 0x40      //I2C address
 //#define TSL2561_I2C_ADDRESS_  (0x29 << 1) // Address select line is grounded
 //#define MPL3115A2_I2C_ADDRESS_  ? // 
 
@@ -269,7 +274,7 @@
 int sample_ftemp = 0;               // used in Heat index calc
 int sample_humid = 0;               // used in Heat index calc
 uint8_t batt_per_level = 0;         //
-uint8_t Ave_Num  = 0; 
+float Ave_Num  = 0.0; 
 
 
 // Pointers for screen images 
@@ -347,6 +352,9 @@
 Ticker hr_ticker;
 Ticker hr_measure_ticker;
 
+
+    
+    
 /*****************************************************************************
 Name: timout_timer()
 Purpose: Ticker interupt routine used to dim the OLED screen 3s before turning screen off
@@ -502,13 +510,13 @@
                 update_display();
                 break;
             }
-            case 23: {// Heart Rate Diagnostic
+            case 23: {// Heart Rate Diagnostic - not used 
                 StartHaptic();
                 Screen_Num = 22;  //Change to screen 22
                 update_display();
                 break;
             }
-            case 24: {// Heart Rate Debug
+            case 24: {// Heart Rate Debug - not used
                 StartHaptic();
                 Screen_Num = 23;  //Change to screen 23
                 update_display();
@@ -516,7 +524,7 @@
             }
             case 25: {// Heat Index Diagnostic
                 StartHaptic();
-                Screen_Num = 24;  //Change to screen 24
+                Screen_Num = 21;  //Change to screen 24
                 update_display();
                 break;
             }
@@ -755,17 +763,17 @@
             }
             case 22: {// Fall Debug
                 StartHaptic();
-                Screen_Num = 23;  //Change to screen 23
+                Screen_Num = 25;  //Change to screen 23
                 update_display();
                 break;
             }
-            case 23: {// Heart Rate Diagnostic
+            case 23: {// Heart Rate Diagnostic - not used
                 StartHaptic();
                 Screen_Num = 24;  //Change to screen 24
                 update_display();
                 break;
             }
-            case 24: {// Heart Rate Debug
+            case 24: {// Heart Rate Debug - not used
                 StartHaptic();
                 Screen_Num = 25;  //Change to screen 25
                 update_display();
@@ -1429,7 +1437,8 @@
 //set_time(48*365*24*3600 + 61*24*3600 + 10*3600-4);  // Set RTC time to Mon, 19 Feb 2018 10:00
 //set_time((2018-1970)*365.25f*24*3600 + (31+28+1-1)*24*3600 + (16)*3600 + (5)*60+ (1) + 38);  // Set RTC time to 3/01/2018 16:04:20
 //set_time((2018-1970)*365.25f*24*3600 + (31+28+26-1)*24*3600 + (10)*3600 + (0)*60+ (0) + 28);  // Set RTC time to 3/26/2018 9:59:31
-    set_time((2018-1970)*365.25f*24*3600 + (31+28+31+18-1)*24*3600 + (10)*3600 + (0)*60+ (0) + 29);  // Set RTC time to 4/18/2018 9:59:31
+ //   set_time((2018-1970)*365.25f*24*3600 + (31+28+31+18-1)*24*3600 + (10)*3600 + (0)*60+ (0) + 29);  // Set RTC time to 4/18/2018 9:59:31
+    set_time((2018-1970)*365.25f*24*3600 + (31+28+31+30+10-1)*24*3600 + (13)*3600 + (15)*60+ (0) + 29);  // Set RTC time to 5/10/2018 9:59:31
     RED_Led = LED_OFF;
     GRN_Led = LED_OFF;
     BLU_Led = LED_OFF;
@@ -1480,6 +1489,8 @@
     kw40z_device.attach_buttonLeft(&ButtonLeft);
     kw40z_device.attach_buttonRight(&ButtonRight);
  //   kw40z_device.attach_buttonSlide(&ButtonSlide);
+ //   kw40z_device.attach_alert(&TimeSet);
+     //kw40z_device.attach_alertIn(&TimeSet);
      kw40z_device.attach_passkey(&PassKey);
 
 // ***** attaching interupts to functions *********
@@ -1630,7 +1641,7 @@
                 textProperties.fontColor = COLOR_RED; // is impact detected? 
             }       
             oled.SetTextProperties(&textProperties); 
-            oled.Label((uint8_t *)"FAP",3,0);  //Display "FAP" at x,y
+            oled.Label((uint8_t *)"AFP",3,0);  //Display "FAP" at x,y
             textProperties.fontColor = COLOR_WHITE;
             oled.SetTextProperties(&textProperties);
            
@@ -1677,7 +1688,7 @@
             oled.FillScreen(COLOR_BLACK); // Clear screen
             oled.Label((uint8_t *)"Fall Alert",20,5); // Display at x,y
             oled.Label((uint8_t *)"Protection",15,20);  
-            oled.Label((uint8_t *)"FAP",15,40); 
+            oled.Label((uint8_t *)"AFP",15,40); 
             if (Fall_Alert == 1){  
            
             textProperties.fontColor = COLOR_GREEN; 
@@ -2975,9 +2986,9 @@
 Returns: None
 ******************************************************************************/
 void Heat_Index_Calculation(){
-    //sample_ftemp = temphumid.sample_ftemp();
+    //sample_ftemp = temphumid.sample_ftemp(); // sampling is now done in rolling UpDate_Ave() function
  
-    //sample_humid = temphumid.sample_humid();
+    //sample_humid = temphumid.sample_humid(); // sampling is now done in rolling UpDate_Ave() function 
             
     hi_calc = -42.379 +
            2.04901523 * sample_ftemp +
@@ -4564,7 +4575,7 @@
     //int i = 4; // used in rolling average
     HexiwearBattery battery;
     battery.sensorOn();  
-    if(Ave_Num == 0){  
+    if(Ave_Num == 0.0f){  
     // this is first measurement since reboot         
     batt_per_level = (uint8_t)battery.readLevelPercent();
     sample_ftemp = temphumid.sample_ftemp();
@@ -4572,13 +4583,13 @@
     }//end if
     else{
     // updated measurments on a rolling average basis: 1/4 new measurement to 3/4 running average
-    batt_per_level = (uint8_t)((Ave_Num-1)*batt_per_level/Ave_Num + battery.readLevelPercent()/Ave_Num);
-    sample_ftemp = (Ave_Num-1)*sample_ftemp/Ave_Num + temphumid.sample_ftemp()/Ave_Num;
-    sample_humid = (Ave_Num-1)*sample_humid/Ave_Num + temphumid.sample_humid()/Ave_Num;  
+    batt_per_level = (uint8_t)((Ave_Num-1)*batt_per_level/Ave_Num + battery.readLevelPercent()/Ave_Num); // do calculation as a float but return an uint8
+    sample_ftemp = (int)(Ave_Num-1)*sample_ftemp/Ave_Num + temphumid.sample_ftemp()/Ave_Num;      
+    sample_humid = (int)(Ave_Num-1)*sample_humid/Ave_Num + temphumid.sample_humid()/Ave_Num;      
         }//end else
-    Ave_Num++;
+    Ave_Num = Ave_Num + 1;
     if(Ave_Num > MAX_AVE_NUM){
-        Ave_Num = MAX_AVE_NUM;//set limit 
+        Ave_Num = MAX_AVE_NUM;  //set limit 
         }    
 }// end UpDate_Ave