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:
nbaker
Date:
Wed Feb 14 22:53:49 2018 +0000
Revision:
7:3d5a8aea0b63
Parent:
6:84e3ba00b995
Child:
8:a5c77b45008d
This version has both the free-fall interrupt (set to 0.5g) and the impact interrupt (set to about 2g) working independently (either one can occur at any time). Also, time and date disp now work but are not adj (defaults to 2/19/18 at 10am).

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