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@8:a5c77b45008d, 2018-02-19 (annotated)
- Committer:
- nbaker
- Date:
- Mon Feb 19 05:11:42 2018 +0000
- Revision:
- 8:a5c77b45008d
- Parent:
- 7:3d5a8aea0b63
- Child:
- 9:d2e39ee9fedd
This version has BLE screens added, data values refreshed at 2Hz for two screens, fall function variables are adjustable, and other minor improvements.
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 |
jmr274 | 5:e1431272be79 | 16 | #include "HTU21D.h" // Non-Freescale HTU21D - combo temperature and Humidity |
nbaker | 4:0803151bc5e4 | 17 | #include "W25Q64FV.h" // W25Q64FVSSIG Serial Flash |
nbaker | 4:0803151bc5e4 | 18 | // Non-Freescale MPL3115A2 - pressure sensor |
nbaker | 4:0803151bc5e4 | 19 | #include "Hexi_Battery/hexi_battery.h" // Battery status |
nbaker | 0:d1d36a3da39b | 20 | #include "OLED_types.h" // Text attributs |
nbaker | 0:d1d36a3da39b | 21 | #include "string.h" |
nbaker | 0:d1d36a3da39b | 22 | #include "OpenSans_Font.h" |
nbaker | 4:0803151bc5e4 | 23 | #include "MAX30101.h" // Non-Freescale MAX30101 - Optical Heart rate sensor |
asong | 1:e4b38d6918ba | 24 | |
asong | 2:824ed4ae8d52 | 25 | |
asong | 1:e4b38d6918ba | 26 | /* We need to confirm whether it's better to include and |
asong | 1:e4b38d6918ba | 27 | configure every module for lowest power, or whether it's |
nbaker | 0:d1d36a3da39b | 28 | better to save memory by not doing that |
nbaker | 0:d1d36a3da39b | 29 | */ |
nbaker | 0:d1d36a3da39b | 30 | |
nbaker | 0:d1d36a3da39b | 31 | // Definitions |
nbaker | 8:a5c77b45008d | 32 | #define SW_Ver 2.07 // For displaying software version |
asong | 2:824ed4ae8d52 | 33 | #define LED_ON 0 |
asong | 2:824ed4ae8d52 | 34 | #define LED_OFF 1 |
asong | 2:824ed4ae8d52 | 35 | #define SCRN_TIME 10.0 |
asong | 2:824ed4ae8d52 | 36 | #define Debug 1 // If "Debug" is defined, our code will compile for debug. Comment out for Production code. |
asong | 2:824ed4ae8d52 | 37 | #define HIGHEST_ZONE 4 |
asong | 2:824ed4ae8d52 | 38 | #define LOWEST_ZONE 1 |
asong | 2:824ed4ae8d52 | 39 | #define ENTER_BELOW 25 |
asong | 2:824ed4ae8d52 | 40 | #define ENTER_ABOVE 50 |
asong | 2:824ed4ae8d52 | 41 | #define EXIT_BELOW 75 |
asong | 2:824ed4ae8d52 | 42 | #define EXIT_ABOVE 100 |
asong | 2:824ed4ae8d52 | 43 | #define VIB_OPT_2 75 |
nbaker | 4:0803151bc5e4 | 44 | #define FXOS8700_I2C_ADDRESS_ (0x1E<<1) //pins SA0,SA1=0 |
asong | 2:824ed4ae8d52 | 45 | |
asong | 1:e4b38d6918ba | 46 | |
nbaker | 0:d1d36a3da39b | 47 | void StartHaptic(void); |
asong | 1:e4b38d6918ba | 48 | void StartHaptic(int x); |
nbaker | 0:d1d36a3da39b | 49 | void StopHaptic(void const *n); |
nbaker | 0:d1d36a3da39b | 50 | void error_screen(void); |
nbaker | 4:0803151bc5e4 | 51 | void update_display(void);// Screen lables refreshed |
nbaker | 8:a5c77b45008d | 52 | void update_display_date(void); // Screen data(only)refreshed |
asong | 2:824ed4ae8d52 | 53 | void Decrement_Age(); |
asong | 2:824ed4ae8d52 | 54 | void Set_Max_Bpm(); |
asong | 2:824ed4ae8d52 | 55 | void Set_Zone_Boundaries(); |
asong | 2:824ed4ae8d52 | 56 | void Increment_Age(); |
asong | 2:824ed4ae8d52 | 57 | void Increment_Target_Zone(); |
asong | 2:824ed4ae8d52 | 58 | void Decrement_Target_Zone(); |
asong | 2:824ed4ae8d52 | 59 | void Increment_HR_Vibr_Pref(); |
asong | 2:824ed4ae8d52 | 60 | void Decrement_HR_Vibr_Pref(); |
asong | 2:824ed4ae8d52 | 61 | void Determine_Current_Zone(); |
asong | 2:824ed4ae8d52 | 62 | void Heart_Rate_Vibrations(); |
asong | 2:824ed4ae8d52 | 63 | void Increment_Heart_Rate(); |
asong | 2:824ed4ae8d52 | 64 | void Decrement_Heart_Rate(); |
asong | 2:824ed4ae8d52 | 65 | void Enable_Heart_Rate(); |
asong | 2:824ed4ae8d52 | 66 | void Disable_Heart_Rate(); |
asong | 2:824ed4ae8d52 | 67 | void Led_Zone_Indicator(); |
jmr274 | 5:e1431272be79 | 68 | void Heat_Index_Calculation(); |
nbaker | 4:0803151bc5e4 | 69 | void fall_config(uint8_t); |
nbaker | 4:0803151bc5e4 | 70 | void fall_detect(void); |
nbaker | 4:0803151bc5e4 | 71 | void fall_det_end(void); |
nbaker | 4:0803151bc5e4 | 72 | void fall_detect_off(void); |
nbaker | 4:0803151bc5e4 | 73 | void impact_detect(void); |
asong | 1:e4b38d6918ba | 74 | |
nbaker | 0:d1d36a3da39b | 75 | // ***************** Global variables *********************** |
nbaker | 0:d1d36a3da39b | 76 | char text_1[20]; // Text buffer - Do we need more? |
asong | 2:824ed4ae8d52 | 77 | char display_buff[30]; //Buffer for conversion to char to display |
jmr274 | 5:e1431272be79 | 78 | char text[20]; // Text Buffer for dynamic value displayed |
nbaker | 8:a5c77b45008d | 79 | bool BLE_On = 0; // Initialize as BLE on |
nbaker | 8:a5c77b45008d | 80 | char pass [20]; // Passcode |
asong | 2:824ed4ae8d52 | 81 | bool Led_Zones = 1; |
asong | 1:e4b38d6918ba | 82 | bool HR_Enable = 0; |
nbaker | 0:d1d36a3da39b | 83 | bool OLED_ON = 1; // Turn OLED power on/off |
nbaker | 4:0803151bc5e4 | 84 | bool Fall_Alert = 1; // Initialize as no active alert |
jmr274 | 5:e1431272be79 | 85 | bool Panic_Alert = 0; // Initialize as no active alert |
nbaker | 8:a5c77b45008d | 86 | uint8_t Fall_Alert_Mode = 1; // Initialize with fall alert mode on |
jmr274 | 5:e1431272be79 | 87 | bool Heart_Rate_Mode = 0; // Initialize with Heart rate off |
nbaker | 0:d1d36a3da39b | 88 | float Accel_Mag=0.0; // Vector magnitude calculated from sensor data |
nbaker | 0:d1d36a3da39b | 89 | float Accel_Data[3]; // Accel Data from sensor |
nbaker | 7:3d5a8aea0b63 | 90 | float Accel_Data_Event[3]; // Accel Data from sensor at interupt |
jmr274 | 5:e1431272be79 | 91 | float Gyro_Mag=0.0; // Vector magnitude calculated from sensor data |
jmr274 | 5:e1431272be79 | 92 | float Gyro_Data[3]; // Gyro data from sensor |
jmr274 | 5:e1431272be79 | 93 | float Fall_Thresh=0.5; // Initialize Fall detect Threshold |
jmr274 | 5:e1431272be79 | 94 | float Impact_Thresh=3.0; // Initialize Impact detect Threshold |
jmr274 | 5:e1431272be79 | 95 | float Movement_Thresh=50.0; // Initialize Movement detect Threshold |
asong | 2:824ed4ae8d52 | 96 | uint8_t Current_Zone = 1; |
asong | 2:824ed4ae8d52 | 97 | uint8_t Prev_Zone = 1; |
asong | 2:824ed4ae8d52 | 98 | uint8_t Heart_Rate = 100; |
asong | 1:e4b38d6918ba | 99 | uint8_t HR_buff[250]; |
asong | 1:e4b38d6918ba | 100 | uint8_t *HR_return; |
asong | 1:e4b38d6918ba | 101 | uint8_t Age = 50; // Initialize age |
asong | 2:824ed4ae8d52 | 102 | uint8_t Max_Bpm = 220 - Age; // Initialize Max BPM |
nbaker | 0:d1d36a3da39b | 103 | uint8_t Screen_Num = 0; // Initialize to main screen |
asong | 1:e4b38d6918ba | 104 | uint8_t Error_Num = 0; // Error num for debug |
asong | 2:824ed4ae8d52 | 105 | uint8_t HR_Vibration = 2; //Choose Heart Rate Vibration Options |
asong | 2:824ed4ae8d52 | 106 | uint8_t Target_Zone = 2; //Initialize Target Heart Rate Zone to Zone 3 |
asong | 2:824ed4ae8d52 | 107 | uint8_t HR_Zone1[2] = {Max_Bpm * .50, Max_Bpm * .60}; //Heart Rate Zone 1 |
asong | 2:824ed4ae8d52 | 108 | uint8_t HR_Zone2[2] = {HR_Zone1[1] + 1, Max_Bpm * .70}; //Heart Rate Zone 2 |
asong | 2:824ed4ae8d52 | 109 | uint8_t HR_Zone3[2] = {HR_Zone2[1] + 1, Max_Bpm * .80}; //Heart Rate Zone 3 |
asong | 2:824ed4ae8d52 | 110 | uint8_t HR_Zone4[2] = {HR_Zone3[1] + 1, Max_Bpm}; //Heart Rate Zone 4 |
jmr274 | 5:e1431272be79 | 111 | int sample_ftemp; |
jmr274 | 5:e1431272be79 | 112 | int sample_humid; |
jmr274 | 5:e1431272be79 | 113 | int heat_index; |
jmr274 | 5:e1431272be79 | 114 | |
nbaker | 0:d1d36a3da39b | 115 | // ***************** Define pins ***************************** |
nbaker | 0:d1d36a3da39b | 116 | FXAS21002 gyro(PTC11,PTC10); // Gyroscope |
nbaker | 0:d1d36a3da39b | 117 | SSD1351 oled(PTB22,PTB21,PTC13,PTB20,PTE6, PTD15); // SSD1351 OLED Driver (MOSI,SCLK,POWER,CS,RST,DC) |
nbaker | 0:d1d36a3da39b | 118 | FXOS8700 accel(PTC11, PTC10); // Accelorometer |
nbaker | 0:d1d36a3da39b | 119 | FXOS8700 mag(PTC11, PTC10); // Mag (same chip as Accel) |
asong | 1:e4b38d6918ba | 120 | //MAX30101 heart(PTB1, PTB0); //Heart Rate Chip |
jmr274 | 5:e1431272be79 | 121 | HTU21D temphumid(PTB1,PTB0); // HTU21D Sensor |
nbaker | 0:d1d36a3da39b | 122 | |
nbaker | 4:0803151bc5e4 | 123 | // initialize I2C bus for FXOS8700, FXAS-Gyro, MPL-Pressure |
nbaker | 4:0803151bc5e4 | 124 | I2C i2c_bus1(PTC11, PTC10); // (SDA, SCL) |
nbaker | 4:0803151bc5e4 | 125 | |
nbaker | 0:d1d36a3da39b | 126 | DigitalOut RED_Led(LED1); |
nbaker | 0:d1d36a3da39b | 127 | DigitalOut GRN_Led(LED2); |
nbaker | 0:d1d36a3da39b | 128 | DigitalOut BLU_Led(LED3); |
nbaker | 0:d1d36a3da39b | 129 | DigitalOut haptic(PTB9); |
nbaker | 4:0803151bc5e4 | 130 | DigitalOut Led_clk1(PTA12); |
nbaker | 4:0803151bc5e4 | 131 | DigitalOut Led_clk2(PTA13); |
nbaker | 4:0803151bc5e4 | 132 | DigitalOut Led_clk3(PTA14); |
nbaker | 4:0803151bc5e4 | 133 | |
nbaker | 4:0803151bc5e4 | 134 | DigitalOut OLED_PWR(PTC13); // this pin turns on/off 15V to OLED display |
jmr274 | 5:e1431272be79 | 135 | DigitalOut Non_Free_PWR(PTB13); // this pin turns on/off non-freescale sensors (Pres/Temp/Hum/Light) |
jmr274 | 5:e1431272be79 | 136 | DigitalOut powerEN (PTB12); // Power Enable HTU21D Sensor |
nbaker | 4:0803151bc5e4 | 137 | DigitalOut HR_PWR(PTA29); // this pin turns on/off Heart rate sensor |
jmr274 | 5:e1431272be79 | 138 | //DigitalIn Sw1(PTA12); //Switch 'T1' on docking station AND Led_clk1!! |
jmr274 | 5:e1431272be79 | 139 | //DigitalIn Sw2(PTA13); //Switch 'T2' on docking station AND Led_clk2!! |
jmr274 | 5:e1431272be79 | 140 | DigitalIn Sw3(PTA15); //Switch 'T3' on docking station |
nbaker | 4:0803151bc5e4 | 141 | |
nbaker | 0:d1d36a3da39b | 142 | |
asong | 1:e4b38d6918ba | 143 | /* Instantiate the Hexi KW40Z Driver (UART TX, UART RX) */ |
nbaker | 0:d1d36a3da39b | 144 | KW40Z kw40z_device(PTE24, PTE25); |
nbaker | 0:d1d36a3da39b | 145 | |
nbaker | 0:d1d36a3da39b | 146 | /* Define timer for haptic feedback */ |
nbaker | 0:d1d36a3da39b | 147 | RtosTimer hapticTimer(StopHaptic, osTimerOnce); |
nbaker | 0:d1d36a3da39b | 148 | |
nbaker | 4:0803151bc5e4 | 149 | //***************** Interrups ***************** |
nbaker | 4:0803151bc5e4 | 150 | InterruptIn Accel_INT1(PTC1); // Accel sensor's interupt 1 |
nbaker | 4:0803151bc5e4 | 151 | InterruptIn Accel_INT2(PTD13); // Accel sensor's interupt 2 |
nbaker | 4:0803151bc5e4 | 152 | |
nbaker | 0:d1d36a3da39b | 153 | //***************** Tickers and Timers ***************** |
nbaker | 0:d1d36a3da39b | 154 | Ticker Screen_Timer;// use ticker to turn off OLED |
nbaker | 0:d1d36a3da39b | 155 | |
nbaker | 4:0803151bc5e4 | 156 | void timout_timer(){ // turn off display mode |
nbaker | 4:0803151bc5e4 | 157 | // oled.FillScreen(COLOR_BLACK); // Clear screen.. is there a better command for this? |
nbaker | 4:0803151bc5e4 | 158 | OLED_PWR = 0; // Turn off OLED power supply |
nbaker | 4:0803151bc5e4 | 159 | OLED_ON = 0; // set flag to off |
nbaker | 4:0803151bc5e4 | 160 | Screen_Timer.detach(); // detach Ticker |
asong | 1:e4b38d6918ba | 161 | }//end routine |
asong | 1:e4b38d6918ba | 162 | |
nbaker | 0:d1d36a3da39b | 163 | void ButtonUp(void) |
nbaker | 0:d1d36a3da39b | 164 | { |
asong | 1:e4b38d6918ba | 165 | Screen_Timer.attach(&timout_timer,(SCRN_TIME));//Is this sufficient to reset/restart ticker timer for OLED? |
asong | 1:e4b38d6918ba | 166 | if (OLED_ON == 0) { |
asong | 1:e4b38d6918ba | 167 | OLED_ON = 1; // Scree was off, set to On |
asong | 1:e4b38d6918ba | 168 | update_display(); |
asong | 1:e4b38d6918ba | 169 | } else { |
asong | 1:e4b38d6918ba | 170 | switch(Screen_Num) { |
asong | 1:e4b38d6918ba | 171 | case 0: {// We're in Main Screen |
asong | 1:e4b38d6918ba | 172 | // do nothing, wrong button |
asong | 1:e4b38d6918ba | 173 | break; |
asong | 1:e4b38d6918ba | 174 | } |
asong | 1:e4b38d6918ba | 175 | case 1: {// Panic Alert option |
asong | 1:e4b38d6918ba | 176 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 177 | Screen_Num = 5; //Change to screen 5 |
nbaker | 0:d1d36a3da39b | 178 | #ifdef Debug // in debug show debug/diagnostic screens |
asong | 1:e4b38d6918ba | 179 | Screen_Num = 26; //Change to screen 20 |
nbaker | 0:d1d36a3da39b | 180 | #endif |
nbaker | 0:d1d36a3da39b | 181 | |
asong | 1:e4b38d6918ba | 182 | update_display(); |
asong | 1:e4b38d6918ba | 183 | break; |
asong | 1:e4b38d6918ba | 184 | } |
asong | 1:e4b38d6918ba | 185 | case 2: {// Fall Alert option |
asong | 1:e4b38d6918ba | 186 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 187 | Screen_Num = 71; //Change to screen 71 |
asong | 1:e4b38d6918ba | 188 | update_display(); |
asong | 1:e4b38d6918ba | 189 | break; |
asong | 1:e4b38d6918ba | 190 | } |
asong | 1:e4b38d6918ba | 191 | case 3: {// Heart Rate Monitoring option |
asong | 1:e4b38d6918ba | 192 | StartHaptic(); |
asong | 1:e4b38d6918ba | 193 | Screen_Num = 2; //Change to screen 2 |
asong | 1:e4b38d6918ba | 194 | update_display(); |
asong | 1:e4b38d6918ba | 195 | break; |
asong | 1:e4b38d6918ba | 196 | } |
asong | 1:e4b38d6918ba | 197 | case 4: {// Alert History option |
asong | 1:e4b38d6918ba | 198 | StartHaptic(); |
asong | 1:e4b38d6918ba | 199 | Screen_Num = 3; //Change to screen 3 |
asong | 1:e4b38d6918ba | 200 | update_display(); |
asong | 1:e4b38d6918ba | 201 | break; |
asong | 1:e4b38d6918ba | 202 | } |
asong | 1:e4b38d6918ba | 203 | case 5: {// About HexiHeart |
asong | 1:e4b38d6918ba | 204 | StartHaptic(); |
asong | 1:e4b38d6918ba | 205 | Screen_Num = 4; //Change to screen 4 |
asong | 1:e4b38d6918ba | 206 | update_display(); |
asong | 1:e4b38d6918ba | 207 | break; |
asong | 1:e4b38d6918ba | 208 | } |
asong | 1:e4b38d6918ba | 209 | case 6: {// Panic Alert |
asong | 1:e4b38d6918ba | 210 | StartHaptic(); |
asong | 1:e4b38d6918ba | 211 | Panic_Alert = !Panic_Alert; |
asong | 1:e4b38d6918ba | 212 | update_display(); |
asong | 1:e4b38d6918ba | 213 | break; |
asong | 1:e4b38d6918ba | 214 | } |
asong | 1:e4b38d6918ba | 215 | case 7: {// Heart Rate Zone |
asong | 1:e4b38d6918ba | 216 | StartHaptic(50); |
asong | 2:824ed4ae8d52 | 217 | Enable_Heart_Rate(); |
asong | 1:e4b38d6918ba | 218 | //heart.enable(); |
asong | 1:e4b38d6918ba | 219 | //HR_Enable = 1; |
asong | 1:e4b38d6918ba | 220 | //while(HR_Enable == 1) |
asong | 1:e4b38d6918ba | 221 | // heart.readRawData(HR_buff, HR_return); |
asong | 1:e4b38d6918ba | 222 | //update_display(); |
asong | 1:e4b38d6918ba | 223 | break; |
asong | 1:e4b38d6918ba | 224 | } |
asong | 1:e4b38d6918ba | 225 | case 8: {// Alert History |
asong | 1:e4b38d6918ba | 226 | StartHaptic(); |
asong | 1:e4b38d6918ba | 227 | //Increment alert index |
asong | 1:e4b38d6918ba | 228 | break; |
asong | 1:e4b38d6918ba | 229 | } |
nbaker | 8:a5c77b45008d | 230 | case 9: {// HexiHeart About info1 |
nbaker | 8:a5c77b45008d | 231 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 232 | Screen_Num = 11; //Change to screen 11 |
nbaker | 8:a5c77b45008d | 233 | update_display(); |
nbaker | 8:a5c77b45008d | 234 | break; |
nbaker | 8:a5c77b45008d | 235 | } |
nbaker | 8:a5c77b45008d | 236 | case 10: {// HexiHeart About info2 |
nbaker | 8:a5c77b45008d | 237 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 238 | Screen_Num = 9; //Change to screen 9 |
nbaker | 8:a5c77b45008d | 239 | update_display(); |
nbaker | 8:a5c77b45008d | 240 | break; |
nbaker | 8:a5c77b45008d | 241 | } |
nbaker | 8:a5c77b45008d | 242 | case 11: {// HexiHeart About info3 |
nbaker | 8:a5c77b45008d | 243 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 244 | Screen_Num = 10; //Change to screen 9 |
nbaker | 8:a5c77b45008d | 245 | update_display(); |
nbaker | 8:a5c77b45008d | 246 | break; |
nbaker | 8:a5c77b45008d | 247 | } |
asong | 1:e4b38d6918ba | 248 | case 20: {// Diagnostic/Debug Screens |
asong | 1:e4b38d6918ba | 249 | StartHaptic(); |
asong | 1:e4b38d6918ba | 250 | Screen_Num = 5; //Change to screen 5 |
asong | 1:e4b38d6918ba | 251 | update_display(); |
asong | 1:e4b38d6918ba | 252 | break; |
asong | 1:e4b38d6918ba | 253 | } |
asong | 1:e4b38d6918ba | 254 | case 21: {// Fall Diagnostic |
asong | 1:e4b38d6918ba | 255 | StartHaptic(); |
asong | 1:e4b38d6918ba | 256 | Screen_Num = 25; //Change to screen 25 |
asong | 1:e4b38d6918ba | 257 | update_display(); |
asong | 1:e4b38d6918ba | 258 | break; |
asong | 1:e4b38d6918ba | 259 | } |
asong | 1:e4b38d6918ba | 260 | case 22: {// Fall Debug |
asong | 1:e4b38d6918ba | 261 | StartHaptic(); |
asong | 1:e4b38d6918ba | 262 | Screen_Num = 21; //Change to screen 21 |
asong | 1:e4b38d6918ba | 263 | update_display(); |
asong | 1:e4b38d6918ba | 264 | break; |
asong | 1:e4b38d6918ba | 265 | } |
asong | 1:e4b38d6918ba | 266 | case 23: {// Heart Rate Diagnostic |
asong | 1:e4b38d6918ba | 267 | StartHaptic(); |
asong | 1:e4b38d6918ba | 268 | Screen_Num = 22; //Change to screen 22 |
asong | 1:e4b38d6918ba | 269 | update_display(); |
asong | 1:e4b38d6918ba | 270 | break; |
asong | 1:e4b38d6918ba | 271 | } |
asong | 1:e4b38d6918ba | 272 | case 24: {// Heart Rate Debug |
asong | 1:e4b38d6918ba | 273 | StartHaptic(); |
asong | 1:e4b38d6918ba | 274 | Screen_Num = 23; //Change to screen 23 |
asong | 1:e4b38d6918ba | 275 | update_display(); |
asong | 1:e4b38d6918ba | 276 | break; |
asong | 1:e4b38d6918ba | 277 | } |
asong | 1:e4b38d6918ba | 278 | case 25: {// Heat Index Diagnostic |
asong | 1:e4b38d6918ba | 279 | StartHaptic(); |
asong | 1:e4b38d6918ba | 280 | Screen_Num = 24; //Change to screen 24 |
asong | 1:e4b38d6918ba | 281 | update_display(); |
asong | 1:e4b38d6918ba | 282 | break; |
asong | 1:e4b38d6918ba | 283 | } |
asong | 1:e4b38d6918ba | 284 | case 26: {//Heart Rate Config Option |
asong | 1:e4b38d6918ba | 285 | StartHaptic(); |
asong | 1:e4b38d6918ba | 286 | Screen_Num = 20; |
asong | 1:e4b38d6918ba | 287 | update_display(); |
asong | 1:e4b38d6918ba | 288 | break; |
asong | 1:e4b38d6918ba | 289 | } |
asong | 1:e4b38d6918ba | 290 | case 27: {//Incrementing Age |
asong | 2:824ed4ae8d52 | 291 | Increment_Age(); |
asong | 2:824ed4ae8d52 | 292 | Set_Zone_Boundaries(); |
asong | 1:e4b38d6918ba | 293 | update_display(); |
asong | 1:e4b38d6918ba | 294 | break; |
asong | 1:e4b38d6918ba | 295 | } |
asong | 1:e4b38d6918ba | 296 | case 28: {//Changing Heart Rate Vibration Preferences |
asong | 2:824ed4ae8d52 | 297 | Increment_HR_Vibr_Pref(); |
asong | 1:e4b38d6918ba | 298 | update_display(); |
asong | 1:e4b38d6918ba | 299 | break; |
asong | 1:e4b38d6918ba | 300 | } |
asong | 1:e4b38d6918ba | 301 | case 30: {//Change Target Heart Rate Zone Preference |
asong | 2:824ed4ae8d52 | 302 | Increment_Target_Zone(); |
asong | 2:824ed4ae8d52 | 303 | update_display(); |
asong | 2:824ed4ae8d52 | 304 | break; |
asong | 2:824ed4ae8d52 | 305 | } |
asong | 2:824ed4ae8d52 | 306 | case 31: { //Manually Increment Heart Rate by 1 |
asong | 2:824ed4ae8d52 | 307 | Increment_Heart_Rate(); |
asong | 2:824ed4ae8d52 | 308 | Determine_Current_Zone(); |
asong | 1:e4b38d6918ba | 309 | update_display(); |
asong | 1:e4b38d6918ba | 310 | break; |
asong | 1:e4b38d6918ba | 311 | } |
nbaker | 8:a5c77b45008d | 312 | |
nbaker | 8:a5c77b45008d | 313 | case 41: {//Fall mode 0,1,2,3 |
nbaker | 8:a5c77b45008d | 314 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 315 | Fall_Alert_Mode++; |
nbaker | 8:a5c77b45008d | 316 | if(Fall_Alert_Mode > 3){ |
nbaker | 8:a5c77b45008d | 317 | Fall_Alert_Mode = 0; |
nbaker | 8:a5c77b45008d | 318 | }//endif |
nbaker | 8:a5c77b45008d | 319 | update_display(); |
nbaker | 8:a5c77b45008d | 320 | __disable_irq(); // Disable all Interrupts |
nbaker | 8:a5c77b45008d | 321 | fall_config(10); // reset sensor |
nbaker | 8:a5c77b45008d | 322 | wait(0.1); |
nbaker | 8:a5c77b45008d | 323 | fall_config(Fall_Alert_Mode); |
nbaker | 8:a5c77b45008d | 324 | wait(0.1); |
nbaker | 8:a5c77b45008d | 325 | __enable_irq(); // Enable all Interrupts |
nbaker | 8:a5c77b45008d | 326 | wait(0.3); |
nbaker | 8:a5c77b45008d | 327 | update_display(); |
nbaker | 8:a5c77b45008d | 328 | break; |
nbaker | 8:a5c77b45008d | 329 | } |
nbaker | 8:a5c77b45008d | 330 | case 42: {// F-Th adj |
nbaker | 8:a5c77b45008d | 331 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 332 | Fall_Thresh = Fall_Thresh + 0.05; |
nbaker | 8:a5c77b45008d | 333 | if(Fall_Thresh > 0.9){ |
nbaker | 8:a5c77b45008d | 334 | Fall_Thresh = 0.9; |
nbaker | 8:a5c77b45008d | 335 | }//endif |
nbaker | 8:a5c77b45008d | 336 | update_display(); |
nbaker | 8:a5c77b45008d | 337 | break; |
nbaker | 8:a5c77b45008d | 338 | } |
nbaker | 8:a5c77b45008d | 339 | case 43: {// I-Th adj |
nbaker | 8:a5c77b45008d | 340 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 341 | Impact_Thresh = Impact_Thresh + 0.1; |
nbaker | 8:a5c77b45008d | 342 | if(Impact_Thresh > 3.9){ |
nbaker | 8:a5c77b45008d | 343 | Impact_Thresh = 3.9; |
nbaker | 8:a5c77b45008d | 344 | }//endif |
nbaker | 8:a5c77b45008d | 345 | update_display(); |
nbaker | 8:a5c77b45008d | 346 | break; |
nbaker | 8:a5c77b45008d | 347 | } |
nbaker | 8:a5c77b45008d | 348 | case 44: {// M-Th adj |
nbaker | 8:a5c77b45008d | 349 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 350 | Movement_Thresh = Movement_Thresh + 5.0; |
nbaker | 8:a5c77b45008d | 351 | if(Movement_Thresh > 300.0){ |
nbaker | 8:a5c77b45008d | 352 | Movement_Thresh = 300.0; |
nbaker | 8:a5c77b45008d | 353 | }//endif |
nbaker | 8:a5c77b45008d | 354 | update_display(); |
nbaker | 8:a5c77b45008d | 355 | break; |
nbaker | 8:a5c77b45008d | 356 | } |
nbaker | 8:a5c77b45008d | 357 | |
nbaker | 8:a5c77b45008d | 358 | case 71: {// BLE |
nbaker | 8:a5c77b45008d | 359 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 360 | Screen_Num = 1; //Change to screen 1 |
nbaker | 8:a5c77b45008d | 361 | update_display(); |
nbaker | 8:a5c77b45008d | 362 | break; |
nbaker | 8:a5c77b45008d | 363 | } |
nbaker | 8:a5c77b45008d | 364 | case 72: {// BlueTooth on/off |
nbaker | 8:a5c77b45008d | 365 | // do nothing, wrong button or change to another screen number if you're making more BLE type screens |
nbaker | 8:a5c77b45008d | 366 | break; |
nbaker | 8:a5c77b45008d | 367 | } |
asong | 1:e4b38d6918ba | 368 | default: { |
asong | 1:e4b38d6918ba | 369 | break; |
asong | 1:e4b38d6918ba | 370 | } |
asong | 1:e4b38d6918ba | 371 | } |
nbaker | 0:d1d36a3da39b | 372 | } |
asong | 1:e4b38d6918ba | 373 | |
nbaker | 0:d1d36a3da39b | 374 | } |
nbaker | 0:d1d36a3da39b | 375 | |
nbaker | 0:d1d36a3da39b | 376 | void ButtonDown(void) |
nbaker | 0:d1d36a3da39b | 377 | { |
asong | 1:e4b38d6918ba | 378 | Screen_Timer.attach(&timout_timer,(SCRN_TIME));//Is this sufficient to reset/restart ticker timer for OLED? |
asong | 1:e4b38d6918ba | 379 | if (OLED_ON == 0) { |
asong | 1:e4b38d6918ba | 380 | OLED_ON = 1; // Screen was off, set to On |
asong | 1:e4b38d6918ba | 381 | update_display(); |
asong | 1:e4b38d6918ba | 382 | } else { |
nbaker | 0:d1d36a3da39b | 383 | |
asong | 1:e4b38d6918ba | 384 | switch(Screen_Num) { |
asong | 1:e4b38d6918ba | 385 | case 0: {// We're in Main Screen |
asong | 1:e4b38d6918ba | 386 | // do nothing, wrong button |
asong | 1:e4b38d6918ba | 387 | break; |
asong | 1:e4b38d6918ba | 388 | } |
asong | 1:e4b38d6918ba | 389 | case 1: {// Panic Alert option |
asong | 1:e4b38d6918ba | 390 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 391 | Screen_Num = 71; //Change to screen 71 |
asong | 1:e4b38d6918ba | 392 | update_display(); |
asong | 1:e4b38d6918ba | 393 | break; |
asong | 1:e4b38d6918ba | 394 | } |
asong | 1:e4b38d6918ba | 395 | case 2: {// Fall Alert option |
asong | 1:e4b38d6918ba | 396 | StartHaptic(); |
asong | 1:e4b38d6918ba | 397 | Screen_Num = 3; //Change to screen 3 |
asong | 1:e4b38d6918ba | 398 | update_display(); |
asong | 1:e4b38d6918ba | 399 | break; |
asong | 1:e4b38d6918ba | 400 | } |
asong | 1:e4b38d6918ba | 401 | case 3: {// Heart Rate Monitoring option |
asong | 1:e4b38d6918ba | 402 | StartHaptic(); |
asong | 1:e4b38d6918ba | 403 | Screen_Num = 4; //Change to screen 4 |
asong | 1:e4b38d6918ba | 404 | update_display(); |
asong | 1:e4b38d6918ba | 405 | break; |
asong | 1:e4b38d6918ba | 406 | } |
asong | 1:e4b38d6918ba | 407 | case 4: {// Alert History option |
asong | 1:e4b38d6918ba | 408 | StartHaptic(); |
asong | 1:e4b38d6918ba | 409 | Screen_Num = 5; //Change to screen 5 |
asong | 1:e4b38d6918ba | 410 | update_display(); |
asong | 1:e4b38d6918ba | 411 | break; |
asong | 1:e4b38d6918ba | 412 | } |
asong | 1:e4b38d6918ba | 413 | case 5: {// About HexiHeart option |
asong | 1:e4b38d6918ba | 414 | StartHaptic(); |
asong | 1:e4b38d6918ba | 415 | Screen_Num = 26; //Change to screen 1 |
nbaker | 0:d1d36a3da39b | 416 | #ifdef Debug // in debug show debug/diagnostic screens |
asong | 1:e4b38d6918ba | 417 | Screen_Num = 20; //Change to screen 20 |
nbaker | 0:d1d36a3da39b | 418 | #endif |
asong | 1:e4b38d6918ba | 419 | update_display(); |
asong | 1:e4b38d6918ba | 420 | break; |
asong | 1:e4b38d6918ba | 421 | } |
asong | 1:e4b38d6918ba | 422 | case 6: {// Panic Alert |
asong | 1:e4b38d6918ba | 423 | // do nothing, wrong button |
asong | 1:e4b38d6918ba | 424 | break; |
asong | 1:e4b38d6918ba | 425 | } |
asong | 1:e4b38d6918ba | 426 | case 7: {// Heart Rate Zone |
asong | 1:e4b38d6918ba | 427 | StartHaptic(100); |
asong | 2:824ed4ae8d52 | 428 | Disable_Heart_Rate(); |
asong | 1:e4b38d6918ba | 429 | break; |
asong | 1:e4b38d6918ba | 430 | } |
asong | 1:e4b38d6918ba | 431 | case 8: {// Alert History |
asong | 1:e4b38d6918ba | 432 | StartHaptic(); |
asong | 1:e4b38d6918ba | 433 | //decriment alert index |
asong | 1:e4b38d6918ba | 434 | break; |
asong | 1:e4b38d6918ba | 435 | } |
nbaker | 8:a5c77b45008d | 436 | case 9: {// HexiHeart About info1 |
nbaker | 8:a5c77b45008d | 437 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 438 | Screen_Num = 10; //Change to screen 10 |
nbaker | 8:a5c77b45008d | 439 | update_display(); |
nbaker | 8:a5c77b45008d | 440 | break; |
nbaker | 8:a5c77b45008d | 441 | } |
nbaker | 8:a5c77b45008d | 442 | case 10: {// HexiHeart About info2 |
nbaker | 8:a5c77b45008d | 443 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 444 | Screen_Num = 11; //Change to screen 11 |
nbaker | 8:a5c77b45008d | 445 | update_display(); |
nbaker | 8:a5c77b45008d | 446 | break; |
nbaker | 8:a5c77b45008d | 447 | } |
nbaker | 8:a5c77b45008d | 448 | case 11: {// HexiHeart About info3 |
nbaker | 8:a5c77b45008d | 449 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 450 | Screen_Num = 9; //Change to screen 9 |
nbaker | 8:a5c77b45008d | 451 | update_display(); |
nbaker | 8:a5c77b45008d | 452 | break; |
nbaker | 8:a5c77b45008d | 453 | } |
asong | 1:e4b38d6918ba | 454 | case 20: {// Diagnostic/Debug Screens |
asong | 1:e4b38d6918ba | 455 | StartHaptic(); |
asong | 1:e4b38d6918ba | 456 | Screen_Num = 26; //Change to screen 1 |
asong | 1:e4b38d6918ba | 457 | update_display(); |
asong | 1:e4b38d6918ba | 458 | break; |
asong | 1:e4b38d6918ba | 459 | } |
asong | 1:e4b38d6918ba | 460 | case 21: {// Fall Diagnostic |
asong | 1:e4b38d6918ba | 461 | StartHaptic(); |
asong | 1:e4b38d6918ba | 462 | Screen_Num = 22; //Change to screen 22 |
asong | 1:e4b38d6918ba | 463 | update_display(); |
asong | 1:e4b38d6918ba | 464 | break; |
asong | 1:e4b38d6918ba | 465 | } |
asong | 1:e4b38d6918ba | 466 | case 22: {// Fall Debug |
asong | 1:e4b38d6918ba | 467 | StartHaptic(); |
asong | 1:e4b38d6918ba | 468 | Screen_Num = 23; //Change to screen 23 |
asong | 1:e4b38d6918ba | 469 | update_display(); |
asong | 1:e4b38d6918ba | 470 | break; |
asong | 1:e4b38d6918ba | 471 | } |
asong | 1:e4b38d6918ba | 472 | case 23: {// Heart Rate Diagnostic |
asong | 1:e4b38d6918ba | 473 | StartHaptic(); |
asong | 1:e4b38d6918ba | 474 | Screen_Num = 24; //Change to screen 24 |
asong | 1:e4b38d6918ba | 475 | update_display(); |
asong | 1:e4b38d6918ba | 476 | break; |
asong | 1:e4b38d6918ba | 477 | } |
asong | 1:e4b38d6918ba | 478 | case 24: {// Heart Rate Debug |
asong | 1:e4b38d6918ba | 479 | StartHaptic(); |
asong | 1:e4b38d6918ba | 480 | Screen_Num = 25; //Change to screen 25 |
asong | 1:e4b38d6918ba | 481 | update_display(); |
asong | 1:e4b38d6918ba | 482 | break; |
asong | 1:e4b38d6918ba | 483 | } |
asong | 1:e4b38d6918ba | 484 | case 25: {// Heat Index Diagnostic |
asong | 1:e4b38d6918ba | 485 | StartHaptic(); |
asong | 1:e4b38d6918ba | 486 | Screen_Num = 21; //Change to screen 21 |
asong | 1:e4b38d6918ba | 487 | update_display(); |
asong | 1:e4b38d6918ba | 488 | break; |
asong | 1:e4b38d6918ba | 489 | } |
asong | 1:e4b38d6918ba | 490 | case 26: {//Heart Rate Configs |
asong | 1:e4b38d6918ba | 491 | StartHaptic(); |
asong | 1:e4b38d6918ba | 492 | Screen_Num = 1; |
asong | 1:e4b38d6918ba | 493 | update_display(); |
asong | 1:e4b38d6918ba | 494 | break; |
asong | 1:e4b38d6918ba | 495 | } |
asong | 1:e4b38d6918ba | 496 | case 27: { //Decrement Age |
asong | 2:824ed4ae8d52 | 497 | Decrement_Age(); |
asong | 2:824ed4ae8d52 | 498 | Set_Zone_Boundaries(); |
asong | 1:e4b38d6918ba | 499 | update_display(); |
asong | 1:e4b38d6918ba | 500 | break; |
asong | 1:e4b38d6918ba | 501 | |
asong | 1:e4b38d6918ba | 502 | } |
asong | 1:e4b38d6918ba | 503 | case 28: { //Changing Heart Rate Vibration Preference |
asong | 2:824ed4ae8d52 | 504 | /* |
asong | 2:824ed4ae8d52 | 505 | StartHaptic(); |
asong | 2:824ed4ae8d52 | 506 | if(HR_Vibration == 1) { |
asong | 2:824ed4ae8d52 | 507 | HR_Vibration = 3; |
asong | 2:824ed4ae8d52 | 508 | } else { |
asong | 2:824ed4ae8d52 | 509 | HR_Vibration -= 1; |
asong | 2:824ed4ae8d52 | 510 | } |
asong | 2:824ed4ae8d52 | 511 | */ |
asong | 2:824ed4ae8d52 | 512 | Decrement_HR_Vibr_Pref(); |
asong | 1:e4b38d6918ba | 513 | update_display(); |
asong | 1:e4b38d6918ba | 514 | break; |
asong | 1:e4b38d6918ba | 515 | } |
asong | 1:e4b38d6918ba | 516 | case 30: {//Change Target Heart Rate Zone Preference |
asong | 2:824ed4ae8d52 | 517 | Decrement_Target_Zone(); |
asong | 2:824ed4ae8d52 | 518 | update_display(); |
asong | 2:824ed4ae8d52 | 519 | break; |
asong | 2:824ed4ae8d52 | 520 | } |
asong | 2:824ed4ae8d52 | 521 | case 31: { //Manually decrement heart rate by 1 |
asong | 2:824ed4ae8d52 | 522 | Decrement_Heart_Rate(); |
asong | 2:824ed4ae8d52 | 523 | Determine_Current_Zone(); |
asong | 1:e4b38d6918ba | 524 | update_display(); |
asong | 1:e4b38d6918ba | 525 | break; |
asong | 1:e4b38d6918ba | 526 | } |
nbaker | 8:a5c77b45008d | 527 | case 41: {//Fall mode 0,1,2,3 |
nbaker | 8:a5c77b45008d | 528 | Fall_Alert_Mode--; |
nbaker | 8:a5c77b45008d | 529 | if(Fall_Alert_Mode > 3){// should be 0xff if decr from zero |
nbaker | 8:a5c77b45008d | 530 | Fall_Alert_Mode = 3; |
nbaker | 8:a5c77b45008d | 531 | } //endif |
nbaker | 8:a5c77b45008d | 532 | update_display(); |
nbaker | 8:a5c77b45008d | 533 | __disable_irq(); // Disable all Interrupts |
nbaker | 8:a5c77b45008d | 534 | fall_config(10); // reset sensor |
nbaker | 8:a5c77b45008d | 535 | wait(0.1); |
nbaker | 8:a5c77b45008d | 536 | fall_config(Fall_Alert_Mode); |
nbaker | 8:a5c77b45008d | 537 | wait(0.1); |
nbaker | 8:a5c77b45008d | 538 | __enable_irq(); // Enable all Interrupts |
nbaker | 8:a5c77b45008d | 539 | wait(0.2); |
nbaker | 8:a5c77b45008d | 540 | update_display(); |
nbaker | 8:a5c77b45008d | 541 | break; |
nbaker | 8:a5c77b45008d | 542 | } |
nbaker | 8:a5c77b45008d | 543 | case 42: {// F-Th adj |
nbaker | 8:a5c77b45008d | 544 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 545 | Fall_Thresh = Fall_Thresh - 0.05; |
nbaker | 8:a5c77b45008d | 546 | if(Fall_Thresh < 0.1){ |
nbaker | 8:a5c77b45008d | 547 | Fall_Thresh = 0.1; |
nbaker | 8:a5c77b45008d | 548 | }//endif |
nbaker | 8:a5c77b45008d | 549 | update_display(); |
nbaker | 8:a5c77b45008d | 550 | break; |
nbaker | 8:a5c77b45008d | 551 | } |
nbaker | 8:a5c77b45008d | 552 | case 43: {// I-Th adj |
nbaker | 8:a5c77b45008d | 553 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 554 | Impact_Thresh = Impact_Thresh - 0.1; |
nbaker | 8:a5c77b45008d | 555 | if(Impact_Thresh < 0.9){ |
nbaker | 8:a5c77b45008d | 556 | Impact_Thresh = 0.9; |
nbaker | 8:a5c77b45008d | 557 | }//endif |
nbaker | 8:a5c77b45008d | 558 | update_display(); |
nbaker | 8:a5c77b45008d | 559 | break; |
nbaker | 8:a5c77b45008d | 560 | } |
nbaker | 8:a5c77b45008d | 561 | case 44: {// M-Th adj |
nbaker | 8:a5c77b45008d | 562 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 563 | Movement_Thresh = Movement_Thresh - 5.0; |
nbaker | 8:a5c77b45008d | 564 | if(Movement_Thresh < 5.0){ |
nbaker | 8:a5c77b45008d | 565 | Movement_Thresh = 5.0; |
nbaker | 8:a5c77b45008d | 566 | }//endif |
nbaker | 8:a5c77b45008d | 567 | update_display(); |
nbaker | 8:a5c77b45008d | 568 | break; |
nbaker | 8:a5c77b45008d | 569 | } |
nbaker | 8:a5c77b45008d | 570 | |
nbaker | 8:a5c77b45008d | 571 | case 71: {// BLE |
nbaker | 8:a5c77b45008d | 572 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 573 | Screen_Num = 2; //Change to screen 2 |
nbaker | 8:a5c77b45008d | 574 | update_display(); |
nbaker | 8:a5c77b45008d | 575 | break; |
nbaker | 8:a5c77b45008d | 576 | } |
nbaker | 8:a5c77b45008d | 577 | case 72: {// BlueTooth on/off |
nbaker | 8:a5c77b45008d | 578 | // do nothing, wrong button or change to another screen number if you're making more BLE type screens |
nbaker | 8:a5c77b45008d | 579 | break; |
nbaker | 8:a5c77b45008d | 580 | } |
nbaker | 8:a5c77b45008d | 581 | |
asong | 1:e4b38d6918ba | 582 | default: { |
asong | 1:e4b38d6918ba | 583 | break; |
asong | 1:e4b38d6918ba | 584 | } |
asong | 1:e4b38d6918ba | 585 | } |
nbaker | 0:d1d36a3da39b | 586 | } |
nbaker | 0:d1d36a3da39b | 587 | } |
nbaker | 0:d1d36a3da39b | 588 | |
nbaker | 0:d1d36a3da39b | 589 | void ButtonRight(void) |
nbaker | 0:d1d36a3da39b | 590 | { |
asong | 1:e4b38d6918ba | 591 | Screen_Timer.attach(&timout_timer,(SCRN_TIME));//Is this sufficient to reset/restart ticker timer for OLED? |
asong | 1:e4b38d6918ba | 592 | if (OLED_ON == 0) { |
asong | 1:e4b38d6918ba | 593 | OLED_ON = 1; // Screen was off, set to On |
asong | 1:e4b38d6918ba | 594 | update_display(); |
asong | 1:e4b38d6918ba | 595 | } else { |
asong | 1:e4b38d6918ba | 596 | switch(Screen_Num) { |
asong | 1:e4b38d6918ba | 597 | case 0: {// We're in Main Screen |
asong | 1:e4b38d6918ba | 598 | StartHaptic(); |
asong | 1:e4b38d6918ba | 599 | Screen_Num = 1; //Change to screen 1 |
asong | 1:e4b38d6918ba | 600 | update_display(); |
asong | 1:e4b38d6918ba | 601 | break; |
asong | 1:e4b38d6918ba | 602 | } |
asong | 1:e4b38d6918ba | 603 | case 1: {// Panic Alert option |
asong | 1:e4b38d6918ba | 604 | StartHaptic(); |
asong | 1:e4b38d6918ba | 605 | Screen_Num = 6; //Change to screen 6 |
asong | 1:e4b38d6918ba | 606 | update_display(); |
asong | 1:e4b38d6918ba | 607 | break; |
asong | 1:e4b38d6918ba | 608 | } |
asong | 1:e4b38d6918ba | 609 | case 2: {// Fall Alert option |
asong | 1:e4b38d6918ba | 610 | StartHaptic(); |
nbaker | 4:0803151bc5e4 | 611 | if(Fall_Alert == 1){ |
nbaker | 4:0803151bc5e4 | 612 | Accel_INT1.fall(&fall_detect_off); // turn off Accel sensor's int#1 calls interupt routine |
nbaker | 4:0803151bc5e4 | 613 | Fall_Alert = 0; |
nbaker | 4:0803151bc5e4 | 614 | } |
nbaker | 4:0803151bc5e4 | 615 | else{ |
nbaker | 4:0803151bc5e4 | 616 | Accel_INT1.fall(&fall_detect); // Accel sensor's int#1 calls interupt routine |
nbaker | 4:0803151bc5e4 | 617 | Fall_Alert = 1; |
nbaker | 4:0803151bc5e4 | 618 | } |
nbaker | 4:0803151bc5e4 | 619 | update_display(); |
asong | 1:e4b38d6918ba | 620 | break; |
asong | 1:e4b38d6918ba | 621 | } |
asong | 1:e4b38d6918ba | 622 | case 3: {// Heart Rate Monitoring option |
asong | 1:e4b38d6918ba | 623 | StartHaptic(); |
asong | 1:e4b38d6918ba | 624 | Screen_Num = 7; //Change to screen 7 |
asong | 1:e4b38d6918ba | 625 | update_display(); |
asong | 1:e4b38d6918ba | 626 | break; |
asong | 1:e4b38d6918ba | 627 | } |
asong | 1:e4b38d6918ba | 628 | case 4: {// Alert History option |
asong | 1:e4b38d6918ba | 629 | StartHaptic(); |
asong | 1:e4b38d6918ba | 630 | Screen_Num = 8; //Change to screen 8 |
asong | 1:e4b38d6918ba | 631 | update_display(); |
asong | 1:e4b38d6918ba | 632 | break; |
asong | 1:e4b38d6918ba | 633 | } |
asong | 1:e4b38d6918ba | 634 | case 5: {// About HexiHeart option |
asong | 1:e4b38d6918ba | 635 | StartHaptic(); |
asong | 1:e4b38d6918ba | 636 | Screen_Num = 9; //Change to screen 9 |
asong | 1:e4b38d6918ba | 637 | update_display(); |
asong | 1:e4b38d6918ba | 638 | break; |
asong | 1:e4b38d6918ba | 639 | } |
nbaker | 0:d1d36a3da39b | 640 | |
asong | 1:e4b38d6918ba | 641 | case 6: {// Panic Alert |
asong | 1:e4b38d6918ba | 642 | // do nothing, wrong button |
asong | 1:e4b38d6918ba | 643 | break; |
asong | 1:e4b38d6918ba | 644 | } |
asong | 1:e4b38d6918ba | 645 | case 7: {// Heart Rate Zone |
asong | 1:e4b38d6918ba | 646 | StartHaptic(); |
asong | 2:824ed4ae8d52 | 647 | Screen_Num = 31; |
asong | 2:824ed4ae8d52 | 648 | update_display(); |
asong | 1:e4b38d6918ba | 649 | break; |
asong | 1:e4b38d6918ba | 650 | } |
asong | 1:e4b38d6918ba | 651 | case 20: {// Diagnostic/Debug Screens |
asong | 1:e4b38d6918ba | 652 | StartHaptic(); |
asong | 1:e4b38d6918ba | 653 | Screen_Num = 21; //Change to screen 21 |
asong | 1:e4b38d6918ba | 654 | update_display(); |
asong | 1:e4b38d6918ba | 655 | break; |
asong | 1:e4b38d6918ba | 656 | } |
nbaker | 8:a5c77b45008d | 657 | case 22: {// Fall Debug |
nbaker | 8:a5c77b45008d | 658 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 659 | Screen_Num = 41; //Change to screen 41 |
nbaker | 8:a5c77b45008d | 660 | update_display(); |
nbaker | 8:a5c77b45008d | 661 | break; |
nbaker | 8:a5c77b45008d | 662 | } |
asong | 1:e4b38d6918ba | 663 | case 26: {//Change to Heart Rate Config Screen |
asong | 1:e4b38d6918ba | 664 | StartHaptic(); |
asong | 1:e4b38d6918ba | 665 | Screen_Num = 27; |
asong | 1:e4b38d6918ba | 666 | update_display(); |
asong | 1:e4b38d6918ba | 667 | break; |
asong | 1:e4b38d6918ba | 668 | } |
asong | 1:e4b38d6918ba | 669 | case 27: {//Change to Heart Rate Vibration Preferences |
asong | 1:e4b38d6918ba | 670 | StartHaptic(); |
asong | 1:e4b38d6918ba | 671 | Screen_Num = 28; |
asong | 1:e4b38d6918ba | 672 | update_display(); |
asong | 1:e4b38d6918ba | 673 | break; |
asong | 1:e4b38d6918ba | 674 | } |
asong | 1:e4b38d6918ba | 675 | case 28: {//Change to Heart Rate Zone Boundary Info |
asong | 1:e4b38d6918ba | 676 | StartHaptic(); |
asong | 1:e4b38d6918ba | 677 | Screen_Num = 29; |
asong | 1:e4b38d6918ba | 678 | update_display(); |
asong | 1:e4b38d6918ba | 679 | break; |
asong | 1:e4b38d6918ba | 680 | } |
asong | 2:824ed4ae8d52 | 681 | case 29: {//Change Target Heart Rate Zone Preference |
asong | 1:e4b38d6918ba | 682 | StartHaptic(); |
asong | 1:e4b38d6918ba | 683 | Screen_Num = 30; |
asong | 1:e4b38d6918ba | 684 | update_display(); |
asong | 1:e4b38d6918ba | 685 | break; |
asong | 1:e4b38d6918ba | 686 | } |
asong | 1:e4b38d6918ba | 687 | case 30: {//Change to Heart Rate Config Screen |
asong | 1:e4b38d6918ba | 688 | StartHaptic(); |
asong | 1:e4b38d6918ba | 689 | Screen_Num = 27; |
asong | 1:e4b38d6918ba | 690 | update_display(); |
asong | 1:e4b38d6918ba | 691 | break; |
asong | 1:e4b38d6918ba | 692 | } |
asong | 2:824ed4ae8d52 | 693 | case 31: { |
asong | 2:824ed4ae8d52 | 694 | StartHaptic(); |
asong | 2:824ed4ae8d52 | 695 | Screen_Num = 32; |
asong | 2:824ed4ae8d52 | 696 | update_display(); |
asong | 2:824ed4ae8d52 | 697 | break; |
asong | 2:824ed4ae8d52 | 698 | } |
asong | 2:824ed4ae8d52 | 699 | case 32: { |
asong | 2:824ed4ae8d52 | 700 | StartHaptic(); |
asong | 2:824ed4ae8d52 | 701 | Screen_Num = 7; |
asong | 2:824ed4ae8d52 | 702 | update_display(); |
asong | 2:824ed4ae8d52 | 703 | break; |
asong | 2:824ed4ae8d52 | 704 | } |
nbaker | 8:a5c77b45008d | 705 | case 41: {// Fall-Mode adj |
nbaker | 8:a5c77b45008d | 706 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 707 | Screen_Num = 42; //Change to screen 42 |
nbaker | 8:a5c77b45008d | 708 | update_display(); |
nbaker | 8:a5c77b45008d | 709 | break; |
nbaker | 8:a5c77b45008d | 710 | } |
nbaker | 8:a5c77b45008d | 711 | case 42: {// F-Th adj |
nbaker | 8:a5c77b45008d | 712 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 713 | Screen_Num = 43; //Change to screen 43 |
nbaker | 8:a5c77b45008d | 714 | update_display(); |
nbaker | 8:a5c77b45008d | 715 | break; |
nbaker | 8:a5c77b45008d | 716 | } |
nbaker | 8:a5c77b45008d | 717 | case 43: {// I-Th adj |
nbaker | 8:a5c77b45008d | 718 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 719 | Screen_Num = 44; //Change to screen 44 |
nbaker | 8:a5c77b45008d | 720 | update_display(); |
nbaker | 8:a5c77b45008d | 721 | break; |
nbaker | 8:a5c77b45008d | 722 | } |
nbaker | 8:a5c77b45008d | 723 | case 44: {// M-Th adj |
nbaker | 8:a5c77b45008d | 724 | // do nothing for now |
nbaker | 8:a5c77b45008d | 725 | break; |
nbaker | 8:a5c77b45008d | 726 | } |
nbaker | 8:a5c77b45008d | 727 | case 71: {// BLE |
nbaker | 8:a5c77b45008d | 728 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 729 | Screen_Num = 72; //Change to screen 72 |
nbaker | 8:a5c77b45008d | 730 | update_display(); |
nbaker | 8:a5c77b45008d | 731 | break; |
nbaker | 8:a5c77b45008d | 732 | } |
nbaker | 8:a5c77b45008d | 733 | case 72: {// BlueTooth on/off |
nbaker | 8:a5c77b45008d | 734 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 735 | BLE_On = !BLE_On; |
nbaker | 8:a5c77b45008d | 736 | update_display(); |
nbaker | 8:a5c77b45008d | 737 | break; |
nbaker | 8:a5c77b45008d | 738 | } |
nbaker | 8:a5c77b45008d | 739 | |
asong | 1:e4b38d6918ba | 740 | default: { |
asong | 1:e4b38d6918ba | 741 | break; |
asong | 1:e4b38d6918ba | 742 | } |
asong | 1:e4b38d6918ba | 743 | } |
nbaker | 0:d1d36a3da39b | 744 | } |
nbaker | 0:d1d36a3da39b | 745 | } |
nbaker | 0:d1d36a3da39b | 746 | |
nbaker | 0:d1d36a3da39b | 747 | void ButtonLeft(void) |
nbaker | 0:d1d36a3da39b | 748 | { |
asong | 1:e4b38d6918ba | 749 | Screen_Timer.attach(&timout_timer,(SCRN_TIME));//Is this sufficient to reset/restart ticker timer for OLED? |
asong | 1:e4b38d6918ba | 750 | if (OLED_ON == 0) { |
asong | 1:e4b38d6918ba | 751 | OLED_ON = 1; // Screen was off, set to On |
asong | 1:e4b38d6918ba | 752 | update_display(); |
asong | 1:e4b38d6918ba | 753 | } else { |
asong | 1:e4b38d6918ba | 754 | switch(Screen_Num) { |
asong | 1:e4b38d6918ba | 755 | case 0: {// We're in Main Screen |
asong | 1:e4b38d6918ba | 756 | // do nothing, wrong button |
asong | 1:e4b38d6918ba | 757 | break; |
asong | 1:e4b38d6918ba | 758 | } |
asong | 1:e4b38d6918ba | 759 | case 1: {// Panic Alert option |
asong | 1:e4b38d6918ba | 760 | StartHaptic(); |
asong | 1:e4b38d6918ba | 761 | Screen_Num = 0; //Change to screen 0 |
asong | 1:e4b38d6918ba | 762 | update_display(); |
asong | 1:e4b38d6918ba | 763 | break; |
asong | 1:e4b38d6918ba | 764 | } |
asong | 1:e4b38d6918ba | 765 | case 2: {// Fall Alert option |
asong | 1:e4b38d6918ba | 766 | StartHaptic(); |
asong | 1:e4b38d6918ba | 767 | Screen_Num = 0; //Change to screen 0 |
asong | 1:e4b38d6918ba | 768 | update_display(); |
asong | 1:e4b38d6918ba | 769 | break; |
asong | 1:e4b38d6918ba | 770 | } |
asong | 1:e4b38d6918ba | 771 | case 3: {// Heart Rate Monitoring option |
asong | 1:e4b38d6918ba | 772 | StartHaptic(); |
asong | 1:e4b38d6918ba | 773 | Screen_Num = 0; //Change to screen 0 |
asong | 1:e4b38d6918ba | 774 | update_display(); |
asong | 1:e4b38d6918ba | 775 | break; |
asong | 1:e4b38d6918ba | 776 | } |
asong | 1:e4b38d6918ba | 777 | case 4: {// Alert History option |
asong | 1:e4b38d6918ba | 778 | StartHaptic(); |
asong | 1:e4b38d6918ba | 779 | Screen_Num = 0; //Change to screen 0 |
asong | 1:e4b38d6918ba | 780 | update_display(); |
asong | 1:e4b38d6918ba | 781 | break; |
asong | 1:e4b38d6918ba | 782 | } |
asong | 1:e4b38d6918ba | 783 | case 5: {// About HexiHeart option |
asong | 1:e4b38d6918ba | 784 | StartHaptic(); |
asong | 1:e4b38d6918ba | 785 | Screen_Num = 0; //Change to screen 0 |
asong | 1:e4b38d6918ba | 786 | update_display(); |
asong | 1:e4b38d6918ba | 787 | break; |
asong | 1:e4b38d6918ba | 788 | } |
asong | 1:e4b38d6918ba | 789 | case 6: {// Panic Alert |
asong | 1:e4b38d6918ba | 790 | StartHaptic(); |
asong | 1:e4b38d6918ba | 791 | Screen_Num = 1; //Change to screen 1 |
asong | 1:e4b38d6918ba | 792 | update_display(); |
asong | 1:e4b38d6918ba | 793 | break; |
asong | 1:e4b38d6918ba | 794 | } |
asong | 1:e4b38d6918ba | 795 | case 7: {// Heart Rate Zone |
asong | 1:e4b38d6918ba | 796 | StartHaptic(); |
asong | 1:e4b38d6918ba | 797 | Screen_Num = 3; //Change to screen 3 |
asong | 1:e4b38d6918ba | 798 | update_display(); |
asong | 1:e4b38d6918ba | 799 | break; |
asong | 1:e4b38d6918ba | 800 | } |
asong | 1:e4b38d6918ba | 801 | case 8: {// Alert History |
asong | 1:e4b38d6918ba | 802 | StartHaptic(); |
asong | 1:e4b38d6918ba | 803 | Screen_Num = 4; //Change to screen 4 |
asong | 1:e4b38d6918ba | 804 | update_display(); |
asong | 1:e4b38d6918ba | 805 | break; |
asong | 1:e4b38d6918ba | 806 | } |
nbaker | 8:a5c77b45008d | 807 | case 9: {// About HexiHeart info1 |
nbaker | 8:a5c77b45008d | 808 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 809 | Screen_Num = 5; //Change to screen 5 |
nbaker | 8:a5c77b45008d | 810 | update_display(); |
nbaker | 8:a5c77b45008d | 811 | break; |
nbaker | 8:a5c77b45008d | 812 | } |
nbaker | 8:a5c77b45008d | 813 | case 10: {// HexiHeart About info2 |
nbaker | 8:a5c77b45008d | 814 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 815 | Screen_Num = 5; //Change to screen 5 |
nbaker | 8:a5c77b45008d | 816 | update_display(); |
nbaker | 8:a5c77b45008d | 817 | break; |
nbaker | 8:a5c77b45008d | 818 | } |
nbaker | 8:a5c77b45008d | 819 | case 11: {// HexiHeart About info3 |
nbaker | 8:a5c77b45008d | 820 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 821 | Screen_Num = 5; //Change to screen 5 |
nbaker | 8:a5c77b45008d | 822 | update_display(); |
nbaker | 8:a5c77b45008d | 823 | break; |
nbaker | 8:a5c77b45008d | 824 | } |
asong | 1:e4b38d6918ba | 825 | case 20: {// Diagnostic/Debug Screens |
asong | 1:e4b38d6918ba | 826 | StartHaptic(); |
asong | 1:e4b38d6918ba | 827 | Screen_Num = 0; //Change to screen 0 |
asong | 1:e4b38d6918ba | 828 | update_display(); |
asong | 1:e4b38d6918ba | 829 | break; |
asong | 1:e4b38d6918ba | 830 | } |
asong | 1:e4b38d6918ba | 831 | case 21: {// Fall Diagnostic |
asong | 1:e4b38d6918ba | 832 | StartHaptic(); |
asong | 1:e4b38d6918ba | 833 | Screen_Num = 20; //Change to screen 20 |
asong | 1:e4b38d6918ba | 834 | update_display(); |
asong | 1:e4b38d6918ba | 835 | break; |
asong | 1:e4b38d6918ba | 836 | } |
asong | 1:e4b38d6918ba | 837 | case 22: {// Fall Debug |
asong | 1:e4b38d6918ba | 838 | StartHaptic(); |
asong | 1:e4b38d6918ba | 839 | Screen_Num = 20; //Change to screen 20 |
asong | 1:e4b38d6918ba | 840 | update_display(); |
asong | 1:e4b38d6918ba | 841 | break; |
asong | 1:e4b38d6918ba | 842 | } |
asong | 1:e4b38d6918ba | 843 | case 23: {// Heart Rate Diagnostic |
asong | 1:e4b38d6918ba | 844 | StartHaptic(); |
asong | 1:e4b38d6918ba | 845 | Screen_Num = 20; //Change to screen 20 |
asong | 1:e4b38d6918ba | 846 | update_display(); |
asong | 1:e4b38d6918ba | 847 | break; |
asong | 1:e4b38d6918ba | 848 | } |
asong | 1:e4b38d6918ba | 849 | case 24: {// Heart Rate Debug |
asong | 1:e4b38d6918ba | 850 | StartHaptic(); |
asong | 1:e4b38d6918ba | 851 | Screen_Num = 20; //Change to screen 20 |
asong | 1:e4b38d6918ba | 852 | update_display(); |
asong | 1:e4b38d6918ba | 853 | break; |
asong | 1:e4b38d6918ba | 854 | } |
asong | 1:e4b38d6918ba | 855 | case 25: {// Heat Index Diagnostic |
asong | 1:e4b38d6918ba | 856 | StartHaptic(); |
asong | 1:e4b38d6918ba | 857 | Screen_Num = 20; //Change to screen 20 |
asong | 1:e4b38d6918ba | 858 | update_display(); |
asong | 1:e4b38d6918ba | 859 | break; |
asong | 1:e4b38d6918ba | 860 | } |
asong | 1:e4b38d6918ba | 861 | case 26: {//Heart Rate Config Option |
asong | 1:e4b38d6918ba | 862 | StartHaptic(); |
asong | 1:e4b38d6918ba | 863 | Screen_Num = 0; |
asong | 1:e4b38d6918ba | 864 | update_display(); |
asong | 1:e4b38d6918ba | 865 | break; |
asong | 1:e4b38d6918ba | 866 | } |
asong | 1:e4b38d6918ba | 867 | case 27: {//Enter Age |
asong | 1:e4b38d6918ba | 868 | StartHaptic(); |
asong | 1:e4b38d6918ba | 869 | Screen_Num = 26; |
asong | 1:e4b38d6918ba | 870 | update_display(); |
asong | 1:e4b38d6918ba | 871 | break; |
asong | 1:e4b38d6918ba | 872 | } |
asong | 1:e4b38d6918ba | 873 | case 28: {//Heart Rate Vibration Preference Screen |
asong | 1:e4b38d6918ba | 874 | StartHaptic(); |
asong | 1:e4b38d6918ba | 875 | Screen_Num = 27; |
asong | 1:e4b38d6918ba | 876 | update_display(); |
asong | 1:e4b38d6918ba | 877 | break; |
asong | 1:e4b38d6918ba | 878 | } |
asong | 1:e4b38d6918ba | 879 | case 29: {//Heart Rate Zone Boundary Info |
asong | 1:e4b38d6918ba | 880 | StartHaptic(); |
asong | 1:e4b38d6918ba | 881 | Screen_Num = 28; |
asong | 1:e4b38d6918ba | 882 | update_display(); |
asong | 1:e4b38d6918ba | 883 | break; |
asong | 1:e4b38d6918ba | 884 | } |
asong | 2:824ed4ae8d52 | 885 | case 30: {//Change Target Heart Rate Zone Preference |
asong | 1:e4b38d6918ba | 886 | StartHaptic(); |
asong | 1:e4b38d6918ba | 887 | Screen_Num = 29; |
asong | 1:e4b38d6918ba | 888 | update_display(); |
asong | 1:e4b38d6918ba | 889 | break; |
asong | 1:e4b38d6918ba | 890 | } |
asong | 2:824ed4ae8d52 | 891 | case 31: { |
asong | 2:824ed4ae8d52 | 892 | StartHaptic(); |
asong | 2:824ed4ae8d52 | 893 | Screen_Num = 7; |
asong | 2:824ed4ae8d52 | 894 | update_display(); |
asong | 2:824ed4ae8d52 | 895 | break; |
asong | 2:824ed4ae8d52 | 896 | } |
asong | 2:824ed4ae8d52 | 897 | case 32: { |
asong | 2:824ed4ae8d52 | 898 | StartHaptic(); |
asong | 2:824ed4ae8d52 | 899 | Screen_Num = 31; |
asong | 2:824ed4ae8d52 | 900 | update_display(); |
asong | 2:824ed4ae8d52 | 901 | break; |
asong | 2:824ed4ae8d52 | 902 | } |
nbaker | 8:a5c77b45008d | 903 | case 41: {// Fall mode screen |
nbaker | 8:a5c77b45008d | 904 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 905 | Screen_Num = 22; |
nbaker | 8:a5c77b45008d | 906 | update_display(); |
nbaker | 8:a5c77b45008d | 907 | break; |
nbaker | 8:a5c77b45008d | 908 | } |
nbaker | 8:a5c77b45008d | 909 | case 42: {// F-Th adj |
nbaker | 8:a5c77b45008d | 910 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 911 | Screen_Num = 41; //Change to screen 41 |
nbaker | 8:a5c77b45008d | 912 | update_display(); |
nbaker | 8:a5c77b45008d | 913 | break; |
nbaker | 8:a5c77b45008d | 914 | } |
nbaker | 8:a5c77b45008d | 915 | case 43: {// I-Th adj |
nbaker | 8:a5c77b45008d | 916 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 917 | Screen_Num = 42; //Change to screen 42 |
nbaker | 8:a5c77b45008d | 918 | update_display(); |
nbaker | 8:a5c77b45008d | 919 | break; |
nbaker | 8:a5c77b45008d | 920 | } |
nbaker | 8:a5c77b45008d | 921 | case 44: {// M-Th adj |
nbaker | 8:a5c77b45008d | 922 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 923 | Screen_Num = 43; //Change to screen 43 |
nbaker | 8:a5c77b45008d | 924 | update_display(); |
nbaker | 8:a5c77b45008d | 925 | break; |
nbaker | 8:a5c77b45008d | 926 | } |
nbaker | 8:a5c77b45008d | 927 | case 71: {// BLE |
nbaker | 8:a5c77b45008d | 928 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 929 | Screen_Num = 0; //Change to screen 0 |
nbaker | 8:a5c77b45008d | 930 | update_display(); |
nbaker | 8:a5c77b45008d | 931 | break; |
nbaker | 8:a5c77b45008d | 932 | } |
nbaker | 8:a5c77b45008d | 933 | |
nbaker | 8:a5c77b45008d | 934 | case 72: {// BlueTooth on/off |
nbaker | 8:a5c77b45008d | 935 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 936 | Screen_Num = 71; //Change to screen 71 |
nbaker | 8:a5c77b45008d | 937 | update_display(); |
nbaker | 8:a5c77b45008d | 938 | break; |
nbaker | 8:a5c77b45008d | 939 | } |
nbaker | 8:a5c77b45008d | 940 | |
asong | 1:e4b38d6918ba | 941 | default: { |
asong | 1:e4b38d6918ba | 942 | break; |
asong | 1:e4b38d6918ba | 943 | } |
asong | 1:e4b38d6918ba | 944 | } |
nbaker | 0:d1d36a3da39b | 945 | } |
nbaker | 0:d1d36a3da39b | 946 | } |
nbaker | 0:d1d36a3da39b | 947 | |
nbaker | 0:d1d36a3da39b | 948 | |
nbaker | 0:d1d36a3da39b | 949 | void ButtonSlide(void) // What is this Slide button??? |
nbaker | 0:d1d36a3da39b | 950 | { |
asong | 1:e4b38d6918ba | 951 | Screen_Timer.attach(&timout_timer,(SCRN_TIME));//Is this sufficient to reset/restart ticker timer for OLED? |
asong | 1:e4b38d6918ba | 952 | if (OLED_ON == 0) { |
asong | 1:e4b38d6918ba | 953 | OLED_ON = 1; // Screen was off, set to On |
asong | 1:e4b38d6918ba | 954 | } |
nbaker | 0:d1d36a3da39b | 955 | StartHaptic(); |
nbaker | 0:d1d36a3da39b | 956 | oled.FillScreen(COLOR_BLACK); // Clear screen |
nbaker | 0:d1d36a3da39b | 957 | strcpy((char *) text_1,"Slide Button"); |
nbaker | 0:d1d36a3da39b | 958 | oled.Label((uint8_t *)text_1,0,40); |
nbaker | 0:d1d36a3da39b | 959 | } |
asong | 1:e4b38d6918ba | 960 | |
nbaker | 0:d1d36a3da39b | 961 | int main() |
nbaker | 0:d1d36a3da39b | 962 | { |
nbaker | 7:3d5a8aea0b63 | 963 | // set_time(1256729737); // Set RTC time to Wed, 28 Oct 2009 11:35:37 |
nbaker | 8:a5c77b45008d | 964 | set_time(48*365*24*3600+61*24*3600+10*3600-4); // Set RTC time to Mon, 19 Feb 2018 10:00 |
nbaker | 4:0803151bc5e4 | 965 | OLED_PWR = 1; // Turn on OLED power supply |
jmr274 | 5:e1431272be79 | 966 | |
jmr274 | 5:e1431272be79 | 967 | |
nbaker | 0:d1d36a3da39b | 968 | oled.FillScreen(COLOR_BLACK); // Clear screen |
asong | 1:e4b38d6918ba | 969 | // ***************** Local variables *********************** |
asong | 1:e4b38d6918ba | 970 | // float accel_data[3]; float accel_rms=0.0; |
nbaker | 4:0803151bc5e4 | 971 | int i; |
nbaker | 4:0803151bc5e4 | 972 | |
nbaker | 0:d1d36a3da39b | 973 | // ************** configure sensor modules ****************** |
nbaker | 4:0803151bc5e4 | 974 | // accel.accel_config(); // configure sensor |
nbaker | 7:3d5a8aea0b63 | 975 | // fall_config(1); // configure sensor for fall detect |
nbaker | 8:a5c77b45008d | 976 | fall_config(Fall_Alert_Mode); // configure sensor for current fall mode |
nbaker | 7:3d5a8aea0b63 | 977 | // mag.mag_config(); |
nbaker | 4:0803151bc5e4 | 978 | gyro.gyro_config(); |
asong | 1:e4b38d6918ba | 979 | |
nbaker | 0:d1d36a3da39b | 980 | RED_Led = LED_OFF; |
nbaker | 0:d1d36a3da39b | 981 | GRN_Led = LED_OFF; |
nbaker | 0:d1d36a3da39b | 982 | BLU_Led = LED_OFF; |
nbaker | 4:0803151bc5e4 | 983 | Led_clk1 = 0; // LEDs on docking station default to off, need to turn on with a 1 |
nbaker | 4:0803151bc5e4 | 984 | Led_clk2 = 0; // LEDs on docking station default to off, need to turn on with a 1 |
nbaker | 4:0803151bc5e4 | 985 | Led_clk3 = 0; // LEDs on docking station default to off, need to turn on with a 1 |
nbaker | 4:0803151bc5e4 | 986 | Non_Free_PWR = 1; // Start with non-freescale sensors (Pres/Temp/Hum/Light)on |
nbaker | 8:a5c77b45008d | 987 | |
nbaker | 8:a5c77b45008d | 988 | HR_PWR = 0; // Start with Heart rate sensor powered off |
nbaker | 4:0803151bc5e4 | 989 | |
nbaker | 0:d1d36a3da39b | 990 | // ***** Register callbacks/interupts to application functions ********* |
nbaker | 0:d1d36a3da39b | 991 | kw40z_device.attach_buttonUp(&ButtonUp); |
nbaker | 0:d1d36a3da39b | 992 | kw40z_device.attach_buttonDown(&ButtonDown); |
nbaker | 0:d1d36a3da39b | 993 | kw40z_device.attach_buttonLeft(&ButtonLeft); |
nbaker | 0:d1d36a3da39b | 994 | kw40z_device.attach_buttonRight(&ButtonRight); |
nbaker | 4:0803151bc5e4 | 995 | // kw40z_device.attach_buttonSlide(&ButtonSlide); |
nbaker | 4:0803151bc5e4 | 996 | |
nbaker | 4:0803151bc5e4 | 997 | // ***** attaching interupts to functions ********* |
nbaker | 4:0803151bc5e4 | 998 | Accel_INT1.fall(&fall_detect); // Accel sensor's int#1 calls interupt routine |
nbaker | 7:3d5a8aea0b63 | 999 | Accel_INT2.fall(&impact_detect); //Accel sensor's int#2 calls interupt routine |
nbaker | 4:0803151bc5e4 | 1000 | |
nbaker | 0:d1d36a3da39b | 1001 | |
nbaker | 0:d1d36a3da39b | 1002 | // **** Get OLED Class Default Text Properties **************** |
asong | 1:e4b38d6918ba | 1003 | oled_text_properties_t textProperties = {0}; |
asong | 1:e4b38d6918ba | 1004 | oled.GetTextProperties(&textProperties); |
asong | 1:e4b38d6918ba | 1005 | |
nbaker | 0:d1d36a3da39b | 1006 | // *********Set text color and screen alignment ************** |
asong | 1:e4b38d6918ba | 1007 | textProperties.fontColor = COLOR_WHITE; |
asong | 1:e4b38d6918ba | 1008 | textProperties.alignParam = OLED_TEXT_ALIGN_LEFT; |
asong | 1:e4b38d6918ba | 1009 | oled.SetTextProperties(&textProperties); |
asong | 1:e4b38d6918ba | 1010 | |
nbaker | 0:d1d36a3da39b | 1011 | // ************** Display spash screen ********************** |
nbaker | 8:a5c77b45008d | 1012 | oled.FillScreen(COLOR_BLACK); // Clear screen |
nbaker | 0:d1d36a3da39b | 1013 | oled.Label((uint8_t *)"Hexi",20,5); // Display white "Hexi" at x,y |
nbaker | 0:d1d36a3da39b | 1014 | textProperties.fontColor = COLOR_RED; |
asong | 1:e4b38d6918ba | 1015 | oled.SetTextProperties(&textProperties); |
asong | 1:e4b38d6918ba | 1016 | oled.Label((uint8_t *)"Heart",45,5); // Display red "Heart" at x,y |
nbaker | 0:d1d36a3da39b | 1017 | |
asong | 1:e4b38d6918ba | 1018 | #ifdef Debug // if this is non-production version - do this |
nbaker | 8:a5c77b45008d | 1019 | strcpy((char *) text_1,"This is Debug"); |
nbaker | 8:a5c77b45008d | 1020 | oled.Label((uint8_t *)text_1,15,50); // text_1 at x,y |
nbaker | 8:a5c77b45008d | 1021 | sprintf(text_1," Ver:%2.2f ",SW_Ver); |
nbaker | 8:a5c77b45008d | 1022 | oled.Label((uint8_t *)text_1,30,70);// text_1 at x,y |
nbaker | 8:a5c77b45008d | 1023 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 1024 | #endif |
nbaker | 8:a5c77b45008d | 1025 | |
nbaker | 0:d1d36a3da39b | 1026 | textProperties.fontColor = COLOR_WHITE; |
nbaker | 0:d1d36a3da39b | 1027 | oled.SetTextProperties(&textProperties); |
nbaker | 0:d1d36a3da39b | 1028 | wait(3); // wait 3 seconds |
asong | 1:e4b38d6918ba | 1029 | update_display(); // Displays current screen (screen 0) |
nbaker | 0:d1d36a3da39b | 1030 | Screen_Timer.attach(&timout_timer,(SCRN_TIME));//start ticker timer for turning off LCD |
asong | 1:e4b38d6918ba | 1031 | // ******************* Main Loop ************************* |
nbaker | 0:d1d36a3da39b | 1032 | while (true) { |
nbaker | 4:0803151bc5e4 | 1033 | i=0; |
nbaker | 4:0803151bc5e4 | 1034 | while (i<20)// used for "Heart beat flash and updated any displayed data) |
nbaker | 4:0803151bc5e4 | 1035 | { |
nbaker | 4:0803151bc5e4 | 1036 | Thread::wait(500); // wait 0.5 sec each loop |
nbaker | 4:0803151bc5e4 | 1037 | if(OLED_PWR==1){ |
nbaker | 8:a5c77b45008d | 1038 | update_display_date(); // refresh display date w/o updating entire display |
nbaker | 4:0803151bc5e4 | 1039 | }// end if |
nbaker | 4:0803151bc5e4 | 1040 | i++; |
nbaker | 4:0803151bc5e4 | 1041 | }// end while(i<20) |
jmr274 | 5:e1431272be79 | 1042 | |
nbaker | 4:0803151bc5e4 | 1043 | // wait(10); // wait 10 sec each loop, was orig half sec |
nbaker | 4:0803151bc5e4 | 1044 | RED_Led = LED_ON; // Used only for diagnostic of wait command |
nbaker | 4:0803151bc5e4 | 1045 | Led_clk3 = 1; // Used only for diagnostic of wait command |
nbaker | 4:0803151bc5e4 | 1046 | wait(0.01); // BLIP led 1/10 sec each loop |
nbaker | 4:0803151bc5e4 | 1047 | RED_Led = LED_OFF; // Used only for diagnostic of wait command |
nbaker | 4:0803151bc5e4 | 1048 | Led_clk3 = 0; |
nbaker | 8:a5c77b45008d | 1049 | Thread::wait(490); // keep up the pace, at 0.5 sec (0.01s+0.49s) update date |
nbaker | 4:0803151bc5e4 | 1050 | |
nbaker | 4:0803151bc5e4 | 1051 | } // end of while(true) |
nbaker | 4:0803151bc5e4 | 1052 | |
nbaker | 0:d1d36a3da39b | 1053 | } |
nbaker | 0:d1d36a3da39b | 1054 | // ************** end of main() |
nbaker | 0:d1d36a3da39b | 1055 | |
nbaker | 0:d1d36a3da39b | 1056 | void update_display(void) |
nbaker | 0:d1d36a3da39b | 1057 | { |
nbaker | 4:0803151bc5e4 | 1058 | OLED_PWR = 1; // make sure OLED power supply is on |
asong | 1:e4b38d6918ba | 1059 | oled_text_properties_t textProperties = {0}; // Need these to change font color |
asong | 1:e4b38d6918ba | 1060 | oled.GetTextProperties(&textProperties); // Need these to change font color |
nbaker | 8:a5c77b45008d | 1061 | __disable_irq(); // Disable all Interrupts |
asong | 1:e4b38d6918ba | 1062 | switch(Screen_Num) { |
asong | 1:e4b38d6918ba | 1063 | case 0: {// Main Screen |
nbaker | 4:0803151bc5e4 | 1064 | HexiwearBattery battery; |
nbaker | 4:0803151bc5e4 | 1065 | battery.sensorOn(); |
asong | 1:e4b38d6918ba | 1066 | oled.FillScreen(COLOR_BLACK); // Clear screen |
nbaker | 4:0803151bc5e4 | 1067 | |
nbaker | 4:0803151bc5e4 | 1068 | if (battery.isBatteryCharging()) { |
nbaker | 4:0803151bc5e4 | 1069 | textProperties.fontColor = COLOR_GREEN; |
nbaker | 4:0803151bc5e4 | 1070 | oled.SetTextProperties(&textProperties); |
nbaker | 4:0803151bc5e4 | 1071 | // sprintf(text_1, "%s", "chrg"); |
nbaker | 4:0803151bc5e4 | 1072 | sprintf(text_1, "%i%%+", (uint8_t)battery.readLevelPercent()); |
nbaker | 4:0803151bc5e4 | 1073 | Screen_Timer.attach(&timout_timer,(SCRN_TIME));// Reset/restart ticker timer for OLED while fully charged |
nbaker | 4:0803151bc5e4 | 1074 | } else { |
nbaker | 4:0803151bc5e4 | 1075 | sprintf(text_1, "%i%%", (uint8_t)battery.readLevelPercent()); |
nbaker | 4:0803151bc5e4 | 1076 | } |
nbaker | 8:a5c77b45008d | 1077 | oled.TextBox((uint8_t *)text_1,60,0,35,15); //show level value of battery in a 35px by 15px text box at x=60, y=0 |
nbaker | 4:0803151bc5e4 | 1078 | |
nbaker | 4:0803151bc5e4 | 1079 | textProperties.fontColor = COLOR_WHITE; |
nbaker | 4:0803151bc5e4 | 1080 | oled.SetTextProperties(&textProperties); |
nbaker | 4:0803151bc5e4 | 1081 | |
nbaker | 4:0803151bc5e4 | 1082 | oled.Label((uint8_t *)"Batt",35,0); // Display "Batt" at x,y |
asong | 1:e4b38d6918ba | 1083 | oled.Label((uint8_t *)"Date",35,20); // Display "Date" at x,y |
asong | 1:e4b38d6918ba | 1084 | oled.Label((uint8_t *)"Time",35,40); // Display "Time" at x,y |
jmr274 | 5:e1431272be79 | 1085 | // oled.Label((uint8_t *)"H.I.",10,80); // Display "H.I." at x,y |
nbaker | 7:3d5a8aea0b63 | 1086 | |
asong | 1:e4b38d6918ba | 1087 | oled.Label((uint8_t *)"BT",40,80); //Display "BT" at x,y |
asong | 1:e4b38d6918ba | 1088 | oled.Label((uint8_t *)"Menu",60,80); //Display "Menu" at x,y |
jmr274 | 5:e1431272be79 | 1089 | |
nbaker | 7:3d5a8aea0b63 | 1090 | textProperties.fontColor = COLOR_GRAY; |
nbaker | 8:a5c77b45008d | 1091 | if(BLE_On == 1){ |
nbaker | 8:a5c77b45008d | 1092 | textProperties.fontColor = COLOR_BLUE; |
nbaker | 8:a5c77b45008d | 1093 | } |
nbaker | 7:3d5a8aea0b63 | 1094 | oled.SetTextProperties(&textProperties); |
nbaker | 8:a5c77b45008d | 1095 | |
nbaker | 7:3d5a8aea0b63 | 1096 | oled.Label((uint8_t *)"BT",40,80); //Display "BT" at x,y |
nbaker | 7:3d5a8aea0b63 | 1097 | textProperties.fontColor = COLOR_WHITE; |
nbaker | 7:3d5a8aea0b63 | 1098 | oled.SetTextProperties(&textProperties); |
nbaker | 7:3d5a8aea0b63 | 1099 | |
nbaker | 7:3d5a8aea0b63 | 1100 | // added real time and date information |
nbaker | 7:3d5a8aea0b63 | 1101 | char buffer[32]; |
nbaker | 7:3d5a8aea0b63 | 1102 | time_t seconds = time(NULL); |
nbaker | 7:3d5a8aea0b63 | 1103 | strftime(buffer,32, "%a,%d %m %Y.%H:%M:%S\r", localtime(&seconds)); |
nbaker | 7:3d5a8aea0b63 | 1104 | sprintf(text_1,"%c%c/%c%c/%c%c%c%c ",buffer[7],buffer[8],buffer[4],buffer[5],buffer[10],buffer[11],buffer[12],buffer[13]); |
nbaker | 7:3d5a8aea0b63 | 1105 | oled.Label((uint8_t *)text_1,20,20);// Date at x,y |
nbaker | 7:3d5a8aea0b63 | 1106 | sprintf(text_1,"%c%c:%c%c:%c%c ",buffer[15],buffer[16],buffer[18],buffer[19],buffer[21],buffer[22]); |
nbaker | 7:3d5a8aea0b63 | 1107 | oled.Label((uint8_t *)text_1,25,40);// Time at x,y |
nbaker | 7:3d5a8aea0b63 | 1108 | |
nbaker | 7:3d5a8aea0b63 | 1109 | |
nbaker | 7:3d5a8aea0b63 | 1110 | |
jmr274 | 5:e1431272be79 | 1111 | Heat_Index_Calculation(); |
jmr274 | 5:e1431272be79 | 1112 | sprintf(text,"%i",heat_index); |
nbaker | 8:a5c77b45008d | 1113 | oled.TextBox((uint8_t *)text,3,80,15,15); //show HI in a 15px by 15px text box at x=3, y=80 |
jmr274 | 5:e1431272be79 | 1114 | strcpy((char *) text,"dF");oled.Label((uint8_t *)text,18,80); |
jmr274 | 5:e1431272be79 | 1115 | |
asong | 1:e4b38d6918ba | 1116 | if(Heart_Rate_Mode == 1) { |
asong | 1:e4b38d6918ba | 1117 | oled.Label((uint8_t *)"BPM",35,60); // Display "H.I." at x,y |
asong | 1:e4b38d6918ba | 1118 | } |
asong | 1:e4b38d6918ba | 1119 | break; |
asong | 1:e4b38d6918ba | 1120 | } |
asong | 1:e4b38d6918ba | 1121 | case 1: {// Panic Alert option |
asong | 1:e4b38d6918ba | 1122 | oled.FillScreen(COLOR_BLACK); // Clear screen |
asong | 1:e4b38d6918ba | 1123 | oled.Label((uint8_t *)"Panic Alert",20,5); // Display at x,y |
asong | 1:e4b38d6918ba | 1124 | oled.Label((uint8_t *)"*",85,15); // "*" at x,y |
asong | 1:e4b38d6918ba | 1125 | oled.Label((uint8_t *)"*",85,60); // "*" at x,y |
asong | 1:e4b38d6918ba | 1126 | oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y |
asong | 1:e4b38d6918ba | 1127 | oled.Label((uint8_t *)"Enter",60,80); //Display "enter" at x,y |
asong | 1:e4b38d6918ba | 1128 | break; |
asong | 1:e4b38d6918ba | 1129 | } |
asong | 1:e4b38d6918ba | 1130 | case 2: {// Fall Alert option |
asong | 1:e4b38d6918ba | 1131 | oled.FillScreen(COLOR_BLACK); // Clear screen |
asong | 1:e4b38d6918ba | 1132 | oled.Label((uint8_t *)"Fall Alert",20,5); // Display at x,y |
nbaker | 4:0803151bc5e4 | 1133 | oled.Label((uint8_t *)"Protection",15,25); |
nbaker | 4:0803151bc5e4 | 1134 | if (Fall_Alert == 1){ |
nbaker | 7:3d5a8aea0b63 | 1135 | oled.Label((uint8_t *)" On ",40,40); |
nbaker | 4:0803151bc5e4 | 1136 | } |
nbaker | 4:0803151bc5e4 | 1137 | else { |
nbaker | 4:0803151bc5e4 | 1138 | oled.Label((uint8_t *)" Off ",40,40); |
nbaker | 4:0803151bc5e4 | 1139 | } |
asong | 1:e4b38d6918ba | 1140 | oled.Label((uint8_t *)"*",85,15); // "*" at x,y |
asong | 1:e4b38d6918ba | 1141 | oled.Label((uint8_t *)"*",85,60); // "*" at x,y |
asong | 1:e4b38d6918ba | 1142 | oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y |
asong | 1:e4b38d6918ba | 1143 | oled.Label((uint8_t *)"Toggle",60,80); //Display "Toggle" at x,y |
asong | 1:e4b38d6918ba | 1144 | break; |
asong | 1:e4b38d6918ba | 1145 | } |
asong | 1:e4b38d6918ba | 1146 | case 3: {// Heart Rate Monitoring option |
asong | 1:e4b38d6918ba | 1147 | oled.FillScreen(COLOR_BLACK); // Clear screen |
asong | 1:e4b38d6918ba | 1148 | oled.Label((uint8_t *)"Heart Rate",20,5); // Display 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 *)"Back",10,80); // Display "Back" at x,y |
asong | 1:e4b38d6918ba | 1152 | oled.Label((uint8_t *)"Enter",60,80); //Display at x,y |
asong | 1:e4b38d6918ba | 1153 | break; |
asong | 1:e4b38d6918ba | 1154 | } |
asong | 1:e4b38d6918ba | 1155 | case 4: {// Alert History option |
asong | 1:e4b38d6918ba | 1156 | oled.FillScreen(COLOR_BLACK); // Clear screen |
nbaker | 7:3d5a8aea0b63 | 1157 | oled.Label((uint8_t *)"Alert History",10,5); // Display at x,y |
asong | 1:e4b38d6918ba | 1158 | oled.Label((uint8_t *)"*",85,15); // "*" at x,y |
asong | 1:e4b38d6918ba | 1159 | oled.Label((uint8_t *)"*",85,60); // "*" at x,y |
asong | 1:e4b38d6918ba | 1160 | oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y |
asong | 1:e4b38d6918ba | 1161 | oled.Label((uint8_t *)"Enter",60,80); //Display at x,y |
asong | 1:e4b38d6918ba | 1162 | break; |
asong | 1:e4b38d6918ba | 1163 | } |
asong | 1:e4b38d6918ba | 1164 | case 5: {// About HexiHeart Screen |
nbaker | 0:d1d36a3da39b | 1165 | |
asong | 1:e4b38d6918ba | 1166 | oled.FillScreen(COLOR_BLACK); // Clear screen |
asong | 1:e4b38d6918ba | 1167 | oled.Label((uint8_t *)"Hexi",20,20); // Display white "Hexi" at x,y |
asong | 1:e4b38d6918ba | 1168 | textProperties.fontColor = COLOR_RED; |
asong | 1:e4b38d6918ba | 1169 | oled.SetTextProperties(&textProperties); |
asong | 1:e4b38d6918ba | 1170 | oled.Label((uint8_t *)"Heart",45,20); // Display red "Heart" at x,y |
asong | 1:e4b38d6918ba | 1171 | textProperties.fontColor = COLOR_WHITE; |
asong | 1:e4b38d6918ba | 1172 | oled.SetTextProperties(&textProperties); |
asong | 1:e4b38d6918ba | 1173 | strcpy((char *) text_1,"About"); |
asong | 1:e4b38d6918ba | 1174 | oled.Label((uint8_t *)text_1,30,5); // text_1 at x,y |
asong | 1:e4b38d6918ba | 1175 | oled.Label((uint8_t *)"*",85,15); // "*" at x,y |
asong | 1:e4b38d6918ba | 1176 | oled.Label((uint8_t *)"*",85,60); // "*" at x,y |
asong | 1:e4b38d6918ba | 1177 | oled.Label((uint8_t *)" Back ",9,80); // Display "Back" at x,y |
asong | 1:e4b38d6918ba | 1178 | oled.Label((uint8_t *)" Enter ",59,80); //Display at x,y |
asong | 1:e4b38d6918ba | 1179 | break; |
asong | 1:e4b38d6918ba | 1180 | } |
asong | 1:e4b38d6918ba | 1181 | |
asong | 1:e4b38d6918ba | 1182 | case 6: {// Panic Alert |
asong | 1:e4b38d6918ba | 1183 | oled.FillScreen(COLOR_BLACK); // Clear screen |
asong | 1:e4b38d6918ba | 1184 | if (Panic_Alert == 0) { |
asong | 1:e4b38d6918ba | 1185 | oled.Label((uint8_t *)"Send ",20,10); // Display at x,y |
asong | 1:e4b38d6918ba | 1186 | } else { |
asong | 1:e4b38d6918ba | 1187 | oled.Label((uint8_t *)"Dismiss ",17,10); // Display at x,y |
asong | 1:e4b38d6918ba | 1188 | } |
asong | 1:e4b38d6918ba | 1189 | oled.Label((uint8_t *)"Panic Alert",15,40); // Display at x,y |
asong | 1:e4b38d6918ba | 1190 | oled.Label((uint8_t *)"-->",80,15); // "*" at x,y |
asong | 1:e4b38d6918ba | 1191 | oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y |
asong | 1:e4b38d6918ba | 1192 | break; |
asong | 1:e4b38d6918ba | 1193 | } |
asong | 1:e4b38d6918ba | 1194 | case 7: {// Heart Rate Zone |
asong | 1:e4b38d6918ba | 1195 | |
asong | 1:e4b38d6918ba | 1196 | oled.FillScreen(COLOR_BLACK); // Clear screen |
asong | 1:e4b38d6918ba | 1197 | oled.Label((uint8_t *)"Heart Rate",15,5); // Display at x,y |
asong | 1:e4b38d6918ba | 1198 | oled.Label((uint8_t *)"HR:",15,25); // Display at x,y |
asong | 2:824ed4ae8d52 | 1199 | sprintf(display_buff, "%u", Heart_Rate); |
asong | 2:824ed4ae8d52 | 1200 | textProperties.fontColor = COLOR_RED; //Change font to red |
asong | 2:824ed4ae8d52 | 1201 | oled.SetTextProperties(&textProperties);//Implement color change |
asong | 2:824ed4ae8d52 | 1202 | oled.Label((uint8_t *)display_buff,43,25); // Display at x,y |
asong | 2:824ed4ae8d52 | 1203 | textProperties.fontColor = COLOR_WHITE; |
asong | 2:824ed4ae8d52 | 1204 | oled.SetTextProperties(&textProperties); |
asong | 1:e4b38d6918ba | 1205 | oled.Label((uint8_t *)"Age: ",15,45); // Display at x,y |
asong | 1:e4b38d6918ba | 1206 | textProperties.fontColor = COLOR_GREEN; |
asong | 1:e4b38d6918ba | 1207 | oled.SetTextProperties(&textProperties); //implements the color change |
asong | 1:e4b38d6918ba | 1208 | sprintf(display_buff, "%u", Age); //Convert int to char array for displaying user age |
asong | 1:e4b38d6918ba | 1209 | oled.Label((uint8_t *)display_buff,43,45); // Display at x,y |
asong | 1:e4b38d6918ba | 1210 | textProperties.fontColor = COLOR_WHITE; |
asong | 1:e4b38d6918ba | 1211 | oled.SetTextProperties(&textProperties); |
asong | 2:824ed4ae8d52 | 1212 | oled.Label((uint8_t *)"On",80,15); // "+" at x,y |
asong | 2:824ed4ae8d52 | 1213 | oled.Label((uint8_t *)"Off",78,60); // "-" at x,y |
asong | 1:e4b38d6918ba | 1214 | oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y |
asong | 1:e4b38d6918ba | 1215 | oled.Label((uint8_t *)"Next",59,80); // Display "Next" at x,y |
asong | 2:824ed4ae8d52 | 1216 | |
asong | 1:e4b38d6918ba | 1217 | //heart.enable(); |
asong | 1:e4b38d6918ba | 1218 | //sprintf(display_buff, "%u", heart.getRevisionID()); //Convert int to char array for displaying user age |
asong | 1:e4b38d6918ba | 1219 | //oled.Label((uint8_t *)display_buff,45,25); // Display at x,y |
asong | 1:e4b38d6918ba | 1220 | //update_display(); |
asong | 1:e4b38d6918ba | 1221 | break; |
asong | 1:e4b38d6918ba | 1222 | } |
asong | 1:e4b38d6918ba | 1223 | case 8: {// Alert History |
asong | 1:e4b38d6918ba | 1224 | oled.FillScreen(COLOR_BLACK); // Clear screen |
asong | 1:e4b38d6918ba | 1225 | oled.Label((uint8_t *)"Alert History",5,5); // Display at x,y |
asong | 1:e4b38d6918ba | 1226 | oled.Label((uint8_t *)"Date - Time",20,40); // Display at x,y |
asong | 1:e4b38d6918ba | 1227 | oled.Label((uint8_t *)"Alert Type:",20,60); // Display at x,y |
asong | 1:e4b38d6918ba | 1228 | oled.Label((uint8_t *)"+",85,15); // "*" at x,y |
asong | 1:e4b38d6918ba | 1229 | oled.Label((uint8_t *)"-",85,60); // "*" at x,y |
asong | 1:e4b38d6918ba | 1230 | oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y |
asong | 1:e4b38d6918ba | 1231 | break; |
asong | 1:e4b38d6918ba | 1232 | } |
nbaker | 8:a5c77b45008d | 1233 | |
nbaker | 8:a5c77b45008d | 1234 | case 9: {// About HexiHeart info1 |
nbaker | 8:a5c77b45008d | 1235 | oled.FillScreen(COLOR_BLACK); // Clear screen |
nbaker | 8:a5c77b45008d | 1236 | oled.Label((uint8_t *)"Hexi",20,1); // Display white "Hexi" at x,y |
nbaker | 8:a5c77b45008d | 1237 | textProperties.fontColor = COLOR_RED; |
nbaker | 8:a5c77b45008d | 1238 | oled.SetTextProperties(&textProperties); |
nbaker | 8:a5c77b45008d | 1239 | oled.Label((uint8_t *)"Heart",45,0); // Display red "Heart" at x,y |
nbaker | 8:a5c77b45008d | 1240 | textProperties.fontColor = COLOR_WHITE; |
nbaker | 8:a5c77b45008d | 1241 | oled.SetTextProperties(&textProperties); |
nbaker | 8:a5c77b45008d | 1242 | oled.Label((uint8_t *)"Senior Proj",5,15); // |
nbaker | 8:a5c77b45008d | 1243 | oled.Label((uint8_t *)"Team Zeta E1.7",5,30); // |
nbaker | 8:a5c77b45008d | 1244 | oled.Label((uint8_t *)"Texas State Univ",0,45); // |
nbaker | 8:a5c77b45008d | 1245 | oled.Label((uint8_t *)"+",85,15); // "*" at x,y |
nbaker | 8:a5c77b45008d | 1246 | oled.Label((uint8_t *)"-",85,60); // "*" at x,y |
nbaker | 8:a5c77b45008d | 1247 | oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y |
nbaker | 8:a5c77b45008d | 1248 | break; |
nbaker | 8:a5c77b45008d | 1249 | } |
nbaker | 8:a5c77b45008d | 1250 | |
nbaker | 8:a5c77b45008d | 1251 | case 10: {// About HexiHeart info2 |
nbaker | 8:a5c77b45008d | 1252 | oled.FillScreen(COLOR_BLACK); // Clear screen |
nbaker | 8:a5c77b45008d | 1253 | oled.Label((uint8_t *)"Hexi",20,0); // Display white "Hexi" at x,y |
nbaker | 8:a5c77b45008d | 1254 | textProperties.fontColor = COLOR_RED; |
nbaker | 8:a5c77b45008d | 1255 | oled.SetTextProperties(&textProperties); |
nbaker | 8:a5c77b45008d | 1256 | oled.Label((uint8_t *)"Heart",45,0); // Display red "Heart" at x,y |
nbaker | 8:a5c77b45008d | 1257 | textProperties.fontColor = COLOR_WHITE; |
nbaker | 8:a5c77b45008d | 1258 | oled.SetTextProperties(&textProperties); |
nbaker | 8:a5c77b45008d | 1259 | oled.Label((uint8_t *)"E2.7 Team Zeta",2,12); // |
nbaker | 8:a5c77b45008d | 1260 | oled.Label((uint8_t *)"Alex Song",5,25); // |
nbaker | 8:a5c77b45008d | 1261 | oled.Label((uint8_t *)"Jasmine Rounsav",5,38); // Jasmine Rounsaville is to long |
nbaker | 8:a5c77b45008d | 1262 | oled.Label((uint8_t *)"Issam Hichami",5,51); // |
nbaker | 8:a5c77b45008d | 1263 | oled.Label((uint8_t *)"Neil Baker",5,64); // |
nbaker | 8:a5c77b45008d | 1264 | |
nbaker | 8:a5c77b45008d | 1265 | oled.Label((uint8_t *)"+",85,15); // "*" at x,y |
nbaker | 8:a5c77b45008d | 1266 | oled.Label((uint8_t *)"-",85,60); // "*" at x,y |
nbaker | 8:a5c77b45008d | 1267 | oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y |
nbaker | 8:a5c77b45008d | 1268 | break; |
nbaker | 8:a5c77b45008d | 1269 | } |
nbaker | 8:a5c77b45008d | 1270 | |
nbaker | 8:a5c77b45008d | 1271 | case 11: {// About HexiHeart info3 |
nbaker | 8:a5c77b45008d | 1272 | oled.FillScreen(COLOR_BLACK); // Clear screen |
nbaker | 8:a5c77b45008d | 1273 | oled.Label((uint8_t *)"Hexi",20,0); // Display white "Hexi" at x,y |
nbaker | 8:a5c77b45008d | 1274 | textProperties.fontColor = COLOR_RED; |
nbaker | 8:a5c77b45008d | 1275 | oled.SetTextProperties(&textProperties); |
nbaker | 8:a5c77b45008d | 1276 | oled.Label((uint8_t *)"Heart",45,0); // Display red "Heart" at x,y |
nbaker | 8:a5c77b45008d | 1277 | // *********get screen alignment ************** |
nbaker | 8:a5c77b45008d | 1278 | oled_text_properties_t textProperties = {0}; |
nbaker | 8:a5c77b45008d | 1279 | oled.GetTextProperties(&textProperties); |
nbaker | 8:a5c77b45008d | 1280 | // *********Set text color and screen alignment ************** |
nbaker | 8:a5c77b45008d | 1281 | textProperties.alignParam = OLED_TEXT_ALIGN_CENTER; |
nbaker | 8:a5c77b45008d | 1282 | oled.SetTextProperties(&textProperties); |
nbaker | 8:a5c77b45008d | 1283 | |
nbaker | 8:a5c77b45008d | 1284 | #ifdef Debug // if this is non-production version - do this |
nbaker | 8:a5c77b45008d | 1285 | oled.Label((uint8_t *)"This is Debug",0,25); // text_1 at X=10,y=25 |
nbaker | 8:a5c77b45008d | 1286 | oled.Label((uint8_t *)"Ver of SW",0,40); // text_1 at x=20,y=40 |
nbaker | 8:a5c77b45008d | 1287 | #endif |
nbaker | 8:a5c77b45008d | 1288 | textProperties.fontColor = COLOR_WHITE; |
nbaker | 8:a5c77b45008d | 1289 | oled.SetTextProperties(&textProperties); |
nbaker | 8:a5c77b45008d | 1290 | sprintf(text_1," SW_Ver:%2.2f ",SW_Ver); |
nbaker | 8:a5c77b45008d | 1291 | oled.Label((uint8_t *)text_1,0,55);// text_1 at x=10,y |
nbaker | 8:a5c77b45008d | 1292 | textProperties.alignParam = OLED_TEXT_ALIGN_LEFT; |
nbaker | 8:a5c77b45008d | 1293 | oled.SetTextProperties(&textProperties); |
nbaker | 8:a5c77b45008d | 1294 | oled.Label((uint8_t *)"+",85,15); // "*" at x,y |
nbaker | 8:a5c77b45008d | 1295 | oled.Label((uint8_t *)"-",85,60); // "*" at x,y |
nbaker | 8:a5c77b45008d | 1296 | oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y |
nbaker | 8:a5c77b45008d | 1297 | break; |
nbaker | 8:a5c77b45008d | 1298 | } |
nbaker | 8:a5c77b45008d | 1299 | |
asong | 1:e4b38d6918ba | 1300 | #ifdef Debug // if this is non-production/debug version - do this |
asong | 1:e4b38d6918ba | 1301 | case 20: {// Diagnostic/Debug Screens |
asong | 1:e4b38d6918ba | 1302 | oled.FillScreen(COLOR_BLACK); // Clear screen |
asong | 1:e4b38d6918ba | 1303 | textProperties.fontColor = COLOR_RED; |
asong | 1:e4b38d6918ba | 1304 | oled.SetTextProperties(&textProperties); |
asong | 1:e4b38d6918ba | 1305 | oled.Label((uint8_t *)"Diagnostics",10,5); // Display at x,y |
asong | 1:e4b38d6918ba | 1306 | oled.Label((uint8_t *)" Enter ",59,80); //Display at x,y |
asong | 1:e4b38d6918ba | 1307 | textProperties.fontColor = COLOR_WHITE; |
asong | 1:e4b38d6918ba | 1308 | oled.SetTextProperties(&textProperties); |
asong | 1:e4b38d6918ba | 1309 | oled.Label((uint8_t *)"*",85,15); // "*" at x,y |
asong | 1:e4b38d6918ba | 1310 | oled.Label((uint8_t *)"*",85,60); // "*" at x,y |
asong | 1:e4b38d6918ba | 1311 | oled.Label((uint8_t *)" Back ",9,80); // Display "Back" at x,y |
nbaker | 0:d1d36a3da39b | 1312 | |
asong | 1:e4b38d6918ba | 1313 | break; |
asong | 1:e4b38d6918ba | 1314 | } |
asong | 1:e4b38d6918ba | 1315 | case 21: {// Fall Alert Diagnostic Screen |
nbaker | 8:a5c77b45008d | 1316 | if(Fall_Alert_Mode == 0){ |
nbaker | 8:a5c77b45008d | 1317 | fall_config(11); // turn accel sensor to active to take reading |
nbaker | 8:a5c77b45008d | 1318 | } |
asong | 1:e4b38d6918ba | 1319 | oled.FillScreen(COLOR_BLACK); // Clear screen |
asong | 1:e4b38d6918ba | 1320 | textProperties.fontColor = COLOR_RED; |
asong | 1:e4b38d6918ba | 1321 | oled.SetTextProperties(&textProperties); |
nbaker | 7:3d5a8aea0b63 | 1322 | oled.Label((uint8_t *)"Fall-Diag",25,5); // Display at x,y |
nbaker | 7:3d5a8aea0b63 | 1323 | // oled.Label((uint8_t *)"Diagnostic",25,5); // Display at x,y |
asong | 1:e4b38d6918ba | 1324 | textProperties.fontColor = COLOR_WHITE; |
asong | 1:e4b38d6918ba | 1325 | oled.SetTextProperties(&textProperties); |
nbaker | 8:a5c77b45008d | 1326 | gyro.acquire_gyro_data_dps(Gyro_Data); |
nbaker | 8:a5c77b45008d | 1327 | Gyro_Mag = (abs(Gyro_Data[0])+abs(Gyro_Data[1])+abs(Gyro_Data[2])); |
asong | 1:e4b38d6918ba | 1328 | accel.acquire_accel_data_g(Accel_Data); |
nbaker | 8:a5c77b45008d | 1329 | if(Fall_Alert_Mode == 0){ |
nbaker | 8:a5c77b45008d | 1330 | fall_config(12); // turn accel sensor to standby |
nbaker | 8:a5c77b45008d | 1331 | } |
nbaker | 8:a5c77b45008d | 1332 | Accel_Mag = 2*sqrt(((Accel_Data[0]*Accel_Data[0])+(Accel_Data[1]*Accel_Data[1])+(Accel_Data[2]*Accel_Data[2]))); |
asong | 1:e4b38d6918ba | 1333 | sprintf(text_1," Accel:%2.2f g ",Accel_Mag); |
asong | 1:e4b38d6918ba | 1334 | oled.Label((uint8_t *)text_1,10,40);// text_1 at x,y |
asong | 1:e4b38d6918ba | 1335 | sprintf(text_1," Gyro:%4.0f D/S ",Gyro_Mag); |
asong | 1:e4b38d6918ba | 1336 | oled.Label((uint8_t *)text_1,10,60);// text_1 at x,y |
nbaker | 8:a5c77b45008d | 1337 | oled.Label((uint8_t *)"*",85,15); // "*" at x,y |
nbaker | 8:a5c77b45008d | 1338 | oled.Label((uint8_t *)"*",85,60); // "*" at x,y |
asong | 1:e4b38d6918ba | 1339 | oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y |
asong | 1:e4b38d6918ba | 1340 | break; |
asong | 1:e4b38d6918ba | 1341 | } |
asong | 1:e4b38d6918ba | 1342 | case 22: {// Fall Alert Debug Screen |
asong | 1:e4b38d6918ba | 1343 | oled.FillScreen(COLOR_BLACK); // Clear screen |
asong | 1:e4b38d6918ba | 1344 | textProperties.fontColor = COLOR_RED; |
asong | 1:e4b38d6918ba | 1345 | oled.SetTextProperties(&textProperties); |
asong | 1:e4b38d6918ba | 1346 | oled.Label((uint8_t *)"Fall Debug",15,5); // Display at x,y |
asong | 1:e4b38d6918ba | 1347 | textProperties.fontColor = COLOR_GREEN; |
asong | 1:e4b38d6918ba | 1348 | oled.SetTextProperties(&textProperties); |
nbaker | 8:a5c77b45008d | 1349 | sprintf(text_1," %i ",Fall_Alert_Mode); |
asong | 1:e4b38d6918ba | 1350 | oled.Label((uint8_t *)text_1,35,20);// text_1 at x,y |
nbaker | 8:a5c77b45008d | 1351 | textProperties.fontColor = COLOR_GRAY; |
nbaker | 8:a5c77b45008d | 1352 | if(Fall_Alert_Mode == 1 || Fall_Alert_Mode == 3){ |
nbaker | 8:a5c77b45008d | 1353 | textProperties.fontColor = COLOR_GREEN; |
nbaker | 8:a5c77b45008d | 1354 | } |
nbaker | 8:a5c77b45008d | 1355 | oled.SetTextProperties(&textProperties); |
nbaker | 8:a5c77b45008d | 1356 | sprintf(text_1," %1.2f g ",Fall_Thresh); |
asong | 1:e4b38d6918ba | 1357 | oled.Label((uint8_t *)text_1,35,35);// text_1 at x,y |
nbaker | 8:a5c77b45008d | 1358 | textProperties.fontColor = COLOR_GRAY; |
nbaker | 8:a5c77b45008d | 1359 | if(Fall_Alert_Mode == 2 || Fall_Alert_Mode == 3){ |
nbaker | 8:a5c77b45008d | 1360 | textProperties.fontColor = COLOR_GREEN; |
nbaker | 8:a5c77b45008d | 1361 | } |
nbaker | 8:a5c77b45008d | 1362 | oled.SetTextProperties(&textProperties); |
nbaker | 8:a5c77b45008d | 1363 | sprintf(text_1," %2.2f g ",Impact_Thresh); |
nbaker | 8:a5c77b45008d | 1364 | oled.Label((uint8_t *)text_1,35,50);// text_1 at x,y |
nbaker | 8:a5c77b45008d | 1365 | textProperties.fontColor = COLOR_GRAY; |
nbaker | 8:a5c77b45008d | 1366 | if(Fall_Alert_Mode == 3){ |
nbaker | 8:a5c77b45008d | 1367 | //textProperties.fontColor = COLOR_GREEN; |
nbaker | 8:a5c77b45008d | 1368 | } |
nbaker | 8:a5c77b45008d | 1369 | oled.SetTextProperties(&textProperties); |
asong | 1:e4b38d6918ba | 1370 | sprintf(text_1," %3.0f D/S ",Movement_Thresh); |
nbaker | 8:a5c77b45008d | 1371 | oled.Label((uint8_t *)text_1,35,65);// text_1 at x,y |
asong | 1:e4b38d6918ba | 1372 | textProperties.fontColor = COLOR_WHITE; |
asong | 1:e4b38d6918ba | 1373 | oled.SetTextProperties(&textProperties); |
nbaker | 8:a5c77b45008d | 1374 | oled.Label((uint8_t *)"Mode:",5,20); // "*" at x,y |
nbaker | 8:a5c77b45008d | 1375 | oled.Label((uint8_t *)"F-Th:",5,35); // "*" at x,y |
nbaker | 8:a5c77b45008d | 1376 | oled.Label((uint8_t *)"I-Th:",5,50); // "*" at x,y |
nbaker | 8:a5c77b45008d | 1377 | oled.Label((uint8_t *)"M-Th:",5,65); // "*" at x,y |
asong | 1:e4b38d6918ba | 1378 | oled.Label((uint8_t *)"*",85,15); // "*" at x,y |
asong | 1:e4b38d6918ba | 1379 | oled.Label((uint8_t *)"*",85,60); // "*" at x,y |
asong | 1:e4b38d6918ba | 1380 | oled.Label((uint8_t *)" Back ",9,80); // Display "Back" at x,y |
nbaker | 8:a5c77b45008d | 1381 | oled.Label((uint8_t *)" Enter ",59,80); //Display at x,y |
asong | 1:e4b38d6918ba | 1382 | break; |
asong | 1:e4b38d6918ba | 1383 | } |
asong | 1:e4b38d6918ba | 1384 | case 23: {// Heart Rate Diagnostic Screen |
asong | 1:e4b38d6918ba | 1385 | oled.FillScreen(COLOR_BLACK); // Clear screen |
asong | 1:e4b38d6918ba | 1386 | textProperties.fontColor = COLOR_RED; |
asong | 1:e4b38d6918ba | 1387 | oled.SetTextProperties(&textProperties); |
asong | 1:e4b38d6918ba | 1388 | oled.Label((uint8_t *)"H.R. Diagnostic",5,5); // Display at x,y |
asong | 1:e4b38d6918ba | 1389 | textProperties.fontColor = COLOR_WHITE; |
asong | 1:e4b38d6918ba | 1390 | oled.SetTextProperties(&textProperties); |
asong | 1:e4b38d6918ba | 1391 | oled.Label((uint8_t *)"*",85,15); // "*" at x,y |
asong | 1:e4b38d6918ba | 1392 | oled.Label((uint8_t *)"*",85,60); // "*" at x,y |
asong | 1:e4b38d6918ba | 1393 | oled.Label((uint8_t *)" Back ",9,80); // Display "Back" at x,y |
asong | 1:e4b38d6918ba | 1394 | // oled.Label((uint8_t *)" Enter ",59,80); //Display at x,y |
asong | 1:e4b38d6918ba | 1395 | break; |
asong | 1:e4b38d6918ba | 1396 | } |
asong | 1:e4b38d6918ba | 1397 | case 24: {// Heart Rate Debug Screen |
asong | 1:e4b38d6918ba | 1398 | oled.FillScreen(COLOR_BLACK); // Clear screen |
asong | 1:e4b38d6918ba | 1399 | textProperties.fontColor = COLOR_RED; |
asong | 1:e4b38d6918ba | 1400 | oled.SetTextProperties(&textProperties); |
asong | 1:e4b38d6918ba | 1401 | oled.Label((uint8_t *)"H.R. Debug",10,5); // Display at x,y |
asong | 1:e4b38d6918ba | 1402 | textProperties.fontColor = COLOR_WHITE; |
asong | 1:e4b38d6918ba | 1403 | oled.SetTextProperties(&textProperties); |
asong | 1:e4b38d6918ba | 1404 | oled.Label((uint8_t *)"*",85,15); // "*" at x,y |
asong | 1:e4b38d6918ba | 1405 | oled.Label((uint8_t *)"*",85,60); // "*" at x,y |
asong | 1:e4b38d6918ba | 1406 | oled.Label((uint8_t *)" Back ",9,80); // Display "Back" at x,y |
asong | 1:e4b38d6918ba | 1407 | // oled.Label((uint8_t *)" Enter ",59,80); //Display at x,y |
asong | 1:e4b38d6918ba | 1408 | break; |
asong | 1:e4b38d6918ba | 1409 | } |
asong | 1:e4b38d6918ba | 1410 | case 25: {// Heat Index Diagnostic Screen |
asong | 1:e4b38d6918ba | 1411 | oled.FillScreen(COLOR_BLACK); // Clear screen |
asong | 1:e4b38d6918ba | 1412 | textProperties.fontColor = COLOR_RED; |
asong | 1:e4b38d6918ba | 1413 | oled.SetTextProperties(&textProperties); |
asong | 1:e4b38d6918ba | 1414 | oled.Label((uint8_t *)"H.I. Diagnostic",5,5); // Display at x,y |
asong | 1:e4b38d6918ba | 1415 | textProperties.fontColor = COLOR_WHITE; |
asong | 1:e4b38d6918ba | 1416 | oled.SetTextProperties(&textProperties); |
asong | 1:e4b38d6918ba | 1417 | oled.Label((uint8_t *)"*",85,15); // "*" at x,y |
asong | 1:e4b38d6918ba | 1418 | oled.Label((uint8_t *)"*",85,60); // "*" at x,y |
asong | 1:e4b38d6918ba | 1419 | oled.Label((uint8_t *)" Back ",9,80); // Display "Back" at x,y |
asong | 1:e4b38d6918ba | 1420 | // oled.Label((uint8_t *)" Enter ",59,80); //Display at x,y |
jmr274 | 5:e1431272be79 | 1421 | |
jmr274 | 6:84e3ba00b995 | 1422 | Heat_Index_Calculation(); |
jmr274 | 5:e1431272be79 | 1423 | |
jmr274 | 5:e1431272be79 | 1424 | oled_text_properties_t textProperties = {0}; |
jmr274 | 5:e1431272be79 | 1425 | oled.GetTextProperties(&textProperties); |
jmr274 | 5:e1431272be79 | 1426 | |
jmr274 | 5:e1431272be79 | 1427 | strcpy((char *) text,"Temp."); |
jmr274 | 5:e1431272be79 | 1428 | oled.Label((uint8_t *)text,5,40); |
jmr274 | 5:e1431272be79 | 1429 | strcpy((char *) text,"Humidity"); |
jmr274 | 5:e1431272be79 | 1430 | oled.Label((uint8_t *)text,5,57); |
jmr274 | 5:e1431272be79 | 1431 | strcpy((char *) text,"H.I."); |
jmr274 | 5:e1431272be79 | 1432 | oled.Label((uint8_t *)text,5,23); |
jmr274 | 5:e1431272be79 | 1433 | |
jmr274 | 5:e1431272be79 | 1434 | /* Set text properties to white and right aligned for the dynamic text */ |
jmr274 | 5:e1431272be79 | 1435 | textProperties.fontColor = COLOR_GREEN; |
jmr274 | 5:e1431272be79 | 1436 | textProperties.alignParam = OLED_TEXT_ALIGN_RIGHT; |
jmr274 | 5:e1431272be79 | 1437 | oled.SetTextProperties(&textProperties); |
jmr274 | 5:e1431272be79 | 1438 | |
jmr274 | 5:e1431272be79 | 1439 | /* Format the value */ |
jmr274 | 5:e1431272be79 | 1440 | sprintf(text,"%i",sample_ftemp); |
jmr274 | 5:e1431272be79 | 1441 | |
nbaker | 8:a5c77b45008d | 1442 | /* Display temp reading in 15px by 15px textbox at(x=55, y=40) */ |
jmr274 | 5:e1431272be79 | 1443 | oled.TextBox((uint8_t *)text,55,40,15,15); //Increase textbox for more digits |
jmr274 | 5:e1431272be79 | 1444 | |
jmr274 | 5:e1431272be79 | 1445 | /* Display Units */ |
jmr274 | 5:e1431272be79 | 1446 | strcpy((char *) text,"dF"); |
jmr274 | 5:e1431272be79 | 1447 | oled.Label((uint8_t *)text,71,40); |
jmr274 | 5:e1431272be79 | 1448 | |
jmr274 | 5:e1431272be79 | 1449 | /* Format the value */ |
jmr274 | 5:e1431272be79 | 1450 | sprintf(text,"%i",sample_humid); |
jmr274 | 5:e1431272be79 | 1451 | |
nbaker | 8:a5c77b45008d | 1452 | /* Display Hum reading in 15px by 15px textbox at(x=55, y=57) */ |
jmr274 | 5:e1431272be79 | 1453 | oled.TextBox((uint8_t *)text,55,57,15,15); //Increase textbox for more digits |
jmr274 | 5:e1431272be79 | 1454 | |
jmr274 | 5:e1431272be79 | 1455 | /* Display Units */ |
jmr274 | 5:e1431272be79 | 1456 | strcpy((char *) text,"%"); |
jmr274 | 5:e1431272be79 | 1457 | oled.Label((uint8_t *)text,71,57); |
jmr274 | 5:e1431272be79 | 1458 | |
jmr274 | 5:e1431272be79 | 1459 | /* Set text properties to white and right aligned for the dynamic text */ |
jmr274 | 5:e1431272be79 | 1460 | textProperties.fontColor = COLOR_BLUE; |
jmr274 | 5:e1431272be79 | 1461 | textProperties.alignParam = OLED_TEXT_ALIGN_RIGHT; |
jmr274 | 5:e1431272be79 | 1462 | oled.SetTextProperties(&textProperties); |
jmr274 | 5:e1431272be79 | 1463 | |
jmr274 | 5:e1431272be79 | 1464 | /* Format the value */ |
jmr274 | 5:e1431272be79 | 1465 | sprintf(text,"%i",heat_index); |
jmr274 | 5:e1431272be79 | 1466 | |
nbaker | 8:a5c77b45008d | 1467 | /* Display HI reading in 15px by 15px textbox at(x=55, y=23) */ |
jmr274 | 5:e1431272be79 | 1468 | oled.TextBox((uint8_t *)text,55,23,15,15); //Increase textbox for more digits |
jmr274 | 5:e1431272be79 | 1469 | |
jmr274 | 5:e1431272be79 | 1470 | /* Display Units */ |
jmr274 | 5:e1431272be79 | 1471 | strcpy((char *) text,"dF");oled.Label((uint8_t *)text,71,23); |
jmr274 | 5:e1431272be79 | 1472 | |
asong | 1:e4b38d6918ba | 1473 | break; |
asong | 1:e4b38d6918ba | 1474 | } |
asong | 1:e4b38d6918ba | 1475 | case 26: {//Heart Rate Config Option |
asong | 1:e4b38d6918ba | 1476 | oled.FillScreen(COLOR_BLACK); // Clear screen |
asong | 1:e4b38d6918ba | 1477 | oled.Label((uint8_t *)"HR Config",10,5); // Display at x,y |
asong | 1:e4b38d6918ba | 1478 | oled.Label((uint8_t *)"*",85,15); // "*" at x,y |
asong | 1:e4b38d6918ba | 1479 | oled.Label((uint8_t *)"*",85,60); // "*" at x,y |
asong | 1:e4b38d6918ba | 1480 | oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y |
asong | 1:e4b38d6918ba | 1481 | oled.Label((uint8_t *)"Enter",60,80); //Display "enter" at x,y |
asong | 1:e4b38d6918ba | 1482 | break; |
asong | 1:e4b38d6918ba | 1483 | } |
asong | 1:e4b38d6918ba | 1484 | case 27: { //Enter Age Screen |
asong | 1:e4b38d6918ba | 1485 | oled.FillScreen(COLOR_BLACK); |
asong | 1:e4b38d6918ba | 1486 | oled.Label((uint8_t *)"Input Age", 10, 5); |
asong | 1:e4b38d6918ba | 1487 | sprintf(display_buff, "%u", Age); //Convert int to char array for displaying user age |
asong | 1:e4b38d6918ba | 1488 | oled.Label((uint8_t *)"Age:", 10, 30); |
asong | 1:e4b38d6918ba | 1489 | oled.Label((uint8_t *)"+",85,15); // "*" at x,y |
asong | 1:e4b38d6918ba | 1490 | oled.Label((uint8_t *)"-",85,60); // "*" at x,y |
asong | 1:e4b38d6918ba | 1491 | oled.Label((uint8_t *)"Menu",10,80); // Display "Menu" at x,y |
asong | 1:e4b38d6918ba | 1492 | oled.Label((uint8_t *)"Next",60,80); //Display "Next" at x,y |
asong | 1:e4b38d6918ba | 1493 | textProperties.fontColor = COLOR_GREEN; |
asong | 1:e4b38d6918ba | 1494 | oled.SetTextProperties(&textProperties); |
asong | 1:e4b38d6918ba | 1495 | oled.Label((uint8_t *)display_buff,43,30); // Display at x,y |
asong | 1:e4b38d6918ba | 1496 | textProperties.fontColor = COLOR_WHITE; |
asong | 1:e4b38d6918ba | 1497 | oled.SetTextProperties(&textProperties); |
asong | 1:e4b38d6918ba | 1498 | oled.Label((uint8_t *)"Max bpm:",10,50); |
asong | 1:e4b38d6918ba | 1499 | textProperties.fontColor = COLOR_RED; |
asong | 1:e4b38d6918ba | 1500 | oled.SetTextProperties(&textProperties); //implements the color change |
asong | 2:824ed4ae8d52 | 1501 | sprintf(display_buff, "%u", Max_Bpm); //Convert int to char array for displaying user max bpm |
asong | 1:e4b38d6918ba | 1502 | oled.Label((uint8_t *)display_buff, 65, 50); |
asong | 1:e4b38d6918ba | 1503 | textProperties.fontColor = COLOR_WHITE; |
asong | 1:e4b38d6918ba | 1504 | oled.SetTextProperties(&textProperties); |
asong | 1:e4b38d6918ba | 1505 | break; |
asong | 1:e4b38d6918ba | 1506 | } |
asong | 1:e4b38d6918ba | 1507 | case 28: {//Choose Heart Rate Vibration Option |
asong | 1:e4b38d6918ba | 1508 | oled.FillScreen(COLOR_BLACK); |
asong | 1:e4b38d6918ba | 1509 | oled.Label((uint8_t *)"Vibrate Pref", 10, 10); |
asong | 1:e4b38d6918ba | 1510 | oled.Label((uint8_t *)"Option:", 10, 25); |
asong | 1:e4b38d6918ba | 1511 | oled.Label((uint8_t *)"+",85,15); // "+" at x,y |
asong | 1:e4b38d6918ba | 1512 | oled.Label((uint8_t *)"-",85,60); // "-" at x,y |
asong | 1:e4b38d6918ba | 1513 | oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y |
asong | 1:e4b38d6918ba | 1514 | oled.Label((uint8_t *)"Next",60,80); //Display "Next" at x,y |
asong | 1:e4b38d6918ba | 1515 | sprintf(display_buff, "%u", HR_Vibration); //Convert int to char array for displaying user preference |
asong | 1:e4b38d6918ba | 1516 | textProperties.fontColor = COLOR_GREEN; //Change font to green |
asong | 1:e4b38d6918ba | 1517 | oled.SetTextProperties(&textProperties);//Implement color change |
asong | 1:e4b38d6918ba | 1518 | oled.Label((uint8_t *)display_buff,55,25); // Display at x,y |
asong | 1:e4b38d6918ba | 1519 | if(HR_Vibration == 1) { |
asong | 1:e4b38d6918ba | 1520 | textProperties.fontColor = COLOR_RED; //Change font to red |
asong | 1:e4b38d6918ba | 1521 | oled.SetTextProperties(&textProperties); //Implement color change |
asong | 1:e4b38d6918ba | 1522 | oled.Label((uint8_t *)"All On",10,45); // Display at x,y |
asong | 1:e4b38d6918ba | 1523 | } else if(HR_Vibration == 2) { |
asong | 1:e4b38d6918ba | 1524 | textProperties.fontColor = COLOR_RED; //Change font to red |
asong | 1:e4b38d6918ba | 1525 | oled.SetTextProperties(&textProperties);//Implement color change |
asong | 1:e4b38d6918ba | 1526 | oled.Label((uint8_t *)"Only Entering",10,38);// Display at x,y |
asong | 1:e4b38d6918ba | 1527 | oled.Label((uint8_t *)"And Exiting",10,53);// Display at x,y |
asong | 1:e4b38d6918ba | 1528 | oled.Label((uint8_t *)"Target Zone",10,68);// Display at x,y |
nbaker | 0:d1d36a3da39b | 1529 | |
asong | 1:e4b38d6918ba | 1530 | } else if(HR_Vibration == 3) { |
asong | 1:e4b38d6918ba | 1531 | textProperties.fontColor = COLOR_RED; //Change font to red |
asong | 1:e4b38d6918ba | 1532 | oled.SetTextProperties(&textProperties); //Implement color change |
asong | 1:e4b38d6918ba | 1533 | oled.Label((uint8_t *)"All Off",10,45);// Display at x,y |
asong | 1:e4b38d6918ba | 1534 | } |
asong | 1:e4b38d6918ba | 1535 | textProperties.fontColor = COLOR_WHITE; |
asong | 1:e4b38d6918ba | 1536 | oled.SetTextProperties(&textProperties); |
asong | 1:e4b38d6918ba | 1537 | break; |
asong | 1:e4b38d6918ba | 1538 | } |
asong | 1:e4b38d6918ba | 1539 | case 29: { //Zone Boundary Info |
asong | 1:e4b38d6918ba | 1540 | oled.FillScreen(COLOR_BLACK); |
asong | 1:e4b38d6918ba | 1541 | oled.Label((uint8_t *)"HR Zone Info", 10, 5);// Display at x,y |
asong | 1:e4b38d6918ba | 1542 | textProperties.fontColor = COLOR_YELLOW; //Change font to yellow |
asong | 1:e4b38d6918ba | 1543 | oled.SetTextProperties(&textProperties);//Implement color change |
asong | 1:e4b38d6918ba | 1544 | oled.Label((uint8_t *)"Z1:", 10, 20);// Display at x,y |
asong | 1:e4b38d6918ba | 1545 | sprintf(display_buff, "%u", HR_Zone1[0]); // Convert int to char to display |
asong | 1:e4b38d6918ba | 1546 | oled.Label((uint8_t *)display_buff, 30, 20);// Display at x,y |
asong | 1:e4b38d6918ba | 1547 | oled.Label((uint8_t *)"-", 52, 20);// Display at x,y |
asong | 1:e4b38d6918ba | 1548 | sprintf(display_buff, "%u", HR_Zone1[1]); // Convert int to char to display |
asong | 1:e4b38d6918ba | 1549 | oled.Label((uint8_t *)display_buff, 60, 20);// Display at x,y |
asong | 1:e4b38d6918ba | 1550 | textProperties.fontColor = COLOR_BLUE; //Change font to blue |
asong | 1:e4b38d6918ba | 1551 | oled.SetTextProperties(&textProperties);//Implement color change |
asong | 1:e4b38d6918ba | 1552 | oled.Label((uint8_t *)"Z2:", 10, 35);// Display at x,y |
asong | 1:e4b38d6918ba | 1553 | sprintf(display_buff, "%u", HR_Zone2[0]); // Convert int to char to display |
asong | 1:e4b38d6918ba | 1554 | oled.Label((uint8_t *)display_buff, 30, 35);// Display at x,y |
asong | 1:e4b38d6918ba | 1555 | oled.Label((uint8_t *)"-", 52, 35);// Display at x,y |
asong | 1:e4b38d6918ba | 1556 | sprintf(display_buff, "%u", HR_Zone2[1]); // Convert int to char to display |
asong | 1:e4b38d6918ba | 1557 | oled.Label((uint8_t *)display_buff, 60, 35);// Display at x,y |
asong | 1:e4b38d6918ba | 1558 | textProperties.fontColor = COLOR_GREEN; //Change font to green |
asong | 1:e4b38d6918ba | 1559 | oled.SetTextProperties(&textProperties);//Implement color change |
asong | 1:e4b38d6918ba | 1560 | oled.Label((uint8_t *)"Z3:", 10, 50);// Display at x,y |
asong | 1:e4b38d6918ba | 1561 | sprintf(display_buff, "%u", HR_Zone3[0]); // Convert int to char to display |
asong | 1:e4b38d6918ba | 1562 | oled.Label((uint8_t *)display_buff, 30, 50);// Display at x,y |
asong | 1:e4b38d6918ba | 1563 | oled.Label((uint8_t *)"-", 52, 50);// Display at x,y |
asong | 1:e4b38d6918ba | 1564 | sprintf(display_buff, "%u", HR_Zone3[1]); // Convert int to char to display |
asong | 1:e4b38d6918ba | 1565 | oled.Label((uint8_t *)display_buff, 60, 50);// Display at x,y |
asong | 1:e4b38d6918ba | 1566 | textProperties.fontColor = COLOR_RED; //Change font to red |
asong | 1:e4b38d6918ba | 1567 | oled.SetTextProperties(&textProperties);//Implement color change |
asong | 1:e4b38d6918ba | 1568 | oled.Label((uint8_t *)"Z4:", 10, 65);// Display at x,y |
asong | 1:e4b38d6918ba | 1569 | sprintf(display_buff, "%u", HR_Zone4[0]); // Convert int to char to display |
asong | 1:e4b38d6918ba | 1570 | oled.Label((uint8_t *)display_buff, 30, 65);// Display at x,y |
asong | 1:e4b38d6918ba | 1571 | oled.Label((uint8_t *)"-", 52, 65);// Display at x,y |
asong | 1:e4b38d6918ba | 1572 | sprintf(display_buff, "%u", HR_Zone4[1]); // Convert int to char to display |
asong | 1:e4b38d6918ba | 1573 | oled.Label((uint8_t *)display_buff, 60, 65);// Display at x,y |
asong | 1:e4b38d6918ba | 1574 | textProperties.fontColor = COLOR_WHITE; //Change font to white |
asong | 1:e4b38d6918ba | 1575 | oled.SetTextProperties(&textProperties);//Implement color change |
asong | 1:e4b38d6918ba | 1576 | oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y |
asong | 1:e4b38d6918ba | 1577 | oled.Label((uint8_t *)"Next",60,80); //Display "Next" at x,y |
asong | 1:e4b38d6918ba | 1578 | break; |
asong | 2:824ed4ae8d52 | 1579 | } |
asong | 2:824ed4ae8d52 | 1580 | case 30: { //Enter Target Heart Rate Zone Preference |
asong | 1:e4b38d6918ba | 1581 | oled.FillScreen(COLOR_BLACK); |
asong | 1:e4b38d6918ba | 1582 | oled.Label((uint8_t *)"Zone Pref", 10, 5);// Display at x,y |
asong | 1:e4b38d6918ba | 1583 | oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y |
asong | 1:e4b38d6918ba | 1584 | oled.Label((uint8_t *)"Next",60,80); //Display "Next" at x,y |
asong | 1:e4b38d6918ba | 1585 | oled.Label((uint8_t *)"+",85,15); // "+" at x,y |
asong | 1:e4b38d6918ba | 1586 | oled.Label((uint8_t *)"-",85,60); // "-" at x,y |
asong | 1:e4b38d6918ba | 1587 | oled.Label((uint8_t *)"Target:", 10, 25);// Display at x,y |
asong | 1:e4b38d6918ba | 1588 | sprintf(display_buff, "%u", Target_Zone); // Convert int to char to display |
asong | 2:824ed4ae8d52 | 1589 | if(Target_Zone == 1) { |
asong | 1:e4b38d6918ba | 1590 | textProperties.fontColor = COLOR_YELLOW; //Change font to yellow |
asong | 1:e4b38d6918ba | 1591 | oled.SetTextProperties(&textProperties);//Implement color change |
asong | 2:824ed4ae8d52 | 1592 | } else if(Target_Zone == 2) { |
asong | 1:e4b38d6918ba | 1593 | textProperties.fontColor = COLOR_BLUE; //Change font to blue |
asong | 1:e4b38d6918ba | 1594 | oled.SetTextProperties(&textProperties);//Implement color change |
asong | 2:824ed4ae8d52 | 1595 | } else if(Target_Zone == 3) { |
asong | 1:e4b38d6918ba | 1596 | textProperties.fontColor = COLOR_GREEN; //Change font to green |
asong | 1:e4b38d6918ba | 1597 | oled.SetTextProperties(&textProperties);//Implement color change |
asong | 2:824ed4ae8d52 | 1598 | } else if(Target_Zone == 4) { |
asong | 1:e4b38d6918ba | 1599 | textProperties.fontColor = COLOR_RED; //Change font to red |
asong | 1:e4b38d6918ba | 1600 | oled.SetTextProperties(&textProperties);//Implement color change |
asong | 1:e4b38d6918ba | 1601 | } |
asong | 1:e4b38d6918ba | 1602 | oled.Label((uint8_t *)display_buff, 55, 25);// Display at x,y |
asong | 1:e4b38d6918ba | 1603 | textProperties.fontColor = COLOR_WHITE; //Change font to white |
asong | 1:e4b38d6918ba | 1604 | oled.SetTextProperties(&textProperties);//Implement color change |
asong | 1:e4b38d6918ba | 1605 | oled.Label((uint8_t *)"Bounds:", 10, 45);// Display at x,y |
asong | 2:824ed4ae8d52 | 1606 | if(Target_Zone == 1) { |
asong | 1:e4b38d6918ba | 1607 | textProperties.fontColor = COLOR_YELLOW; //Change font to yellow |
asong | 1:e4b38d6918ba | 1608 | oled.SetTextProperties(&textProperties);//Implement color change |
asong | 1:e4b38d6918ba | 1609 | sprintf(display_buff, "%u", HR_Zone1[0]); // Convert int to char to display |
asong | 1:e4b38d6918ba | 1610 | oled.Label((uint8_t *)display_buff, 10, 60);// Display at x,y |
asong | 1:e4b38d6918ba | 1611 | oled.Label((uint8_t *)"-", 32, 60);// Display at x,y |
asong | 1:e4b38d6918ba | 1612 | sprintf(display_buff, "%u", HR_Zone1[1]); // Convert int to char to display |
asong | 1:e4b38d6918ba | 1613 | oled.Label((uint8_t *)display_buff, 40, 60);// Display at x,y |
asong | 2:824ed4ae8d52 | 1614 | } else if(Target_Zone == 2) { |
asong | 1:e4b38d6918ba | 1615 | textProperties.fontColor = COLOR_BLUE; //Change font to blue |
asong | 1:e4b38d6918ba | 1616 | oled.SetTextProperties(&textProperties);//Implement color change |
asong | 1:e4b38d6918ba | 1617 | sprintf(display_buff, "%u", HR_Zone2[0]); // Convert int to char to display |
asong | 1:e4b38d6918ba | 1618 | oled.Label((uint8_t *)display_buff, 10, 60);// Display at x,y |
asong | 1:e4b38d6918ba | 1619 | oled.Label((uint8_t *)"-", 32, 60);// Display at x,y |
asong | 1:e4b38d6918ba | 1620 | sprintf(display_buff, "%u", HR_Zone2[1]); // Convert int to char to display |
asong | 1:e4b38d6918ba | 1621 | oled.Label((uint8_t *)display_buff, 40, 60);// Display at x,y |
asong | 2:824ed4ae8d52 | 1622 | } else if(Target_Zone == 3) { |
asong | 1:e4b38d6918ba | 1623 | textProperties.fontColor = COLOR_GREEN; //Change font to green |
asong | 1:e4b38d6918ba | 1624 | oled.SetTextProperties(&textProperties);//Implement color change |
asong | 1:e4b38d6918ba | 1625 | sprintf(display_buff, "%u", HR_Zone3[0]); // Convert int to char to display |
asong | 1:e4b38d6918ba | 1626 | oled.Label((uint8_t *)display_buff, 10, 60); // Display at x,y |
asong | 1:e4b38d6918ba | 1627 | oled.Label((uint8_t *)"-", 32, 60); // Display at x,y |
asong | 1:e4b38d6918ba | 1628 | sprintf(display_buff, "%u", HR_Zone3[1]); // Convert int to char to display |
asong | 1:e4b38d6918ba | 1629 | oled.Label((uint8_t *)display_buff, 40, 60);// Display at x,y |
asong | 2:824ed4ae8d52 | 1630 | } else if(Target_Zone == 4) { |
asong | 1:e4b38d6918ba | 1631 | textProperties.fontColor = COLOR_RED; //Change font to red |
asong | 1:e4b38d6918ba | 1632 | oled.SetTextProperties(&textProperties);//Implement color change |
asong | 1:e4b38d6918ba | 1633 | sprintf(display_buff, "%u", HR_Zone4[0]); // Convert int to char to display |
asong | 1:e4b38d6918ba | 1634 | oled.Label((uint8_t *)display_buff, 10, 60); // Display at x,y |
asong | 1:e4b38d6918ba | 1635 | oled.Label((uint8_t *)"-", 32, 60); // Display at x,y |
asong | 1:e4b38d6918ba | 1636 | sprintf(display_buff, "%u", HR_Zone4[1]); // Convert int to char to display |
asong | 1:e4b38d6918ba | 1637 | oled.Label((uint8_t *)display_buff, 40, 60); // Display at x,y |
asong | 1:e4b38d6918ba | 1638 | } |
asong | 1:e4b38d6918ba | 1639 | textProperties.fontColor = COLOR_WHITE; //Change font to white |
asong | 1:e4b38d6918ba | 1640 | oled.SetTextProperties(&textProperties);//Implement color change |
asong | 2:824ed4ae8d52 | 1641 | break; |
asong | 2:824ed4ae8d52 | 1642 | } |
asong | 2:824ed4ae8d52 | 1643 | case 31: { |
asong | 2:824ed4ae8d52 | 1644 | oled.FillScreen(COLOR_BLACK); |
asong | 2:824ed4ae8d52 | 1645 | Heart_Rate_Vibrations(); |
asong | 2:824ed4ae8d52 | 1646 | oled.Label((uint8_t *)"Enter HR", 10, 5);// Display at x,y |
asong | 2:824ed4ae8d52 | 1647 | oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y |
asong | 2:824ed4ae8d52 | 1648 | oled.Label((uint8_t *)"Next",60,80); //Display "Next" at x,y |
asong | 2:824ed4ae8d52 | 1649 | oled.Label((uint8_t *)"+",85,15); // "+" at x,y |
asong | 2:824ed4ae8d52 | 1650 | oled.Label((uint8_t *)"-",85,60); // "-" at x,y |
asong | 2:824ed4ae8d52 | 1651 | oled.Label((uint8_t *)"HR:", 10, 25); |
asong | 2:824ed4ae8d52 | 1652 | sprintf(display_buff, "%u", Heart_Rate); // Convert int to char to display |
asong | 2:824ed4ae8d52 | 1653 | textProperties.fontColor = COLOR_RED; //Change font to red |
asong | 2:824ed4ae8d52 | 1654 | oled.SetTextProperties(&textProperties);//Implement color change |
asong | 2:824ed4ae8d52 | 1655 | oled.Label((uint8_t *)display_buff, 40, 25); |
asong | 2:824ed4ae8d52 | 1656 | textProperties.fontColor = COLOR_WHITE; //Change font to white |
asong | 2:824ed4ae8d52 | 1657 | oled.SetTextProperties(&textProperties);//Implement color change |
asong | 2:824ed4ae8d52 | 1658 | oled.Label((uint8_t *)"Cur Zone:", 10, 45); |
asong | 2:824ed4ae8d52 | 1659 | if(Current_Zone == 1) { |
asong | 2:824ed4ae8d52 | 1660 | textProperties.fontColor = COLOR_YELLOW; |
asong | 2:824ed4ae8d52 | 1661 | oled.SetTextProperties(&textProperties); |
asong | 2:824ed4ae8d52 | 1662 | } else if(Current_Zone == 2) { |
asong | 2:824ed4ae8d52 | 1663 | textProperties.fontColor = COLOR_BLUE; |
asong | 2:824ed4ae8d52 | 1664 | oled.SetTextProperties(&textProperties); |
asong | 2:824ed4ae8d52 | 1665 | } else if(Current_Zone == 3) { |
asong | 2:824ed4ae8d52 | 1666 | textProperties.fontColor = COLOR_GREEN; |
asong | 2:824ed4ae8d52 | 1667 | oled.SetTextProperties(&textProperties); |
asong | 2:824ed4ae8d52 | 1668 | } else if(Current_Zone == 4) { |
asong | 2:824ed4ae8d52 | 1669 | textProperties.fontColor = COLOR_RED; |
asong | 2:824ed4ae8d52 | 1670 | oled.SetTextProperties(&textProperties); |
asong | 2:824ed4ae8d52 | 1671 | } |
asong | 2:824ed4ae8d52 | 1672 | sprintf(display_buff, "%u", Current_Zone); // Convert int to char to display |
asong | 2:824ed4ae8d52 | 1673 | oled.Label((uint8_t *)display_buff, 71, 45); |
asong | 2:824ed4ae8d52 | 1674 | textProperties.fontColor = COLOR_WHITE; //Change font to white |
asong | 2:824ed4ae8d52 | 1675 | oled.SetTextProperties(&textProperties);//Implement color change |
asong | 2:824ed4ae8d52 | 1676 | oled.Label((uint8_t *)"Prev Zone:", 10, 60); |
asong | 2:824ed4ae8d52 | 1677 | if(Prev_Zone == 1) { |
asong | 2:824ed4ae8d52 | 1678 | textProperties.fontColor = COLOR_YELLOW; |
asong | 2:824ed4ae8d52 | 1679 | oled.SetTextProperties(&textProperties); |
asong | 2:824ed4ae8d52 | 1680 | } else if(Prev_Zone == 2) { |
asong | 2:824ed4ae8d52 | 1681 | textProperties.fontColor = COLOR_BLUE; |
asong | 2:824ed4ae8d52 | 1682 | oled.SetTextProperties(&textProperties); |
asong | 2:824ed4ae8d52 | 1683 | } else if(Prev_Zone == 3) { |
asong | 2:824ed4ae8d52 | 1684 | textProperties.fontColor = COLOR_GREEN; |
asong | 2:824ed4ae8d52 | 1685 | oled.SetTextProperties(&textProperties); |
asong | 2:824ed4ae8d52 | 1686 | } else if(Prev_Zone == 4) { |
asong | 2:824ed4ae8d52 | 1687 | textProperties.fontColor = COLOR_RED; |
asong | 2:824ed4ae8d52 | 1688 | oled.SetTextProperties(&textProperties); |
asong | 2:824ed4ae8d52 | 1689 | } |
asong | 2:824ed4ae8d52 | 1690 | sprintf(display_buff, "%u", Prev_Zone); // Convert int to char to display |
asong | 2:824ed4ae8d52 | 1691 | oled.Label((uint8_t *)display_buff, 71, 60); |
asong | 2:824ed4ae8d52 | 1692 | textProperties.fontColor = COLOR_WHITE; //Change font to white |
asong | 2:824ed4ae8d52 | 1693 | oled.SetTextProperties(&textProperties);//Implement color change |
asong | 2:824ed4ae8d52 | 1694 | Led_Zone_Indicator(); |
asong | 2:824ed4ae8d52 | 1695 | break; |
asong | 2:824ed4ae8d52 | 1696 | } |
asong | 2:824ed4ae8d52 | 1697 | case 32: { |
asong | 2:824ed4ae8d52 | 1698 | //Zone Boundary Info |
asong | 2:824ed4ae8d52 | 1699 | oled.FillScreen(COLOR_BLACK); |
asong | 2:824ed4ae8d52 | 1700 | oled.Label((uint8_t *)"HR Zone Info", 10, 5);// Display at x,y |
asong | 2:824ed4ae8d52 | 1701 | textProperties.fontColor = COLOR_YELLOW; //Change font to yellow |
asong | 2:824ed4ae8d52 | 1702 | oled.SetTextProperties(&textProperties);//Implement color change |
asong | 2:824ed4ae8d52 | 1703 | oled.Label((uint8_t *)"Z1:", 10, 20);// Display at x,y |
asong | 2:824ed4ae8d52 | 1704 | sprintf(display_buff, "%u", HR_Zone1[0]); // Convert int to char to display |
asong | 2:824ed4ae8d52 | 1705 | oled.Label((uint8_t *)display_buff, 30, 20);// Display at x,y |
asong | 2:824ed4ae8d52 | 1706 | oled.Label((uint8_t *)"-", 52, 20);// Display at x,y |
asong | 2:824ed4ae8d52 | 1707 | sprintf(display_buff, "%u", HR_Zone1[1]); // Convert int to char to display |
asong | 2:824ed4ae8d52 | 1708 | oled.Label((uint8_t *)display_buff, 60, 20);// Display at x,y |
asong | 2:824ed4ae8d52 | 1709 | textProperties.fontColor = COLOR_BLUE; //Change font to blue |
asong | 2:824ed4ae8d52 | 1710 | oled.SetTextProperties(&textProperties);//Implement color change |
asong | 2:824ed4ae8d52 | 1711 | oled.Label((uint8_t *)"Z2:", 10, 35);// Display at x,y |
asong | 2:824ed4ae8d52 | 1712 | sprintf(display_buff, "%u", HR_Zone2[0]); // Convert int to char to display |
asong | 2:824ed4ae8d52 | 1713 | oled.Label((uint8_t *)display_buff, 30, 35);// Display at x,y |
asong | 2:824ed4ae8d52 | 1714 | oled.Label((uint8_t *)"-", 52, 35);// Display at x,y |
asong | 2:824ed4ae8d52 | 1715 | sprintf(display_buff, "%u", HR_Zone2[1]); // Convert int to char to display |
asong | 2:824ed4ae8d52 | 1716 | oled.Label((uint8_t *)display_buff, 60, 35);// Display at x,y |
asong | 2:824ed4ae8d52 | 1717 | textProperties.fontColor = COLOR_GREEN; //Change font to green |
asong | 2:824ed4ae8d52 | 1718 | oled.SetTextProperties(&textProperties);//Implement color change |
asong | 2:824ed4ae8d52 | 1719 | oled.Label((uint8_t *)"Z3:", 10, 50);// Display at x,y |
asong | 2:824ed4ae8d52 | 1720 | sprintf(display_buff, "%u", HR_Zone3[0]); // Convert int to char to display |
asong | 2:824ed4ae8d52 | 1721 | oled.Label((uint8_t *)display_buff, 30, 50);// Display at x,y |
asong | 2:824ed4ae8d52 | 1722 | oled.Label((uint8_t *)"-", 52, 50);// Display at x,y |
asong | 2:824ed4ae8d52 | 1723 | sprintf(display_buff, "%u", HR_Zone3[1]); // Convert int to char to display |
asong | 2:824ed4ae8d52 | 1724 | oled.Label((uint8_t *)display_buff, 60, 50);// Display at x,y |
asong | 2:824ed4ae8d52 | 1725 | textProperties.fontColor = COLOR_RED; //Change font to red |
asong | 2:824ed4ae8d52 | 1726 | oled.SetTextProperties(&textProperties);//Implement color change |
asong | 2:824ed4ae8d52 | 1727 | oled.Label((uint8_t *)"Z4:", 10, 65);// Display at x,y |
asong | 2:824ed4ae8d52 | 1728 | sprintf(display_buff, "%u", HR_Zone4[0]); // Convert int to char to display |
asong | 2:824ed4ae8d52 | 1729 | oled.Label((uint8_t *)display_buff, 30, 65);// Display at x,y |
asong | 2:824ed4ae8d52 | 1730 | oled.Label((uint8_t *)"-", 52, 65);// Display at x,y |
asong | 2:824ed4ae8d52 | 1731 | sprintf(display_buff, "%u", HR_Zone4[1]); // Convert int to char to display |
asong | 2:824ed4ae8d52 | 1732 | oled.Label((uint8_t *)display_buff, 60, 65);// Display at x,y |
asong | 2:824ed4ae8d52 | 1733 | textProperties.fontColor = COLOR_WHITE; //Change font to white |
asong | 2:824ed4ae8d52 | 1734 | oled.SetTextProperties(&textProperties);//Implement color change |
asong | 2:824ed4ae8d52 | 1735 | oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y |
asong | 2:824ed4ae8d52 | 1736 | oled.Label((uint8_t *)"Next",60,80); //Display "Next" at x,y |
asong | 2:824ed4ae8d52 | 1737 | break; |
nbaker | 8:a5c77b45008d | 1738 | } |
nbaker | 8:a5c77b45008d | 1739 | case 41: { //Fall mode |
nbaker | 8:a5c77b45008d | 1740 | oled.FillScreen(COLOR_BLACK); |
nbaker | 8:a5c77b45008d | 1741 | oled.Label((uint8_t *)"Adj Fall Mode", 10, 5); |
nbaker | 8:a5c77b45008d | 1742 | sprintf(display_buff, "%u", Fall_Alert_Mode); //Convert int to char array for displaying mode |
nbaker | 8:a5c77b45008d | 1743 | oled.Label((uint8_t *)"Mode:", 5, 30); |
nbaker | 8:a5c77b45008d | 1744 | oled.Label((uint8_t *)"+",85,15); // "*" at x,y |
nbaker | 8:a5c77b45008d | 1745 | oled.Label((uint8_t *)"-",85,60); // "*" at x,y |
nbaker | 8:a5c77b45008d | 1746 | oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y |
nbaker | 8:a5c77b45008d | 1747 | oled.Label((uint8_t *)"Next",60,80); //Display "Next" at x,y |
nbaker | 8:a5c77b45008d | 1748 | textProperties.fontColor = COLOR_GREEN; |
nbaker | 8:a5c77b45008d | 1749 | oled.SetTextProperties(&textProperties); |
nbaker | 8:a5c77b45008d | 1750 | oled.Label((uint8_t *)display_buff,43,30); // Display at x,y |
nbaker | 8:a5c77b45008d | 1751 | textProperties.fontColor = COLOR_WHITE; |
nbaker | 8:a5c77b45008d | 1752 | oled.SetTextProperties(&textProperties); |
nbaker | 8:a5c77b45008d | 1753 | break; |
nbaker | 8:a5c77b45008d | 1754 | } |
nbaker | 8:a5c77b45008d | 1755 | case 42: { //Fall Thresh |
nbaker | 8:a5c77b45008d | 1756 | oled.FillScreen(COLOR_BLACK); |
nbaker | 8:a5c77b45008d | 1757 | oled.Label((uint8_t *)"Adj F-Th", 10, 5); |
nbaker | 8:a5c77b45008d | 1758 | sprintf(display_buff, "%2.2f g", Fall_Thresh); //Convert int to char array for displaying mode |
nbaker | 8:a5c77b45008d | 1759 | oled.Label((uint8_t *)"F_Th:", 5, 30); |
nbaker | 8:a5c77b45008d | 1760 | oled.Label((uint8_t *)"+",85,15); // "*" at x,y |
nbaker | 8:a5c77b45008d | 1761 | oled.Label((uint8_t *)"-",85,60); // "*" at x,y |
nbaker | 8:a5c77b45008d | 1762 | oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y |
nbaker | 8:a5c77b45008d | 1763 | oled.Label((uint8_t *)"Next",60,80); //Display "Next" at x,y |
nbaker | 8:a5c77b45008d | 1764 | textProperties.fontColor = COLOR_GREEN; |
nbaker | 8:a5c77b45008d | 1765 | oled.SetTextProperties(&textProperties); |
nbaker | 8:a5c77b45008d | 1766 | oled.Label((uint8_t *)display_buff,43,30); // Display at x,y |
nbaker | 8:a5c77b45008d | 1767 | textProperties.fontColor = COLOR_WHITE; |
nbaker | 8:a5c77b45008d | 1768 | oled.SetTextProperties(&textProperties); |
nbaker | 8:a5c77b45008d | 1769 | break; |
nbaker | 8:a5c77b45008d | 1770 | } |
nbaker | 8:a5c77b45008d | 1771 | case 43: { //Impact Thresh |
nbaker | 8:a5c77b45008d | 1772 | oled.FillScreen(COLOR_BLACK); |
nbaker | 8:a5c77b45008d | 1773 | oled.Label((uint8_t *)"Adj I-Th", 10, 5); |
nbaker | 8:a5c77b45008d | 1774 | sprintf(display_buff, "%2.2f g", Impact_Thresh); //Convert int to char array for displaying mode |
nbaker | 8:a5c77b45008d | 1775 | oled.Label((uint8_t *)"I_Th:", 5, 30); |
nbaker | 8:a5c77b45008d | 1776 | oled.Label((uint8_t *)"+",85,15); // "*" at x,y |
nbaker | 8:a5c77b45008d | 1777 | oled.Label((uint8_t *)"-",85,60); // "*" at x,y |
nbaker | 8:a5c77b45008d | 1778 | oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y |
nbaker | 8:a5c77b45008d | 1779 | oled.Label((uint8_t *)"Next",60,80); //Display "Next" at x,y |
nbaker | 8:a5c77b45008d | 1780 | textProperties.fontColor = COLOR_GREEN; |
nbaker | 8:a5c77b45008d | 1781 | oled.SetTextProperties(&textProperties); |
nbaker | 8:a5c77b45008d | 1782 | oled.Label((uint8_t *)display_buff,43,30); // Display at x,y |
nbaker | 8:a5c77b45008d | 1783 | textProperties.fontColor = COLOR_WHITE; |
nbaker | 8:a5c77b45008d | 1784 | oled.SetTextProperties(&textProperties); |
nbaker | 8:a5c77b45008d | 1785 | break; |
nbaker | 8:a5c77b45008d | 1786 | } |
nbaker | 8:a5c77b45008d | 1787 | case 44: { //Motion Thresh |
nbaker | 8:a5c77b45008d | 1788 | oled.FillScreen(COLOR_BLACK); |
nbaker | 8:a5c77b45008d | 1789 | oled.Label((uint8_t *)"Adj M-Th", 10, 5); |
nbaker | 8:a5c77b45008d | 1790 | sprintf(display_buff, "%4.0f D/S", Movement_Thresh); //Convert int to char array for displaying mode |
nbaker | 8:a5c77b45008d | 1791 | oled.Label((uint8_t *)"M_Th:", 5, 30); |
nbaker | 8:a5c77b45008d | 1792 | oled.Label((uint8_t *)"+",85,15); // "*" at x,y |
nbaker | 8:a5c77b45008d | 1793 | oled.Label((uint8_t *)"-",85,60); // "*" at x,y |
nbaker | 8:a5c77b45008d | 1794 | oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y |
nbaker | 8:a5c77b45008d | 1795 | // oled.Label((uint8_t *)"Next",60,80); //Display "Next" at x,y |
nbaker | 8:a5c77b45008d | 1796 | textProperties.fontColor = COLOR_GREEN; |
nbaker | 8:a5c77b45008d | 1797 | oled.SetTextProperties(&textProperties); |
nbaker | 8:a5c77b45008d | 1798 | oled.Label((uint8_t *)display_buff,43,30); // Display at x,y |
nbaker | 8:a5c77b45008d | 1799 | textProperties.fontColor = COLOR_WHITE; |
nbaker | 8:a5c77b45008d | 1800 | oled.SetTextProperties(&textProperties); |
nbaker | 8:a5c77b45008d | 1801 | break; |
asong | 1:e4b38d6918ba | 1802 | } |
nbaker | 0:d1d36a3da39b | 1803 | #endif // end of non-production/debug version code |
nbaker | 8:a5c77b45008d | 1804 | |
nbaker | 8:a5c77b45008d | 1805 | case 71: {// BLE |
nbaker | 8:a5c77b45008d | 1806 | oled.FillScreen(COLOR_BLACK); // Clear screen |
nbaker | 8:a5c77b45008d | 1807 | oled.Label((uint8_t *)"BLUETOOTH",5,5); // Display at x,y |
nbaker | 8:a5c77b45008d | 1808 | oled.Label((uint8_t *)" Enter ",59,80); //Display at x,y |
nbaker | 8:a5c77b45008d | 1809 | textProperties.fontColor = COLOR_WHITE; |
nbaker | 8:a5c77b45008d | 1810 | oled.SetTextProperties(&textProperties); |
nbaker | 8:a5c77b45008d | 1811 | oled.Label((uint8_t *)"*",85,15); // "*" at x,y |
nbaker | 8:a5c77b45008d | 1812 | oled.Label((uint8_t *)"*",85,60); // "*" at x,y |
nbaker | 8:a5c77b45008d | 1813 | oled.Label((uint8_t *)" Back ",9,80); // Display "Back" at x,y |
nbaker | 8:a5c77b45008d | 1814 | break; |
nbaker | 8:a5c77b45008d | 1815 | } |
nbaker | 8:a5c77b45008d | 1816 | |
nbaker | 8:a5c77b45008d | 1817 | case 72: {// BlueTooth on/off |
nbaker | 8:a5c77b45008d | 1818 | oled.FillScreen(COLOR_BLACK); // Clear screen |
nbaker | 8:a5c77b45008d | 1819 | oled.Label((uint8_t *)"BLUETOOTH",5,5); // Display at x,y |
nbaker | 8:a5c77b45008d | 1820 | if (BLE_On == 1) { |
nbaker | 8:a5c77b45008d | 1821 | strcpy((char *) text,"PAIR CODE"); |
nbaker | 8:a5c77b45008d | 1822 | oled.TextBox((uint8_t *)text,5,25,85,18); |
nbaker | 8:a5c77b45008d | 1823 | /* Display Bond Pass Key in a 85px by 18px textbox at x=5,y=25 */ |
nbaker | 8:a5c77b45008d | 1824 | |
nbaker | 8:a5c77b45008d | 1825 | /* This part was not compiling |
nbaker | 8:a5c77b45008d | 1826 | sprintf(text,"%d", kw40z_device.GetPassKey()); |
nbaker | 8:a5c77b45008d | 1827 | oled.TextBox((uint8_t *)text,0,40,95,18); |
nbaker | 8:a5c77b45008d | 1828 | */ |
nbaker | 8:a5c77b45008d | 1829 | oled.TextBox((uint8_t *)"Passkey",5,40,85,18); //show passkey in a 85px by 18px text box at x=5, y=40 |
nbaker | 8:a5c77b45008d | 1830 | } else { |
nbaker | 8:a5c77b45008d | 1831 | oled.Label((uint8_t *)" Off ",40,40); |
nbaker | 8:a5c77b45008d | 1832 | } |
nbaker | 8:a5c77b45008d | 1833 | // oled.Label((uint8_t *)"*",85,15); // "*" at x,y |
nbaker | 8:a5c77b45008d | 1834 | // oled.Label((uint8_t *)"*",85,60); // "*" at x,y |
nbaker | 8:a5c77b45008d | 1835 | oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y |
nbaker | 8:a5c77b45008d | 1836 | oled.Label((uint8_t *)"Toggle",60,80); //Display "Toggle" at x,y |
nbaker | 8:a5c77b45008d | 1837 | break; |
nbaker | 8:a5c77b45008d | 1838 | } |
nbaker | 8:a5c77b45008d | 1839 | |
nbaker | 8:a5c77b45008d | 1840 | |
asong | 1:e4b38d6918ba | 1841 | default: { |
asong | 2:824ed4ae8d52 | 1842 | Error_Num=1; |
asong | 2:824ed4ae8d52 | 1843 | error_screen(); // Clear screen |
asong | 2:824ed4ae8d52 | 1844 | break; |
asong | 2:824ed4ae8d52 | 1845 | } |
nbaker | 8:a5c77b45008d | 1846 | }//end of switch |
nbaker | 8:a5c77b45008d | 1847 | __enable_irq(); // Enable all Interrupts |
nbaker | 8:a5c77b45008d | 1848 | }// end upday_display() |
nbaker | 8:a5c77b45008d | 1849 | |
asong | 1:e4b38d6918ba | 1850 | void error_screen(void) |
asong | 1:e4b38d6918ba | 1851 | { |
asong | 1:e4b38d6918ba | 1852 | oled.FillScreen(COLOR_RED); // Clear screen |
asong | 1:e4b38d6918ba | 1853 | oled.Label((uint8_t *)"Error! ",30,30); // Display error at x,y |
asong | 1:e4b38d6918ba | 1854 | sprintf(text_1," %i ",Error_Num); |
asong | 1:e4b38d6918ba | 1855 | oled.Label((uint8_t *)text_1,30,60); // Display error at x,y |
asong | 1:e4b38d6918ba | 1856 | wait(3); // wait 3 seconds |
asong | 1:e4b38d6918ba | 1857 | oled.FillScreen(COLOR_BLACK); // Clear screen |
nbaker | 0:d1d36a3da39b | 1858 | } |
asong | 2:824ed4ae8d52 | 1859 | |
asong | 2:824ed4ae8d52 | 1860 | /***************************************************************************** |
asong | 2:824ed4ae8d52 | 1861 | Name: StartHaptic |
asong | 2:824ed4ae8d52 | 1862 | Purpose: Cause the HexiHeart device to vibrate for a predetermined amount of |
asong | 2:824ed4ae8d52 | 1863 | time |
asong | 2:824ed4ae8d52 | 1864 | Inputs: None |
asong | 2:824ed4ae8d52 | 1865 | Returns: None |
asong | 2:824ed4ae8d52 | 1866 | ******************************************************************************/ |
nbaker | 0:d1d36a3da39b | 1867 | void StartHaptic(void) |
nbaker | 0:d1d36a3da39b | 1868 | { |
nbaker | 8:a5c77b45008d | 1869 | hapticTimer.start(30); // was originaly 50, then 30 |
nbaker | 8:a5c77b45008d | 1870 | /* this 30 value seems to not work after Neil added a global |
nbaker | 8:a5c77b45008d | 1871 | __disable_irq() and __enable_irq() for the update_display() functions on 2/18/18 |
nbaker | 8:a5c77b45008d | 1872 | */ |
nbaker | 0:d1d36a3da39b | 1873 | haptic = 1; |
nbaker | 0:d1d36a3da39b | 1874 | } |
nbaker | 0:d1d36a3da39b | 1875 | |
asong | 2:824ed4ae8d52 | 1876 | /***************************************************************************** |
asong | 2:824ed4ae8d52 | 1877 | Name: StartHaptic |
asong | 2:824ed4ae8d52 | 1878 | Purpose: Cause the HexiHeart device to vibrate for x amount of time |
asong | 2:824ed4ae8d52 | 1879 | Inputs: An int representing the duration of the vibration |
asong | 2:824ed4ae8d52 | 1880 | Returns: None |
asong | 2:824ed4ae8d52 | 1881 | ******************************************************************************/ |
nbaker | 8:a5c77b45008d | 1882 | |
asong | 1:e4b38d6918ba | 1883 | void StartHaptic(int x) |
nbaker | 8:a5c77b45008d | 1884 | { |
asong | 1:e4b38d6918ba | 1885 | hapticTimer.start(x); |
asong | 2:824ed4ae8d52 | 1886 | haptic = 1; |
asong | 1:e4b38d6918ba | 1887 | } |
asong | 1:e4b38d6918ba | 1888 | |
asong | 1:e4b38d6918ba | 1889 | void StopHaptic(void const *n) |
asong | 1:e4b38d6918ba | 1890 | { |
nbaker | 0:d1d36a3da39b | 1891 | haptic = 0; |
nbaker | 0:d1d36a3da39b | 1892 | hapticTimer.stop(); |
nbaker | 0:d1d36a3da39b | 1893 | } |
asong | 2:824ed4ae8d52 | 1894 | |
asong | 2:824ed4ae8d52 | 1895 | /***************************************************************************** |
asong | 2:824ed4ae8d52 | 1896 | Name: Increment_Age |
asong | 2:824ed4ae8d52 | 1897 | Purpose: Increment the user's age by 1 |
asong | 2:824ed4ae8d52 | 1898 | Inputs: None |
asong | 2:824ed4ae8d52 | 1899 | Returns: None |
asong | 2:824ed4ae8d52 | 1900 | ******************************************************************************/ |
asong | 2:824ed4ae8d52 | 1901 | void Increment_Age() |
asong | 2:824ed4ae8d52 | 1902 | { |
asong | 2:824ed4ae8d52 | 1903 | StartHaptic(); |
asong | 2:824ed4ae8d52 | 1904 | if(Age < 100) { |
asong | 2:824ed4ae8d52 | 1905 | Age += 1; |
asong | 2:824ed4ae8d52 | 1906 | Screen_Num = 27; |
asong | 2:824ed4ae8d52 | 1907 | } else { |
asong | 2:824ed4ae8d52 | 1908 | Age = 1; |
asong | 2:824ed4ae8d52 | 1909 | } |
asong | 2:824ed4ae8d52 | 1910 | } |
asong | 2:824ed4ae8d52 | 1911 | |
asong | 2:824ed4ae8d52 | 1912 | /***************************************************************************** |
asong | 2:824ed4ae8d52 | 1913 | Name: Decrement_Age |
asong | 2:824ed4ae8d52 | 1914 | Purpose: Decrement the user's age by 1 |
asong | 2:824ed4ae8d52 | 1915 | Inputs: None |
asong | 2:824ed4ae8d52 | 1916 | Returns: None |
asong | 2:824ed4ae8d52 | 1917 | ******************************************************************************/ |
asong | 2:824ed4ae8d52 | 1918 | void Decrement_Age() |
asong | 2:824ed4ae8d52 | 1919 | { |
asong | 2:824ed4ae8d52 | 1920 | StartHaptic(); |
asong | 2:824ed4ae8d52 | 1921 | if(Age == 1) { |
asong | 2:824ed4ae8d52 | 1922 | Age = 100; |
asong | 2:824ed4ae8d52 | 1923 | } else { |
asong | 2:824ed4ae8d52 | 1924 | Age -= 1; |
asong | 2:824ed4ae8d52 | 1925 | Screen_Num = 27; |
asong | 2:824ed4ae8d52 | 1926 | } |
asong | 2:824ed4ae8d52 | 1927 | } |
asong | 2:824ed4ae8d52 | 1928 | |
asong | 2:824ed4ae8d52 | 1929 | /***************************************************************************** |
asong | 2:824ed4ae8d52 | 1930 | Name: Set_Max_Bpm |
asong | 2:824ed4ae8d52 | 1931 | Purpose: Calculates the user's maximum heart rate based on their age |
asong | 2:824ed4ae8d52 | 1932 | Inputs: None |
asong | 2:824ed4ae8d52 | 1933 | Returns: None |
asong | 2:824ed4ae8d52 | 1934 | ******************************************************************************/ |
asong | 2:824ed4ae8d52 | 1935 | void Set_Max_Bpm() |
asong | 2:824ed4ae8d52 | 1936 | { |
asong | 2:824ed4ae8d52 | 1937 | Max_Bpm = 220 - Age; |
asong | 2:824ed4ae8d52 | 1938 | } |
asong | 2:824ed4ae8d52 | 1939 | |
asong | 2:824ed4ae8d52 | 1940 | /***************************************************************************** |
asong | 2:824ed4ae8d52 | 1941 | Name: Set_Zone_Boundaries |
asong | 2:824ed4ae8d52 | 1942 | Purpose: Calculates the user's heart rate zones' boundaries based on the user's |
asong | 2:824ed4ae8d52 | 1943 | maximum heart rate |
asong | 2:824ed4ae8d52 | 1944 | Inputs: None |
asong | 2:824ed4ae8d52 | 1945 | Returns: None |
asong | 2:824ed4ae8d52 | 1946 | ******************************************************************************/ |
asong | 2:824ed4ae8d52 | 1947 | void Set_Zone_Boundaries() |
asong | 2:824ed4ae8d52 | 1948 | { |
asong | 2:824ed4ae8d52 | 1949 | Set_Max_Bpm(); |
asong | 2:824ed4ae8d52 | 1950 | HR_Zone1[0] = Max_Bpm * .50; //Set Heart Rate Zone 1 |
asong | 2:824ed4ae8d52 | 1951 | HR_Zone1[1] = Max_Bpm * .60; //Set Heart Rate Zone 1 |
asong | 2:824ed4ae8d52 | 1952 | HR_Zone2[0] = HR_Zone1[1] + 1; //Set Heart Rate Zone 2 |
asong | 2:824ed4ae8d52 | 1953 | HR_Zone2[1] = Max_Bpm * .70; //Set Heart Rate Zone 2 |
asong | 2:824ed4ae8d52 | 1954 | HR_Zone3[0] = HR_Zone2[1] + 1; //Set Heart Rate Zone 3 |
asong | 2:824ed4ae8d52 | 1955 | HR_Zone3[1] = Max_Bpm * .80; //Set Heart Rate Zone 3 |
asong | 2:824ed4ae8d52 | 1956 | HR_Zone4[0] = HR_Zone3[1] + 1; //Set Heart Rate Zone 4 |
asong | 2:824ed4ae8d52 | 1957 | HR_Zone4[1] = Max_Bpm; //Set Heart Rate Zone 4 |
asong | 2:824ed4ae8d52 | 1958 | } |
asong | 2:824ed4ae8d52 | 1959 | |
asong | 2:824ed4ae8d52 | 1960 | /***************************************************************************** |
asong | 2:824ed4ae8d52 | 1961 | Name: Increment_Target_Zone |
asong | 2:824ed4ae8d52 | 1962 | Purpose: Imcrements the user's target heart rate zone preference by 1 |
asong | 2:824ed4ae8d52 | 1963 | Inputs: None |
asong | 2:824ed4ae8d52 | 1964 | Returns: None |
asong | 2:824ed4ae8d52 | 1965 | ******************************************************************************/ |
asong | 2:824ed4ae8d52 | 1966 | void Increment_Target_Zone() |
asong | 2:824ed4ae8d52 | 1967 | { |
asong | 2:824ed4ae8d52 | 1968 | StartHaptic(); |
asong | 2:824ed4ae8d52 | 1969 | if(Target_Zone == 4) { |
asong | 2:824ed4ae8d52 | 1970 | Target_Zone = 1; |
asong | 2:824ed4ae8d52 | 1971 | } else { |
asong | 2:824ed4ae8d52 | 1972 | Target_Zone += 1; |
asong | 2:824ed4ae8d52 | 1973 | } |
asong | 2:824ed4ae8d52 | 1974 | } |
asong | 2:824ed4ae8d52 | 1975 | |
asong | 2:824ed4ae8d52 | 1976 | /***************************************************************************** |
asong | 2:824ed4ae8d52 | 1977 | Name: Decrement_Target_Zone |
asong | 2:824ed4ae8d52 | 1978 | Purpose: Decrements the user's target heart rate zone preference by 1 |
asong | 2:824ed4ae8d52 | 1979 | Inputs: None |
asong | 2:824ed4ae8d52 | 1980 | Returns: None |
asong | 2:824ed4ae8d52 | 1981 | ******************************************************************************/ |
asong | 2:824ed4ae8d52 | 1982 | void Decrement_Target_Zone() |
asong | 2:824ed4ae8d52 | 1983 | { |
asong | 2:824ed4ae8d52 | 1984 | StartHaptic(); |
asong | 2:824ed4ae8d52 | 1985 | if(Target_Zone == 1) { |
asong | 2:824ed4ae8d52 | 1986 | Target_Zone = 4; |
asong | 2:824ed4ae8d52 | 1987 | } else { |
asong | 2:824ed4ae8d52 | 1988 | Target_Zone -= 1; |
asong | 2:824ed4ae8d52 | 1989 | } |
asong | 2:824ed4ae8d52 | 1990 | } |
asong | 2:824ed4ae8d52 | 1991 | |
asong | 2:824ed4ae8d52 | 1992 | /***************************************************************************** |
asong | 2:824ed4ae8d52 | 1993 | Name: Increment_HR_Vibr_Pref |
asong | 2:824ed4ae8d52 | 1994 | Purpose: Increment the user's heart rate vibration preference by 1 |
asong | 2:824ed4ae8d52 | 1995 | Inputs: None |
asong | 2:824ed4ae8d52 | 1996 | Returns: None |
asong | 2:824ed4ae8d52 | 1997 | ******************************************************************************/ |
asong | 2:824ed4ae8d52 | 1998 | void Increment_HR_Vibr_Pref() |
asong | 2:824ed4ae8d52 | 1999 | { |
asong | 2:824ed4ae8d52 | 2000 | StartHaptic(); |
asong | 2:824ed4ae8d52 | 2001 | if(HR_Vibration == 3) { |
asong | 2:824ed4ae8d52 | 2002 | HR_Vibration = 1; |
asong | 2:824ed4ae8d52 | 2003 | } else { |
asong | 2:824ed4ae8d52 | 2004 | HR_Vibration += 1; |
asong | 2:824ed4ae8d52 | 2005 | } |
asong | 2:824ed4ae8d52 | 2006 | } |
asong | 2:824ed4ae8d52 | 2007 | |
asong | 2:824ed4ae8d52 | 2008 | /***************************************************************************** |
asong | 2:824ed4ae8d52 | 2009 | Name: Decrement_HR_Vibr_Pref |
asong | 2:824ed4ae8d52 | 2010 | Purpose: Decrement the user's heart rate vibration preference by 1 |
asong | 2:824ed4ae8d52 | 2011 | Inputs: None |
asong | 2:824ed4ae8d52 | 2012 | Returns: None |
asong | 2:824ed4ae8d52 | 2013 | ******************************************************************************/ |
asong | 2:824ed4ae8d52 | 2014 | void Decrement_HR_Vibr_Pref() |
asong | 2:824ed4ae8d52 | 2015 | { |
asong | 2:824ed4ae8d52 | 2016 | StartHaptic(); |
asong | 2:824ed4ae8d52 | 2017 | if(HR_Vibration == 1) { |
asong | 2:824ed4ae8d52 | 2018 | HR_Vibration = 3; |
asong | 2:824ed4ae8d52 | 2019 | } else { |
asong | 2:824ed4ae8d52 | 2020 | HR_Vibration -= 1; |
asong | 2:824ed4ae8d52 | 2021 | } |
asong | 2:824ed4ae8d52 | 2022 | } |
asong | 2:824ed4ae8d52 | 2023 | |
asong | 2:824ed4ae8d52 | 2024 | /***************************************************************************** |
asong | 2:824ed4ae8d52 | 2025 | Name: Enable_Heart_Rate |
asong | 2:824ed4ae8d52 | 2026 | Purpose: Turn on the HexiHeart heart rate function |
asong | 2:824ed4ae8d52 | 2027 | Inputs: None |
asong | 2:824ed4ae8d52 | 2028 | Returns: None |
asong | 2:824ed4ae8d52 | 2029 | ******************************************************************************/ |
asong | 2:824ed4ae8d52 | 2030 | void Enable_Heart_Rate() |
asong | 2:824ed4ae8d52 | 2031 | { |
asong | 2:824ed4ae8d52 | 2032 | Heart_Rate_Mode = true; |
asong | 2:824ed4ae8d52 | 2033 | Heart_Rate_Vibrations(); |
asong | 2:824ed4ae8d52 | 2034 | } |
asong | 2:824ed4ae8d52 | 2035 | |
asong | 2:824ed4ae8d52 | 2036 | /***************************************************************************** |
asong | 2:824ed4ae8d52 | 2037 | Name: Disable_Heart_Rate |
asong | 2:824ed4ae8d52 | 2038 | Purpose: Turn off the HexiHeart heart rate function |
asong | 2:824ed4ae8d52 | 2039 | Inputs: None |
asong | 2:824ed4ae8d52 | 2040 | Returns: None |
asong | 2:824ed4ae8d52 | 2041 | ******************************************************************************/ |
asong | 2:824ed4ae8d52 | 2042 | void Disable_Heart_Rate() |
asong | 2:824ed4ae8d52 | 2043 | { |
asong | 2:824ed4ae8d52 | 2044 | Heart_Rate_Mode = false; |
asong | 2:824ed4ae8d52 | 2045 | Heart_Rate_Vibrations(); |
asong | 2:824ed4ae8d52 | 2046 | } |
asong | 2:824ed4ae8d52 | 2047 | |
asong | 2:824ed4ae8d52 | 2048 | /***************************************************************************** |
asong | 2:824ed4ae8d52 | 2049 | Name: Determine_Current_Zone |
asong | 2:824ed4ae8d52 | 2050 | Purpose: Determines which zone the heart rate is in and assigns the curent |
asong | 2:824ed4ae8d52 | 2051 | zone and previous zone |
asong | 2:824ed4ae8d52 | 2052 | Inputs: None |
asong | 2:824ed4ae8d52 | 2053 | Returns: None |
asong | 2:824ed4ae8d52 | 2054 | ******************************************************************************/ |
asong | 2:824ed4ae8d52 | 2055 | void Determine_Current_Zone() |
asong | 2:824ed4ae8d52 | 2056 | { |
asong | 2:824ed4ae8d52 | 2057 | Prev_Zone = Current_Zone; |
asong | 2:824ed4ae8d52 | 2058 | |
asong | 2:824ed4ae8d52 | 2059 | if(Heart_Rate >= HR_Zone1[0] && Heart_Rate <= HR_Zone1[1]) { |
asong | 2:824ed4ae8d52 | 2060 | Current_Zone = 1; |
asong | 2:824ed4ae8d52 | 2061 | } else if(Heart_Rate >= HR_Zone2[0] && Heart_Rate <= HR_Zone2[1]) { |
asong | 2:824ed4ae8d52 | 2062 | Current_Zone = 2; |
asong | 2:824ed4ae8d52 | 2063 | } else if(Heart_Rate >= HR_Zone3[0] && Heart_Rate <= HR_Zone3[1]) { |
asong | 2:824ed4ae8d52 | 2064 | Current_Zone = 3; |
asong | 2:824ed4ae8d52 | 2065 | } else if(Heart_Rate >= HR_Zone4[0] && Heart_Rate <= HR_Zone4[1]) { |
asong | 2:824ed4ae8d52 | 2066 | Current_Zone = 4; |
asong | 2:824ed4ae8d52 | 2067 | } else { |
asong | 2:824ed4ae8d52 | 2068 | //error reading, don't change anything |
asong | 2:824ed4ae8d52 | 2069 | } |
asong | 2:824ed4ae8d52 | 2070 | |
asong | 2:824ed4ae8d52 | 2071 | |
asong | 2:824ed4ae8d52 | 2072 | } |
asong | 2:824ed4ae8d52 | 2073 | /***************************************************************************** |
asong | 2:824ed4ae8d52 | 2074 | Name: Run_Heart_Vibrations |
asong | 2:824ed4ae8d52 | 2075 | Purpose: Performs the HexiHeart heart rate function |
asong | 2:824ed4ae8d52 | 2076 | Inputs: None |
asong | 2:824ed4ae8d52 | 2077 | Returns: None |
asong | 2:824ed4ae8d52 | 2078 | ******************************************************************************/ |
asong | 2:824ed4ae8d52 | 2079 | void Heart_Rate_Vibrations() |
asong | 2:824ed4ae8d52 | 2080 | { |
asong | 2:824ed4ae8d52 | 2081 | if(Heart_Rate_Mode == true) { |
asong | 2:824ed4ae8d52 | 2082 | if(HR_Vibration == 1) { |
asong | 2:824ed4ae8d52 | 2083 | //All Pre-loaded vibrations enabled |
asong | 2:824ed4ae8d52 | 2084 | if(Current_Zone == Prev_Zone) { |
asong | 2:824ed4ae8d52 | 2085 | // Do nothing if no zone change |
asong | 2:824ed4ae8d52 | 2086 | } else if(Current_Zone == Target_Zone) { //Changed to target zone |
asong | 2:824ed4ae8d52 | 2087 | if(Target_Zone == LOWEST_ZONE || Prev_Zone > Target_Zone) { //must have entered from above |
asong | 2:824ed4ae8d52 | 2088 | StartHaptic(ENTER_ABOVE); |
asong | 2:824ed4ae8d52 | 2089 | } else if(Target_Zone == HIGHEST_ZONE || Prev_Zone < Target_Zone) { //must have entered from below |
asong | 2:824ed4ae8d52 | 2090 | StartHaptic(ENTER_BELOW); |
asong | 2:824ed4ae8d52 | 2091 | } |
asong | 2:824ed4ae8d52 | 2092 | } else if(Current_Zone != Target_Zone && Prev_Zone == Target_Zone) { |
asong | 2:824ed4ae8d52 | 2093 | if(Target_Zone == HIGHEST_ZONE || Current_Zone < Target_Zone) { //must have exited below |
asong | 2:824ed4ae8d52 | 2094 | StartHaptic(EXIT_BELOW); |
asong | 2:824ed4ae8d52 | 2095 | } else if(Target_Zone == LOWEST_ZONE || Current_Zone > Target_Zone) { //must have exited above |
asong | 2:824ed4ae8d52 | 2096 | StartHaptic(EXIT_ABOVE); |
asong | 2:824ed4ae8d52 | 2097 | } |
asong | 2:824ed4ae8d52 | 2098 | } |
asong | 2:824ed4ae8d52 | 2099 | } else if(HR_Vibration == 2) { |
asong | 2:824ed4ae8d52 | 2100 | //Only Entering and Exiting target zone |
asong | 2:824ed4ae8d52 | 2101 | if(Current_Zone == Prev_Zone) { |
asong | 2:824ed4ae8d52 | 2102 | //do nothing |
asong | 2:824ed4ae8d52 | 2103 | } else if(Current_Zone == Target_Zone) { |
asong | 2:824ed4ae8d52 | 2104 | StartHaptic(VIB_OPT_2); |
asong | 2:824ed4ae8d52 | 2105 | wait(0.1); |
asong | 2:824ed4ae8d52 | 2106 | StartHaptic(VIB_OPT_2); |
asong | 2:824ed4ae8d52 | 2107 | } else if(Current_Zone != Target_Zone && Prev_Zone == Target_Zone) { |
asong | 2:824ed4ae8d52 | 2108 | StartHaptic(VIB_OPT_2); |
asong | 2:824ed4ae8d52 | 2109 | wait(0.1); |
asong | 2:824ed4ae8d52 | 2110 | StartHaptic(VIB_OPT_2); |
asong | 2:824ed4ae8d52 | 2111 | wait(0.1); |
asong | 2:824ed4ae8d52 | 2112 | StartHaptic(VIB_OPT_2); |
asong | 2:824ed4ae8d52 | 2113 | } |
asong | 2:824ed4ae8d52 | 2114 | |
asong | 2:824ed4ae8d52 | 2115 | } else if(HR_Vibration == 3) { |
asong | 2:824ed4ae8d52 | 2116 | //No Vibrations |
asong | 2:824ed4ae8d52 | 2117 | |
asong | 2:824ed4ae8d52 | 2118 | } else { |
asong | 2:824ed4ae8d52 | 2119 | //Error, can only be choices 1-3 |
asong | 2:824ed4ae8d52 | 2120 | error_screen(); |
asong | 2:824ed4ae8d52 | 2121 | } |
asong | 2:824ed4ae8d52 | 2122 | } |
asong | 2:824ed4ae8d52 | 2123 | } |
asong | 2:824ed4ae8d52 | 2124 | |
asong | 2:824ed4ae8d52 | 2125 | /***************************************************************************** |
asong | 2:824ed4ae8d52 | 2126 | Name: Increment_Heart_Rate |
asong | 2:824ed4ae8d52 | 2127 | Purpose: Manually increment the the heart rate measurement by 1 for testing |
asong | 2:824ed4ae8d52 | 2128 | purposes |
asong | 2:824ed4ae8d52 | 2129 | Inputs: None |
asong | 2:824ed4ae8d52 | 2130 | Returns: None |
asong | 2:824ed4ae8d52 | 2131 | ******************************************************************************/ |
asong | 2:824ed4ae8d52 | 2132 | void Increment_Heart_Rate() |
asong | 2:824ed4ae8d52 | 2133 | { |
asong | 2:824ed4ae8d52 | 2134 | //StartHaptic(); |
asong | 2:824ed4ae8d52 | 2135 | if(Heart_Rate == HR_Zone4[1]) { |
asong | 2:824ed4ae8d52 | 2136 | Heart_Rate = HR_Zone1[0]; |
asong | 2:824ed4ae8d52 | 2137 | } else { |
asong | 2:824ed4ae8d52 | 2138 | Heart_Rate += 1; |
asong | 2:824ed4ae8d52 | 2139 | } |
asong | 2:824ed4ae8d52 | 2140 | } |
asong | 2:824ed4ae8d52 | 2141 | |
asong | 2:824ed4ae8d52 | 2142 | /***************************************************************************** |
asong | 2:824ed4ae8d52 | 2143 | Name: Decrement_Heart_Rate |
asong | 2:824ed4ae8d52 | 2144 | Purpose: Manually decrement the the heart rate measurement by 1 for testing |
asong | 2:824ed4ae8d52 | 2145 | purposes |
asong | 2:824ed4ae8d52 | 2146 | Inputs: None |
asong | 2:824ed4ae8d52 | 2147 | Returns: None |
asong | 2:824ed4ae8d52 | 2148 | ******************************************************************************/ |
asong | 2:824ed4ae8d52 | 2149 | void Decrement_Heart_Rate() |
asong | 2:824ed4ae8d52 | 2150 | { |
asong | 2:824ed4ae8d52 | 2151 | //StartHaptic(); |
asong | 2:824ed4ae8d52 | 2152 | if(Heart_Rate == HR_Zone1[0]) { |
asong | 2:824ed4ae8d52 | 2153 | Heart_Rate = HR_Zone4[1]; |
asong | 2:824ed4ae8d52 | 2154 | } else { |
asong | 2:824ed4ae8d52 | 2155 | Heart_Rate -= 1; |
asong | 2:824ed4ae8d52 | 2156 | } |
nbaker | 4:0803151bc5e4 | 2157 | } // end of Decrement_Heart_Rate |
asong | 2:824ed4ae8d52 | 2158 | |
asong | 2:824ed4ae8d52 | 2159 | void Led_Zone_Indicator() |
asong | 2:824ed4ae8d52 | 2160 | { |
asong | 2:824ed4ae8d52 | 2161 | if(Led_Zones == true) |
asong | 2:824ed4ae8d52 | 2162 | { |
asong | 2:824ed4ae8d52 | 2163 | if(Current_Zone == 1) |
asong | 2:824ed4ae8d52 | 2164 | { |
asong | 2:824ed4ae8d52 | 2165 | BLU_Led = LED_OFF; |
asong | 2:824ed4ae8d52 | 2166 | RED_Led = LED_ON; |
asong | 2:824ed4ae8d52 | 2167 | GRN_Led = LED_ON; |
asong | 3:6792c1ba586c | 2168 | |
asong | 3:6792c1ba586c | 2169 | wait(0.5); |
asong | 3:6792c1ba586c | 2170 | RED_Led = LED_OFF; |
asong | 3:6792c1ba586c | 2171 | GRN_Led = LED_OFF; |
asong | 2:824ed4ae8d52 | 2172 | } |
asong | 2:824ed4ae8d52 | 2173 | else if(Current_Zone == 2) |
asong | 2:824ed4ae8d52 | 2174 | { |
asong | 2:824ed4ae8d52 | 2175 | if(Prev_Zone == 1) |
asong | 2:824ed4ae8d52 | 2176 | { |
asong | 2:824ed4ae8d52 | 2177 | RED_Led = LED_OFF; |
asong | 2:824ed4ae8d52 | 2178 | GRN_Led = LED_OFF; |
asong | 2:824ed4ae8d52 | 2179 | } |
asong | 2:824ed4ae8d52 | 2180 | else if(Prev_Zone == 3) |
asong | 2:824ed4ae8d52 | 2181 | { |
asong | 2:824ed4ae8d52 | 2182 | GRN_Led = LED_OFF; |
asong | 2:824ed4ae8d52 | 2183 | } |
asong | 2:824ed4ae8d52 | 2184 | BLU_Led = LED_ON; |
asong | 3:6792c1ba586c | 2185 | wait(0.5); |
asong | 3:6792c1ba586c | 2186 | BLU_Led = LED_OFF; |
asong | 2:824ed4ae8d52 | 2187 | } |
asong | 2:824ed4ae8d52 | 2188 | else if(Current_Zone == 3) |
asong | 2:824ed4ae8d52 | 2189 | { |
asong | 2:824ed4ae8d52 | 2190 | if(Prev_Zone == 2) |
asong | 2:824ed4ae8d52 | 2191 | { |
asong | 2:824ed4ae8d52 | 2192 | BLU_Led = LED_OFF; |
asong | 2:824ed4ae8d52 | 2193 | } |
asong | 2:824ed4ae8d52 | 2194 | else if(Prev_Zone == 4) |
asong | 2:824ed4ae8d52 | 2195 | { |
asong | 2:824ed4ae8d52 | 2196 | RED_Led = LED_OFF; |
asong | 2:824ed4ae8d52 | 2197 | } |
asong | 2:824ed4ae8d52 | 2198 | GRN_Led = LED_ON; |
asong | 3:6792c1ba586c | 2199 | wait(0.5); |
asong | 3:6792c1ba586c | 2200 | GRN_Led = LED_OFF; |
asong | 2:824ed4ae8d52 | 2201 | } |
asong | 2:824ed4ae8d52 | 2202 | else if(Current_Zone == 4) |
asong | 2:824ed4ae8d52 | 2203 | { |
asong | 2:824ed4ae8d52 | 2204 | GRN_Led = LED_OFF; |
asong | 2:824ed4ae8d52 | 2205 | RED_Led = LED_ON; |
asong | 3:6792c1ba586c | 2206 | wait(0.5); |
asong | 3:6792c1ba586c | 2207 | RED_Led = LED_OFF; |
asong | 2:824ed4ae8d52 | 2208 | } |
nbaker | 4:0803151bc5e4 | 2209 | } |
nbaker | 4:0803151bc5e4 | 2210 | }//end of Led_Zone_Indicator |
jmr274 | 5:e1431272be79 | 2211 | |
jmr274 | 5:e1431272be79 | 2212 | /***************************************************************************** |
jmr274 | 5:e1431272be79 | 2213 | Name: Heat_Index_Calculation() |
jmr274 | 5:e1431272be79 | 2214 | Purpose: Calculates the heat index using the temperature and humidity sensors |
jmr274 | 5:e1431272be79 | 2215 | Inputs: None |
jmr274 | 5:e1431272be79 | 2216 | Returns: None |
jmr274 | 5:e1431272be79 | 2217 | ******************************************************************************/ |
jmr274 | 5:e1431272be79 | 2218 | void Heat_Index_Calculation(){ |
jmr274 | 5:e1431272be79 | 2219 | sample_ftemp = temphumid.sample_ftemp(); |
jmr274 | 5:e1431272be79 | 2220 | |
jmr274 | 5:e1431272be79 | 2221 | sample_humid = temphumid.sample_humid(); |
jmr274 | 5:e1431272be79 | 2222 | |
jmr274 | 5:e1431272be79 | 2223 | heat_index = -42.379 + |
jmr274 | 5:e1431272be79 | 2224 | 2.04901523 * sample_ftemp + |
jmr274 | 5:e1431272be79 | 2225 | 10.14333127 * sample_humid - |
jmr274 | 5:e1431272be79 | 2226 | 0.22475541 * sample_ftemp * sample_humid - |
jmr274 | 5:e1431272be79 | 2227 | 0.00683783 * sample_ftemp * sample_ftemp - |
jmr274 | 5:e1431272be79 | 2228 | 0.05481717 * sample_humid * sample_humid + |
jmr274 | 5:e1431272be79 | 2229 | 0.00122874 * sample_ftemp * sample_ftemp * sample_humid + |
jmr274 | 5:e1431272be79 | 2230 | 0.00085282 * sample_ftemp * sample_humid * sample_humid - |
jmr274 | 5:e1431272be79 | 2231 | 0.00000199 * sample_ftemp * sample_ftemp * sample_humid * sample_humid; |
jmr274 | 5:e1431272be79 | 2232 | } |
jmr274 | 5:e1431272be79 | 2233 | |
nbaker | 4:0803151bc5e4 | 2234 | /***************************************************************************** |
nbaker | 4:0803151bc5e4 | 2235 | Name: fall_detect() |
nbaker | 4:0803151bc5e4 | 2236 | Purpose: Interupt rutine called when accelerometer IC has detected a free-fall >= 0.5g |
nbaker | 4:0803151bc5e4 | 2237 | |
nbaker | 4:0803151bc5e4 | 2238 | ******************************************************************************/ |
nbaker | 4:0803151bc5e4 | 2239 | |
nbaker | 4:0803151bc5e4 | 2240 | void fall_detect(){// fall detect interupt rutine |
nbaker | 4:0803151bc5e4 | 2241 | if(Fall_Alert == 1){ |
nbaker | 7:3d5a8aea0b63 | 2242 | accel.acquire_accel_data_g(Accel_Data_Event); |
nbaker | 4:0803151bc5e4 | 2243 | // for now just turn on display and give haptic feedback |
nbaker | 7:3d5a8aea0b63 | 2244 | Screen_Num = 21; //Change to screen 21 (Fall diag screen) |
nbaker | 4:0803151bc5e4 | 2245 | Screen_Timer.attach(&timout_timer,(SCRN_TIME));// Reset/restart ticker timer for OLED |
nbaker | 4:0803151bc5e4 | 2246 | if (OLED_ON == 0) { |
nbaker | 4:0803151bc5e4 | 2247 | OLED_ON = 1; // Scree was off, set to On |
nbaker | 4:0803151bc5e4 | 2248 | } // endif |
nbaker | 4:0803151bc5e4 | 2249 | |
nbaker | 4:0803151bc5e4 | 2250 | //__disable_irq(); // Disable all Interrupts |
nbaker | 4:0803151bc5e4 | 2251 | // oled.Label((uint8_t *)" Fall Detected ",05,70); // Display at x,y |
nbaker | 4:0803151bc5e4 | 2252 | update_display(); |
nbaker | 7:3d5a8aea0b63 | 2253 | Accel_Mag = 2*sqrt(((Accel_Data_Event[0]*Accel_Data_Event[0])+(Accel_Data_Event[1]*Accel_Data_Event[1])+(Accel_Data_Event[2]*Accel_Data_Event[2]))); |
nbaker | 7:3d5a8aea0b63 | 2254 | sprintf(text_1,"Free-Fall:%2.2fg",Accel_Mag); |
nbaker | 8:a5c77b45008d | 2255 | oled.Label((uint8_t *)text_1,2,5);// text_1 at x,y |
nbaker | 7:3d5a8aea0b63 | 2256 | |
nbaker | 4:0803151bc5e4 | 2257 | BLU_Led = LED_ON; // LEDs default to on, need to turn off |
nbaker | 4:0803151bc5e4 | 2258 | Led_clk2 = 1; // Turn LED2 on docking station on |
nbaker | 4:0803151bc5e4 | 2259 | haptic = 1; |
nbaker | 4:0803151bc5e4 | 2260 | Accel_INT1.rise(&fall_det_end); // Accel sensor's int#1 calls interupt routine |
nbaker | 4:0803151bc5e4 | 2261 | //__enable_irq(); // Enable all Interrupts |
nbaker | 4:0803151bc5e4 | 2262 | }// end if |
nbaker | 4:0803151bc5e4 | 2263 | }//end fall_detect interupt routine |
nbaker | 4:0803151bc5e4 | 2264 | |
nbaker | 4:0803151bc5e4 | 2265 | |
nbaker | 4:0803151bc5e4 | 2266 | void fall_detect_off(){// fall detect interupt rutine |
nbaker | 4:0803151bc5e4 | 2267 | // for now just turn on display and give haptic feedback |
nbaker | 4:0803151bc5e4 | 2268 | }//end fall_detect_off interupt routine |
nbaker | 4:0803151bc5e4 | 2269 | |
nbaker | 4:0803151bc5e4 | 2270 | void fall_det_end(){ |
nbaker | 4:0803151bc5e4 | 2271 | haptic = 0; // Turn off Haptic |
nbaker | 4:0803151bc5e4 | 2272 | BLU_Led = LED_OFF; // Turn off HexiHeart Blue LED |
nbaker | 4:0803151bc5e4 | 2273 | Led_clk2 = 0; // Turn off LED2 on docking station on |
nbaker | 8:a5c77b45008d | 2274 | // oled.Label((uint8_t *)" ",05,70); // clear display at x,y |
nbaker | 4:0803151bc5e4 | 2275 | Accel_INT1.fall(&fall_detect); // Accel sensor's int#1 calls interupt routine |
nbaker | 4:0803151bc5e4 | 2276 | } //end fall_det_end interupt routine |
nbaker | 4:0803151bc5e4 | 2277 | |
nbaker | 4:0803151bc5e4 | 2278 | /***************************************************************************** |
nbaker | 4:0803151bc5e4 | 2279 | Name: impact_detect() |
nbaker | 4:0803151bc5e4 | 2280 | Purpose: Interupt rutine called when accelerometer IC has detected a vector |
nbaker | 4:0803151bc5e4 | 2281 | magnitude acceleration >= 3.0g |
nbaker | 4:0803151bc5e4 | 2282 | |
nbaker | 4:0803151bc5e4 | 2283 | ******************************************************************************/ |
nbaker | 4:0803151bc5e4 | 2284 | |
nbaker | 4:0803151bc5e4 | 2285 | void impact_detect(){ |
nbaker | 7:3d5a8aea0b63 | 2286 | if(Fall_Alert == 1){ |
nbaker | 7:3d5a8aea0b63 | 2287 | accel.acquire_accel_data_g(Accel_Data_Event); |
nbaker | 7:3d5a8aea0b63 | 2288 | // for now just turn on display and give haptic feedback |
nbaker | 7:3d5a8aea0b63 | 2289 | Screen_Num = 21; //Change to screen 21 (Fall diag screen) |
nbaker | 7:3d5a8aea0b63 | 2290 | Screen_Timer.attach(&timout_timer,(SCRN_TIME));// Reset/restart ticker timer for OLED |
nbaker | 7:3d5a8aea0b63 | 2291 | if (OLED_ON == 0) { |
nbaker | 7:3d5a8aea0b63 | 2292 | OLED_ON = 1; // Scree was off, set to On |
nbaker | 7:3d5a8aea0b63 | 2293 | } // endif |
nbaker | 7:3d5a8aea0b63 | 2294 | // update_display(); |
nbaker | 7:3d5a8aea0b63 | 2295 | |
nbaker | 7:3d5a8aea0b63 | 2296 | accel.acquire_accel_data_g(Accel_Data); |
nbaker | 8:a5c77b45008d | 2297 | Accel_Mag = 2*sqrt(((Accel_Data_Event[0]*Accel_Data_Event[0])+(Accel_Data_Event[1]*Accel_Data_Event[1])+(Accel_Data_Event[2]*Accel_Data_Event[2]))); |
nbaker | 7:3d5a8aea0b63 | 2298 | sprintf(text_1,"Impact:%2.2fg",Accel_Mag); |
nbaker | 8:a5c77b45008d | 2299 | oled.Label((uint8_t *)text_1,3,20);// text_1 at x,y |
nbaker | 7:3d5a8aea0b63 | 2300 | |
nbaker | 7:3d5a8aea0b63 | 2301 | Led_clk3 = 1; // Turn LED2 on docking station on |
nbaker | 7:3d5a8aea0b63 | 2302 | }// end if |
nbaker | 4:0803151bc5e4 | 2303 | }//end impact_detect interupt routine |
nbaker | 4:0803151bc5e4 | 2304 | |
nbaker | 4:0803151bc5e4 | 2305 | /***************************************************************************** |
nbaker | 4:0803151bc5e4 | 2306 | Name: fall_config() |
nbaker | 4:0803151bc5e4 | 2307 | Purpose: Used to set accelerometer IC's internal registers to set up chip level |
nbaker | 4:0803151bc5e4 | 2308 | interrupts |
nbaker | 4:0803151bc5e4 | 2309 | Inputs: int value from 0 to 256 |
nbaker | 4:0803151bc5e4 | 2310 | Returns: None |
nbaker | 4:0803151bc5e4 | 2311 | ******************************************************************************/ |
nbaker | 4:0803151bc5e4 | 2312 | |
nbaker | 4:0803151bc5e4 | 2313 | void fall_config(uint8_t Num){ |
nbaker | 4:0803151bc5e4 | 2314 | // use case switches here to configure for |
nbaker | 8:a5c77b45008d | 2315 | switch(Num) { |
nbaker | 8:a5c77b45008d | 2316 | case 0: {// put in standby |
nbaker | 4:0803151bc5e4 | 2317 | char d[2]; |
nbaker | 4:0803151bc5e4 | 2318 | d[0] = FXOS8700_CTRL_REG1; //Puts device in Standby mode |
nbaker | 4:0803151bc5e4 | 2319 | d[1] = 0x00; |
nbaker | 8:a5c77b45008d | 2320 | i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2); |
nbaker | 4:0803151bc5e4 | 2321 | |
nbaker | 8:a5c77b45008d | 2322 | /*For lowest power ~8uA, set ODR-12.5Hz,(low-pwr accel mode) or 2uA in standby mode */ |
nbaker | 4:0803151bc5e4 | 2323 | oled.Label((uint8_t *)" Mode 0 ",30,60); // Display "mode" at x,y |
nbaker | 8:a5c77b45008d | 2324 | oled.Label((uint8_t *)" No Int",30,75); // Display "mode" at x,y |
nbaker | 8:a5c77b45008d | 2325 | break; |
nbaker | 8:a5c77b45008d | 2326 | }// end of case 0 |
nbaker | 8:a5c77b45008d | 2327 | |
nbaker | 8:a5c77b45008d | 2328 | case 1: {// configure for free-fall int only |
nbaker | 4:0803151bc5e4 | 2329 | char d[2]; |
nbaker | 8:a5c77b45008d | 2330 | d[0] = 0x2a; //0x2a Config reg1 |
nbaker | 4:0803151bc5e4 | 2331 | d[1] = 0x00; //Put device in Standby mode |
nbaker | 4:0803151bc5e4 | 2332 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 4:0803151bc5e4 | 2333 | oled.Label((uint8_t *)" Step1 error ",30,05); // Display "error" at x,y |
nbaker | 4:0803151bc5e4 | 2334 | wait(3.0); // display for 3 seconds |
nbaker | 4:0803151bc5e4 | 2335 | }//end if |
nbaker | 4:0803151bc5e4 | 2336 | |
nbaker | 4:0803151bc5e4 | 2337 | d[0] = 0x0e; //XYZ_DATA_CFG (set full-scall range) |
nbaker | 8:a5c77b45008d | 2338 | d[1] = 0b00000001; //Set data to default range of +/-2g for full range (2x0.488mg/LSB), High-pass filter off |
nbaker | 4:0803151bc5e4 | 2339 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 4:0803151bc5e4 | 2340 | oled.Label((uint8_t *)" Step1a error ",30,05); // Display "error" at x,y |
nbaker | 4:0803151bc5e4 | 2341 | wait(3.0); // display for 3 seconds |
nbaker | 4:0803151bc5e4 | 2342 | }//end if |
nbaker | 8:a5c77b45008d | 2343 | /* |
nbaker | 8:a5c77b45008d | 2344 | d[0] = 0x0a; //TRIG_CFG (address of FIFO trigger config reg) |
nbaker | 4:0803151bc5e4 | 2345 | d[1] = 0b00000100; //Trigger on freefall |
nbaker | 4:0803151bc5e4 | 2346 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 4:0803151bc5e4 | 2347 | oled.Label((uint8_t *)" Step2 error ",30,05); // Display "error" at x,y |
nbaker | 4:0803151bc5e4 | 2348 | wait(3.0); // display for 3 seconds |
nbaker | 4:0803151bc5e4 | 2349 | }//end if |
nbaker | 8:a5c77b45008d | 2350 | */ |
nbaker | 4:0803151bc5e4 | 2351 | d[0] = 0x15; //A_FFMT_CFG (address of Free fall trigger config reg), write in Standby only |
nbaker | 4:0803151bc5e4 | 2352 | d[1] = 0b00111000; //set to freefall, and look at all axis. |
nbaker | 4:0803151bc5e4 | 2353 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 4:0803151bc5e4 | 2354 | oled.Label((uint8_t *)" Step3 error ",30,05); // Display "error" at x,y |
nbaker | 4:0803151bc5e4 | 2355 | wait(3.0); // display for 3 seconds |
nbaker | 4:0803151bc5e4 | 2356 | }//end if |
nbaker | 4:0803151bc5e4 | 2357 | |
nbaker | 4:0803151bc5e4 | 2358 | d[0] = 0x17; //A_FFMT_THS (address of Free fall threshold reg), write in Active or Standby |
nbaker | 4:0803151bc5e4 | 2359 | d[1] = 0b00001000; //set freefall threshold to about 756mg for now |
nbaker | 4:0803151bc5e4 | 2360 | // d[1] = uint8_t(1000*Fall_Thresh/63); //set freefall threshold - Resolution is 63mg/LSB, 0b111_1111 is maximum value |
nbaker | 4:0803151bc5e4 | 2361 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 4:0803151bc5e4 | 2362 | oled.Label((uint8_t *)" Step4 error ",30,05); // Display "error" at x,y |
nbaker | 4:0803151bc5e4 | 2363 | wait(3.0); // display for 3 seconds |
nbaker | 4:0803151bc5e4 | 2364 | }//end if |
nbaker | 4:0803151bc5e4 | 2365 | |
nbaker | 4:0803151bc5e4 | 2366 | d[0] = 0x18; //A_FFMT_COUNT (address of Free fall debounce counter), write in Active or Standby |
nbaker | 4:0803151bc5e4 | 2367 | d[1] = 0b00000110; //with ODR at 100Hz, should equal 60mS debounce time or 120mS in Sleep |
nbaker | 4:0803151bc5e4 | 2368 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 4:0803151bc5e4 | 2369 | oled.Label((uint8_t *)" Step5 error ",30,05); // Display "error" at x,y |
nbaker | 4:0803151bc5e4 | 2370 | wait(3.0); // display for 3 seconds |
nbaker | 4:0803151bc5e4 | 2371 | }//end if |
nbaker | 4:0803151bc5e4 | 2372 | |
nbaker | 4:0803151bc5e4 | 2373 | d[0] = 0x2b; //CTRL_REG2 (address of control reg), write in Standby only |
nbaker | 4:0803151bc5e4 | 2374 | d[1] = 0b00001101; //Turns Auto-Sleep mode on and low-noise, low power |
nbaker | 4:0803151bc5e4 | 2375 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 4:0803151bc5e4 | 2376 | oled.Label((uint8_t *)" Step6 error ",30,05); // Display "error" at x,y |
nbaker | 4:0803151bc5e4 | 2377 | wait(3.0); // display for 3 seconds |
nbaker | 4:0803151bc5e4 | 2378 | }//end if |
nbaker | 4:0803151bc5e4 | 2379 | |
nbaker | 4:0803151bc5e4 | 2380 | d[0] = 0x2c; //CTRL_REG3 (address of Int control reg), write in Standby only |
nbaker | 4:0803151bc5e4 | 2381 | d[1] = 0b00001000; //FFMT will wake chip from sleep, int are active high |
nbaker | 4:0803151bc5e4 | 2382 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 4:0803151bc5e4 | 2383 | oled.Label((uint8_t *)" Step7 error ",30,05); // Display "error" at x,y |
nbaker | 4:0803151bc5e4 | 2384 | wait(3.0); // display for 3 seconds |
nbaker | 4:0803151bc5e4 | 2385 | }//end if |
nbaker | 4:0803151bc5e4 | 2386 | |
nbaker | 4:0803151bc5e4 | 2387 | d[0] = 0x2d; //CTRL_REG4 (address of Int enable reg), write in Standby only |
nbaker | 4:0803151bc5e4 | 2388 | d[1] = 0b00000100; // FFMT int enabled and for debug I'm using a sleep int |
nbaker | 4:0803151bc5e4 | 2389 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 4:0803151bc5e4 | 2390 | oled.Label((uint8_t *)" Step8 error ",30,05); // Display "error" at x,y |
nbaker | 4:0803151bc5e4 | 2391 | wait(3.0); // display for 3 seconds |
nbaker | 4:0803151bc5e4 | 2392 | }//end if |
nbaker | 8:a5c77b45008d | 2393 | |
nbaker | 4:0803151bc5e4 | 2394 | d[0] = 0x2e; //CTRL_REG5 (Int routing reg), write in Standby only |
nbaker | 4:0803151bc5e4 | 2395 | d[1] = 0b00000100; // Make FFMT int output on pin INT1(PTC1) |
nbaker | 4:0803151bc5e4 | 2396 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 4:0803151bc5e4 | 2397 | oled.Label((uint8_t *)" Step9 error ",30,05); // Display "error" at x,y |
nbaker | 4:0803151bc5e4 | 2398 | wait(3.0); // display for 3 seconds |
nbaker | 4:0803151bc5e4 | 2399 | }//end if |
nbaker | 4:0803151bc5e4 | 2400 | |
nbaker | 8:a5c77b45008d | 2401 | d[0] = 0x2a; //0x2a Config reg1, write in Standby only except for bit[0] |
nbaker | 4:0803151bc5e4 | 2402 | d[1] = 0b00011001; //Auto-Sleep mode on set to 50Hz, ODR set to 100Hz Puts device back into Active mode |
nbaker | 4:0803151bc5e4 | 2403 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 4:0803151bc5e4 | 2404 | oled.Label((uint8_t *)" Step10 error ",30,05); // Display "error" at x,y |
nbaker | 4:0803151bc5e4 | 2405 | wait(3.0); // display for 3 seconds |
nbaker | 4:0803151bc5e4 | 2406 | }//end if |
nbaker | 4:0803151bc5e4 | 2407 | |
nbaker | 4:0803151bc5e4 | 2408 | //oled.FillScreen(COLOR_BLACK); // Clear screen |
nbaker | 8:a5c77b45008d | 2409 | oled.Label((uint8_t *)" Mode 1 ",30,60); // Display "mode" at x,y |
nbaker | 8:a5c77b45008d | 2410 | oled.Label((uint8_t *)" FF ",30,75); // Display "mode" at x,y |
nbaker | 8:a5c77b45008d | 2411 | |
nbaker | 4:0803151bc5e4 | 2412 | break; |
nbaker | 7:3d5a8aea0b63 | 2413 | }// end of case 1 |
nbaker | 7:3d5a8aea0b63 | 2414 | |
nbaker | 8:a5c77b45008d | 2415 | case 2: {// configure for vector impact only |
nbaker | 7:3d5a8aea0b63 | 2416 | char d[2]; |
nbaker | 7:3d5a8aea0b63 | 2417 | |
nbaker | 7:3d5a8aea0b63 | 2418 | d[0] = FXOS8700_CTRL_REG1; //Config reg1 0x2a |
nbaker | 7:3d5a8aea0b63 | 2419 | d[1] = 0x00; //Put device in Standby mode |
nbaker | 7:3d5a8aea0b63 | 2420 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 7:3d5a8aea0b63 | 2421 | oled.Label((uint8_t *)" Step1 error ",30,05); // Display "error" at x,y |
nbaker | 7:3d5a8aea0b63 | 2422 | wait(3.0); // display for 3 seconds |
nbaker | 7:3d5a8aea0b63 | 2423 | }//end if |
nbaker | 7:3d5a8aea0b63 | 2424 | |
nbaker | 7:3d5a8aea0b63 | 2425 | d[0] = 0x0e; //XYZ_DATA_CFG (set full-scall range) |
nbaker | 7:3d5a8aea0b63 | 2426 | d[1] = 0b00000001; //Set data to +/-4g for full range (0.488mg/LSB), High-pass filter off |
nbaker | 7:3d5a8aea0b63 | 2427 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 7:3d5a8aea0b63 | 2428 | oled.Label((uint8_t *)" Step1a error ",30,05); // Display "error" at x,y |
nbaker | 7:3d5a8aea0b63 | 2429 | wait(3.0); // display for 3 seconds |
nbaker | 7:3d5a8aea0b63 | 2430 | }//end if |
nbaker | 8:a5c77b45008d | 2431 | /* |
nbaker | 8:a5c77b45008d | 2432 | d[0] = 0x0a; //TRIG_CFG (address of FIFO trigger config reg) |
nbaker | 7:3d5a8aea0b63 | 2433 | d[1] = 0b00000110; //Trigger on freefall and on Vector |
nbaker | 7:3d5a8aea0b63 | 2434 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 7:3d5a8aea0b63 | 2435 | oled.Label((uint8_t *)" Step2 error ",30,05); // Display "error" at x,y |
nbaker | 7:3d5a8aea0b63 | 2436 | wait(3.0); // display for 3 seconds |
nbaker | 7:3d5a8aea0b63 | 2437 | }//end if |
nbaker | 8:a5c77b45008d | 2438 | */ |
nbaker | 8:a5c77b45008d | 2439 | d[0] = 0x5f; //A_VECM_CFG (address of Vector config reg), write in Standby only |
nbaker | 8:a5c77b45008d | 2440 | d[1] = 0b00111000; //Use reference values, don't update ref, enable. |
nbaker | 8:a5c77b45008d | 2441 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 8:a5c77b45008d | 2442 | oled.Label((uint8_t *)" Step3 error ",30,05); // Display "error" at x,y |
nbaker | 8:a5c77b45008d | 2443 | wait(3.0); // display for 3 seconds |
nbaker | 8:a5c77b45008d | 2444 | }//end if |
nbaker | 8:a5c77b45008d | 2445 | |
nbaker | 8:a5c77b45008d | 2446 | d[0] = 0x60; //A_VECM_MSB (address of Vector threshold reg), write in Active or Standby |
nbaker | 8:a5c77b45008d | 2447 | d[1] = 0b00000111; //set impact threshold to less than 1g for now |
nbaker | 8:a5c77b45008d | 2448 | // d[1] = uint8_t((1000*Impact_Thresh/0.488)/256); //set MSB Impact threshold - Resolution is 0.488mg/LSB so 0.5g=1024.6 => MSB=0b00000100 LSB=0b00000000 |
nbaker | 8:a5c77b45008d | 2449 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 8:a5c77b45008d | 2450 | oled.Label((uint8_t *)" Step4a error ",30,05); // Display "error" at x,y |
nbaker | 8:a5c77b45008d | 2451 | wait(3.0); // display for 3 seconds |
nbaker | 8:a5c77b45008d | 2452 | }//end if |
nbaker | 8:a5c77b45008d | 2453 | |
nbaker | 8:a5c77b45008d | 2454 | d[0] = 0x61; //A_VECM_LSB (address of Vector threshold reg), write in Active or Standby |
nbaker | 8:a5c77b45008d | 2455 | d[1] = 0b00000011; //set impact threshold to less than 1g for now |
nbaker | 8:a5c77b45008d | 2456 | // d[1] = uint8_t(256*((1000*Impact_Thresh/0.488)%256)); //set MSB Impact threshold - Resolution 0.488mg/LSB so 0.5g=1024.6 => MSB=0b00000100 LSB=0b00000000 |
nbaker | 8:a5c77b45008d | 2457 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 8:a5c77b45008d | 2458 | oled.Label((uint8_t *)" Step4b error ",30,05); // Display "error" at x,y |
nbaker | 8:a5c77b45008d | 2459 | wait(3.0); // display for 3 seconds |
nbaker | 8:a5c77b45008d | 2460 | }//end if |
nbaker | 8:a5c77b45008d | 2461 | |
nbaker | 8:a5c77b45008d | 2462 | d[0] = 0x62; //A_VECM_COUNT (address of Vector debounce counter), write in Active or Standby |
nbaker | 8:a5c77b45008d | 2463 | d[1] = 0b00000110; //with ODR at 100Hz, should equal ??mS debounce time or ??mS in Sleep |
nbaker | 8:a5c77b45008d | 2464 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 8:a5c77b45008d | 2465 | oled.Label((uint8_t *)" Step5 error ",30,05); // Display "error" at x,y |
nbaker | 8:a5c77b45008d | 2466 | wait(3.0); // display for 3 seconds |
nbaker | 8:a5c77b45008d | 2467 | }//end if |
nbaker | 8:a5c77b45008d | 2468 | |
nbaker | 8:a5c77b45008d | 2469 | // Registers 0x63 - 0x68 are vector reference values which I'm leaving set to 0 because we want absolute measurements |
nbaker | 8:a5c77b45008d | 2470 | |
nbaker | 8:a5c77b45008d | 2471 | d[0] = 0x2b; //CTRL_REG2 (address of control reg), write in Standby only |
nbaker | 8:a5c77b45008d | 2472 | d[1] = 0b00001101; //Turns Auto-Sleep mode on and low-noise, low power |
nbaker | 8:a5c77b45008d | 2473 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 8:a5c77b45008d | 2474 | oled.Label((uint8_t *)" Step6 error ",30,05); // Display "error" at x,y |
nbaker | 8:a5c77b45008d | 2475 | wait(3.0); // display for 3 seconds |
nbaker | 8:a5c77b45008d | 2476 | }//end if |
nbaker | 7:3d5a8aea0b63 | 2477 | |
nbaker | 8:a5c77b45008d | 2478 | d[0] = 0x2c; //CTRL_REG3 (address of Int control reg), write in Standby only |
nbaker | 8:a5c77b45008d | 2479 | d[1] = 0b00000100; //Vector will wake chip from sleep, int are active high |
nbaker | 8:a5c77b45008d | 2480 | // d[1] = 0b00001000; //FFMT will wake chip from sleep, int are active high |
nbaker | 8:a5c77b45008d | 2481 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 8:a5c77b45008d | 2482 | oled.Label((uint8_t *)" Step7 error ",30,05); // Display "error" at x,y |
nbaker | 8:a5c77b45008d | 2483 | wait(3.0); // display for 3 seconds |
nbaker | 8:a5c77b45008d | 2484 | }//end if |
nbaker | 8:a5c77b45008d | 2485 | |
nbaker | 8:a5c77b45008d | 2486 | d[0] = 0x2d; //CTRL_REG4 (address of Int enable reg), write in Standby only |
nbaker | 8:a5c77b45008d | 2487 | d[1] = 0b00000010; // Vector int enabled |
nbaker | 8:a5c77b45008d | 2488 | // d[1] = 0b00000100; // FFMT int enabled |
nbaker | 8:a5c77b45008d | 2489 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 8:a5c77b45008d | 2490 | oled.Label((uint8_t *)" Step8 error ",30,05); // Display "error" at x,y |
nbaker | 8:a5c77b45008d | 2491 | wait(3.0); // display for 3 seconds |
nbaker | 8:a5c77b45008d | 2492 | }//end if |
nbaker | 8:a5c77b45008d | 2493 | wait(0.2); // people have had a problem here and needed a delay |
nbaker | 8:a5c77b45008d | 2494 | d[0] = 0x2e; //CTRL_REG5 (Int routing reg), write in Standby only |
nbaker | 8:a5c77b45008d | 2495 | d[1] = 0b00000100; // Make FFMT int output on pin INT1(PTC1) and Vector on INT2(PTD13) |
nbaker | 8:a5c77b45008d | 2496 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 8:a5c77b45008d | 2497 | oled.Label((uint8_t *)" Step9 error ",30,05); // Display "error" at x,y |
nbaker | 8:a5c77b45008d | 2498 | wait(3.0); // display for 3 seconds |
nbaker | 8:a5c77b45008d | 2499 | }//end if |
nbaker | 8:a5c77b45008d | 2500 | |
nbaker | 8:a5c77b45008d | 2501 | d[0] = FXOS8700_CTRL_REG1; //CTRL_REG1, write in Standby only except for bit[0] |
nbaker | 8:a5c77b45008d | 2502 | d[1] = 0b00011001; //Auto-Sleep mode on set to 50Hz, ODR set to 100Hz Puts device back into Active mode |
nbaker | 8:a5c77b45008d | 2503 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 8:a5c77b45008d | 2504 | oled.Label((uint8_t *)" Step10 error ",30,05); // Display "error" at x,y |
nbaker | 8:a5c77b45008d | 2505 | wait(3.0); // display for 3 seconds |
nbaker | 8:a5c77b45008d | 2506 | }//end if |
nbaker | 8:a5c77b45008d | 2507 | |
nbaker | 8:a5c77b45008d | 2508 | //oled.FillScreen(COLOR_BLACK); // Clear screen |
nbaker | 8:a5c77b45008d | 2509 | oled.Label((uint8_t *)" Mode 2 ",30,60); // Display "mode" at x,y |
nbaker | 8:a5c77b45008d | 2510 | oled.Label((uint8_t *)"Imp ",30,75); // Display "mode" at x,y |
nbaker | 8:a5c77b45008d | 2511 | break; |
nbaker | 8:a5c77b45008d | 2512 | }// end of case 2 |
nbaker | 8:a5c77b45008d | 2513 | |
nbaker | 8:a5c77b45008d | 2514 | case 3: {// configure FFMT for free-fall event AND config for vector impact |
nbaker | 8:a5c77b45008d | 2515 | |
nbaker | 8:a5c77b45008d | 2516 | char d[2]; |
nbaker | 8:a5c77b45008d | 2517 | |
nbaker | 8:a5c77b45008d | 2518 | d[0] = 0x2a; //0x2a Config reg1, |
nbaker | 8:a5c77b45008d | 2519 | d[1] = 0x00; //Put device in Standby mode |
nbaker | 8:a5c77b45008d | 2520 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 8:a5c77b45008d | 2521 | oled.Label((uint8_t *)" Step1 error ",30,05); // Display "error" at x,y |
nbaker | 8:a5c77b45008d | 2522 | wait(3.0); // display for 3 seconds |
nbaker | 8:a5c77b45008d | 2523 | }//end if |
nbaker | 8:a5c77b45008d | 2524 | |
nbaker | 8:a5c77b45008d | 2525 | d[0] = 0x0e; //XYZ_DATA_CFG (set full-scall range) |
nbaker | 8:a5c77b45008d | 2526 | d[1] = 0b00000001; //Set data to +/-4g for full range (0.488mg/LSB), High-pass filter off |
nbaker | 8:a5c77b45008d | 2527 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 8:a5c77b45008d | 2528 | oled.Label((uint8_t *)" Step1a error ",30,05); // Display "error" at x,y |
nbaker | 8:a5c77b45008d | 2529 | wait(3.0); // display for 3 seconds |
nbaker | 8:a5c77b45008d | 2530 | }//end if |
nbaker | 8:a5c77b45008d | 2531 | /* |
nbaker | 8:a5c77b45008d | 2532 | d[0] = 0x0a; //TRIG_CFG (address of FIFO trigger config reg) |
nbaker | 8:a5c77b45008d | 2533 | d[1] = 0b00000110; //Trigger on freefall and on Vector |
nbaker | 8:a5c77b45008d | 2534 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 8:a5c77b45008d | 2535 | oled.Label((uint8_t *)" Step2 error ",30,05); // Display "error" at x,y |
nbaker | 8:a5c77b45008d | 2536 | wait(3.0); // display for 3 seconds |
nbaker | 8:a5c77b45008d | 2537 | }//end if |
nbaker | 8:a5c77b45008d | 2538 | */ |
nbaker | 7:3d5a8aea0b63 | 2539 | d[0] = 0x15; //A_FFMT_CFG (address of Free fall trigger config reg), write in Standby only |
nbaker | 7:3d5a8aea0b63 | 2540 | d[1] = 0b00111000; //set to freefall, and look at all axis. |
nbaker | 7:3d5a8aea0b63 | 2541 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 7:3d5a8aea0b63 | 2542 | oled.Label((uint8_t *)" Step3 error ",30,05); // Display "error" at x,y |
nbaker | 7:3d5a8aea0b63 | 2543 | wait(3.0); // display for 3 seconds |
nbaker | 7:3d5a8aea0b63 | 2544 | }//end if |
nbaker | 7:3d5a8aea0b63 | 2545 | |
nbaker | 7:3d5a8aea0b63 | 2546 | d[0] = 0x17; //A_FFMT_THS (address of Free fall threshold reg), write in Active or Standby |
nbaker | 7:3d5a8aea0b63 | 2547 | d[1] = 0b00001000; //set freefall threshold to about 756mg for now |
nbaker | 7:3d5a8aea0b63 | 2548 | // d[1] = uint8_t(1000*Fall_Thresh/63); //set freefall threshold - Resolution is 63mg/LSB, 0b111_1111 is maximum value |
nbaker | 7:3d5a8aea0b63 | 2549 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 7:3d5a8aea0b63 | 2550 | oled.Label((uint8_t *)" Step4 error ",30,05); // Display "error" at x,y |
nbaker | 7:3d5a8aea0b63 | 2551 | wait(3.0); // display for 3 seconds |
nbaker | 7:3d5a8aea0b63 | 2552 | }//end if |
nbaker | 7:3d5a8aea0b63 | 2553 | |
nbaker | 7:3d5a8aea0b63 | 2554 | d[0] = 0x18; //A_FFMT_COUNT (address of Free fall debounce counter), write in Active or Standby |
nbaker | 7:3d5a8aea0b63 | 2555 | d[1] = 0b00000110; //with ODR at 100Hz, should equal 60mS debounce time or 120mS in Sleep |
nbaker | 7:3d5a8aea0b63 | 2556 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 7:3d5a8aea0b63 | 2557 | oled.Label((uint8_t *)" Step5 error ",30,05); // Display "error" at x,y |
nbaker | 7:3d5a8aea0b63 | 2558 | wait(3.0); // display for 3 seconds |
nbaker | 7:3d5a8aea0b63 | 2559 | }//end if |
nbaker | 7:3d5a8aea0b63 | 2560 | |
nbaker | 7:3d5a8aea0b63 | 2561 | d[0] = 0x5f; //A_VECM_CFG (address of Vector config reg), write in Standby only |
nbaker | 7:3d5a8aea0b63 | 2562 | d[1] = 0b00111000; //Use reference values, don't update ref, enable. |
nbaker | 7:3d5a8aea0b63 | 2563 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 7:3d5a8aea0b63 | 2564 | oled.Label((uint8_t *)" Step3 error ",30,05); // Display "error" at x,y |
nbaker | 7:3d5a8aea0b63 | 2565 | wait(3.0); // display for 3 seconds |
nbaker | 7:3d5a8aea0b63 | 2566 | }//end if |
nbaker | 7:3d5a8aea0b63 | 2567 | |
nbaker | 7:3d5a8aea0b63 | 2568 | d[0] = 0x60; //A_VECM_MSB (address of Vector threshold reg), write in Active or Standby |
nbaker | 8:a5c77b45008d | 2569 | d[1] = 0b00000111; //set impact threshold to less than 1g for now |
nbaker | 7:3d5a8aea0b63 | 2570 | // d[1] = uint8_t((1000*Impact_Thresh/0.488)/256); //set MSB Impact threshold - Resolution is 0.488mg/LSB so 0.5g=1024.6 => MSB=0b00000100 LSB=0b00000000 |
nbaker | 7:3d5a8aea0b63 | 2571 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 7:3d5a8aea0b63 | 2572 | oled.Label((uint8_t *)" Step4a error ",30,05); // Display "error" at x,y |
nbaker | 7:3d5a8aea0b63 | 2573 | wait(3.0); // display for 3 seconds |
nbaker | 7:3d5a8aea0b63 | 2574 | }//end if |
nbaker | 7:3d5a8aea0b63 | 2575 | |
nbaker | 7:3d5a8aea0b63 | 2576 | d[0] = 0x61; //A_VECM_LSB (address of Vector threshold reg), write in Active or Standby |
nbaker | 7:3d5a8aea0b63 | 2577 | d[1] = 0b00000011; //set impact threshold to less than 1g for now |
nbaker | 7:3d5a8aea0b63 | 2578 | // d[1] = uint8_t(256*((1000*Impact_Thresh/0.488)%256)); //set MSB Impact threshold - Resolution 0.488mg/LSB so 0.5g=1024.6 => MSB=0b00000100 LSB=0b00000000 |
nbaker | 7:3d5a8aea0b63 | 2579 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 7:3d5a8aea0b63 | 2580 | oled.Label((uint8_t *)" Step4b error ",30,05); // Display "error" at x,y |
nbaker | 7:3d5a8aea0b63 | 2581 | wait(3.0); // display for 3 seconds |
nbaker | 7:3d5a8aea0b63 | 2582 | }//end if |
nbaker | 7:3d5a8aea0b63 | 2583 | |
nbaker | 7:3d5a8aea0b63 | 2584 | d[0] = 0x62; //A_VECM_COUNT (address of Vector debounce counter), write in Active or Standby |
nbaker | 7:3d5a8aea0b63 | 2585 | d[1] = 0b00000110; //with ODR at 100Hz, should equal ??mS debounce time or ??mS in Sleep |
nbaker | 7:3d5a8aea0b63 | 2586 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 7:3d5a8aea0b63 | 2587 | oled.Label((uint8_t *)" Step5 error ",30,05); // Display "error" at x,y |
nbaker | 7:3d5a8aea0b63 | 2588 | wait(3.0); // display for 3 seconds |
nbaker | 7:3d5a8aea0b63 | 2589 | }//end if |
nbaker | 7:3d5a8aea0b63 | 2590 | |
nbaker | 7:3d5a8aea0b63 | 2591 | // Registers 0x63 - 0x68 are vector reference values which I'm leaving set to 0 because we want absolute measurements |
nbaker | 7:3d5a8aea0b63 | 2592 | |
nbaker | 7:3d5a8aea0b63 | 2593 | d[0] = 0x2b; //CTRL_REG2 (address of control reg), write in Standby only |
nbaker | 7:3d5a8aea0b63 | 2594 | d[1] = 0b00001101; //Turns Auto-Sleep mode on and low-noise, low power |
nbaker | 7:3d5a8aea0b63 | 2595 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 7:3d5a8aea0b63 | 2596 | oled.Label((uint8_t *)" Step6 error ",30,05); // Display "error" at x,y |
nbaker | 7:3d5a8aea0b63 | 2597 | wait(3.0); // display for 3 seconds |
nbaker | 7:3d5a8aea0b63 | 2598 | }//end if |
nbaker | 7:3d5a8aea0b63 | 2599 | |
nbaker | 7:3d5a8aea0b63 | 2600 | d[0] = 0x2c; //CTRL_REG3 (address of Int control reg), write in Standby only |
nbaker | 7:3d5a8aea0b63 | 2601 | d[1] = 0b00001100; //FFMT or Vector will wake chip from sleep, int are active high |
nbaker | 7:3d5a8aea0b63 | 2602 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 7:3d5a8aea0b63 | 2603 | oled.Label((uint8_t *)" Step7 error ",30,05); // Display "error" at x,y |
nbaker | 7:3d5a8aea0b63 | 2604 | wait(3.0); // display for 3 seconds |
nbaker | 7:3d5a8aea0b63 | 2605 | }//end if |
nbaker | 7:3d5a8aea0b63 | 2606 | |
nbaker | 7:3d5a8aea0b63 | 2607 | d[0] = 0x2d; //CTRL_REG4 (address of Int enable reg), write in Standby only |
nbaker | 7:3d5a8aea0b63 | 2608 | d[1] = 0b00000110; // FFMT and Vector int enabled |
nbaker | 7:3d5a8aea0b63 | 2609 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 7:3d5a8aea0b63 | 2610 | oled.Label((uint8_t *)" Step8 error ",30,05); // Display "error" at x,y |
nbaker | 7:3d5a8aea0b63 | 2611 | wait(3.0); // display for 3 seconds |
nbaker | 7:3d5a8aea0b63 | 2612 | }//end if |
nbaker | 8:a5c77b45008d | 2613 | wait(0.2); // people have had a problem here and needed a delay |
nbaker | 8:a5c77b45008d | 2614 | |
nbaker | 7:3d5a8aea0b63 | 2615 | d[0] = 0x2e; //CTRL_REG5 (Int routing reg), write in Standby only |
nbaker | 7:3d5a8aea0b63 | 2616 | d[1] = 0b00000100; // Make FFMT int output on pin INT1(PTC1) and Vector on INT2(PTD13) |
nbaker | 7:3d5a8aea0b63 | 2617 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 7:3d5a8aea0b63 | 2618 | oled.Label((uint8_t *)" Step9 error ",30,05); // Display "error" at x,y |
nbaker | 7:3d5a8aea0b63 | 2619 | wait(3.0); // display for 3 seconds |
nbaker | 7:3d5a8aea0b63 | 2620 | }//end if |
nbaker | 7:3d5a8aea0b63 | 2621 | |
nbaker | 8:a5c77b45008d | 2622 | d[0] = 0x2a; //0x2a Config reg1, write in Standby only except for bit[0] |
nbaker | 7:3d5a8aea0b63 | 2623 | d[1] = 0b00011001; //Auto-Sleep mode on set to 50Hz, ODR set to 100Hz Puts device back into Active mode |
nbaker | 7:3d5a8aea0b63 | 2624 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 7:3d5a8aea0b63 | 2625 | oled.Label((uint8_t *)" Step10 error ",30,05); // Display "error" at x,y |
nbaker | 7:3d5a8aea0b63 | 2626 | wait(3.0); // display for 3 seconds |
nbaker | 7:3d5a8aea0b63 | 2627 | }//end if |
nbaker | 7:3d5a8aea0b63 | 2628 | |
nbaker | 7:3d5a8aea0b63 | 2629 | //oled.FillScreen(COLOR_BLACK); // Clear screen |
nbaker | 8:a5c77b45008d | 2630 | oled.Label((uint8_t *)" Mode 3 ",30,60); // Display "mode" at x,y |
nbaker | 8:a5c77b45008d | 2631 | oled.Label((uint8_t *)"FF & Imp",30,75); // Display "mode" at x,y |
nbaker | 7:3d5a8aea0b63 | 2632 | break; |
nbaker | 7:3d5a8aea0b63 | 2633 | }// end of case 3 |
nbaker | 7:3d5a8aea0b63 | 2634 | |
nbaker | 7:3d5a8aea0b63 | 2635 | case 10: {// reset IC |
nbaker | 7:3d5a8aea0b63 | 2636 | char d[2]; |
nbaker | 8:a5c77b45008d | 2637 | d[0] = 0x2a; //0x2a Config reg1 |
nbaker | 8:a5c77b45008d | 2638 | d[1] = 0x00; //Put device in Standby mode |
nbaker | 8:a5c77b45008d | 2639 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 8:a5c77b45008d | 2640 | oled.Label((uint8_t *)" Step1 error ",30,05); // Display "error" at x,y |
nbaker | 8:a5c77b45008d | 2641 | wait(3.0); // display for 3 seconds |
nbaker | 8:a5c77b45008d | 2642 | }//end if |
nbaker | 8:a5c77b45008d | 2643 | |
nbaker | 7:3d5a8aea0b63 | 2644 | d[0] = 0x2b; //CTRL_REG2 |
nbaker | 7:3d5a8aea0b63 | 2645 | d[1] = 0b01000000; // set bit to force reset of FXOS8700 |
nbaker | 7:3d5a8aea0b63 | 2646 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 7:3d5a8aea0b63 | 2647 | oled.Label((uint8_t *)" Reset error ",30,05); // Display "error" at x,y |
nbaker | 7:3d5a8aea0b63 | 2648 | wait(3.0); // display for 3 seconds |
nbaker | 7:3d5a8aea0b63 | 2649 | }//end if |
nbaker | 8:a5c77b45008d | 2650 | oled.Label((uint8_t *)" Reset ",30,45); // Display "reset" at x,y |
nbaker | 7:3d5a8aea0b63 | 2651 | break; |
nbaker | 7:3d5a8aea0b63 | 2652 | }// end case 10 |
nbaker | 7:3d5a8aea0b63 | 2653 | |
nbaker | 8:a5c77b45008d | 2654 | case 11: {// wake for read, was in stanby |
nbaker | 8:a5c77b45008d | 2655 | char d[2]; |
nbaker | 8:a5c77b45008d | 2656 | d[0] = FXOS8700_CTRL_REG1; //Puts device in Standby mode just in case |
nbaker | 8:a5c77b45008d | 2657 | d[1] = 0x00; |
nbaker | 8:a5c77b45008d | 2658 | i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2); |
nbaker | 8:a5c77b45008d | 2659 | |
nbaker | 8:a5c77b45008d | 2660 | d[0] = 0x0e; //XYZ_DATA_CFG (set full-scall range) |
nbaker | 8:a5c77b45008d | 2661 | d[1] = 0b00000001; //Set data to +/-4g for full range (0.488mg/LSB), High-pass filter off |
nbaker | 8:a5c77b45008d | 2662 | i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2); |
nbaker | 8:a5c77b45008d | 2663 | |
nbaker | 8:a5c77b45008d | 2664 | /*For lowest power ~8uA, set ODR-12.5Hz,(low-pwr accel mode) or 2uA in standby mode */ |
nbaker | 8:a5c77b45008d | 2665 | d[0] = 0x2a; //0x2a Config reg1, write in Standby only except for bit[0] |
nbaker | 8:a5c77b45008d | 2666 | d[1] = 0b00011001; //Auto-Sleep mode on set to 50Hz, ODR set to 100Hz Puts device back into Active mode |
nbaker | 8:a5c77b45008d | 2667 | i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d, 2); |
nbaker | 8:a5c77b45008d | 2668 | break; |
nbaker | 8:a5c77b45008d | 2669 | }// end of case 11 |
nbaker | 8:a5c77b45008d | 2670 | |
nbaker | 8:a5c77b45008d | 2671 | case 12: {// put into standby |
nbaker | 8:a5c77b45008d | 2672 | char d[2]; |
nbaker | 8:a5c77b45008d | 2673 | d[0] = FXOS8700_CTRL_REG1; //Puts device in Standby mode |
nbaker | 8:a5c77b45008d | 2674 | d[1] = 0x00; |
nbaker | 8:a5c77b45008d | 2675 | i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2); |
nbaker | 8:a5c77b45008d | 2676 | |
nbaker | 8:a5c77b45008d | 2677 | /*For lowest power ~8uA, set ODR-12.5Hz,(low-pwr accel mode) or 2uA in standby mode */ |
nbaker | 8:a5c77b45008d | 2678 | |
nbaker | 8:a5c77b45008d | 2679 | |
nbaker | 8:a5c77b45008d | 2680 | break; |
nbaker | 8:a5c77b45008d | 2681 | }// end of case 11 |
nbaker | 8:a5c77b45008d | 2682 | |
nbaker | 8:a5c77b45008d | 2683 | |
nbaker | 4:0803151bc5e4 | 2684 | default: { |
nbaker | 4:0803151bc5e4 | 2685 | oled.Label((uint8_t *)" Mode ? ",30,60); // Display "mode" at x,y |
nbaker | 4:0803151bc5e4 | 2686 | // unknown config |
nbaker | 4:0803151bc5e4 | 2687 | break; |
nbaker | 4:0803151bc5e4 | 2688 | } |
nbaker | 4:0803151bc5e4 | 2689 | }// end switch |
nbaker | 4:0803151bc5e4 | 2690 | |
nbaker | 4:0803151bc5e4 | 2691 | }// end Fall_config |
nbaker | 4:0803151bc5e4 | 2692 | |
nbaker | 8:a5c77b45008d | 2693 | /***************************************************************************** |
nbaker | 8:a5c77b45008d | 2694 | Name: update_display_date |
nbaker | 8:a5c77b45008d | 2695 | Purpose: Updating display data without updating any data labels. This keeps |
nbaker | 8:a5c77b45008d | 2696 | measurements and time values current while reducing screen flicker. |
nbaker | 8:a5c77b45008d | 2697 | ******************************************************************************/ |
nbaker | 8:a5c77b45008d | 2698 | void update_display_date(void) |
nbaker | 8:a5c77b45008d | 2699 | { |
nbaker | 8:a5c77b45008d | 2700 | oled_text_properties_t textProperties = {0}; // Need these to change font color |
nbaker | 8:a5c77b45008d | 2701 | oled.GetTextProperties(&textProperties); // Need these to change font color |
nbaker | 8:a5c77b45008d | 2702 | __disable_irq(); // Disable all Interrupts |
nbaker | 8:a5c77b45008d | 2703 | |
nbaker | 8:a5c77b45008d | 2704 | switch(Screen_Num) { |
nbaker | 8:a5c77b45008d | 2705 | case 0: {// Main Screen |
nbaker | 8:a5c77b45008d | 2706 | HexiwearBattery battery; |
nbaker | 8:a5c77b45008d | 2707 | battery.sensorOn(); |
nbaker | 8:a5c77b45008d | 2708 | if (battery.isBatteryCharging()) { |
nbaker | 8:a5c77b45008d | 2709 | textProperties.fontColor = COLOR_GREEN; |
nbaker | 8:a5c77b45008d | 2710 | oled.SetTextProperties(&textProperties); |
nbaker | 8:a5c77b45008d | 2711 | |
nbaker | 8:a5c77b45008d | 2712 | sprintf(text_1, "%i%%+", (uint8_t)battery.readLevelPercent()); |
nbaker | 8:a5c77b45008d | 2713 | // Screen_Timer.attach(&timout_timer,(SCRN_TIME));// Reset/restart ticker timer for OLED while fully charged |
nbaker | 8:a5c77b45008d | 2714 | } else { |
nbaker | 8:a5c77b45008d | 2715 | sprintf(text_1, "%i%%", (uint8_t)battery.readLevelPercent()); |
nbaker | 8:a5c77b45008d | 2716 | } |
nbaker | 8:a5c77b45008d | 2717 | oled.TextBox((uint8_t *)text_1,60,0,35,15); //show level value of battery in a 35px by 15px text box at x=60, y=0 |
nbaker | 8:a5c77b45008d | 2718 | |
nbaker | 8:a5c77b45008d | 2719 | textProperties.fontColor = COLOR_WHITE; |
nbaker | 8:a5c77b45008d | 2720 | oled.SetTextProperties(&textProperties); |
nbaker | 8:a5c77b45008d | 2721 | |
nbaker | 8:a5c77b45008d | 2722 | // added real time and date information |
nbaker | 8:a5c77b45008d | 2723 | char buffer[32]; |
nbaker | 8:a5c77b45008d | 2724 | time_t seconds = time(NULL); |
nbaker | 8:a5c77b45008d | 2725 | strftime(buffer,32, "%a,%d %m %Y.%H:%M:%S\r", localtime(&seconds)); |
nbaker | 8:a5c77b45008d | 2726 | // sprintf(text_1,"%c%c/%c%c/%c%c%c%c ",buffer[7],buffer[8],buffer[4],buffer[5],buffer[10],buffer[11],buffer[12],buffer[13]); |
nbaker | 8:a5c77b45008d | 2727 | // oled.Label((uint8_t *)text_1,20,20);// Date at x,y |
nbaker | 8:a5c77b45008d | 2728 | sprintf(text_1,"%c%c:%c%c:%c%c ",buffer[15],buffer[16],buffer[18],buffer[19],buffer[21],buffer[22]); |
nbaker | 8:a5c77b45008d | 2729 | oled.Label((uint8_t *)text_1,25,40);// Time at x,y |
nbaker | 8:a5c77b45008d | 2730 | |
nbaker | 8:a5c77b45008d | 2731 | Heat_Index_Calculation(); |
nbaker | 8:a5c77b45008d | 2732 | sprintf(text,"%i",heat_index); |
nbaker | 8:a5c77b45008d | 2733 | oled.TextBox((uint8_t *)text,3,80,15,15); //show HI in a 15px by 15px text box at x=3, y=80 |
nbaker | 8:a5c77b45008d | 2734 | break; |
nbaker | 8:a5c77b45008d | 2735 | }// end case 0 |
nbaker | 8:a5c77b45008d | 2736 | |
nbaker | 8:a5c77b45008d | 2737 | case 21: {// Fall Alert Diagnostic Screen |
nbaker | 8:a5c77b45008d | 2738 | if(Fall_Alert_Mode == 0){ |
nbaker | 8:a5c77b45008d | 2739 | fall_config(11); // turn accel sensor to active to take reading |
nbaker | 8:a5c77b45008d | 2740 | } |
nbaker | 8:a5c77b45008d | 2741 | textProperties.fontColor = COLOR_WHITE; |
nbaker | 8:a5c77b45008d | 2742 | oled.SetTextProperties(&textProperties); |
nbaker | 8:a5c77b45008d | 2743 | gyro.acquire_gyro_data_dps(Gyro_Data); |
nbaker | 8:a5c77b45008d | 2744 | Gyro_Mag = (abs(Gyro_Data[0])+abs(Gyro_Data[1])+abs(Gyro_Data[2])); |
nbaker | 8:a5c77b45008d | 2745 | sprintf(text_1," %4.0f D/S ",Gyro_Mag); |
nbaker | 8:a5c77b45008d | 2746 | oled.Label((uint8_t *)text_1,42,60);// text_1 at x,y |
nbaker | 8:a5c77b45008d | 2747 | |
nbaker | 8:a5c77b45008d | 2748 | accel.acquire_accel_data_g(Accel_Data); |
nbaker | 8:a5c77b45008d | 2749 | if(Fall_Alert_Mode == 0){ |
nbaker | 8:a5c77b45008d | 2750 | fall_config(12); // turn accel sensor back to standby |
nbaker | 8:a5c77b45008d | 2751 | } |
nbaker | 8:a5c77b45008d | 2752 | Accel_Mag = 2*sqrt(((Accel_Data[0]*Accel_Data[0])+(Accel_Data[1]*Accel_Data[1])+(Accel_Data[2]*Accel_Data[2]))); |
nbaker | 8:a5c77b45008d | 2753 | sprintf(text_1," %2.2f g ",Accel_Mag); |
nbaker | 8:a5c77b45008d | 2754 | oled.Label((uint8_t *)text_1,44,40);// text_1 at x,y |
nbaker | 8:a5c77b45008d | 2755 | if(Accel_Mag > Fall_Thresh + 0.1 && Led_clk2 == 1){// are we stuck in limbo? |
nbaker | 8:a5c77b45008d | 2756 | fall_det_end(); |
nbaker | 8:a5c77b45008d | 2757 | } |
nbaker | 8:a5c77b45008d | 2758 | break; |
nbaker | 8:a5c77b45008d | 2759 | }//end case 21 |
nbaker | 8:a5c77b45008d | 2760 | |
nbaker | 8:a5c77b45008d | 2761 | default: { |
nbaker | 8:a5c77b45008d | 2762 | // do nothing for other screens |
nbaker | 8:a5c77b45008d | 2763 | break; |
nbaker | 8:a5c77b45008d | 2764 | } |
nbaker | 8:a5c77b45008d | 2765 | }// end switch |
nbaker | 8:a5c77b45008d | 2766 | __enable_irq(); // Enable all Interrupts |
nbaker | 8:a5c77b45008d | 2767 | }// end of update_display_date |
nbaker | 8:a5c77b45008d | 2768 | |
nbaker | 8:a5c77b45008d | 2769 | |
nbaker | 8:a5c77b45008d | 2770 | /***************************************************************************** |
nbaker | 8:a5c77b45008d | 2771 | Name: BLUETOOTH |
nbaker | 8:a5c77b45008d | 2772 | Purpose: HexiHeart Connecction |
nbaker | 8:a5c77b45008d | 2773 | Inputs: None |
nbaker | 8:a5c77b45008d | 2774 | Returns: None |
nbaker | 8:a5c77b45008d | 2775 | ******************************************************************************/ |
nbaker | 8:a5c77b45008d | 2776 | |
nbaker | 8:a5c77b45008d | 2777 | |
nbaker | 8:a5c77b45008d | 2778 | void txTask(void) |
nbaker | 8:a5c77b45008d | 2779 | { |
nbaker | 8:a5c77b45008d | 2780 | |
nbaker | 8:a5c77b45008d | 2781 | while (true) { |
nbaker | 8:a5c77b45008d | 2782 | /*Notify Hexiwear App that it is running Sensor Tag mode*/ |
nbaker | 8:a5c77b45008d | 2783 | /* This part was not compiling |
nbaker | 8:a5c77b45008d | 2784 | kw40z_device.SendSetApplicationMode(GUI_CURRENT_APP_SENSOR_TAG); |
nbaker | 8:a5c77b45008d | 2785 | */ |
nbaker | 8:a5c77b45008d | 2786 | } |
nbaker | 8:a5c77b45008d | 2787 | } |