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

Committer:
jmr274
Date:
Tue Feb 13 05:36:04 2018 +0000
Revision:
5:e1431272be79
Parent:
4:0803151bc5e4
Child:
6:84e3ba00b995
Added Heat Index

Who changed what in which revision?

UserRevisionLine numberNew contents of line
asong 1:e4b38d6918ba 1 /**********************************************************************
asong 1:e4b38d6918ba 2 Texas State University Senior Project - HexiHeart
nbaker 0:d1d36a3da39b 3 Team Zeta: Alex Song, Jasmine Rounsaville, Issam Hichami, Neil Baker
nbaker 0:d1d36a3da39b 4 Version: HexiHeart_1st 11/12/17
nbaker 0:d1d36a3da39b 5 This version has basic menu layout and screen timeout feature. The menu
asong 1:e4b38d6918ba 6 are just placeholders (for the most part) and will be either adjusted or
nbaker 0:d1d36a3da39b 7 replaced with graphic images.
nbaker 0:d1d36a3da39b 8
nbaker 0:d1d36a3da39b 9 ***********************************************************************/
nbaker 0:d1d36a3da39b 10
nbaker 0:d1d36a3da39b 11 #include "mbed.h"
nbaker 0:d1d36a3da39b 12 #include "Hexi_KW40Z.h" // Button and BLE fuctions
nbaker 0:d1d36a3da39b 13 #include "FXOS8700.h" // 3D Accelorometer & Mag
nbaker 0:d1d36a3da39b 14 #include "FXAS21002.h" // 3-Axis Gyroscope
nbaker 0:d1d36a3da39b 15 #include "Hexi_OLED_SSD1351.h" // OLED fuctions
jmr274 5:e1431272be79 16 #include "HTU21D.h" // Non-Freescale HTU21D - combo temperature and Humidity
nbaker 4:0803151bc5e4 17 #include "W25Q64FV.h" // W25Q64FVSSIG Serial Flash
nbaker 4:0803151bc5e4 18 // Non-Freescale MPL3115A2 - pressure sensor
nbaker 4:0803151bc5e4 19 #include "Hexi_Battery/hexi_battery.h" // Battery status
nbaker 0:d1d36a3da39b 20 #include "OLED_types.h" // Text attributs
nbaker 0:d1d36a3da39b 21 #include "string.h"
nbaker 0:d1d36a3da39b 22 #include "OpenSans_Font.h"
nbaker 4:0803151bc5e4 23 #include "MAX30101.h" // Non-Freescale MAX30101 - Optical Heart rate sensor
asong 1:e4b38d6918ba 24
asong 2:824ed4ae8d52 25
asong 1:e4b38d6918ba 26 /* We need to confirm whether it's better to include and
asong 1:e4b38d6918ba 27 configure every module for lowest power, or whether it's
nbaker 0:d1d36a3da39b 28 better to save memory by not doing that
nbaker 0:d1d36a3da39b 29 */
nbaker 0:d1d36a3da39b 30
nbaker 0:d1d36a3da39b 31 // Definitions
asong 2:824ed4ae8d52 32 #define LED_ON 0
asong 2:824ed4ae8d52 33 #define LED_OFF 1
asong 2:824ed4ae8d52 34 #define SCRN_TIME 10.0
asong 2:824ed4ae8d52 35 #define Debug 1 // If "Debug" is defined, our code will compile for debug. Comment out for Production code.
asong 2:824ed4ae8d52 36 #define HIGHEST_ZONE 4
asong 2:824ed4ae8d52 37 #define LOWEST_ZONE 1
asong 2:824ed4ae8d52 38 #define ENTER_BELOW 25
asong 2:824ed4ae8d52 39 #define ENTER_ABOVE 50
asong 2:824ed4ae8d52 40 #define EXIT_BELOW 75
asong 2:824ed4ae8d52 41 #define EXIT_ABOVE 100
asong 2:824ed4ae8d52 42 #define VIB_OPT_2 75
nbaker 4:0803151bc5e4 43 #define FXOS8700_I2C_ADDRESS_ (0x1E<<1) //pins SA0,SA1=0
asong 2:824ed4ae8d52 44
asong 1:e4b38d6918ba 45
nbaker 0:d1d36a3da39b 46 void StartHaptic(void);
asong 1:e4b38d6918ba 47 void StartHaptic(int x);
nbaker 0:d1d36a3da39b 48 void StopHaptic(void const *n);
nbaker 0:d1d36a3da39b 49 void error_screen(void);
nbaker 4:0803151bc5e4 50 void update_display(void);// Screen lables refreshed
nbaker 4:0803151bc5e4 51 void update_data(void); // Screen data(only)refreshed
asong 2:824ed4ae8d52 52 void Decrement_Age();
asong 2:824ed4ae8d52 53 void Set_Max_Bpm();
asong 2:824ed4ae8d52 54 void Set_Zone_Boundaries();
asong 2:824ed4ae8d52 55 void Increment_Age();
asong 2:824ed4ae8d52 56 void Increment_Target_Zone();
asong 2:824ed4ae8d52 57 void Decrement_Target_Zone();
asong 2:824ed4ae8d52 58 void Increment_HR_Vibr_Pref();
asong 2:824ed4ae8d52 59 void Decrement_HR_Vibr_Pref();
asong 2:824ed4ae8d52 60 void Determine_Current_Zone();
asong 2:824ed4ae8d52 61 void Heart_Rate_Vibrations();
asong 2:824ed4ae8d52 62 void Increment_Heart_Rate();
asong 2:824ed4ae8d52 63 void Decrement_Heart_Rate();
asong 2:824ed4ae8d52 64 void Enable_Heart_Rate();
asong 2:824ed4ae8d52 65 void Disable_Heart_Rate();
asong 2:824ed4ae8d52 66 void Led_Zone_Indicator();
jmr274 5:e1431272be79 67 void Heat_Index_Calculation();
nbaker 4:0803151bc5e4 68 void fall_config(uint8_t);
nbaker 4:0803151bc5e4 69 void fall_detect(void);
nbaker 4:0803151bc5e4 70 void fall_det_end(void);
nbaker 4:0803151bc5e4 71 void fall_detect_off(void);
nbaker 4:0803151bc5e4 72 void impact_detect(void);
asong 1:e4b38d6918ba 73
nbaker 0:d1d36a3da39b 74 // ***************** Global variables ***********************
nbaker 0:d1d36a3da39b 75 char text_1[20]; // Text buffer - Do we need more?
asong 2:824ed4ae8d52 76 char display_buff[30]; //Buffer for conversion to char to display
jmr274 5:e1431272be79 77 char text[20]; // Text Buffer for dynamic value displayed
asong 2:824ed4ae8d52 78 bool Led_Zones = 1;
asong 1:e4b38d6918ba 79 bool HR_Enable = 0;
nbaker 0:d1d36a3da39b 80 bool OLED_ON = 1; // Turn OLED power on/off
nbaker 4:0803151bc5e4 81 bool Fall_Alert = 1; // Initialize as no active alert
jmr274 5:e1431272be79 82 bool Panic_Alert = 0; // Initialize as no active alert
jmr274 5:e1431272be79 83 bool Fall_Alert_Mode = 1; // Initialize with fall alert mode on
jmr274 5:e1431272be79 84 bool Heart_Rate_Mode = 0; // Initialize with Heart rate off
nbaker 0:d1d36a3da39b 85 float Accel_Mag=0.0; // Vector magnitude calculated from sensor data
nbaker 0:d1d36a3da39b 86 float Accel_Data[3]; // Accel Data from sensor
jmr274 5:e1431272be79 87 float Gyro_Mag=0.0; // Vector magnitude calculated from sensor data
jmr274 5:e1431272be79 88 float Gyro_Data[3]; // Gyro data from sensor
jmr274 5:e1431272be79 89 float Fall_Thresh=0.5; // Initialize Fall detect Threshold
jmr274 5:e1431272be79 90 float Impact_Thresh=3.0; // Initialize Impact detect Threshold
jmr274 5:e1431272be79 91 float Movement_Thresh=50.0; // Initialize Movement detect Threshold
asong 2:824ed4ae8d52 92 uint8_t Current_Zone = 1;
asong 2:824ed4ae8d52 93 uint8_t Prev_Zone = 1;
asong 2:824ed4ae8d52 94 uint8_t Heart_Rate = 100;
asong 1:e4b38d6918ba 95 uint8_t HR_buff[250];
asong 1:e4b38d6918ba 96 uint8_t *HR_return;
asong 1:e4b38d6918ba 97 uint8_t Age = 50; // Initialize age
asong 2:824ed4ae8d52 98 uint8_t Max_Bpm = 220 - Age; // Initialize Max BPM
nbaker 0:d1d36a3da39b 99 uint8_t Screen_Num = 0; // Initialize to main screen
asong 1:e4b38d6918ba 100 uint8_t Error_Num = 0; // Error num for debug
asong 2:824ed4ae8d52 101 uint8_t HR_Vibration = 2; //Choose Heart Rate Vibration Options
asong 2:824ed4ae8d52 102 uint8_t Target_Zone = 2; //Initialize Target Heart Rate Zone to Zone 3
asong 2:824ed4ae8d52 103 uint8_t HR_Zone1[2] = {Max_Bpm * .50, Max_Bpm * .60}; //Heart Rate Zone 1
asong 2:824ed4ae8d52 104 uint8_t HR_Zone2[2] = {HR_Zone1[1] + 1, Max_Bpm * .70}; //Heart Rate Zone 2
asong 2:824ed4ae8d52 105 uint8_t HR_Zone3[2] = {HR_Zone2[1] + 1, Max_Bpm * .80}; //Heart Rate Zone 3
asong 2:824ed4ae8d52 106 uint8_t HR_Zone4[2] = {HR_Zone3[1] + 1, Max_Bpm}; //Heart Rate Zone 4
jmr274 5:e1431272be79 107 int sample_ftemp;
jmr274 5:e1431272be79 108 int sample_humid;
jmr274 5:e1431272be79 109 int heat_index;
jmr274 5:e1431272be79 110
nbaker 0:d1d36a3da39b 111 // ***************** Define pins *****************************
nbaker 0:d1d36a3da39b 112 FXAS21002 gyro(PTC11,PTC10); // Gyroscope
nbaker 0:d1d36a3da39b 113 SSD1351 oled(PTB22,PTB21,PTC13,PTB20,PTE6, PTD15); // SSD1351 OLED Driver (MOSI,SCLK,POWER,CS,RST,DC)
nbaker 0:d1d36a3da39b 114 FXOS8700 accel(PTC11, PTC10); // Accelorometer
nbaker 0:d1d36a3da39b 115 FXOS8700 mag(PTC11, PTC10); // Mag (same chip as Accel)
asong 1:e4b38d6918ba 116 //MAX30101 heart(PTB1, PTB0); //Heart Rate Chip
jmr274 5:e1431272be79 117 HTU21D temphumid(PTB1,PTB0); // HTU21D Sensor
nbaker 0:d1d36a3da39b 118
nbaker 4:0803151bc5e4 119 // initialize I2C bus for FXOS8700, FXAS-Gyro, MPL-Pressure
nbaker 4:0803151bc5e4 120 I2C i2c_bus1(PTC11, PTC10); // (SDA, SCL)
nbaker 4:0803151bc5e4 121
nbaker 0:d1d36a3da39b 122 DigitalOut RED_Led(LED1);
nbaker 0:d1d36a3da39b 123 DigitalOut GRN_Led(LED2);
nbaker 0:d1d36a3da39b 124 DigitalOut BLU_Led(LED3);
nbaker 0:d1d36a3da39b 125 DigitalOut haptic(PTB9);
nbaker 4:0803151bc5e4 126 DigitalOut Led_clk1(PTA12);
nbaker 4:0803151bc5e4 127 DigitalOut Led_clk2(PTA13);
nbaker 4:0803151bc5e4 128 DigitalOut Led_clk3(PTA14);
nbaker 4:0803151bc5e4 129
nbaker 4:0803151bc5e4 130 DigitalOut OLED_PWR(PTC13); // this pin turns on/off 15V to OLED display
jmr274 5:e1431272be79 131 DigitalOut Non_Free_PWR(PTB13); // this pin turns on/off non-freescale sensors (Pres/Temp/Hum/Light)
jmr274 5:e1431272be79 132 DigitalOut powerEN (PTB12); // Power Enable HTU21D Sensor
nbaker 4:0803151bc5e4 133 DigitalOut HR_PWR(PTA29); // this pin turns on/off Heart rate sensor
jmr274 5:e1431272be79 134 //DigitalIn Sw1(PTA12); //Switch 'T1' on docking station AND Led_clk1!!
jmr274 5:e1431272be79 135 //DigitalIn Sw2(PTA13); //Switch 'T2' on docking station AND Led_clk2!!
jmr274 5:e1431272be79 136 DigitalIn Sw3(PTA15); //Switch 'T3' on docking station
nbaker 4:0803151bc5e4 137
nbaker 0:d1d36a3da39b 138
asong 1:e4b38d6918ba 139 /* Instantiate the Hexi KW40Z Driver (UART TX, UART RX) */
nbaker 0:d1d36a3da39b 140 KW40Z kw40z_device(PTE24, PTE25);
nbaker 0:d1d36a3da39b 141
nbaker 0:d1d36a3da39b 142 /* Define timer for haptic feedback */
nbaker 0:d1d36a3da39b 143 RtosTimer hapticTimer(StopHaptic, osTimerOnce);
nbaker 0:d1d36a3da39b 144
nbaker 4:0803151bc5e4 145 //***************** Interrups *****************
nbaker 4:0803151bc5e4 146 InterruptIn Accel_INT1(PTC1); // Accel sensor's interupt 1
nbaker 4:0803151bc5e4 147 InterruptIn Accel_INT2(PTD13); // Accel sensor's interupt 2
nbaker 4:0803151bc5e4 148
nbaker 0:d1d36a3da39b 149 //***************** Tickers and Timers *****************
nbaker 0:d1d36a3da39b 150 Ticker Screen_Timer;// use ticker to turn off OLED
nbaker 0:d1d36a3da39b 151
nbaker 4:0803151bc5e4 152 void timout_timer(){ // turn off display mode
nbaker 4:0803151bc5e4 153 // oled.FillScreen(COLOR_BLACK); // Clear screen.. is there a better command for this?
nbaker 4:0803151bc5e4 154 OLED_PWR = 0; // Turn off OLED power supply
nbaker 4:0803151bc5e4 155 OLED_ON = 0; // set flag to off
nbaker 4:0803151bc5e4 156 Screen_Timer.detach(); // detach Ticker
asong 1:e4b38d6918ba 157 }//end routine
asong 1:e4b38d6918ba 158
nbaker 0:d1d36a3da39b 159 void ButtonUp(void)
nbaker 0:d1d36a3da39b 160 {
asong 1:e4b38d6918ba 161 Screen_Timer.attach(&timout_timer,(SCRN_TIME));//Is this sufficient to reset/restart ticker timer for OLED?
asong 1:e4b38d6918ba 162 if (OLED_ON == 0) {
asong 1:e4b38d6918ba 163 OLED_ON = 1; // Scree was off, set to On
asong 1:e4b38d6918ba 164 update_display();
asong 1:e4b38d6918ba 165 } else {
asong 1:e4b38d6918ba 166 switch(Screen_Num) {
asong 1:e4b38d6918ba 167 case 0: {// We're in Main Screen
asong 1:e4b38d6918ba 168 // do nothing, wrong button
asong 1:e4b38d6918ba 169 break;
asong 1:e4b38d6918ba 170 }
asong 1:e4b38d6918ba 171 case 1: {// Panic Alert option
asong 1:e4b38d6918ba 172 StartHaptic();
asong 1:e4b38d6918ba 173 Screen_Num = 26; //Change to screen 5
nbaker 0:d1d36a3da39b 174 #ifdef Debug // in debug show debug/diagnostic screens
asong 1:e4b38d6918ba 175 Screen_Num = 26; //Change to screen 20
nbaker 0:d1d36a3da39b 176 #endif
nbaker 0:d1d36a3da39b 177
asong 1:e4b38d6918ba 178 update_display();
asong 1:e4b38d6918ba 179 break;
asong 1:e4b38d6918ba 180 }
asong 1:e4b38d6918ba 181 case 2: {// Fall Alert option
asong 1:e4b38d6918ba 182 StartHaptic();
asong 1:e4b38d6918ba 183 Screen_Num = 1; //Change to screen 1
asong 1:e4b38d6918ba 184 update_display();
asong 1:e4b38d6918ba 185 break;
asong 1:e4b38d6918ba 186 }
asong 1:e4b38d6918ba 187 case 3: {// Heart Rate Monitoring option
asong 1:e4b38d6918ba 188 StartHaptic();
asong 1:e4b38d6918ba 189 Screen_Num = 2; //Change to screen 2
asong 1:e4b38d6918ba 190 update_display();
asong 1:e4b38d6918ba 191 break;
asong 1:e4b38d6918ba 192 }
asong 1:e4b38d6918ba 193 case 4: {// Alert History option
asong 1:e4b38d6918ba 194 StartHaptic();
asong 1:e4b38d6918ba 195 Screen_Num = 3; //Change to screen 3
asong 1:e4b38d6918ba 196 update_display();
asong 1:e4b38d6918ba 197 break;
asong 1:e4b38d6918ba 198 }
asong 1:e4b38d6918ba 199 case 5: {// About HexiHeart
asong 1:e4b38d6918ba 200 StartHaptic();
asong 1:e4b38d6918ba 201 Screen_Num = 4; //Change to screen 4
asong 1:e4b38d6918ba 202 update_display();
asong 1:e4b38d6918ba 203 break;
asong 1:e4b38d6918ba 204 }
asong 1:e4b38d6918ba 205 case 6: {// Panic Alert
asong 1:e4b38d6918ba 206 StartHaptic();
asong 1:e4b38d6918ba 207 Panic_Alert = !Panic_Alert;
asong 1:e4b38d6918ba 208 update_display();
asong 1:e4b38d6918ba 209 break;
asong 1:e4b38d6918ba 210 }
asong 1:e4b38d6918ba 211 case 7: {// Heart Rate Zone
asong 1:e4b38d6918ba 212 StartHaptic(50);
asong 2:824ed4ae8d52 213 Enable_Heart_Rate();
asong 1:e4b38d6918ba 214 //heart.enable();
asong 1:e4b38d6918ba 215 //HR_Enable = 1;
asong 1:e4b38d6918ba 216 //while(HR_Enable == 1)
asong 1:e4b38d6918ba 217 // heart.readRawData(HR_buff, HR_return);
asong 1:e4b38d6918ba 218 //update_display();
asong 1:e4b38d6918ba 219 break;
asong 1:e4b38d6918ba 220 }
asong 1:e4b38d6918ba 221 case 8: {// Alert History
asong 1:e4b38d6918ba 222 StartHaptic();
asong 1:e4b38d6918ba 223 //Increment alert index
asong 1:e4b38d6918ba 224 break;
asong 1:e4b38d6918ba 225 }
asong 1:e4b38d6918ba 226 case 20: {// Diagnostic/Debug Screens
asong 1:e4b38d6918ba 227 StartHaptic();
asong 1:e4b38d6918ba 228 Screen_Num = 5; //Change to screen 5
asong 1:e4b38d6918ba 229 update_display();
asong 1:e4b38d6918ba 230 break;
asong 1:e4b38d6918ba 231 }
asong 1:e4b38d6918ba 232 case 21: {// Fall Diagnostic
asong 1:e4b38d6918ba 233 StartHaptic();
asong 1:e4b38d6918ba 234 Screen_Num = 25; //Change to screen 25
asong 1:e4b38d6918ba 235 update_display();
asong 1:e4b38d6918ba 236 break;
asong 1:e4b38d6918ba 237 }
asong 1:e4b38d6918ba 238 case 22: {// Fall Debug
asong 1:e4b38d6918ba 239 StartHaptic();
asong 1:e4b38d6918ba 240 Screen_Num = 21; //Change to screen 21
asong 1:e4b38d6918ba 241 update_display();
asong 1:e4b38d6918ba 242 break;
asong 1:e4b38d6918ba 243 }
asong 1:e4b38d6918ba 244 case 23: {// Heart Rate Diagnostic
asong 1:e4b38d6918ba 245 StartHaptic();
asong 1:e4b38d6918ba 246 Screen_Num = 22; //Change to screen 22
asong 1:e4b38d6918ba 247 update_display();
asong 1:e4b38d6918ba 248 break;
asong 1:e4b38d6918ba 249 }
asong 1:e4b38d6918ba 250 case 24: {// Heart Rate Debug
asong 1:e4b38d6918ba 251 StartHaptic();
asong 1:e4b38d6918ba 252 Screen_Num = 23; //Change to screen 23
asong 1:e4b38d6918ba 253 update_display();
asong 1:e4b38d6918ba 254 break;
asong 1:e4b38d6918ba 255 }
asong 1:e4b38d6918ba 256 case 25: {// Heat Index Diagnostic
asong 1:e4b38d6918ba 257 StartHaptic();
asong 1:e4b38d6918ba 258 Screen_Num = 24; //Change to screen 24
asong 1:e4b38d6918ba 259 update_display();
asong 1:e4b38d6918ba 260 break;
asong 1:e4b38d6918ba 261 }
asong 1:e4b38d6918ba 262 case 26: {//Heart Rate Config Option
asong 1:e4b38d6918ba 263 StartHaptic();
asong 1:e4b38d6918ba 264 Screen_Num = 20;
asong 1:e4b38d6918ba 265 update_display();
asong 1:e4b38d6918ba 266 break;
asong 1:e4b38d6918ba 267 }
asong 1:e4b38d6918ba 268 case 27: {//Incrementing Age
asong 2:824ed4ae8d52 269 Increment_Age();
asong 2:824ed4ae8d52 270 Set_Zone_Boundaries();
asong 1:e4b38d6918ba 271 update_display();
asong 1:e4b38d6918ba 272 break;
asong 1:e4b38d6918ba 273 }
asong 1:e4b38d6918ba 274 case 28: {//Changing Heart Rate Vibration Preferences
asong 2:824ed4ae8d52 275 Increment_HR_Vibr_Pref();
asong 1:e4b38d6918ba 276 update_display();
asong 1:e4b38d6918ba 277 break;
asong 1:e4b38d6918ba 278 }
asong 1:e4b38d6918ba 279 case 30: {//Change Target Heart Rate Zone Preference
asong 2:824ed4ae8d52 280 Increment_Target_Zone();
asong 2:824ed4ae8d52 281 update_display();
asong 2:824ed4ae8d52 282 break;
asong 2:824ed4ae8d52 283 }
asong 2:824ed4ae8d52 284 case 31: { //Manually Increment Heart Rate by 1
asong 2:824ed4ae8d52 285 Increment_Heart_Rate();
asong 2:824ed4ae8d52 286 Determine_Current_Zone();
asong 1:e4b38d6918ba 287 update_display();
asong 1:e4b38d6918ba 288 break;
asong 1:e4b38d6918ba 289 }
asong 1:e4b38d6918ba 290 default: {
asong 1:e4b38d6918ba 291 break;
asong 1:e4b38d6918ba 292 }
asong 1:e4b38d6918ba 293 }
nbaker 0:d1d36a3da39b 294 }
asong 1:e4b38d6918ba 295
nbaker 0:d1d36a3da39b 296 }
nbaker 0:d1d36a3da39b 297
nbaker 0:d1d36a3da39b 298 void ButtonDown(void)
nbaker 0:d1d36a3da39b 299 {
asong 1:e4b38d6918ba 300 Screen_Timer.attach(&timout_timer,(SCRN_TIME));//Is this sufficient to reset/restart ticker timer for OLED?
asong 1:e4b38d6918ba 301 if (OLED_ON == 0) {
asong 1:e4b38d6918ba 302 OLED_ON = 1; // Screen was off, set to On
asong 1:e4b38d6918ba 303 update_display();
asong 1:e4b38d6918ba 304 } else {
nbaker 0:d1d36a3da39b 305
asong 1:e4b38d6918ba 306 switch(Screen_Num) {
asong 1:e4b38d6918ba 307 case 0: {// We're in Main Screen
asong 1:e4b38d6918ba 308 // do nothing, wrong button
asong 1:e4b38d6918ba 309 break;
asong 1:e4b38d6918ba 310 }
asong 1:e4b38d6918ba 311 case 1: {// Panic Alert option
asong 1:e4b38d6918ba 312 StartHaptic();
asong 1:e4b38d6918ba 313 Screen_Num = 2; //Change to screen 2
asong 1:e4b38d6918ba 314 update_display();
asong 1:e4b38d6918ba 315 break;
asong 1:e4b38d6918ba 316 }
asong 1:e4b38d6918ba 317 case 2: {// Fall Alert option
asong 1:e4b38d6918ba 318 StartHaptic();
asong 1:e4b38d6918ba 319 Screen_Num = 3; //Change to screen 3
asong 1:e4b38d6918ba 320 update_display();
asong 1:e4b38d6918ba 321 break;
asong 1:e4b38d6918ba 322 }
asong 1:e4b38d6918ba 323 case 3: {// Heart Rate Monitoring option
asong 1:e4b38d6918ba 324 StartHaptic();
asong 1:e4b38d6918ba 325 Screen_Num = 4; //Change to screen 4
asong 1:e4b38d6918ba 326 update_display();
asong 1:e4b38d6918ba 327 break;
asong 1:e4b38d6918ba 328 }
asong 1:e4b38d6918ba 329 case 4: {// Alert History option
asong 1:e4b38d6918ba 330 StartHaptic();
asong 1:e4b38d6918ba 331 Screen_Num = 5; //Change to screen 5
asong 1:e4b38d6918ba 332 update_display();
asong 1:e4b38d6918ba 333 break;
asong 1:e4b38d6918ba 334 }
asong 1:e4b38d6918ba 335 case 5: {// About HexiHeart option
asong 1:e4b38d6918ba 336 StartHaptic();
asong 1:e4b38d6918ba 337 Screen_Num = 26; //Change to screen 1
nbaker 0:d1d36a3da39b 338 #ifdef Debug // in debug show debug/diagnostic screens
asong 1:e4b38d6918ba 339 Screen_Num = 20; //Change to screen 20
nbaker 0:d1d36a3da39b 340 #endif
asong 1:e4b38d6918ba 341 update_display();
asong 1:e4b38d6918ba 342 break;
asong 1:e4b38d6918ba 343 }
asong 1:e4b38d6918ba 344 case 6: {// Panic Alert
asong 1:e4b38d6918ba 345 // do nothing, wrong button
asong 1:e4b38d6918ba 346 break;
asong 1:e4b38d6918ba 347 }
asong 1:e4b38d6918ba 348 case 7: {// Heart Rate Zone
asong 1:e4b38d6918ba 349 StartHaptic(100);
asong 2:824ed4ae8d52 350 Disable_Heart_Rate();
asong 1:e4b38d6918ba 351 break;
asong 1:e4b38d6918ba 352 }
asong 1:e4b38d6918ba 353 case 8: {// Alert History
asong 1:e4b38d6918ba 354 StartHaptic();
asong 1:e4b38d6918ba 355 //decriment alert index
asong 1:e4b38d6918ba 356 break;
asong 1:e4b38d6918ba 357 }
asong 1:e4b38d6918ba 358 case 20: {// Diagnostic/Debug Screens
asong 1:e4b38d6918ba 359 StartHaptic();
asong 1:e4b38d6918ba 360 Screen_Num = 26; //Change to screen 1
asong 1:e4b38d6918ba 361 update_display();
asong 1:e4b38d6918ba 362 break;
asong 1:e4b38d6918ba 363 }
asong 1:e4b38d6918ba 364 case 21: {// Fall Diagnostic
asong 1:e4b38d6918ba 365 StartHaptic();
asong 1:e4b38d6918ba 366 Screen_Num = 22; //Change to screen 22
asong 1:e4b38d6918ba 367 update_display();
asong 1:e4b38d6918ba 368 break;
asong 1:e4b38d6918ba 369 }
asong 1:e4b38d6918ba 370 case 22: {// Fall Debug
asong 1:e4b38d6918ba 371 StartHaptic();
asong 1:e4b38d6918ba 372 Screen_Num = 23; //Change to screen 23
asong 1:e4b38d6918ba 373 update_display();
asong 1:e4b38d6918ba 374 break;
asong 1:e4b38d6918ba 375 }
asong 1:e4b38d6918ba 376 case 23: {// Heart Rate Diagnostic
asong 1:e4b38d6918ba 377 StartHaptic();
asong 1:e4b38d6918ba 378 Screen_Num = 24; //Change to screen 24
asong 1:e4b38d6918ba 379 update_display();
asong 1:e4b38d6918ba 380 break;
asong 1:e4b38d6918ba 381 }
asong 1:e4b38d6918ba 382 case 24: {// Heart Rate Debug
asong 1:e4b38d6918ba 383 StartHaptic();
asong 1:e4b38d6918ba 384 Screen_Num = 25; //Change to screen 25
asong 1:e4b38d6918ba 385 update_display();
asong 1:e4b38d6918ba 386 break;
asong 1:e4b38d6918ba 387 }
asong 1:e4b38d6918ba 388 case 25: {// Heat Index Diagnostic
asong 1:e4b38d6918ba 389 StartHaptic();
asong 1:e4b38d6918ba 390 Screen_Num = 21; //Change to screen 21
asong 1:e4b38d6918ba 391 update_display();
asong 1:e4b38d6918ba 392 break;
asong 1:e4b38d6918ba 393 }
asong 1:e4b38d6918ba 394 case 26: {//Heart Rate Configs
asong 1:e4b38d6918ba 395 StartHaptic();
asong 1:e4b38d6918ba 396 Screen_Num = 1;
asong 1:e4b38d6918ba 397 update_display();
asong 1:e4b38d6918ba 398 break;
asong 1:e4b38d6918ba 399 }
asong 1:e4b38d6918ba 400 case 27: { //Decrement Age
asong 2:824ed4ae8d52 401 Decrement_Age();
asong 2:824ed4ae8d52 402 Set_Zone_Boundaries();
asong 1:e4b38d6918ba 403 update_display();
asong 1:e4b38d6918ba 404 break;
asong 1:e4b38d6918ba 405
asong 1:e4b38d6918ba 406 }
asong 1:e4b38d6918ba 407 case 28: { //Changing Heart Rate Vibration Preference
asong 2:824ed4ae8d52 408 /*
asong 2:824ed4ae8d52 409 StartHaptic();
asong 2:824ed4ae8d52 410 if(HR_Vibration == 1) {
asong 2:824ed4ae8d52 411 HR_Vibration = 3;
asong 2:824ed4ae8d52 412 } else {
asong 2:824ed4ae8d52 413 HR_Vibration -= 1;
asong 2:824ed4ae8d52 414 }
asong 2:824ed4ae8d52 415 */
asong 2:824ed4ae8d52 416 Decrement_HR_Vibr_Pref();
asong 1:e4b38d6918ba 417 update_display();
asong 1:e4b38d6918ba 418 break;
asong 1:e4b38d6918ba 419 }
asong 1:e4b38d6918ba 420 case 30: {//Change Target Heart Rate Zone Preference
asong 2:824ed4ae8d52 421 Decrement_Target_Zone();
asong 2:824ed4ae8d52 422 update_display();
asong 2:824ed4ae8d52 423 break;
asong 2:824ed4ae8d52 424 }
asong 2:824ed4ae8d52 425 case 31: { //Manually decrement heart rate by 1
asong 2:824ed4ae8d52 426 Decrement_Heart_Rate();
asong 2:824ed4ae8d52 427 Determine_Current_Zone();
asong 1:e4b38d6918ba 428 update_display();
asong 1:e4b38d6918ba 429 break;
asong 1:e4b38d6918ba 430 }
asong 1:e4b38d6918ba 431 default: {
asong 1:e4b38d6918ba 432 break;
asong 1:e4b38d6918ba 433 }
asong 1:e4b38d6918ba 434 }
nbaker 0:d1d36a3da39b 435 }
nbaker 0:d1d36a3da39b 436 }
nbaker 0:d1d36a3da39b 437
nbaker 0:d1d36a3da39b 438 void ButtonRight(void)
nbaker 0:d1d36a3da39b 439 {
asong 1:e4b38d6918ba 440 Screen_Timer.attach(&timout_timer,(SCRN_TIME));//Is this sufficient to reset/restart ticker timer for OLED?
asong 1:e4b38d6918ba 441 if (OLED_ON == 0) {
asong 1:e4b38d6918ba 442 OLED_ON = 1; // Screen was off, set to On
asong 1:e4b38d6918ba 443 update_display();
asong 1:e4b38d6918ba 444 } else {
asong 1:e4b38d6918ba 445 switch(Screen_Num) {
asong 1:e4b38d6918ba 446 case 0: {// We're in Main Screen
asong 1:e4b38d6918ba 447 StartHaptic();
asong 1:e4b38d6918ba 448 Screen_Num = 1; //Change to screen 1
asong 1:e4b38d6918ba 449 update_display();
asong 1:e4b38d6918ba 450 break;
asong 1:e4b38d6918ba 451 }
asong 1:e4b38d6918ba 452 case 1: {// Panic Alert option
asong 1:e4b38d6918ba 453 StartHaptic();
asong 1:e4b38d6918ba 454 Screen_Num = 6; //Change to screen 6
asong 1:e4b38d6918ba 455 update_display();
asong 1:e4b38d6918ba 456 break;
asong 1:e4b38d6918ba 457 }
asong 1:e4b38d6918ba 458 case 2: {// Fall Alert option
asong 1:e4b38d6918ba 459 StartHaptic();
nbaker 4:0803151bc5e4 460 if(Fall_Alert == 1){
nbaker 4:0803151bc5e4 461 Accel_INT1.fall(&fall_detect_off); // turn off Accel sensor's int#1 calls interupt routine
nbaker 4:0803151bc5e4 462 Fall_Alert = 0;
nbaker 4:0803151bc5e4 463 }
nbaker 4:0803151bc5e4 464 else{
nbaker 4:0803151bc5e4 465 Accel_INT1.fall(&fall_detect); // Accel sensor's int#1 calls interupt routine
nbaker 4:0803151bc5e4 466 Fall_Alert = 1;
nbaker 4:0803151bc5e4 467 }
nbaker 4:0803151bc5e4 468 update_display();
asong 1:e4b38d6918ba 469 break;
asong 1:e4b38d6918ba 470 }
asong 1:e4b38d6918ba 471 case 3: {// Heart Rate Monitoring option
asong 1:e4b38d6918ba 472 StartHaptic();
asong 1:e4b38d6918ba 473 Screen_Num = 7; //Change to screen 7
asong 1:e4b38d6918ba 474 update_display();
asong 1:e4b38d6918ba 475 break;
asong 1:e4b38d6918ba 476 }
asong 1:e4b38d6918ba 477 case 4: {// Alert History option
asong 1:e4b38d6918ba 478 StartHaptic();
asong 1:e4b38d6918ba 479 Screen_Num = 8; //Change to screen 8
asong 1:e4b38d6918ba 480 update_display();
asong 1:e4b38d6918ba 481 break;
asong 1:e4b38d6918ba 482 }
asong 1:e4b38d6918ba 483 case 5: {// About HexiHeart option
asong 1:e4b38d6918ba 484 StartHaptic();
asong 1:e4b38d6918ba 485 Screen_Num = 9; //Change to screen 9
asong 1:e4b38d6918ba 486 update_display();
asong 1:e4b38d6918ba 487 break;
asong 1:e4b38d6918ba 488 }
nbaker 0:d1d36a3da39b 489
asong 1:e4b38d6918ba 490 case 6: {// Panic Alert
asong 1:e4b38d6918ba 491 // do nothing, wrong button
asong 1:e4b38d6918ba 492 break;
asong 1:e4b38d6918ba 493 }
asong 1:e4b38d6918ba 494 case 7: {// Heart Rate Zone
asong 1:e4b38d6918ba 495 StartHaptic();
asong 2:824ed4ae8d52 496 Screen_Num = 31;
asong 2:824ed4ae8d52 497 update_display();
asong 1:e4b38d6918ba 498 break;
asong 1:e4b38d6918ba 499 }
asong 1:e4b38d6918ba 500 case 20: {// Diagnostic/Debug Screens
asong 1:e4b38d6918ba 501 StartHaptic();
asong 1:e4b38d6918ba 502 Screen_Num = 21; //Change to screen 21
asong 1:e4b38d6918ba 503 update_display();
asong 1:e4b38d6918ba 504 break;
asong 1:e4b38d6918ba 505 }
asong 1:e4b38d6918ba 506 case 26: {//Change to Heart Rate Config Screen
asong 1:e4b38d6918ba 507 StartHaptic();
asong 1:e4b38d6918ba 508 Screen_Num = 27;
asong 1:e4b38d6918ba 509 update_display();
asong 1:e4b38d6918ba 510 break;
asong 1:e4b38d6918ba 511 }
asong 1:e4b38d6918ba 512 case 27: {//Change to Heart Rate Vibration Preferences
asong 1:e4b38d6918ba 513 StartHaptic();
asong 1:e4b38d6918ba 514 Screen_Num = 28;
asong 1:e4b38d6918ba 515 update_display();
asong 1:e4b38d6918ba 516 break;
asong 1:e4b38d6918ba 517 }
asong 1:e4b38d6918ba 518 case 28: {//Change to Heart Rate Zone Boundary Info
asong 1:e4b38d6918ba 519 StartHaptic();
asong 1:e4b38d6918ba 520 Screen_Num = 29;
asong 1:e4b38d6918ba 521 update_display();
asong 1:e4b38d6918ba 522 break;
asong 1:e4b38d6918ba 523 }
asong 2:824ed4ae8d52 524 case 29: {//Change Target Heart Rate Zone Preference
asong 1:e4b38d6918ba 525 StartHaptic();
asong 1:e4b38d6918ba 526 Screen_Num = 30;
asong 1:e4b38d6918ba 527 update_display();
asong 1:e4b38d6918ba 528 break;
asong 1:e4b38d6918ba 529 }
asong 1:e4b38d6918ba 530 case 30: {//Change to Heart Rate Config Screen
asong 1:e4b38d6918ba 531 StartHaptic();
asong 1:e4b38d6918ba 532 Screen_Num = 27;
asong 1:e4b38d6918ba 533 update_display();
asong 1:e4b38d6918ba 534 break;
asong 1:e4b38d6918ba 535 }
asong 2:824ed4ae8d52 536 case 31: {
asong 2:824ed4ae8d52 537 StartHaptic();
asong 2:824ed4ae8d52 538 Screen_Num = 32;
asong 2:824ed4ae8d52 539 update_display();
asong 2:824ed4ae8d52 540 break;
asong 2:824ed4ae8d52 541 }
asong 2:824ed4ae8d52 542 case 32: {
asong 2:824ed4ae8d52 543 StartHaptic();
asong 2:824ed4ae8d52 544 Screen_Num = 7;
asong 2:824ed4ae8d52 545 update_display();
asong 2:824ed4ae8d52 546 break;
asong 2:824ed4ae8d52 547 }
asong 1:e4b38d6918ba 548 default: {
asong 1:e4b38d6918ba 549 break;
asong 1:e4b38d6918ba 550 }
asong 1:e4b38d6918ba 551 }
nbaker 0:d1d36a3da39b 552 }
nbaker 0:d1d36a3da39b 553 }
nbaker 0:d1d36a3da39b 554
nbaker 0:d1d36a3da39b 555 void ButtonLeft(void)
nbaker 0:d1d36a3da39b 556 {
asong 1:e4b38d6918ba 557 Screen_Timer.attach(&timout_timer,(SCRN_TIME));//Is this sufficient to reset/restart ticker timer for OLED?
asong 1:e4b38d6918ba 558 if (OLED_ON == 0) {
asong 1:e4b38d6918ba 559 OLED_ON = 1; // Screen was off, set to On
asong 1:e4b38d6918ba 560 update_display();
asong 1:e4b38d6918ba 561 } else {
asong 1:e4b38d6918ba 562 switch(Screen_Num) {
asong 1:e4b38d6918ba 563 case 0: {// We're in Main Screen
asong 1:e4b38d6918ba 564 // do nothing, wrong button
asong 1:e4b38d6918ba 565 break;
asong 1:e4b38d6918ba 566 }
asong 1:e4b38d6918ba 567 case 1: {// Panic Alert option
asong 1:e4b38d6918ba 568 StartHaptic();
asong 1:e4b38d6918ba 569 Screen_Num = 0; //Change to screen 0
asong 1:e4b38d6918ba 570 update_display();
asong 1:e4b38d6918ba 571 break;
asong 1:e4b38d6918ba 572 }
asong 1:e4b38d6918ba 573 case 2: {// Fall Alert option
asong 1:e4b38d6918ba 574 StartHaptic();
asong 1:e4b38d6918ba 575 Screen_Num = 0; //Change to screen 0
asong 1:e4b38d6918ba 576 update_display();
asong 1:e4b38d6918ba 577 break;
asong 1:e4b38d6918ba 578 }
asong 1:e4b38d6918ba 579 case 3: {// Heart Rate Monitoring option
asong 1:e4b38d6918ba 580 StartHaptic();
asong 1:e4b38d6918ba 581 Screen_Num = 0; //Change to screen 0
asong 1:e4b38d6918ba 582 update_display();
asong 1:e4b38d6918ba 583 break;
asong 1:e4b38d6918ba 584 }
asong 1:e4b38d6918ba 585 case 4: {// Alert History option
asong 1:e4b38d6918ba 586 StartHaptic();
asong 1:e4b38d6918ba 587 Screen_Num = 0; //Change to screen 0
asong 1:e4b38d6918ba 588 update_display();
asong 1:e4b38d6918ba 589 break;
asong 1:e4b38d6918ba 590 }
asong 1:e4b38d6918ba 591 case 5: {// About HexiHeart option
asong 1:e4b38d6918ba 592 StartHaptic();
asong 1:e4b38d6918ba 593 Screen_Num = 0; //Change to screen 0
asong 1:e4b38d6918ba 594 update_display();
asong 1:e4b38d6918ba 595 break;
asong 1:e4b38d6918ba 596 }
asong 1:e4b38d6918ba 597 case 6: {// Panic Alert
asong 1:e4b38d6918ba 598 StartHaptic();
asong 1:e4b38d6918ba 599 Screen_Num = 1; //Change to screen 1
asong 1:e4b38d6918ba 600 update_display();
asong 1:e4b38d6918ba 601 break;
asong 1:e4b38d6918ba 602 }
asong 1:e4b38d6918ba 603 case 7: {// Heart Rate Zone
asong 1:e4b38d6918ba 604 StartHaptic();
asong 1:e4b38d6918ba 605 Screen_Num = 3; //Change to screen 3
asong 1:e4b38d6918ba 606 update_display();
asong 1:e4b38d6918ba 607 break;
asong 1:e4b38d6918ba 608 }
asong 1:e4b38d6918ba 609 case 8: {// Alert History
asong 1:e4b38d6918ba 610 StartHaptic();
asong 1:e4b38d6918ba 611 Screen_Num = 4; //Change to screen 4
asong 1:e4b38d6918ba 612 update_display();
asong 1:e4b38d6918ba 613 break;
asong 1:e4b38d6918ba 614 }
asong 1:e4b38d6918ba 615 case 20: {// Diagnostic/Debug Screens
asong 1:e4b38d6918ba 616 StartHaptic();
asong 1:e4b38d6918ba 617 Screen_Num = 0; //Change to screen 0
asong 1:e4b38d6918ba 618 update_display();
asong 1:e4b38d6918ba 619 break;
asong 1:e4b38d6918ba 620 }
asong 1:e4b38d6918ba 621 case 21: {// Fall Diagnostic
asong 1:e4b38d6918ba 622 StartHaptic();
asong 1:e4b38d6918ba 623 Screen_Num = 20; //Change to screen 20
asong 1:e4b38d6918ba 624 update_display();
asong 1:e4b38d6918ba 625 break;
asong 1:e4b38d6918ba 626 }
asong 1:e4b38d6918ba 627 case 22: {// Fall Debug
asong 1:e4b38d6918ba 628 StartHaptic();
asong 1:e4b38d6918ba 629 Screen_Num = 20; //Change to screen 20
asong 1:e4b38d6918ba 630 update_display();
asong 1:e4b38d6918ba 631 break;
asong 1:e4b38d6918ba 632 }
asong 1:e4b38d6918ba 633 case 23: {// Heart Rate Diagnostic
asong 1:e4b38d6918ba 634 StartHaptic();
asong 1:e4b38d6918ba 635 Screen_Num = 20; //Change to screen 20
asong 1:e4b38d6918ba 636 update_display();
asong 1:e4b38d6918ba 637 break;
asong 1:e4b38d6918ba 638 }
asong 1:e4b38d6918ba 639 case 24: {// Heart Rate Debug
asong 1:e4b38d6918ba 640 StartHaptic();
asong 1:e4b38d6918ba 641 Screen_Num = 20; //Change to screen 20
asong 1:e4b38d6918ba 642 update_display();
asong 1:e4b38d6918ba 643 break;
asong 1:e4b38d6918ba 644 }
asong 1:e4b38d6918ba 645 case 25: {// Heat Index Diagnostic
asong 1:e4b38d6918ba 646 StartHaptic();
asong 1:e4b38d6918ba 647 Screen_Num = 20; //Change to screen 20
asong 1:e4b38d6918ba 648 update_display();
asong 1:e4b38d6918ba 649 break;
asong 1:e4b38d6918ba 650 }
asong 1:e4b38d6918ba 651 case 26: {//Heart Rate Config Option
asong 1:e4b38d6918ba 652 StartHaptic();
asong 1:e4b38d6918ba 653 Screen_Num = 0;
asong 1:e4b38d6918ba 654 update_display();
asong 1:e4b38d6918ba 655 break;
asong 1:e4b38d6918ba 656 }
asong 1:e4b38d6918ba 657 case 27: {//Enter Age
asong 1:e4b38d6918ba 658 StartHaptic();
asong 1:e4b38d6918ba 659 Screen_Num = 26;
asong 1:e4b38d6918ba 660 update_display();
asong 1:e4b38d6918ba 661 break;
asong 1:e4b38d6918ba 662 }
asong 1:e4b38d6918ba 663 case 28: {//Heart Rate Vibration Preference Screen
asong 1:e4b38d6918ba 664 StartHaptic();
asong 1:e4b38d6918ba 665 Screen_Num = 27;
asong 1:e4b38d6918ba 666 update_display();
asong 1:e4b38d6918ba 667 break;
asong 1:e4b38d6918ba 668 }
asong 1:e4b38d6918ba 669 case 29: {//Heart Rate Zone Boundary Info
asong 1:e4b38d6918ba 670 StartHaptic();
asong 1:e4b38d6918ba 671 Screen_Num = 28;
asong 1:e4b38d6918ba 672 update_display();
asong 1:e4b38d6918ba 673 break;
asong 1:e4b38d6918ba 674 }
asong 2:824ed4ae8d52 675 case 30: {//Change Target Heart Rate Zone Preference
asong 1:e4b38d6918ba 676 StartHaptic();
asong 1:e4b38d6918ba 677 Screen_Num = 29;
asong 1:e4b38d6918ba 678 update_display();
asong 1:e4b38d6918ba 679 break;
asong 1:e4b38d6918ba 680 }
asong 2:824ed4ae8d52 681 case 31: {
asong 2:824ed4ae8d52 682 StartHaptic();
asong 2:824ed4ae8d52 683 Screen_Num = 7;
asong 2:824ed4ae8d52 684 update_display();
asong 2:824ed4ae8d52 685 break;
asong 2:824ed4ae8d52 686 }
asong 2:824ed4ae8d52 687 case 32: {
asong 2:824ed4ae8d52 688 StartHaptic();
asong 2:824ed4ae8d52 689 Screen_Num = 31;
asong 2:824ed4ae8d52 690 update_display();
asong 2:824ed4ae8d52 691 break;
asong 2:824ed4ae8d52 692 }
asong 1:e4b38d6918ba 693 default: {
asong 1:e4b38d6918ba 694 break;
asong 1:e4b38d6918ba 695 }
asong 1:e4b38d6918ba 696 }
nbaker 0:d1d36a3da39b 697 }
nbaker 0:d1d36a3da39b 698 }
nbaker 0:d1d36a3da39b 699
nbaker 0:d1d36a3da39b 700
nbaker 0:d1d36a3da39b 701 void ButtonSlide(void) // What is this Slide button???
nbaker 0:d1d36a3da39b 702 {
asong 1:e4b38d6918ba 703 Screen_Timer.attach(&timout_timer,(SCRN_TIME));//Is this sufficient to reset/restart ticker timer for OLED?
asong 1:e4b38d6918ba 704 if (OLED_ON == 0) {
asong 1:e4b38d6918ba 705 OLED_ON = 1; // Screen was off, set to On
asong 1:e4b38d6918ba 706 }
nbaker 0:d1d36a3da39b 707 StartHaptic();
nbaker 0:d1d36a3da39b 708 oled.FillScreen(COLOR_BLACK); // Clear screen
nbaker 0:d1d36a3da39b 709 strcpy((char *) text_1,"Slide Button");
nbaker 0:d1d36a3da39b 710 oled.Label((uint8_t *)text_1,0,40);
nbaker 0:d1d36a3da39b 711 }
asong 1:e4b38d6918ba 712
nbaker 0:d1d36a3da39b 713 int main()
nbaker 0:d1d36a3da39b 714 {
nbaker 4:0803151bc5e4 715 OLED_PWR = 1; // Turn on OLED power supply
jmr274 5:e1431272be79 716
jmr274 5:e1431272be79 717
nbaker 0:d1d36a3da39b 718 oled.FillScreen(COLOR_BLACK); // Clear screen
asong 1:e4b38d6918ba 719 // ***************** Local variables ***********************
asong 1:e4b38d6918ba 720 // float accel_data[3]; float accel_rms=0.0;
nbaker 4:0803151bc5e4 721 int i;
nbaker 4:0803151bc5e4 722
nbaker 0:d1d36a3da39b 723 // ************** configure sensor modules ******************
nbaker 4:0803151bc5e4 724 // accel.accel_config(); // configure sensor
nbaker 4:0803151bc5e4 725 fall_config(1); // configure sensor for fall detect
nbaker 4:0803151bc5e4 726 // Fall_config(Fall_Alert_Mode); // configure sensor for fall mode
nbaker 0:d1d36a3da39b 727 mag.mag_config();
nbaker 4:0803151bc5e4 728 gyro.gyro_config();
asong 1:e4b38d6918ba 729
nbaker 0:d1d36a3da39b 730 RED_Led = LED_OFF;
nbaker 0:d1d36a3da39b 731 GRN_Led = LED_OFF;
nbaker 0:d1d36a3da39b 732 BLU_Led = LED_OFF;
nbaker 4:0803151bc5e4 733 Led_clk1 = 0; // LEDs on docking station default to off, need to turn on with a 1
nbaker 4:0803151bc5e4 734 Led_clk2 = 0; // LEDs on docking station default to off, need to turn on with a 1
nbaker 4:0803151bc5e4 735 Led_clk3 = 0; // LEDs on docking station default to off, need to turn on with a 1
nbaker 4:0803151bc5e4 736 Non_Free_PWR = 1; // Start with non-freescale sensors (Pres/Temp/Hum/Light)on
nbaker 4:0803151bc5e4 737 HR_PWR = 1; // Start with Heart rate sensor powered on
nbaker 4:0803151bc5e4 738
nbaker 0:d1d36a3da39b 739 // ***** Register callbacks/interupts to application functions *********
nbaker 0:d1d36a3da39b 740 kw40z_device.attach_buttonUp(&ButtonUp);
nbaker 0:d1d36a3da39b 741 kw40z_device.attach_buttonDown(&ButtonDown);
nbaker 0:d1d36a3da39b 742 kw40z_device.attach_buttonLeft(&ButtonLeft);
nbaker 0:d1d36a3da39b 743 kw40z_device.attach_buttonRight(&ButtonRight);
nbaker 4:0803151bc5e4 744 // kw40z_device.attach_buttonSlide(&ButtonSlide);
nbaker 4:0803151bc5e4 745
nbaker 4:0803151bc5e4 746 // ***** attaching interupts to functions *********
nbaker 4:0803151bc5e4 747 Accel_INT1.fall(&fall_detect); // Accel sensor's int#1 calls interupt routine
nbaker 4:0803151bc5e4 748 // Accel_INT2.fall(&impact_detect); //Accel sensor's int#2 calls interupt routine
nbaker 4:0803151bc5e4 749
nbaker 0:d1d36a3da39b 750
nbaker 0:d1d36a3da39b 751 // **** Get OLED Class Default Text Properties ****************
asong 1:e4b38d6918ba 752 oled_text_properties_t textProperties = {0};
asong 1:e4b38d6918ba 753 oled.GetTextProperties(&textProperties);
asong 1:e4b38d6918ba 754
nbaker 0:d1d36a3da39b 755 // *********Set text color and screen alignment **************
asong 1:e4b38d6918ba 756 textProperties.fontColor = COLOR_WHITE;
asong 1:e4b38d6918ba 757 textProperties.alignParam = OLED_TEXT_ALIGN_LEFT;
asong 1:e4b38d6918ba 758 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 759
nbaker 0:d1d36a3da39b 760 // ************** Display spash screen **********************
nbaker 0:d1d36a3da39b 761
nbaker 0:d1d36a3da39b 762 oled.Label((uint8_t *)"Hexi",20,5); // Display white "Hexi" at x,y
nbaker 0:d1d36a3da39b 763 textProperties.fontColor = COLOR_RED;
asong 1:e4b38d6918ba 764 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 765 oled.Label((uint8_t *)"Heart",45,5); // Display red "Heart" at x,y
nbaker 0:d1d36a3da39b 766
asong 1:e4b38d6918ba 767 #ifdef Debug // if this is non-production version - do this
nbaker 0:d1d36a3da39b 768 strcpy((char *) text_1,"This is Debug Ver");
nbaker 0:d1d36a3da39b 769 oled.Label((uint8_t *)text_1,0,60); // text_1 at x,y
nbaker 0:d1d36a3da39b 770 StartHaptic();
asong 1:e4b38d6918ba 771 #endif
nbaker 0:d1d36a3da39b 772 textProperties.fontColor = COLOR_WHITE;
nbaker 0:d1d36a3da39b 773 oled.SetTextProperties(&textProperties);
nbaker 0:d1d36a3da39b 774 wait(3); // wait 3 seconds
asong 1:e4b38d6918ba 775 update_display(); // Displays current screen (screen 0)
nbaker 0:d1d36a3da39b 776 Screen_Timer.attach(&timout_timer,(SCRN_TIME));//start ticker timer for turning off LCD
asong 1:e4b38d6918ba 777 // ******************* Main Loop *************************
nbaker 0:d1d36a3da39b 778 while (true) {
nbaker 4:0803151bc5e4 779 i=0;
nbaker 4:0803151bc5e4 780 while (i<20)// used for "Heart beat flash and updated any displayed data)
nbaker 4:0803151bc5e4 781 {
nbaker 4:0803151bc5e4 782 Thread::wait(500); // wait 0.5 sec each loop
nbaker 4:0803151bc5e4 783 if(OLED_PWR==1){
nbaker 4:0803151bc5e4 784 // update_data();
nbaker 4:0803151bc5e4 785 }// end if
nbaker 4:0803151bc5e4 786 i++;
nbaker 4:0803151bc5e4 787 }// end while(i<20)
jmr274 5:e1431272be79 788
nbaker 4:0803151bc5e4 789 // wait(10); // wait 10 sec each loop, was orig half sec
nbaker 4:0803151bc5e4 790 RED_Led = LED_ON; // Used only for diagnostic of wait command
nbaker 4:0803151bc5e4 791 Led_clk3 = 1; // Used only for diagnostic of wait command
nbaker 4:0803151bc5e4 792 wait(0.01); // BLIP led 1/10 sec each loop
nbaker 4:0803151bc5e4 793 RED_Led = LED_OFF; // Used only for diagnostic of wait command
nbaker 4:0803151bc5e4 794 Led_clk3 = 0;
nbaker 4:0803151bc5e4 795 Thread::wait(490); // keep up the pace, at 0.5 sec (0.01s+0.49s) update date
nbaker 0:d1d36a3da39b 796
nbaker 4:0803151bc5e4 797 // update_data(); // refresh display date w/o updating entire display
nbaker 4:0803151bc5e4 798
nbaker 4:0803151bc5e4 799 } // end of while(true)
nbaker 4:0803151bc5e4 800
nbaker 0:d1d36a3da39b 801 }
nbaker 0:d1d36a3da39b 802 // ************** end of main()
nbaker 0:d1d36a3da39b 803
nbaker 0:d1d36a3da39b 804 void update_display(void)
nbaker 0:d1d36a3da39b 805 {
nbaker 4:0803151bc5e4 806 OLED_PWR = 1; // make sure OLED power supply is on
asong 1:e4b38d6918ba 807 oled_text_properties_t textProperties = {0}; // Need these to change font color
asong 1:e4b38d6918ba 808 oled.GetTextProperties(&textProperties); // Need these to change font color
asong 1:e4b38d6918ba 809 switch(Screen_Num) {
asong 1:e4b38d6918ba 810 case 0: {// Main Screen
nbaker 4:0803151bc5e4 811 HexiwearBattery battery;
nbaker 4:0803151bc5e4 812 battery.sensorOn();
asong 1:e4b38d6918ba 813 oled.FillScreen(COLOR_BLACK); // Clear screen
nbaker 4:0803151bc5e4 814
nbaker 4:0803151bc5e4 815 if (battery.isBatteryCharging()) {
nbaker 4:0803151bc5e4 816 textProperties.fontColor = COLOR_GREEN;
nbaker 4:0803151bc5e4 817 oled.SetTextProperties(&textProperties);
nbaker 4:0803151bc5e4 818 // sprintf(text_1, "%s", "chrg");
nbaker 4:0803151bc5e4 819 sprintf(text_1, "%i%%+", (uint8_t)battery.readLevelPercent());
nbaker 4:0803151bc5e4 820 Screen_Timer.attach(&timout_timer,(SCRN_TIME));// Reset/restart ticker timer for OLED while fully charged
nbaker 4:0803151bc5e4 821 } else {
nbaker 4:0803151bc5e4 822 sprintf(text_1, "%i%%", (uint8_t)battery.readLevelPercent());
nbaker 4:0803151bc5e4 823 }
nbaker 4:0803151bc5e4 824 oled.TextBox((uint8_t *)text_1,60,0,35,15); //show level value of battery originaly at 55,40,35,15
nbaker 4:0803151bc5e4 825
nbaker 4:0803151bc5e4 826 textProperties.fontColor = COLOR_WHITE;
nbaker 4:0803151bc5e4 827 oled.SetTextProperties(&textProperties);
nbaker 4:0803151bc5e4 828
nbaker 4:0803151bc5e4 829 oled.Label((uint8_t *)"Batt",35,0); // Display "Batt" at x,y
asong 1:e4b38d6918ba 830 oled.Label((uint8_t *)"Date",35,20); // Display "Date" at x,y
asong 1:e4b38d6918ba 831 oled.Label((uint8_t *)"Time",35,40); // Display "Time" at x,y
jmr274 5:e1431272be79 832 // oled.Label((uint8_t *)"H.I.",10,80); // Display "H.I." at x,y
asong 1:e4b38d6918ba 833 oled.Label((uint8_t *)"BT",40,80); //Display "BT" at x,y
asong 1:e4b38d6918ba 834 oled.Label((uint8_t *)"Menu",60,80); //Display "Menu" at x,y
jmr274 5:e1431272be79 835
jmr274 5:e1431272be79 836 Heat_Index_Calculation();
jmr274 5:e1431272be79 837 sprintf(text,"%i",heat_index);
jmr274 5:e1431272be79 838 oled.TextBox((uint8_t *)text,5,80,15,15);
jmr274 5:e1431272be79 839 strcpy((char *) text,"dF");oled.Label((uint8_t *)text,18,80);
jmr274 5:e1431272be79 840
asong 1:e4b38d6918ba 841 if(Heart_Rate_Mode == 1) {
asong 1:e4b38d6918ba 842 oled.Label((uint8_t *)"BPM",35,60); // Display "H.I." at x,y
asong 1:e4b38d6918ba 843 }
asong 1:e4b38d6918ba 844 break;
asong 1:e4b38d6918ba 845 }
asong 1:e4b38d6918ba 846 case 1: {// Panic Alert option
asong 1:e4b38d6918ba 847 oled.FillScreen(COLOR_BLACK); // Clear screen
asong 1:e4b38d6918ba 848 oled.Label((uint8_t *)"Panic Alert",20,5); // Display at x,y
asong 1:e4b38d6918ba 849 oled.Label((uint8_t *)"*",85,15); // "*" at x,y
asong 1:e4b38d6918ba 850 oled.Label((uint8_t *)"*",85,60); // "*" at x,y
asong 1:e4b38d6918ba 851 oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
asong 1:e4b38d6918ba 852 oled.Label((uint8_t *)"Enter",60,80); //Display "enter" at x,y
asong 1:e4b38d6918ba 853 break;
asong 1:e4b38d6918ba 854 }
asong 1:e4b38d6918ba 855 case 2: {// Fall Alert option
asong 1:e4b38d6918ba 856 oled.FillScreen(COLOR_BLACK); // Clear screen
asong 1:e4b38d6918ba 857 oled.Label((uint8_t *)"Fall Alert",20,5); // Display at x,y
nbaker 4:0803151bc5e4 858 oled.Label((uint8_t *)"Protection",15,25);
nbaker 4:0803151bc5e4 859 if (Fall_Alert == 1){
nbaker 4:0803151bc5e4 860 oled.Label((uint8_t *)" On ",42,40);
nbaker 4:0803151bc5e4 861 }
nbaker 4:0803151bc5e4 862 else {
nbaker 4:0803151bc5e4 863 oled.Label((uint8_t *)" Off ",40,40);
nbaker 4:0803151bc5e4 864 }
asong 1:e4b38d6918ba 865 oled.Label((uint8_t *)"*",85,15); // "*" at x,y
asong 1:e4b38d6918ba 866 oled.Label((uint8_t *)"*",85,60); // "*" at x,y
asong 1:e4b38d6918ba 867 oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
asong 1:e4b38d6918ba 868 oled.Label((uint8_t *)"Toggle",60,80); //Display "Toggle" at x,y
asong 1:e4b38d6918ba 869 break;
asong 1:e4b38d6918ba 870 }
asong 1:e4b38d6918ba 871 case 3: {// Heart Rate Monitoring option
asong 1:e4b38d6918ba 872 oled.FillScreen(COLOR_BLACK); // Clear screen
asong 1:e4b38d6918ba 873 oled.Label((uint8_t *)"Heart Rate",20,5); // Display at x,y
asong 1:e4b38d6918ba 874 oled.Label((uint8_t *)"*",85,15); // "*" at x,y
asong 1:e4b38d6918ba 875 oled.Label((uint8_t *)"*",85,60); // "*" at x,y
asong 1:e4b38d6918ba 876 oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
asong 1:e4b38d6918ba 877 oled.Label((uint8_t *)"Enter",60,80); //Display at x,y
asong 1:e4b38d6918ba 878 break;
asong 1:e4b38d6918ba 879 }
asong 1:e4b38d6918ba 880 case 4: {// Alert History option
asong 1:e4b38d6918ba 881 oled.FillScreen(COLOR_BLACK); // Clear screen
asong 1:e4b38d6918ba 882 oled.Label((uint8_t *)"Alert History",5,5); // Display at x,y
asong 1:e4b38d6918ba 883 oled.Label((uint8_t *)"*",85,15); // "*" at x,y
asong 1:e4b38d6918ba 884 oled.Label((uint8_t *)"*",85,60); // "*" at x,y
asong 1:e4b38d6918ba 885 oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
asong 1:e4b38d6918ba 886 oled.Label((uint8_t *)"Enter",60,80); //Display at x,y
asong 1:e4b38d6918ba 887 break;
asong 1:e4b38d6918ba 888 }
asong 1:e4b38d6918ba 889 case 5: {// About HexiHeart Screen
nbaker 0:d1d36a3da39b 890
asong 1:e4b38d6918ba 891 oled.FillScreen(COLOR_BLACK); // Clear screen
asong 1:e4b38d6918ba 892 oled.Label((uint8_t *)"Hexi",20,20); // Display white "Hexi" at x,y
asong 1:e4b38d6918ba 893 textProperties.fontColor = COLOR_RED;
asong 1:e4b38d6918ba 894 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 895 oled.Label((uint8_t *)"Heart",45,20); // Display red "Heart" at x,y
asong 1:e4b38d6918ba 896 textProperties.fontColor = COLOR_WHITE;
asong 1:e4b38d6918ba 897 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 898 strcpy((char *) text_1,"About");
asong 1:e4b38d6918ba 899 oled.Label((uint8_t *)text_1,30,5); // text_1 at x,y
asong 1:e4b38d6918ba 900 oled.Label((uint8_t *)"*",85,15); // "*" at x,y
asong 1:e4b38d6918ba 901 oled.Label((uint8_t *)"*",85,60); // "*" at x,y
asong 1:e4b38d6918ba 902 oled.Label((uint8_t *)" Back ",9,80); // Display "Back" at x,y
asong 1:e4b38d6918ba 903 oled.Label((uint8_t *)" Enter ",59,80); //Display at x,y
asong 1:e4b38d6918ba 904 break;
asong 1:e4b38d6918ba 905 }
asong 1:e4b38d6918ba 906
asong 1:e4b38d6918ba 907 case 6: {// Panic Alert
asong 1:e4b38d6918ba 908 oled.FillScreen(COLOR_BLACK); // Clear screen
asong 1:e4b38d6918ba 909 if (Panic_Alert == 0) {
asong 1:e4b38d6918ba 910 oled.Label((uint8_t *)"Send ",20,10); // Display at x,y
asong 1:e4b38d6918ba 911 } else {
asong 1:e4b38d6918ba 912 oled.Label((uint8_t *)"Dismiss ",17,10); // Display at x,y
asong 1:e4b38d6918ba 913 }
asong 1:e4b38d6918ba 914 oled.Label((uint8_t *)"Panic Alert",15,40); // Display at x,y
asong 1:e4b38d6918ba 915 oled.Label((uint8_t *)"-->",80,15); // "*" at x,y
asong 1:e4b38d6918ba 916 oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
asong 1:e4b38d6918ba 917 break;
asong 1:e4b38d6918ba 918 }
asong 1:e4b38d6918ba 919 case 7: {// Heart Rate Zone
asong 1:e4b38d6918ba 920
asong 1:e4b38d6918ba 921 oled.FillScreen(COLOR_BLACK); // Clear screen
asong 1:e4b38d6918ba 922 oled.Label((uint8_t *)"Heart Rate",15,5); // Display at x,y
asong 1:e4b38d6918ba 923 oled.Label((uint8_t *)"HR:",15,25); // Display at x,y
asong 2:824ed4ae8d52 924 sprintf(display_buff, "%u", Heart_Rate);
asong 2:824ed4ae8d52 925 textProperties.fontColor = COLOR_RED; //Change font to red
asong 2:824ed4ae8d52 926 oled.SetTextProperties(&textProperties);//Implement color change
asong 2:824ed4ae8d52 927 oled.Label((uint8_t *)display_buff,43,25); // Display at x,y
asong 2:824ed4ae8d52 928 textProperties.fontColor = COLOR_WHITE;
asong 2:824ed4ae8d52 929 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 930 oled.Label((uint8_t *)"Age: ",15,45); // Display at x,y
asong 1:e4b38d6918ba 931 textProperties.fontColor = COLOR_GREEN;
asong 1:e4b38d6918ba 932 oled.SetTextProperties(&textProperties); //implements the color change
asong 1:e4b38d6918ba 933 sprintf(display_buff, "%u", Age); //Convert int to char array for displaying user age
asong 1:e4b38d6918ba 934 oled.Label((uint8_t *)display_buff,43,45); // Display at x,y
asong 1:e4b38d6918ba 935 textProperties.fontColor = COLOR_WHITE;
asong 1:e4b38d6918ba 936 oled.SetTextProperties(&textProperties);
asong 2:824ed4ae8d52 937 oled.Label((uint8_t *)"On",80,15); // "+" at x,y
asong 2:824ed4ae8d52 938 oled.Label((uint8_t *)"Off",78,60); // "-" at x,y
asong 1:e4b38d6918ba 939 oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
asong 1:e4b38d6918ba 940 oled.Label((uint8_t *)"Next",59,80); // Display "Next" at x,y
asong 2:824ed4ae8d52 941
asong 1:e4b38d6918ba 942 //heart.enable();
asong 1:e4b38d6918ba 943 //sprintf(display_buff, "%u", heart.getRevisionID()); //Convert int to char array for displaying user age
asong 1:e4b38d6918ba 944 //oled.Label((uint8_t *)display_buff,45,25); // Display at x,y
asong 1:e4b38d6918ba 945 //update_display();
asong 1:e4b38d6918ba 946 break;
asong 1:e4b38d6918ba 947 }
asong 1:e4b38d6918ba 948 case 8: {// Alert History
asong 1:e4b38d6918ba 949 oled.FillScreen(COLOR_BLACK); // Clear screen
asong 1:e4b38d6918ba 950 oled.Label((uint8_t *)"Alert History",5,5); // Display at x,y
asong 1:e4b38d6918ba 951 oled.Label((uint8_t *)"Date - Time",20,40); // Display at x,y
asong 1:e4b38d6918ba 952 oled.Label((uint8_t *)"Alert Type:",20,60); // Display at x,y
asong 1:e4b38d6918ba 953 oled.Label((uint8_t *)"+",85,15); // "*" at x,y
asong 1:e4b38d6918ba 954 oled.Label((uint8_t *)"-",85,60); // "*" at x,y
asong 1:e4b38d6918ba 955 oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
asong 1:e4b38d6918ba 956 break;
asong 1:e4b38d6918ba 957 }
asong 1:e4b38d6918ba 958 #ifdef Debug // if this is non-production/debug version - do this
asong 1:e4b38d6918ba 959 case 20: {// Diagnostic/Debug Screens
asong 1:e4b38d6918ba 960 oled.FillScreen(COLOR_BLACK); // Clear screen
asong 1:e4b38d6918ba 961 textProperties.fontColor = COLOR_RED;
asong 1:e4b38d6918ba 962 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 963 oled.Label((uint8_t *)"Diagnostics",10,5); // Display at x,y
asong 1:e4b38d6918ba 964 oled.Label((uint8_t *)" Enter ",59,80); //Display at x,y
asong 1:e4b38d6918ba 965 textProperties.fontColor = COLOR_WHITE;
asong 1:e4b38d6918ba 966 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 967 oled.Label((uint8_t *)"*",85,15); // "*" at x,y
asong 1:e4b38d6918ba 968 oled.Label((uint8_t *)"*",85,60); // "*" at x,y
asong 1:e4b38d6918ba 969 oled.Label((uint8_t *)" Back ",9,80); // Display "Back" at x,y
nbaker 0:d1d36a3da39b 970
asong 1:e4b38d6918ba 971 break;
asong 1:e4b38d6918ba 972 }
asong 1:e4b38d6918ba 973 case 21: {// Fall Alert Diagnostic Screen
asong 1:e4b38d6918ba 974 oled.FillScreen(COLOR_BLACK); // Clear screen
asong 1:e4b38d6918ba 975 textProperties.fontColor = COLOR_RED;
asong 1:e4b38d6918ba 976 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 977 oled.Label((uint8_t *)"Fall",30,5); // Display at x,y
asong 1:e4b38d6918ba 978 oled.Label((uint8_t *)"Diagnostic",25,5); // Display at x,y
asong 1:e4b38d6918ba 979 textProperties.fontColor = COLOR_WHITE;
asong 1:e4b38d6918ba 980 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 981 accel.acquire_accel_data_g(Accel_Data);
asong 1:e4b38d6918ba 982 // gyro.acquire_gyro_data_g(Gyro_Data);
asong 1:e4b38d6918ba 983 Accel_Mag = sqrt(((Accel_Data[0]*Accel_Data[0])+(Accel_Data[1]*Accel_Data[1])+(Accel_Data[2]*Accel_Data[2])));
asong 1:e4b38d6918ba 984 // Gyro_Mag = (abs(Gyro_Data[0])+abs(Gyro_Data[1])+abs(Gyro_Data[3]));
asong 1:e4b38d6918ba 985 sprintf(text_1," Accel:%2.2f g ",Accel_Mag);
asong 1:e4b38d6918ba 986 oled.Label((uint8_t *)text_1,10,40);// text_1 at x,y
asong 1:e4b38d6918ba 987 sprintf(text_1," Gyro:%4.0f D/S ",Gyro_Mag);
asong 1:e4b38d6918ba 988 oled.Label((uint8_t *)text_1,10,60);// text_1 at x,y
asong 1:e4b38d6918ba 989 oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
asong 1:e4b38d6918ba 990 break;
asong 1:e4b38d6918ba 991 }
asong 1:e4b38d6918ba 992 case 22: {// Fall Alert Debug Screen
asong 1:e4b38d6918ba 993 oled.FillScreen(COLOR_BLACK); // Clear screen
asong 1:e4b38d6918ba 994 textProperties.fontColor = COLOR_RED;
asong 1:e4b38d6918ba 995 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 996 oled.Label((uint8_t *)"Fall Debug",15,5); // Display at x,y
asong 1:e4b38d6918ba 997 textProperties.fontColor = COLOR_GREEN;
asong 1:e4b38d6918ba 998 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 999 sprintf(text_1," %1.1f g ",Fall_Thresh);
asong 1:e4b38d6918ba 1000 oled.Label((uint8_t *)text_1,35,20);// text_1 at x,y
asong 1:e4b38d6918ba 1001 sprintf(text_1," %2.1f g ",Impact_Thresh);
asong 1:e4b38d6918ba 1002 oled.Label((uint8_t *)text_1,35,35);// text_1 at x,y
asong 1:e4b38d6918ba 1003 sprintf(text_1," %3.0f D/S ",Movement_Thresh);
asong 1:e4b38d6918ba 1004 oled.Label((uint8_t *)text_1,35,50);// text_1 at x,y
asong 1:e4b38d6918ba 1005 textProperties.fontColor = COLOR_WHITE;
asong 1:e4b38d6918ba 1006 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 1007 oled.Label((uint8_t *)"F-Th:",5,20); // "*" at x,y
asong 1:e4b38d6918ba 1008 oled.Label((uint8_t *)"I-Th:",5,35); // "*" at x,y
asong 1:e4b38d6918ba 1009 oled.Label((uint8_t *)"M-Th:",5,50); // "*" at x,y
asong 1:e4b38d6918ba 1010 oled.Label((uint8_t *)"*",85,15); // "*" at x,y
asong 1:e4b38d6918ba 1011 oled.Label((uint8_t *)"*",85,60); // "*" at x,y
asong 1:e4b38d6918ba 1012 oled.Label((uint8_t *)" Back ",9,80); // Display "Back" at x,y
asong 1:e4b38d6918ba 1013 // oled.Label((uint8_t *)" Enter ",59,80); //Display at x,y
asong 1:e4b38d6918ba 1014 break;
asong 1:e4b38d6918ba 1015 }
asong 1:e4b38d6918ba 1016 case 23: {// Heart Rate Diagnostic Screen
asong 1:e4b38d6918ba 1017 oled.FillScreen(COLOR_BLACK); // Clear screen
asong 1:e4b38d6918ba 1018 textProperties.fontColor = COLOR_RED;
asong 1:e4b38d6918ba 1019 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 1020 oled.Label((uint8_t *)"H.R. Diagnostic",5,5); // Display at x,y
asong 1:e4b38d6918ba 1021 textProperties.fontColor = COLOR_WHITE;
asong 1:e4b38d6918ba 1022 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 1023 oled.Label((uint8_t *)"*",85,15); // "*" at x,y
asong 1:e4b38d6918ba 1024 oled.Label((uint8_t *)"*",85,60); // "*" at x,y
asong 1:e4b38d6918ba 1025 oled.Label((uint8_t *)" Back ",9,80); // Display "Back" at x,y
asong 1:e4b38d6918ba 1026 // oled.Label((uint8_t *)" Enter ",59,80); //Display at x,y
asong 1:e4b38d6918ba 1027 break;
asong 1:e4b38d6918ba 1028 }
asong 1:e4b38d6918ba 1029 case 24: {// Heart Rate Debug Screen
asong 1:e4b38d6918ba 1030 oled.FillScreen(COLOR_BLACK); // Clear screen
asong 1:e4b38d6918ba 1031 textProperties.fontColor = COLOR_RED;
asong 1:e4b38d6918ba 1032 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 1033 oled.Label((uint8_t *)"H.R. Debug",10,5); // Display at x,y
asong 1:e4b38d6918ba 1034 textProperties.fontColor = COLOR_WHITE;
asong 1:e4b38d6918ba 1035 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 1036 oled.Label((uint8_t *)"*",85,15); // "*" at x,y
asong 1:e4b38d6918ba 1037 oled.Label((uint8_t *)"*",85,60); // "*" at x,y
asong 1:e4b38d6918ba 1038 oled.Label((uint8_t *)" Back ",9,80); // Display "Back" at x,y
asong 1:e4b38d6918ba 1039 // oled.Label((uint8_t *)" Enter ",59,80); //Display at x,y
asong 1:e4b38d6918ba 1040 break;
asong 1:e4b38d6918ba 1041 }
asong 1:e4b38d6918ba 1042 case 25: {// Heat Index Diagnostic Screen
asong 1:e4b38d6918ba 1043 oled.FillScreen(COLOR_BLACK); // Clear screen
asong 1:e4b38d6918ba 1044 textProperties.fontColor = COLOR_RED;
asong 1:e4b38d6918ba 1045 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 1046 oled.Label((uint8_t *)"H.I. Diagnostic",5,5); // Display at x,y
asong 1:e4b38d6918ba 1047 textProperties.fontColor = COLOR_WHITE;
asong 1:e4b38d6918ba 1048 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 1049 oled.Label((uint8_t *)"*",85,15); // "*" at x,y
asong 1:e4b38d6918ba 1050 oled.Label((uint8_t *)"*",85,60); // "*" at x,y
asong 1:e4b38d6918ba 1051 oled.Label((uint8_t *)" Back ",9,80); // Display "Back" at x,y
asong 1:e4b38d6918ba 1052 // oled.Label((uint8_t *)" Enter ",59,80); //Display at x,y
jmr274 5:e1431272be79 1053
jmr274 5:e1431272be79 1054
jmr274 5:e1431272be79 1055
jmr274 5:e1431272be79 1056 oled_text_properties_t textProperties = {0};
jmr274 5:e1431272be79 1057 oled.GetTextProperties(&textProperties);
jmr274 5:e1431272be79 1058
jmr274 5:e1431272be79 1059 strcpy((char *) text,"Temp.");
jmr274 5:e1431272be79 1060 oled.Label((uint8_t *)text,5,40);
jmr274 5:e1431272be79 1061 strcpy((char *) text,"Humidity");
jmr274 5:e1431272be79 1062 oled.Label((uint8_t *)text,5,57);
jmr274 5:e1431272be79 1063 strcpy((char *) text,"H.I.");
jmr274 5:e1431272be79 1064 oled.Label((uint8_t *)text,5,23);
jmr274 5:e1431272be79 1065
jmr274 5:e1431272be79 1066 /* Set text properties to white and right aligned for the dynamic text */
jmr274 5:e1431272be79 1067 textProperties.fontColor = COLOR_GREEN;
jmr274 5:e1431272be79 1068 textProperties.alignParam = OLED_TEXT_ALIGN_RIGHT;
jmr274 5:e1431272be79 1069 oled.SetTextProperties(&textProperties);
jmr274 5:e1431272be79 1070
jmr274 5:e1431272be79 1071 /* Format the value */
jmr274 5:e1431272be79 1072 sprintf(text,"%i",sample_ftemp);
jmr274 5:e1431272be79 1073
jmr274 5:e1431272be79 1074 /* Display time reading in 35px by 15px textbox at(x=55, y=40) */
jmr274 5:e1431272be79 1075 oled.TextBox((uint8_t *)text,55,40,15,15); //Increase textbox for more digits
jmr274 5:e1431272be79 1076
jmr274 5:e1431272be79 1077 /* Display Units */
jmr274 5:e1431272be79 1078 strcpy((char *) text,"dF");
jmr274 5:e1431272be79 1079 oled.Label((uint8_t *)text,71,40);
jmr274 5:e1431272be79 1080
jmr274 5:e1431272be79 1081 /* Format the value */
jmr274 5:e1431272be79 1082 sprintf(text,"%i",sample_humid);
jmr274 5:e1431272be79 1083
jmr274 5:e1431272be79 1084 /* Display time reading in 35px by 15px textbox at(x=55, y=40) */
jmr274 5:e1431272be79 1085 oled.TextBox((uint8_t *)text,55,57,15,15); //Increase textbox for more digits
jmr274 5:e1431272be79 1086
jmr274 5:e1431272be79 1087 /* Display Units */
jmr274 5:e1431272be79 1088 strcpy((char *) text,"%");
jmr274 5:e1431272be79 1089 oled.Label((uint8_t *)text,71,57);
jmr274 5:e1431272be79 1090
jmr274 5:e1431272be79 1091 /* Set text properties to white and right aligned for the dynamic text */
jmr274 5:e1431272be79 1092 textProperties.fontColor = COLOR_BLUE;
jmr274 5:e1431272be79 1093 textProperties.alignParam = OLED_TEXT_ALIGN_RIGHT;
jmr274 5:e1431272be79 1094 oled.SetTextProperties(&textProperties);
jmr274 5:e1431272be79 1095
jmr274 5:e1431272be79 1096 /* Format the value */
jmr274 5:e1431272be79 1097 sprintf(text,"%i",heat_index);
jmr274 5:e1431272be79 1098
jmr274 5:e1431272be79 1099 /* Display time reading in 35px by 15px textbox at(x=55, y=40) */
jmr274 5:e1431272be79 1100 oled.TextBox((uint8_t *)text,55,23,15,15); //Increase textbox for more digits
jmr274 5:e1431272be79 1101
jmr274 5:e1431272be79 1102 /* Display Units */
jmr274 5:e1431272be79 1103 strcpy((char *) text,"dF");oled.Label((uint8_t *)text,71,23);
jmr274 5:e1431272be79 1104
asong 1:e4b38d6918ba 1105 break;
asong 1:e4b38d6918ba 1106 }
asong 1:e4b38d6918ba 1107 case 26: {//Heart Rate Config Option
asong 1:e4b38d6918ba 1108 oled.FillScreen(COLOR_BLACK); // Clear screen
asong 1:e4b38d6918ba 1109 oled.Label((uint8_t *)"HR Config",10,5); // Display at x,y
asong 1:e4b38d6918ba 1110 oled.Label((uint8_t *)"*",85,15); // "*" at x,y
asong 1:e4b38d6918ba 1111 oled.Label((uint8_t *)"*",85,60); // "*" at x,y
asong 1:e4b38d6918ba 1112 oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
asong 1:e4b38d6918ba 1113 oled.Label((uint8_t *)"Enter",60,80); //Display "enter" at x,y
asong 1:e4b38d6918ba 1114 break;
asong 1:e4b38d6918ba 1115 }
asong 1:e4b38d6918ba 1116 case 27: { //Enter Age Screen
asong 1:e4b38d6918ba 1117 oled.FillScreen(COLOR_BLACK);
asong 1:e4b38d6918ba 1118 oled.Label((uint8_t *)"Input Age", 10, 5);
asong 1:e4b38d6918ba 1119 sprintf(display_buff, "%u", Age); //Convert int to char array for displaying user age
asong 1:e4b38d6918ba 1120 oled.Label((uint8_t *)"Age:", 10, 30);
asong 1:e4b38d6918ba 1121 oled.Label((uint8_t *)"+",85,15); // "*" at x,y
asong 1:e4b38d6918ba 1122 oled.Label((uint8_t *)"-",85,60); // "*" at x,y
asong 1:e4b38d6918ba 1123 oled.Label((uint8_t *)"Menu",10,80); // Display "Menu" at x,y
asong 1:e4b38d6918ba 1124 oled.Label((uint8_t *)"Next",60,80); //Display "Next" at x,y
asong 1:e4b38d6918ba 1125 textProperties.fontColor = COLOR_GREEN;
asong 1:e4b38d6918ba 1126 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 1127 oled.Label((uint8_t *)display_buff,43,30); // Display at x,y
asong 1:e4b38d6918ba 1128 textProperties.fontColor = COLOR_WHITE;
asong 1:e4b38d6918ba 1129 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 1130 oled.Label((uint8_t *)"Max bpm:",10,50);
asong 1:e4b38d6918ba 1131 textProperties.fontColor = COLOR_RED;
asong 1:e4b38d6918ba 1132 oled.SetTextProperties(&textProperties); //implements the color change
asong 2:824ed4ae8d52 1133 sprintf(display_buff, "%u", Max_Bpm); //Convert int to char array for displaying user max bpm
asong 1:e4b38d6918ba 1134 oled.Label((uint8_t *)display_buff, 65, 50);
asong 1:e4b38d6918ba 1135 textProperties.fontColor = COLOR_WHITE;
asong 1:e4b38d6918ba 1136 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 1137 break;
asong 1:e4b38d6918ba 1138 }
asong 1:e4b38d6918ba 1139 case 28: {//Choose Heart Rate Vibration Option
asong 1:e4b38d6918ba 1140 oled.FillScreen(COLOR_BLACK);
asong 1:e4b38d6918ba 1141 oled.Label((uint8_t *)"Vibrate Pref", 10, 10);
asong 1:e4b38d6918ba 1142 oled.Label((uint8_t *)"Option:", 10, 25);
asong 1:e4b38d6918ba 1143 oled.Label((uint8_t *)"+",85,15); // "+" at x,y
asong 1:e4b38d6918ba 1144 oled.Label((uint8_t *)"-",85,60); // "-" at x,y
asong 1:e4b38d6918ba 1145 oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
asong 1:e4b38d6918ba 1146 oled.Label((uint8_t *)"Next",60,80); //Display "Next" at x,y
asong 1:e4b38d6918ba 1147 sprintf(display_buff, "%u", HR_Vibration); //Convert int to char array for displaying user preference
asong 1:e4b38d6918ba 1148 textProperties.fontColor = COLOR_GREEN; //Change font to green
asong 1:e4b38d6918ba 1149 oled.SetTextProperties(&textProperties);//Implement color change
asong 1:e4b38d6918ba 1150 oled.Label((uint8_t *)display_buff,55,25); // Display at x,y
asong 1:e4b38d6918ba 1151 if(HR_Vibration == 1) {
asong 1:e4b38d6918ba 1152 textProperties.fontColor = COLOR_RED; //Change font to red
asong 1:e4b38d6918ba 1153 oled.SetTextProperties(&textProperties); //Implement color change
asong 1:e4b38d6918ba 1154 oled.Label((uint8_t *)"All On",10,45); // Display at x,y
asong 1:e4b38d6918ba 1155 } else if(HR_Vibration == 2) {
asong 1:e4b38d6918ba 1156 textProperties.fontColor = COLOR_RED; //Change font to red
asong 1:e4b38d6918ba 1157 oled.SetTextProperties(&textProperties);//Implement color change
asong 1:e4b38d6918ba 1158 oled.Label((uint8_t *)"Only Entering",10,38);// Display at x,y
asong 1:e4b38d6918ba 1159 oled.Label((uint8_t *)"And Exiting",10,53);// Display at x,y
asong 1:e4b38d6918ba 1160 oled.Label((uint8_t *)"Target Zone",10,68);// Display at x,y
nbaker 0:d1d36a3da39b 1161
asong 1:e4b38d6918ba 1162 } else if(HR_Vibration == 3) {
asong 1:e4b38d6918ba 1163 textProperties.fontColor = COLOR_RED; //Change font to red
asong 1:e4b38d6918ba 1164 oled.SetTextProperties(&textProperties); //Implement color change
asong 1:e4b38d6918ba 1165 oled.Label((uint8_t *)"All Off",10,45);// Display at x,y
asong 1:e4b38d6918ba 1166 }
asong 1:e4b38d6918ba 1167 textProperties.fontColor = COLOR_WHITE;
asong 1:e4b38d6918ba 1168 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 1169 break;
asong 1:e4b38d6918ba 1170 }
asong 1:e4b38d6918ba 1171 case 29: { //Zone Boundary Info
asong 1:e4b38d6918ba 1172 oled.FillScreen(COLOR_BLACK);
asong 1:e4b38d6918ba 1173 oled.Label((uint8_t *)"HR Zone Info", 10, 5);// Display at x,y
asong 1:e4b38d6918ba 1174 textProperties.fontColor = COLOR_YELLOW; //Change font to yellow
asong 1:e4b38d6918ba 1175 oled.SetTextProperties(&textProperties);//Implement color change
asong 1:e4b38d6918ba 1176 oled.Label((uint8_t *)"Z1:", 10, 20);// Display at x,y
asong 1:e4b38d6918ba 1177 sprintf(display_buff, "%u", HR_Zone1[0]); // Convert int to char to display
asong 1:e4b38d6918ba 1178 oled.Label((uint8_t *)display_buff, 30, 20);// Display at x,y
asong 1:e4b38d6918ba 1179 oled.Label((uint8_t *)"-", 52, 20);// Display at x,y
asong 1:e4b38d6918ba 1180 sprintf(display_buff, "%u", HR_Zone1[1]); // Convert int to char to display
asong 1:e4b38d6918ba 1181 oled.Label((uint8_t *)display_buff, 60, 20);// Display at x,y
asong 1:e4b38d6918ba 1182 textProperties.fontColor = COLOR_BLUE; //Change font to blue
asong 1:e4b38d6918ba 1183 oled.SetTextProperties(&textProperties);//Implement color change
asong 1:e4b38d6918ba 1184 oled.Label((uint8_t *)"Z2:", 10, 35);// Display at x,y
asong 1:e4b38d6918ba 1185 sprintf(display_buff, "%u", HR_Zone2[0]); // Convert int to char to display
asong 1:e4b38d6918ba 1186 oled.Label((uint8_t *)display_buff, 30, 35);// Display at x,y
asong 1:e4b38d6918ba 1187 oled.Label((uint8_t *)"-", 52, 35);// Display at x,y
asong 1:e4b38d6918ba 1188 sprintf(display_buff, "%u", HR_Zone2[1]); // Convert int to char to display
asong 1:e4b38d6918ba 1189 oled.Label((uint8_t *)display_buff, 60, 35);// Display at x,y
asong 1:e4b38d6918ba 1190 textProperties.fontColor = COLOR_GREEN; //Change font to green
asong 1:e4b38d6918ba 1191 oled.SetTextProperties(&textProperties);//Implement color change
asong 1:e4b38d6918ba 1192 oled.Label((uint8_t *)"Z3:", 10, 50);// Display at x,y
asong 1:e4b38d6918ba 1193 sprintf(display_buff, "%u", HR_Zone3[0]); // Convert int to char to display
asong 1:e4b38d6918ba 1194 oled.Label((uint8_t *)display_buff, 30, 50);// Display at x,y
asong 1:e4b38d6918ba 1195 oled.Label((uint8_t *)"-", 52, 50);// Display at x,y
asong 1:e4b38d6918ba 1196 sprintf(display_buff, "%u", HR_Zone3[1]); // Convert int to char to display
asong 1:e4b38d6918ba 1197 oled.Label((uint8_t *)display_buff, 60, 50);// Display at x,y
asong 1:e4b38d6918ba 1198 textProperties.fontColor = COLOR_RED; //Change font to red
asong 1:e4b38d6918ba 1199 oled.SetTextProperties(&textProperties);//Implement color change
asong 1:e4b38d6918ba 1200 oled.Label((uint8_t *)"Z4:", 10, 65);// Display at x,y
asong 1:e4b38d6918ba 1201 sprintf(display_buff, "%u", HR_Zone4[0]); // Convert int to char to display
asong 1:e4b38d6918ba 1202 oled.Label((uint8_t *)display_buff, 30, 65);// Display at x,y
asong 1:e4b38d6918ba 1203 oled.Label((uint8_t *)"-", 52, 65);// Display at x,y
asong 1:e4b38d6918ba 1204 sprintf(display_buff, "%u", HR_Zone4[1]); // Convert int to char to display
asong 1:e4b38d6918ba 1205 oled.Label((uint8_t *)display_buff, 60, 65);// Display at x,y
asong 1:e4b38d6918ba 1206 textProperties.fontColor = COLOR_WHITE; //Change font to white
asong 1:e4b38d6918ba 1207 oled.SetTextProperties(&textProperties);//Implement color change
asong 1:e4b38d6918ba 1208 oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
asong 1:e4b38d6918ba 1209 oled.Label((uint8_t *)"Next",60,80); //Display "Next" at x,y
asong 1:e4b38d6918ba 1210 break;
asong 2:824ed4ae8d52 1211 }
asong 2:824ed4ae8d52 1212 case 30: { //Enter Target Heart Rate Zone Preference
asong 1:e4b38d6918ba 1213 oled.FillScreen(COLOR_BLACK);
asong 1:e4b38d6918ba 1214 oled.Label((uint8_t *)"Zone Pref", 10, 5);// Display at x,y
asong 1:e4b38d6918ba 1215 oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
asong 1:e4b38d6918ba 1216 oled.Label((uint8_t *)"Next",60,80); //Display "Next" at x,y
asong 1:e4b38d6918ba 1217 oled.Label((uint8_t *)"+",85,15); // "+" at x,y
asong 1:e4b38d6918ba 1218 oled.Label((uint8_t *)"-",85,60); // "-" at x,y
asong 1:e4b38d6918ba 1219 oled.Label((uint8_t *)"Target:", 10, 25);// Display at x,y
asong 1:e4b38d6918ba 1220 sprintf(display_buff, "%u", Target_Zone); // Convert int to char to display
asong 2:824ed4ae8d52 1221 if(Target_Zone == 1) {
asong 1:e4b38d6918ba 1222 textProperties.fontColor = COLOR_YELLOW; //Change font to yellow
asong 1:e4b38d6918ba 1223 oled.SetTextProperties(&textProperties);//Implement color change
asong 2:824ed4ae8d52 1224 } else if(Target_Zone == 2) {
asong 1:e4b38d6918ba 1225 textProperties.fontColor = COLOR_BLUE; //Change font to blue
asong 1:e4b38d6918ba 1226 oled.SetTextProperties(&textProperties);//Implement color change
asong 2:824ed4ae8d52 1227 } else if(Target_Zone == 3) {
asong 1:e4b38d6918ba 1228 textProperties.fontColor = COLOR_GREEN; //Change font to green
asong 1:e4b38d6918ba 1229 oled.SetTextProperties(&textProperties);//Implement color change
asong 2:824ed4ae8d52 1230 } else if(Target_Zone == 4) {
asong 1:e4b38d6918ba 1231 textProperties.fontColor = COLOR_RED; //Change font to red
asong 1:e4b38d6918ba 1232 oled.SetTextProperties(&textProperties);//Implement color change
asong 1:e4b38d6918ba 1233 }
asong 1:e4b38d6918ba 1234 oled.Label((uint8_t *)display_buff, 55, 25);// Display at x,y
asong 1:e4b38d6918ba 1235 textProperties.fontColor = COLOR_WHITE; //Change font to white
asong 1:e4b38d6918ba 1236 oled.SetTextProperties(&textProperties);//Implement color change
asong 1:e4b38d6918ba 1237 oled.Label((uint8_t *)"Bounds:", 10, 45);// Display at x,y
asong 2:824ed4ae8d52 1238 if(Target_Zone == 1) {
asong 1:e4b38d6918ba 1239 textProperties.fontColor = COLOR_YELLOW; //Change font to yellow
asong 1:e4b38d6918ba 1240 oled.SetTextProperties(&textProperties);//Implement color change
asong 1:e4b38d6918ba 1241 sprintf(display_buff, "%u", HR_Zone1[0]); // Convert int to char to display
asong 1:e4b38d6918ba 1242 oled.Label((uint8_t *)display_buff, 10, 60);// Display at x,y
asong 1:e4b38d6918ba 1243 oled.Label((uint8_t *)"-", 32, 60);// Display at x,y
asong 1:e4b38d6918ba 1244 sprintf(display_buff, "%u", HR_Zone1[1]); // Convert int to char to display
asong 1:e4b38d6918ba 1245 oled.Label((uint8_t *)display_buff, 40, 60);// Display at x,y
asong 2:824ed4ae8d52 1246 } else if(Target_Zone == 2) {
asong 1:e4b38d6918ba 1247 textProperties.fontColor = COLOR_BLUE; //Change font to blue
asong 1:e4b38d6918ba 1248 oled.SetTextProperties(&textProperties);//Implement color change
asong 1:e4b38d6918ba 1249 sprintf(display_buff, "%u", HR_Zone2[0]); // Convert int to char to display
asong 1:e4b38d6918ba 1250 oled.Label((uint8_t *)display_buff, 10, 60);// Display at x,y
asong 1:e4b38d6918ba 1251 oled.Label((uint8_t *)"-", 32, 60);// Display at x,y
asong 1:e4b38d6918ba 1252 sprintf(display_buff, "%u", HR_Zone2[1]); // Convert int to char to display
asong 1:e4b38d6918ba 1253 oled.Label((uint8_t *)display_buff, 40, 60);// Display at x,y
asong 2:824ed4ae8d52 1254 } else if(Target_Zone == 3) {
asong 1:e4b38d6918ba 1255 textProperties.fontColor = COLOR_GREEN; //Change font to green
asong 1:e4b38d6918ba 1256 oled.SetTextProperties(&textProperties);//Implement color change
asong 1:e4b38d6918ba 1257 sprintf(display_buff, "%u", HR_Zone3[0]); // Convert int to char to display
asong 1:e4b38d6918ba 1258 oled.Label((uint8_t *)display_buff, 10, 60); // Display at x,y
asong 1:e4b38d6918ba 1259 oled.Label((uint8_t *)"-", 32, 60); // Display at x,y
asong 1:e4b38d6918ba 1260 sprintf(display_buff, "%u", HR_Zone3[1]); // Convert int to char to display
asong 1:e4b38d6918ba 1261 oled.Label((uint8_t *)display_buff, 40, 60);// Display at x,y
asong 2:824ed4ae8d52 1262 } else if(Target_Zone == 4) {
asong 1:e4b38d6918ba 1263 textProperties.fontColor = COLOR_RED; //Change font to red
asong 1:e4b38d6918ba 1264 oled.SetTextProperties(&textProperties);//Implement color change
asong 1:e4b38d6918ba 1265 sprintf(display_buff, "%u", HR_Zone4[0]); // Convert int to char to display
asong 1:e4b38d6918ba 1266 oled.Label((uint8_t *)display_buff, 10, 60); // Display at x,y
asong 1:e4b38d6918ba 1267 oled.Label((uint8_t *)"-", 32, 60); // Display at x,y
asong 1:e4b38d6918ba 1268 sprintf(display_buff, "%u", HR_Zone4[1]); // Convert int to char to display
asong 1:e4b38d6918ba 1269 oled.Label((uint8_t *)display_buff, 40, 60); // Display at x,y
asong 1:e4b38d6918ba 1270 }
asong 1:e4b38d6918ba 1271 textProperties.fontColor = COLOR_WHITE; //Change font to white
asong 1:e4b38d6918ba 1272 oled.SetTextProperties(&textProperties);//Implement color change
asong 2:824ed4ae8d52 1273 break;
asong 2:824ed4ae8d52 1274 }
asong 2:824ed4ae8d52 1275 case 31: {
asong 2:824ed4ae8d52 1276 oled.FillScreen(COLOR_BLACK);
asong 2:824ed4ae8d52 1277 Heart_Rate_Vibrations();
asong 2:824ed4ae8d52 1278 oled.Label((uint8_t *)"Enter HR", 10, 5);// Display at x,y
asong 2:824ed4ae8d52 1279 oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
asong 2:824ed4ae8d52 1280 oled.Label((uint8_t *)"Next",60,80); //Display "Next" at x,y
asong 2:824ed4ae8d52 1281 oled.Label((uint8_t *)"+",85,15); // "+" at x,y
asong 2:824ed4ae8d52 1282 oled.Label((uint8_t *)"-",85,60); // "-" at x,y
asong 2:824ed4ae8d52 1283 oled.Label((uint8_t *)"HR:", 10, 25);
asong 2:824ed4ae8d52 1284 sprintf(display_buff, "%u", Heart_Rate); // Convert int to char to display
asong 2:824ed4ae8d52 1285 textProperties.fontColor = COLOR_RED; //Change font to red
asong 2:824ed4ae8d52 1286 oled.SetTextProperties(&textProperties);//Implement color change
asong 2:824ed4ae8d52 1287 oled.Label((uint8_t *)display_buff, 40, 25);
asong 2:824ed4ae8d52 1288 textProperties.fontColor = COLOR_WHITE; //Change font to white
asong 2:824ed4ae8d52 1289 oled.SetTextProperties(&textProperties);//Implement color change
asong 2:824ed4ae8d52 1290 oled.Label((uint8_t *)"Cur Zone:", 10, 45);
asong 2:824ed4ae8d52 1291 if(Current_Zone == 1) {
asong 2:824ed4ae8d52 1292 textProperties.fontColor = COLOR_YELLOW;
asong 2:824ed4ae8d52 1293 oled.SetTextProperties(&textProperties);
asong 2:824ed4ae8d52 1294 } else if(Current_Zone == 2) {
asong 2:824ed4ae8d52 1295 textProperties.fontColor = COLOR_BLUE;
asong 2:824ed4ae8d52 1296 oled.SetTextProperties(&textProperties);
asong 2:824ed4ae8d52 1297 } else if(Current_Zone == 3) {
asong 2:824ed4ae8d52 1298 textProperties.fontColor = COLOR_GREEN;
asong 2:824ed4ae8d52 1299 oled.SetTextProperties(&textProperties);
asong 2:824ed4ae8d52 1300 } else if(Current_Zone == 4) {
asong 2:824ed4ae8d52 1301 textProperties.fontColor = COLOR_RED;
asong 2:824ed4ae8d52 1302 oled.SetTextProperties(&textProperties);
asong 2:824ed4ae8d52 1303 }
asong 2:824ed4ae8d52 1304 sprintf(display_buff, "%u", Current_Zone); // Convert int to char to display
asong 2:824ed4ae8d52 1305 oled.Label((uint8_t *)display_buff, 71, 45);
asong 2:824ed4ae8d52 1306 textProperties.fontColor = COLOR_WHITE; //Change font to white
asong 2:824ed4ae8d52 1307 oled.SetTextProperties(&textProperties);//Implement color change
asong 2:824ed4ae8d52 1308 oled.Label((uint8_t *)"Prev Zone:", 10, 60);
asong 2:824ed4ae8d52 1309 if(Prev_Zone == 1) {
asong 2:824ed4ae8d52 1310 textProperties.fontColor = COLOR_YELLOW;
asong 2:824ed4ae8d52 1311 oled.SetTextProperties(&textProperties);
asong 2:824ed4ae8d52 1312 } else if(Prev_Zone == 2) {
asong 2:824ed4ae8d52 1313 textProperties.fontColor = COLOR_BLUE;
asong 2:824ed4ae8d52 1314 oled.SetTextProperties(&textProperties);
asong 2:824ed4ae8d52 1315 } else if(Prev_Zone == 3) {
asong 2:824ed4ae8d52 1316 textProperties.fontColor = COLOR_GREEN;
asong 2:824ed4ae8d52 1317 oled.SetTextProperties(&textProperties);
asong 2:824ed4ae8d52 1318 } else if(Prev_Zone == 4) {
asong 2:824ed4ae8d52 1319 textProperties.fontColor = COLOR_RED;
asong 2:824ed4ae8d52 1320 oled.SetTextProperties(&textProperties);
asong 2:824ed4ae8d52 1321 }
asong 2:824ed4ae8d52 1322 sprintf(display_buff, "%u", Prev_Zone); // Convert int to char to display
asong 2:824ed4ae8d52 1323 oled.Label((uint8_t *)display_buff, 71, 60);
asong 2:824ed4ae8d52 1324 textProperties.fontColor = COLOR_WHITE; //Change font to white
asong 2:824ed4ae8d52 1325 oled.SetTextProperties(&textProperties);//Implement color change
asong 2:824ed4ae8d52 1326 Led_Zone_Indicator();
asong 2:824ed4ae8d52 1327 break;
asong 2:824ed4ae8d52 1328 }
asong 2:824ed4ae8d52 1329 case 32: {
asong 2:824ed4ae8d52 1330 //Zone Boundary Info
asong 2:824ed4ae8d52 1331 oled.FillScreen(COLOR_BLACK);
asong 2:824ed4ae8d52 1332 oled.Label((uint8_t *)"HR Zone Info", 10, 5);// Display at x,y
asong 2:824ed4ae8d52 1333 textProperties.fontColor = COLOR_YELLOW; //Change font to yellow
asong 2:824ed4ae8d52 1334 oled.SetTextProperties(&textProperties);//Implement color change
asong 2:824ed4ae8d52 1335 oled.Label((uint8_t *)"Z1:", 10, 20);// Display at x,y
asong 2:824ed4ae8d52 1336 sprintf(display_buff, "%u", HR_Zone1[0]); // Convert int to char to display
asong 2:824ed4ae8d52 1337 oled.Label((uint8_t *)display_buff, 30, 20);// Display at x,y
asong 2:824ed4ae8d52 1338 oled.Label((uint8_t *)"-", 52, 20);// Display at x,y
asong 2:824ed4ae8d52 1339 sprintf(display_buff, "%u", HR_Zone1[1]); // Convert int to char to display
asong 2:824ed4ae8d52 1340 oled.Label((uint8_t *)display_buff, 60, 20);// Display at x,y
asong 2:824ed4ae8d52 1341 textProperties.fontColor = COLOR_BLUE; //Change font to blue
asong 2:824ed4ae8d52 1342 oled.SetTextProperties(&textProperties);//Implement color change
asong 2:824ed4ae8d52 1343 oled.Label((uint8_t *)"Z2:", 10, 35);// Display at x,y
asong 2:824ed4ae8d52 1344 sprintf(display_buff, "%u", HR_Zone2[0]); // Convert int to char to display
asong 2:824ed4ae8d52 1345 oled.Label((uint8_t *)display_buff, 30, 35);// Display at x,y
asong 2:824ed4ae8d52 1346 oled.Label((uint8_t *)"-", 52, 35);// Display at x,y
asong 2:824ed4ae8d52 1347 sprintf(display_buff, "%u", HR_Zone2[1]); // Convert int to char to display
asong 2:824ed4ae8d52 1348 oled.Label((uint8_t *)display_buff, 60, 35);// Display at x,y
asong 2:824ed4ae8d52 1349 textProperties.fontColor = COLOR_GREEN; //Change font to green
asong 2:824ed4ae8d52 1350 oled.SetTextProperties(&textProperties);//Implement color change
asong 2:824ed4ae8d52 1351 oled.Label((uint8_t *)"Z3:", 10, 50);// Display at x,y
asong 2:824ed4ae8d52 1352 sprintf(display_buff, "%u", HR_Zone3[0]); // Convert int to char to display
asong 2:824ed4ae8d52 1353 oled.Label((uint8_t *)display_buff, 30, 50);// Display at x,y
asong 2:824ed4ae8d52 1354 oled.Label((uint8_t *)"-", 52, 50);// Display at x,y
asong 2:824ed4ae8d52 1355 sprintf(display_buff, "%u", HR_Zone3[1]); // Convert int to char to display
asong 2:824ed4ae8d52 1356 oled.Label((uint8_t *)display_buff, 60, 50);// Display at x,y
asong 2:824ed4ae8d52 1357 textProperties.fontColor = COLOR_RED; //Change font to red
asong 2:824ed4ae8d52 1358 oled.SetTextProperties(&textProperties);//Implement color change
asong 2:824ed4ae8d52 1359 oled.Label((uint8_t *)"Z4:", 10, 65);// Display at x,y
asong 2:824ed4ae8d52 1360 sprintf(display_buff, "%u", HR_Zone4[0]); // Convert int to char to display
asong 2:824ed4ae8d52 1361 oled.Label((uint8_t *)display_buff, 30, 65);// Display at x,y
asong 2:824ed4ae8d52 1362 oled.Label((uint8_t *)"-", 52, 65);// Display at x,y
asong 2:824ed4ae8d52 1363 sprintf(display_buff, "%u", HR_Zone4[1]); // Convert int to char to display
asong 2:824ed4ae8d52 1364 oled.Label((uint8_t *)display_buff, 60, 65);// Display at x,y
asong 2:824ed4ae8d52 1365 textProperties.fontColor = COLOR_WHITE; //Change font to white
asong 2:824ed4ae8d52 1366 oled.SetTextProperties(&textProperties);//Implement color change
asong 2:824ed4ae8d52 1367 oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
asong 2:824ed4ae8d52 1368 oled.Label((uint8_t *)"Next",60,80); //Display "Next" at x,y
asong 2:824ed4ae8d52 1369 break;
asong 1:e4b38d6918ba 1370 }
nbaker 0:d1d36a3da39b 1371 #endif // end of non-production/debug version code
asong 1:e4b38d6918ba 1372 default: {
asong 2:824ed4ae8d52 1373 Error_Num=1;
asong 2:824ed4ae8d52 1374 error_screen(); // Clear screen
asong 2:824ed4ae8d52 1375 break;
asong 2:824ed4ae8d52 1376 }
nbaker 0:d1d36a3da39b 1377 }
nbaker 0:d1d36a3da39b 1378 }
asong 1:e4b38d6918ba 1379 void error_screen(void)
asong 1:e4b38d6918ba 1380 {
asong 1:e4b38d6918ba 1381 oled.FillScreen(COLOR_RED); // Clear screen
asong 1:e4b38d6918ba 1382 oled.Label((uint8_t *)"Error! ",30,30); // Display error at x,y
asong 1:e4b38d6918ba 1383 sprintf(text_1," %i ",Error_Num);
asong 1:e4b38d6918ba 1384 oled.Label((uint8_t *)text_1,30,60); // Display error at x,y
asong 1:e4b38d6918ba 1385 wait(3); // wait 3 seconds
asong 1:e4b38d6918ba 1386 oled.FillScreen(COLOR_BLACK); // Clear screen
nbaker 0:d1d36a3da39b 1387 }
asong 2:824ed4ae8d52 1388
asong 2:824ed4ae8d52 1389 /*****************************************************************************
asong 2:824ed4ae8d52 1390 Name: StartHaptic
asong 2:824ed4ae8d52 1391 Purpose: Cause the HexiHeart device to vibrate for a predetermined amount of
asong 2:824ed4ae8d52 1392 time
asong 2:824ed4ae8d52 1393 Inputs: None
asong 2:824ed4ae8d52 1394 Returns: None
asong 2:824ed4ae8d52 1395 ******************************************************************************/
nbaker 0:d1d36a3da39b 1396 void StartHaptic(void)
nbaker 0:d1d36a3da39b 1397 {
nbaker 0:d1d36a3da39b 1398 hapticTimer.start(30); // was originaly 50
nbaker 0:d1d36a3da39b 1399 haptic = 1;
nbaker 0:d1d36a3da39b 1400 }
nbaker 0:d1d36a3da39b 1401
asong 2:824ed4ae8d52 1402 /*****************************************************************************
asong 2:824ed4ae8d52 1403 Name: StartHaptic
asong 2:824ed4ae8d52 1404 Purpose: Cause the HexiHeart device to vibrate for x amount of time
asong 2:824ed4ae8d52 1405 Inputs: An int representing the duration of the vibration
asong 2:824ed4ae8d52 1406 Returns: None
asong 2:824ed4ae8d52 1407 ******************************************************************************/
asong 1:e4b38d6918ba 1408 void StartHaptic(int x)
asong 1:e4b38d6918ba 1409 {
asong 1:e4b38d6918ba 1410 hapticTimer.start(x);
asong 2:824ed4ae8d52 1411 haptic = 1;
asong 1:e4b38d6918ba 1412 }
asong 1:e4b38d6918ba 1413
asong 1:e4b38d6918ba 1414 void StopHaptic(void const *n)
asong 1:e4b38d6918ba 1415 {
nbaker 0:d1d36a3da39b 1416 haptic = 0;
nbaker 0:d1d36a3da39b 1417 hapticTimer.stop();
nbaker 0:d1d36a3da39b 1418 }
asong 2:824ed4ae8d52 1419
asong 2:824ed4ae8d52 1420 /*****************************************************************************
asong 2:824ed4ae8d52 1421 Name: Increment_Age
asong 2:824ed4ae8d52 1422 Purpose: Increment the user's age by 1
asong 2:824ed4ae8d52 1423 Inputs: None
asong 2:824ed4ae8d52 1424 Returns: None
asong 2:824ed4ae8d52 1425 ******************************************************************************/
asong 2:824ed4ae8d52 1426 void Increment_Age()
asong 2:824ed4ae8d52 1427 {
asong 2:824ed4ae8d52 1428 StartHaptic();
asong 2:824ed4ae8d52 1429 if(Age < 100) {
asong 2:824ed4ae8d52 1430 Age += 1;
asong 2:824ed4ae8d52 1431 Screen_Num = 27;
asong 2:824ed4ae8d52 1432 } else {
asong 2:824ed4ae8d52 1433 Age = 1;
asong 2:824ed4ae8d52 1434 }
asong 2:824ed4ae8d52 1435 }
asong 2:824ed4ae8d52 1436
asong 2:824ed4ae8d52 1437 /*****************************************************************************
asong 2:824ed4ae8d52 1438 Name: Decrement_Age
asong 2:824ed4ae8d52 1439 Purpose: Decrement the user's age by 1
asong 2:824ed4ae8d52 1440 Inputs: None
asong 2:824ed4ae8d52 1441 Returns: None
asong 2:824ed4ae8d52 1442 ******************************************************************************/
asong 2:824ed4ae8d52 1443 void Decrement_Age()
asong 2:824ed4ae8d52 1444 {
asong 2:824ed4ae8d52 1445 StartHaptic();
asong 2:824ed4ae8d52 1446 if(Age == 1) {
asong 2:824ed4ae8d52 1447 Age = 100;
asong 2:824ed4ae8d52 1448 } else {
asong 2:824ed4ae8d52 1449 Age -= 1;
asong 2:824ed4ae8d52 1450 Screen_Num = 27;
asong 2:824ed4ae8d52 1451 }
asong 2:824ed4ae8d52 1452 }
asong 2:824ed4ae8d52 1453
asong 2:824ed4ae8d52 1454 /*****************************************************************************
asong 2:824ed4ae8d52 1455 Name: Set_Max_Bpm
asong 2:824ed4ae8d52 1456 Purpose: Calculates the user's maximum heart rate based on their age
asong 2:824ed4ae8d52 1457 Inputs: None
asong 2:824ed4ae8d52 1458 Returns: None
asong 2:824ed4ae8d52 1459 ******************************************************************************/
asong 2:824ed4ae8d52 1460 void Set_Max_Bpm()
asong 2:824ed4ae8d52 1461 {
asong 2:824ed4ae8d52 1462 Max_Bpm = 220 - Age;
asong 2:824ed4ae8d52 1463 }
asong 2:824ed4ae8d52 1464
asong 2:824ed4ae8d52 1465 /*****************************************************************************
asong 2:824ed4ae8d52 1466 Name: Set_Zone_Boundaries
asong 2:824ed4ae8d52 1467 Purpose: Calculates the user's heart rate zones' boundaries based on the user's
asong 2:824ed4ae8d52 1468 maximum heart rate
asong 2:824ed4ae8d52 1469 Inputs: None
asong 2:824ed4ae8d52 1470 Returns: None
asong 2:824ed4ae8d52 1471 ******************************************************************************/
asong 2:824ed4ae8d52 1472 void Set_Zone_Boundaries()
asong 2:824ed4ae8d52 1473 {
asong 2:824ed4ae8d52 1474 Set_Max_Bpm();
asong 2:824ed4ae8d52 1475 HR_Zone1[0] = Max_Bpm * .50; //Set Heart Rate Zone 1
asong 2:824ed4ae8d52 1476 HR_Zone1[1] = Max_Bpm * .60; //Set Heart Rate Zone 1
asong 2:824ed4ae8d52 1477 HR_Zone2[0] = HR_Zone1[1] + 1; //Set Heart Rate Zone 2
asong 2:824ed4ae8d52 1478 HR_Zone2[1] = Max_Bpm * .70; //Set Heart Rate Zone 2
asong 2:824ed4ae8d52 1479 HR_Zone3[0] = HR_Zone2[1] + 1; //Set Heart Rate Zone 3
asong 2:824ed4ae8d52 1480 HR_Zone3[1] = Max_Bpm * .80; //Set Heart Rate Zone 3
asong 2:824ed4ae8d52 1481 HR_Zone4[0] = HR_Zone3[1] + 1; //Set Heart Rate Zone 4
asong 2:824ed4ae8d52 1482 HR_Zone4[1] = Max_Bpm; //Set Heart Rate Zone 4
asong 2:824ed4ae8d52 1483 }
asong 2:824ed4ae8d52 1484
asong 2:824ed4ae8d52 1485 /*****************************************************************************
asong 2:824ed4ae8d52 1486 Name: Increment_Target_Zone
asong 2:824ed4ae8d52 1487 Purpose: Imcrements the user's target heart rate zone preference by 1
asong 2:824ed4ae8d52 1488 Inputs: None
asong 2:824ed4ae8d52 1489 Returns: None
asong 2:824ed4ae8d52 1490 ******************************************************************************/
asong 2:824ed4ae8d52 1491 void Increment_Target_Zone()
asong 2:824ed4ae8d52 1492 {
asong 2:824ed4ae8d52 1493 StartHaptic();
asong 2:824ed4ae8d52 1494 if(Target_Zone == 4) {
asong 2:824ed4ae8d52 1495 Target_Zone = 1;
asong 2:824ed4ae8d52 1496 } else {
asong 2:824ed4ae8d52 1497 Target_Zone += 1;
asong 2:824ed4ae8d52 1498 }
asong 2:824ed4ae8d52 1499 }
asong 2:824ed4ae8d52 1500
asong 2:824ed4ae8d52 1501 /*****************************************************************************
asong 2:824ed4ae8d52 1502 Name: Decrement_Target_Zone
asong 2:824ed4ae8d52 1503 Purpose: Decrements the user's target heart rate zone preference by 1
asong 2:824ed4ae8d52 1504 Inputs: None
asong 2:824ed4ae8d52 1505 Returns: None
asong 2:824ed4ae8d52 1506 ******************************************************************************/
asong 2:824ed4ae8d52 1507 void Decrement_Target_Zone()
asong 2:824ed4ae8d52 1508 {
asong 2:824ed4ae8d52 1509 StartHaptic();
asong 2:824ed4ae8d52 1510 if(Target_Zone == 1) {
asong 2:824ed4ae8d52 1511 Target_Zone = 4;
asong 2:824ed4ae8d52 1512 } else {
asong 2:824ed4ae8d52 1513 Target_Zone -= 1;
asong 2:824ed4ae8d52 1514 }
asong 2:824ed4ae8d52 1515 }
asong 2:824ed4ae8d52 1516
asong 2:824ed4ae8d52 1517 /*****************************************************************************
asong 2:824ed4ae8d52 1518 Name: Increment_HR_Vibr_Pref
asong 2:824ed4ae8d52 1519 Purpose: Increment the user's heart rate vibration preference by 1
asong 2:824ed4ae8d52 1520 Inputs: None
asong 2:824ed4ae8d52 1521 Returns: None
asong 2:824ed4ae8d52 1522 ******************************************************************************/
asong 2:824ed4ae8d52 1523 void Increment_HR_Vibr_Pref()
asong 2:824ed4ae8d52 1524 {
asong 2:824ed4ae8d52 1525 StartHaptic();
asong 2:824ed4ae8d52 1526 if(HR_Vibration == 3) {
asong 2:824ed4ae8d52 1527 HR_Vibration = 1;
asong 2:824ed4ae8d52 1528 } else {
asong 2:824ed4ae8d52 1529 HR_Vibration += 1;
asong 2:824ed4ae8d52 1530 }
asong 2:824ed4ae8d52 1531 }
asong 2:824ed4ae8d52 1532
asong 2:824ed4ae8d52 1533 /*****************************************************************************
asong 2:824ed4ae8d52 1534 Name: Decrement_HR_Vibr_Pref
asong 2:824ed4ae8d52 1535 Purpose: Decrement the user's heart rate vibration preference by 1
asong 2:824ed4ae8d52 1536 Inputs: None
asong 2:824ed4ae8d52 1537 Returns: None
asong 2:824ed4ae8d52 1538 ******************************************************************************/
asong 2:824ed4ae8d52 1539 void Decrement_HR_Vibr_Pref()
asong 2:824ed4ae8d52 1540 {
asong 2:824ed4ae8d52 1541 StartHaptic();
asong 2:824ed4ae8d52 1542 if(HR_Vibration == 1) {
asong 2:824ed4ae8d52 1543 HR_Vibration = 3;
asong 2:824ed4ae8d52 1544 } else {
asong 2:824ed4ae8d52 1545 HR_Vibration -= 1;
asong 2:824ed4ae8d52 1546 }
asong 2:824ed4ae8d52 1547 }
asong 2:824ed4ae8d52 1548
asong 2:824ed4ae8d52 1549 /*****************************************************************************
asong 2:824ed4ae8d52 1550 Name: Enable_Heart_Rate
asong 2:824ed4ae8d52 1551 Purpose: Turn on the HexiHeart heart rate function
asong 2:824ed4ae8d52 1552 Inputs: None
asong 2:824ed4ae8d52 1553 Returns: None
asong 2:824ed4ae8d52 1554 ******************************************************************************/
asong 2:824ed4ae8d52 1555 void Enable_Heart_Rate()
asong 2:824ed4ae8d52 1556 {
asong 2:824ed4ae8d52 1557 Heart_Rate_Mode = true;
asong 2:824ed4ae8d52 1558 Heart_Rate_Vibrations();
asong 2:824ed4ae8d52 1559 }
asong 2:824ed4ae8d52 1560
asong 2:824ed4ae8d52 1561 /*****************************************************************************
asong 2:824ed4ae8d52 1562 Name: Disable_Heart_Rate
asong 2:824ed4ae8d52 1563 Purpose: Turn off the HexiHeart heart rate function
asong 2:824ed4ae8d52 1564 Inputs: None
asong 2:824ed4ae8d52 1565 Returns: None
asong 2:824ed4ae8d52 1566 ******************************************************************************/
asong 2:824ed4ae8d52 1567 void Disable_Heart_Rate()
asong 2:824ed4ae8d52 1568 {
asong 2:824ed4ae8d52 1569 Heart_Rate_Mode = false;
asong 2:824ed4ae8d52 1570 Heart_Rate_Vibrations();
asong 2:824ed4ae8d52 1571 }
asong 2:824ed4ae8d52 1572
asong 2:824ed4ae8d52 1573 /*****************************************************************************
asong 2:824ed4ae8d52 1574 Name: Determine_Current_Zone
asong 2:824ed4ae8d52 1575 Purpose: Determines which zone the heart rate is in and assigns the curent
asong 2:824ed4ae8d52 1576 zone and previous zone
asong 2:824ed4ae8d52 1577 Inputs: None
asong 2:824ed4ae8d52 1578 Returns: None
asong 2:824ed4ae8d52 1579 ******************************************************************************/
asong 2:824ed4ae8d52 1580 void Determine_Current_Zone()
asong 2:824ed4ae8d52 1581 {
asong 2:824ed4ae8d52 1582 Prev_Zone = Current_Zone;
asong 2:824ed4ae8d52 1583
asong 2:824ed4ae8d52 1584 if(Heart_Rate >= HR_Zone1[0] && Heart_Rate <= HR_Zone1[1]) {
asong 2:824ed4ae8d52 1585 Current_Zone = 1;
asong 2:824ed4ae8d52 1586 } else if(Heart_Rate >= HR_Zone2[0] && Heart_Rate <= HR_Zone2[1]) {
asong 2:824ed4ae8d52 1587 Current_Zone = 2;
asong 2:824ed4ae8d52 1588 } else if(Heart_Rate >= HR_Zone3[0] && Heart_Rate <= HR_Zone3[1]) {
asong 2:824ed4ae8d52 1589 Current_Zone = 3;
asong 2:824ed4ae8d52 1590 } else if(Heart_Rate >= HR_Zone4[0] && Heart_Rate <= HR_Zone4[1]) {
asong 2:824ed4ae8d52 1591 Current_Zone = 4;
asong 2:824ed4ae8d52 1592 } else {
asong 2:824ed4ae8d52 1593 //error reading, don't change anything
asong 2:824ed4ae8d52 1594 }
asong 2:824ed4ae8d52 1595
asong 2:824ed4ae8d52 1596
asong 2:824ed4ae8d52 1597 }
asong 2:824ed4ae8d52 1598 /*****************************************************************************
asong 2:824ed4ae8d52 1599 Name: Run_Heart_Vibrations
asong 2:824ed4ae8d52 1600 Purpose: Performs the HexiHeart heart rate function
asong 2:824ed4ae8d52 1601 Inputs: None
asong 2:824ed4ae8d52 1602 Returns: None
asong 2:824ed4ae8d52 1603 ******************************************************************************/
asong 2:824ed4ae8d52 1604 void Heart_Rate_Vibrations()
asong 2:824ed4ae8d52 1605 {
asong 2:824ed4ae8d52 1606 if(Heart_Rate_Mode == true) {
asong 2:824ed4ae8d52 1607 if(HR_Vibration == 1) {
asong 2:824ed4ae8d52 1608 //All Pre-loaded vibrations enabled
asong 2:824ed4ae8d52 1609 if(Current_Zone == Prev_Zone) {
asong 2:824ed4ae8d52 1610 // Do nothing if no zone change
asong 2:824ed4ae8d52 1611 } else if(Current_Zone == Target_Zone) { //Changed to target zone
asong 2:824ed4ae8d52 1612 if(Target_Zone == LOWEST_ZONE || Prev_Zone > Target_Zone) { //must have entered from above
asong 2:824ed4ae8d52 1613 StartHaptic(ENTER_ABOVE);
asong 2:824ed4ae8d52 1614 } else if(Target_Zone == HIGHEST_ZONE || Prev_Zone < Target_Zone) { //must have entered from below
asong 2:824ed4ae8d52 1615 StartHaptic(ENTER_BELOW);
asong 2:824ed4ae8d52 1616 }
asong 2:824ed4ae8d52 1617 } else if(Current_Zone != Target_Zone && Prev_Zone == Target_Zone) {
asong 2:824ed4ae8d52 1618 if(Target_Zone == HIGHEST_ZONE || Current_Zone < Target_Zone) { //must have exited below
asong 2:824ed4ae8d52 1619 StartHaptic(EXIT_BELOW);
asong 2:824ed4ae8d52 1620 } else if(Target_Zone == LOWEST_ZONE || Current_Zone > Target_Zone) { //must have exited above
asong 2:824ed4ae8d52 1621 StartHaptic(EXIT_ABOVE);
asong 2:824ed4ae8d52 1622 }
asong 2:824ed4ae8d52 1623 }
asong 2:824ed4ae8d52 1624 } else if(HR_Vibration == 2) {
asong 2:824ed4ae8d52 1625 //Only Entering and Exiting target zone
asong 2:824ed4ae8d52 1626 if(Current_Zone == Prev_Zone) {
asong 2:824ed4ae8d52 1627 //do nothing
asong 2:824ed4ae8d52 1628 } else if(Current_Zone == Target_Zone) {
asong 2:824ed4ae8d52 1629 StartHaptic(VIB_OPT_2);
asong 2:824ed4ae8d52 1630 wait(0.1);
asong 2:824ed4ae8d52 1631 StartHaptic(VIB_OPT_2);
asong 2:824ed4ae8d52 1632 } else if(Current_Zone != Target_Zone && Prev_Zone == Target_Zone) {
asong 2:824ed4ae8d52 1633 StartHaptic(VIB_OPT_2);
asong 2:824ed4ae8d52 1634 wait(0.1);
asong 2:824ed4ae8d52 1635 StartHaptic(VIB_OPT_2);
asong 2:824ed4ae8d52 1636 wait(0.1);
asong 2:824ed4ae8d52 1637 StartHaptic(VIB_OPT_2);
asong 2:824ed4ae8d52 1638 }
asong 2:824ed4ae8d52 1639
asong 2:824ed4ae8d52 1640 } else if(HR_Vibration == 3) {
asong 2:824ed4ae8d52 1641 //No Vibrations
asong 2:824ed4ae8d52 1642
asong 2:824ed4ae8d52 1643 } else {
asong 2:824ed4ae8d52 1644 //Error, can only be choices 1-3
asong 2:824ed4ae8d52 1645 error_screen();
asong 2:824ed4ae8d52 1646 }
asong 2:824ed4ae8d52 1647 }
asong 2:824ed4ae8d52 1648 }
asong 2:824ed4ae8d52 1649
asong 2:824ed4ae8d52 1650 /*****************************************************************************
asong 2:824ed4ae8d52 1651 Name: Increment_Heart_Rate
asong 2:824ed4ae8d52 1652 Purpose: Manually increment the the heart rate measurement by 1 for testing
asong 2:824ed4ae8d52 1653 purposes
asong 2:824ed4ae8d52 1654 Inputs: None
asong 2:824ed4ae8d52 1655 Returns: None
asong 2:824ed4ae8d52 1656 ******************************************************************************/
asong 2:824ed4ae8d52 1657 void Increment_Heart_Rate()
asong 2:824ed4ae8d52 1658 {
asong 2:824ed4ae8d52 1659 //StartHaptic();
asong 2:824ed4ae8d52 1660 if(Heart_Rate == HR_Zone4[1]) {
asong 2:824ed4ae8d52 1661 Heart_Rate = HR_Zone1[0];
asong 2:824ed4ae8d52 1662 } else {
asong 2:824ed4ae8d52 1663 Heart_Rate += 1;
asong 2:824ed4ae8d52 1664 }
asong 2:824ed4ae8d52 1665 }
asong 2:824ed4ae8d52 1666
asong 2:824ed4ae8d52 1667 /*****************************************************************************
asong 2:824ed4ae8d52 1668 Name: Decrement_Heart_Rate
asong 2:824ed4ae8d52 1669 Purpose: Manually decrement the the heart rate measurement by 1 for testing
asong 2:824ed4ae8d52 1670 purposes
asong 2:824ed4ae8d52 1671 Inputs: None
asong 2:824ed4ae8d52 1672 Returns: None
asong 2:824ed4ae8d52 1673 ******************************************************************************/
asong 2:824ed4ae8d52 1674 void Decrement_Heart_Rate()
asong 2:824ed4ae8d52 1675 {
asong 2:824ed4ae8d52 1676 //StartHaptic();
asong 2:824ed4ae8d52 1677 if(Heart_Rate == HR_Zone1[0]) {
asong 2:824ed4ae8d52 1678 Heart_Rate = HR_Zone4[1];
asong 2:824ed4ae8d52 1679 } else {
asong 2:824ed4ae8d52 1680 Heart_Rate -= 1;
asong 2:824ed4ae8d52 1681 }
nbaker 4:0803151bc5e4 1682 } // end of Decrement_Heart_Rate
asong 2:824ed4ae8d52 1683
asong 2:824ed4ae8d52 1684 void Led_Zone_Indicator()
asong 2:824ed4ae8d52 1685 {
asong 2:824ed4ae8d52 1686 if(Led_Zones == true)
asong 2:824ed4ae8d52 1687 {
asong 2:824ed4ae8d52 1688 if(Current_Zone == 1)
asong 2:824ed4ae8d52 1689 {
asong 2:824ed4ae8d52 1690 BLU_Led = LED_OFF;
asong 2:824ed4ae8d52 1691 RED_Led = LED_ON;
asong 2:824ed4ae8d52 1692 GRN_Led = LED_ON;
asong 3:6792c1ba586c 1693
asong 3:6792c1ba586c 1694 wait(0.5);
asong 3:6792c1ba586c 1695 RED_Led = LED_OFF;
asong 3:6792c1ba586c 1696 GRN_Led = LED_OFF;
asong 2:824ed4ae8d52 1697 }
asong 2:824ed4ae8d52 1698 else if(Current_Zone == 2)
asong 2:824ed4ae8d52 1699 {
asong 2:824ed4ae8d52 1700 if(Prev_Zone == 1)
asong 2:824ed4ae8d52 1701 {
asong 2:824ed4ae8d52 1702 RED_Led = LED_OFF;
asong 2:824ed4ae8d52 1703 GRN_Led = LED_OFF;
asong 2:824ed4ae8d52 1704 }
asong 2:824ed4ae8d52 1705 else if(Prev_Zone == 3)
asong 2:824ed4ae8d52 1706 {
asong 2:824ed4ae8d52 1707 GRN_Led = LED_OFF;
asong 2:824ed4ae8d52 1708 }
asong 2:824ed4ae8d52 1709 BLU_Led = LED_ON;
asong 3:6792c1ba586c 1710 wait(0.5);
asong 3:6792c1ba586c 1711 BLU_Led = LED_OFF;
asong 2:824ed4ae8d52 1712 }
asong 2:824ed4ae8d52 1713 else if(Current_Zone == 3)
asong 2:824ed4ae8d52 1714 {
asong 2:824ed4ae8d52 1715 if(Prev_Zone == 2)
asong 2:824ed4ae8d52 1716 {
asong 2:824ed4ae8d52 1717 BLU_Led = LED_OFF;
asong 2:824ed4ae8d52 1718 }
asong 2:824ed4ae8d52 1719 else if(Prev_Zone == 4)
asong 2:824ed4ae8d52 1720 {
asong 2:824ed4ae8d52 1721 RED_Led = LED_OFF;
asong 2:824ed4ae8d52 1722 }
asong 2:824ed4ae8d52 1723 GRN_Led = LED_ON;
asong 3:6792c1ba586c 1724 wait(0.5);
asong 3:6792c1ba586c 1725 GRN_Led = LED_OFF;
asong 2:824ed4ae8d52 1726 }
asong 2:824ed4ae8d52 1727 else if(Current_Zone == 4)
asong 2:824ed4ae8d52 1728 {
asong 2:824ed4ae8d52 1729 GRN_Led = LED_OFF;
asong 2:824ed4ae8d52 1730 RED_Led = LED_ON;
asong 3:6792c1ba586c 1731 wait(0.5);
asong 3:6792c1ba586c 1732 RED_Led = LED_OFF;
asong 2:824ed4ae8d52 1733 }
nbaker 4:0803151bc5e4 1734 }
nbaker 4:0803151bc5e4 1735 }//end of Led_Zone_Indicator
jmr274 5:e1431272be79 1736
jmr274 5:e1431272be79 1737 /*****************************************************************************
jmr274 5:e1431272be79 1738 Name: Heat_Index_Calculation()
jmr274 5:e1431272be79 1739 Purpose: Calculates the heat index using the temperature and humidity sensors
jmr274 5:e1431272be79 1740 Inputs: None
jmr274 5:e1431272be79 1741 Returns: None
jmr274 5:e1431272be79 1742 ******************************************************************************/
jmr274 5:e1431272be79 1743 void Heat_Index_Calculation(){
jmr274 5:e1431272be79 1744 sample_ftemp = temphumid.sample_ftemp();
jmr274 5:e1431272be79 1745
jmr274 5:e1431272be79 1746 sample_humid = temphumid.sample_humid();
jmr274 5:e1431272be79 1747
jmr274 5:e1431272be79 1748 heat_index = -42.379 +
jmr274 5:e1431272be79 1749 2.04901523 * sample_ftemp +
jmr274 5:e1431272be79 1750 10.14333127 * sample_humid -
jmr274 5:e1431272be79 1751 0.22475541 * sample_ftemp * sample_humid -
jmr274 5:e1431272be79 1752 0.00683783 * sample_ftemp * sample_ftemp -
jmr274 5:e1431272be79 1753 0.05481717 * sample_humid * sample_humid +
jmr274 5:e1431272be79 1754 0.00122874 * sample_ftemp * sample_ftemp * sample_humid +
jmr274 5:e1431272be79 1755 0.00085282 * sample_ftemp * sample_humid * sample_humid -
jmr274 5:e1431272be79 1756 0.00000199 * sample_ftemp * sample_ftemp * sample_humid * sample_humid;
jmr274 5:e1431272be79 1757 }
jmr274 5:e1431272be79 1758
nbaker 4:0803151bc5e4 1759 /*****************************************************************************
nbaker 4:0803151bc5e4 1760 Name: fall_detect()
nbaker 4:0803151bc5e4 1761 Purpose: Interupt rutine called when accelerometer IC has detected a free-fall >= 0.5g
nbaker 4:0803151bc5e4 1762
nbaker 4:0803151bc5e4 1763 ******************************************************************************/
nbaker 4:0803151bc5e4 1764
nbaker 4:0803151bc5e4 1765 void fall_detect(){// fall detect interupt rutine
nbaker 4:0803151bc5e4 1766 if(Fall_Alert == 1){
nbaker 4:0803151bc5e4 1767
nbaker 4:0803151bc5e4 1768 // for now just turn on display and give haptic feedback
nbaker 4:0803151bc5e4 1769 Screen_Num = 22; //Change to screen 22 (Fall diag screen)
nbaker 4:0803151bc5e4 1770 Screen_Timer.attach(&timout_timer,(SCRN_TIME));// Reset/restart ticker timer for OLED
nbaker 4:0803151bc5e4 1771 if (OLED_ON == 0) {
nbaker 4:0803151bc5e4 1772 OLED_ON = 1; // Scree was off, set to On
nbaker 4:0803151bc5e4 1773 } // endif
nbaker 4:0803151bc5e4 1774
nbaker 4:0803151bc5e4 1775 //__disable_irq(); // Disable all Interrupts
nbaker 4:0803151bc5e4 1776 // oled.Label((uint8_t *)" Fall Detected ",05,70); // Display at x,y
nbaker 4:0803151bc5e4 1777
nbaker 4:0803151bc5e4 1778 update_display();
nbaker 4:0803151bc5e4 1779 BLU_Led = LED_ON; // LEDs default to on, need to turn off
nbaker 4:0803151bc5e4 1780 Led_clk2 = 1; // Turn LED2 on docking station on
nbaker 4:0803151bc5e4 1781 haptic = 1;
nbaker 4:0803151bc5e4 1782 Accel_INT1.rise(&fall_det_end); // Accel sensor's int#1 calls interupt routine
nbaker 4:0803151bc5e4 1783 //__enable_irq(); // Enable all Interrupts
nbaker 4:0803151bc5e4 1784 }// end if
nbaker 4:0803151bc5e4 1785 }//end fall_detect interupt routine
nbaker 4:0803151bc5e4 1786
nbaker 4:0803151bc5e4 1787
nbaker 4:0803151bc5e4 1788 void fall_detect_off(){// fall detect interupt rutine
nbaker 4:0803151bc5e4 1789 // for now just turn on display and give haptic feedback
nbaker 4:0803151bc5e4 1790 }//end fall_detect_off interupt routine
nbaker 4:0803151bc5e4 1791
nbaker 4:0803151bc5e4 1792 void fall_det_end(){
nbaker 4:0803151bc5e4 1793 haptic = 0; // Turn off Haptic
nbaker 4:0803151bc5e4 1794 BLU_Led = LED_OFF; // Turn off HexiHeart Blue LED
nbaker 4:0803151bc5e4 1795 Led_clk2 = 0; // Turn off LED2 on docking station on
nbaker 4:0803151bc5e4 1796 oled.Label((uint8_t *)" ",05,70); // clear display at x,y
nbaker 4:0803151bc5e4 1797 Accel_INT1.fall(&fall_detect); // Accel sensor's int#1 calls interupt routine
nbaker 4:0803151bc5e4 1798 } //end fall_det_end interupt routine
nbaker 4:0803151bc5e4 1799
nbaker 4:0803151bc5e4 1800 /*****************************************************************************
nbaker 4:0803151bc5e4 1801 Name: impact_detect()
nbaker 4:0803151bc5e4 1802 Purpose: Interupt rutine called when accelerometer IC has detected a vector
nbaker 4:0803151bc5e4 1803 magnitude acceleration >= 3.0g
nbaker 4:0803151bc5e4 1804
nbaker 4:0803151bc5e4 1805 ******************************************************************************/
nbaker 4:0803151bc5e4 1806
nbaker 4:0803151bc5e4 1807 void impact_detect(){
nbaker 4:0803151bc5e4 1808 // oled.Label((uint8_t *)" Impact Detected ",05,60); // Display at x,y
nbaker 4:0803151bc5e4 1809 // GRN_Led = LED_ON; // LEDs default to on, need to turn off
nbaker 4:0803151bc5e4 1810 Led_clk3 = 1; // Turn LED2 on docking station on
nbaker 4:0803151bc5e4 1811 }//end impact_detect interupt routine
nbaker 4:0803151bc5e4 1812
nbaker 4:0803151bc5e4 1813 /*****************************************************************************
nbaker 4:0803151bc5e4 1814 Name: fall_config()
nbaker 4:0803151bc5e4 1815 Purpose: Used to set accelerometer IC's internal registers to set up chip level
nbaker 4:0803151bc5e4 1816 interrupts
nbaker 4:0803151bc5e4 1817 Inputs: int value from 0 to 256
nbaker 4:0803151bc5e4 1818 Returns: None
nbaker 4:0803151bc5e4 1819 ******************************************************************************/
nbaker 4:0803151bc5e4 1820
asong 2:824ed4ae8d52 1821
nbaker 4:0803151bc5e4 1822 void fall_config(uint8_t Num){
nbaker 4:0803151bc5e4 1823 // use case switches here to configure for
nbaker 4:0803151bc5e4 1824 switch(Num) {
nbaker 4:0803151bc5e4 1825 case 0: {// configure as normal (or maybe sleep)
nbaker 4:0803151bc5e4 1826 char d[2];
nbaker 4:0803151bc5e4 1827 d[0] = FXOS8700_CTRL_REG1; //Puts device in Standby mode
nbaker 4:0803151bc5e4 1828 d[1] = 0x00;
nbaker 4:0803151bc5e4 1829 i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2);
nbaker 4:0803151bc5e4 1830
nbaker 4:0803151bc5e4 1831 d[0] = FXOS8700_CTRL_REG1; //Puts device back into active mode
nbaker 4:0803151bc5e4 1832 d[1] = 0x01;
nbaker 4:0803151bc5e4 1833 i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d, 2);
nbaker 4:0803151bc5e4 1834 oled.Label((uint8_t *)" Mode 0 ",30,60); // Display "mode" at x,y
nbaker 4:0803151bc5e4 1835 break;
nbaker 4:0803151bc5e4 1836 }
nbaker 4:0803151bc5e4 1837 case 1: {// configure for free-fall int
nbaker 4:0803151bc5e4 1838 StartHaptic(); // for debug
nbaker 4:0803151bc5e4 1839 char d[2];
nbaker 4:0803151bc5e4 1840 d[0] = FXOS8700_CTRL_REG1; //Config reg1
nbaker 4:0803151bc5e4 1841 d[1] = 0x00; //Put device in Standby mode
nbaker 4:0803151bc5e4 1842 if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
nbaker 4:0803151bc5e4 1843 oled.Label((uint8_t *)" Step1 error ",30,05); // Display "error" at x,y
nbaker 4:0803151bc5e4 1844 wait(3.0); // display for 3 seconds
nbaker 4:0803151bc5e4 1845 }//end if
nbaker 4:0803151bc5e4 1846
nbaker 4:0803151bc5e4 1847 d[0] = 0x0e; //XYZ_DATA_CFG (set full-scall range)
nbaker 4:0803151bc5e4 1848 d[1] = 0b00000000; //Set data to default range of +/-2g for full range (2x0.488mg/LSB), High-pass filter off
nbaker 4:0803151bc5e4 1849 if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
nbaker 4:0803151bc5e4 1850 oled.Label((uint8_t *)" Step1a error ",30,05); // Display "error" at x,y
nbaker 4:0803151bc5e4 1851 wait(3.0); // display for 3 seconds
nbaker 4:0803151bc5e4 1852 }//end if
nbaker 4:0803151bc5e4 1853
nbaker 4:0803151bc5e4 1854 d[0] = 0x0a; //TRIG_CFG (address of trigger config reg)
nbaker 4:0803151bc5e4 1855 d[1] = 0b00000100; //Trigger on freefall
nbaker 4:0803151bc5e4 1856 if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
nbaker 4:0803151bc5e4 1857 oled.Label((uint8_t *)" Step2 error ",30,05); // Display "error" at x,y
nbaker 4:0803151bc5e4 1858 wait(3.0); // display for 3 seconds
nbaker 4:0803151bc5e4 1859 }//end if
nbaker 4:0803151bc5e4 1860
nbaker 4:0803151bc5e4 1861 d[0] = 0x15; //A_FFMT_CFG (address of Free fall trigger config reg), write in Standby only
nbaker 4:0803151bc5e4 1862 d[1] = 0b00111000; //set to freefall, and look at all axis.
nbaker 4:0803151bc5e4 1863 if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
nbaker 4:0803151bc5e4 1864 oled.Label((uint8_t *)" Step3 error ",30,05); // Display "error" at x,y
nbaker 4:0803151bc5e4 1865 wait(3.0); // display for 3 seconds
nbaker 4:0803151bc5e4 1866 }//end if
nbaker 4:0803151bc5e4 1867
nbaker 4:0803151bc5e4 1868 d[0] = 0x17; //A_FFMT_THS (address of Free fall threshold reg), write in Active or Standby
nbaker 4:0803151bc5e4 1869 d[1] = 0b00001000; //set freefall threshold to about 756mg for now
nbaker 4:0803151bc5e4 1870 // d[1] = uint8_t(1000*Fall_Thresh/63); //set freefall threshold - Resolution is 63mg/LSB, 0b111_1111 is maximum value
nbaker 4:0803151bc5e4 1871 if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
nbaker 4:0803151bc5e4 1872 oled.Label((uint8_t *)" Step4 error ",30,05); // Display "error" at x,y
nbaker 4:0803151bc5e4 1873 wait(3.0); // display for 3 seconds
nbaker 4:0803151bc5e4 1874 }//end if
nbaker 4:0803151bc5e4 1875
nbaker 4:0803151bc5e4 1876 d[0] = 0x18; //A_FFMT_COUNT (address of Free fall debounce counter), write in Active or Standby
nbaker 4:0803151bc5e4 1877 d[1] = 0b00000110; //with ODR at 100Hz, should equal 60mS debounce time or 120mS in Sleep
nbaker 4:0803151bc5e4 1878 if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
nbaker 4:0803151bc5e4 1879 oled.Label((uint8_t *)" Step5 error ",30,05); // Display "error" at x,y
nbaker 4:0803151bc5e4 1880 wait(3.0); // display for 3 seconds
nbaker 4:0803151bc5e4 1881 }//end if
nbaker 4:0803151bc5e4 1882
nbaker 4:0803151bc5e4 1883 d[0] = 0x2b; //CTRL_REG2 (address of control reg), write in Standby only
nbaker 4:0803151bc5e4 1884 d[1] = 0b00001101; //Turns Auto-Sleep mode on and low-noise, low power
nbaker 4:0803151bc5e4 1885 if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
nbaker 4:0803151bc5e4 1886 oled.Label((uint8_t *)" Step6 error ",30,05); // Display "error" at x,y
nbaker 4:0803151bc5e4 1887 wait(3.0); // display for 3 seconds
nbaker 4:0803151bc5e4 1888 }//end if
nbaker 4:0803151bc5e4 1889
nbaker 4:0803151bc5e4 1890 d[0] = 0x2c; //CTRL_REG3 (address of Int control reg), write in Standby only
nbaker 4:0803151bc5e4 1891 d[1] = 0b00001000; //FFMT will wake chip from sleep, int are active high
nbaker 4:0803151bc5e4 1892 if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
nbaker 4:0803151bc5e4 1893 oled.Label((uint8_t *)" Step7 error ",30,05); // Display "error" at x,y
nbaker 4:0803151bc5e4 1894 wait(3.0); // display for 3 seconds
nbaker 4:0803151bc5e4 1895 }//end if
nbaker 4:0803151bc5e4 1896
nbaker 4:0803151bc5e4 1897 d[0] = 0x2d; //CTRL_REG4 (address of Int enable reg), write in Standby only
nbaker 4:0803151bc5e4 1898 d[1] = 0b00000100; // FFMT int enabled and for debug I'm using a sleep int
nbaker 4:0803151bc5e4 1899 if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
nbaker 4:0803151bc5e4 1900 oled.Label((uint8_t *)" Step8 error ",30,05); // Display "error" at x,y
nbaker 4:0803151bc5e4 1901 wait(3.0); // display for 3 seconds
nbaker 4:0803151bc5e4 1902 }//end if
nbaker 4:0803151bc5e4 1903
nbaker 4:0803151bc5e4 1904 d[0] = 0x2e; //CTRL_REG5 (Int routing reg), write in Standby only
nbaker 4:0803151bc5e4 1905 d[1] = 0b00000100; // Make FFMT int output on pin INT1(PTC1)
nbaker 4:0803151bc5e4 1906 if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
nbaker 4:0803151bc5e4 1907 oled.Label((uint8_t *)" Step9 error ",30,05); // Display "error" at x,y
nbaker 4:0803151bc5e4 1908 wait(3.0); // display for 3 seconds
nbaker 4:0803151bc5e4 1909 }//end if
nbaker 4:0803151bc5e4 1910
nbaker 4:0803151bc5e4 1911 d[0] = FXOS8700_CTRL_REG1; //CTRL_REG1, write in Standby only except for bit[0]
nbaker 4:0803151bc5e4 1912 d[1] = 0b00011001; //Auto-Sleep mode on set to 50Hz, ODR set to 100Hz Puts device back into Active mode
nbaker 4:0803151bc5e4 1913 if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
nbaker 4:0803151bc5e4 1914 oled.Label((uint8_t *)" Step10 error ",30,05); // Display "error" at x,y
nbaker 4:0803151bc5e4 1915 wait(3.0); // display for 3 seconds
nbaker 4:0803151bc5e4 1916 }//end if
nbaker 4:0803151bc5e4 1917
nbaker 4:0803151bc5e4 1918 //oled.FillScreen(COLOR_BLACK); // Clear screen
nbaker 4:0803151bc5e4 1919 oled.Label((uint8_t *)" Mode 1 ",30,60); // Display "mode" at x,y
nbaker 4:0803151bc5e4 1920 GRN_Led = LED_ON; // LEDs default to on, need to turn on
nbaker 4:0803151bc5e4 1921 break;
nbaker 4:0803151bc5e4 1922 }
nbaker 4:0803151bc5e4 1923 default: {
nbaker 4:0803151bc5e4 1924 oled.Label((uint8_t *)" Mode ? ",30,60); // Display "mode" at x,y
nbaker 4:0803151bc5e4 1925 // unknown config
nbaker 4:0803151bc5e4 1926 break;
nbaker 4:0803151bc5e4 1927 }
nbaker 4:0803151bc5e4 1928 }// end switch
nbaker 4:0803151bc5e4 1929
nbaker 4:0803151bc5e4 1930 }// end Fall_config
nbaker 4:0803151bc5e4 1931