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:
Wed Mar 28 21:47:04 2018 +0000
Parent:
10:eaea844e763c
Child:
12:fd39a7983e06
Commit message:
v2.10 - Added BLE pairing code (need to test it), spoofing amb light sensor data for alert status.

Changed in this revision

Hexi_KW40Z.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Hexi_KW40Z.lib	Mon Mar 26 00:29:18 2018 +0000
+++ b/Hexi_KW40Z.lib	Wed Mar 28 21:47:04 2018 +0000
@@ -1,1 +1,1 @@
-https://developer.mbed.org/teams/Hexiwear/code/Hexi_KW40Z/#f6f9b24aea57
+https://developer.mbed.org/teams/Hexiwear/code/Hexi_KW40Z/#3f5ed7abc5c7
--- a/main.cpp	Mon Mar 26 00:29:18 2018 +0000
+++ b/main.cpp	Wed Mar 28 21:47:04 2018 +0000
@@ -1,8 +1,14 @@
 /**********************************************************************
-Texas State University Senior Project - HexiHeart 
-Team Zeta: Alex Song, Jasmine Rounsaville, Issam Hichami, Neil Baker
+HexiHeart
+Texas State University Senior Project - Fall 2017/Spring 2018 
 
-Program layout:
+Team Zeta: 
+Alex Song           - https://www.linkedin.com/in/alex-song-a12632134/
+Jasmine Rounsaville - https://www.linkedin.com/in/jasmine-rounsaville/
+Issam Hichami       - https://www.linkedin.com/in/issam-hichami-06878aa3/
+Neil Baker          - https://www.linkedin.com/in/neil-baker-41602a23/
+
+ ****** Program layout********
 Declarations
 Up Button routines
 Down Button routines
@@ -13,6 +19,10 @@
 Function and interupt routines
 Display data screen update routines
 
+**************   Versions  ****************
+v2.10 - Adding BLE pairing code, spoofing amb light sensor data for alert status 
+light=10 =>Panic Alert, 20=Fall+asked for help, 30=Fall+No responce, 40=?...
+
 v2.09 - Added final fall mode (full sequential fall algorithm), including alert screen 
 and dismiss alert screen.  Added FAP (Fall Alert Protection) to main screen. fixed "aggressive Haptic" problem by using a Ticker to 
 turn off Haptic instead of RTOS timer.
@@ -29,7 +39,6 @@
 This version has basic menu layout and screen timeout feature.  The menu
 are just placeholders (for the most part) and will be either adjusted or
 replaced with graphic images.
-
 ***********************************************************************/
 
 #include "mbed.h"
@@ -49,8 +58,8 @@
 #include "images.h"
 
 
-// Definitions
-#define SW_Ver          2.09    // For displaying software version
+//***************  Definitions
+#define SW_Ver          2.10    // For displaying software version
 #define LED_ON          0
 #define LED_OFF         1
 #define SCRN_TIME       10.0
@@ -108,6 +117,7 @@
 void motion_detect_debug();     // Interupt routine
 void chkmotion(void);           // Routine used with Ticker
 void chk_help_needed(void);      // Routine used with Ticker
+void txTask(void);
 void MAX30101_test_config(uint8_t);
 void Send_Alert(uint8_t);    // fuction to store and send alert
 
@@ -115,7 +125,7 @@
 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
+bool BLE_On = 1;            // Initialize as BLE on
 char pass [20];              // Passcode
 bool Led_Zones = 1;
 bool HR_Enable = 0;
@@ -208,6 +218,9 @@
 /* Define timer for haptic feedback */
 RtosTimer hapticTimer(StopHaptic, osTimerOnce);
 
+/*Create a Thread to handle sending BLE Sensor Data */ 
+//Thread txThread;
+
 //***************** Interrups *****************
 InterruptIn Accel_INT1(PTC1);       // Accel sensor's interupt 1
 InterruptIn Accel_INT2(PTD13);      // Accel sensor's interupt 2
@@ -224,6 +237,7 @@
 Ticker chk_fall; // Ticker used to check on active fall
 Ticker chk_motion; // Ticker used to check on post fall motion
 Ticker Haptic_Timer;
