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