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:
asong
Date:
Sat Feb 03 21:42:00 2018 +0000
Revision:
1:e4b38d6918ba
Parent:
0:d1d36a3da39b
Child:
2:824ed4ae8d52
Alex's version including heart rate code;

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
nbaker 0:d1d36a3da39b 16 #include "OLED_types.h" // Text attributs
nbaker 0:d1d36a3da39b 17 #include "string.h"
nbaker 0:d1d36a3da39b 18 #include "OpenSans_Font.h"
asong 1:e4b38d6918ba 19 #include "MAX30101.h"
asong 1:e4b38d6918ba 20
asong 1:e4b38d6918ba 21 /* We need to confirm whether it's better to include and
asong 1:e4b38d6918ba 22 configure every module for lowest power, or whether it's
nbaker 0:d1d36a3da39b 23 better to save memory by not doing that
nbaker 0:d1d36a3da39b 24 */
nbaker 0:d1d36a3da39b 25
nbaker 0:d1d36a3da39b 26 // Definitions
nbaker 0:d1d36a3da39b 27 #define LED_ON 0
nbaker 0:d1d36a3da39b 28 #define LED_OFF 1
nbaker 0:d1d36a3da39b 29 #define SCRN_TIME 10.0
nbaker 0:d1d36a3da39b 30 #define Debug 1 // If "Debug" is defined, our code will compile for debug. Comment out for Production code.
asong 1:e4b38d6918ba 31
nbaker 0:d1d36a3da39b 32 void StartHaptic(void);
asong 1:e4b38d6918ba 33 void StartHaptic(int x);
nbaker 0:d1d36a3da39b 34 void StopHaptic(void const *n);
nbaker 0:d1d36a3da39b 35 void error_screen(void);
nbaker 0:d1d36a3da39b 36 void update_display(void);
nbaker 0:d1d36a3da39b 37
asong 1:e4b38d6918ba 38
nbaker 0:d1d36a3da39b 39 // ***************** Global variables ***********************
nbaker 0:d1d36a3da39b 40 char text_1[20]; // Text buffer - Do we need more?
asong 1:e4b38d6918ba 41 char display_buff[20]; //Buffer for conversion to char to display
asong 1:e4b38d6918ba 42 bool HR_Enable = 0;
nbaker 0:d1d36a3da39b 43 bool OLED_ON = 1; // Turn OLED power on/off
nbaker 0:d1d36a3da39b 44 bool Fall_Alert = 0; // Initialize as no active alert
nbaker 0:d1d36a3da39b 45 bool Panic_Alert = 0; // Initialize as no active alert
asong 1:e4b38d6918ba 46 bool Fall_Alert_Mode = 1; // Initialize with fall alert mode on
asong 1:e4b38d6918ba 47 bool Heart_Rate_Mode = 0; // Initialize with Heart rate off
nbaker 0:d1d36a3da39b 48 float Accel_Mag=0.0; // Vector magnitude calculated from sensor data
nbaker 0:d1d36a3da39b 49 float Accel_Data[3]; // Accel Data from sensor
nbaker 0:d1d36a3da39b 50 float Gyro_Mag=0.0; // Vector magnitude calculated from sensor data
nbaker 0:d1d36a3da39b 51 float Gyro_Data[3]; // Gyro data from sensor
nbaker 0:d1d36a3da39b 52 float Fall_Thresh=0.5; // Initialize Fall detect Threshold
nbaker 0:d1d36a3da39b 53 float Impact_Thresh=3.0; // Initialize Impact detect Threshold
nbaker 0:d1d36a3da39b 54 float Movement_Thresh=50.0; // Initialize Movement detect Threshold
asong 1:e4b38d6918ba 55 uint8_t HR_buff[250];
asong 1:e4b38d6918ba 56 uint8_t *HR_return;
asong 1:e4b38d6918ba 57 uint8_t Age = 50; // Initialize age
asong 1:e4b38d6918ba 58 uint8_t Max_BPM = 220 - Age; // Initialize Max BPM
nbaker 0:d1d36a3da39b 59 uint8_t Screen_Num = 0; // Initialize to main screen
asong 1:e4b38d6918ba 60 uint8_t Error_Num = 0; // Error num for debug
asong 1:e4b38d6918ba 61 uint8_t HR_Vibration = 1; //Choose Heart Rate Vibration Options
asong 1:e4b38d6918ba 62 uint8_t Target_Zone = 3; //Initialize Target Heart Rate Zone to Zone 3
asong 1:e4b38d6918ba 63 uint8_t HR_Zone1[2] = {Max_BPM * .50, Max_BPM * .60}; //Heart Rate Zone 1
asong 1:e4b38d6918ba 64 uint8_t HR_Zone2[2] = {HR_Zone1[1] + 1, Max_BPM * .70}; //Heart Rate Zone 2
asong 1:e4b38d6918ba 65 uint8_t HR_Zone3[2] = {HR_Zone2[1] + 1, Max_BPM * .80}; //Heart Rate Zone 3
asong 1:e4b38d6918ba 66 uint8_t HR_Zone4[2] = {HR_Zone3[1] + 1, Max_BPM}; //Heart Rate Zone 4
nbaker 0:d1d36a3da39b 67 // ***************** Define pins *****************************
nbaker 0:d1d36a3da39b 68 FXAS21002 gyro(PTC11,PTC10); // Gyroscope
nbaker 0:d1d36a3da39b 69 SSD1351 oled(PTB22,PTB21,PTC13,PTB20,PTE6, PTD15); // SSD1351 OLED Driver (MOSI,SCLK,POWER,CS,RST,DC)
nbaker 0:d1d36a3da39b 70 FXOS8700 accel(PTC11, PTC10); // Accelorometer
nbaker 0:d1d36a3da39b 71 FXOS8700 mag(PTC11, PTC10); // Mag (same chip as Accel)
asong 1:e4b38d6918ba 72 //MAX30101 heart(PTB1, PTB0); //Heart Rate Chip
nbaker 0:d1d36a3da39b 73
nbaker 0:d1d36a3da39b 74 DigitalOut RED_Led(LED1);
nbaker 0:d1d36a3da39b 75 DigitalOut GRN_Led(LED2);
nbaker 0:d1d36a3da39b 76 DigitalOut BLU_Led(LED3);
nbaker 0:d1d36a3da39b 77 DigitalOut haptic(PTB9);
nbaker 0:d1d36a3da39b 78
asong 1:e4b38d6918ba 79 /* Instantiate the Hexi KW40Z Driver (UART TX, UART RX) */
nbaker 0:d1d36a3da39b 80 KW40Z kw40z_device(PTE24, PTE25);
nbaker 0:d1d36a3da39b 81
nbaker 0:d1d36a3da39b 82 /* Define timer for haptic feedback */
nbaker 0:d1d36a3da39b 83 RtosTimer hapticTimer(StopHaptic, osTimerOnce);
nbaker 0:d1d36a3da39b 84
nbaker 0:d1d36a3da39b 85 //***************** Tickers and Timers *****************
nbaker 0:d1d36a3da39b 86 Ticker Screen_Timer;// use ticker to turn off OLED
nbaker 0:d1d36a3da39b 87
asong 1:e4b38d6918ba 88 void timout_timer() // turn off display mode
asong 1:e4b38d6918ba 89 {
asong 1:e4b38d6918ba 90 oled.FillScreen(COLOR_BLACK); // Clear screen.. is there a better command for this?
asong 1:e4b38d6918ba 91 OLED_ON = 0; // set flag to off
asong 1:e4b38d6918ba 92 Screen_Timer.detach();
asong 1:e4b38d6918ba 93 }//end routine
asong 1:e4b38d6918ba 94
nbaker 0:d1d36a3da39b 95 void ButtonUp(void)
nbaker 0:d1d36a3da39b 96 {
asong 1:e4b38d6918ba 97 Screen_Timer.attach(&timout_timer,(SCRN_TIME));//Is this sufficient to reset/restart ticker timer for OLED?
asong 1:e4b38d6918ba 98 if (OLED_ON == 0) {
asong 1:e4b38d6918ba 99 OLED_ON = 1; // Scree was off, set to On
asong 1:e4b38d6918ba 100 update_display();
asong 1:e4b38d6918ba 101 } else {
asong 1:e4b38d6918ba 102 switch(Screen_Num) {
asong 1:e4b38d6918ba 103 case 0: {// We're in Main Screen
asong 1:e4b38d6918ba 104 // do nothing, wrong button
asong 1:e4b38d6918ba 105 break;
asong 1:e4b38d6918ba 106 }
asong 1:e4b38d6918ba 107 case 1: {// Panic Alert option
asong 1:e4b38d6918ba 108 StartHaptic();
asong 1:e4b38d6918ba 109 Screen_Num = 26; //Change to screen 5
nbaker 0:d1d36a3da39b 110 #ifdef Debug // in debug show debug/diagnostic screens
asong 1:e4b38d6918ba 111 Screen_Num = 26; //Change to screen 20
nbaker 0:d1d36a3da39b 112 #endif
nbaker 0:d1d36a3da39b 113
asong 1:e4b38d6918ba 114 update_display();
asong 1:e4b38d6918ba 115 break;
asong 1:e4b38d6918ba 116 }
asong 1:e4b38d6918ba 117 case 2: {// Fall Alert option
asong 1:e4b38d6918ba 118 StartHaptic();
asong 1:e4b38d6918ba 119 Screen_Num = 1; //Change to screen 1
asong 1:e4b38d6918ba 120 update_display();
asong 1:e4b38d6918ba 121 break;
asong 1:e4b38d6918ba 122 }
asong 1:e4b38d6918ba 123 case 3: {// Heart Rate Monitoring option
asong 1:e4b38d6918ba 124 StartHaptic();
asong 1:e4b38d6918ba 125 Screen_Num = 2; //Change to screen 2
asong 1:e4b38d6918ba 126 update_display();
asong 1:e4b38d6918ba 127 break;
asong 1:e4b38d6918ba 128 }
asong 1:e4b38d6918ba 129 case 4: {// Alert History option
asong 1:e4b38d6918ba 130 StartHaptic();
asong 1:e4b38d6918ba 131 Screen_Num = 3; //Change to screen 3
asong 1:e4b38d6918ba 132 update_display();
asong 1:e4b38d6918ba 133 break;
asong 1:e4b38d6918ba 134 }
asong 1:e4b38d6918ba 135 case 5: {// About HexiHeart
asong 1:e4b38d6918ba 136 StartHaptic();
asong 1:e4b38d6918ba 137 Screen_Num = 4; //Change to screen 4
asong 1:e4b38d6918ba 138 update_display();
asong 1:e4b38d6918ba 139 break;
asong 1:e4b38d6918ba 140 }
asong 1:e4b38d6918ba 141 case 6: {// Panic Alert
asong 1:e4b38d6918ba 142 StartHaptic();
asong 1:e4b38d6918ba 143 Panic_Alert = !Panic_Alert;
asong 1:e4b38d6918ba 144 update_display();
asong 1:e4b38d6918ba 145 break;
asong 1:e4b38d6918ba 146 }
asong 1:e4b38d6918ba 147 case 7: {// Heart Rate Zone
asong 1:e4b38d6918ba 148 StartHaptic(50);
asong 1:e4b38d6918ba 149 //heart.enable();
asong 1:e4b38d6918ba 150 //HR_Enable = 1;
asong 1:e4b38d6918ba 151 //while(HR_Enable == 1)
asong 1:e4b38d6918ba 152 // heart.readRawData(HR_buff, HR_return);
asong 1:e4b38d6918ba 153 //update_display();
asong 1:e4b38d6918ba 154 break;
asong 1:e4b38d6918ba 155 }
asong 1:e4b38d6918ba 156 case 8: {// Alert History
asong 1:e4b38d6918ba 157 StartHaptic();
asong 1:e4b38d6918ba 158 //Increment alert index
asong 1:e4b38d6918ba 159 break;
asong 1:e4b38d6918ba 160 }
asong 1:e4b38d6918ba 161 case 20: {// Diagnostic/Debug Screens
asong 1:e4b38d6918ba 162 StartHaptic();
asong 1:e4b38d6918ba 163 Screen_Num = 5; //Change to screen 5
asong 1:e4b38d6918ba 164 update_display();
asong 1:e4b38d6918ba 165 break;
asong 1:e4b38d6918ba 166 }
asong 1:e4b38d6918ba 167 case 21: {// Fall Diagnostic
asong 1:e4b38d6918ba 168 StartHaptic();
asong 1:e4b38d6918ba 169 Screen_Num = 25; //Change to screen 25
asong 1:e4b38d6918ba 170 update_display();
asong 1:e4b38d6918ba 171 break;
asong 1:e4b38d6918ba 172 }
asong 1:e4b38d6918ba 173 case 22: {// Fall Debug
asong 1:e4b38d6918ba 174 StartHaptic();
asong 1:e4b38d6918ba 175 Screen_Num = 21; //Change to screen 21
asong 1:e4b38d6918ba 176 update_display();
asong 1:e4b38d6918ba 177 break;
asong 1:e4b38d6918ba 178 }
asong 1:e4b38d6918ba 179 case 23: {// Heart Rate Diagnostic
asong 1:e4b38d6918ba 180 StartHaptic();
asong 1:e4b38d6918ba 181 Screen_Num = 22; //Change to screen 22
asong 1:e4b38d6918ba 182 update_display();
asong 1:e4b38d6918ba 183 break;
asong 1:e4b38d6918ba 184 }
asong 1:e4b38d6918ba 185 case 24: {// Heart Rate Debug
asong 1:e4b38d6918ba 186 StartHaptic();
asong 1:e4b38d6918ba 187 Screen_Num = 23; //Change to screen 23
asong 1:e4b38d6918ba 188 update_display();
asong 1:e4b38d6918ba 189 break;
asong 1:e4b38d6918ba 190 }
asong 1:e4b38d6918ba 191 case 25: {// Heat Index Diagnostic
asong 1:e4b38d6918ba 192 StartHaptic();
asong 1:e4b38d6918ba 193 Screen_Num = 24; //Change to screen 24
asong 1:e4b38d6918ba 194 update_display();
asong 1:e4b38d6918ba 195 break;
asong 1:e4b38d6918ba 196 }
asong 1:e4b38d6918ba 197 case 26: {//Heart Rate Config Option
asong 1:e4b38d6918ba 198 StartHaptic();
asong 1:e4b38d6918ba 199 Screen_Num = 20;
asong 1:e4b38d6918ba 200 update_display();
asong 1:e4b38d6918ba 201 break;
asong 1:e4b38d6918ba 202 }
asong 1:e4b38d6918ba 203 case 27: {//Incrementing Age
asong 1:e4b38d6918ba 204 StartHaptic();
asong 1:e4b38d6918ba 205 if(Age < 100) {
asong 1:e4b38d6918ba 206 Age += 1;
asong 1:e4b38d6918ba 207 Screen_Num = 27;
asong 1:e4b38d6918ba 208 } else {
asong 1:e4b38d6918ba 209 Age = 1;
nbaker 0:d1d36a3da39b 210 }
asong 1:e4b38d6918ba 211 Max_BPM = 220 - Age; //Calculate New Max BPM
asong 1:e4b38d6918ba 212 HR_Zone1[0] = Max_BPM * .50; //Set Heart Rate Zone 1
asong 1:e4b38d6918ba 213 HR_Zone1[1] = Max_BPM * .60; //Set Heart Rate Zone 1
asong 1:e4b38d6918ba 214 HR_Zone2[0] = HR_Zone1[1] + 1; //Set Heart Rate Zone 2
asong 1:e4b38d6918ba 215 HR_Zone2[1] = Max_BPM * .70; //Set Heart Rate Zone 2
asong 1:e4b38d6918ba 216 HR_Zone3[0] = HR_Zone2[1] + 1; //Set Heart Rate Zone 3
asong 1:e4b38d6918ba 217 HR_Zone3[1] = Max_BPM * .80; //Set Heart Rate Zone 3
asong 1:e4b38d6918ba 218 HR_Zone4[0] = HR_Zone3[1] + 1; //Set Heart Rate Zone 4
asong 1:e4b38d6918ba 219 HR_Zone4[1] = Max_BPM; //Set Heart Rate Zone 4
asong 1:e4b38d6918ba 220 update_display();
asong 1:e4b38d6918ba 221 break;
asong 1:e4b38d6918ba 222
asong 1:e4b38d6918ba 223 }
asong 1:e4b38d6918ba 224 case 28: {//Changing Heart Rate Vibration Preferences
asong 1:e4b38d6918ba 225 StartHaptic();
asong 1:e4b38d6918ba 226 if(HR_Vibration == 3) {
asong 1:e4b38d6918ba 227 HR_Vibration = 1;
asong 1:e4b38d6918ba 228 } else {
asong 1:e4b38d6918ba 229 HR_Vibration += 1;
nbaker 0:d1d36a3da39b 230 }
asong 1:e4b38d6918ba 231 update_display();
asong 1:e4b38d6918ba 232 break;
asong 1:e4b38d6918ba 233 }
asong 1:e4b38d6918ba 234 case 30: {//Change Target Heart Rate Zone Preference
asong 1:e4b38d6918ba 235 StartHaptic();
asong 1:e4b38d6918ba 236 if(Target_Zone == 4)
asong 1:e4b38d6918ba 237 {
asong 1:e4b38d6918ba 238 Target_Zone = 1;
asong 1:e4b38d6918ba 239 }
asong 1:e4b38d6918ba 240 else
asong 1:e4b38d6918ba 241 {
asong 1:e4b38d6918ba 242 Target_Zone += 1;
nbaker 0:d1d36a3da39b 243 }
asong 1:e4b38d6918ba 244 update_display();
asong 1:e4b38d6918ba 245 break;
asong 1:e4b38d6918ba 246 }
asong 1:e4b38d6918ba 247 default: {
asong 1:e4b38d6918ba 248 break;
asong 1:e4b38d6918ba 249 }
asong 1:e4b38d6918ba 250 }
nbaker 0:d1d36a3da39b 251 }
asong 1:e4b38d6918ba 252
nbaker 0:d1d36a3da39b 253 }
nbaker 0:d1d36a3da39b 254
nbaker 0:d1d36a3da39b 255 void ButtonDown(void)
nbaker 0:d1d36a3da39b 256 {
asong 1:e4b38d6918ba 257 Screen_Timer.attach(&timout_timer,(SCRN_TIME));//Is this sufficient to reset/restart ticker timer for OLED?
asong 1:e4b38d6918ba 258 if (OLED_ON == 0) {
asong 1:e4b38d6918ba 259 OLED_ON = 1; // Screen was off, set to On
asong 1:e4b38d6918ba 260 update_display();
asong 1:e4b38d6918ba 261 } else {
nbaker 0:d1d36a3da39b 262
asong 1:e4b38d6918ba 263 switch(Screen_Num) {
asong 1:e4b38d6918ba 264 case 0: {// We're in Main Screen
asong 1:e4b38d6918ba 265 // do nothing, wrong button
asong 1:e4b38d6918ba 266 break;
asong 1:e4b38d6918ba 267 }
asong 1:e4b38d6918ba 268 case 1: {// Panic Alert option
asong 1:e4b38d6918ba 269 StartHaptic();
asong 1:e4b38d6918ba 270 Screen_Num = 2; //Change to screen 2
asong 1:e4b38d6918ba 271 update_display();
asong 1:e4b38d6918ba 272 break;
asong 1:e4b38d6918ba 273 }
asong 1:e4b38d6918ba 274 case 2: {// Fall Alert option
asong 1:e4b38d6918ba 275 StartHaptic();
asong 1:e4b38d6918ba 276 Screen_Num = 3; //Change to screen 3
asong 1:e4b38d6918ba 277 update_display();
asong 1:e4b38d6918ba 278 break;
asong 1:e4b38d6918ba 279 }
asong 1:e4b38d6918ba 280 case 3: {// Heart Rate Monitoring option
asong 1:e4b38d6918ba 281 StartHaptic();
asong 1:e4b38d6918ba 282 Screen_Num = 4; //Change to screen 4
asong 1:e4b38d6918ba 283 update_display();
asong 1:e4b38d6918ba 284 break;
asong 1:e4b38d6918ba 285 }
asong 1:e4b38d6918ba 286 case 4: {// Alert History option
asong 1:e4b38d6918ba 287 StartHaptic();
asong 1:e4b38d6918ba 288 Screen_Num = 5; //Change to screen 5
asong 1:e4b38d6918ba 289 update_display();
asong 1:e4b38d6918ba 290 break;
asong 1:e4b38d6918ba 291 }
asong 1:e4b38d6918ba 292 case 5: {// About HexiHeart option
asong 1:e4b38d6918ba 293 StartHaptic();
asong 1:e4b38d6918ba 294 Screen_Num = 26; //Change to screen 1
nbaker 0:d1d36a3da39b 295 #ifdef Debug // in debug show debug/diagnostic screens
asong 1:e4b38d6918ba 296 Screen_Num = 20; //Change to screen 20
nbaker 0:d1d36a3da39b 297 #endif
asong 1:e4b38d6918ba 298 update_display();
asong 1:e4b38d6918ba 299 break;
asong 1:e4b38d6918ba 300 }
asong 1:e4b38d6918ba 301 case 6: {// Panic Alert
asong 1:e4b38d6918ba 302 // do nothing, wrong button
asong 1:e4b38d6918ba 303 break;
asong 1:e4b38d6918ba 304 }
asong 1:e4b38d6918ba 305 case 7: {// Heart Rate Zone
asong 1:e4b38d6918ba 306 StartHaptic(100);
asong 1:e4b38d6918ba 307 HR_Enable = 0;
asong 1:e4b38d6918ba 308 break;
asong 1:e4b38d6918ba 309 }
asong 1:e4b38d6918ba 310 case 8: {// Alert History
asong 1:e4b38d6918ba 311 StartHaptic();
asong 1:e4b38d6918ba 312 //decriment alert index
asong 1:e4b38d6918ba 313 break;
asong 1:e4b38d6918ba 314 }
asong 1:e4b38d6918ba 315 case 20: {// Diagnostic/Debug Screens
asong 1:e4b38d6918ba 316 StartHaptic();
asong 1:e4b38d6918ba 317 Screen_Num = 26; //Change to screen 1
asong 1:e4b38d6918ba 318 update_display();
asong 1:e4b38d6918ba 319 break;
asong 1:e4b38d6918ba 320 }
asong 1:e4b38d6918ba 321 case 21: {// Fall Diagnostic
asong 1:e4b38d6918ba 322 StartHaptic();
asong 1:e4b38d6918ba 323 Screen_Num = 22; //Change to screen 22
asong 1:e4b38d6918ba 324 update_display();
asong 1:e4b38d6918ba 325 break;
asong 1:e4b38d6918ba 326 }
asong 1:e4b38d6918ba 327 case 22: {// Fall Debug
asong 1:e4b38d6918ba 328 StartHaptic();
asong 1:e4b38d6918ba 329 Screen_Num = 23; //Change to screen 23
asong 1:e4b38d6918ba 330 update_display();
asong 1:e4b38d6918ba 331 break;
asong 1:e4b38d6918ba 332 }
asong 1:e4b38d6918ba 333 case 23: {// Heart Rate Diagnostic
asong 1:e4b38d6918ba 334 StartHaptic();
asong 1:e4b38d6918ba 335 Screen_Num = 24; //Change to screen 24
asong 1:e4b38d6918ba 336 update_display();
asong 1:e4b38d6918ba 337 break;
asong 1:e4b38d6918ba 338 }
asong 1:e4b38d6918ba 339 case 24: {// Heart Rate Debug
asong 1:e4b38d6918ba 340 StartHaptic();
asong 1:e4b38d6918ba 341 Screen_Num = 25; //Change to screen 25
asong 1:e4b38d6918ba 342 update_display();
asong 1:e4b38d6918ba 343 break;
asong 1:e4b38d6918ba 344 }
asong 1:e4b38d6918ba 345 case 25: {// Heat Index Diagnostic
asong 1:e4b38d6918ba 346 StartHaptic();
asong 1:e4b38d6918ba 347 Screen_Num = 21; //Change to screen 21
asong 1:e4b38d6918ba 348 update_display();
asong 1:e4b38d6918ba 349 break;
asong 1:e4b38d6918ba 350 }
asong 1:e4b38d6918ba 351 case 26: {//Heart Rate Configs
asong 1:e4b38d6918ba 352 StartHaptic();
asong 1:e4b38d6918ba 353 Screen_Num = 1;
asong 1:e4b38d6918ba 354 update_display();
asong 1:e4b38d6918ba 355 break;
asong 1:e4b38d6918ba 356 }
asong 1:e4b38d6918ba 357 case 27: { //Decrement Age
asong 1:e4b38d6918ba 358 StartHaptic();
asong 1:e4b38d6918ba 359 if(Age == 1) {
asong 1:e4b38d6918ba 360 Age = 100;
asong 1:e4b38d6918ba 361 } else {
asong 1:e4b38d6918ba 362 Age -= 1;
asong 1:e4b38d6918ba 363 Screen_Num = 27;
nbaker 0:d1d36a3da39b 364 }
asong 1:e4b38d6918ba 365 Max_BPM = 220 - Age; //Calculate New Max BPM
asong 1:e4b38d6918ba 366 HR_Zone1[0] = Max_BPM * .50; //Set Heart Rate Zone 1
asong 1:e4b38d6918ba 367 HR_Zone1[1] = Max_BPM * .60; //Set Heart Rate Zone 1
asong 1:e4b38d6918ba 368 HR_Zone2[0] = HR_Zone1[1] + 1; //Set Heart Rate Zone 2
asong 1:e4b38d6918ba 369 HR_Zone2[1] = Max_BPM * .70; //Set Heart Rate Zone 2
asong 1:e4b38d6918ba 370 HR_Zone3[0] = HR_Zone2[1] + 1; //Set Heart Rate Zone 3
asong 1:e4b38d6918ba 371 HR_Zone3[1] = Max_BPM * .80; //Set Heart Rate Zone 3
asong 1:e4b38d6918ba 372 HR_Zone4[0] = HR_Zone3[1] + 1; //Set Heart Rate Zone 4
asong 1:e4b38d6918ba 373 HR_Zone4[1] = Max_BPM; //Set Heart Rate Zone 4
asong 1:e4b38d6918ba 374 update_display();
asong 1:e4b38d6918ba 375 break;
asong 1:e4b38d6918ba 376
asong 1:e4b38d6918ba 377 }
asong 1:e4b38d6918ba 378 case 28: { //Changing Heart Rate Vibration Preference
asong 1:e4b38d6918ba 379 StartHaptic();
asong 1:e4b38d6918ba 380 if(HR_Vibration == 1) {
asong 1:e4b38d6918ba 381 HR_Vibration = 3;
asong 1:e4b38d6918ba 382 } else {
asong 1:e4b38d6918ba 383 HR_Vibration -= 1;
nbaker 0:d1d36a3da39b 384 }
asong 1:e4b38d6918ba 385 update_display();
asong 1:e4b38d6918ba 386 break;
asong 1:e4b38d6918ba 387 }
asong 1:e4b38d6918ba 388 case 30: {//Change Target Heart Rate Zone Preference
asong 1:e4b38d6918ba 389 StartHaptic();
asong 1:e4b38d6918ba 390 if(Target_Zone == 1)
asong 1:e4b38d6918ba 391 {
asong 1:e4b38d6918ba 392 Target_Zone = 4;
nbaker 0:d1d36a3da39b 393 }
asong 1:e4b38d6918ba 394 else
asong 1:e4b38d6918ba 395 {
asong 1:e4b38d6918ba 396 Target_Zone -= 1;
nbaker 0:d1d36a3da39b 397 }
asong 1:e4b38d6918ba 398 update_display();
asong 1:e4b38d6918ba 399 break;
asong 1:e4b38d6918ba 400 }
asong 1:e4b38d6918ba 401 default: {
asong 1:e4b38d6918ba 402 break;
asong 1:e4b38d6918ba 403 }
asong 1:e4b38d6918ba 404 }
nbaker 0:d1d36a3da39b 405 }
nbaker 0:d1d36a3da39b 406 }
nbaker 0:d1d36a3da39b 407
nbaker 0:d1d36a3da39b 408 void ButtonRight(void)
nbaker 0:d1d36a3da39b 409 {
asong 1:e4b38d6918ba 410 Screen_Timer.attach(&timout_timer,(SCRN_TIME));//Is this sufficient to reset/restart ticker timer for OLED?
asong 1:e4b38d6918ba 411 if (OLED_ON == 0) {
asong 1:e4b38d6918ba 412 OLED_ON = 1; // Screen was off, set to On
asong 1:e4b38d6918ba 413 update_display();
asong 1:e4b38d6918ba 414 } else {
asong 1:e4b38d6918ba 415 switch(Screen_Num) {
asong 1:e4b38d6918ba 416 case 0: {// We're in Main Screen
asong 1:e4b38d6918ba 417 StartHaptic();
asong 1:e4b38d6918ba 418 Screen_Num = 1; //Change to screen 1
asong 1:e4b38d6918ba 419 update_display();
asong 1:e4b38d6918ba 420 break;
asong 1:e4b38d6918ba 421 }
asong 1:e4b38d6918ba 422 case 1: {// Panic Alert option
asong 1:e4b38d6918ba 423 StartHaptic();
asong 1:e4b38d6918ba 424 Screen_Num = 6; //Change to screen 6
asong 1:e4b38d6918ba 425 update_display();
asong 1:e4b38d6918ba 426 break;
asong 1:e4b38d6918ba 427 }
asong 1:e4b38d6918ba 428 case 2: {// Fall Alert option
asong 1:e4b38d6918ba 429 StartHaptic();
asong 1:e4b38d6918ba 430 // toggle on/off
asong 1:e4b38d6918ba 431 break;
asong 1:e4b38d6918ba 432 }
asong 1:e4b38d6918ba 433 case 3: {// Heart Rate Monitoring option
asong 1:e4b38d6918ba 434 StartHaptic();
asong 1:e4b38d6918ba 435 Screen_Num = 7; //Change to screen 7
asong 1:e4b38d6918ba 436 update_display();
asong 1:e4b38d6918ba 437 break;
asong 1:e4b38d6918ba 438 }
asong 1:e4b38d6918ba 439 case 4: {// Alert History option
asong 1:e4b38d6918ba 440 StartHaptic();
asong 1:e4b38d6918ba 441 Screen_Num = 8; //Change to screen 8
asong 1:e4b38d6918ba 442 update_display();
asong 1:e4b38d6918ba 443 break;
asong 1:e4b38d6918ba 444 }
asong 1:e4b38d6918ba 445 case 5: {// About HexiHeart option
asong 1:e4b38d6918ba 446 StartHaptic();
asong 1:e4b38d6918ba 447 Screen_Num = 9; //Change to screen 9
asong 1:e4b38d6918ba 448 update_display();
asong 1:e4b38d6918ba 449 break;
asong 1:e4b38d6918ba 450 }
nbaker 0:d1d36a3da39b 451
asong 1:e4b38d6918ba 452 case 6: {// Panic Alert
asong 1:e4b38d6918ba 453 // do nothing, wrong button
asong 1:e4b38d6918ba 454 break;
asong 1:e4b38d6918ba 455 }
asong 1:e4b38d6918ba 456 case 7: {// Heart Rate Zone
asong 1:e4b38d6918ba 457 StartHaptic();
asong 1:e4b38d6918ba 458 // toggle on/off
asong 1:e4b38d6918ba 459 break;
asong 1:e4b38d6918ba 460 }
asong 1:e4b38d6918ba 461 case 20: {// Diagnostic/Debug Screens
asong 1:e4b38d6918ba 462 StartHaptic();
asong 1:e4b38d6918ba 463 Screen_Num = 21; //Change to screen 21
asong 1:e4b38d6918ba 464 update_display();
asong 1:e4b38d6918ba 465 break;
asong 1:e4b38d6918ba 466 }
asong 1:e4b38d6918ba 467 case 26: {//Change to Heart Rate Config Screen
asong 1:e4b38d6918ba 468 StartHaptic();
asong 1:e4b38d6918ba 469 Screen_Num = 27;
asong 1:e4b38d6918ba 470 update_display();
asong 1:e4b38d6918ba 471 break;
asong 1:e4b38d6918ba 472 }
asong 1:e4b38d6918ba 473 case 27: {//Change to Heart Rate Vibration Preferences
asong 1:e4b38d6918ba 474 StartHaptic();
asong 1:e4b38d6918ba 475 Screen_Num = 28;
asong 1:e4b38d6918ba 476 update_display();
asong 1:e4b38d6918ba 477 break;
asong 1:e4b38d6918ba 478 }
asong 1:e4b38d6918ba 479 case 28: {//Change to Heart Rate Zone Boundary Info
asong 1:e4b38d6918ba 480 StartHaptic();
asong 1:e4b38d6918ba 481 Screen_Num = 29;
asong 1:e4b38d6918ba 482 update_display();
asong 1:e4b38d6918ba 483 break;
asong 1:e4b38d6918ba 484 }
asong 1:e4b38d6918ba 485 case 29: {//Change Target Heart Rate Zone Preference
asong 1:e4b38d6918ba 486 StartHaptic();
asong 1:e4b38d6918ba 487 Screen_Num = 30;
asong 1:e4b38d6918ba 488 update_display();
asong 1:e4b38d6918ba 489 break;
asong 1:e4b38d6918ba 490 }
asong 1:e4b38d6918ba 491 case 30: {//Change to Heart Rate Config Screen
asong 1:e4b38d6918ba 492 StartHaptic();
asong 1:e4b38d6918ba 493 Screen_Num = 27;
asong 1:e4b38d6918ba 494 update_display();
asong 1:e4b38d6918ba 495 break;
asong 1:e4b38d6918ba 496 }
asong 1:e4b38d6918ba 497 default: {
asong 1:e4b38d6918ba 498 break;
asong 1:e4b38d6918ba 499 }
asong 1:e4b38d6918ba 500 }
nbaker 0:d1d36a3da39b 501 }
nbaker 0:d1d36a3da39b 502 }
nbaker 0:d1d36a3da39b 503
nbaker 0:d1d36a3da39b 504 void ButtonLeft(void)
nbaker 0:d1d36a3da39b 505 {
asong 1:e4b38d6918ba 506 Screen_Timer.attach(&timout_timer,(SCRN_TIME));//Is this sufficient to reset/restart ticker timer for OLED?
asong 1:e4b38d6918ba 507 if (OLED_ON == 0) {
asong 1:e4b38d6918ba 508 OLED_ON = 1; // Screen was off, set to On
asong 1:e4b38d6918ba 509 update_display();
asong 1:e4b38d6918ba 510 } else {
asong 1:e4b38d6918ba 511 switch(Screen_Num) {
asong 1:e4b38d6918ba 512 case 0: {// We're in Main Screen
asong 1:e4b38d6918ba 513 // do nothing, wrong button
asong 1:e4b38d6918ba 514 break;
asong 1:e4b38d6918ba 515 }
asong 1:e4b38d6918ba 516 case 1: {// Panic Alert option
asong 1:e4b38d6918ba 517 StartHaptic();
asong 1:e4b38d6918ba 518 Screen_Num = 0; //Change to screen 0
asong 1:e4b38d6918ba 519 update_display();
asong 1:e4b38d6918ba 520 break;
asong 1:e4b38d6918ba 521 }
asong 1:e4b38d6918ba 522 case 2: {// Fall Alert option
asong 1:e4b38d6918ba 523 StartHaptic();
asong 1:e4b38d6918ba 524 Screen_Num = 0; //Change to screen 0
asong 1:e4b38d6918ba 525 update_display();
asong 1:e4b38d6918ba 526 break;
asong 1:e4b38d6918ba 527 }
asong 1:e4b38d6918ba 528 case 3: {// Heart Rate Monitoring option
asong 1:e4b38d6918ba 529 StartHaptic();
asong 1:e4b38d6918ba 530 Screen_Num = 0; //Change to screen 0
asong 1:e4b38d6918ba 531 update_display();
asong 1:e4b38d6918ba 532 break;
asong 1:e4b38d6918ba 533 }
asong 1:e4b38d6918ba 534 case 4: {// Alert History option
asong 1:e4b38d6918ba 535 StartHaptic();
asong 1:e4b38d6918ba 536 Screen_Num = 0; //Change to screen 0
asong 1:e4b38d6918ba 537 update_display();
asong 1:e4b38d6918ba 538 break;
asong 1:e4b38d6918ba 539 }
asong 1:e4b38d6918ba 540 case 5: {// About HexiHeart option
asong 1:e4b38d6918ba 541 StartHaptic();
asong 1:e4b38d6918ba 542 Screen_Num = 0; //Change to screen 0
asong 1:e4b38d6918ba 543 update_display();
asong 1:e4b38d6918ba 544 break;
asong 1:e4b38d6918ba 545 }
asong 1:e4b38d6918ba 546 case 6: {// Panic Alert
asong 1:e4b38d6918ba 547 StartHaptic();
asong 1:e4b38d6918ba 548 Screen_Num = 1; //Change to screen 1
asong 1:e4b38d6918ba 549 update_display();
asong 1:e4b38d6918ba 550 break;
asong 1:e4b38d6918ba 551 }
asong 1:e4b38d6918ba 552 case 7: {// Heart Rate Zone
asong 1:e4b38d6918ba 553 StartHaptic();
asong 1:e4b38d6918ba 554 Screen_Num = 3; //Change to screen 3
asong 1:e4b38d6918ba 555 update_display();
asong 1:e4b38d6918ba 556 break;
asong 1:e4b38d6918ba 557 }
asong 1:e4b38d6918ba 558 case 8: {// Alert History
asong 1:e4b38d6918ba 559 StartHaptic();
asong 1:e4b38d6918ba 560 Screen_Num = 4; //Change to screen 4
asong 1:e4b38d6918ba 561 update_display();
asong 1:e4b38d6918ba 562 break;
asong 1:e4b38d6918ba 563 }
asong 1:e4b38d6918ba 564 case 20: {// Diagnostic/Debug Screens
asong 1:e4b38d6918ba 565 StartHaptic();
asong 1:e4b38d6918ba 566 Screen_Num = 0; //Change to screen 0
asong 1:e4b38d6918ba 567 update_display();
asong 1:e4b38d6918ba 568 break;
asong 1:e4b38d6918ba 569 }
asong 1:e4b38d6918ba 570 case 21: {// Fall Diagnostic
asong 1:e4b38d6918ba 571 StartHaptic();
asong 1:e4b38d6918ba 572 Screen_Num = 20; //Change to screen 20
asong 1:e4b38d6918ba 573 update_display();
asong 1:e4b38d6918ba 574 break;
asong 1:e4b38d6918ba 575 }
asong 1:e4b38d6918ba 576 case 22: {// Fall Debug
asong 1:e4b38d6918ba 577 StartHaptic();
asong 1:e4b38d6918ba 578 Screen_Num = 20; //Change to screen 20
asong 1:e4b38d6918ba 579 update_display();
asong 1:e4b38d6918ba 580 break;
asong 1:e4b38d6918ba 581 }
asong 1:e4b38d6918ba 582 case 23: {// Heart Rate Diagnostic
asong 1:e4b38d6918ba 583 StartHaptic();
asong 1:e4b38d6918ba 584 Screen_Num = 20; //Change to screen 20
asong 1:e4b38d6918ba 585 update_display();
asong 1:e4b38d6918ba 586 break;
asong 1:e4b38d6918ba 587 }
asong 1:e4b38d6918ba 588 case 24: {// Heart Rate Debug
asong 1:e4b38d6918ba 589 StartHaptic();
asong 1:e4b38d6918ba 590 Screen_Num = 20; //Change to screen 20
asong 1:e4b38d6918ba 591 update_display();
asong 1:e4b38d6918ba 592 break;
asong 1:e4b38d6918ba 593 }
asong 1:e4b38d6918ba 594 case 25: {// Heat Index Diagnostic
asong 1:e4b38d6918ba 595 StartHaptic();
asong 1:e4b38d6918ba 596 Screen_Num = 20; //Change to screen 20
asong 1:e4b38d6918ba 597 update_display();
asong 1:e4b38d6918ba 598 break;
asong 1:e4b38d6918ba 599 }
asong 1:e4b38d6918ba 600 case 26: {//Heart Rate Config Option
asong 1:e4b38d6918ba 601 StartHaptic();
asong 1:e4b38d6918ba 602 Screen_Num = 0;
asong 1:e4b38d6918ba 603 update_display();
asong 1:e4b38d6918ba 604 break;
asong 1:e4b38d6918ba 605 }
asong 1:e4b38d6918ba 606 case 27: {//Enter Age
asong 1:e4b38d6918ba 607 StartHaptic();
asong 1:e4b38d6918ba 608 Screen_Num = 26;
asong 1:e4b38d6918ba 609 update_display();
asong 1:e4b38d6918ba 610 break;
asong 1:e4b38d6918ba 611 }
asong 1:e4b38d6918ba 612 case 28: {//Heart Rate Vibration Preference Screen
asong 1:e4b38d6918ba 613 StartHaptic();
asong 1:e4b38d6918ba 614 Screen_Num = 27;
asong 1:e4b38d6918ba 615 update_display();
asong 1:e4b38d6918ba 616 break;
asong 1:e4b38d6918ba 617 }
asong 1:e4b38d6918ba 618 case 29: {//Heart Rate Zone Boundary Info
asong 1:e4b38d6918ba 619 StartHaptic();
asong 1:e4b38d6918ba 620 Screen_Num = 28;
asong 1:e4b38d6918ba 621 update_display();
asong 1:e4b38d6918ba 622 break;
asong 1:e4b38d6918ba 623 }
asong 1:e4b38d6918ba 624 case 30: {//Change Target Heart Rate Zone Preference
asong 1:e4b38d6918ba 625 StartHaptic();
asong 1:e4b38d6918ba 626 Screen_Num = 29;
asong 1:e4b38d6918ba 627 update_display();
asong 1:e4b38d6918ba 628 break;
asong 1:e4b38d6918ba 629 }
asong 1:e4b38d6918ba 630 default: {
asong 1:e4b38d6918ba 631 break;
asong 1:e4b38d6918ba 632 }
asong 1:e4b38d6918ba 633 }
nbaker 0:d1d36a3da39b 634 }
nbaker 0:d1d36a3da39b 635 }
nbaker 0:d1d36a3da39b 636
nbaker 0:d1d36a3da39b 637
nbaker 0:d1d36a3da39b 638 void ButtonSlide(void) // What is this Slide button???
nbaker 0:d1d36a3da39b 639 {
asong 1:e4b38d6918ba 640 Screen_Timer.attach(&timout_timer,(SCRN_TIME));//Is this sufficient to reset/restart ticker timer for OLED?
asong 1:e4b38d6918ba 641 if (OLED_ON == 0) {
asong 1:e4b38d6918ba 642 OLED_ON = 1; // Screen was off, set to On
asong 1:e4b38d6918ba 643 }
nbaker 0:d1d36a3da39b 644 StartHaptic();
nbaker 0:d1d36a3da39b 645 oled.FillScreen(COLOR_BLACK); // Clear screen
nbaker 0:d1d36a3da39b 646 strcpy((char *) text_1,"Slide Button");
nbaker 0:d1d36a3da39b 647 oled.Label((uint8_t *)text_1,0,40);
nbaker 0:d1d36a3da39b 648 }
asong 1:e4b38d6918ba 649
nbaker 0:d1d36a3da39b 650 int main()
nbaker 0:d1d36a3da39b 651 {
nbaker 0:d1d36a3da39b 652 oled.FillScreen(COLOR_BLACK); // Clear screen
asong 1:e4b38d6918ba 653 // ***************** Local variables ***********************
asong 1:e4b38d6918ba 654 // float accel_data[3]; float accel_rms=0.0;
asong 1:e4b38d6918ba 655
nbaker 0:d1d36a3da39b 656 // ************** configure sensor modules ******************
nbaker 0:d1d36a3da39b 657 accel.accel_config();
nbaker 0:d1d36a3da39b 658 mag.mag_config();
nbaker 0:d1d36a3da39b 659 // gyro.gyro_config();
asong 1:e4b38d6918ba 660
nbaker 0:d1d36a3da39b 661 RED_Led = LED_OFF;
nbaker 0:d1d36a3da39b 662 GRN_Led = LED_OFF;
nbaker 0:d1d36a3da39b 663 BLU_Led = LED_OFF;
nbaker 0:d1d36a3da39b 664 // ***** Register callbacks/interupts to application functions *********
nbaker 0:d1d36a3da39b 665 kw40z_device.attach_buttonUp(&ButtonUp);
nbaker 0:d1d36a3da39b 666 kw40z_device.attach_buttonDown(&ButtonDown);
nbaker 0:d1d36a3da39b 667 kw40z_device.attach_buttonLeft(&ButtonLeft);
nbaker 0:d1d36a3da39b 668 kw40z_device.attach_buttonRight(&ButtonRight);
nbaker 0:d1d36a3da39b 669 kw40z_device.attach_buttonSlide(&ButtonSlide);
nbaker 0:d1d36a3da39b 670
nbaker 0:d1d36a3da39b 671 // **** Get OLED Class Default Text Properties ****************
asong 1:e4b38d6918ba 672 oled_text_properties_t textProperties = {0};
asong 1:e4b38d6918ba 673 oled.GetTextProperties(&textProperties);
asong 1:e4b38d6918ba 674
nbaker 0:d1d36a3da39b 675 // *********Set text color and screen alignment **************
asong 1:e4b38d6918ba 676 textProperties.fontColor = COLOR_WHITE;
asong 1:e4b38d6918ba 677 textProperties.alignParam = OLED_TEXT_ALIGN_LEFT;
asong 1:e4b38d6918ba 678 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 679
nbaker 0:d1d36a3da39b 680 // ************** Display spash screen **********************
nbaker 0:d1d36a3da39b 681
nbaker 0:d1d36a3da39b 682 oled.Label((uint8_t *)"Hexi",20,5); // Display white "Hexi" at x,y
nbaker 0:d1d36a3da39b 683 textProperties.fontColor = COLOR_RED;
asong 1:e4b38d6918ba 684 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 685 oled.Label((uint8_t *)"Heart",45,5); // Display red "Heart" at x,y
nbaker 0:d1d36a3da39b 686
asong 1:e4b38d6918ba 687 #ifdef Debug // if this is non-production version - do this
nbaker 0:d1d36a3da39b 688 strcpy((char *) text_1,"This is Debug Ver");
nbaker 0:d1d36a3da39b 689 oled.Label((uint8_t *)text_1,0,60); // text_1 at x,y
nbaker 0:d1d36a3da39b 690 StartHaptic();
asong 1:e4b38d6918ba 691 #endif
nbaker 0:d1d36a3da39b 692 textProperties.fontColor = COLOR_WHITE;
nbaker 0:d1d36a3da39b 693 oled.SetTextProperties(&textProperties);
nbaker 0:d1d36a3da39b 694 wait(3); // wait 3 seconds
asong 1:e4b38d6918ba 695 update_display(); // Displays current screen (screen 0)
nbaker 0:d1d36a3da39b 696 Screen_Timer.attach(&timout_timer,(SCRN_TIME));//start ticker timer for turning off LCD
asong 1:e4b38d6918ba 697 // ******************* Main Loop *************************
nbaker 0:d1d36a3da39b 698 while (true) {
nbaker 0:d1d36a3da39b 699
asong 1:e4b38d6918ba 700 Thread::wait(500); // wait half a sec in each loop
nbaker 0:d1d36a3da39b 701 }
nbaker 0:d1d36a3da39b 702 }
nbaker 0:d1d36a3da39b 703 // ************** end of main()
nbaker 0:d1d36a3da39b 704
nbaker 0:d1d36a3da39b 705 void update_display(void)
nbaker 0:d1d36a3da39b 706 {
asong 1:e4b38d6918ba 707 oled_text_properties_t textProperties = {0}; // Need these to change font color
asong 1:e4b38d6918ba 708 oled.GetTextProperties(&textProperties); // Need these to change font color
asong 1:e4b38d6918ba 709 switch(Screen_Num) {
asong 1:e4b38d6918ba 710 case 0: {// Main Screen
asong 1:e4b38d6918ba 711 oled.FillScreen(COLOR_BLACK); // Clear screen
asong 1:e4b38d6918ba 712 oled.Label((uint8_t *)"Batt",60,0); // Display "Batt" at x,y
asong 1:e4b38d6918ba 713 oled.Label((uint8_t *)"Date",35,20); // Display "Date" at x,y
asong 1:e4b38d6918ba 714 oled.Label((uint8_t *)"Time",35,40); // Display "Time" at x,y
asong 1:e4b38d6918ba 715 oled.Label((uint8_t *)"H.I.",10,80); // Display "H.I." at x,y
asong 1:e4b38d6918ba 716 oled.Label((uint8_t *)"BT",40,80); //Display "BT" at x,y
asong 1:e4b38d6918ba 717 oled.Label((uint8_t *)"Menu",60,80); //Display "Menu" at x,y
asong 1:e4b38d6918ba 718 if(Heart_Rate_Mode == 1) {
asong 1:e4b38d6918ba 719 oled.Label((uint8_t *)"BPM",35,60); // Display "H.I." at x,y
asong 1:e4b38d6918ba 720 }
asong 1:e4b38d6918ba 721 break;
asong 1:e4b38d6918ba 722 }
asong 1:e4b38d6918ba 723 case 1: {// Panic Alert option
asong 1:e4b38d6918ba 724 oled.FillScreen(COLOR_BLACK); // Clear screen
asong 1:e4b38d6918ba 725 oled.Label((uint8_t *)"Panic Alert",20,5); // Display at x,y
asong 1:e4b38d6918ba 726 oled.Label((uint8_t *)"*",85,15); // "*" at x,y
asong 1:e4b38d6918ba 727 oled.Label((uint8_t *)"*",85,60); // "*" at x,y
asong 1:e4b38d6918ba 728 oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
asong 1:e4b38d6918ba 729 oled.Label((uint8_t *)"Enter",60,80); //Display "enter" at x,y
asong 1:e4b38d6918ba 730 break;
asong 1:e4b38d6918ba 731 }
asong 1:e4b38d6918ba 732 case 2: {// Fall Alert option
asong 1:e4b38d6918ba 733 oled.FillScreen(COLOR_BLACK); // Clear screen
asong 1:e4b38d6918ba 734 oled.Label((uint8_t *)"Fall Alert",20,5); // Display at x,y
asong 1:e4b38d6918ba 735 oled.Label((uint8_t *)"*",85,15); // "*" at x,y
asong 1:e4b38d6918ba 736 oled.Label((uint8_t *)"*",85,60); // "*" at x,y
asong 1:e4b38d6918ba 737 oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
asong 1:e4b38d6918ba 738 oled.Label((uint8_t *)"Toggle",60,80); //Display "Toggle" at x,y
asong 1:e4b38d6918ba 739 break;
asong 1:e4b38d6918ba 740 }
asong 1:e4b38d6918ba 741 case 3: {// Heart Rate Monitoring option
asong 1:e4b38d6918ba 742 oled.FillScreen(COLOR_BLACK); // Clear screen
asong 1:e4b38d6918ba 743 oled.Label((uint8_t *)"Heart Rate",20,5); // Display at x,y
asong 1:e4b38d6918ba 744 oled.Label((uint8_t *)"*",85,15); // "*" at x,y
asong 1:e4b38d6918ba 745 oled.Label((uint8_t *)"*",85,60); // "*" at x,y
asong 1:e4b38d6918ba 746 oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
asong 1:e4b38d6918ba 747 oled.Label((uint8_t *)"Enter",60,80); //Display at x,y
asong 1:e4b38d6918ba 748 break;
asong 1:e4b38d6918ba 749 }
asong 1:e4b38d6918ba 750 case 4: {// Alert History option
asong 1:e4b38d6918ba 751 oled.FillScreen(COLOR_BLACK); // Clear screen
asong 1:e4b38d6918ba 752 oled.Label((uint8_t *)"Alert History",5,5); // Display at x,y
asong 1:e4b38d6918ba 753 oled.Label((uint8_t *)"*",85,15); // "*" at x,y
asong 1:e4b38d6918ba 754 oled.Label((uint8_t *)"*",85,60); // "*" at x,y
asong 1:e4b38d6918ba 755 oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
asong 1:e4b38d6918ba 756 oled.Label((uint8_t *)"Enter",60,80); //Display at x,y
asong 1:e4b38d6918ba 757 break;
asong 1:e4b38d6918ba 758 }
asong 1:e4b38d6918ba 759 case 5: {// About HexiHeart Screen
nbaker 0:d1d36a3da39b 760
asong 1:e4b38d6918ba 761 oled.FillScreen(COLOR_BLACK); // Clear screen
asong 1:e4b38d6918ba 762 oled.Label((uint8_t *)"Hexi",20,20); // Display white "Hexi" at x,y
asong 1:e4b38d6918ba 763 textProperties.fontColor = COLOR_RED;
asong 1:e4b38d6918ba 764 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 765 oled.Label((uint8_t *)"Heart",45,20); // Display red "Heart" at x,y
asong 1:e4b38d6918ba 766 textProperties.fontColor = COLOR_WHITE;
asong 1:e4b38d6918ba 767 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 768 strcpy((char *) text_1,"About");
asong 1:e4b38d6918ba 769 oled.Label((uint8_t *)text_1,30,5); // text_1 at x,y
asong 1:e4b38d6918ba 770 oled.Label((uint8_t *)"*",85,15); // "*" at x,y
asong 1:e4b38d6918ba 771 oled.Label((uint8_t *)"*",85,60); // "*" at x,y
asong 1:e4b38d6918ba 772 oled.Label((uint8_t *)" Back ",9,80); // Display "Back" at x,y
asong 1:e4b38d6918ba 773 oled.Label((uint8_t *)" Enter ",59,80); //Display at x,y
asong 1:e4b38d6918ba 774 break;
asong 1:e4b38d6918ba 775 }
asong 1:e4b38d6918ba 776
asong 1:e4b38d6918ba 777 case 6: {// Panic Alert
asong 1:e4b38d6918ba 778 oled.FillScreen(COLOR_BLACK); // Clear screen
asong 1:e4b38d6918ba 779 if (Panic_Alert == 0) {
asong 1:e4b38d6918ba 780 oled.Label((uint8_t *)"Send ",20,10); // Display at x,y
asong 1:e4b38d6918ba 781 } else {
asong 1:e4b38d6918ba 782 oled.Label((uint8_t *)"Dismiss ",17,10); // Display at x,y
asong 1:e4b38d6918ba 783 }
asong 1:e4b38d6918ba 784 oled.Label((uint8_t *)"Panic Alert",15,40); // Display at x,y
asong 1:e4b38d6918ba 785 oled.Label((uint8_t *)"-->",80,15); // "*" at x,y
asong 1:e4b38d6918ba 786 oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
asong 1:e4b38d6918ba 787 break;
asong 1:e4b38d6918ba 788 }
asong 1:e4b38d6918ba 789 case 7: {// Heart Rate Zone
asong 1:e4b38d6918ba 790
asong 1:e4b38d6918ba 791 oled.FillScreen(COLOR_BLACK); // Clear screen
asong 1:e4b38d6918ba 792 oled.Label((uint8_t *)"Heart Rate",15,5); // Display at x,y
asong 1:e4b38d6918ba 793 oled.Label((uint8_t *)"HR:",15,25); // Display at x,y
asong 1:e4b38d6918ba 794 oled.Label((uint8_t *)"Age: ",15,45); // Display at x,y
asong 1:e4b38d6918ba 795 textProperties.fontColor = COLOR_GREEN;
asong 1:e4b38d6918ba 796 oled.SetTextProperties(&textProperties); //implements the color change
asong 1:e4b38d6918ba 797 sprintf(display_buff, "%u", Age); //Convert int to char array for displaying user age
asong 1:e4b38d6918ba 798 oled.Label((uint8_t *)display_buff,43,45); // Display at x,y
asong 1:e4b38d6918ba 799 textProperties.fontColor = COLOR_WHITE;
asong 1:e4b38d6918ba 800 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 801 oled.Label((uint8_t *)"+",85,15); // "+" at x,y
asong 1:e4b38d6918ba 802 oled.Label((uint8_t *)"-",85,60); // "-" at x,y
asong 1:e4b38d6918ba 803 oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
asong 1:e4b38d6918ba 804 oled.Label((uint8_t *)"Next",59,80); // Display "Next" at x,y
asong 1:e4b38d6918ba 805
asong 1:e4b38d6918ba 806 //heart.enable();
asong 1:e4b38d6918ba 807 //sprintf(display_buff, "%u", heart.getRevisionID()); //Convert int to char array for displaying user age
asong 1:e4b38d6918ba 808 //oled.Label((uint8_t *)display_buff,45,25); // Display at x,y
asong 1:e4b38d6918ba 809 //update_display();
asong 1:e4b38d6918ba 810 break;
asong 1:e4b38d6918ba 811 }
asong 1:e4b38d6918ba 812 case 8: {// Alert History
asong 1:e4b38d6918ba 813 oled.FillScreen(COLOR_BLACK); // Clear screen
asong 1:e4b38d6918ba 814 oled.Label((uint8_t *)"Alert History",5,5); // Display at x,y
asong 1:e4b38d6918ba 815 oled.Label((uint8_t *)"Date - Time",20,40); // Display at x,y
asong 1:e4b38d6918ba 816 oled.Label((uint8_t *)"Alert Type:",20,60); // Display at x,y
asong 1:e4b38d6918ba 817 oled.Label((uint8_t *)"+",85,15); // "*" at x,y
asong 1:e4b38d6918ba 818 oled.Label((uint8_t *)"-",85,60); // "*" at x,y
asong 1:e4b38d6918ba 819 oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
asong 1:e4b38d6918ba 820 break;
asong 1:e4b38d6918ba 821 }
asong 1:e4b38d6918ba 822 #ifdef Debug // if this is non-production/debug version - do this
asong 1:e4b38d6918ba 823 case 20: {// Diagnostic/Debug Screens
asong 1:e4b38d6918ba 824 oled.FillScreen(COLOR_BLACK); // Clear screen
asong 1:e4b38d6918ba 825 textProperties.fontColor = COLOR_RED;
asong 1:e4b38d6918ba 826 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 827 oled.Label((uint8_t *)"Diagnostics",10,5); // Display at x,y
asong 1:e4b38d6918ba 828 oled.Label((uint8_t *)" Enter ",59,80); //Display at x,y
asong 1:e4b38d6918ba 829 textProperties.fontColor = COLOR_WHITE;
asong 1:e4b38d6918ba 830 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 831 oled.Label((uint8_t *)"*",85,15); // "*" at x,y
asong 1:e4b38d6918ba 832 oled.Label((uint8_t *)"*",85,60); // "*" at x,y
asong 1:e4b38d6918ba 833 oled.Label((uint8_t *)" Back ",9,80); // Display "Back" at x,y
nbaker 0:d1d36a3da39b 834
asong 1:e4b38d6918ba 835 break;
asong 1:e4b38d6918ba 836 }
asong 1:e4b38d6918ba 837 case 21: {// Fall Alert Diagnostic Screen
asong 1:e4b38d6918ba 838 oled.FillScreen(COLOR_BLACK); // Clear screen
asong 1:e4b38d6918ba 839 textProperties.fontColor = COLOR_RED;
asong 1:e4b38d6918ba 840 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 841 oled.Label((uint8_t *)"Fall",30,5); // Display at x,y
asong 1:e4b38d6918ba 842 oled.Label((uint8_t *)"Diagnostic",25,5); // Display at x,y
asong 1:e4b38d6918ba 843 textProperties.fontColor = COLOR_WHITE;
asong 1:e4b38d6918ba 844 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 845 accel.acquire_accel_data_g(Accel_Data);
asong 1:e4b38d6918ba 846 // gyro.acquire_gyro_data_g(Gyro_Data);
asong 1:e4b38d6918ba 847 Accel_Mag = sqrt(((Accel_Data[0]*Accel_Data[0])+(Accel_Data[1]*Accel_Data[1])+(Accel_Data[2]*Accel_Data[2])));
asong 1:e4b38d6918ba 848 // Gyro_Mag = (abs(Gyro_Data[0])+abs(Gyro_Data[1])+abs(Gyro_Data[3]));
asong 1:e4b38d6918ba 849 sprintf(text_1," Accel:%2.2f g ",Accel_Mag);
asong 1:e4b38d6918ba 850 oled.Label((uint8_t *)text_1,10,40);// text_1 at x,y
asong 1:e4b38d6918ba 851 sprintf(text_1," Gyro:%4.0f D/S ",Gyro_Mag);
asong 1:e4b38d6918ba 852 oled.Label((uint8_t *)text_1,10,60);// text_1 at x,y
asong 1:e4b38d6918ba 853 oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
asong 1:e4b38d6918ba 854 break;
asong 1:e4b38d6918ba 855 }
asong 1:e4b38d6918ba 856 case 22: {// Fall Alert Debug Screen
asong 1:e4b38d6918ba 857 oled.FillScreen(COLOR_BLACK); // Clear screen
asong 1:e4b38d6918ba 858 textProperties.fontColor = COLOR_RED;
asong 1:e4b38d6918ba 859 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 860 oled.Label((uint8_t *)"Fall Debug",15,5); // Display at x,y
asong 1:e4b38d6918ba 861 textProperties.fontColor = COLOR_GREEN;
asong 1:e4b38d6918ba 862 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 863 sprintf(text_1," %1.1f g ",Fall_Thresh);
asong 1:e4b38d6918ba 864 oled.Label((uint8_t *)text_1,35,20);// text_1 at x,y
asong 1:e4b38d6918ba 865 sprintf(text_1," %2.1f g ",Impact_Thresh);
asong 1:e4b38d6918ba 866 oled.Label((uint8_t *)text_1,35,35);// text_1 at x,y
asong 1:e4b38d6918ba 867 sprintf(text_1," %3.0f D/S ",Movement_Thresh);
asong 1:e4b38d6918ba 868 oled.Label((uint8_t *)text_1,35,50);// text_1 at x,y
asong 1:e4b38d6918ba 869 textProperties.fontColor = COLOR_WHITE;
asong 1:e4b38d6918ba 870 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 871 oled.Label((uint8_t *)"F-Th:",5,20); // "*" at x,y
asong 1:e4b38d6918ba 872 oled.Label((uint8_t *)"I-Th:",5,35); // "*" at x,y
asong 1:e4b38d6918ba 873 oled.Label((uint8_t *)"M-Th:",5,50); // "*" 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 ",9,80); // Display "Back" at x,y
asong 1:e4b38d6918ba 877 // oled.Label((uint8_t *)" Enter ",59,80); //Display at x,y
asong 1:e4b38d6918ba 878 break;
asong 1:e4b38d6918ba 879 }
asong 1:e4b38d6918ba 880 case 23: {// Heart Rate Diagnostic Screen
asong 1:e4b38d6918ba 881 oled.FillScreen(COLOR_BLACK); // Clear screen
asong 1:e4b38d6918ba 882 textProperties.fontColor = COLOR_RED;
asong 1:e4b38d6918ba 883 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 884 oled.Label((uint8_t *)"H.R. Diagnostic",5,5); // Display at x,y
asong 1:e4b38d6918ba 885 textProperties.fontColor = COLOR_WHITE;
asong 1:e4b38d6918ba 886 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 887 oled.Label((uint8_t *)"*",85,15); // "*" at x,y
asong 1:e4b38d6918ba 888 oled.Label((uint8_t *)"*",85,60); // "*" at x,y
asong 1:e4b38d6918ba 889 oled.Label((uint8_t *)" Back ",9,80); // Display "Back" at x,y
asong 1:e4b38d6918ba 890 // oled.Label((uint8_t *)" Enter ",59,80); //Display at x,y
asong 1:e4b38d6918ba 891 break;
asong 1:e4b38d6918ba 892 }
asong 1:e4b38d6918ba 893 case 24: {// Heart Rate Debug Screen
asong 1:e4b38d6918ba 894 oled.FillScreen(COLOR_BLACK); // Clear screen
asong 1:e4b38d6918ba 895 textProperties.fontColor = COLOR_RED;
asong 1:e4b38d6918ba 896 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 897 oled.Label((uint8_t *)"H.R. Debug",10,5); // Display at x,y
asong 1:e4b38d6918ba 898 textProperties.fontColor = COLOR_WHITE;
asong 1:e4b38d6918ba 899 oled.SetTextProperties(&textProperties);
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 case 25: {// Heat Index Diagnostic Screen
asong 1:e4b38d6918ba 907 oled.FillScreen(COLOR_BLACK); // Clear screen
asong 1:e4b38d6918ba 908 textProperties.fontColor = COLOR_RED;
asong 1:e4b38d6918ba 909 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 910 oled.Label((uint8_t *)"H.I. Diagnostic",5,5); // Display at x,y
asong 1:e4b38d6918ba 911 textProperties.fontColor = COLOR_WHITE;
asong 1:e4b38d6918ba 912 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 913 oled.Label((uint8_t *)"*",85,15); // "*" at x,y
asong 1:e4b38d6918ba 914 oled.Label((uint8_t *)"*",85,60); // "*" at x,y
asong 1:e4b38d6918ba 915 oled.Label((uint8_t *)" Back ",9,80); // Display "Back" at x,y
asong 1:e4b38d6918ba 916 // oled.Label((uint8_t *)" Enter ",59,80); //Display at x,y
asong 1:e4b38d6918ba 917 break;
asong 1:e4b38d6918ba 918 }
asong 1:e4b38d6918ba 919 case 26: {//Heart Rate Config Option
asong 1:e4b38d6918ba 920 oled.FillScreen(COLOR_BLACK); // Clear screen
asong 1:e4b38d6918ba 921 oled.Label((uint8_t *)"HR Config",10,5); // Display at x,y
asong 1:e4b38d6918ba 922 oled.Label((uint8_t *)"*",85,15); // "*" at x,y
asong 1:e4b38d6918ba 923 oled.Label((uint8_t *)"*",85,60); // "*" at x,y
asong 1:e4b38d6918ba 924 oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
asong 1:e4b38d6918ba 925 oled.Label((uint8_t *)"Enter",60,80); //Display "enter" at x,y
asong 1:e4b38d6918ba 926 break;
asong 1:e4b38d6918ba 927 }
asong 1:e4b38d6918ba 928 case 27: { //Enter Age Screen
asong 1:e4b38d6918ba 929 oled.FillScreen(COLOR_BLACK);
asong 1:e4b38d6918ba 930 oled.Label((uint8_t *)"Input Age", 10, 5);
asong 1:e4b38d6918ba 931 sprintf(display_buff, "%u", Age); //Convert int to char array for displaying user age
asong 1:e4b38d6918ba 932 oled.Label((uint8_t *)"Age:", 10, 30);
asong 1:e4b38d6918ba 933 oled.Label((uint8_t *)"+",85,15); // "*" at x,y
asong 1:e4b38d6918ba 934 oled.Label((uint8_t *)"-",85,60); // "*" at x,y
asong 1:e4b38d6918ba 935 oled.Label((uint8_t *)"Menu",10,80); // Display "Menu" at x,y
asong 1:e4b38d6918ba 936 oled.Label((uint8_t *)"Next",60,80); //Display "Next" at x,y
asong 1:e4b38d6918ba 937 textProperties.fontColor = COLOR_GREEN;
asong 1:e4b38d6918ba 938 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 939 oled.Label((uint8_t *)display_buff,43,30); // Display at x,y
asong 1:e4b38d6918ba 940 textProperties.fontColor = COLOR_WHITE;
asong 1:e4b38d6918ba 941 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 942 oled.Label((uint8_t *)"Max bpm:",10,50);
asong 1:e4b38d6918ba 943 textProperties.fontColor = COLOR_RED;
asong 1:e4b38d6918ba 944 oled.SetTextProperties(&textProperties); //implements the color change
asong 1:e4b38d6918ba 945 sprintf(display_buff, "%u", Max_BPM); //Convert int to char array for displaying user max bpm
asong 1:e4b38d6918ba 946 oled.Label((uint8_t *)display_buff, 65, 50);
asong 1:e4b38d6918ba 947 textProperties.fontColor = COLOR_WHITE;
asong 1:e4b38d6918ba 948 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 949 break;
asong 1:e4b38d6918ba 950 }
asong 1:e4b38d6918ba 951 case 28: {//Choose Heart Rate Vibration Option
asong 1:e4b38d6918ba 952 oled.FillScreen(COLOR_BLACK);
asong 1:e4b38d6918ba 953 oled.Label((uint8_t *)"Vibrate Pref", 10, 10);
asong 1:e4b38d6918ba 954 oled.Label((uint8_t *)"Option:", 10, 25);
asong 1:e4b38d6918ba 955 oled.Label((uint8_t *)"+",85,15); // "+" at x,y
asong 1:e4b38d6918ba 956 oled.Label((uint8_t *)"-",85,60); // "-" at x,y
asong 1:e4b38d6918ba 957 oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
asong 1:e4b38d6918ba 958 oled.Label((uint8_t *)"Next",60,80); //Display "Next" at x,y
asong 1:e4b38d6918ba 959 sprintf(display_buff, "%u", HR_Vibration); //Convert int to char array for displaying user preference
asong 1:e4b38d6918ba 960 textProperties.fontColor = COLOR_GREEN; //Change font to green
asong 1:e4b38d6918ba 961 oled.SetTextProperties(&textProperties);//Implement color change
asong 1:e4b38d6918ba 962 oled.Label((uint8_t *)display_buff,55,25); // Display at x,y
asong 1:e4b38d6918ba 963 if(HR_Vibration == 1) {
asong 1:e4b38d6918ba 964 textProperties.fontColor = COLOR_RED; //Change font to red
asong 1:e4b38d6918ba 965 oled.SetTextProperties(&textProperties); //Implement color change
asong 1:e4b38d6918ba 966 oled.Label((uint8_t *)"All On",10,45); // Display at x,y
asong 1:e4b38d6918ba 967 } else if(HR_Vibration == 2) {
asong 1:e4b38d6918ba 968 textProperties.fontColor = COLOR_RED; //Change font to red
asong 1:e4b38d6918ba 969 oled.SetTextProperties(&textProperties);//Implement color change
asong 1:e4b38d6918ba 970 oled.Label((uint8_t *)"Only Entering",10,38);// Display at x,y
asong 1:e4b38d6918ba 971 oled.Label((uint8_t *)"And Exiting",10,53);// Display at x,y
asong 1:e4b38d6918ba 972 oled.Label((uint8_t *)"Target Zone",10,68);// Display at x,y
nbaker 0:d1d36a3da39b 973
asong 1:e4b38d6918ba 974 } else if(HR_Vibration == 3) {
asong 1:e4b38d6918ba 975 textProperties.fontColor = COLOR_RED; //Change font to red
asong 1:e4b38d6918ba 976 oled.SetTextProperties(&textProperties); //Implement color change
asong 1:e4b38d6918ba 977 oled.Label((uint8_t *)"All Off",10,45);// Display at x,y
asong 1:e4b38d6918ba 978 }
asong 1:e4b38d6918ba 979 textProperties.fontColor = COLOR_WHITE;
asong 1:e4b38d6918ba 980 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 981 break;
asong 1:e4b38d6918ba 982 }
asong 1:e4b38d6918ba 983 case 29: { //Zone Boundary Info
asong 1:e4b38d6918ba 984 oled.FillScreen(COLOR_BLACK);
asong 1:e4b38d6918ba 985 oled.Label((uint8_t *)"HR Zone Info", 10, 5);// Display at x,y
asong 1:e4b38d6918ba 986 textProperties.fontColor = COLOR_YELLOW; //Change font to yellow
asong 1:e4b38d6918ba 987 oled.SetTextProperties(&textProperties);//Implement color change
asong 1:e4b38d6918ba 988 oled.Label((uint8_t *)"Z1:", 10, 20);// Display at x,y
asong 1:e4b38d6918ba 989 sprintf(display_buff, "%u", HR_Zone1[0]); // Convert int to char to display
asong 1:e4b38d6918ba 990 oled.Label((uint8_t *)display_buff, 30, 20);// Display at x,y
asong 1:e4b38d6918ba 991 oled.Label((uint8_t *)"-", 52, 20);// Display at x,y
asong 1:e4b38d6918ba 992 sprintf(display_buff, "%u", HR_Zone1[1]); // Convert int to char to display
asong 1:e4b38d6918ba 993 oled.Label((uint8_t *)display_buff, 60, 20);// Display at x,y
asong 1:e4b38d6918ba 994 textProperties.fontColor = COLOR_BLUE; //Change font to blue
asong 1:e4b38d6918ba 995 oled.SetTextProperties(&textProperties);//Implement color change
asong 1:e4b38d6918ba 996 oled.Label((uint8_t *)"Z2:", 10, 35);// Display at x,y
asong 1:e4b38d6918ba 997 sprintf(display_buff, "%u", HR_Zone2[0]); // Convert int to char to display
asong 1:e4b38d6918ba 998 oled.Label((uint8_t *)display_buff, 30, 35);// Display at x,y
asong 1:e4b38d6918ba 999 oled.Label((uint8_t *)"-", 52, 35);// Display at x,y
asong 1:e4b38d6918ba 1000 sprintf(display_buff, "%u", HR_Zone2[1]); // Convert int to char to display
asong 1:e4b38d6918ba 1001 oled.Label((uint8_t *)display_buff, 60, 35);// Display at x,y
asong 1:e4b38d6918ba 1002 textProperties.fontColor = COLOR_GREEN; //Change font to green
asong 1:e4b38d6918ba 1003 oled.SetTextProperties(&textProperties);//Implement color change
asong 1:e4b38d6918ba 1004 oled.Label((uint8_t *)"Z3:", 10, 50);// Display at x,y
asong 1:e4b38d6918ba 1005 sprintf(display_buff, "%u", HR_Zone3[0]); // Convert int to char to display
asong 1:e4b38d6918ba 1006 oled.Label((uint8_t *)display_buff, 30, 50);// Display at x,y
asong 1:e4b38d6918ba 1007 oled.Label((uint8_t *)"-", 52, 50);// Display at x,y
asong 1:e4b38d6918ba 1008 sprintf(display_buff, "%u", HR_Zone3[1]); // Convert int to char to display
asong 1:e4b38d6918ba 1009 oled.Label((uint8_t *)display_buff, 60, 50);// Display at x,y
asong 1:e4b38d6918ba 1010 textProperties.fontColor = COLOR_RED; //Change font to red
asong 1:e4b38d6918ba 1011 oled.SetTextProperties(&textProperties);//Implement color change
asong 1:e4b38d6918ba 1012 oled.Label((uint8_t *)"Z4:", 10, 65);// Display at x,y
asong 1:e4b38d6918ba 1013 sprintf(display_buff, "%u", HR_Zone4[0]); // Convert int to char to display
asong 1:e4b38d6918ba 1014 oled.Label((uint8_t *)display_buff, 30, 65);// Display at x,y
asong 1:e4b38d6918ba 1015 oled.Label((uint8_t *)"-", 52, 65);// Display at x,y
asong 1:e4b38d6918ba 1016 sprintf(display_buff, "%u", HR_Zone4[1]); // Convert int to char to display
asong 1:e4b38d6918ba 1017 oled.Label((uint8_t *)display_buff, 60, 65);// Display at x,y
asong 1:e4b38d6918ba 1018 textProperties.fontColor = COLOR_WHITE; //Change font to white
asong 1:e4b38d6918ba 1019 oled.SetTextProperties(&textProperties);//Implement color change
asong 1:e4b38d6918ba 1020 oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
asong 1:e4b38d6918ba 1021 oled.Label((uint8_t *)"Next",60,80); //Display "Next" at x,y
asong 1:e4b38d6918ba 1022 break;
asong 1:e4b38d6918ba 1023 }
asong 1:e4b38d6918ba 1024 case 30:{ //Enter Target Heart Rate Zone Preference
asong 1:e4b38d6918ba 1025 oled.FillScreen(COLOR_BLACK);
asong 1:e4b38d6918ba 1026 oled.Label((uint8_t *)"Zone Pref", 10, 5);// Display at x,y
asong 1:e4b38d6918ba 1027 oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
asong 1:e4b38d6918ba 1028 oled.Label((uint8_t *)"Next",60,80); //Display "Next" at x,y
asong 1:e4b38d6918ba 1029 oled.Label((uint8_t *)"+",85,15); // "+" at x,y
asong 1:e4b38d6918ba 1030 oled.Label((uint8_t *)"-",85,60); // "-" at x,y
asong 1:e4b38d6918ba 1031 oled.Label((uint8_t *)"Target:", 10, 25);// Display at x,y
asong 1:e4b38d6918ba 1032 sprintf(display_buff, "%u", Target_Zone); // Convert int to char to display
asong 1:e4b38d6918ba 1033 if(Target_Zone == 1)
asong 1:e4b38d6918ba 1034 {
asong 1:e4b38d6918ba 1035 textProperties.fontColor = COLOR_YELLOW; //Change font to yellow
asong 1:e4b38d6918ba 1036 oled.SetTextProperties(&textProperties);//Implement color change
asong 1:e4b38d6918ba 1037 }
asong 1:e4b38d6918ba 1038 else if(Target_Zone == 2)
asong 1:e4b38d6918ba 1039 {
asong 1:e4b38d6918ba 1040 textProperties.fontColor = COLOR_BLUE; //Change font to blue
asong 1:e4b38d6918ba 1041 oled.SetTextProperties(&textProperties);//Implement color change
asong 1:e4b38d6918ba 1042 }
asong 1:e4b38d6918ba 1043 else if(Target_Zone == 3)
asong 1:e4b38d6918ba 1044 {
asong 1:e4b38d6918ba 1045 textProperties.fontColor = COLOR_GREEN; //Change font to green
asong 1:e4b38d6918ba 1046 oled.SetTextProperties(&textProperties);//Implement color change
asong 1:e4b38d6918ba 1047 }
asong 1:e4b38d6918ba 1048 else if(Target_Zone == 4)
asong 1:e4b38d6918ba 1049 {
asong 1:e4b38d6918ba 1050 textProperties.fontColor = COLOR_RED; //Change font to red
asong 1:e4b38d6918ba 1051 oled.SetTextProperties(&textProperties);//Implement color change
asong 1:e4b38d6918ba 1052 }
asong 1:e4b38d6918ba 1053 oled.Label((uint8_t *)display_buff, 55, 25);// Display at x,y
asong 1:e4b38d6918ba 1054 textProperties.fontColor = COLOR_WHITE; //Change font to white
asong 1:e4b38d6918ba 1055 oled.SetTextProperties(&textProperties);//Implement color change
asong 1:e4b38d6918ba 1056 oled.Label((uint8_t *)"Bounds:", 10, 45);// Display at x,y
asong 1:e4b38d6918ba 1057 if(Target_Zone == 1)
asong 1:e4b38d6918ba 1058 {
asong 1:e4b38d6918ba 1059 textProperties.fontColor = COLOR_YELLOW; //Change font to yellow
asong 1:e4b38d6918ba 1060 oled.SetTextProperties(&textProperties);//Implement color change
asong 1:e4b38d6918ba 1061 sprintf(display_buff, "%u", HR_Zone1[0]); // Convert int to char to display
asong 1:e4b38d6918ba 1062 oled.Label((uint8_t *)display_buff, 10, 60);// Display at x,y
asong 1:e4b38d6918ba 1063 oled.Label((uint8_t *)"-", 32, 60);// Display at x,y
asong 1:e4b38d6918ba 1064 sprintf(display_buff, "%u", HR_Zone1[1]); // Convert int to char to display
asong 1:e4b38d6918ba 1065 oled.Label((uint8_t *)display_buff, 40, 60);// Display at x,y
asong 1:e4b38d6918ba 1066 }
asong 1:e4b38d6918ba 1067 else if(Target_Zone == 2)
asong 1:e4b38d6918ba 1068 {
asong 1:e4b38d6918ba 1069 textProperties.fontColor = COLOR_BLUE; //Change font to blue
asong 1:e4b38d6918ba 1070 oled.SetTextProperties(&textProperties);//Implement color change
asong 1:e4b38d6918ba 1071 sprintf(display_buff, "%u", HR_Zone2[0]); // Convert int to char to display
asong 1:e4b38d6918ba 1072 oled.Label((uint8_t *)display_buff, 10, 60);// Display at x,y
asong 1:e4b38d6918ba 1073 oled.Label((uint8_t *)"-", 32, 60);// Display at x,y
asong 1:e4b38d6918ba 1074 sprintf(display_buff, "%u", HR_Zone2[1]); // Convert int to char to display
asong 1:e4b38d6918ba 1075 oled.Label((uint8_t *)display_buff, 40, 60);// Display at x,y
asong 1:e4b38d6918ba 1076 }
asong 1:e4b38d6918ba 1077 else if(Target_Zone == 3)
asong 1:e4b38d6918ba 1078 {
asong 1:e4b38d6918ba 1079 textProperties.fontColor = COLOR_GREEN; //Change font to green
asong 1:e4b38d6918ba 1080 oled.SetTextProperties(&textProperties);//Implement color change
asong 1:e4b38d6918ba 1081 sprintf(display_buff, "%u", HR_Zone3[0]); // Convert int to char to display
asong 1:e4b38d6918ba 1082 oled.Label((uint8_t *)display_buff, 10, 60); // Display at x,y
asong 1:e4b38d6918ba 1083 oled.Label((uint8_t *)"-", 32, 60); // Display at x,y
asong 1:e4b38d6918ba 1084 sprintf(display_buff, "%u", HR_Zone3[1]); // Convert int to char to display
asong 1:e4b38d6918ba 1085 oled.Label((uint8_t *)display_buff, 40, 60);// Display at x,y
asong 1:e4b38d6918ba 1086 }
asong 1:e4b38d6918ba 1087 else if(Target_Zone == 4)
asong 1:e4b38d6918ba 1088 {
asong 1:e4b38d6918ba 1089 textProperties.fontColor = COLOR_RED; //Change font to red
asong 1:e4b38d6918ba 1090 oled.SetTextProperties(&textProperties);//Implement color change
asong 1:e4b38d6918ba 1091 sprintf(display_buff, "%u", HR_Zone4[0]); // Convert int to char to display
asong 1:e4b38d6918ba 1092 oled.Label((uint8_t *)display_buff, 10, 60); // Display at x,y
asong 1:e4b38d6918ba 1093 oled.Label((uint8_t *)"-", 32, 60); // Display at x,y
asong 1:e4b38d6918ba 1094 sprintf(display_buff, "%u", HR_Zone4[1]); // Convert int to char to display
asong 1:e4b38d6918ba 1095 oled.Label((uint8_t *)display_buff, 40, 60); // Display at x,y
asong 1:e4b38d6918ba 1096 }
asong 1:e4b38d6918ba 1097 textProperties.fontColor = COLOR_WHITE; //Change font to white
asong 1:e4b38d6918ba 1098 oled.SetTextProperties(&textProperties);//Implement color change
asong 1:e4b38d6918ba 1099 break;
asong 1:e4b38d6918ba 1100 }
nbaker 0:d1d36a3da39b 1101 #endif // end of non-production/debug version code
asong 1:e4b38d6918ba 1102 default: {
asong 1:e4b38d6918ba 1103 Error_Num=1;
asong 1:e4b38d6918ba 1104 error_screen(); // Clear screen
asong 1:e4b38d6918ba 1105 break;
asong 1:e4b38d6918ba 1106 }
nbaker 0:d1d36a3da39b 1107 }
nbaker 0:d1d36a3da39b 1108 }
asong 1:e4b38d6918ba 1109 void error_screen(void)
asong 1:e4b38d6918ba 1110 {
asong 1:e4b38d6918ba 1111 oled.FillScreen(COLOR_RED); // Clear screen
asong 1:e4b38d6918ba 1112 oled.Label((uint8_t *)"Error! ",30,30); // Display error at x,y
asong 1:e4b38d6918ba 1113 sprintf(text_1," %i ",Error_Num);
asong 1:e4b38d6918ba 1114 oled.Label((uint8_t *)text_1,30,60); // Display error at x,y
asong 1:e4b38d6918ba 1115 wait(3); // wait 3 seconds
asong 1:e4b38d6918ba 1116 oled.FillScreen(COLOR_BLACK); // Clear screen
nbaker 0:d1d36a3da39b 1117 }
nbaker 0:d1d36a3da39b 1118 void StartHaptic(void)
nbaker 0:d1d36a3da39b 1119 {
nbaker 0:d1d36a3da39b 1120 hapticTimer.start(30); // was originaly 50
nbaker 0:d1d36a3da39b 1121 haptic = 1;
nbaker 0:d1d36a3da39b 1122 }
nbaker 0:d1d36a3da39b 1123
asong 1:e4b38d6918ba 1124 void StartHaptic(int x)
asong 1:e4b38d6918ba 1125 {
asong 1:e4b38d6918ba 1126 hapticTimer.start(x);
asong 1:e4b38d6918ba 1127 haptic = 1;
asong 1:e4b38d6918ba 1128 }
asong 1:e4b38d6918ba 1129
asong 1:e4b38d6918ba 1130 void StopHaptic(void const *n)
asong 1:e4b38d6918ba 1131 {
nbaker 0:d1d36a3da39b 1132 haptic = 0;
nbaker 0:d1d36a3da39b 1133 hapticTimer.stop();
nbaker 0:d1d36a3da39b 1134 }