+Ticker WDT;
 
 void timout_timer(){ // turn off display mode
 #ifdef Debug    // in debug keep screens on for demo  
@@ -235,7 +249,8 @@
         } //end if
     else {
 #endif        
-//  oled.FillScreen(COLOR_BLACK); // Clear screen.. is there a better command for this?
+   /* Turn on the backlight of the OLED Display */
+    //oled.DimScreenON(); just dim display for debug
      OLED_PWR = 0;  // Turn off OLED power supply
      OLED_ON = 0;  // set flag to off
      Screen_Timer.detach();  // detach Ticker
@@ -244,6 +259,17 @@
 #endif   
 }//end routine
 
+void PassKey(void)
+{
+    Screen_Timer.attach(&timout_timer,(SCRN_TIME));//Is this sufficient to reset/restart ticker timer for OLED?
+    if (OLED_ON == 0) {
+        OLED_ON = 1; // Scree was off, set to On
+    }
+        Screen_Num = 72;  //Change to screen BLE screen 72
+        StartHaptic();
+        update_display();
+}// PassKey
+
 void ButtonUp(void)
 {
     Screen_Timer.attach(&timout_timer,(SCRN_TIME));//Is this sufficient to reset/restart ticker timer for OLED?
@@ -294,7 +320,7 @@
                 StartHaptic();
                 Panic_Alert = !Panic_Alert;
                 if(Panic_Alert == 1){
-                Send_Alert(0); // send/store alert type zero
+                Send_Alert(10); // send/store alert type zero
                 }//endif
                 update_display();
                 break;
@@ -869,7 +895,7 @@
             }         
             case 47: {// Fall-Detected screen "are you ok?"
                 StartHaptic();
-                Send_Alert(1); // send/store alert type one
+                Send_Alert(20); // send/store alert type one
                 Screen_Num = 48;  //Change to screen 48 (send alert screen)
                 update_display();
                 break;
@@ -883,6 +909,7 @@
              case 72: {// BlueTooth on/off
                 StartHaptic();
                 BLE_On = !BLE_On;
+                kw40z_device.ToggleAdvertisementMode();
                 update_display();
                 break;
             }           
@@ -1195,6 +1222,7 @@
     kw40z_device.attach_buttonLeft(&ButtonLeft);
     kw40z_device.attach_buttonRight(&ButtonRight);
  //   kw40z_device.attach_buttonSlide(&ButtonSlide);
+     kw40z_device.attach_passkey(&PassKey);
 
 // ***** attaching interupts to functions *********
     //Accel_INT1.fall(&fall_detect); // Accel sensor's int#1 (PTC1) calls interupt routine (now setup in fall_config())
@@ -1203,6 +1231,8 @@
     //Gyro_INT2.fall(&motion_detect); // Gyro sensor's int#2 (PTC18) calls interupt routine (not used)
     //HR_INT1.fall(&some_HR_read_function_yet_to_be_named); // MAX30101 - Heart rate sensor's interupt (PTB18)
 
+
+    
 // **** Get OLED Class Default Text Properties ****************
     oled_text_properties_t textProperties = {0};
     oled.GetTextProperties(&textProperties);
@@ -1240,7 +1270,8 @@
     oled.SetTextProperties(&textProperties);
     wait(2);  // wait 3 seconds
     
-
+   // txThread.start(txTask); /*Start transmitting Sensor Tag Data */
+    
     update_display(); // Displays current screen (screen 0)
     Screen_Timer.attach(&timout_timer,(SCRN_TIME));//start ticker timer for turning off LCD
 //  ******************* Main Loop *************************
@@ -2124,10 +2155,12 @@
 
         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",60,80);  //Display at x,y
+            textProperties.fontColor = COLOR_BLUE;
+            oled.SetTextProperties(&textProperties);
+            oled.Label((uint8_t *)"BLUETOOTH",10,5); // Display at x,y
             textProperties.fontColor = COLOR_WHITE;
             oled.SetTextProperties(&textProperties);
+            oled.Label((uint8_t *)"Enter",60,80);  //Display 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
@@ -2135,20 +2168,23 @@
         }
 
         case 72: {// BlueTooth on/off
-            oled.FillScreen(COLOR_BLACK); // Clear screen
-            oled.Label((uint8_t *)"BLUETOOTH",5,5); // Display at x,y
+           oled.FillScreen(COLOR_BLACK); // Clear screen
+            textProperties.fontColor = COLOR_BLUE;
+            oled.SetTextProperties(&textProperties);
+            oled.Label((uint8_t *)"BLUETOOTH",10,5); // Display at x,y
+            textProperties.fontColor = COLOR_WHITE;
+            oled.SetTextProperties(&textProperties);
             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
+                /* Display PAIR CODE in a 90px by 18px textbox at x=0,y=25 */
+                strcpy((char *) text,"PAIR CODE");
+                oled.TextBox((uint8_t *)text,10,25,80,18);
+
+                /* Display Bond Pass Key in a 90px by 18px textbox at x=0,y=40 */
                 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
+                oled.TextBox((uint8_t *)text,10,45,80,18);
             } else {
-                oled.Label((uint8_t *)" Off ",40,40);
+                oled.Label((uint8_t *)" Off ",40,45);
             }
   //          oled.Label((uint8_t *)"*",85,15); // "*" at x,y
   //          oled.Label((uint8_t *)"*",85,60); // "*" at x,y
@@ -2884,7 +2920,7 @@
         oled.Label((uint8_t *)"No responce!", 5, 20);
         textProperties.fontColor = COLOR_WHITE;
         oled.SetTextProperties(&textProperties);
-        Send_Alert(2); // send alert type two     
+        Send_Alert(30); // send alert type two     
         haptic = 1;
         wait(0.5);// very aggressive hapic
         haptic = 0;
@@ -2905,13 +2941,21 @@
 Name: Send_Alert()
 Purpose: routine used to store and send alert
 Inputs: int value from 0 to 256
-0=Panic, 1=Fall+asked for help, 2=Fall+No responce, 3=?
+10=Panic, 20=Fall+asked for help, 30=Fall+No responce, 40=?...
 Returns: None
 ******************************************************************************/
 void Send_Alert(uint8_t Num){
     
     // store alert
-    // transmit alert
+    
+    
+    // ************ transmit alert
+     /*Notify Hexiwear App that it is running Sensor Tag mode*/
+        kw40z_device.SendSetApplicationMode(GUI_CURRENT_APP_SENSOR_TAG);
+               
+        /*Send Ambient Light Level at with aler number */ 
+        //10=Panic, 20=Fall+asked for help, 30=Fall+No responce, 40=?...
+        kw40z_device.SendAmbientLight(Num);
     
     }//end Send_Alert routine
 
@@ -3891,7 +3935,19 @@
             }
             break;
         }//end case 21       
-            
+        case 72: {// BlueTooth on/off
+            textProperties.fontColor = COLOR_WHITE;
+            oled.SetTextProperties(&textProperties);
+            if (BLE_On == 1) {
+                /* re-Display Bond Pass Key in a 90px by 18px textbox at x=0,y=40 */
+                sprintf(text,"%d", kw40z_device.GetPassKey());
+                oled.TextBox((uint8_t *)text,10,45,80,18);
+            } else {
+                // do nothing, don't update when not active
+            }
+
+            break;
+        }// end case 72
             default: {
                     // do nothing for other screens
              break;
@@ -3902,20 +3958,43 @@
 
 
 /*****************************************************************************
-Name: BLUETOOTH
+Name: txTask()
 Purpose: HexiHeart Connecction
 Inputs: None
 Returns: None
 ******************************************************************************/
 
-
-void txTask(void)
+void txTask(void)// we're not really using this because we arn't always transmitting
 {
-
     while (true) {
+        // update sensor data
+        
         /*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
+        kw40z_device.SendSetApplicationMode(GUI_CURRENT_APP_SENSOR_TAG);
+        
+        /* send sensor data
+        
+        //Send Battery Level 
+        kw40z_device.SendBatteryLevel(battery);
+               
+        //Send Ambient Light Level 
+        kw40z_device.SendAmbientLight(light);
+        
+        //Send Humidity 
+        kw40z_device.SendHumidity(humidity);
+        
+        //Send Temperature  
+        kw40z_device.SendTemperature(temperature);
+
+        //Send Pressure 
+        kw40z_device.SendPressure(pressure);
+        
+        //Send Mag,Accel,Gyro Data. 
+        kw40z_device.SendGyro(x,y,z);
+        kw40z_device.SendAccel(z,x,y);
+        kw40z_device.SendMag(y,z,x);
+        
+        */  
+        Thread::wait(1000);  
+    }// end while
+}// end TxTask
\ No newline at end of file