The HexiHeart is a demo project product that takes advantage of many of the onboard Hexiwear sensors and capabilities to create a multifunctional fitness and safety watch.

Dependencies:   FXAS21002 FXOS8700 Hexi_KW40Z Hexi_OLED_SSD1351 MAXIM W25Q64FVSSIG HTU21D MPL3115A2 TSL2561

Fork of HexiHeart_Alex by Hexiwear_zeta

Committer:
nbaker
Date:
Mon Mar 26 00:29:18 2018 +0000
Revision:
10:eaea844e763c
Parent:
9:d2e39ee9fedd
Child:
11:ccda4d44bd8e
Added final fall mode (full sequential fall algorithm), including alert screen and dismiss alert screen.  Added FAP (Fall Alert Protection) to main screen. fixed "aggressive Haptic" problem by using a Ticker to turn off Haptic instead of RTOS.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
asong 1:e4b38d6918ba 1 /**********************************************************************
nbaker 9:d2e39ee9fedd 2 Texas State University Senior Project - HexiHeart
nbaker 0:d1d36a3da39b 3 Team Zeta: Alex Song, Jasmine Rounsaville, Issam Hichami, Neil Baker
nbaker 9:d2e39ee9fedd 4
nbaker 9:d2e39ee9fedd 5 Program layout:
nbaker 9:d2e39ee9fedd 6 Declarations
nbaker 9:d2e39ee9fedd 7 Up Button routines
nbaker 9:d2e39ee9fedd 8 Down Button routines
nbaker 9:d2e39ee9fedd 9 Right Button routines
nbaker 9:d2e39ee9fedd 10 Left Button routines
nbaker 9:d2e39ee9fedd 11 Main()
nbaker 9:d2e39ee9fedd 12 Main display screen routines
nbaker 9:d2e39ee9fedd 13 Function and interupt routines
nbaker 9:d2e39ee9fedd 14 Display data screen update routines
nbaker 9:d2e39ee9fedd 15
nbaker 10:eaea844e763c 16 v2.09 - Added final fall mode (full sequential fall algorithm), including alert screen
nbaker 10:eaea844e763c 17 and dismiss alert screen. Added FAP (Fall Alert Protection) to main screen. fixed "aggressive Haptic" problem by using a Ticker to
nbaker 10:eaea844e763c 18 turn off Haptic instead of RTOS timer.
nbaker 10:eaea844e763c 19
nbaker 9:d2e39ee9fedd 20 v2.08 - Fixed impact detect functionality, all fall detect parameters are now adjustable,
nbaker 9:d2e39ee9fedd 21 added motion detect function, incorporated new heat index calc, increased font by 20% for time/date.
nbaker 9:d2e39ee9fedd 22 Added SW and power resetting to initialize sensors in known state.
nbaker 9:d2e39ee9fedd 23
nbaker 9:d2e39ee9fedd 24 v2.07 - 2/18/18 - Added fall mode option to test fall/impact separately, Added global
nbaker 9:d2e39ee9fedd 25 interrupt disable prevent button interrupts while refreshing screen, this caused haptic
nbaker 9:d2e39ee9fedd 26 timer to stop working right.
nbaker 9:d2e39ee9fedd 27
nbaker 9:d2e39ee9fedd 28 v1.0 - 11/12/17
nbaker 0:d1d36a3da39b 29 This version has basic menu layout and screen timeout feature. The menu
asong 1:e4b38d6918ba 30 are just placeholders (for the most part) and will be either adjusted or
nbaker 0:d1d36a3da39b 31 replaced with graphic images.
nbaker 0:d1d36a3da39b 32
nbaker 0:d1d36a3da39b 33 ***********************************************************************/
nbaker 0:d1d36a3da39b 34
nbaker 0:d1d36a3da39b 35 #include "mbed.h"
nbaker 0:d1d36a3da39b 36 #include "Hexi_KW40Z.h" // Button and BLE fuctions
nbaker 9:d2e39ee9fedd 37 #include "FXOS8700.h" // Freescale/NXP FXOS8700CQ - 3D Accelorometer & Mag
nbaker 9:d2e39ee9fedd 38 #include "FXAS21002.h" // Freescale/NXP FXAS21002CQ - 3-Axis Gyroscope
nbaker 9:d2e39ee9fedd 39 //#include "MPL3115A2.h" // Freescale/NXP MPL3115A2 - pressure sensor
nbaker 9:d2e39ee9fedd 40 #include "HTU21D.h" // Non-Freescale/NXP - HTU21D - combo temperature and Humidity
nbaker 9:d2e39ee9fedd 41 #include "W25Q64FV.h" // Non-Freescale/NXP - W25Q64FVSSIG - 8MB/64Mbit Serial Flash memory
nbaker 9:d2e39ee9fedd 42 #include "MAX30101.h" // Non-Freescale MAX30101 - Optical Heart rate sensor
nbaker 9:d2e39ee9fedd 43 //#include "TSL2561.h" // Non-Freescale/NXP TSL2561 - light sensor
nbaker 9:d2e39ee9fedd 44 #include "Hexi_Battery/hexi_battery.h" // Battery status
nbaker 0:d1d36a3da39b 45 #include "Hexi_OLED_SSD1351.h" // OLED fuctions
nbaker 0:d1d36a3da39b 46 #include "OLED_types.h" // Text attributs
nbaker 0:d1d36a3da39b 47 #include "string.h"
nbaker 0:d1d36a3da39b 48 #include "OpenSans_Font.h"
nbaker 9:d2e39ee9fedd 49 #include "images.h"
asong 1:e4b38d6918ba 50
asong 2:824ed4ae8d52 51
nbaker 0:d1d36a3da39b 52 // Definitions
nbaker 10:eaea844e763c 53 #define SW_Ver 2.09 // For displaying software version
asong 2:824ed4ae8d52 54 #define LED_ON 0
asong 2:824ed4ae8d52 55 #define LED_OFF 1
asong 2:824ed4ae8d52 56 #define SCRN_TIME 10.0
asong 2:824ed4ae8d52 57 #define Debug 1 // If "Debug" is defined, our code will compile for debug. Comment out for Production code.
asong 2:824ed4ae8d52 58 #define HIGHEST_ZONE 4
asong 2:824ed4ae8d52 59 #define LOWEST_ZONE 1
asong 2:824ed4ae8d52 60 #define ENTER_BELOW 25
asong 2:824ed4ae8d52 61 #define ENTER_ABOVE 50
asong 2:824ed4ae8d52 62 #define EXIT_BELOW 75
asong 2:824ed4ae8d52 63 #define EXIT_ABOVE 100
asong 2:824ed4ae8d52 64 #define VIB_OPT_2 75
nbaker 4:0803151bc5e4 65 #define FXOS8700_I2C_ADDRESS_ (0x1E<<1) //pins SA0,SA1=0
nbaker 9:d2e39ee9fedd 66 #define FXAS21002_I2C_ADDRESS_ 0x40 //
nbaker 9:d2e39ee9fedd 67 //#define TSL2561_I2C_ADDRESS_ (0x29 << 1) // Address select line is grounded
nbaker 9:d2e39ee9fedd 68 //#define MPL3115A2_I2C_ADDRESS_ ? //
asong 1:e4b38d6918ba 69
nbaker 0:d1d36a3da39b 70 void StartHaptic(void);
nbaker 10:eaea844e763c 71 void Haptic_Off_(void); // added by NRB
asong 1:e4b38d6918ba 72 void StartHaptic(int x);
nbaker 0:d1d36a3da39b 73 void StopHaptic(void const *n);
nbaker 9:d2e39ee9fedd 74 void error_screen(void); // display error screen
nbaker 4:0803151bc5e4 75 void update_display(void);// Screen lables refreshed
nbaker 8:a5c77b45008d 76 void update_display_date(void); // Screen data(only)refreshed
asong 2:824ed4ae8d52 77 void Decrement_Age();
asong 2:824ed4ae8d52 78 void Set_Max_Bpm();
asong 2:824ed4ae8d52 79 void Set_Zone_Boundaries();
asong 2:824ed4ae8d52 80 void Increment_Age();
asong 2:824ed4ae8d52 81 void Increment_Target_Zone();
asong 2:824ed4ae8d52 82 void Decrement_Target_Zone();
asong 2:824ed4ae8d52 83 void Increment_HR_Vibr_Pref();
asong 2:824ed4ae8d52 84 void Decrement_HR_Vibr_Pref();
asong 2:824ed4ae8d52 85 void Determine_Current_Zone();
asong 2:824ed4ae8d52 86 void Heart_Rate_Vibrations();
asong 2:824ed4ae8d52 87 void Increment_Heart_Rate();
asong 2:824ed4ae8d52 88 void Decrement_Heart_Rate();
asong 2:824ed4ae8d52 89 void Enable_Heart_Rate();
asong 2:824ed4ae8d52 90 void Disable_Heart_Rate();
asong 2:824ed4ae8d52 91 void Led_Zone_Indicator();
jmr274 5:e1431272be79 92 void Heat_Index_Calculation();
nbaker 10:eaea844e763c 93 void fall_config(uint8_t); //function call to setup fall detecting modes
nbaker 10:eaea844e763c 94 void accel_sensor_config(uint8_t);
nbaker 10:eaea844e763c 95 void gyro_sensor_config(uint8_t);
nbaker 9:d2e39ee9fedd 96 void light_config(uint8_t);
nbaker 9:d2e39ee9fedd 97 void press_config(uint8_t);
nbaker 10:eaea844e763c 98 void fall_detect(void); // Interupt routine
nbaker 10:eaea844e763c 99 void fall_detect_debug(void); // Interupt routine
nbaker 10:eaea844e763c 100 void fall_det_end(void); // Interupt routine
nbaker 10:eaea844e763c 101 void fall_det_end_debug(void); // Interupt routine
nbaker 10:eaea844e763c 102 void chkfall(void); // Routine used with Ticker
nbaker 10:eaea844e763c 103 void interupt_off(void);
nbaker 10:eaea844e763c 104 void clear_fall(void); // Routine used with Ticker
nbaker 10:eaea844e763c 105 void impact_detect(void); // Interupt routine
nbaker 10:eaea844e763c 106 void impact_detect_debug(void); // Interupt routine
nbaker 10:eaea844e763c 107 void motion_detect(); // Interupt routine
nbaker 10:eaea844e763c 108 void motion_detect_debug(); // Interupt routine
nbaker 10:eaea844e763c 109 void chkmotion(void); // Routine used with Ticker
nbaker 10:eaea844e763c 110 void chk_help_needed(void); // Routine used with Ticker
nbaker 9:d2e39ee9fedd 111 void MAX30101_test_config(uint8_t);
nbaker 10:eaea844e763c 112 void Send_Alert(uint8_t); // fuction to store and send alert
asong 1:e4b38d6918ba 113
nbaker 0:d1d36a3da39b 114 // ***************** Global variables ***********************
nbaker 0:d1d36a3da39b 115 char text_1[20]; // Text buffer - Do we need more?
asong 2:824ed4ae8d52 116 char display_buff[30]; //Buffer for conversion to char to display
jmr274 5:e1431272be79 117 char text[20]; // Text Buffer for dynamic value displayed
nbaker 8:a5c77b45008d 118 bool BLE_On = 0; // Initialize as BLE on
nbaker 8:a5c77b45008d 119 char pass [20]; // Passcode
asong 2:824ed4ae8d52 120 bool Led_Zones = 1;
asong 1:e4b38d6918ba 121 bool HR_Enable = 0;
nbaker 0:d1d36a3da39b 122 bool OLED_ON = 1; // Turn OLED power on/off
nbaker 4:0803151bc5e4 123 bool Fall_Alert = 1; // Initialize as no active alert
jmr274 5:e1431272be79 124 bool Panic_Alert = 0; // Initialize as no active alert
nbaker 10:eaea844e763c 125 uint8_t Fall_Alert_Mode = 5; // Initialize with fall alert mode on
jmr274 5:e1431272be79 126 bool Heart_Rate_Mode = 0; // Initialize with Heart rate off
nbaker 0:d1d36a3da39b 127 float Accel_Mag=0.0; // Vector magnitude calculated from sensor data
nbaker 0:d1d36a3da39b 128 float Accel_Data[3]; // Accel Data from sensor
nbaker 7:3d5a8aea0b63 129 float Accel_Data_Event[3]; // Accel Data from sensor at interupt
nbaker 10:eaea844e763c 130 float Fall_Event_Data[7]; // Fall event Data ff-value, ff-time, impact-value, 4byte timestamp
jmr274 5:e1431272be79 131 float Gyro_Mag=0.0; // Vector magnitude calculated from sensor data
nbaker 10:eaea844e763c 132 float Gyro_Data[3]; // Gyro data from sensor
nbaker 10:eaea844e763c 133 float Fall_Thresh=0.5; // Initialize Free-Fall detect Threshold as being <= 0.5g
nbaker 10:eaea844e763c 134 float Fall_Impact_Max_Wait_Time=2.0;// maximum wait time from end of fall detect to impact detect
nbaker 10:eaea844e763c 135 float Impact_Thresh=3.0; // Initialize Impact detect Threshold
nbaker 10:eaea844e763c 136 float Movement_Thresh=50.0; // Initialize Movement detect Threshold
nbaker 9:d2e39ee9fedd 137 float Min_Movement_Time=5.0; // Initialize Movement minimum movement time to 5 sec
nbaker 9:d2e39ee9fedd 138 float Min_Movement_duration=60.0; // Initialize Movement min-movement testing duration to 60 sec
nbaker 10:eaea844e763c 139 float Do_You_Need_Help_Time=10.0; // Time to dismiss "Do you need Help" screen
asong 2:824ed4ae8d52 140 uint8_t Current_Zone = 1;
asong 2:824ed4ae8d52 141 uint8_t Prev_Zone = 1;
asong 2:824ed4ae8d52 142 uint8_t Heart_Rate = 100;
asong 1:e4b38d6918ba 143 uint8_t HR_buff[250];
asong 1:e4b38d6918ba 144 uint8_t *HR_return;
asong 1:e4b38d6918ba 145 uint8_t Age = 50; // Initialize age
asong 2:824ed4ae8d52 146 uint8_t Max_Bpm = 220 - Age; // Initialize Max BPM
nbaker 0:d1d36a3da39b 147 uint8_t Screen_Num = 0; // Initialize to main screen
asong 1:e4b38d6918ba 148 uint8_t Error_Num = 0; // Error num for debug
asong 2:824ed4ae8d52 149 uint8_t HR_Vibration = 2; //Choose Heart Rate Vibration Options
asong 2:824ed4ae8d52 150 uint8_t Target_Zone = 2; //Initialize Target Heart Rate Zone to Zone 3
asong 2:824ed4ae8d52 151 uint8_t HR_Zone1[2] = {Max_Bpm * .50, Max_Bpm * .60}; //Heart Rate Zone 1
asong 2:824ed4ae8d52 152 uint8_t HR_Zone2[2] = {HR_Zone1[1] + 1, Max_Bpm * .70}; //Heart Rate Zone 2
asong 2:824ed4ae8d52 153 uint8_t HR_Zone3[2] = {HR_Zone2[1] + 1, Max_Bpm * .80}; //Heart Rate Zone 3
asong 2:824ed4ae8d52 154 uint8_t HR_Zone4[2] = {HR_Zone3[1] + 1, Max_Bpm}; //Heart Rate Zone 4
nbaker 9:d2e39ee9fedd 155 int sample_ftemp; // used in Heat index calc
nbaker 9:d2e39ee9fedd 156 int sample_humid; // used in Heat index calc
nbaker 9:d2e39ee9fedd 157 int heat_index; // used in Heat index calc
nbaker 9:d2e39ee9fedd 158 int hi_calc; // used in Heat index calc
nbaker 9:d2e39ee9fedd 159 int adjustment; // used in Heat index calc
nbaker 9:d2e39ee9fedd 160
nbaker 9:d2e39ee9fedd 161 // Pointers for screen images
nbaker 9:d2e39ee9fedd 162 const uint8_t *Hexi_Heart_ = Hexi_Heart_bmp;
nbaker 9:d2e39ee9fedd 163 //const uint8_t *NB_Linkedin = NB_Linkedin_bmp;
nbaker 9:d2e39ee9fedd 164 //const uint8_t *AS_Linkedin = NB_Linkedin_bmp;
nbaker 9:d2e39ee9fedd 165 //const uint8_t *IR_Linkedin = NB_Linkedin_bmp;
nbaker 9:d2e39ee9fedd 166 //const uint8_t *IH_Linkedin = NB_Linkedin_bmp;
nbaker 9:d2e39ee9fedd 167
jmr274 5:e1431272be79 168
nbaker 0:d1d36a3da39b 169 // ***************** Define pins *****************************
nbaker 9:d2e39ee9fedd 170 //W25Q64FVSSIG - 8MB/64Mbit Serial Flash memory (SPI1)(MOSI,SCLK,POWER,CS,RST,DC)
nbaker 9:d2e39ee9fedd 171 //W25Q64FV(PinName mosi, PinName miso, PinName sclk, PinName cs, int frequency=10000000);
nbaker 9:d2e39ee9fedd 172 //MKW40Z (SPI1)
nbaker 9:d2e39ee9fedd 173 SSD1351 oled(PTB22,PTB21,PTC13,PTB20,PTE6, PTD15); // SSD1351 OLED Driver SPI2(MOSI,SCLK,POWER,CS,RST,DC)
nbaker 9:d2e39ee9fedd 174 FXAS21002 gyro(PTC11,PTC10); // Gyroscope (I2C1 data bus(SDA, SCL))
nbaker 9:d2e39ee9fedd 175 FXOS8700 accel(PTC11, PTC10); // Accelorometer (I2C1 data bus(SDA, SCL))
nbaker 9:d2e39ee9fedd 176 FXOS8700 mag(PTC11, PTC10); // Mag (same chip as Accel) (I2C1 data bus(SDA, SCL))
nbaker 9:d2e39ee9fedd 177 //MAX30101 heart(PTB1, PTB0); //Heart Rate Chip (I2C0 data bus(SDA, SCL))
nbaker 9:d2e39ee9fedd 178 HTU21D temphumid(PTB1,PTB0); // HTU21D Sensor (I2C0 data bus(SDA, SCL))
nbaker 9:d2e39ee9fedd 179 //TSL2561 - (PTB1, PTB0); //Amb light sensor (I2C0 data bus(SDA, SCL))
nbaker 0:d1d36a3da39b 180
nbaker 4:0803151bc5e4 181 // initialize I2C bus for FXOS8700, FXAS-Gyro, MPL-Pressure
nbaker 4:0803151bc5e4 182 I2C i2c_bus1(PTC11, PTC10); // (SDA, SCL)
nbaker 9:d2e39ee9fedd 183 // initialize I2C bus for MAX30101, HTU21D, TSL2561
nbaker 9:d2e39ee9fedd 184 I2C i2c_bus0(PTB1, PTB0); // (SDA, SCL)
nbaker 9:d2e39ee9fedd 185
nbaker 9:d2e39ee9fedd 186 // initialize SPI bus for W25Q64FVSSIG, (and MKW40Z if needed)
nbaker 9:d2e39ee9fedd 187 // SPI spi_bus1(PTD6, PTD7, PTD5); // (MOSI, MISO, SCLK) CS=PTD4?(low=select)
nbaker 4:0803151bc5e4 188
nbaker 0:d1d36a3da39b 189 DigitalOut RED_Led(LED1);
nbaker 0:d1d36a3da39b 190 DigitalOut GRN_Led(LED2);
nbaker 0:d1d36a3da39b 191 DigitalOut BLU_Led(LED3);
nbaker 0:d1d36a3da39b 192 DigitalOut haptic(PTB9);
nbaker 4:0803151bc5e4 193 DigitalOut Led_clk1(PTA12);
nbaker 4:0803151bc5e4 194 DigitalOut Led_clk2(PTA13);
nbaker 4:0803151bc5e4 195 DigitalOut Led_clk3(PTA14);
nbaker 4:0803151bc5e4 196
nbaker 9:d2e39ee9fedd 197 DigitalOut OLED_PWR(PTC13); // this pin turns on/off 15V supply to OLED display
nbaker 9:d2e39ee9fedd 198 DigitalOut PowerEN (PTB12); // 3V3B Power Enable for HTU21D (Temp/Hum sensor) and Light sensor Sensor supply
nbaker 9:d2e39ee9fedd 199 DigitalOut HR_PWR(PTA29); // this pin turns on/off power to heart rate sensor
jmr274 5:e1431272be79 200 //DigitalIn Sw1(PTA12); //Switch 'T1' on docking station AND Led_clk1!!
jmr274 5:e1431272be79 201 //DigitalIn Sw2(PTA13); //Switch 'T2' on docking station AND Led_clk2!!
jmr274 5:e1431272be79 202 DigitalIn Sw3(PTA15); //Switch 'T3' on docking station
nbaker 4:0803151bc5e4 203
nbaker 0:d1d36a3da39b 204
asong 1:e4b38d6918ba 205 /* Instantiate the Hexi KW40Z Driver (UART TX, UART RX) */
nbaker 0:d1d36a3da39b 206 KW40Z kw40z_device(PTE24, PTE25);
nbaker 0:d1d36a3da39b 207
nbaker 0:d1d36a3da39b 208 /* Define timer for haptic feedback */
nbaker 0:d1d36a3da39b 209 RtosTimer hapticTimer(StopHaptic, osTimerOnce);
nbaker 0:d1d36a3da39b 210
nbaker 4:0803151bc5e4 211 //***************** Interrups *****************
nbaker 9:d2e39ee9fedd 212 InterruptIn Accel_INT1(PTC1); // Accel sensor's interupt 1
nbaker 9:d2e39ee9fedd 213 InterruptIn Accel_INT2(PTD13); // Accel sensor's interupt 2
nbaker 9:d2e39ee9fedd 214 InterruptIn Gyro_INT1(PTD1); // Gyro sensor's interupt 1
nbaker 9:d2e39ee9fedd 215 InterruptIn Gyro_INT2(PTC18); // Gyro sensor's interupt 2
nbaker 9:d2e39ee9fedd 216 //InterruptIn Amb_Light_INT1(PTC0); // TSL2561- Light sensor's interupt
nbaker 9:d2e39ee9fedd 217 //InterruptIn HR_INT1(PTB18); // MAX30101 - Heart rate sensor's interupt
nbaker 9:d2e39ee9fedd 218 //InterruptIn Pressure_INT1(PTD12); // MPL3115A2 pressure sensor's interupt 1
nbaker 9:d2e39ee9fedd 219 //InterruptIn Pressure_INT2(PTD10); // MPL3115A2 pressure sensor's interupt 2
nbaker 4:0803151bc5e4 220
nbaker 0:d1d36a3da39b 221 //***************** Tickers and Timers *****************
nbaker 0:d1d36a3da39b 222 Ticker Screen_Timer;// use ticker to turn off OLED
nbaker 10:eaea844e763c 223 Timer f_time; // Timer used to measure fall
nbaker 10:eaea844e763c 224 Ticker chk_fall; // Ticker used to check on active fall
nbaker 10:eaea844e763c 225 Ticker chk_motion; // Ticker used to check on post fall motion
nbaker 10:eaea844e763c 226 Ticker Haptic_Timer;
nbaker 0:d1d36a3da39b 227
nbaker 4:0803151bc5e4 228 void timout_timer(){ // turn off display mode
nbaker 9:d2e39ee9fedd 229 #ifdef Debug // in debug keep screens on for demo
nbaker 9:d2e39ee9fedd 230 HexiwearBattery battery;
nbaker 9:d2e39ee9fedd 231 battery.sensorOn();
nbaker 9:d2e39ee9fedd 232
nbaker 9:d2e39ee9fedd 233 if (battery.isBatteryCharging() || (uint8_t)battery.readLevelPercent()> 99) {
nbaker 9:d2e39ee9fedd 234 Screen_Timer.attach(&timout_timer,(SCRN_TIME));// Reset/restart ticker timer for OLED while fully charged
nbaker 9:d2e39ee9fedd 235 } //end if
nbaker 9:d2e39ee9fedd 236 else {
nbaker 9:d2e39ee9fedd 237 #endif
nbaker 4:0803151bc5e4 238 // oled.FillScreen(COLOR_BLACK); // Clear screen.. is there a better command for this?
nbaker 4:0803151bc5e4 239 OLED_PWR = 0; // Turn off OLED power supply
nbaker 4:0803151bc5e4 240 OLED_ON = 0; // set flag to off
nbaker 4:0803151bc5e4 241 Screen_Timer.detach(); // detach Ticker
nbaker 9:d2e39ee9fedd 242 #ifdef Debug // in debug keep screens on for demo
nbaker 9:d2e39ee9fedd 243 } // endelse
nbaker 9:d2e39ee9fedd 244 #endif
asong 1:e4b38d6918ba 245 }//end routine
asong 1:e4b38d6918ba 246
nbaker 0:d1d36a3da39b 247 void ButtonUp(void)
nbaker 0:d1d36a3da39b 248 {
asong 1:e4b38d6918ba 249 Screen_Timer.attach(&timout_timer,(SCRN_TIME));//Is this sufficient to reset/restart ticker timer for OLED?
asong 1:e4b38d6918ba 250 if (OLED_ON == 0) {
asong 1:e4b38d6918ba 251 OLED_ON = 1; // Scree was off, set to On
asong 1:e4b38d6918ba 252 update_display();
asong 1:e4b38d6918ba 253 } else {
asong 1:e4b38d6918ba 254 switch(Screen_Num) {
asong 1:e4b38d6918ba 255 case 0: {// We're in Main Screen
asong 1:e4b38d6918ba 256 // do nothing, wrong button
asong 1:e4b38d6918ba 257 break;
asong 1:e4b38d6918ba 258 }
asong 1:e4b38d6918ba 259 case 1: {// Panic Alert option
asong 1:e4b38d6918ba 260 StartHaptic();
nbaker 8:a5c77b45008d 261 Screen_Num = 5; //Change to screen 5
nbaker 0:d1d36a3da39b 262 #ifdef Debug // in debug show debug/diagnostic screens
asong 1:e4b38d6918ba 263 Screen_Num = 26; //Change to screen 20
nbaker 0:d1d36a3da39b 264 #endif
nbaker 0:d1d36a3da39b 265
asong 1:e4b38d6918ba 266 update_display();
asong 1:e4b38d6918ba 267 break;
asong 1:e4b38d6918ba 268 }
asong 1:e4b38d6918ba 269 case 2: {// Fall Alert option
asong 1:e4b38d6918ba 270 StartHaptic();
nbaker 8:a5c77b45008d 271 Screen_Num = 71; //Change to screen 71
asong 1:e4b38d6918ba 272 update_display();
asong 1:e4b38d6918ba 273 break;
asong 1:e4b38d6918ba 274 }
asong 1:e4b38d6918ba 275 case 3: {// Heart Rate Monitoring option
asong 1:e4b38d6918ba 276 StartHaptic();
asong 1:e4b38d6918ba 277 Screen_Num = 2; //Change to screen 2
asong 1:e4b38d6918ba 278 update_display();
asong 1:e4b38d6918ba 279 break;
asong 1:e4b38d6918ba 280 }
asong 1:e4b38d6918ba 281 case 4: {// Alert History option
asong 1:e4b38d6918ba 282 StartHaptic();
asong 1:e4b38d6918ba 283 Screen_Num = 3; //Change to screen 3
asong 1:e4b38d6918ba 284 update_display();
asong 1:e4b38d6918ba 285 break;
asong 1:e4b38d6918ba 286 }
asong 1:e4b38d6918ba 287 case 5: {// About HexiHeart
asong 1:e4b38d6918ba 288 StartHaptic();
asong 1:e4b38d6918ba 289 Screen_Num = 4; //Change to screen 4
asong 1:e4b38d6918ba 290 update_display();
asong 1:e4b38d6918ba 291 break;
asong 1:e4b38d6918ba 292 }
asong 1:e4b38d6918ba 293 case 6: {// Panic Alert
asong 1:e4b38d6918ba 294 StartHaptic();
asong 1:e4b38d6918ba 295 Panic_Alert = !Panic_Alert;
nbaker 10:eaea844e763c 296 if(Panic_Alert == 1){
nbaker 10:eaea844e763c 297 Send_Alert(0); // send/store alert type zero
nbaker 10:eaea844e763c 298 }//endif
asong 1:e4b38d6918ba 299 update_display();
asong 1:e4b38d6918ba 300 break;
asong 1:e4b38d6918ba 301 }
asong 1:e4b38d6918ba 302 case 7: {// Heart Rate Zone
asong 1:e4b38d6918ba 303 StartHaptic(50);
asong 2:824ed4ae8d52 304 Enable_Heart_Rate();
asong 1:e4b38d6918ba 305 //heart.enable();
asong 1:e4b38d6918ba 306 //HR_Enable = 1;
asong 1:e4b38d6918ba 307 //while(HR_Enable == 1)
asong 1:e4b38d6918ba 308 // heart.readRawData(HR_buff, HR_return);
asong 1:e4b38d6918ba 309 //update_display();
asong 1:e4b38d6918ba 310 break;
asong 1:e4b38d6918ba 311 }
asong 1:e4b38d6918ba 312 case 8: {// Alert History
asong 1:e4b38d6918ba 313 StartHaptic();
asong 1:e4b38d6918ba 314 //Increment alert index
asong 1:e4b38d6918ba 315 break;
asong 1:e4b38d6918ba 316 }
nbaker 8:a5c77b45008d 317 case 9: {// HexiHeart About info1
nbaker 8:a5c77b45008d 318 StartHaptic();
nbaker 8:a5c77b45008d 319 Screen_Num = 11; //Change to screen 11
nbaker 8:a5c77b45008d 320 update_display();
nbaker 8:a5c77b45008d 321 break;
nbaker 8:a5c77b45008d 322 }
nbaker 8:a5c77b45008d 323 case 10: {// HexiHeart About info2
nbaker 8:a5c77b45008d 324 StartHaptic();
nbaker 8:a5c77b45008d 325 Screen_Num = 9; //Change to screen 9
nbaker 8:a5c77b45008d 326 update_display();
nbaker 8:a5c77b45008d 327 break;
nbaker 8:a5c77b45008d 328 }
nbaker 8:a5c77b45008d 329 case 11: {// HexiHeart About info3
nbaker 8:a5c77b45008d 330 StartHaptic();
nbaker 8:a5c77b45008d 331 Screen_Num = 10; //Change to screen 9
nbaker 8:a5c77b45008d 332 update_display();
nbaker 8:a5c77b45008d 333 break;
nbaker 8:a5c77b45008d 334 }
asong 1:e4b38d6918ba 335 case 20: {// Diagnostic/Debug Screens
asong 1:e4b38d6918ba 336 StartHaptic();
asong 1:e4b38d6918ba 337 Screen_Num = 5; //Change to screen 5
asong 1:e4b38d6918ba 338 update_display();
asong 1:e4b38d6918ba 339 break;
asong 1:e4b38d6918ba 340 }
asong 1:e4b38d6918ba 341 case 21: {// Fall Diagnostic
asong 1:e4b38d6918ba 342 StartHaptic();
asong 1:e4b38d6918ba 343 Screen_Num = 25; //Change to screen 25
asong 1:e4b38d6918ba 344 update_display();
asong 1:e4b38d6918ba 345 break;
asong 1:e4b38d6918ba 346 }
asong 1:e4b38d6918ba 347 case 22: {// Fall Debug
asong 1:e4b38d6918ba 348 StartHaptic();
asong 1:e4b38d6918ba 349 Screen_Num = 21; //Change to screen 21
asong 1:e4b38d6918ba 350 update_display();
asong 1:e4b38d6918ba 351 break;
asong 1:e4b38d6918ba 352 }
asong 1:e4b38d6918ba 353 case 23: {// Heart Rate Diagnostic
asong 1:e4b38d6918ba 354 StartHaptic();
asong 1:e4b38d6918ba 355 Screen_Num = 22; //Change to screen 22
asong 1:e4b38d6918ba 356 update_display();
asong 1:e4b38d6918ba 357 break;
asong 1:e4b38d6918ba 358 }
asong 1:e4b38d6918ba 359 case 24: {// Heart Rate Debug
asong 1:e4b38d6918ba 360 StartHaptic();
asong 1:e4b38d6918ba 361 Screen_Num = 23; //Change to screen 23
asong 1:e4b38d6918ba 362 update_display();
asong 1:e4b38d6918ba 363 break;
asong 1:e4b38d6918ba 364 }
asong 1:e4b38d6918ba 365 case 25: {// Heat Index Diagnostic
asong 1:e4b38d6918ba 366 StartHaptic();
asong 1:e4b38d6918ba 367 Screen_Num = 24; //Change to screen 24
asong 1:e4b38d6918ba 368 update_display();
asong 1:e4b38d6918ba 369 break;
asong 1:e4b38d6918ba 370 }
asong 1:e4b38d6918ba 371 case 26: {//Heart Rate Config Option
asong 1:e4b38d6918ba 372 StartHaptic();
asong 1:e4b38d6918ba 373 Screen_Num = 20;
asong 1:e4b38d6918ba 374 update_display();
asong 1:e4b38d6918ba 375 break;
asong 1:e4b38d6918ba 376 }
asong 1:e4b38d6918ba 377 case 27: {//Incrementing Age
asong 2:824ed4ae8d52 378 Increment_Age();
asong 2:824ed4ae8d52 379 Set_Zone_Boundaries();
asong 1:e4b38d6918ba 380 update_display();
asong 1:e4b38d6918ba 381 break;
asong 1:e4b38d6918ba 382 }
asong 1:e4b38d6918ba 383 case 28: {//Changing Heart Rate Vibration Preferences
asong 2:824ed4ae8d52 384 Increment_HR_Vibr_Pref();
asong 1:e4b38d6918ba 385 update_display();
asong 1:e4b38d6918ba 386 break;
asong 1:e4b38d6918ba 387 }
asong 1:e4b38d6918ba 388 case 30: {//Change Target Heart Rate Zone Preference
asong 2:824ed4ae8d52 389 Increment_Target_Zone();
asong 2:824ed4ae8d52 390 update_display();
asong 2:824ed4ae8d52 391 break;
asong 2:824ed4ae8d52 392 }
asong 2:824ed4ae8d52 393 case 31: { //Manually Increment Heart Rate by 1
asong 2:824ed4ae8d52 394 Increment_Heart_Rate();
asong 2:824ed4ae8d52 395 Determine_Current_Zone();
asong 1:e4b38d6918ba 396 update_display();
asong 1:e4b38d6918ba 397 break;
asong 1:e4b38d6918ba 398 }
nbaker 8:a5c77b45008d 399
nbaker 10:eaea844e763c 400 case 41: {//Fall mode 0,1,2,3,4,5
nbaker 10:eaea844e763c 401 // 0=nothing, 1=fall_only, 2=impact only, 3=motion_only, 4=all, 5=main sequence
nbaker 8:a5c77b45008d 402 StartHaptic();
nbaker 8:a5c77b45008d 403 Fall_Alert_Mode++;
nbaker 10:eaea844e763c 404 if(Fall_Alert_Mode > 5){
nbaker 8:a5c77b45008d 405 Fall_Alert_Mode = 0;
nbaker 8:a5c77b45008d 406 }//endif
nbaker 8:a5c77b45008d 407 update_display();
nbaker 8:a5c77b45008d 408 __disable_irq(); // Disable all Interrupts
nbaker 9:d2e39ee9fedd 409 fall_config(10); // reset accel sensor
nbaker 10:eaea844e763c 410 //gyro_sensor_config(10); // reset gyro sensor
nbaker 8:a5c77b45008d 411 wait(0.1);
nbaker 10:eaea844e763c 412 //gyro_sensor_config(Fall_Alert_Mode); // leave gyro sensor active
nbaker 8:a5c77b45008d 413 fall_config(Fall_Alert_Mode);
nbaker 8:a5c77b45008d 414 wait(0.1);
nbaker 8:a5c77b45008d 415 __enable_irq(); // Enable all Interrupts
nbaker 8:a5c77b45008d 416 wait(0.3);
nbaker 8:a5c77b45008d 417 update_display();
nbaker 8:a5c77b45008d 418 break;
nbaker 8:a5c77b45008d 419 }
nbaker 8:a5c77b45008d 420 case 42: {// F-Th adj
nbaker 8:a5c77b45008d 421 StartHaptic();
nbaker 9:d2e39ee9fedd 422 Fall_Thresh = Fall_Thresh + 0.05f;
nbaker 9:d2e39ee9fedd 423 if(Fall_Thresh > 0.9f){
nbaker 8:a5c77b45008d 424 Fall_Thresh = 0.9;
nbaker 8:a5c77b45008d 425 }//endif
nbaker 8:a5c77b45008d 426 update_display();
nbaker 8:a5c77b45008d 427 break;
nbaker 8:a5c77b45008d 428 }
nbaker 8:a5c77b45008d 429 case 43: {// I-Th adj
nbaker 8:a5c77b45008d 430 StartHaptic();
nbaker 9:d2e39ee9fedd 431 Impact_Thresh = Impact_Thresh + 0.1f;
nbaker 9:d2e39ee9fedd 432 if(Impact_Thresh > 3.9f){
nbaker 8:a5c77b45008d 433 Impact_Thresh = 3.9;
nbaker 8:a5c77b45008d 434 }//endif
nbaker 8:a5c77b45008d 435 update_display();
nbaker 8:a5c77b45008d 436 break;
nbaker 8:a5c77b45008d 437 }
nbaker 8:a5c77b45008d 438 case 44: {// M-Th adj
nbaker 8:a5c77b45008d 439 StartHaptic();
nbaker 9:d2e39ee9fedd 440 Movement_Thresh = Movement_Thresh + 5.0f;
nbaker 9:d2e39ee9fedd 441 if(Movement_Thresh > 300.0f){
nbaker 8:a5c77b45008d 442 Movement_Thresh = 300.0;
nbaker 8:a5c77b45008d 443 }//endif
nbaker 8:a5c77b45008d 444 update_display();
nbaker 8:a5c77b45008d 445 break;
nbaker 8:a5c77b45008d 446 }
nbaker 9:d2e39ee9fedd 447 case 45: {// Min_Movement_Time adj
nbaker 9:d2e39ee9fedd 448 StartHaptic();
nbaker 9:d2e39ee9fedd 449 Min_Movement_Time = Min_Movement_Time + 0.1f;
nbaker 9:d2e39ee9fedd 450 if(Min_Movement_Time > 2.4f){
nbaker 9:d2e39ee9fedd 451 Min_Movement_Time = 2.4;
nbaker 9:d2e39ee9fedd 452 }//endif
nbaker 9:d2e39ee9fedd 453 update_display();
nbaker 9:d2e39ee9fedd 454 break;
nbaker 9:d2e39ee9fedd 455 }
nbaker 9:d2e39ee9fedd 456 case 46: {// Min_Movement_duration adj
nbaker 9:d2e39ee9fedd 457 StartHaptic();
nbaker 9:d2e39ee9fedd 458 Min_Movement_duration = Min_Movement_duration + 5.0f;
nbaker 9:d2e39ee9fedd 459 if(Min_Movement_duration > 300.0f){
nbaker 9:d2e39ee9fedd 460 Min_Movement_duration = 300.0;
nbaker 9:d2e39ee9fedd 461 }//endif
nbaker 9:d2e39ee9fedd 462 update_display();
nbaker 9:d2e39ee9fedd 463 break;
nbaker 9:d2e39ee9fedd 464 }
nbaker 8:a5c77b45008d 465
nbaker 8:a5c77b45008d 466 case 71: {// BLE
nbaker 8:a5c77b45008d 467 StartHaptic();
nbaker 8:a5c77b45008d 468 Screen_Num = 1; //Change to screen 1
nbaker 8:a5c77b45008d 469 update_display();
nbaker 8:a5c77b45008d 470 break;
nbaker 8:a5c77b45008d 471 }
nbaker 8:a5c77b45008d 472 case 72: {// BlueTooth on/off
nbaker 8:a5c77b45008d 473 // do nothing, wrong button or change to another screen number if you're making more BLE type screens
nbaker 8:a5c77b45008d 474 break;
nbaker 8:a5c77b45008d 475 }
asong 1:e4b38d6918ba 476 default: {
asong 1:e4b38d6918ba 477 break;
asong 1:e4b38d6918ba 478 }
asong 1:e4b38d6918ba 479 }
nbaker 0:d1d36a3da39b 480 }
asong 1:e4b38d6918ba 481
nbaker 0:d1d36a3da39b 482 }
nbaker 0:d1d36a3da39b 483
nbaker 0:d1d36a3da39b 484 void ButtonDown(void)
nbaker 0:d1d36a3da39b 485 {
asong 1:e4b38d6918ba 486 Screen_Timer.attach(&timout_timer,(SCRN_TIME));//Is this sufficient to reset/restart ticker timer for OLED?
asong 1:e4b38d6918ba 487 if (OLED_ON == 0) {
asong 1:e4b38d6918ba 488 OLED_ON = 1; // Screen was off, set to On
asong 1:e4b38d6918ba 489 update_display();
asong 1:e4b38d6918ba 490 } else {
nbaker 0:d1d36a3da39b 491
asong 1:e4b38d6918ba 492 switch(Screen_Num) {
asong 1:e4b38d6918ba 493 case 0: {// We're in Main Screen
asong 1:e4b38d6918ba 494 // do nothing, wrong button
asong 1:e4b38d6918ba 495 break;
asong 1:e4b38d6918ba 496 }
asong 1:e4b38d6918ba 497 case 1: {// Panic Alert option
asong 1:e4b38d6918ba 498 StartHaptic();
nbaker 8:a5c77b45008d 499 Screen_Num = 71; //Change to screen 71
asong 1:e4b38d6918ba 500 update_display();
asong 1:e4b38d6918ba 501 break;
asong 1:e4b38d6918ba 502 }
asong 1:e4b38d6918ba 503 case 2: {// Fall Alert option
asong 1:e4b38d6918ba 504 StartHaptic();
asong 1:e4b38d6918ba 505 Screen_Num = 3; //Change to screen 3
asong 1:e4b38d6918ba 506 update_display();
asong 1:e4b38d6918ba 507 break;
asong 1:e4b38d6918ba 508 }
asong 1:e4b38d6918ba 509 case 3: {// Heart Rate Monitoring option
asong 1:e4b38d6918ba 510 StartHaptic();
asong 1:e4b38d6918ba 511 Screen_Num = 4; //Change to screen 4
asong 1:e4b38d6918ba 512 update_display();
asong 1:e4b38d6918ba 513 break;
asong 1:e4b38d6918ba 514 }
asong 1:e4b38d6918ba 515 case 4: {// Alert History option
asong 1:e4b38d6918ba 516 StartHaptic();
asong 1:e4b38d6918ba 517 Screen_Num = 5; //Change to screen 5
asong 1:e4b38d6918ba 518 update_display();
asong 1:e4b38d6918ba 519 break;
asong 1:e4b38d6918ba 520 }
asong 1:e4b38d6918ba 521 case 5: {// About HexiHeart option
asong 1:e4b38d6918ba 522 StartHaptic();
asong 1:e4b38d6918ba 523 Screen_Num = 26; //Change to screen 1
nbaker 0:d1d36a3da39b 524 #ifdef Debug // in debug show debug/diagnostic screens
asong 1:e4b38d6918ba 525 Screen_Num = 20; //Change to screen 20
nbaker 0:d1d36a3da39b 526 #endif
asong 1:e4b38d6918ba 527 update_display();
asong 1:e4b38d6918ba 528 break;
asong 1:e4b38d6918ba 529 }
asong 1:e4b38d6918ba 530 case 6: {// Panic Alert
asong 1:e4b38d6918ba 531 // do nothing, wrong button
asong 1:e4b38d6918ba 532 break;
asong 1:e4b38d6918ba 533 }
asong 1:e4b38d6918ba 534 case 7: {// Heart Rate Zone
asong 1:e4b38d6918ba 535 StartHaptic(100);
asong 2:824ed4ae8d52 536 Disable_Heart_Rate();
asong 1:e4b38d6918ba 537 break;
asong 1:e4b38d6918ba 538 }
asong 1:e4b38d6918ba 539 case 8: {// Alert History
asong 1:e4b38d6918ba 540 StartHaptic();
asong 1:e4b38d6918ba 541 //decriment alert index
asong 1:e4b38d6918ba 542 break;
asong 1:e4b38d6918ba 543 }
nbaker 8:a5c77b45008d 544 case 9: {// HexiHeart About info1
nbaker 8:a5c77b45008d 545 StartHaptic();
nbaker 8:a5c77b45008d 546 Screen_Num = 10; //Change to screen 10
nbaker 8:a5c77b45008d 547 update_display();
nbaker 8:a5c77b45008d 548 break;
nbaker 8:a5c77b45008d 549 }
nbaker 8:a5c77b45008d 550 case 10: {// HexiHeart About info2
nbaker 8:a5c77b45008d 551 StartHaptic();
nbaker 8:a5c77b45008d 552 Screen_Num = 11; //Change to screen 11
nbaker 8:a5c77b45008d 553 update_display();
nbaker 8:a5c77b45008d 554 break;
nbaker 8:a5c77b45008d 555 }
nbaker 8:a5c77b45008d 556 case 11: {// HexiHeart About info3
nbaker 8:a5c77b45008d 557 StartHaptic();
nbaker 8:a5c77b45008d 558 Screen_Num = 9; //Change to screen 9
nbaker 8:a5c77b45008d 559 update_display();
nbaker 8:a5c77b45008d 560 break;
nbaker 8:a5c77b45008d 561 }
asong 1:e4b38d6918ba 562 case 20: {// Diagnostic/Debug Screens
asong 1:e4b38d6918ba 563 StartHaptic();
asong 1:e4b38d6918ba 564 Screen_Num = 26; //Change to screen 1
asong 1:e4b38d6918ba 565 update_display();
asong 1:e4b38d6918ba 566 break;
asong 1:e4b38d6918ba 567 }
asong 1:e4b38d6918ba 568 case 21: {// Fall Diagnostic
asong 1:e4b38d6918ba 569 StartHaptic();
asong 1:e4b38d6918ba 570 Screen_Num = 22; //Change to screen 22
asong 1:e4b38d6918ba 571 update_display();
asong 1:e4b38d6918ba 572 break;
asong 1:e4b38d6918ba 573 }
asong 1:e4b38d6918ba 574 case 22: {// Fall Debug
asong 1:e4b38d6918ba 575 StartHaptic();
asong 1:e4b38d6918ba 576 Screen_Num = 23; //Change to screen 23
asong 1:e4b38d6918ba 577 update_display();
asong 1:e4b38d6918ba 578 break;
asong 1:e4b38d6918ba 579 }
asong 1:e4b38d6918ba 580 case 23: {// Heart Rate Diagnostic
asong 1:e4b38d6918ba 581 StartHaptic();
asong 1:e4b38d6918ba 582 Screen_Num = 24; //Change to screen 24
asong 1:e4b38d6918ba 583 update_display();
asong 1:e4b38d6918ba 584 break;
asong 1:e4b38d6918ba 585 }
asong 1:e4b38d6918ba 586 case 24: {// Heart Rate Debug
asong 1:e4b38d6918ba 587 StartHaptic();
asong 1:e4b38d6918ba 588 Screen_Num = 25; //Change to screen 25
asong 1:e4b38d6918ba 589 update_display();
asong 1:e4b38d6918ba 590 break;
asong 1:e4b38d6918ba 591 }
asong 1:e4b38d6918ba 592 case 25: {// Heat Index Diagnostic
asong 1:e4b38d6918ba 593 StartHaptic();
asong 1:e4b38d6918ba 594 Screen_Num = 21; //Change to screen 21
asong 1:e4b38d6918ba 595 update_display();
asong 1:e4b38d6918ba 596 break;
asong 1:e4b38d6918ba 597 }
asong 1:e4b38d6918ba 598 case 26: {//Heart Rate Configs
asong 1:e4b38d6918ba 599 StartHaptic();
asong 1:e4b38d6918ba 600 Screen_Num = 1;
asong 1:e4b38d6918ba 601 update_display();
asong 1:e4b38d6918ba 602 break;
asong 1:e4b38d6918ba 603 }
asong 1:e4b38d6918ba 604 case 27: { //Decrement Age
asong 2:824ed4ae8d52 605 Decrement_Age();
asong 2:824ed4ae8d52 606 Set_Zone_Boundaries();
asong 1:e4b38d6918ba 607 update_display();
asong 1:e4b38d6918ba 608 break;
asong 1:e4b38d6918ba 609
asong 1:e4b38d6918ba 610 }
asong 1:e4b38d6918ba 611 case 28: { //Changing Heart Rate Vibration Preference
asong 2:824ed4ae8d52 612 /*
asong 2:824ed4ae8d52 613 StartHaptic();
asong 2:824ed4ae8d52 614 if(HR_Vibration == 1) {
asong 2:824ed4ae8d52 615 HR_Vibration = 3;
asong 2:824ed4ae8d52 616 } else {
asong 2:824ed4ae8d52 617 HR_Vibration -= 1;
asong 2:824ed4ae8d52 618 }
asong 2:824ed4ae8d52 619 */
asong 2:824ed4ae8d52 620 Decrement_HR_Vibr_Pref();
asong 1:e4b38d6918ba 621 update_display();
asong 1:e4b38d6918ba 622 break;
asong 1:e4b38d6918ba 623 }
asong 1:e4b38d6918ba 624 case 30: {//Change Target Heart Rate Zone Preference
asong 2:824ed4ae8d52 625 Decrement_Target_Zone();
asong 2:824ed4ae8d52 626 update_display();
asong 2:824ed4ae8d52 627 break;
asong 2:824ed4ae8d52 628 }
asong 2:824ed4ae8d52 629 case 31: { //Manually decrement heart rate by 1
asong 2:824ed4ae8d52 630 Decrement_Heart_Rate();
asong 2:824ed4ae8d52 631 Determine_Current_Zone();
asong 1:e4b38d6918ba 632 update_display();
asong 1:e4b38d6918ba 633 break;
asong 1:e4b38d6918ba 634 }
nbaker 10:eaea844e763c 635 case 41: {//Fall mode 0,1,2,3,4,5
nbaker 10:eaea844e763c 636 // 0=nothing, 1=fall_only, 2=impact only, 3=motion_only, 4=all, 5=main sequence
nbaker 9:d2e39ee9fedd 637 StartHaptic();
nbaker 8:a5c77b45008d 638 Fall_Alert_Mode--;
nbaker 10:eaea844e763c 639 if(Fall_Alert_Mode > 5){// should be 0xff if decr from zero
nbaker 10:eaea844e763c 640 Fall_Alert_Mode = 5;
nbaker 8:a5c77b45008d 641 } //endif
nbaker 8:a5c77b45008d 642 update_display();
nbaker 8:a5c77b45008d 643 __disable_irq(); // Disable all Interrupts
nbaker 9:d2e39ee9fedd 644 fall_config(10); // reset accel sensor
nbaker 10:eaea844e763c 645 //gyro_sensor_config(10); // reset gyro sensor
nbaker 8:a5c77b45008d 646 wait(0.1);
nbaker 10:eaea844e763c 647 //gyro_sensor_config(Fall_Alert_Mode); // leave gyro sensor active
nbaker 8:a5c77b45008d 648 fall_config(Fall_Alert_Mode);
nbaker 8:a5c77b45008d 649 wait(0.1);
nbaker 8:a5c77b45008d 650 __enable_irq(); // Enable all Interrupts
nbaker 8:a5c77b45008d 651 wait(0.2);
nbaker 8:a5c77b45008d 652 update_display();
nbaker 8:a5c77b45008d 653 break;
nbaker 8:a5c77b45008d 654 }
nbaker 8:a5c77b45008d 655 case 42: {// F-Th adj
nbaker 8:a5c77b45008d 656 StartHaptic();
nbaker 9:d2e39ee9fedd 657 Fall_Thresh = Fall_Thresh - 0.05f;
nbaker 9:d2e39ee9fedd 658 if(Fall_Thresh < 0.1f){
nbaker 8:a5c77b45008d 659 Fall_Thresh = 0.1;
nbaker 8:a5c77b45008d 660 }//endif
nbaker 8:a5c77b45008d 661 update_display();
nbaker 8:a5c77b45008d 662 break;
nbaker 8:a5c77b45008d 663 }
nbaker 8:a5c77b45008d 664 case 43: {// I-Th adj
nbaker 8:a5c77b45008d 665 StartHaptic();
nbaker 9:d2e39ee9fedd 666 Impact_Thresh = Impact_Thresh - 0.1f;
nbaker 9:d2e39ee9fedd 667 if(Impact_Thresh < 0.9f){
nbaker 8:a5c77b45008d 668 Impact_Thresh = 0.9;
nbaker 8:a5c77b45008d 669 }//endif
nbaker 8:a5c77b45008d 670 update_display();
nbaker 8:a5c77b45008d 671 break;
nbaker 8:a5c77b45008d 672 }
nbaker 8:a5c77b45008d 673 case 44: {// M-Th adj
nbaker 8:a5c77b45008d 674 StartHaptic();
nbaker 9:d2e39ee9fedd 675 Movement_Thresh = Movement_Thresh - 5.0f;
nbaker 9:d2e39ee9fedd 676 if(Movement_Thresh < 5.0f){
nbaker 8:a5c77b45008d 677 Movement_Thresh = 5.0;
nbaker 8:a5c77b45008d 678 }//endif
nbaker 8:a5c77b45008d 679 update_display();
nbaker 8:a5c77b45008d 680 break;
nbaker 8:a5c77b45008d 681 }
nbaker 9:d2e39ee9fedd 682 case 45: {// Min_Movement_Time adj
nbaker 9:d2e39ee9fedd 683 StartHaptic();
nbaker 9:d2e39ee9fedd 684 Min_Movement_Time = Min_Movement_Time - 0.1f;
nbaker 9:d2e39ee9fedd 685 if(Min_Movement_Time < 0.5f){
nbaker 9:d2e39ee9fedd 686 Min_Movement_Time = 0.5;
nbaker 9:d2e39ee9fedd 687 }//endif
nbaker 9:d2e39ee9fedd 688 update_display();
nbaker 9:d2e39ee9fedd 689 break;
nbaker 9:d2e39ee9fedd 690 }
nbaker 9:d2e39ee9fedd 691 case 46: {// Min_Movement_duration adj
nbaker 9:d2e39ee9fedd 692 StartHaptic();
nbaker 9:d2e39ee9fedd 693 Min_Movement_duration = Min_Movement_duration - 5.0f;
nbaker 9:d2e39ee9fedd 694 if(Min_Movement_duration < 5.0f){
nbaker 9:d2e39ee9fedd 695 Min_Movement_duration = 5.0;
nbaker 9:d2e39ee9fedd 696 }//endif
nbaker 9:d2e39ee9fedd 697 update_display();
nbaker 9:d2e39ee9fedd 698 break;
nbaker 9:d2e39ee9fedd 699 }
nbaker 9:d2e39ee9fedd 700
nbaker 8:a5c77b45008d 701 case 71: {// BLE
nbaker 8:a5c77b45008d 702 StartHaptic();
nbaker 8:a5c77b45008d 703 Screen_Num = 2; //Change to screen 2
nbaker 8:a5c77b45008d 704 update_display();
nbaker 8:a5c77b45008d 705 break;
nbaker 8:a5c77b45008d 706 }
nbaker 8:a5c77b45008d 707 case 72: {// BlueTooth on/off
nbaker 8:a5c77b45008d 708 // do nothing, wrong button or change to another screen number if you're making more BLE type screens
nbaker 8:a5c77b45008d 709 break;
nbaker 8:a5c77b45008d 710 }
nbaker 8:a5c77b45008d 711
asong 1:e4b38d6918ba 712 default: {
asong 1:e4b38d6918ba 713 break;
asong 1:e4b38d6918ba 714 }
asong 1:e4b38d6918ba 715 }
nbaker 0:d1d36a3da39b 716 }
nbaker 0:d1d36a3da39b 717 }
nbaker 0:d1d36a3da39b 718
nbaker 0:d1d36a3da39b 719 void ButtonRight(void)
nbaker 0:d1d36a3da39b 720 {
asong 1:e4b38d6918ba 721 Screen_Timer.attach(&timout_timer,(SCRN_TIME));//Is this sufficient to reset/restart ticker timer for OLED?
asong 1:e4b38d6918ba 722 if (OLED_ON == 0) {
asong 1:e4b38d6918ba 723 OLED_ON = 1; // Screen was off, set to On
asong 1:e4b38d6918ba 724 update_display();
asong 1:e4b38d6918ba 725 } else {
asong 1:e4b38d6918ba 726 switch(Screen_Num) {
asong 1:e4b38d6918ba 727 case 0: {// We're in Main Screen
asong 1:e4b38d6918ba 728 StartHaptic();
asong 1:e4b38d6918ba 729 Screen_Num = 1; //Change to screen 1
asong 1:e4b38d6918ba 730 update_display();
asong 1:e4b38d6918ba 731 break;
asong 1:e4b38d6918ba 732 }
asong 1:e4b38d6918ba 733 case 1: {// Panic Alert option
asong 1:e4b38d6918ba 734 StartHaptic();
asong 1:e4b38d6918ba 735 Screen_Num = 6; //Change to screen 6
asong 1:e4b38d6918ba 736 update_display();
asong 1:e4b38d6918ba 737 break;
asong 1:e4b38d6918ba 738 }
asong 1:e4b38d6918ba 739 case 2: {// Fall Alert option
asong 1:e4b38d6918ba 740 StartHaptic();
nbaker 4:0803151bc5e4 741 if(Fall_Alert == 1){
nbaker 4:0803151bc5e4 742 Fall_Alert = 0;
nbaker 10:eaea844e763c 743 fall_config(0); // configure sensors for standby
nbaker 4:0803151bc5e4 744 }
nbaker 4:0803151bc5e4 745 else{
nbaker 10:eaea844e763c 746 //Accel_INT1.fall(&fall_detect); // Accel sensor's int#1 calls interupt routine
nbaker 4:0803151bc5e4 747 Fall_Alert = 1;
nbaker 10:eaea844e763c 748 fall_config(Fall_Alert_Mode); // configure sensors for current fall mode
nbaker 4:0803151bc5e4 749 }
nbaker 4:0803151bc5e4 750 update_display();
asong 1:e4b38d6918ba 751 break;
asong 1:e4b38d6918ba 752 }
asong 1:e4b38d6918ba 753 case 3: {// Heart Rate Monitoring option
asong 1:e4b38d6918ba 754 StartHaptic();
asong 1:e4b38d6918ba 755 Screen_Num = 7; //Change to screen 7
asong 1:e4b38d6918ba 756 update_display();
asong 1:e4b38d6918ba 757 break;
asong 1:e4b38d6918ba 758 }
asong 1:e4b38d6918ba 759 case 4: {// Alert History option
asong 1:e4b38d6918ba 760 StartHaptic();
asong 1:e4b38d6918ba 761 Screen_Num = 8; //Change to screen 8
asong 1:e4b38d6918ba 762 update_display();
asong 1:e4b38d6918ba 763 break;
asong 1:e4b38d6918ba 764 }
asong 1:e4b38d6918ba 765 case 5: {// About HexiHeart option
asong 1:e4b38d6918ba 766 StartHaptic();
asong 1:e4b38d6918ba 767 Screen_Num = 9; //Change to screen 9
asong 1:e4b38d6918ba 768 update_display();
asong 1:e4b38d6918ba 769 break;
asong 1:e4b38d6918ba 770 }
nbaker 0:d1d36a3da39b 771
asong 1:e4b38d6918ba 772 case 6: {// Panic Alert
asong 1:e4b38d6918ba 773 // do nothing, wrong button
asong 1:e4b38d6918ba 774 break;
asong 1:e4b38d6918ba 775 }
asong 1:e4b38d6918ba 776 case 7: {// Heart Rate Zone
asong 1:e4b38d6918ba 777 StartHaptic();
asong 2:824ed4ae8d52 778 Screen_Num = 31;
asong 2:824ed4ae8d52 779 update_display();
asong 1:e4b38d6918ba 780 break;
asong 1:e4b38d6918ba 781 }
asong 1:e4b38d6918ba 782 case 20: {// Diagnostic/Debug Screens
asong 1:e4b38d6918ba 783 StartHaptic();
asong 1:e4b38d6918ba 784 Screen_Num = 21; //Change to screen 21
asong 1:e4b38d6918ba 785 update_display();
asong 1:e4b38d6918ba 786 break;
asong 1:e4b38d6918ba 787 }
nbaker 8:a5c77b45008d 788 case 22: {// Fall Debug
nbaker 8:a5c77b45008d 789 StartHaptic();
nbaker 8:a5c77b45008d 790 Screen_Num = 41; //Change to screen 41
nbaker 8:a5c77b45008d 791 update_display();
nbaker 8:a5c77b45008d 792 break;
nbaker 8:a5c77b45008d 793 }
asong 1:e4b38d6918ba 794 case 26: {//Change to Heart Rate Config Screen
asong 1:e4b38d6918ba 795 StartHaptic();
asong 1:e4b38d6918ba 796 Screen_Num = 27;
asong 1:e4b38d6918ba 797 update_display();
asong 1:e4b38d6918ba 798 break;
asong 1:e4b38d6918ba 799 }
asong 1:e4b38d6918ba 800 case 27: {//Change to Heart Rate Vibration Preferences
asong 1:e4b38d6918ba 801 StartHaptic();
asong 1:e4b38d6918ba 802 Screen_Num = 28;
asong 1:e4b38d6918ba 803 update_display();
asong 1:e4b38d6918ba 804 break;
asong 1:e4b38d6918ba 805 }
asong 1:e4b38d6918ba 806 case 28: {//Change to Heart Rate Zone Boundary Info
asong 1:e4b38d6918ba 807 StartHaptic();
asong 1:e4b38d6918ba 808 Screen_Num = 29;
asong 1:e4b38d6918ba 809 update_display();
asong 1:e4b38d6918ba 810 break;
asong 1:e4b38d6918ba 811 }
asong 2:824ed4ae8d52 812 case 29: {//Change Target Heart Rate Zone Preference
asong 1:e4b38d6918ba 813 StartHaptic();
asong 1:e4b38d6918ba 814 Screen_Num = 30;
asong 1:e4b38d6918ba 815 update_display();
asong 1:e4b38d6918ba 816 break;
asong 1:e4b38d6918ba 817 }
asong 1:e4b38d6918ba 818 case 30: {//Change to Heart Rate Config Screen
asong 1:e4b38d6918ba 819 StartHaptic();
asong 1:e4b38d6918ba 820 Screen_Num = 27;
asong 1:e4b38d6918ba 821 update_display();
asong 1:e4b38d6918ba 822 break;
asong 1:e4b38d6918ba 823 }
asong 2:824ed4ae8d52 824 case 31: {
asong 2:824ed4ae8d52 825 StartHaptic();
asong 2:824ed4ae8d52 826 Screen_Num = 32;
asong 2:824ed4ae8d52 827 update_display();
asong 2:824ed4ae8d52 828 break;
asong 2:824ed4ae8d52 829 }
asong 2:824ed4ae8d52 830 case 32: {
asong 2:824ed4ae8d52 831 StartHaptic();
asong 2:824ed4ae8d52 832 Screen_Num = 7;
asong 2:824ed4ae8d52 833 update_display();
asong 2:824ed4ae8d52 834 break;
asong 2:824ed4ae8d52 835 }
nbaker 8:a5c77b45008d 836 case 41: {// Fall-Mode adj
nbaker 8:a5c77b45008d 837 StartHaptic();
nbaker 8:a5c77b45008d 838 Screen_Num = 42; //Change to screen 42
nbaker 8:a5c77b45008d 839 update_display();
nbaker 8:a5c77b45008d 840 break;
nbaker 8:a5c77b45008d 841 }
nbaker 8:a5c77b45008d 842 case 42: {// F-Th adj
nbaker 8:a5c77b45008d 843 StartHaptic();
nbaker 8:a5c77b45008d 844 Screen_Num = 43; //Change to screen 43
nbaker 8:a5c77b45008d 845 update_display();
nbaker 8:a5c77b45008d 846 break;
nbaker 8:a5c77b45008d 847 }
nbaker 8:a5c77b45008d 848 case 43: {// I-Th adj
nbaker 8:a5c77b45008d 849 StartHaptic();
nbaker 8:a5c77b45008d 850 Screen_Num = 44; //Change to screen 44
nbaker 8:a5c77b45008d 851 update_display();
nbaker 8:a5c77b45008d 852 break;
nbaker 8:a5c77b45008d 853 }
nbaker 8:a5c77b45008d 854 case 44: {// M-Th adj
nbaker 9:d2e39ee9fedd 855 StartHaptic();
nbaker 9:d2e39ee9fedd 856 Screen_Num = 45; //Change to screen 44
nbaker 9:d2e39ee9fedd 857 update_display();
nbaker 8:a5c77b45008d 858 break;
nbaker 8:a5c77b45008d 859 }
nbaker 9:d2e39ee9fedd 860 case 45: {// Min_time adj
nbaker 9:d2e39ee9fedd 861 StartHaptic();
nbaker 9:d2e39ee9fedd 862 Screen_Num = 46; //Change to screen 44
nbaker 9:d2e39ee9fedd 863 update_display();
nbaker 9:d2e39ee9fedd 864 break;
nbaker 9:d2e39ee9fedd 865 }
nbaker 9:d2e39ee9fedd 866 case 46: {// Time_dur adj
nbaker 9:d2e39ee9fedd 867 //do nothing for now
nbaker 9:d2e39ee9fedd 868 break;
nbaker 9:d2e39ee9fedd 869 }
nbaker 10:eaea844e763c 870 case 47: {// Fall-Detected screen "are you ok?"
nbaker 10:eaea844e763c 871 StartHaptic();
nbaker 10:eaea844e763c 872 Send_Alert(1); // send/store alert type one
nbaker 10:eaea844e763c 873 Screen_Num = 48; //Change to screen 48 (send alert screen)
nbaker 10:eaea844e763c 874 update_display();
nbaker 10:eaea844e763c 875 break;
nbaker 10:eaea844e763c 876 }
nbaker 8:a5c77b45008d 877 case 71: {// BLE
nbaker 8:a5c77b45008d 878 StartHaptic();
nbaker 8:a5c77b45008d 879 Screen_Num = 72; //Change to screen 72
nbaker 8:a5c77b45008d 880 update_display();
nbaker 8:a5c77b45008d 881 break;
nbaker 8:a5c77b45008d 882 }
nbaker 8:a5c77b45008d 883 case 72: {// BlueTooth on/off
nbaker 8:a5c77b45008d 884 StartHaptic();
nbaker 8:a5c77b45008d 885 BLE_On = !BLE_On;
nbaker 8:a5c77b45008d 886 update_display();
nbaker 8:a5c77b45008d 887 break;
nbaker 8:a5c77b45008d 888 }
nbaker 8:a5c77b45008d 889
asong 1:e4b38d6918ba 890 default: {
asong 1:e4b38d6918ba 891 break;
asong 1:e4b38d6918ba 892 }
asong 1:e4b38d6918ba 893 }
nbaker 0:d1d36a3da39b 894 }
nbaker 0:d1d36a3da39b 895 }
nbaker 0:d1d36a3da39b 896
nbaker 0:d1d36a3da39b 897 void ButtonLeft(void)
nbaker 0:d1d36a3da39b 898 {
asong 1:e4b38d6918ba 899 Screen_Timer.attach(&timout_timer,(SCRN_TIME));//Is this sufficient to reset/restart ticker timer for OLED?
asong 1:e4b38d6918ba 900 if (OLED_ON == 0) {
asong 1:e4b38d6918ba 901 OLED_ON = 1; // Screen was off, set to On
asong 1:e4b38d6918ba 902 update_display();
asong 1:e4b38d6918ba 903 } else {
asong 1:e4b38d6918ba 904 switch(Screen_Num) {
asong 1:e4b38d6918ba 905 case 0: {// We're in Main Screen
asong 1:e4b38d6918ba 906 // do nothing, wrong button
asong 1:e4b38d6918ba 907 break;
asong 1:e4b38d6918ba 908 }
asong 1:e4b38d6918ba 909 case 1: {// Panic Alert option
asong 1:e4b38d6918ba 910 StartHaptic();
asong 1:e4b38d6918ba 911 Screen_Num = 0; //Change to screen 0
asong 1:e4b38d6918ba 912 update_display();
asong 1:e4b38d6918ba 913 break;
asong 1:e4b38d6918ba 914 }
asong 1:e4b38d6918ba 915 case 2: {// Fall Alert option
asong 1:e4b38d6918ba 916 StartHaptic();
asong 1:e4b38d6918ba 917 Screen_Num = 0; //Change to screen 0
asong 1:e4b38d6918ba 918 update_display();
asong 1:e4b38d6918ba 919 break;
asong 1:e4b38d6918ba 920 }
asong 1:e4b38d6918ba 921 case 3: {// Heart Rate Monitoring option
asong 1:e4b38d6918ba 922 StartHaptic();
asong 1:e4b38d6918ba 923 Screen_Num = 0; //Change to screen 0
asong 1:e4b38d6918ba 924 update_display();
asong 1:e4b38d6918ba 925 break;
asong 1:e4b38d6918ba 926 }
asong 1:e4b38d6918ba 927 case 4: {// Alert History option
asong 1:e4b38d6918ba 928 StartHaptic();
asong 1:e4b38d6918ba 929 Screen_Num = 0; //Change to screen 0
asong 1:e4b38d6918ba 930 update_display();
asong 1:e4b38d6918ba 931 break;
asong 1:e4b38d6918ba 932 }
asong 1:e4b38d6918ba 933 case 5: {// About HexiHeart option
asong 1:e4b38d6918ba 934 StartHaptic();
asong 1:e4b38d6918ba 935 Screen_Num = 0; //Change to screen 0
asong 1:e4b38d6918ba 936 update_display();
asong 1:e4b38d6918ba 937 break;
asong 1:e4b38d6918ba 938 }
asong 1:e4b38d6918ba 939 case 6: {// Panic Alert
asong 1:e4b38d6918ba 940 StartHaptic();
asong 1:e4b38d6918ba 941 Screen_Num = 1; //Change to screen 1
asong 1:e4b38d6918ba 942 update_display();
asong 1:e4b38d6918ba 943 break;
asong 1:e4b38d6918ba 944 }
asong 1:e4b38d6918ba 945 case 7: {// Heart Rate Zone
asong 1:e4b38d6918ba 946 StartHaptic();
asong 1:e4b38d6918ba 947 Screen_Num = 3; //Change to screen 3
asong 1:e4b38d6918ba 948 update_display();
asong 1:e4b38d6918ba 949 break;
asong 1:e4b38d6918ba 950 }
asong 1:e4b38d6918ba 951 case 8: {// Alert History
asong 1:e4b38d6918ba 952 StartHaptic();
asong 1:e4b38d6918ba 953 Screen_Num = 4; //Change to screen 4
asong 1:e4b38d6918ba 954 update_display();
asong 1:e4b38d6918ba 955 break;
asong 1:e4b38d6918ba 956 }
nbaker 8:a5c77b45008d 957 case 9: {// About HexiHeart info1
nbaker 8:a5c77b45008d 958 StartHaptic();
nbaker 8:a5c77b45008d 959 Screen_Num = 5; //Change to screen 5
nbaker 8:a5c77b45008d 960 update_display();
nbaker 8:a5c77b45008d 961 break;
nbaker 8:a5c77b45008d 962 }
nbaker 8:a5c77b45008d 963 case 10: {// HexiHeart About info2
nbaker 8:a5c77b45008d 964 StartHaptic();
nbaker 8:a5c77b45008d 965 Screen_Num = 5; //Change to screen 5
nbaker 8:a5c77b45008d 966 update_display();
nbaker 8:a5c77b45008d 967 break;
nbaker 8:a5c77b45008d 968 }
nbaker 8:a5c77b45008d 969 case 11: {// HexiHeart About info3
nbaker 8:a5c77b45008d 970 StartHaptic();
nbaker 8:a5c77b45008d 971 Screen_Num = 5; //Change to screen 5
nbaker 8:a5c77b45008d 972 update_display();
nbaker 8:a5c77b45008d 973 break;
nbaker 8:a5c77b45008d 974 }
asong 1:e4b38d6918ba 975 case 20: {// Diagnostic/Debug Screens
asong 1:e4b38d6918ba 976 StartHaptic();
asong 1:e4b38d6918ba 977 Screen_Num = 0; //Change to screen 0
asong 1:e4b38d6918ba 978 update_display();
asong 1:e4b38d6918ba 979 break;
asong 1:e4b38d6918ba 980 }
asong 1:e4b38d6918ba 981 case 21: {// Fall Diagnostic
asong 1:e4b38d6918ba 982 StartHaptic();
asong 1:e4b38d6918ba 983 Screen_Num = 20; //Change to screen 20
asong 1:e4b38d6918ba 984 update_display();
asong 1:e4b38d6918ba 985 break;
asong 1:e4b38d6918ba 986 }
asong 1:e4b38d6918ba 987 case 22: {// Fall Debug
asong 1:e4b38d6918ba 988 StartHaptic();
asong 1:e4b38d6918ba 989 Screen_Num = 20; //Change to screen 20
asong 1:e4b38d6918ba 990 update_display();
asong 1:e4b38d6918ba 991 break;
asong 1:e4b38d6918ba 992 }
asong 1:e4b38d6918ba 993 case 23: {// Heart Rate Diagnostic
asong 1:e4b38d6918ba 994 StartHaptic();
asong 1:e4b38d6918ba 995 Screen_Num = 20; //Change to screen 20
asong 1:e4b38d6918ba 996 update_display();
asong 1:e4b38d6918ba 997 break;
asong 1:e4b38d6918ba 998 }
asong 1:e4b38d6918ba 999 case 24: {// Heart Rate Debug
asong 1:e4b38d6918ba 1000 StartHaptic();
asong 1:e4b38d6918ba 1001 Screen_Num = 20; //Change to screen 20
asong 1:e4b38d6918ba 1002 update_display();
asong 1:e4b38d6918ba 1003 break;
asong 1:e4b38d6918ba 1004 }
asong 1:e4b38d6918ba 1005 case 25: {// Heat Index Diagnostic
asong 1:e4b38d6918ba 1006 StartHaptic();
asong 1:e4b38d6918ba 1007 Screen_Num = 20; //Change to screen 20
asong 1:e4b38d6918ba 1008 update_display();
asong 1:e4b38d6918ba 1009 break;
asong 1:e4b38d6918ba 1010 }
asong 1:e4b38d6918ba 1011 case 26: {//Heart Rate Config Option
asong 1:e4b38d6918ba 1012 StartHaptic();
asong 1:e4b38d6918ba 1013 Screen_Num = 0;
asong 1:e4b38d6918ba 1014 update_display();
asong 1:e4b38d6918ba 1015 break;
asong 1:e4b38d6918ba 1016 }
asong 1:e4b38d6918ba 1017 case 27: {//Enter Age
asong 1:e4b38d6918ba 1018 StartHaptic();
asong 1:e4b38d6918ba 1019 Screen_Num = 26;
asong 1:e4b38d6918ba 1020 update_display();
asong 1:e4b38d6918ba 1021 break;
asong 1:e4b38d6918ba 1022 }
asong 1:e4b38d6918ba 1023 case 28: {//Heart Rate Vibration Preference Screen
asong 1:e4b38d6918ba 1024 StartHaptic();
asong 1:e4b38d6918ba 1025 Screen_Num = 27;
asong 1:e4b38d6918ba 1026 update_display();
asong 1:e4b38d6918ba 1027 break;
asong 1:e4b38d6918ba 1028 }
asong 1:e4b38d6918ba 1029 case 29: {//Heart Rate Zone Boundary Info
asong 1:e4b38d6918ba 1030 StartHaptic();
asong 1:e4b38d6918ba 1031 Screen_Num = 28;
asong 1:e4b38d6918ba 1032 update_display();
asong 1:e4b38d6918ba 1033 break;
asong 1:e4b38d6918ba 1034 }
asong 2:824ed4ae8d52 1035 case 30: {//Change Target Heart Rate Zone Preference
asong 1:e4b38d6918ba 1036 StartHaptic();
asong 1:e4b38d6918ba 1037 Screen_Num = 29;
asong 1:e4b38d6918ba 1038 update_display();
asong 1:e4b38d6918ba 1039 break;
asong 1:e4b38d6918ba 1040 }
asong 2:824ed4ae8d52 1041 case 31: {
asong 2:824ed4ae8d52 1042 StartHaptic();
asong 2:824ed4ae8d52 1043 Screen_Num = 7;
asong 2:824ed4ae8d52 1044 update_display();
asong 2:824ed4ae8d52 1045 break;
asong 2:824ed4ae8d52 1046 }
asong 2:824ed4ae8d52 1047 case 32: {
asong 2:824ed4ae8d52 1048 StartHaptic();
asong 2:824ed4ae8d52 1049 Screen_Num = 31;
asong 2:824ed4ae8d52 1050 update_display();
asong 2:824ed4ae8d52 1051 break;
asong 2:824ed4ae8d52 1052 }
nbaker 8:a5c77b45008d 1053 case 41: {// Fall mode screen
nbaker 8:a5c77b45008d 1054 StartHaptic();
nbaker 8:a5c77b45008d 1055 Screen_Num = 22;
nbaker 8:a5c77b45008d 1056 update_display();
nbaker 8:a5c77b45008d 1057 break;
nbaker 8:a5c77b45008d 1058 }
nbaker 8:a5c77b45008d 1059 case 42: {// F-Th adj
nbaker 8:a5c77b45008d 1060 StartHaptic();
nbaker 8:a5c77b45008d 1061 Screen_Num = 41; //Change to screen 41
nbaker 8:a5c77b45008d 1062 update_display();
nbaker 8:a5c77b45008d 1063 break;
nbaker 8:a5c77b45008d 1064 }
nbaker 8:a5c77b45008d 1065 case 43: {// I-Th adj
nbaker 8:a5c77b45008d 1066 StartHaptic();
nbaker 8:a5c77b45008d 1067 Screen_Num = 42; //Change to screen 42
nbaker 8:a5c77b45008d 1068 update_display();
nbaker 8:a5c77b45008d 1069 break;
nbaker 8:a5c77b45008d 1070 }
nbaker 8:a5c77b45008d 1071 case 44: {// M-Th adj
nbaker 8:a5c77b45008d 1072 StartHaptic();
nbaker 8:a5c77b45008d 1073 Screen_Num = 43; //Change to screen 43
nbaker 8:a5c77b45008d 1074 update_display();
nbaker 8:a5c77b45008d 1075 break;
nbaker 9:d2e39ee9fedd 1076 }
nbaker 9:d2e39ee9fedd 1077 case 45: {// M-time adj
nbaker 9:d2e39ee9fedd 1078 StartHaptic();
nbaker 9:d2e39ee9fedd 1079 Screen_Num = 44; //Change to screen 44
nbaker 9:d2e39ee9fedd 1080 update_display();
nbaker 9:d2e39ee9fedd 1081 break;
nbaker 9:d2e39ee9fedd 1082 }
nbaker 9:d2e39ee9fedd 1083 case 46: {// M-dur adj
nbaker 9:d2e39ee9fedd 1084 StartHaptic();
nbaker 9:d2e39ee9fedd 1085 Screen_Num = 45; //Change to screen 45
nbaker 9:d2e39ee9fedd 1086 update_display();
nbaker 9:d2e39ee9fedd 1087 break;
nbaker 10:eaea844e763c 1088 }
nbaker 10:eaea844e763c 1089 case 47: {// Fall-detected screen
nbaker 10:eaea844e763c 1090 StartHaptic();
nbaker 10:eaea844e763c 1091 Led_clk1 = 0; // Turn off LED1, on docking station
nbaker 10:eaea844e763c 1092 Led_clk2 = 0; // Turn off LED2, on docking station
nbaker 10:eaea844e763c 1093 Screen_Num = 0; //Change to screen 0
nbaker 10:eaea844e763c 1094 update_display();
nbaker 10:eaea844e763c 1095 break;
nbaker 10:eaea844e763c 1096 }
nbaker 10:eaea844e763c 1097 case 48: {// Sending Fall-Alert screen
nbaker 10:eaea844e763c 1098 StartHaptic();
nbaker 10:eaea844e763c 1099 Led_clk1 = 0; // Turn off LED1, on docking station
nbaker 10:eaea844e763c 1100 Led_clk2 = 0; // Turn off LED2, on docking station
nbaker 10:eaea844e763c 1101 // stop/dismiss alert
nbaker 10:eaea844e763c 1102 Screen_Num = 0; //Change to screen 0
nbaker 10:eaea844e763c 1103 update_display();
nbaker 10:eaea844e763c 1104 break;
nbaker 10:eaea844e763c 1105 }
nbaker 9:d2e39ee9fedd 1106
nbaker 8:a5c77b45008d 1107 case 71: {// BLE
nbaker 8:a5c77b45008d 1108 StartHaptic();
nbaker 8:a5c77b45008d 1109 Screen_Num = 0; //Change to screen 0
nbaker 8:a5c77b45008d 1110 update_display();
nbaker 8:a5c77b45008d 1111 break;
nbaker 8:a5c77b45008d 1112 }
nbaker 8:a5c77b45008d 1113
nbaker 8:a5c77b45008d 1114 case 72: {// BlueTooth on/off
nbaker 8:a5c77b45008d 1115 StartHaptic();
nbaker 8:a5c77b45008d 1116 Screen_Num = 71; //Change to screen 71
nbaker 8:a5c77b45008d 1117 update_display();
nbaker 8:a5c77b45008d 1118 break;
nbaker 8:a5c77b45008d 1119 }
nbaker 8:a5c77b45008d 1120
asong 1:e4b38d6918ba 1121 default: {
asong 1:e4b38d6918ba 1122 break;
asong 1:e4b38d6918ba 1123 }
asong 1:e4b38d6918ba 1124 }
nbaker 0:d1d36a3da39b 1125 }
nbaker 0:d1d36a3da39b 1126 }
nbaker 0:d1d36a3da39b 1127
nbaker 0:d1d36a3da39b 1128
nbaker 0:d1d36a3da39b 1129 void ButtonSlide(void) // What is this Slide button???
nbaker 0:d1d36a3da39b 1130 {
asong 1:e4b38d6918ba 1131 Screen_Timer.attach(&timout_timer,(SCRN_TIME));//Is this sufficient to reset/restart ticker timer for OLED?
asong 1:e4b38d6918ba 1132 if (OLED_ON == 0) {
asong 1:e4b38d6918ba 1133 OLED_ON = 1; // Screen was off, set to On
asong 1:e4b38d6918ba 1134 }
nbaker 0:d1d36a3da39b 1135 StartHaptic();
nbaker 0:d1d36a3da39b 1136 oled.FillScreen(COLOR_BLACK); // Clear screen
nbaker 0:d1d36a3da39b 1137 strcpy((char *) text_1,"Slide Button");
nbaker 0:d1d36a3da39b 1138 oled.Label((uint8_t *)text_1,0,40);
nbaker 0:d1d36a3da39b 1139 }
asong 1:e4b38d6918ba 1140
nbaker 0:d1d36a3da39b 1141 int main()
nbaker 0:d1d36a3da39b 1142 {
nbaker 7:3d5a8aea0b63 1143 // set_time(1256729737); // Set RTC time to Wed, 28 Oct 2009 11:35:37
nbaker 9:d2e39ee9fedd 1144 // set_time((Year-1970)*365*24*3600+(days of this year)*24*3600+(hr)*3600 + (min)*60 + (Sec) - fudge factor); // Set RTC time to Mon, 19 Feb 2018 10:00
nbaker 10:eaea844e763c 1145 //set_time(48*365*24*3600 + 61*24*3600 + 10*3600-4); // Set RTC time to Mon, 19 Feb 2018 10:00
nbaker 10:eaea844e763c 1146 //set_time((2018-1970)*365.25f*24*3600 + (31+28+1-1)*24*3600 + (16)*3600 + (5)*60+ (1) + 38); // Set RTC time to 3/01/2018 16:04:20
nbaker 10:eaea844e763c 1147 set_time((2018-1970)*365.25f*24*3600 + (31+28+26-1)*24*3600 + (10)*3600 + (0)*60+ (0) + 28); // Set RTC time to 3/26/2018 10:00:00
nbaker 9:d2e39ee9fedd 1148 RED_Led = LED_OFF;
nbaker 9:d2e39ee9fedd 1149 GRN_Led = LED_OFF;
nbaker 9:d2e39ee9fedd 1150 BLU_Led = LED_OFF;
nbaker 9:d2e39ee9fedd 1151 Led_clk1 = 0; // LEDs on docking station default to off, need to turn on with a 1
nbaker 9:d2e39ee9fedd 1152 Led_clk2 = 0; // LEDs on docking station default to off, need to turn on with a 1
nbaker 9:d2e39ee9fedd 1153 Led_clk3 = 0; // LEDs on docking station default to off, need to turn on with a 1
jmr274 5:e1431272be79 1154
nbaker 9:d2e39ee9fedd 1155 // ***************** Reset sensors ***********************
nbaker 9:d2e39ee9fedd 1156 OLED_PWR = 0; // Turn off OLED power supply
nbaker 9:d2e39ee9fedd 1157 PowerEN = 1; // Turn off (=1)HTU21(Temp/Hum) and TSL2561(Light) sensors to reset them
nbaker 9:d2e39ee9fedd 1158 HR_PWR = 0; // Turn off (=0) Heart rate sensor 1.8V and HRM(3.3V) supply to reset
nbaker 9:d2e39ee9fedd 1159 wait(0.2); // how long should we wait for sensors to power down?
jmr274 5:e1431272be79 1160
nbaker 9:d2e39ee9fedd 1161 PowerEN = 0; // Turn on (=0) HTU21(Temp/Hum) and TSL2561(Light) sensors to reset them
nbaker 9:d2e39ee9fedd 1162 HR_PWR = 1; // Turn on (=1)Heart rate sensor
nbaker 9:d2e39ee9fedd 1163 OLED_PWR = 1; // Turn on OLED power supply
nbaker 9:d2e39ee9fedd 1164 wait(0.2); // how long should we wait for sensors to power up?
nbaker 9:d2e39ee9fedd 1165
nbaker 9:d2e39ee9fedd 1166 oled.FillScreen(COLOR_BLACK); // Clear screen
nbaker 10:eaea844e763c 1167 fall_config(10); // SW reset accell and gyro sensor
nbaker 10:eaea844e763c 1168 // gyro_sensor_config(10); // SW reset gyro sensor
nbaker 9:d2e39ee9fedd 1169 press_config(0); // put pressure sensor into 2uA standby, we're not using it
nbaker 9:d2e39ee9fedd 1170 MAX30101_test_config(10); // SW reset accell sensor
nbaker 9:d2e39ee9fedd 1171 oled.FillScreen(COLOR_BLACK); // Clear screen
nbaker 9:d2e39ee9fedd 1172
asong 1:e4b38d6918ba 1173 // ***************** Local variables ***********************
asong 1:e4b38d6918ba 1174 // float accel_data[3]; float accel_rms=0.0;
nbaker 4:0803151bc5e4 1175 int i;
nbaker 4:0803151bc5e4 1176
nbaker 0:d1d36a3da39b 1177 // ************** configure sensor modules ******************
asong 1:e4b38d6918ba 1178
nbaker 10:eaea844e763c 1179 //accel.accel_config(); // original configure accel sensor
nbaker 9:d2e39ee9fedd 1180 fall_config(Fall_Alert_Mode); // configure sensor (I2C1) for current fall mode
nbaker 10:eaea844e763c 1181 //Fall_Alert_Mode: 0=none, 1=fall_only, 2=impact only, 3=motion_only, 4=all three, 5=full sequencial
nbaker 10:eaea844e763c 1182 //gyro.gyro_config(); // original configure gyro sensor
nbaker 10:eaea844e763c 1183 //gyro_sensor_config(Fall_Alert_Mode); // configure gyro sensor (I2C1) 0=standby, 1=active, 2=interupt set up (now setup in fall_config())
nbaker 10:eaea844e763c 1184 //mag.mag_config(); // we don't need mag
nbaker 10:eaea844e763c 1185 //light_config(0); // config TSL2561 ambient light sensor (I2C0) for lowest power - cycling PowerEn should have reset it to state
nbaker 10:eaea844e763c 1186 //Configure HTU21(Temp/Hum)? No need, it seems to draw 0.02uA when not being activly read over data bus
nbaker 8:a5c77b45008d 1187
nbaker 9:d2e39ee9fedd 1188 // need to configure MAX30101 at some point
nbaker 9:d2e39ee9fedd 1189 // MAX30101_test_config(0);
nbaker 9:d2e39ee9fedd 1190
nbaker 9:d2e39ee9fedd 1191
nbaker 0:d1d36a3da39b 1192 // ***** Register callbacks/interupts to application functions *********
nbaker 0:d1d36a3da39b 1193 kw40z_device.attach_buttonUp(&ButtonUp);
nbaker 0:d1d36a3da39b 1194 kw40z_device.attach_buttonDown(&ButtonDown);
nbaker 0:d1d36a3da39b 1195 kw40z_device.attach_buttonLeft(&ButtonLeft);
nbaker 0:d1d36a3da39b 1196 kw40z_device.attach_buttonRight(&ButtonRight);
nbaker 4:0803151bc5e4 1197 // kw40z_device.attach_buttonSlide(&ButtonSlide);
nbaker 4:0803151bc5e4 1198
nbaker 4:0803151bc5e4 1199 // ***** attaching interupts to functions *********
nbaker 10:eaea844e763c 1200 //Accel_INT1.fall(&fall_detect); // Accel sensor's int#1 (PTC1) calls interupt routine (now setup in fall_config())
nbaker 10:eaea844e763c 1201 //Accel_INT2.fall(&impact_detect); //Accel sensor's int#2 (PTD13) calls interupt routine(now setup in fall_config())
nbaker 10:eaea844e763c 1202 //Gyro_INT1.fall(&motion_detect); // Gyro sensor's int#1 (PTD1) calls interupt routine (now setup in fall_config())
nbaker 10:eaea844e763c 1203 //Gyro_INT2.fall(&motion_detect); // Gyro sensor's int#2 (PTC18) calls interupt routine (not used)
nbaker 10:eaea844e763c 1204 //HR_INT1.fall(&some_HR_read_function_yet_to_be_named); // MAX30101 - Heart rate sensor's interupt (PTB18)
nbaker 0:d1d36a3da39b 1205
nbaker 0:d1d36a3da39b 1206 // **** Get OLED Class Default Text Properties ****************
asong 1:e4b38d6918ba 1207 oled_text_properties_t textProperties = {0};
asong 1:e4b38d6918ba 1208 oled.GetTextProperties(&textProperties);
asong 1:e4b38d6918ba 1209
nbaker 0:d1d36a3da39b 1210 // *********Set text color and screen alignment **************
nbaker 9:d2e39ee9fedd 1211 //textProperties.font = OpenSans_12x18_Regular; // Max Width of Character = 12px, Max Height of Character = 18px
nbaker 9:d2e39ee9fedd 1212 //textProperties.font = OpenSans_10x15_Regular; // <-This is default Font, Max Width of Character = 10px, Max Height of Character = 15px
asong 1:e4b38d6918ba 1213 textProperties.fontColor = COLOR_WHITE;
asong 1:e4b38d6918ba 1214 textProperties.alignParam = OLED_TEXT_ALIGN_LEFT;
asong 1:e4b38d6918ba 1215 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 1216
nbaker 0:d1d36a3da39b 1217 // ************** Display spash screen **********************
nbaker 9:d2e39ee9fedd 1218 /*
nbaker 9:d2e39ee9fedd 1219 oled.FillScreen(COLOR_BLACK); // Clear screen
nbaker 9:d2e39ee9fedd 1220 oled.DrawImage(Hexi_Heart_,0,0); // my Hexi_Heart image is offset for some reason
nbaker 9:d2e39ee9fedd 1221 wait(0.5); // wait 3 seconds
nbaker 9:d2e39ee9fedd 1222 */
nbaker 8:a5c77b45008d 1223 oled.FillScreen(COLOR_BLACK); // Clear screen
nbaker 0:d1d36a3da39b 1224 oled.Label((uint8_t *)"Hexi",20,5); // Display white "Hexi" at x,y
nbaker 0:d1d36a3da39b 1225 textProperties.fontColor = COLOR_RED;
asong 1:e4b38d6918ba 1226 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 1227 oled.Label((uint8_t *)"Heart",45,5); // Display red "Heart" at x,y
nbaker 0:d1d36a3da39b 1228
asong 1:e4b38d6918ba 1229 #ifdef Debug // if this is non-production version - do this
nbaker 8:a5c77b45008d 1230 strcpy((char *) text_1,"This is Debug");
nbaker 9:d2e39ee9fedd 1231 oled.Label((uint8_t *)text_1,15,45); // text_1 at x,y
nbaker 9:d2e39ee9fedd 1232 strcpy((char *) text_1,"Ver:");
nbaker 9:d2e39ee9fedd 1233 oled.Label((uint8_t *)text_1,15,60); // text_1 at x,y
nbaker 9:d2e39ee9fedd 1234 sprintf(text_1,"%2.2f ",SW_Ver);
nbaker 9:d2e39ee9fedd 1235 oled.Label((uint8_t *)text_1,60,60);// text_1 at x,y
nbaker 8:a5c77b45008d 1236 StartHaptic();
nbaker 8:a5c77b45008d 1237 #endif
nbaker 8:a5c77b45008d 1238
nbaker 0:d1d36a3da39b 1239 textProperties.fontColor = COLOR_WHITE;
nbaker 0:d1d36a3da39b 1240 oled.SetTextProperties(&textProperties);
nbaker 9:d2e39ee9fedd 1241 wait(2); // wait 3 seconds
nbaker 9:d2e39ee9fedd 1242
nbaker 9:d2e39ee9fedd 1243
asong 1:e4b38d6918ba 1244 update_display(); // Displays current screen (screen 0)
nbaker 0:d1d36a3da39b 1245 Screen_Timer.attach(&timout_timer,(SCRN_TIME));//start ticker timer for turning off LCD
asong 1:e4b38d6918ba 1246 // ******************* Main Loop *************************
nbaker 0:d1d36a3da39b 1247 while (true) {
nbaker 4:0803151bc5e4 1248 i=0;
nbaker 4:0803151bc5e4 1249 while (i<20)// used for "Heart beat flash and updated any displayed data)
nbaker 4:0803151bc5e4 1250 {
nbaker 4:0803151bc5e4 1251 Thread::wait(500); // wait 0.5 sec each loop
nbaker 4:0803151bc5e4 1252 if(OLED_PWR==1){
nbaker 8:a5c77b45008d 1253 update_display_date(); // refresh display date w/o updating entire display
nbaker 4:0803151bc5e4 1254 }// end if
nbaker 9:d2e39ee9fedd 1255
nbaker 4:0803151bc5e4 1256 i++;
nbaker 4:0803151bc5e4 1257 }// end while(i<20)
jmr274 5:e1431272be79 1258
nbaker 4:0803151bc5e4 1259 // wait(10); // wait 10 sec each loop, was orig half sec
nbaker 4:0803151bc5e4 1260 RED_Led = LED_ON; // Used only for diagnostic of wait command
nbaker 4:0803151bc5e4 1261 Led_clk3 = 1; // Used only for diagnostic of wait command
nbaker 4:0803151bc5e4 1262 wait(0.01); // BLIP led 1/10 sec each loop
nbaker 9:d2e39ee9fedd 1263 /// VLPW(0.01); // BLIP led 1/10 sec each loop
nbaker 4:0803151bc5e4 1264 RED_Led = LED_OFF; // Used only for diagnostic of wait command
nbaker 4:0803151bc5e4 1265 Led_clk3 = 0;
nbaker 8:a5c77b45008d 1266 Thread::wait(490); // keep up the pace, at 0.5 sec (0.01s+0.49s) update date
nbaker 9:d2e39ee9fedd 1267
nbaker 4:0803151bc5e4 1268 } // end of while(true)
nbaker 4:0803151bc5e4 1269
nbaker 0:d1d36a3da39b 1270 }
nbaker 0:d1d36a3da39b 1271 // ************** end of main()
nbaker 0:d1d36a3da39b 1272
nbaker 0:d1d36a3da39b 1273 void update_display(void)
nbaker 0:d1d36a3da39b 1274 {
nbaker 4:0803151bc5e4 1275 OLED_PWR = 1; // make sure OLED power supply is on
asong 1:e4b38d6918ba 1276 oled_text_properties_t textProperties = {0}; // Need these to change font color
asong 1:e4b38d6918ba 1277 oled.GetTextProperties(&textProperties); // Need these to change font color
nbaker 8:a5c77b45008d 1278 __disable_irq(); // Disable all Interrupts
asong 1:e4b38d6918ba 1279 switch(Screen_Num) {
asong 1:e4b38d6918ba 1280 case 0: {// Main Screen
nbaker 4:0803151bc5e4 1281 HexiwearBattery battery;
nbaker 4:0803151bc5e4 1282 battery.sensorOn();
asong 1:e4b38d6918ba 1283 oled.FillScreen(COLOR_BLACK); // Clear screen
nbaker 4:0803151bc5e4 1284
nbaker 4:0803151bc5e4 1285 if (battery.isBatteryCharging()) {
nbaker 4:0803151bc5e4 1286 textProperties.fontColor = COLOR_GREEN;
nbaker 4:0803151bc5e4 1287 oled.SetTextProperties(&textProperties);
nbaker 4:0803151bc5e4 1288 // sprintf(text_1, "%s", "chrg");
nbaker 4:0803151bc5e4 1289 sprintf(text_1, "%i%%+", (uint8_t)battery.readLevelPercent());
nbaker 4:0803151bc5e4 1290 Screen_Timer.attach(&timout_timer,(SCRN_TIME));// Reset/restart ticker timer for OLED while fully charged
nbaker 4:0803151bc5e4 1291 } else {
nbaker 4:0803151bc5e4 1292 sprintf(text_1, "%i%%", (uint8_t)battery.readLevelPercent());
nbaker 4:0803151bc5e4 1293 }
nbaker 8:a5c77b45008d 1294 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 1295
nbaker 4:0803151bc5e4 1296 textProperties.fontColor = COLOR_WHITE;
nbaker 4:0803151bc5e4 1297 oled.SetTextProperties(&textProperties);
nbaker 4:0803151bc5e4 1298
nbaker 4:0803151bc5e4 1299 oled.Label((uint8_t *)"Batt",35,0); // Display "Batt" at x,y
nbaker 9:d2e39ee9fedd 1300 // oled.Label((uint8_t *)"Date",35,20); // Display "Date" at x,y
nbaker 9:d2e39ee9fedd 1301 // oled.Label((uint8_t *)"Time",35,40); // Display "Time" at x,y
jmr274 5:e1431272be79 1302 // oled.Label((uint8_t *)"H.I.",10,80); // Display "H.I." at x,y
nbaker 7:3d5a8aea0b63 1303
asong 1:e4b38d6918ba 1304 oled.Label((uint8_t *)"BT",40,80); //Display "BT" at x,y
asong 1:e4b38d6918ba 1305 oled.Label((uint8_t *)"Menu",60,80); //Display "Menu" at x,y
jmr274 5:e1431272be79 1306
nbaker 7:3d5a8aea0b63 1307 textProperties.fontColor = COLOR_GRAY;
nbaker 8:a5c77b45008d 1308 if(BLE_On == 1){
nbaker 9:d2e39ee9fedd 1309 textProperties.fontColor = COLOR_BLUE; // If BLE on make "BT" blue!
nbaker 8:a5c77b45008d 1310 }
nbaker 7:3d5a8aea0b63 1311 oled.SetTextProperties(&textProperties);
nbaker 8:a5c77b45008d 1312
nbaker 7:3d5a8aea0b63 1313 oled.Label((uint8_t *)"BT",40,80); //Display "BT" at x,y
nbaker 7:3d5a8aea0b63 1314 textProperties.fontColor = COLOR_WHITE;
nbaker 7:3d5a8aea0b63 1315 oled.SetTextProperties(&textProperties);
nbaker 10:eaea844e763c 1316
nbaker 10:eaea844e763c 1317 textProperties.fontColor = COLOR_GRAY;
nbaker 10:eaea844e763c 1318 if(Fall_Alert == 1){
nbaker 10:eaea844e763c 1319 textProperties.fontColor = COLOR_GREEN; // is Fall protection on?
nbaker 10:eaea844e763c 1320 }
nbaker 10:eaea844e763c 1321 if(Fall_Alert == 1 && Led_clk1 == 1){
nbaker 10:eaea844e763c 1322 textProperties.fontColor = COLOR_YELLOW; // is Fall detected?
nbaker 10:eaea844e763c 1323 }
nbaker 10:eaea844e763c 1324 if(Fall_Alert == 1 && Led_clk1 == 1 && Led_clk2 == 1){
nbaker 10:eaea844e763c 1325 textProperties.fontColor = COLOR_RED; // is impact detected?
nbaker 10:eaea844e763c 1326 }
nbaker 10:eaea844e763c 1327 oled.SetTextProperties(&textProperties);
nbaker 10:eaea844e763c 1328 oled.Label((uint8_t *)"FAP",1,0); //Display "FAP" at x,y
nbaker 10:eaea844e763c 1329 textProperties.fontColor = COLOR_WHITE;
nbaker 10:eaea844e763c 1330 oled.SetTextProperties(&textProperties);
nbaker 7:3d5a8aea0b63 1331
nbaker 7:3d5a8aea0b63 1332 // added real time and date information
nbaker 7:3d5a8aea0b63 1333 char buffer[32];
nbaker 7:3d5a8aea0b63 1334 time_t seconds = time(NULL);
nbaker 9:d2e39ee9fedd 1335 strftime(buffer,32, "%a,%d %m %Y.%H:%M:%S\r", localtime(&seconds)); //format local time and store in buffer
nbaker 9:d2e39ee9fedd 1336
nbaker 9:d2e39ee9fedd 1337 textProperties.font = OpenSans_12x18_Regular; // Max Width of Character = 12px, Max Height of Character = 18px
nbaker 9:d2e39ee9fedd 1338 textProperties.fontColor = COLOR_WHITE;
nbaker 9:d2e39ee9fedd 1339 oled.SetTextProperties(&textProperties);
nbaker 9:d2e39ee9fedd 1340
nbaker 7:3d5a8aea0b63 1341 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 9:d2e39ee9fedd 1342 oled.Label((uint8_t *)text_1,15,25);// Date at x,y
nbaker 7:3d5a8aea0b63 1343 sprintf(text_1,"%c%c:%c%c:%c%c ",buffer[15],buffer[16],buffer[18],buffer[19],buffer[21],buffer[22]);
nbaker 7:3d5a8aea0b63 1344 oled.Label((uint8_t *)text_1,25,40);// Time at x,y
nbaker 9:d2e39ee9fedd 1345
nbaker 9:d2e39ee9fedd 1346 textProperties.font = OpenSans_10x15_Regular; // Max Width of Character = 10px, Max Height of Character = 15px
nbaker 9:d2e39ee9fedd 1347 textProperties.fontColor = COLOR_WHITE;
nbaker 9:d2e39ee9fedd 1348 oled.SetTextProperties(&textProperties);
nbaker 9:d2e39ee9fedd 1349
jmr274 5:e1431272be79 1350 Heat_Index_Calculation();
jmr274 5:e1431272be79 1351 sprintf(text,"%i",heat_index);
nbaker 8:a5c77b45008d 1352 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 1353 strcpy((char *) text,"dF");oled.Label((uint8_t *)text,18,80);
jmr274 5:e1431272be79 1354
asong 1:e4b38d6918ba 1355 if(Heart_Rate_Mode == 1) {
asong 1:e4b38d6918ba 1356 oled.Label((uint8_t *)"BPM",35,60); // Display "H.I." at x,y
asong 1:e4b38d6918ba 1357 }
asong 1:e4b38d6918ba 1358 break;
asong 1:e4b38d6918ba 1359 }
asong 1:e4b38d6918ba 1360 case 1: {// Panic Alert option
asong 1:e4b38d6918ba 1361 oled.FillScreen(COLOR_BLACK); // Clear screen
asong 1:e4b38d6918ba 1362 oled.Label((uint8_t *)"Panic Alert",20,5); // Display at x,y
asong 1:e4b38d6918ba 1363 oled.Label((uint8_t *)"*",85,15); // "*" at x,y
asong 1:e4b38d6918ba 1364 oled.Label((uint8_t *)"*",85,60); // "*" at x,y
asong 1:e4b38d6918ba 1365 oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
asong 1:e4b38d6918ba 1366 oled.Label((uint8_t *)"Enter",60,80); //Display "enter" at x,y
asong 1:e4b38d6918ba 1367 break;
asong 1:e4b38d6918ba 1368 }
asong 1:e4b38d6918ba 1369 case 2: {// Fall Alert option
asong 1:e4b38d6918ba 1370 oled.FillScreen(COLOR_BLACK); // Clear screen
asong 1:e4b38d6918ba 1371 oled.Label((uint8_t *)"Fall Alert",20,5); // Display at x,y
nbaker 9:d2e39ee9fedd 1372 oled.Label((uint8_t *)"Protection",15,20);
nbaker 10:eaea844e763c 1373 oled.Label((uint8_t *)"FAP",15,40);
nbaker 4:0803151bc5e4 1374 if (Fall_Alert == 1){
nbaker 9:d2e39ee9fedd 1375
nbaker 9:d2e39ee9fedd 1376 textProperties.fontColor = COLOR_GREEN;
nbaker 9:d2e39ee9fedd 1377 oled.SetTextProperties(&textProperties);
nbaker 10:eaea844e763c 1378 oled.Label((uint8_t *)" On ",42,40);
nbaker 4:0803151bc5e4 1379 }
nbaker 4:0803151bc5e4 1380 else {
nbaker 9:d2e39ee9fedd 1381 textProperties.fontColor = COLOR_GRAY;
nbaker 9:d2e39ee9fedd 1382 oled.SetTextProperties(&textProperties);
nbaker 10:eaea844e763c 1383 oled.Label((uint8_t *)" Off ",40,40);
nbaker 9:d2e39ee9fedd 1384
nbaker 4:0803151bc5e4 1385 }
nbaker 9:d2e39ee9fedd 1386 textProperties.fontColor = COLOR_WHITE;
nbaker 9:d2e39ee9fedd 1387 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 1388 oled.Label((uint8_t *)"*",85,15); // "*" at x,y
asong 1:e4b38d6918ba 1389 oled.Label((uint8_t *)"*",85,60); // "*" at x,y
asong 1:e4b38d6918ba 1390 oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
nbaker 9:d2e39ee9fedd 1391 oled.Label((uint8_t *)"Toggle",59,80); //Display "Toggle" at x,y
asong 1:e4b38d6918ba 1392 break;
asong 1:e4b38d6918ba 1393 }
asong 1:e4b38d6918ba 1394 case 3: {// Heart Rate Monitoring option
asong 1:e4b38d6918ba 1395 oled.FillScreen(COLOR_BLACK); // Clear screen
asong 1:e4b38d6918ba 1396 oled.Label((uint8_t *)"Heart Rate",20,5); // Display at x,y
asong 1:e4b38d6918ba 1397 oled.Label((uint8_t *)"*",85,15); // "*" at x,y
asong 1:e4b38d6918ba 1398 oled.Label((uint8_t *)"*",85,60); // "*" at x,y
asong 1:e4b38d6918ba 1399 oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
asong 1:e4b38d6918ba 1400 oled.Label((uint8_t *)"Enter",60,80); //Display at x,y
asong 1:e4b38d6918ba 1401 break;
asong 1:e4b38d6918ba 1402 }
asong 1:e4b38d6918ba 1403 case 4: {// Alert History option
asong 1:e4b38d6918ba 1404 oled.FillScreen(COLOR_BLACK); // Clear screen
nbaker 7:3d5a8aea0b63 1405 oled.Label((uint8_t *)"Alert History",10,5); // Display at x,y
asong 1:e4b38d6918ba 1406 oled.Label((uint8_t *)"*",85,15); // "*" at x,y
asong 1:e4b38d6918ba 1407 oled.Label((uint8_t *)"*",85,60); // "*" at x,y
asong 1:e4b38d6918ba 1408 oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
asong 1:e4b38d6918ba 1409 oled.Label((uint8_t *)"Enter",60,80); //Display at x,y
asong 1:e4b38d6918ba 1410 break;
asong 1:e4b38d6918ba 1411 }
asong 1:e4b38d6918ba 1412 case 5: {// About HexiHeart Screen
nbaker 0:d1d36a3da39b 1413
asong 1:e4b38d6918ba 1414 oled.FillScreen(COLOR_BLACK); // Clear screen
asong 1:e4b38d6918ba 1415 oled.Label((uint8_t *)"Hexi",20,20); // Display white "Hexi" at x,y
asong 1:e4b38d6918ba 1416 textProperties.fontColor = COLOR_RED;
asong 1:e4b38d6918ba 1417 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 1418 oled.Label((uint8_t *)"Heart",45,20); // Display red "Heart" at x,y
asong 1:e4b38d6918ba 1419 textProperties.fontColor = COLOR_WHITE;
asong 1:e4b38d6918ba 1420 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 1421 strcpy((char *) text_1,"About");
asong 1:e4b38d6918ba 1422 oled.Label((uint8_t *)text_1,30,5); // text_1 at x,y
asong 1:e4b38d6918ba 1423 oled.Label((uint8_t *)"*",85,15); // "*" at x,y
asong 1:e4b38d6918ba 1424 oled.Label((uint8_t *)"*",85,60); // "*" at x,y
nbaker 9:d2e39ee9fedd 1425 oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
nbaker 9:d2e39ee9fedd 1426 oled.Label((uint8_t *)"Enter",60,80); //Display at x,y
asong 1:e4b38d6918ba 1427 break;
asong 1:e4b38d6918ba 1428 }
asong 1:e4b38d6918ba 1429
asong 1:e4b38d6918ba 1430 case 6: {// Panic Alert
asong 1:e4b38d6918ba 1431 oled.FillScreen(COLOR_BLACK); // Clear screen
asong 1:e4b38d6918ba 1432 if (Panic_Alert == 0) {
asong 1:e4b38d6918ba 1433 oled.Label((uint8_t *)"Send ",20,10); // Display at x,y
asong 1:e4b38d6918ba 1434 } else {
asong 1:e4b38d6918ba 1435 oled.Label((uint8_t *)"Dismiss ",17,10); // Display at x,y
asong 1:e4b38d6918ba 1436 }
asong 1:e4b38d6918ba 1437 oled.Label((uint8_t *)"Panic Alert",15,40); // Display at x,y
asong 1:e4b38d6918ba 1438 oled.Label((uint8_t *)"-->",80,15); // "*" at x,y
asong 1:e4b38d6918ba 1439 oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
asong 1:e4b38d6918ba 1440 break;
asong 1:e4b38d6918ba 1441 }
asong 1:e4b38d6918ba 1442 case 7: {// Heart Rate Zone
asong 1:e4b38d6918ba 1443
asong 1:e4b38d6918ba 1444 oled.FillScreen(COLOR_BLACK); // Clear screen
asong 1:e4b38d6918ba 1445 oled.Label((uint8_t *)"Heart Rate",15,5); // Display at x,y
asong 1:e4b38d6918ba 1446 oled.Label((uint8_t *)"HR:",15,25); // Display at x,y
asong 2:824ed4ae8d52 1447 sprintf(display_buff, "%u", Heart_Rate);
asong 2:824ed4ae8d52 1448 textProperties.fontColor = COLOR_RED; //Change font to red
asong 2:824ed4ae8d52 1449 oled.SetTextProperties(&textProperties);//Implement color change
asong 2:824ed4ae8d52 1450 oled.Label((uint8_t *)display_buff,43,25); // Display at x,y
asong 2:824ed4ae8d52 1451 textProperties.fontColor = COLOR_WHITE;
asong 2:824ed4ae8d52 1452 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 1453 oled.Label((uint8_t *)"Age: ",15,45); // Display at x,y
asong 1:e4b38d6918ba 1454 textProperties.fontColor = COLOR_GREEN;
asong 1:e4b38d6918ba 1455 oled.SetTextProperties(&textProperties); //implements the color change
asong 1:e4b38d6918ba 1456 sprintf(display_buff, "%u", Age); //Convert int to char array for displaying user age
asong 1:e4b38d6918ba 1457 oled.Label((uint8_t *)display_buff,43,45); // Display at x,y
asong 1:e4b38d6918ba 1458 textProperties.fontColor = COLOR_WHITE;
asong 1:e4b38d6918ba 1459 oled.SetTextProperties(&textProperties);
asong 2:824ed4ae8d52 1460 oled.Label((uint8_t *)"On",80,15); // "+" at x,y
asong 2:824ed4ae8d52 1461 oled.Label((uint8_t *)"Off",78,60); // "-" at x,y
asong 1:e4b38d6918ba 1462 oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
nbaker 9:d2e39ee9fedd 1463 oled.Label((uint8_t *)"Next",60,80); // Display "Next" at x,y
asong 2:824ed4ae8d52 1464
asong 1:e4b38d6918ba 1465 //heart.enable();
asong 1:e4b38d6918ba 1466 //sprintf(display_buff, "%u", heart.getRevisionID()); //Convert int to char array for displaying user age
asong 1:e4b38d6918ba 1467 //oled.Label((uint8_t *)display_buff,45,25); // Display at x,y
asong 1:e4b38d6918ba 1468 //update_display();
asong 1:e4b38d6918ba 1469 break;
asong 1:e4b38d6918ba 1470 }
asong 1:e4b38d6918ba 1471 case 8: {// Alert History
asong 1:e4b38d6918ba 1472 oled.FillScreen(COLOR_BLACK); // Clear screen
asong 1:e4b38d6918ba 1473 oled.Label((uint8_t *)"Alert History",5,5); // Display at x,y
asong 1:e4b38d6918ba 1474 oled.Label((uint8_t *)"Date - Time",20,40); // Display at x,y
asong 1:e4b38d6918ba 1475 oled.Label((uint8_t *)"Alert Type:",20,60); // Display at x,y
asong 1:e4b38d6918ba 1476 oled.Label((uint8_t *)"+",85,15); // "*" at x,y
asong 1:e4b38d6918ba 1477 oled.Label((uint8_t *)"-",85,60); // "*" at x,y
asong 1:e4b38d6918ba 1478 oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
asong 1:e4b38d6918ba 1479 break;
asong 1:e4b38d6918ba 1480 }
nbaker 8:a5c77b45008d 1481
nbaker 8:a5c77b45008d 1482 case 9: {// About HexiHeart info1
nbaker 8:a5c77b45008d 1483 oled.FillScreen(COLOR_BLACK); // Clear screen
nbaker 8:a5c77b45008d 1484 oled.Label((uint8_t *)"Hexi",20,1); // Display white "Hexi" at x,y
nbaker 8:a5c77b45008d 1485 textProperties.fontColor = COLOR_RED;
nbaker 8:a5c77b45008d 1486 oled.SetTextProperties(&textProperties);
nbaker 8:a5c77b45008d 1487 oled.Label((uint8_t *)"Heart",45,0); // Display red "Heart" at x,y
nbaker 8:a5c77b45008d 1488 textProperties.fontColor = COLOR_WHITE;
nbaker 8:a5c77b45008d 1489 oled.SetTextProperties(&textProperties);
nbaker 8:a5c77b45008d 1490 oled.Label((uint8_t *)"Senior Proj",5,15); //
nbaker 9:d2e39ee9fedd 1491 oled.Label((uint8_t *)"Team Zeta E2.7",5,30); //
nbaker 8:a5c77b45008d 1492 oled.Label((uint8_t *)"Texas State Univ",0,45); //
nbaker 8:a5c77b45008d 1493 oled.Label((uint8_t *)"+",85,15); // "*" at x,y
nbaker 8:a5c77b45008d 1494 oled.Label((uint8_t *)"-",85,60); // "*" at x,y
nbaker 8:a5c77b45008d 1495 oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
nbaker 8:a5c77b45008d 1496 break;
nbaker 8:a5c77b45008d 1497 }
nbaker 8:a5c77b45008d 1498
nbaker 8:a5c77b45008d 1499 case 10: {// About HexiHeart info2
nbaker 8:a5c77b45008d 1500 oled.FillScreen(COLOR_BLACK); // Clear screen
nbaker 8:a5c77b45008d 1501 oled.Label((uint8_t *)"Hexi",20,0); // Display white "Hexi" at x,y
nbaker 8:a5c77b45008d 1502 textProperties.fontColor = COLOR_RED;
nbaker 8:a5c77b45008d 1503 oled.SetTextProperties(&textProperties);
nbaker 8:a5c77b45008d 1504 oled.Label((uint8_t *)"Heart",45,0); // Display red "Heart" at x,y
nbaker 8:a5c77b45008d 1505 textProperties.fontColor = COLOR_WHITE;
nbaker 8:a5c77b45008d 1506 oled.SetTextProperties(&textProperties);
nbaker 9:d2e39ee9fedd 1507 // oled.Label((uint8_t *)"E2.7 Team Zeta",2,12); //
nbaker 9:d2e39ee9fedd 1508 oled.Label((uint8_t *)"Alex Song",5,12); //
nbaker 9:d2e39ee9fedd 1509 oled.Label((uint8_t *)"Jasmine ",5,24); // Jasmine Rounsaville is to long
nbaker 9:d2e39ee9fedd 1510 oled.Label((uint8_t *)"Rounsaville",15,37); // Jasmine Rounsaville is to long
nbaker 8:a5c77b45008d 1511 oled.Label((uint8_t *)"Issam Hichami",5,51); //
nbaker 8:a5c77b45008d 1512 oled.Label((uint8_t *)"Neil Baker",5,64); //
nbaker 8:a5c77b45008d 1513
nbaker 8:a5c77b45008d 1514 oled.Label((uint8_t *)"+",85,15); // "*" at x,y
nbaker 8:a5c77b45008d 1515 oled.Label((uint8_t *)"-",85,60); // "*" at x,y
nbaker 8:a5c77b45008d 1516 oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
nbaker 8:a5c77b45008d 1517 break;
nbaker 8:a5c77b45008d 1518 }
nbaker 8:a5c77b45008d 1519
nbaker 8:a5c77b45008d 1520 case 11: {// About HexiHeart info3
nbaker 8:a5c77b45008d 1521 oled.FillScreen(COLOR_BLACK); // Clear screen
nbaker 8:a5c77b45008d 1522 oled.Label((uint8_t *)"Hexi",20,0); // Display white "Hexi" at x,y
nbaker 8:a5c77b45008d 1523 textProperties.fontColor = COLOR_RED;
nbaker 8:a5c77b45008d 1524 oled.SetTextProperties(&textProperties);
nbaker 8:a5c77b45008d 1525 oled.Label((uint8_t *)"Heart",45,0); // Display red "Heart" at x,y
nbaker 8:a5c77b45008d 1526 // *********get screen alignment **************
nbaker 8:a5c77b45008d 1527 oled_text_properties_t textProperties = {0};
nbaker 8:a5c77b45008d 1528 oled.GetTextProperties(&textProperties);
nbaker 8:a5c77b45008d 1529 // *********Set text color and screen alignment **************
nbaker 8:a5c77b45008d 1530 textProperties.alignParam = OLED_TEXT_ALIGN_CENTER;
nbaker 8:a5c77b45008d 1531 oled.SetTextProperties(&textProperties);
nbaker 8:a5c77b45008d 1532
nbaker 8:a5c77b45008d 1533 #ifdef Debug // if this is non-production version - do this
nbaker 8:a5c77b45008d 1534 oled.Label((uint8_t *)"This is Debug",0,25); // text_1 at X=10,y=25
nbaker 8:a5c77b45008d 1535 oled.Label((uint8_t *)"Ver of SW",0,40); // text_1 at x=20,y=40
nbaker 8:a5c77b45008d 1536 #endif
nbaker 8:a5c77b45008d 1537 textProperties.fontColor = COLOR_WHITE;
nbaker 8:a5c77b45008d 1538 oled.SetTextProperties(&textProperties);
nbaker 8:a5c77b45008d 1539 sprintf(text_1," SW_Ver:%2.2f ",SW_Ver);
nbaker 8:a5c77b45008d 1540 oled.Label((uint8_t *)text_1,0,55);// text_1 at x=10,y
nbaker 8:a5c77b45008d 1541 textProperties.alignParam = OLED_TEXT_ALIGN_LEFT;
nbaker 8:a5c77b45008d 1542 oled.SetTextProperties(&textProperties);
nbaker 8:a5c77b45008d 1543 oled.Label((uint8_t *)"+",85,15); // "*" at x,y
nbaker 8:a5c77b45008d 1544 oled.Label((uint8_t *)"-",85,60); // "*" at x,y
nbaker 8:a5c77b45008d 1545 oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
nbaker 8:a5c77b45008d 1546 break;
nbaker 8:a5c77b45008d 1547 }
nbaker 8:a5c77b45008d 1548
asong 1:e4b38d6918ba 1549 #ifdef Debug // if this is non-production/debug version - do this
asong 1:e4b38d6918ba 1550 case 20: {// Diagnostic/Debug Screens
asong 1:e4b38d6918ba 1551 oled.FillScreen(COLOR_BLACK); // Clear screen
asong 1:e4b38d6918ba 1552 textProperties.fontColor = COLOR_RED;
asong 1:e4b38d6918ba 1553 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 1554 oled.Label((uint8_t *)"Diagnostics",10,5); // Display at x,y
nbaker 9:d2e39ee9fedd 1555 oled.Label((uint8_t *)"Enter",60,80); //Display at x,y
asong 1:e4b38d6918ba 1556 textProperties.fontColor = COLOR_WHITE;
asong 1:e4b38d6918ba 1557 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 1558 oled.Label((uint8_t *)"*",85,15); // "*" at x,y
asong 1:e4b38d6918ba 1559 oled.Label((uint8_t *)"*",85,60); // "*" at x,y
nbaker 9:d2e39ee9fedd 1560 oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
nbaker 0:d1d36a3da39b 1561
asong 1:e4b38d6918ba 1562 break;
asong 1:e4b38d6918ba 1563 }
asong 1:e4b38d6918ba 1564 case 21: {// Fall Alert Diagnostic Screen
nbaker 8:a5c77b45008d 1565 if(Fall_Alert_Mode == 0){
nbaker 8:a5c77b45008d 1566 fall_config(11); // turn accel sensor to active to take reading
nbaker 8:a5c77b45008d 1567 }
asong 1:e4b38d6918ba 1568 oled.FillScreen(COLOR_BLACK); // Clear screen
asong 1:e4b38d6918ba 1569 textProperties.fontColor = COLOR_RED;
asong 1:e4b38d6918ba 1570 oled.SetTextProperties(&textProperties);
nbaker 7:3d5a8aea0b63 1571 oled.Label((uint8_t *)"Fall-Diag",25,5); // Display at x,y
nbaker 7:3d5a8aea0b63 1572 // oled.Label((uint8_t *)"Diagnostic",25,5); // Display at x,y
asong 1:e4b38d6918ba 1573 textProperties.fontColor = COLOR_WHITE;
asong 1:e4b38d6918ba 1574 oled.SetTextProperties(&textProperties);
nbaker 8:a5c77b45008d 1575 gyro.acquire_gyro_data_dps(Gyro_Data);
nbaker 8:a5c77b45008d 1576 Gyro_Mag = (abs(Gyro_Data[0])+abs(Gyro_Data[1])+abs(Gyro_Data[2]));
asong 1:e4b38d6918ba 1577 accel.acquire_accel_data_g(Accel_Data);
nbaker 8:a5c77b45008d 1578 if(Fall_Alert_Mode == 0){
nbaker 8:a5c77b45008d 1579 fall_config(12); // turn accel sensor to standby
nbaker 8:a5c77b45008d 1580 }
nbaker 8:a5c77b45008d 1581 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 1582 sprintf(text_1," Accel:%2.2f g ",Accel_Mag);
nbaker 9:d2e39ee9fedd 1583 oled.Label((uint8_t *)text_1,5,40);// text_1 at x,y
asong 1:e4b38d6918ba 1584 sprintf(text_1," Gyro:%4.0f D/S ",Gyro_Mag);
nbaker 9:d2e39ee9fedd 1585 oled.Label((uint8_t *)text_1,5,60);// text_1 at x,y
nbaker 8:a5c77b45008d 1586 oled.Label((uint8_t *)"*",85,15); // "*" at x,y
nbaker 8:a5c77b45008d 1587 oled.Label((uint8_t *)"*",85,60); // "*" at x,y
asong 1:e4b38d6918ba 1588 oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
asong 1:e4b38d6918ba 1589 break;
asong 1:e4b38d6918ba 1590 }
asong 1:e4b38d6918ba 1591 case 22: {// Fall Alert Debug Screen
asong 1:e4b38d6918ba 1592 oled.FillScreen(COLOR_BLACK); // Clear screen
asong 1:e4b38d6918ba 1593 textProperties.fontColor = COLOR_RED;
asong 1:e4b38d6918ba 1594 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 1595 oled.Label((uint8_t *)"Fall Debug",15,5); // Display at x,y
asong 1:e4b38d6918ba 1596 textProperties.fontColor = COLOR_GREEN;
asong 1:e4b38d6918ba 1597 oled.SetTextProperties(&textProperties);
nbaker 8:a5c77b45008d 1598 sprintf(text_1," %i ",Fall_Alert_Mode);
nbaker 10:eaea844e763c 1599 oled.Label((uint8_t *)text_1,36,20);// text_1 at x,y
nbaker 8:a5c77b45008d 1600 textProperties.fontColor = COLOR_GRAY;
nbaker 10:eaea844e763c 1601 if(Fall_Alert_Mode == 1 || Fall_Alert_Mode >= 4){
nbaker 9:d2e39ee9fedd 1602 textProperties.fontColor = COLOR_GREEN;
nbaker 8:a5c77b45008d 1603 }
nbaker 8:a5c77b45008d 1604 oled.SetTextProperties(&textProperties);
nbaker 8:a5c77b45008d 1605 sprintf(text_1," %1.2f g ",Fall_Thresh);
asong 1:e4b38d6918ba 1606 oled.Label((uint8_t *)text_1,35,35);// text_1 at x,y
nbaker 8:a5c77b45008d 1607 textProperties.fontColor = COLOR_GRAY;
nbaker 10:eaea844e763c 1608 if(Fall_Alert_Mode == 2 || Fall_Alert_Mode >= 4){
nbaker 9:d2e39ee9fedd 1609 textProperties.fontColor = COLOR_GREEN;
nbaker 8:a5c77b45008d 1610 }
nbaker 8:a5c77b45008d 1611 oled.SetTextProperties(&textProperties);
nbaker 8:a5c77b45008d 1612 sprintf(text_1," %2.2f g ",Impact_Thresh);
nbaker 8:a5c77b45008d 1613 oled.Label((uint8_t *)text_1,35,50);// text_1 at x,y
nbaker 8:a5c77b45008d 1614 textProperties.fontColor = COLOR_GRAY;
nbaker 10:eaea844e763c 1615 if(Fall_Alert_Mode == 3 || Fall_Alert_Mode >= 4){
nbaker 9:d2e39ee9fedd 1616 textProperties.fontColor = COLOR_GREEN;
nbaker 8:a5c77b45008d 1617 }
nbaker 8:a5c77b45008d 1618 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 1619 sprintf(text_1," %3.0f D/S ",Movement_Thresh);
nbaker 8:a5c77b45008d 1620 oled.Label((uint8_t *)text_1,35,65);// text_1 at x,y
asong 1:e4b38d6918ba 1621 textProperties.fontColor = COLOR_WHITE;
asong 1:e4b38d6918ba 1622 oled.SetTextProperties(&textProperties);
nbaker 8:a5c77b45008d 1623 oled.Label((uint8_t *)"Mode:",5,20); // "*" at x,y
nbaker 8:a5c77b45008d 1624 oled.Label((uint8_t *)"F-Th:",5,35); // "*" at x,y
nbaker 8:a5c77b45008d 1625 oled.Label((uint8_t *)"I-Th:",5,50); // "*" at x,y
nbaker 8:a5c77b45008d 1626 oled.Label((uint8_t *)"M-Th:",5,65); // "*" at x,y
asong 1:e4b38d6918ba 1627 oled.Label((uint8_t *)"*",85,15); // "*" at x,y
asong 1:e4b38d6918ba 1628 oled.Label((uint8_t *)"*",85,60); // "*" at x,y
nbaker 9:d2e39ee9fedd 1629 oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
nbaker 9:d2e39ee9fedd 1630 oled.Label((uint8_t *)"Enter",60,80); //Display at x,y
asong 1:e4b38d6918ba 1631 break;
asong 1:e4b38d6918ba 1632 }
asong 1:e4b38d6918ba 1633 case 23: {// Heart Rate Diagnostic Screen
asong 1:e4b38d6918ba 1634 oled.FillScreen(COLOR_BLACK); // Clear screen
asong 1:e4b38d6918ba 1635 textProperties.fontColor = COLOR_RED;
asong 1:e4b38d6918ba 1636 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 1637 oled.Label((uint8_t *)"H.R. Diagnostic",5,5); // Display at x,y
asong 1:e4b38d6918ba 1638 textProperties.fontColor = COLOR_WHITE;
asong 1:e4b38d6918ba 1639 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 1640 oled.Label((uint8_t *)"*",85,15); // "*" at x,y
asong 1:e4b38d6918ba 1641 oled.Label((uint8_t *)"*",85,60); // "*" at x,y
nbaker 9:d2e39ee9fedd 1642 oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
asong 1:e4b38d6918ba 1643 // oled.Label((uint8_t *)" Enter ",59,80); //Display at x,y
asong 1:e4b38d6918ba 1644 break;
asong 1:e4b38d6918ba 1645 }
asong 1:e4b38d6918ba 1646 case 24: {// Heart Rate Debug Screen
asong 1:e4b38d6918ba 1647 oled.FillScreen(COLOR_BLACK); // Clear screen
asong 1:e4b38d6918ba 1648 textProperties.fontColor = COLOR_RED;
asong 1:e4b38d6918ba 1649 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 1650 oled.Label((uint8_t *)"H.R. Debug",10,5); // Display at x,y
asong 1:e4b38d6918ba 1651 textProperties.fontColor = COLOR_WHITE;
asong 1:e4b38d6918ba 1652 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 1653 oled.Label((uint8_t *)"*",85,15); // "*" at x,y
asong 1:e4b38d6918ba 1654 oled.Label((uint8_t *)"*",85,60); // "*" at x,y
nbaker 9:d2e39ee9fedd 1655 oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
asong 1:e4b38d6918ba 1656 // oled.Label((uint8_t *)" Enter ",59,80); //Display at x,y
asong 1:e4b38d6918ba 1657 break;
asong 1:e4b38d6918ba 1658 }
asong 1:e4b38d6918ba 1659 case 25: {// Heat Index Diagnostic Screen
asong 1:e4b38d6918ba 1660 oled.FillScreen(COLOR_BLACK); // Clear screen
asong 1:e4b38d6918ba 1661 textProperties.fontColor = COLOR_RED;
asong 1:e4b38d6918ba 1662 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 1663 oled.Label((uint8_t *)"H.I. Diagnostic",5,5); // Display at x,y
asong 1:e4b38d6918ba 1664 textProperties.fontColor = COLOR_WHITE;
asong 1:e4b38d6918ba 1665 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 1666 oled.Label((uint8_t *)"*",85,15); // "*" at x,y
asong 1:e4b38d6918ba 1667 oled.Label((uint8_t *)"*",85,60); // "*" at x,y
nbaker 9:d2e39ee9fedd 1668 oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
asong 1:e4b38d6918ba 1669 // oled.Label((uint8_t *)" Enter ",59,80); //Display at x,y
jmr274 5:e1431272be79 1670
jmr274 6:84e3ba00b995 1671 Heat_Index_Calculation();
jmr274 5:e1431272be79 1672
jmr274 5:e1431272be79 1673 oled_text_properties_t textProperties = {0};
jmr274 5:e1431272be79 1674 oled.GetTextProperties(&textProperties);
jmr274 5:e1431272be79 1675
jmr274 5:e1431272be79 1676 strcpy((char *) text,"Temp.");
jmr274 5:e1431272be79 1677 oled.Label((uint8_t *)text,5,40);
jmr274 5:e1431272be79 1678 strcpy((char *) text,"Humidity");
jmr274 5:e1431272be79 1679 oled.Label((uint8_t *)text,5,57);
jmr274 5:e1431272be79 1680 strcpy((char *) text,"H.I.");
jmr274 5:e1431272be79 1681 oled.Label((uint8_t *)text,5,23);
jmr274 5:e1431272be79 1682
jmr274 5:e1431272be79 1683 /* Set text properties to white and right aligned for the dynamic text */
jmr274 5:e1431272be79 1684 textProperties.fontColor = COLOR_GREEN;
jmr274 5:e1431272be79 1685 textProperties.alignParam = OLED_TEXT_ALIGN_RIGHT;
jmr274 5:e1431272be79 1686 oled.SetTextProperties(&textProperties);
jmr274 5:e1431272be79 1687
jmr274 5:e1431272be79 1688 /* Format the value */
jmr274 5:e1431272be79 1689 sprintf(text,"%i",sample_ftemp);
jmr274 5:e1431272be79 1690
nbaker 8:a5c77b45008d 1691 /* Display temp reading in 15px by 15px textbox at(x=55, y=40) */
jmr274 5:e1431272be79 1692 oled.TextBox((uint8_t *)text,55,40,15,15); //Increase textbox for more digits
jmr274 5:e1431272be79 1693
jmr274 5:e1431272be79 1694 /* Display Units */
jmr274 5:e1431272be79 1695 strcpy((char *) text,"dF");
jmr274 5:e1431272be79 1696 oled.Label((uint8_t *)text,71,40);
jmr274 5:e1431272be79 1697
jmr274 5:e1431272be79 1698 /* Format the value */
jmr274 5:e1431272be79 1699 sprintf(text,"%i",sample_humid);
jmr274 5:e1431272be79 1700
nbaker 8:a5c77b45008d 1701 /* Display Hum reading in 15px by 15px textbox at(x=55, y=57) */
jmr274 5:e1431272be79 1702 oled.TextBox((uint8_t *)text,55,57,15,15); //Increase textbox for more digits
jmr274 5:e1431272be79 1703
jmr274 5:e1431272be79 1704 /* Display Units */
jmr274 5:e1431272be79 1705 strcpy((char *) text,"%");
jmr274 5:e1431272be79 1706 oled.Label((uint8_t *)text,71,57);
jmr274 5:e1431272be79 1707
jmr274 5:e1431272be79 1708 /* Set text properties to white and right aligned for the dynamic text */
jmr274 5:e1431272be79 1709 textProperties.fontColor = COLOR_BLUE;
jmr274 5:e1431272be79 1710 textProperties.alignParam = OLED_TEXT_ALIGN_RIGHT;
jmr274 5:e1431272be79 1711 oled.SetTextProperties(&textProperties);
jmr274 5:e1431272be79 1712
jmr274 5:e1431272be79 1713 /* Format the value */
jmr274 5:e1431272be79 1714 sprintf(text,"%i",heat_index);
jmr274 5:e1431272be79 1715
nbaker 8:a5c77b45008d 1716 /* Display HI reading in 15px by 15px textbox at(x=55, y=23) */
jmr274 5:e1431272be79 1717 oled.TextBox((uint8_t *)text,55,23,15,15); //Increase textbox for more digits
jmr274 5:e1431272be79 1718
jmr274 5:e1431272be79 1719 /* Display Units */
jmr274 5:e1431272be79 1720 strcpy((char *) text,"dF");oled.Label((uint8_t *)text,71,23);
jmr274 5:e1431272be79 1721
asong 1:e4b38d6918ba 1722 break;
asong 1:e4b38d6918ba 1723 }
asong 1:e4b38d6918ba 1724 case 26: {//Heart Rate Config Option
asong 1:e4b38d6918ba 1725 oled.FillScreen(COLOR_BLACK); // Clear screen
asong 1:e4b38d6918ba 1726 oled.Label((uint8_t *)"HR Config",10,5); // Display at x,y
asong 1:e4b38d6918ba 1727 oled.Label((uint8_t *)"*",85,15); // "*" at x,y
asong 1:e4b38d6918ba 1728 oled.Label((uint8_t *)"*",85,60); // "*" at x,y
asong 1:e4b38d6918ba 1729 oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
asong 1:e4b38d6918ba 1730 oled.Label((uint8_t *)"Enter",60,80); //Display "enter" at x,y
asong 1:e4b38d6918ba 1731 break;
asong 1:e4b38d6918ba 1732 }
asong 1:e4b38d6918ba 1733 case 27: { //Enter Age Screen
asong 1:e4b38d6918ba 1734 oled.FillScreen(COLOR_BLACK);
asong 1:e4b38d6918ba 1735 oled.Label((uint8_t *)"Input Age", 10, 5);
asong 1:e4b38d6918ba 1736 sprintf(display_buff, "%u", Age); //Convert int to char array for displaying user age
asong 1:e4b38d6918ba 1737 oled.Label((uint8_t *)"Age:", 10, 30);
asong 1:e4b38d6918ba 1738 oled.Label((uint8_t *)"+",85,15); // "*" at x,y
asong 1:e4b38d6918ba 1739 oled.Label((uint8_t *)"-",85,60); // "*" at x,y
asong 1:e4b38d6918ba 1740 oled.Label((uint8_t *)"Menu",10,80); // Display "Menu" at x,y
asong 1:e4b38d6918ba 1741 oled.Label((uint8_t *)"Next",60,80); //Display "Next" at x,y
asong 1:e4b38d6918ba 1742 textProperties.fontColor = COLOR_GREEN;
asong 1:e4b38d6918ba 1743 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 1744 oled.Label((uint8_t *)display_buff,43,30); // Display at x,y
asong 1:e4b38d6918ba 1745 textProperties.fontColor = COLOR_WHITE;
asong 1:e4b38d6918ba 1746 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 1747 oled.Label((uint8_t *)"Max bpm:",10,50);
asong 1:e4b38d6918ba 1748 textProperties.fontColor = COLOR_RED;
asong 1:e4b38d6918ba 1749 oled.SetTextProperties(&textProperties); //implements the color change
asong 2:824ed4ae8d52 1750 sprintf(display_buff, "%u", Max_Bpm); //Convert int to char array for displaying user max bpm
asong 1:e4b38d6918ba 1751 oled.Label((uint8_t *)display_buff, 65, 50);
asong 1:e4b38d6918ba 1752 textProperties.fontColor = COLOR_WHITE;
asong 1:e4b38d6918ba 1753 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 1754 break;
asong 1:e4b38d6918ba 1755 }
asong 1:e4b38d6918ba 1756 case 28: {//Choose Heart Rate Vibration Option
asong 1:e4b38d6918ba 1757 oled.FillScreen(COLOR_BLACK);
asong 1:e4b38d6918ba 1758 oled.Label((uint8_t *)"Vibrate Pref", 10, 10);
asong 1:e4b38d6918ba 1759 oled.Label((uint8_t *)"Option:", 10, 25);
asong 1:e4b38d6918ba 1760 oled.Label((uint8_t *)"+",85,15); // "+" at x,y
asong 1:e4b38d6918ba 1761 oled.Label((uint8_t *)"-",85,60); // "-" at x,y
asong 1:e4b38d6918ba 1762 oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
asong 1:e4b38d6918ba 1763 oled.Label((uint8_t *)"Next",60,80); //Display "Next" at x,y
asong 1:e4b38d6918ba 1764 sprintf(display_buff, "%u", HR_Vibration); //Convert int to char array for displaying user preference
asong 1:e4b38d6918ba 1765 textProperties.fontColor = COLOR_GREEN; //Change font to green
asong 1:e4b38d6918ba 1766 oled.SetTextProperties(&textProperties);//Implement color change
asong 1:e4b38d6918ba 1767 oled.Label((uint8_t *)display_buff,55,25); // Display at x,y
asong 1:e4b38d6918ba 1768 if(HR_Vibration == 1) {
asong 1:e4b38d6918ba 1769 textProperties.fontColor = COLOR_RED; //Change font to red
asong 1:e4b38d6918ba 1770 oled.SetTextProperties(&textProperties); //Implement color change
asong 1:e4b38d6918ba 1771 oled.Label((uint8_t *)"All On",10,45); // Display at x,y
asong 1:e4b38d6918ba 1772 } else if(HR_Vibration == 2) {
asong 1:e4b38d6918ba 1773 textProperties.fontColor = COLOR_RED; //Change font to red
asong 1:e4b38d6918ba 1774 oled.SetTextProperties(&textProperties);//Implement color change
asong 1:e4b38d6918ba 1775 oled.Label((uint8_t *)"Only Entering",10,38);// Display at x,y
asong 1:e4b38d6918ba 1776 oled.Label((uint8_t *)"And Exiting",10,53);// Display at x,y
asong 1:e4b38d6918ba 1777 oled.Label((uint8_t *)"Target Zone",10,68);// Display at x,y
nbaker 0:d1d36a3da39b 1778
asong 1:e4b38d6918ba 1779 } else if(HR_Vibration == 3) {
asong 1:e4b38d6918ba 1780 textProperties.fontColor = COLOR_RED; //Change font to red
asong 1:e4b38d6918ba 1781 oled.SetTextProperties(&textProperties); //Implement color change
asong 1:e4b38d6918ba 1782 oled.Label((uint8_t *)"All Off",10,45);// Display at x,y
asong 1:e4b38d6918ba 1783 }
asong 1:e4b38d6918ba 1784 textProperties.fontColor = COLOR_WHITE;
asong 1:e4b38d6918ba 1785 oled.SetTextProperties(&textProperties);
asong 1:e4b38d6918ba 1786 break;
asong 1:e4b38d6918ba 1787 }
asong 1:e4b38d6918ba 1788 case 29: { //Zone Boundary Info
asong 1:e4b38d6918ba 1789 oled.FillScreen(COLOR_BLACK);
asong 1:e4b38d6918ba 1790 oled.Label((uint8_t *)"HR Zone Info", 10, 5);// Display at x,y
asong 1:e4b38d6918ba 1791 textProperties.fontColor = COLOR_YELLOW; //Change font to yellow
asong 1:e4b38d6918ba 1792 oled.SetTextProperties(&textProperties);//Implement color change
asong 1:e4b38d6918ba 1793 oled.Label((uint8_t *)"Z1:", 10, 20);// Display at x,y
asong 1:e4b38d6918ba 1794 sprintf(display_buff, "%u", HR_Zone1[0]); // Convert int to char to display
asong 1:e4b38d6918ba 1795 oled.Label((uint8_t *)display_buff, 30, 20);// Display at x,y
asong 1:e4b38d6918ba 1796 oled.Label((uint8_t *)"-", 52, 20);// Display at x,y
asong 1:e4b38d6918ba 1797 sprintf(display_buff, "%u", HR_Zone1[1]); // Convert int to char to display
asong 1:e4b38d6918ba 1798 oled.Label((uint8_t *)display_buff, 60, 20);// Display at x,y
asong 1:e4b38d6918ba 1799 textProperties.fontColor = COLOR_BLUE; //Change font to blue
asong 1:e4b38d6918ba 1800 oled.SetTextProperties(&textProperties);//Implement color change
asong 1:e4b38d6918ba 1801 oled.Label((uint8_t *)"Z2:", 10, 35);// Display at x,y
asong 1:e4b38d6918ba 1802 sprintf(display_buff, "%u", HR_Zone2[0]); // Convert int to char to display
asong 1:e4b38d6918ba 1803 oled.Label((uint8_t *)display_buff, 30, 35);// Display at x,y
asong 1:e4b38d6918ba 1804 oled.Label((uint8_t *)"-", 52, 35);// Display at x,y
asong 1:e4b38d6918ba 1805 sprintf(display_buff, "%u", HR_Zone2[1]); // Convert int to char to display
asong 1:e4b38d6918ba 1806 oled.Label((uint8_t *)display_buff, 60, 35);// Display at x,y
asong 1:e4b38d6918ba 1807 textProperties.fontColor = COLOR_GREEN; //Change font to green
asong 1:e4b38d6918ba 1808 oled.SetTextProperties(&textProperties);//Implement color change
asong 1:e4b38d6918ba 1809 oled.Label((uint8_t *)"Z3:", 10, 50);// Display at x,y
asong 1:e4b38d6918ba 1810 sprintf(display_buff, "%u", HR_Zone3[0]); // Convert int to char to display
asong 1:e4b38d6918ba 1811 oled.Label((uint8_t *)display_buff, 30, 50);// Display at x,y
asong 1:e4b38d6918ba 1812 oled.Label((uint8_t *)"-", 52, 50);// Display at x,y
asong 1:e4b38d6918ba 1813 sprintf(display_buff, "%u", HR_Zone3[1]); // Convert int to char to display
asong 1:e4b38d6918ba 1814 oled.Label((uint8_t *)display_buff, 60, 50);// Display at x,y
asong 1:e4b38d6918ba 1815 textProperties.fontColor = COLOR_RED; //Change font to red
asong 1:e4b38d6918ba 1816 oled.SetTextProperties(&textProperties);//Implement color change
asong 1:e4b38d6918ba 1817 oled.Label((uint8_t *)"Z4:", 10, 65);// Display at x,y
asong 1:e4b38d6918ba 1818 sprintf(display_buff, "%u", HR_Zone4[0]); // Convert int to char to display
asong 1:e4b38d6918ba 1819 oled.Label((uint8_t *)display_buff, 30, 65);// Display at x,y
asong 1:e4b38d6918ba 1820 oled.Label((uint8_t *)"-", 52, 65);// Display at x,y
asong 1:e4b38d6918ba 1821 sprintf(display_buff, "%u", HR_Zone4[1]); // Convert int to char to display
asong 1:e4b38d6918ba 1822 oled.Label((uint8_t *)display_buff, 60, 65);// Display at x,y
asong 1:e4b38d6918ba 1823 textProperties.fontColor = COLOR_WHITE; //Change font to white
asong 1:e4b38d6918ba 1824 oled.SetTextProperties(&textProperties);//Implement color change
asong 1:e4b38d6918ba 1825 oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
asong 1:e4b38d6918ba 1826 oled.Label((uint8_t *)"Next",60,80); //Display "Next" at x,y
asong 1:e4b38d6918ba 1827 break;
asong 2:824ed4ae8d52 1828 }
asong 2:824ed4ae8d52 1829 case 30: { //Enter Target Heart Rate Zone Preference
asong 1:e4b38d6918ba 1830 oled.FillScreen(COLOR_BLACK);
asong 1:e4b38d6918ba 1831 oled.Label((uint8_t *)"Zone Pref", 10, 5);// Display at x,y
asong 1:e4b38d6918ba 1832 oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
asong 1:e4b38d6918ba 1833 oled.Label((uint8_t *)"Next",60,80); //Display "Next" at x,y
asong 1:e4b38d6918ba 1834 oled.Label((uint8_t *)"+",85,15); // "+" at x,y
asong 1:e4b38d6918ba 1835 oled.Label((uint8_t *)"-",85,60); // "-" at x,y
asong 1:e4b38d6918ba 1836 oled.Label((uint8_t *)"Target:", 10, 25);// Display at x,y
asong 1:e4b38d6918ba 1837 sprintf(display_buff, "%u", Target_Zone); // Convert int to char to display
asong 2:824ed4ae8d52 1838 if(Target_Zone == 1) {
asong 1:e4b38d6918ba 1839 textProperties.fontColor = COLOR_YELLOW; //Change font to yellow
asong 1:e4b38d6918ba 1840 oled.SetTextProperties(&textProperties);//Implement color change
asong 2:824ed4ae8d52 1841 } else if(Target_Zone == 2) {
asong 1:e4b38d6918ba 1842 textProperties.fontColor = COLOR_BLUE; //Change font to blue
asong 1:e4b38d6918ba 1843 oled.SetTextProperties(&textProperties);//Implement color change
asong 2:824ed4ae8d52 1844 } else if(Target_Zone == 3) {
asong 1:e4b38d6918ba 1845 textProperties.fontColor = COLOR_GREEN; //Change font to green
asong 1:e4b38d6918ba 1846 oled.SetTextProperties(&textProperties);//Implement color change
asong 2:824ed4ae8d52 1847 } else if(Target_Zone == 4) {
asong 1:e4b38d6918ba 1848 textProperties.fontColor = COLOR_RED; //Change font to red
asong 1:e4b38d6918ba 1849 oled.SetTextProperties(&textProperties);//Implement color change
asong 1:e4b38d6918ba 1850 }
asong 1:e4b38d6918ba 1851 oled.Label((uint8_t *)display_buff, 55, 25);// Display at x,y
asong 1:e4b38d6918ba 1852 textProperties.fontColor = COLOR_WHITE; //Change font to white
asong 1:e4b38d6918ba 1853 oled.SetTextProperties(&textProperties);//Implement color change
asong 1:e4b38d6918ba 1854 oled.Label((uint8_t *)"Bounds:", 10, 45);// Display at x,y
asong 2:824ed4ae8d52 1855 if(Target_Zone == 1) {
asong 1:e4b38d6918ba 1856 textProperties.fontColor = COLOR_YELLOW; //Change font to yellow
asong 1:e4b38d6918ba 1857 oled.SetTextProperties(&textProperties);//Implement color change
asong 1:e4b38d6918ba 1858 sprintf(display_buff, "%u", HR_Zone1[0]); // Convert int to char to display
asong 1:e4b38d6918ba 1859 oled.Label((uint8_t *)display_buff, 10, 60);// Display at x,y
asong 1:e4b38d6918ba 1860 oled.Label((uint8_t *)"-", 32, 60);// Display at x,y
asong 1:e4b38d6918ba 1861 sprintf(display_buff, "%u", HR_Zone1[1]); // Convert int to char to display
asong 1:e4b38d6918ba 1862 oled.Label((uint8_t *)display_buff, 40, 60);// Display at x,y
asong 2:824ed4ae8d52 1863 } else if(Target_Zone == 2) {
asong 1:e4b38d6918ba 1864 textProperties.fontColor = COLOR_BLUE; //Change font to blue
asong 1:e4b38d6918ba 1865 oled.SetTextProperties(&textProperties);//Implement color change
asong 1:e4b38d6918ba 1866 sprintf(display_buff, "%u", HR_Zone2[0]); // Convert int to char to display
asong 1:e4b38d6918ba 1867 oled.Label((uint8_t *)display_buff, 10, 60);// Display at x,y
asong 1:e4b38d6918ba 1868 oled.Label((uint8_t *)"-", 32, 60);// Display at x,y
asong 1:e4b38d6918ba 1869 sprintf(display_buff, "%u", HR_Zone2[1]); // Convert int to char to display
asong 1:e4b38d6918ba 1870 oled.Label((uint8_t *)display_buff, 40, 60);// Display at x,y
asong 2:824ed4ae8d52 1871 } else if(Target_Zone == 3) {
asong 1:e4b38d6918ba 1872 textProperties.fontColor = COLOR_GREEN; //Change font to green
asong 1:e4b38d6918ba 1873 oled.SetTextProperties(&textProperties);//Implement color change
asong 1:e4b38d6918ba 1874 sprintf(display_buff, "%u", HR_Zone3[0]); // Convert int to char to display
asong 1:e4b38d6918ba 1875 oled.Label((uint8_t *)display_buff, 10, 60); // Display at x,y
asong 1:e4b38d6918ba 1876 oled.Label((uint8_t *)"-", 32, 60); // Display at x,y
asong 1:e4b38d6918ba 1877 sprintf(display_buff, "%u", HR_Zone3[1]); // Convert int to char to display
asong 1:e4b38d6918ba 1878 oled.Label((uint8_t *)display_buff, 40, 60);// Display at x,y
asong 2:824ed4ae8d52 1879 } else if(Target_Zone == 4) {
asong 1:e4b38d6918ba 1880 textProperties.fontColor = COLOR_RED; //Change font to red
asong 1:e4b38d6918ba 1881 oled.SetTextProperties(&textProperties);//Implement color change
asong 1:e4b38d6918ba 1882 sprintf(display_buff, "%u", HR_Zone4[0]); // Convert int to char to display
asong 1:e4b38d6918ba 1883 oled.Label((uint8_t *)display_buff, 10, 60); // Display at x,y
asong 1:e4b38d6918ba 1884 oled.Label((uint8_t *)"-", 32, 60); // Display at x,y
asong 1:e4b38d6918ba 1885 sprintf(display_buff, "%u", HR_Zone4[1]); // Convert int to char to display
asong 1:e4b38d6918ba 1886 oled.Label((uint8_t *)display_buff, 40, 60); // Display at x,y
asong 1:e4b38d6918ba 1887 }
asong 1:e4b38d6918ba 1888 textProperties.fontColor = COLOR_WHITE; //Change font to white
asong 1:e4b38d6918ba 1889 oled.SetTextProperties(&textProperties);//Implement color change
asong 2:824ed4ae8d52 1890 break;
asong 2:824ed4ae8d52 1891 }
asong 2:824ed4ae8d52 1892 case 31: {
asong 2:824ed4ae8d52 1893 oled.FillScreen(COLOR_BLACK);
asong 2:824ed4ae8d52 1894 Heart_Rate_Vibrations();
asong 2:824ed4ae8d52 1895 oled.Label((uint8_t *)"Enter HR", 10, 5);// Display at x,y
asong 2:824ed4ae8d52 1896 oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
asong 2:824ed4ae8d52 1897 oled.Label((uint8_t *)"Next",60,80); //Display "Next" at x,y
asong 2:824ed4ae8d52 1898 oled.Label((uint8_t *)"+",85,15); // "+" at x,y
asong 2:824ed4ae8d52 1899 oled.Label((uint8_t *)"-",85,60); // "-" at x,y
asong 2:824ed4ae8d52 1900 oled.Label((uint8_t *)"HR:", 10, 25);
asong 2:824ed4ae8d52 1901 sprintf(display_buff, "%u", Heart_Rate); // Convert int to char to display
asong 2:824ed4ae8d52 1902 textProperties.fontColor = COLOR_RED; //Change font to red
asong 2:824ed4ae8d52 1903 oled.SetTextProperties(&textProperties);//Implement color change
asong 2:824ed4ae8d52 1904 oled.Label((uint8_t *)display_buff, 40, 25);
asong 2:824ed4ae8d52 1905 textProperties.fontColor = COLOR_WHITE; //Change font to white
asong 2:824ed4ae8d52 1906 oled.SetTextProperties(&textProperties);//Implement color change
asong 2:824ed4ae8d52 1907 oled.Label((uint8_t *)"Cur Zone:", 10, 45);
asong 2:824ed4ae8d52 1908 if(Current_Zone == 1) {
asong 2:824ed4ae8d52 1909 textProperties.fontColor = COLOR_YELLOW;
asong 2:824ed4ae8d52 1910 oled.SetTextProperties(&textProperties);
asong 2:824ed4ae8d52 1911 } else if(Current_Zone == 2) {
asong 2:824ed4ae8d52 1912 textProperties.fontColor = COLOR_BLUE;
asong 2:824ed4ae8d52 1913 oled.SetTextProperties(&textProperties);
asong 2:824ed4ae8d52 1914 } else if(Current_Zone == 3) {
asong 2:824ed4ae8d52 1915 textProperties.fontColor = COLOR_GREEN;
asong 2:824ed4ae8d52 1916 oled.SetTextProperties(&textProperties);
asong 2:824ed4ae8d52 1917 } else if(Current_Zone == 4) {
asong 2:824ed4ae8d52 1918 textProperties.fontColor = COLOR_RED;
asong 2:824ed4ae8d52 1919 oled.SetTextProperties(&textProperties);
asong 2:824ed4ae8d52 1920 }
asong 2:824ed4ae8d52 1921 sprintf(display_buff, "%u", Current_Zone); // Convert int to char to display
asong 2:824ed4ae8d52 1922 oled.Label((uint8_t *)display_buff, 71, 45);
asong 2:824ed4ae8d52 1923 textProperties.fontColor = COLOR_WHITE; //Change font to white
asong 2:824ed4ae8d52 1924 oled.SetTextProperties(&textProperties);//Implement color change
asong 2:824ed4ae8d52 1925 oled.Label((uint8_t *)"Prev Zone:", 10, 60);
asong 2:824ed4ae8d52 1926 if(Prev_Zone == 1) {
asong 2:824ed4ae8d52 1927 textProperties.fontColor = COLOR_YELLOW;
asong 2:824ed4ae8d52 1928 oled.SetTextProperties(&textProperties);
asong 2:824ed4ae8d52 1929 } else if(Prev_Zone == 2) {
asong 2:824ed4ae8d52 1930 textProperties.fontColor = COLOR_BLUE;
asong 2:824ed4ae8d52 1931 oled.SetTextProperties(&textProperties);
asong 2:824ed4ae8d52 1932 } else if(Prev_Zone == 3) {
asong 2:824ed4ae8d52 1933 textProperties.fontColor = COLOR_GREEN;
asong 2:824ed4ae8d52 1934 oled.SetTextProperties(&textProperties);
asong 2:824ed4ae8d52 1935 } else if(Prev_Zone == 4) {
asong 2:824ed4ae8d52 1936 textProperties.fontColor = COLOR_RED;
asong 2:824ed4ae8d52 1937 oled.SetTextProperties(&textProperties);
asong 2:824ed4ae8d52 1938 }
asong 2:824ed4ae8d52 1939 sprintf(display_buff, "%u", Prev_Zone); // Convert int to char to display
asong 2:824ed4ae8d52 1940 oled.Label((uint8_t *)display_buff, 71, 60);
asong 2:824ed4ae8d52 1941 textProperties.fontColor = COLOR_WHITE; //Change font to white
asong 2:824ed4ae8d52 1942 oled.SetTextProperties(&textProperties);//Implement color change
asong 2:824ed4ae8d52 1943 Led_Zone_Indicator();
asong 2:824ed4ae8d52 1944 break;
asong 2:824ed4ae8d52 1945 }
asong 2:824ed4ae8d52 1946 case 32: {
asong 2:824ed4ae8d52 1947 //Zone Boundary Info
asong 2:824ed4ae8d52 1948 oled.FillScreen(COLOR_BLACK);
asong 2:824ed4ae8d52 1949 oled.Label((uint8_t *)"HR Zone Info", 10, 5);// Display at x,y
asong 2:824ed4ae8d52 1950 textProperties.fontColor = COLOR_YELLOW; //Change font to yellow
asong 2:824ed4ae8d52 1951 oled.SetTextProperties(&textProperties);//Implement color change
asong 2:824ed4ae8d52 1952 oled.Label((uint8_t *)"Z1:", 10, 20);// Display at x,y
asong 2:824ed4ae8d52 1953 sprintf(display_buff, "%u", HR_Zone1[0]); // Convert int to char to display
asong 2:824ed4ae8d52 1954 oled.Label((uint8_t *)display_buff, 30, 20);// Display at x,y
asong 2:824ed4ae8d52 1955 oled.Label((uint8_t *)"-", 52, 20);// Display at x,y
asong 2:824ed4ae8d52 1956 sprintf(display_buff, "%u", HR_Zone1[1]); // Convert int to char to display
asong 2:824ed4ae8d52 1957 oled.Label((uint8_t *)display_buff, 60, 20);// Display at x,y
asong 2:824ed4ae8d52 1958 textProperties.fontColor = COLOR_BLUE; //Change font to blue
asong 2:824ed4ae8d52 1959 oled.SetTextProperties(&textProperties);//Implement color change
asong 2:824ed4ae8d52 1960 oled.Label((uint8_t *)"Z2:", 10, 35);// Display at x,y
asong 2:824ed4ae8d52 1961 sprintf(display_buff, "%u", HR_Zone2[0]); // Convert int to char to display
asong 2:824ed4ae8d52 1962 oled.Label((uint8_t *)display_buff, 30, 35);// Display at x,y
asong 2:824ed4ae8d52 1963 oled.Label((uint8_t *)"-", 52, 35);// Display at x,y
asong 2:824ed4ae8d52 1964 sprintf(display_buff, "%u", HR_Zone2[1]); // Convert int to char to display
asong 2:824ed4ae8d52 1965 oled.Label((uint8_t *)display_buff, 60, 35);// Display at x,y
asong 2:824ed4ae8d52 1966 textProperties.fontColor = COLOR_GREEN; //Change font to green
asong 2:824ed4ae8d52 1967 oled.SetTextProperties(&textProperties);//Implement color change
asong 2:824ed4ae8d52 1968 oled.Label((uint8_t *)"Z3:", 10, 50);// Display at x,y
asong 2:824ed4ae8d52 1969 sprintf(display_buff, "%u", HR_Zone3[0]); // Convert int to char to display
asong 2:824ed4ae8d52 1970 oled.Label((uint8_t *)display_buff, 30, 50);// Display at x,y
asong 2:824ed4ae8d52 1971 oled.Label((uint8_t *)"-", 52, 50);// Display at x,y
asong 2:824ed4ae8d52 1972 sprintf(display_buff, "%u", HR_Zone3[1]); // Convert int to char to display
asong 2:824ed4ae8d52 1973 oled.Label((uint8_t *)display_buff, 60, 50);// Display at x,y
asong 2:824ed4ae8d52 1974 textProperties.fontColor = COLOR_RED; //Change font to red
asong 2:824ed4ae8d52 1975 oled.SetTextProperties(&textProperties);//Implement color change
asong 2:824ed4ae8d52 1976 oled.Label((uint8_t *)"Z4:", 10, 65);// Display at x,y
asong 2:824ed4ae8d52 1977 sprintf(display_buff, "%u", HR_Zone4[0]); // Convert int to char to display
asong 2:824ed4ae8d52 1978 oled.Label((uint8_t *)display_buff, 30, 65);// Display at x,y
asong 2:824ed4ae8d52 1979 oled.Label((uint8_t *)"-", 52, 65);// Display at x,y
asong 2:824ed4ae8d52 1980 sprintf(display_buff, "%u", HR_Zone4[1]); // Convert int to char to display
asong 2:824ed4ae8d52 1981 oled.Label((uint8_t *)display_buff, 60, 65);// Display at x,y
asong 2:824ed4ae8d52 1982 textProperties.fontColor = COLOR_WHITE; //Change font to white
asong 2:824ed4ae8d52 1983 oled.SetTextProperties(&textProperties);//Implement color change
asong 2:824ed4ae8d52 1984 oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
asong 2:824ed4ae8d52 1985 oled.Label((uint8_t *)"Next",60,80); //Display "Next" at x,y
asong 2:824ed4ae8d52 1986 break;
nbaker 8:a5c77b45008d 1987 }
nbaker 8:a5c77b45008d 1988 case 41: { //Fall mode
nbaker 8:a5c77b45008d 1989 oled.FillScreen(COLOR_BLACK);
nbaker 8:a5c77b45008d 1990 oled.Label((uint8_t *)"Adj Fall Mode", 10, 5);
nbaker 8:a5c77b45008d 1991 sprintf(display_buff, "%u", Fall_Alert_Mode); //Convert int to char array for displaying mode
nbaker 8:a5c77b45008d 1992 oled.Label((uint8_t *)"Mode:", 5, 30);
nbaker 8:a5c77b45008d 1993 oled.Label((uint8_t *)"+",85,15); // "*" at x,y
nbaker 8:a5c77b45008d 1994 oled.Label((uint8_t *)"-",85,60); // "*" at x,y
nbaker 8:a5c77b45008d 1995 oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
nbaker 8:a5c77b45008d 1996 oled.Label((uint8_t *)"Next",60,80); //Display "Next" at x,y
nbaker 8:a5c77b45008d 1997 textProperties.fontColor = COLOR_GREEN;
nbaker 8:a5c77b45008d 1998 oled.SetTextProperties(&textProperties);
nbaker 8:a5c77b45008d 1999 oled.Label((uint8_t *)display_buff,43,30); // Display at x,y
nbaker 8:a5c77b45008d 2000 textProperties.fontColor = COLOR_WHITE;
nbaker 8:a5c77b45008d 2001 oled.SetTextProperties(&textProperties);
nbaker 8:a5c77b45008d 2002 break;
nbaker 8:a5c77b45008d 2003 }
nbaker 8:a5c77b45008d 2004 case 42: { //Fall Thresh
nbaker 8:a5c77b45008d 2005 oled.FillScreen(COLOR_BLACK);
nbaker 8:a5c77b45008d 2006 oled.Label((uint8_t *)"Adj F-Th", 10, 5);
nbaker 8:a5c77b45008d 2007 sprintf(display_buff, "%2.2f g", Fall_Thresh); //Convert int to char array for displaying mode
nbaker 8:a5c77b45008d 2008 oled.Label((uint8_t *)"F_Th:", 5, 30);
nbaker 8:a5c77b45008d 2009 oled.Label((uint8_t *)"+",85,15); // "*" at x,y
nbaker 8:a5c77b45008d 2010 oled.Label((uint8_t *)"-",85,60); // "*" at x,y
nbaker 8:a5c77b45008d 2011 oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
nbaker 8:a5c77b45008d 2012 oled.Label((uint8_t *)"Next",60,80); //Display "Next" at x,y
nbaker 8:a5c77b45008d 2013 textProperties.fontColor = COLOR_GREEN;
nbaker 8:a5c77b45008d 2014 oled.SetTextProperties(&textProperties);
nbaker 8:a5c77b45008d 2015 oled.Label((uint8_t *)display_buff,43,30); // Display at x,y
nbaker 8:a5c77b45008d 2016 textProperties.fontColor = COLOR_WHITE;
nbaker 8:a5c77b45008d 2017 oled.SetTextProperties(&textProperties);
nbaker 8:a5c77b45008d 2018 break;
nbaker 8:a5c77b45008d 2019 }
nbaker 8:a5c77b45008d 2020 case 43: { //Impact Thresh
nbaker 8:a5c77b45008d 2021 oled.FillScreen(COLOR_BLACK);
nbaker 8:a5c77b45008d 2022 oled.Label((uint8_t *)"Adj I-Th", 10, 5);
nbaker 8:a5c77b45008d 2023 sprintf(display_buff, "%2.2f g", Impact_Thresh); //Convert int to char array for displaying mode
nbaker 8:a5c77b45008d 2024 oled.Label((uint8_t *)"I_Th:", 5, 30);
nbaker 8:a5c77b45008d 2025 oled.Label((uint8_t *)"+",85,15); // "*" at x,y
nbaker 8:a5c77b45008d 2026 oled.Label((uint8_t *)"-",85,60); // "*" at x,y
nbaker 8:a5c77b45008d 2027 oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
nbaker 8:a5c77b45008d 2028 oled.Label((uint8_t *)"Next",60,80); //Display "Next" at x,y
nbaker 8:a5c77b45008d 2029 textProperties.fontColor = COLOR_GREEN;
nbaker 8:a5c77b45008d 2030 oled.SetTextProperties(&textProperties);
nbaker 8:a5c77b45008d 2031 oled.Label((uint8_t *)display_buff,43,30); // Display at x,y
nbaker 8:a5c77b45008d 2032 textProperties.fontColor = COLOR_WHITE;
nbaker 8:a5c77b45008d 2033 oled.SetTextProperties(&textProperties);
nbaker 8:a5c77b45008d 2034 break;
nbaker 8:a5c77b45008d 2035 }
nbaker 8:a5c77b45008d 2036 case 44: { //Motion Thresh
nbaker 8:a5c77b45008d 2037 oled.FillScreen(COLOR_BLACK);
nbaker 8:a5c77b45008d 2038 oled.Label((uint8_t *)"Adj M-Th", 10, 5);
nbaker 8:a5c77b45008d 2039 sprintf(display_buff, "%4.0f D/S", Movement_Thresh); //Convert int to char array for displaying mode
nbaker 8:a5c77b45008d 2040 oled.Label((uint8_t *)"M_Th:", 5, 30);
nbaker 8:a5c77b45008d 2041 oled.Label((uint8_t *)"+",85,15); // "*" at x,y
nbaker 8:a5c77b45008d 2042 oled.Label((uint8_t *)"-",85,60); // "*" at x,y
nbaker 8:a5c77b45008d 2043 oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
nbaker 9:d2e39ee9fedd 2044 oled.Label((uint8_t *)"Next",60,80); //Display "Next" at x,y
nbaker 9:d2e39ee9fedd 2045 textProperties.fontColor = COLOR_GREEN;
nbaker 9:d2e39ee9fedd 2046 oled.SetTextProperties(&textProperties);
nbaker 9:d2e39ee9fedd 2047 oled.Label((uint8_t *)display_buff,43,30); // Display at x,y
nbaker 9:d2e39ee9fedd 2048 textProperties.fontColor = COLOR_WHITE;
nbaker 9:d2e39ee9fedd 2049 oled.SetTextProperties(&textProperties);
nbaker 9:d2e39ee9fedd 2050 break;
nbaker 9:d2e39ee9fedd 2051 }//end case 44
nbaker 9:d2e39ee9fedd 2052 case 45: { //Min_Movement_Time
nbaker 9:d2e39ee9fedd 2053 oled.FillScreen(COLOR_BLACK);
nbaker 9:d2e39ee9fedd 2054 oled.Label((uint8_t *)"Adj MinM_Tim", 10, 5);
nbaker 9:d2e39ee9fedd 2055 sprintf(display_buff, "%1.2fSec", Min_Movement_Time); //Convert int to char array for displaying mode
nbaker 9:d2e39ee9fedd 2056 oled.Label((uint8_t *)"m_Tm:", 5, 30);
nbaker 9:d2e39ee9fedd 2057 oled.Label((uint8_t *)"+",85,15); // "*" at x,y
nbaker 9:d2e39ee9fedd 2058 oled.Label((uint8_t *)"-",85,60); // "*" at x,y
nbaker 9:d2e39ee9fedd 2059 oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
nbaker 9:d2e39ee9fedd 2060 oled.Label((uint8_t *)"Next",60,80); //Display "Next" at x,y
nbaker 8:a5c77b45008d 2061 textProperties.fontColor = COLOR_GREEN;
nbaker 8:a5c77b45008d 2062 oled.SetTextProperties(&textProperties);
nbaker 8:a5c77b45008d 2063 oled.Label((uint8_t *)display_buff,43,30); // Display at x,y
nbaker 8:a5c77b45008d 2064 textProperties.fontColor = COLOR_WHITE;
nbaker 8:a5c77b45008d 2065 oled.SetTextProperties(&textProperties);
nbaker 8:a5c77b45008d 2066 break;
nbaker 9:d2e39ee9fedd 2067 }//end case 45
nbaker 9:d2e39ee9fedd 2068 case 46: { //Min_Movement_Time
nbaker 9:d2e39ee9fedd 2069 oled.FillScreen(COLOR_BLACK);
nbaker 9:d2e39ee9fedd 2070 oled.Label((uint8_t *)"Adj MinM_Dur", 10, 5);
nbaker 9:d2e39ee9fedd 2071 sprintf(display_buff, "%2.1fSec", Min_Movement_duration); //Convert int to char array for displaying mode
nbaker 9:d2e39ee9fedd 2072 oled.Label((uint8_t *)"mDur:", 5, 30);
nbaker 9:d2e39ee9fedd 2073 oled.Label((uint8_t *)"+",85,15); // "*" at x,y
nbaker 9:d2e39ee9fedd 2074 oled.Label((uint8_t *)"-",85,60); // "*" at x,y
nbaker 9:d2e39ee9fedd 2075 oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
nbaker 9:d2e39ee9fedd 2076 // oled.Label((uint8_t *)"Next",60,80); //Display "Next" at x,y
nbaker 9:d2e39ee9fedd 2077 textProperties.fontColor = COLOR_GREEN;
nbaker 9:d2e39ee9fedd 2078 oled.SetTextProperties(&textProperties);
nbaker 9:d2e39ee9fedd 2079 oled.Label((uint8_t *)display_buff,43,30); // Display at x,y
nbaker 9:d2e39ee9fedd 2080 textProperties.fontColor = COLOR_WHITE;
nbaker 9:d2e39ee9fedd 2081 oled.SetTextProperties(&textProperties);
nbaker 9:d2e39ee9fedd 2082 break;
nbaker 9:d2e39ee9fedd 2083 }//end case 46
nbaker 10:eaea844e763c 2084
nbaker 10:eaea844e763c 2085 case 47: { //Post fall "are you OK?" screen
nbaker 10:eaea844e763c 2086 oled.FillScreen(COLOR_BLACK);
nbaker 10:eaea844e763c 2087 textProperties.fontColor = COLOR_RED;
nbaker 10:eaea844e763c 2088 oled.SetTextProperties(&textProperties);
nbaker 10:eaea844e763c 2089 oled.Label((uint8_t *)"Fall Detected!", 5, 5);
nbaker 10:eaea844e763c 2090 textProperties.font = OpenSans_12x18_Regular; // Max Width of Character = 12px, Max Height of Character = 18px
nbaker 10:eaea844e763c 2091 textProperties.fontColor = COLOR_WHITE;
nbaker 10:eaea844e763c 2092 oled.SetTextProperties(&textProperties);
nbaker 10:eaea844e763c 2093 oled.Label((uint8_t *)"Do you need", 5, 20);
nbaker 10:eaea844e763c 2094 oled.Label((uint8_t *)"Help?", 10, 35);
nbaker 10:eaea844e763c 2095 //oled.Label((uint8_t *)"+",85,15); // "*" at x,y
nbaker 10:eaea844e763c 2096 //oled.Label((uint8_t *)"-",85,60); // "*" at x,y
nbaker 10:eaea844e763c 2097 oled.Label((uint8_t *)"No",10,75); // Display "Back" at x,y
nbaker 10:eaea844e763c 2098 oled.Label((uint8_t *)"YES!",60,75); //Display "Next" at x,y
nbaker 10:eaea844e763c 2099 textProperties.font = OpenSans_10x15_Regular; // Max Width of Character = 10px, Max Height of Character = 15px
nbaker 10:eaea844e763c 2100 textProperties.fontColor = COLOR_WHITE;
nbaker 10:eaea844e763c 2101 oled.SetTextProperties(&textProperties);
nbaker 10:eaea844e763c 2102 break;
nbaker 10:eaea844e763c 2103 }//end case 47
nbaker 10:eaea844e763c 2104
nbaker 10:eaea844e763c 2105 case 48: { //Sending Fall alert screen
nbaker 10:eaea844e763c 2106 oled.FillScreen(COLOR_BLACK);
nbaker 10:eaea844e763c 2107 textProperties.fontColor = COLOR_RED;
nbaker 10:eaea844e763c 2108 oled.SetTextProperties(&textProperties);
nbaker 10:eaea844e763c 2109 oled.Label((uint8_t *)"Fall Detected!", 5, 5);
nbaker 10:eaea844e763c 2110 textProperties.font = OpenSans_12x18_Regular; // Max Width of Character = 12px, Max Height of Character = 18px
nbaker 10:eaea844e763c 2111 textProperties.fontColor = COLOR_WHITE;
nbaker 10:eaea844e763c 2112 oled.SetTextProperties(&textProperties);
nbaker 10:eaea844e763c 2113 oled.Label((uint8_t *)"Sending", 20, 40);
nbaker 10:eaea844e763c 2114 oled.Label((uint8_t *)"Alert", 25, 55);
nbaker 10:eaea844e763c 2115 oled.Label((uint8_t *)"Dismiss?",5,75); // Display "Back" at x,y
nbaker 10:eaea844e763c 2116 //oled.Label((uint8_t *)"YES!",60,80); //Display "Next" at x,y
nbaker 10:eaea844e763c 2117 textProperties.font = OpenSans_10x15_Regular; // Max Width of Character = 10px, Max Height of Character = 15px
nbaker 10:eaea844e763c 2118 textProperties.fontColor = COLOR_WHITE;
nbaker 10:eaea844e763c 2119 oled.SetTextProperties(&textProperties);
nbaker 10:eaea844e763c 2120 break;
nbaker 10:eaea844e763c 2121 }//end case 48
nbaker 9:d2e39ee9fedd 2122
nbaker 0:d1d36a3da39b 2123 #endif // end of non-production/debug version code
nbaker 8:a5c77b45008d 2124
nbaker 8:a5c77b45008d 2125 case 71: {// BLE
nbaker 8:a5c77b45008d 2126 oled.FillScreen(COLOR_BLACK); // Clear screen
nbaker 8:a5c77b45008d 2127 oled.Label((uint8_t *)"BLUETOOTH",5,5); // Display at x,y
nbaker 9:d2e39ee9fedd 2128 oled.Label((uint8_t *)"Enter",60,80); //Display at x,y
nbaker 8:a5c77b45008d 2129 textProperties.fontColor = COLOR_WHITE;
nbaker 8:a5c77b45008d 2130 oled.SetTextProperties(&textProperties);
nbaker 8:a5c77b45008d 2131 oled.Label((uint8_t *)"*",85,15); // "*" at x,y
nbaker 8:a5c77b45008d 2132 oled.Label((uint8_t *)"*",85,60); // "*" at x,y
nbaker 9:d2e39ee9fedd 2133 oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
nbaker 8:a5c77b45008d 2134 break;
nbaker 8:a5c77b45008d 2135 }
nbaker 8:a5c77b45008d 2136
nbaker 8:a5c77b45008d 2137 case 72: {// BlueTooth on/off
nbaker 8:a5c77b45008d 2138 oled.FillScreen(COLOR_BLACK); // Clear screen
nbaker 8:a5c77b45008d 2139 oled.Label((uint8_t *)"BLUETOOTH",5,5); // Display at x,y
nbaker 8:a5c77b45008d 2140 if (BLE_On == 1) {
nbaker 8:a5c77b45008d 2141 strcpy((char *) text,"PAIR CODE");
nbaker 8:a5c77b45008d 2142 oled.TextBox((uint8_t *)text,5,25,85,18);
nbaker 8:a5c77b45008d 2143 /* Display Bond Pass Key in a 85px by 18px textbox at x=5,y=25 */
nbaker 8:a5c77b45008d 2144
nbaker 8:a5c77b45008d 2145 /* This part was not compiling
nbaker 8:a5c77b45008d 2146 sprintf(text,"%d", kw40z_device.GetPassKey());
nbaker 8:a5c77b45008d 2147 oled.TextBox((uint8_t *)text,0,40,95,18);
nbaker 8:a5c77b45008d 2148 */
nbaker 8:a5c77b45008d 2149 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 2150 } else {
nbaker 8:a5c77b45008d 2151 oled.Label((uint8_t *)" Off ",40,40);
nbaker 8:a5c77b45008d 2152 }
nbaker 8:a5c77b45008d 2153 // oled.Label((uint8_t *)"*",85,15); // "*" at x,y
nbaker 8:a5c77b45008d 2154 // oled.Label((uint8_t *)"*",85,60); // "*" at x,y
nbaker 8:a5c77b45008d 2155 oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y
nbaker 9:d2e39ee9fedd 2156 oled.Label((uint8_t *)"Toggle",59,80); //Display "Toggle" at x,y
nbaker 8:a5c77b45008d 2157 break;
nbaker 8:a5c77b45008d 2158 }
nbaker 8:a5c77b45008d 2159
nbaker 8:a5c77b45008d 2160
asong 1:e4b38d6918ba 2161 default: {
asong 2:824ed4ae8d52 2162 Error_Num=1;
asong 2:824ed4ae8d52 2163 error_screen(); // Clear screen
asong 2:824ed4ae8d52 2164 break;
asong 2:824ed4ae8d52 2165 }
nbaker 8:a5c77b45008d 2166 }//end of switch
nbaker 8:a5c77b45008d 2167 __enable_irq(); // Enable all Interrupts
nbaker 8:a5c77b45008d 2168 }// end upday_display()
nbaker 8:a5c77b45008d 2169
asong 1:e4b38d6918ba 2170 void error_screen(void)
asong 1:e4b38d6918ba 2171 {
asong 1:e4b38d6918ba 2172 oled.FillScreen(COLOR_RED); // Clear screen
asong 1:e4b38d6918ba 2173 oled.Label((uint8_t *)"Error! ",30,30); // Display error at x,y
asong 1:e4b38d6918ba 2174 sprintf(text_1," %i ",Error_Num);
asong 1:e4b38d6918ba 2175 oled.Label((uint8_t *)text_1,30,60); // Display error at x,y
asong 1:e4b38d6918ba 2176 wait(3); // wait 3 seconds
asong 1:e4b38d6918ba 2177 oled.FillScreen(COLOR_BLACK); // Clear screen
nbaker 0:d1d36a3da39b 2178 }
asong 2:824ed4ae8d52 2179
asong 2:824ed4ae8d52 2180 /*****************************************************************************
asong 2:824ed4ae8d52 2181 Name: StartHaptic
asong 2:824ed4ae8d52 2182 Purpose: Cause the HexiHeart device to vibrate for a predetermined amount of
asong 2:824ed4ae8d52 2183 time
asong 2:824ed4ae8d52 2184 Inputs: None
asong 2:824ed4ae8d52 2185 Returns: None
asong 2:824ed4ae8d52 2186 ******************************************************************************/
nbaker 0:d1d36a3da39b 2187 void StartHaptic(void)
nbaker 0:d1d36a3da39b 2188 {
nbaker 10:eaea844e763c 2189 Haptic_Timer.attach(&Haptic_Off_,(0.05));
nbaker 10:eaea844e763c 2190 // hapticTimer.start(30); // was originaly 50, then 30
nbaker 8:a5c77b45008d 2191 /* this 30 value seems to not work after Neil added a global
nbaker 8:a5c77b45008d 2192 __disable_irq() and __enable_irq() for the update_display() functions on 2/18/18
nbaker 8:a5c77b45008d 2193 */
nbaker 0:d1d36a3da39b 2194 haptic = 1;
nbaker 0:d1d36a3da39b 2195 }
nbaker 10:eaea844e763c 2196 void Haptic_Off_(void)
nbaker 10:eaea844e763c 2197 {
nbaker 10:eaea844e763c 2198 haptic = 0;
nbaker 10:eaea844e763c 2199 }
nbaker 0:d1d36a3da39b 2200
asong 2:824ed4ae8d52 2201 /*****************************************************************************
asong 2:824ed4ae8d52 2202 Name: StartHaptic
asong 2:824ed4ae8d52 2203 Purpose: Cause the HexiHeart device to vibrate for x amount of time
asong 2:824ed4ae8d52 2204 Inputs: An int representing the duration of the vibration
asong 2:824ed4ae8d52 2205 Returns: None
asong 2:824ed4ae8d52 2206 ******************************************************************************/
nbaker 8:a5c77b45008d 2207
asong 1:e4b38d6918ba 2208 void StartHaptic(int x)
nbaker 8:a5c77b45008d 2209 {
asong 1:e4b38d6918ba 2210 hapticTimer.start(x);
asong 2:824ed4ae8d52 2211 haptic = 1;
asong 1:e4b38d6918ba 2212 }
asong 1:e4b38d6918ba 2213
asong 1:e4b38d6918ba 2214 void StopHaptic(void const *n)
asong 1:e4b38d6918ba 2215 {
nbaker 0:d1d36a3da39b 2216 haptic = 0;
nbaker 0:d1d36a3da39b 2217 hapticTimer.stop();
nbaker 0:d1d36a3da39b 2218 }
asong 2:824ed4ae8d52 2219
asong 2:824ed4ae8d52 2220 /*****************************************************************************
asong 2:824ed4ae8d52 2221 Name: Increment_Age
asong 2:824ed4ae8d52 2222 Purpose: Increment the user's age by 1
asong 2:824ed4ae8d52 2223 Inputs: None
asong 2:824ed4ae8d52 2224 Returns: None
asong 2:824ed4ae8d52 2225 ******************************************************************************/
asong 2:824ed4ae8d52 2226 void Increment_Age()
asong 2:824ed4ae8d52 2227 {
asong 2:824ed4ae8d52 2228 StartHaptic();
asong 2:824ed4ae8d52 2229 if(Age < 100) {
asong 2:824ed4ae8d52 2230 Age += 1;
asong 2:824ed4ae8d52 2231 Screen_Num = 27;
asong 2:824ed4ae8d52 2232 } else {
asong 2:824ed4ae8d52 2233 Age = 1;
asong 2:824ed4ae8d52 2234 }
asong 2:824ed4ae8d52 2235 }
asong 2:824ed4ae8d52 2236
asong 2:824ed4ae8d52 2237 /*****************************************************************************
asong 2:824ed4ae8d52 2238 Name: Decrement_Age
asong 2:824ed4ae8d52 2239 Purpose: Decrement the user's age by 1
asong 2:824ed4ae8d52 2240 Inputs: None
asong 2:824ed4ae8d52 2241 Returns: None
asong 2:824ed4ae8d52 2242 ******************************************************************************/
asong 2:824ed4ae8d52 2243 void Decrement_Age()
asong 2:824ed4ae8d52 2244 {
asong 2:824ed4ae8d52 2245 StartHaptic();
asong 2:824ed4ae8d52 2246 if(Age == 1) {
asong 2:824ed4ae8d52 2247 Age = 100;
asong 2:824ed4ae8d52 2248 } else {
asong 2:824ed4ae8d52 2249 Age -= 1;
asong 2:824ed4ae8d52 2250 Screen_Num = 27;
asong 2:824ed4ae8d52 2251 }
asong 2:824ed4ae8d52 2252 }
asong 2:824ed4ae8d52 2253
asong 2:824ed4ae8d52 2254 /*****************************************************************************
asong 2:824ed4ae8d52 2255 Name: Set_Max_Bpm
asong 2:824ed4ae8d52 2256 Purpose: Calculates the user's maximum heart rate based on their age
asong 2:824ed4ae8d52 2257 Inputs: None
asong 2:824ed4ae8d52 2258 Returns: None
asong 2:824ed4ae8d52 2259 ******************************************************************************/
asong 2:824ed4ae8d52 2260 void Set_Max_Bpm()
asong 2:824ed4ae8d52 2261 {
asong 2:824ed4ae8d52 2262 Max_Bpm = 220 - Age;
asong 2:824ed4ae8d52 2263 }
asong 2:824ed4ae8d52 2264
asong 2:824ed4ae8d52 2265 /*****************************************************************************
asong 2:824ed4ae8d52 2266 Name: Set_Zone_Boundaries
asong 2:824ed4ae8d52 2267 Purpose: Calculates the user's heart rate zones' boundaries based on the user's
asong 2:824ed4ae8d52 2268 maximum heart rate
asong 2:824ed4ae8d52 2269 Inputs: None
asong 2:824ed4ae8d52 2270 Returns: None
asong 2:824ed4ae8d52 2271 ******************************************************************************/
asong 2:824ed4ae8d52 2272 void Set_Zone_Boundaries()
asong 2:824ed4ae8d52 2273 {
asong 2:824ed4ae8d52 2274 Set_Max_Bpm();
asong 2:824ed4ae8d52 2275 HR_Zone1[0] = Max_Bpm * .50; //Set Heart Rate Zone 1
asong 2:824ed4ae8d52 2276 HR_Zone1[1] = Max_Bpm * .60; //Set Heart Rate Zone 1
asong 2:824ed4ae8d52 2277 HR_Zone2[0] = HR_Zone1[1] + 1; //Set Heart Rate Zone 2
asong 2:824ed4ae8d52 2278 HR_Zone2[1] = Max_Bpm * .70; //Set Heart Rate Zone 2
asong 2:824ed4ae8d52 2279 HR_Zone3[0] = HR_Zone2[1] + 1; //Set Heart Rate Zone 3
asong 2:824ed4ae8d52 2280 HR_Zone3[1] = Max_Bpm * .80; //Set Heart Rate Zone 3
asong 2:824ed4ae8d52 2281 HR_Zone4[0] = HR_Zone3[1] + 1; //Set Heart Rate Zone 4
asong 2:824ed4ae8d52 2282 HR_Zone4[1] = Max_Bpm; //Set Heart Rate Zone 4
asong 2:824ed4ae8d52 2283 }
asong 2:824ed4ae8d52 2284
asong 2:824ed4ae8d52 2285 /*****************************************************************************
asong 2:824ed4ae8d52 2286 Name: Increment_Target_Zone
asong 2:824ed4ae8d52 2287 Purpose: Imcrements the user's target heart rate zone preference by 1
asong 2:824ed4ae8d52 2288 Inputs: None
asong 2:824ed4ae8d52 2289 Returns: None
asong 2:824ed4ae8d52 2290 ******************************************************************************/
asong 2:824ed4ae8d52 2291 void Increment_Target_Zone()
asong 2:824ed4ae8d52 2292 {
asong 2:824ed4ae8d52 2293 StartHaptic();
asong 2:824ed4ae8d52 2294 if(Target_Zone == 4) {
asong 2:824ed4ae8d52 2295 Target_Zone = 1;
asong 2:824ed4ae8d52 2296 } else {
asong 2:824ed4ae8d52 2297 Target_Zone += 1;
asong 2:824ed4ae8d52 2298 }
asong 2:824ed4ae8d52 2299 }
asong 2:824ed4ae8d52 2300
asong 2:824ed4ae8d52 2301 /*****************************************************************************
asong 2:824ed4ae8d52 2302 Name: Decrement_Target_Zone
asong 2:824ed4ae8d52 2303 Purpose: Decrements the user's target heart rate zone preference by 1
asong 2:824ed4ae8d52 2304 Inputs: None
asong 2:824ed4ae8d52 2305 Returns: None
asong 2:824ed4ae8d52 2306 ******************************************************************************/
asong 2:824ed4ae8d52 2307 void Decrement_Target_Zone()
asong 2:824ed4ae8d52 2308 {
asong 2:824ed4ae8d52 2309 StartHaptic();
asong 2:824ed4ae8d52 2310 if(Target_Zone == 1) {
asong 2:824ed4ae8d52 2311 Target_Zone = 4;
asong 2:824ed4ae8d52 2312 } else {
asong 2:824ed4ae8d52 2313 Target_Zone -= 1;
asong 2:824ed4ae8d52 2314 }
asong 2:824ed4ae8d52 2315 }
asong 2:824ed4ae8d52 2316
asong 2:824ed4ae8d52 2317 /*****************************************************************************
asong 2:824ed4ae8d52 2318 Name: Increment_HR_Vibr_Pref
asong 2:824ed4ae8d52 2319 Purpose: Increment the user's heart rate vibration preference by 1
asong 2:824ed4ae8d52 2320 Inputs: None
asong 2:824ed4ae8d52 2321 Returns: None
asong 2:824ed4ae8d52 2322 ******************************************************************************/
asong 2:824ed4ae8d52 2323 void Increment_HR_Vibr_Pref()
asong 2:824ed4ae8d52 2324 {
asong 2:824ed4ae8d52 2325 StartHaptic();
asong 2:824ed4ae8d52 2326 if(HR_Vibration == 3) {
asong 2:824ed4ae8d52 2327 HR_Vibration = 1;
asong 2:824ed4ae8d52 2328 } else {
asong 2:824ed4ae8d52 2329 HR_Vibration += 1;
asong 2:824ed4ae8d52 2330 }
asong 2:824ed4ae8d52 2331 }
asong 2:824ed4ae8d52 2332
asong 2:824ed4ae8d52 2333 /*****************************************************************************
asong 2:824ed4ae8d52 2334 Name: Decrement_HR_Vibr_Pref
asong 2:824ed4ae8d52 2335 Purpose: Decrement the user's heart rate vibration preference by 1
asong 2:824ed4ae8d52 2336 Inputs: None
asong 2:824ed4ae8d52 2337 Returns: None
asong 2:824ed4ae8d52 2338 ******************************************************************************/
asong 2:824ed4ae8d52 2339 void Decrement_HR_Vibr_Pref()
asong 2:824ed4ae8d52 2340 {
asong 2:824ed4ae8d52 2341 StartHaptic();
asong 2:824ed4ae8d52 2342 if(HR_Vibration == 1) {
asong 2:824ed4ae8d52 2343 HR_Vibration = 3;
asong 2:824ed4ae8d52 2344 } else {
asong 2:824ed4ae8d52 2345 HR_Vibration -= 1;
asong 2:824ed4ae8d52 2346 }
asong 2:824ed4ae8d52 2347 }
asong 2:824ed4ae8d52 2348
asong 2:824ed4ae8d52 2349 /*****************************************************************************
asong 2:824ed4ae8d52 2350 Name: Enable_Heart_Rate
asong 2:824ed4ae8d52 2351 Purpose: Turn on the HexiHeart heart rate function
asong 2:824ed4ae8d52 2352 Inputs: None
asong 2:824ed4ae8d52 2353 Returns: None
asong 2:824ed4ae8d52 2354 ******************************************************************************/
asong 2:824ed4ae8d52 2355 void Enable_Heart_Rate()
asong 2:824ed4ae8d52 2356 {
asong 2:824ed4ae8d52 2357 Heart_Rate_Mode = true;
asong 2:824ed4ae8d52 2358 Heart_Rate_Vibrations();
asong 2:824ed4ae8d52 2359 }
asong 2:824ed4ae8d52 2360
asong 2:824ed4ae8d52 2361 /*****************************************************************************
asong 2:824ed4ae8d52 2362 Name: Disable_Heart_Rate
asong 2:824ed4ae8d52 2363 Purpose: Turn off the HexiHeart heart rate function
asong 2:824ed4ae8d52 2364 Inputs: None
asong 2:824ed4ae8d52 2365 Returns: None
asong 2:824ed4ae8d52 2366 ******************************************************************************/
asong 2:824ed4ae8d52 2367 void Disable_Heart_Rate()
asong 2:824ed4ae8d52 2368 {
asong 2:824ed4ae8d52 2369 Heart_Rate_Mode = false;
asong 2:824ed4ae8d52 2370 Heart_Rate_Vibrations();
asong 2:824ed4ae8d52 2371 }
asong 2:824ed4ae8d52 2372
asong 2:824ed4ae8d52 2373 /*****************************************************************************
asong 2:824ed4ae8d52 2374 Name: Determine_Current_Zone
asong 2:824ed4ae8d52 2375 Purpose: Determines which zone the heart rate is in and assigns the curent
asong 2:824ed4ae8d52 2376 zone and previous zone
asong 2:824ed4ae8d52 2377 Inputs: None
asong 2:824ed4ae8d52 2378 Returns: None
asong 2:824ed4ae8d52 2379 ******************************************************************************/
asong 2:824ed4ae8d52 2380 void Determine_Current_Zone()
asong 2:824ed4ae8d52 2381 {
asong 2:824ed4ae8d52 2382 Prev_Zone = Current_Zone;
asong 2:824ed4ae8d52 2383
asong 2:824ed4ae8d52 2384 if(Heart_Rate >= HR_Zone1[0] && Heart_Rate <= HR_Zone1[1]) {
asong 2:824ed4ae8d52 2385 Current_Zone = 1;
asong 2:824ed4ae8d52 2386 } else if(Heart_Rate >= HR_Zone2[0] && Heart_Rate <= HR_Zone2[1]) {
asong 2:824ed4ae8d52 2387 Current_Zone = 2;
asong 2:824ed4ae8d52 2388 } else if(Heart_Rate >= HR_Zone3[0] && Heart_Rate <= HR_Zone3[1]) {
asong 2:824ed4ae8d52 2389 Current_Zone = 3;
asong 2:824ed4ae8d52 2390 } else if(Heart_Rate >= HR_Zone4[0] && Heart_Rate <= HR_Zone4[1]) {
asong 2:824ed4ae8d52 2391 Current_Zone = 4;
asong 2:824ed4ae8d52 2392 } else {
asong 2:824ed4ae8d52 2393 //error reading, don't change anything
asong 2:824ed4ae8d52 2394 }
asong 2:824ed4ae8d52 2395
asong 2:824ed4ae8d52 2396
asong 2:824ed4ae8d52 2397 }
asong 2:824ed4ae8d52 2398 /*****************************************************************************
asong 2:824ed4ae8d52 2399 Name: Run_Heart_Vibrations
asong 2:824ed4ae8d52 2400 Purpose: Performs the HexiHeart heart rate function
asong 2:824ed4ae8d52 2401 Inputs: None
asong 2:824ed4ae8d52 2402 Returns: None
asong 2:824ed4ae8d52 2403 ******************************************************************************/
asong 2:824ed4ae8d52 2404 void Heart_Rate_Vibrations()
asong 2:824ed4ae8d52 2405 {
asong 2:824ed4ae8d52 2406 if(Heart_Rate_Mode == true) {
asong 2:824ed4ae8d52 2407 if(HR_Vibration == 1) {
asong 2:824ed4ae8d52 2408 //All Pre-loaded vibrations enabled
asong 2:824ed4ae8d52 2409 if(Current_Zone == Prev_Zone) {
asong 2:824ed4ae8d52 2410 // Do nothing if no zone change
asong 2:824ed4ae8d52 2411 } else if(Current_Zone == Target_Zone) { //Changed to target zone
asong 2:824ed4ae8d52 2412 if(Target_Zone == LOWEST_ZONE || Prev_Zone > Target_Zone) { //must have entered from above
asong 2:824ed4ae8d52 2413 StartHaptic(ENTER_ABOVE);
asong 2:824ed4ae8d52 2414 } else if(Target_Zone == HIGHEST_ZONE || Prev_Zone < Target_Zone) { //must have entered from below
asong 2:824ed4ae8d52 2415 StartHaptic(ENTER_BELOW);
asong 2:824ed4ae8d52 2416 }
asong 2:824ed4ae8d52 2417 } else if(Current_Zone != Target_Zone && Prev_Zone == Target_Zone) {
asong 2:824ed4ae8d52 2418 if(Target_Zone == HIGHEST_ZONE || Current_Zone < Target_Zone) { //must have exited below
asong 2:824ed4ae8d52 2419 StartHaptic(EXIT_BELOW);
asong 2:824ed4ae8d52 2420 } else if(Target_Zone == LOWEST_ZONE || Current_Zone > Target_Zone) { //must have exited above
asong 2:824ed4ae8d52 2421 StartHaptic(EXIT_ABOVE);
asong 2:824ed4ae8d52 2422 }
asong 2:824ed4ae8d52 2423 }
asong 2:824ed4ae8d52 2424 } else if(HR_Vibration == 2) {
asong 2:824ed4ae8d52 2425 //Only Entering and Exiting target zone
asong 2:824ed4ae8d52 2426 if(Current_Zone == Prev_Zone) {
asong 2:824ed4ae8d52 2427 //do nothing
asong 2:824ed4ae8d52 2428 } else if(Current_Zone == Target_Zone) {
asong 2:824ed4ae8d52 2429 StartHaptic(VIB_OPT_2);
asong 2:824ed4ae8d52 2430 wait(0.1);
asong 2:824ed4ae8d52 2431 StartHaptic(VIB_OPT_2);
asong 2:824ed4ae8d52 2432 } else if(Current_Zone != Target_Zone && Prev_Zone == Target_Zone) {
asong 2:824ed4ae8d52 2433 StartHaptic(VIB_OPT_2);
asong 2:824ed4ae8d52 2434 wait(0.1);
asong 2:824ed4ae8d52 2435 StartHaptic(VIB_OPT_2);
asong 2:824ed4ae8d52 2436 wait(0.1);
asong 2:824ed4ae8d52 2437 StartHaptic(VIB_OPT_2);
asong 2:824ed4ae8d52 2438 }
asong 2:824ed4ae8d52 2439
asong 2:824ed4ae8d52 2440 } else if(HR_Vibration == 3) {
asong 2:824ed4ae8d52 2441 //No Vibrations
asong 2:824ed4ae8d52 2442
asong 2:824ed4ae8d52 2443 } else {
asong 2:824ed4ae8d52 2444 //Error, can only be choices 1-3
asong 2:824ed4ae8d52 2445 error_screen();
asong 2:824ed4ae8d52 2446 }
asong 2:824ed4ae8d52 2447 }
asong 2:824ed4ae8d52 2448 }
asong 2:824ed4ae8d52 2449
asong 2:824ed4ae8d52 2450 /*****************************************************************************
asong 2:824ed4ae8d52 2451 Name: Increment_Heart_Rate
asong 2:824ed4ae8d52 2452 Purpose: Manually increment the the heart rate measurement by 1 for testing
asong 2:824ed4ae8d52 2453 purposes
asong 2:824ed4ae8d52 2454 Inputs: None
asong 2:824ed4ae8d52 2455 Returns: None
asong 2:824ed4ae8d52 2456 ******************************************************************************/
asong 2:824ed4ae8d52 2457 void Increment_Heart_Rate()
asong 2:824ed4ae8d52 2458 {
asong 2:824ed4ae8d52 2459 //StartHaptic();
asong 2:824ed4ae8d52 2460 if(Heart_Rate == HR_Zone4[1]) {
asong 2:824ed4ae8d52 2461 Heart_Rate = HR_Zone1[0];
asong 2:824ed4ae8d52 2462 } else {
asong 2:824ed4ae8d52 2463 Heart_Rate += 1;
asong 2:824ed4ae8d52 2464 }
asong 2:824ed4ae8d52 2465 }
asong 2:824ed4ae8d52 2466
asong 2:824ed4ae8d52 2467 /*****************************************************************************
asong 2:824ed4ae8d52 2468 Name: Decrement_Heart_Rate
asong 2:824ed4ae8d52 2469 Purpose: Manually decrement the the heart rate measurement by 1 for testing
asong 2:824ed4ae8d52 2470 purposes
asong 2:824ed4ae8d52 2471 Inputs: None
asong 2:824ed4ae8d52 2472 Returns: None
asong 2:824ed4ae8d52 2473 ******************************************************************************/
asong 2:824ed4ae8d52 2474 void Decrement_Heart_Rate()
asong 2:824ed4ae8d52 2475 {
asong 2:824ed4ae8d52 2476 //StartHaptic();
asong 2:824ed4ae8d52 2477 if(Heart_Rate == HR_Zone1[0]) {
asong 2:824ed4ae8d52 2478 Heart_Rate = HR_Zone4[1];
asong 2:824ed4ae8d52 2479 } else {
asong 2:824ed4ae8d52 2480 Heart_Rate -= 1;
asong 2:824ed4ae8d52 2481 }
nbaker 4:0803151bc5e4 2482 } // end of Decrement_Heart_Rate
asong 2:824ed4ae8d52 2483
asong 2:824ed4ae8d52 2484 void Led_Zone_Indicator()
asong 2:824ed4ae8d52 2485 {
asong 2:824ed4ae8d52 2486 if(Led_Zones == true)
asong 2:824ed4ae8d52 2487 {
asong 2:824ed4ae8d52 2488 if(Current_Zone == 1)
asong 2:824ed4ae8d52 2489 {
asong 2:824ed4ae8d52 2490 BLU_Led = LED_OFF;
asong 2:824ed4ae8d52 2491 RED_Led = LED_ON;
asong 2:824ed4ae8d52 2492 GRN_Led = LED_ON;
asong 3:6792c1ba586c 2493
asong 3:6792c1ba586c 2494 wait(0.5);
asong 3:6792c1ba586c 2495 RED_Led = LED_OFF;
asong 3:6792c1ba586c 2496 GRN_Led = LED_OFF;
asong 2:824ed4ae8d52 2497 }
asong 2:824ed4ae8d52 2498 else if(Current_Zone == 2)
asong 2:824ed4ae8d52 2499 {
asong 2:824ed4ae8d52 2500 if(Prev_Zone == 1)
asong 2:824ed4ae8d52 2501 {
asong 2:824ed4ae8d52 2502 RED_Led = LED_OFF;
asong 2:824ed4ae8d52 2503 GRN_Led = LED_OFF;
asong 2:824ed4ae8d52 2504 }
asong 2:824ed4ae8d52 2505 else if(Prev_Zone == 3)
asong 2:824ed4ae8d52 2506 {
asong 2:824ed4ae8d52 2507 GRN_Led = LED_OFF;
asong 2:824ed4ae8d52 2508 }
asong 2:824ed4ae8d52 2509 BLU_Led = LED_ON;
asong 3:6792c1ba586c 2510 wait(0.5);
asong 3:6792c1ba586c 2511 BLU_Led = LED_OFF;
asong 2:824ed4ae8d52 2512 }
asong 2:824ed4ae8d52 2513 else if(Current_Zone == 3)
asong 2:824ed4ae8d52 2514 {
asong 2:824ed4ae8d52 2515 if(Prev_Zone == 2)
asong 2:824ed4ae8d52 2516 {
asong 2:824ed4ae8d52 2517 BLU_Led = LED_OFF;
asong 2:824ed4ae8d52 2518 }
asong 2:824ed4ae8d52 2519 else if(Prev_Zone == 4)
asong 2:824ed4ae8d52 2520 {
asong 2:824ed4ae8d52 2521 RED_Led = LED_OFF;
asong 2:824ed4ae8d52 2522 }
asong 2:824ed4ae8d52 2523 GRN_Led = LED_ON;
asong 3:6792c1ba586c 2524 wait(0.5);
asong 3:6792c1ba586c 2525 GRN_Led = LED_OFF;
asong 2:824ed4ae8d52 2526 }
asong 2:824ed4ae8d52 2527 else if(Current_Zone == 4)
asong 2:824ed4ae8d52 2528 {
asong 2:824ed4ae8d52 2529 GRN_Led = LED_OFF;
asong 2:824ed4ae8d52 2530 RED_Led = LED_ON;
asong 3:6792c1ba586c 2531 wait(0.5);
asong 3:6792c1ba586c 2532 RED_Led = LED_OFF;
asong 2:824ed4ae8d52 2533 }
nbaker 4:0803151bc5e4 2534 }
nbaker 4:0803151bc5e4 2535 }//end of Led_Zone_Indicator
jmr274 5:e1431272be79 2536
jmr274 5:e1431272be79 2537 /*****************************************************************************
jmr274 5:e1431272be79 2538 Name: Heat_Index_Calculation()
jmr274 5:e1431272be79 2539 Purpose: Calculates the heat index using the temperature and humidity sensors
jmr274 5:e1431272be79 2540 Inputs: None
jmr274 5:e1431272be79 2541 Returns: None
jmr274 5:e1431272be79 2542 ******************************************************************************/
jmr274 5:e1431272be79 2543 void Heat_Index_Calculation(){
jmr274 5:e1431272be79 2544 sample_ftemp = temphumid.sample_ftemp();
jmr274 5:e1431272be79 2545
jmr274 5:e1431272be79 2546 sample_humid = temphumid.sample_humid();
jmr274 5:e1431272be79 2547
nbaker 9:d2e39ee9fedd 2548 hi_calc = -42.379 +
jmr274 5:e1431272be79 2549 2.04901523 * sample_ftemp +
jmr274 5:e1431272be79 2550 10.14333127 * sample_humid -
jmr274 5:e1431272be79 2551 0.22475541 * sample_ftemp * sample_humid -
jmr274 5:e1431272be79 2552 0.00683783 * sample_ftemp * sample_ftemp -
jmr274 5:e1431272be79 2553 0.05481717 * sample_humid * sample_humid +
jmr274 5:e1431272be79 2554 0.00122874 * sample_ftemp * sample_ftemp * sample_humid +
jmr274 5:e1431272be79 2555 0.00085282 * sample_ftemp * sample_humid * sample_humid -
jmr274 5:e1431272be79 2556 0.00000199 * sample_ftemp * sample_ftemp * sample_humid * sample_humid;
nbaker 9:d2e39ee9fedd 2557
nbaker 9:d2e39ee9fedd 2558 if (sample_humid < 13 && sample_ftemp > 80 && sample_ftemp < 112){
nbaker 9:d2e39ee9fedd 2559 adjustment = ((13 - sample_humid) / 4) * sqrt((17-abs(sample_ftemp-95.0))/17);
nbaker 9:d2e39ee9fedd 2560 heat_index = hi_calc - adjustment;
nbaker 9:d2e39ee9fedd 2561 }
nbaker 9:d2e39ee9fedd 2562
nbaker 9:d2e39ee9fedd 2563 else if (sample_humid > 85 && sample_ftemp > 80 && sample_ftemp < 87){
nbaker 9:d2e39ee9fedd 2564 adjustment = ((sample_humid - 85) / 10) * ((87 - sample_ftemp)/5);
nbaker 9:d2e39ee9fedd 2565 heat_index = hi_calc + adjustment;
nbaker 9:d2e39ee9fedd 2566 }
nbaker 9:d2e39ee9fedd 2567
nbaker 9:d2e39ee9fedd 2568 else if (hi_calc < 80){
nbaker 9:d2e39ee9fedd 2569 heat_index = 0.5 * (sample_ftemp + 61.0 + ((sample_ftemp - 68.0) * 1.2) + (sample_humid * 0.094));
nbaker 9:d2e39ee9fedd 2570 }
nbaker 9:d2e39ee9fedd 2571
nbaker 9:d2e39ee9fedd 2572 else {heat_index = hi_calc;}
jmr274 5:e1431272be79 2573 }
jmr274 5:e1431272be79 2574
nbaker 4:0803151bc5e4 2575 /*****************************************************************************
nbaker 10:eaea844e763c 2576 Name: fall_detect_debug()
nbaker 10:eaea844e763c 2577 Purpose: Debug Interupt routine called when accelerometer IC has detected a
nbaker 10:eaea844e763c 2578 free-fall (accel <= 0.5g)
nbaker 10:eaea844e763c 2579 Inputs: interupt1 of accel sensor
nbaker 4:0803151bc5e4 2580 ******************************************************************************/
nbaker 10:eaea844e763c 2581 void fall_detect_debug(){// fall detect interupt routine
nbaker 4:0803151bc5e4 2582 if(Fall_Alert == 1){
nbaker 7:3d5a8aea0b63 2583 accel.acquire_accel_data_g(Accel_Data_Event);
nbaker 4:0803151bc5e4 2584 // for now just turn on display and give haptic feedback
nbaker 4:0803151bc5e4 2585 Screen_Timer.attach(&timout_timer,(SCRN_TIME));// Reset/restart ticker timer for OLED
nbaker 9:d2e39ee9fedd 2586
nbaker 4:0803151bc5e4 2587 if (OLED_ON == 0) {
nbaker 4:0803151bc5e4 2588 OLED_ON = 1; // Scree was off, set to On
nbaker 9:d2e39ee9fedd 2589 update_display();
nbaker 9:d2e39ee9fedd 2590 } // endif
nbaker 9:d2e39ee9fedd 2591 if (Screen_Num != 21){
nbaker 9:d2e39ee9fedd 2592 Screen_Num = 21; //Change to screen 21 (Fall diag screen)
nbaker 9:d2e39ee9fedd 2593 update_display();
nbaker 9:d2e39ee9fedd 2594 } // endif
nbaker 4:0803151bc5e4 2595
nbaker 4:0803151bc5e4 2596 //__disable_irq(); // Disable all Interrupts
nbaker 4:0803151bc5e4 2597 // oled.Label((uint8_t *)" Fall Detected ",05,70); // Display at x,y
nbaker 9:d2e39ee9fedd 2598
nbaker 9:d2e39ee9fedd 2599 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 9:d2e39ee9fedd 2600 sprintf(text_1,"Free-Fall:%2.2fg",Accel_Mag);
nbaker 9:d2e39ee9fedd 2601 oled.Label((uint8_t *)text_1,2,5);// text_1 at x,y
nbaker 7:3d5a8aea0b63 2602
nbaker 4:0803151bc5e4 2603 BLU_Led = LED_ON; // LEDs default to on, need to turn off
nbaker 10:eaea844e763c 2604 Led_clk1 = 1; // Turn on LED1, on docking station
nbaker 10:eaea844e763c 2605 StartHaptic();
nbaker 10:eaea844e763c 2606 // haptic = 1;
nbaker 10:eaea844e763c 2607 Accel_INT1.rise(&fall_det_end_debug); // reset accel sensor's int#1 to active high and proper int routine
nbaker 4:0803151bc5e4 2608 //__enable_irq(); // Enable all Interrupts
nbaker 4:0803151bc5e4 2609 }// end if
nbaker 10:eaea844e763c 2610 }//end fall_detect_debug interupt routine
nbaker 4:0803151bc5e4 2611
nbaker 10:eaea844e763c 2612 /*****************************************************************************
nbaker 10:eaea844e763c 2613 Name: fall_det_end_debug()
nbaker 10:eaea844e763c 2614 Purpose: Debug interupt routine called when accelerometer IC has detected that the
nbaker 10:eaea844e763c 2615 free-fall acceleration has ended (accel now >0.5g)
nbaker 10:eaea844e763c 2616 Inputs: interupt1 of accel sensor
nbaker 10:eaea844e763c 2617 ******************************************************************************/
nbaker 10:eaea844e763c 2618 void fall_det_end_debug(){
nbaker 4:0803151bc5e4 2619 haptic = 0; // Turn off Haptic
nbaker 4:0803151bc5e4 2620 BLU_Led = LED_OFF; // Turn off HexiHeart Blue LED
nbaker 10:eaea844e763c 2621 Led_clk1 = 0; // Turn off LED1, on docking station
nbaker 9:d2e39ee9fedd 2622 fall_config(21); // reads interrupts to clear old interupt
nbaker 8:a5c77b45008d 2623 // oled.Label((uint8_t *)" ",05,70); // clear display at x,y
nbaker 10:eaea844e763c 2624 Accel_INT1.fall(&fall_detect_debug); // reset accel sensor's int#1 to active low and proper int routine
nbaker 10:eaea844e763c 2625 } //end fall_det_end_debug interupt routine
nbaker 4:0803151bc5e4 2626
nbaker 4:0803151bc5e4 2627 /*****************************************************************************
nbaker 10:eaea844e763c 2628 Name: impact_detect_debug()
nbaker 10:eaea844e763c 2629 Purpose: Debug Interupt routine called when accelerometer IC has detected a vector
nbaker 4:0803151bc5e4 2630 magnitude acceleration >= 3.0g
nbaker 10:eaea844e763c 2631 Inputs: interupt2 of accel sensor
nbaker 4:0803151bc5e4 2632 ******************************************************************************/
nbaker 10:eaea844e763c 2633 void impact_detect_debug(){
nbaker 7:3d5a8aea0b63 2634 if(Fall_Alert == 1){
nbaker 7:3d5a8aea0b63 2635 accel.acquire_accel_data_g(Accel_Data_Event);
nbaker 9:d2e39ee9fedd 2636 haptic = 1;
nbaker 10:eaea844e763c 2637 Led_clk2 = 1; // Turn LED2 on docking station on
nbaker 9:d2e39ee9fedd 2638
nbaker 7:3d5a8aea0b63 2639 Screen_Timer.attach(&timout_timer,(SCRN_TIME));// Reset/restart ticker timer for OLED
nbaker 7:3d5a8aea0b63 2640 if (OLED_ON == 0) {
nbaker 9:d2e39ee9fedd 2641 OLED_ON = 1; // Screen was off, set to On
nbaker 9:d2e39ee9fedd 2642 update_display();
nbaker 9:d2e39ee9fedd 2643 } // endif
nbaker 9:d2e39ee9fedd 2644
nbaker 9:d2e39ee9fedd 2645 if (Screen_Num != 21){
nbaker 9:d2e39ee9fedd 2646 Screen_Num = 21; //Change to screen 21 (Fall diag screen)
nbaker 9:d2e39ee9fedd 2647 update_display();
nbaker 9:d2e39ee9fedd 2648 } // endif
nbaker 9:d2e39ee9fedd 2649 accel.acquire_accel_data_g(Accel_Data);
nbaker 9:d2e39ee9fedd 2650 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 9:d2e39ee9fedd 2651 sprintf(text_1,"Impact:%2.2fg",Accel_Mag);
nbaker 9:d2e39ee9fedd 2652 oled.Label((uint8_t *)text_1,3,20);// text_1 at x,y
nbaker 9:d2e39ee9fedd 2653 wait(0.1);
nbaker 10:eaea844e763c 2654 Led_clk2 = 0; // Turn LED2 off docking station on
nbaker 9:d2e39ee9fedd 2655 haptic = 0;
nbaker 7:3d5a8aea0b63 2656 }// end if
nbaker 10:eaea844e763c 2657 }//end impact_detect_debug interupt routine
nbaker 4:0803151bc5e4 2658
nbaker 4:0803151bc5e4 2659 /*****************************************************************************
nbaker 10:eaea844e763c 2660 Name: motion_detect_debug()
nbaker 10:eaea844e763c 2661 Purpose: Debug Interupt routine called when gyro IC has detected motion >= 50 deg/sec
nbaker 9:d2e39ee9fedd 2662 in order to see if fall-impact resulted in motion-less person.
nbaker 10:eaea844e763c 2663 Inputs: interupt1 of gyro sensor
nbaker 9:d2e39ee9fedd 2664 ******************************************************************************/
nbaker 10:eaea844e763c 2665 void motion_detect_debug(){
nbaker 9:d2e39ee9fedd 2666 float Gyro_Data_Event[3]; // store right away to see what it was
nbaker 9:d2e39ee9fedd 2667 if(Fall_Alert == 1 && Fall_Alert_Mode > 2){// only service interupt if automatic fall detect is selected by user
nbaker 9:d2e39ee9fedd 2668 gyro.acquire_gyro_data_dps(Gyro_Data_Event);
nbaker 9:d2e39ee9fedd 2669 Gyro_Mag = (abs(Gyro_Data_Event[0])+abs(Gyro_Data_Event[1])+abs(Gyro_Data_Event[2]));
nbaker 9:d2e39ee9fedd 2670 haptic = 1;
nbaker 10:eaea844e763c 2671 Led_clk3 = 1; // Turn on LED3, on docking station
nbaker 9:d2e39ee9fedd 2672
nbaker 9:d2e39ee9fedd 2673 Screen_Timer.attach(&timout_timer,(SCRN_TIME));// Reset/restart ticker timer for OLED
nbaker 9:d2e39ee9fedd 2674 if (OLED_ON == 0) {
nbaker 9:d2e39ee9fedd 2675 OLED_ON = 1; // Screen was off, set to On
nbaker 9:d2e39ee9fedd 2676 update_display();
nbaker 9:d2e39ee9fedd 2677 } // endif
nbaker 9:d2e39ee9fedd 2678
nbaker 9:d2e39ee9fedd 2679 if (Screen_Num != 21){
nbaker 9:d2e39ee9fedd 2680 Screen_Num = 21; //Change to screen 21 (Fall diag screen)
nbaker 9:d2e39ee9fedd 2681 update_display();
nbaker 9:d2e39ee9fedd 2682 } // endif
nbaker 9:d2e39ee9fedd 2683 sprintf(text_1,"Motion:%4.0f d/s",Gyro_Mag);
nbaker 9:d2e39ee9fedd 2684 oled.Label((uint8_t *)text_1,3,20);// text_1 at x,y
nbaker 10:eaea844e763c 2685 gyro_sensor_config(13); // reset motion counter
nbaker 9:d2e39ee9fedd 2686 wait(0.1);
nbaker 10:eaea844e763c 2687 Led_clk3 = 0; // Turn LED3 off docking station on
nbaker 9:d2e39ee9fedd 2688 haptic = 0;
nbaker 9:d2e39ee9fedd 2689 }// end if
nbaker 10:eaea844e763c 2690 }//end motion_detect_debug interupt routine
nbaker 10:eaea844e763c 2691
nbaker 10:eaea844e763c 2692 //********** Full sequential fall interup routines below *********************
nbaker 10:eaea844e763c 2693 /*****************************************************************************
nbaker 10:eaea844e763c 2694 Name: fall_detect()
nbaker 10:eaea844e763c 2695 Purpose: Interupt routine called when accelerometer IC has detected a
nbaker 10:eaea844e763c 2696 free-fall (accel <= 0.5g)
nbaker 10:eaea844e763c 2697 Inputs: interupt1 of accel sensor
nbaker 10:eaea844e763c 2698 ******************************************************************************/
nbaker 10:eaea844e763c 2699 void fall_detect(){// fall detect interupt routine
nbaker 10:eaea844e763c 2700 if(Fall_Alert == 1 && Led_clk2 == 0){// are we looking for falls? Have we already det impact?
nbaker 10:eaea844e763c 2701 accel.acquire_accel_data_g(Accel_Data_Event);
nbaker 10:eaea844e763c 2702 f_time.reset();
nbaker 10:eaea844e763c 2703 f_time.start(); //start measuring fall time
nbaker 10:eaea844e763c 2704 for (int i=0; i<7; i++){
nbaker 10:eaea844e763c 2705 Fall_Event_Data[i] = 0; // clear any old information
nbaker 10:eaea844e763c 2706 }//end for loop
nbaker 10:eaea844e763c 2707
nbaker 10:eaea844e763c 2708 // Screen_Timer.attach(&timout_timer,(SCRN_TIME));// Reset/restart ticker timer for OLED
nbaker 10:eaea844e763c 2709 //time_t seconds = time(NULL);
nbaker 10:eaea844e763c 2710 //store time into Fall_Event_Data buffer
nbaker 10:eaea844e763c 2711 Fall_Event_Data[0] = 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 10:eaea844e763c 2712 Led_clk1 = 1; // Turn on LED1, on docking station
nbaker 10:eaea844e763c 2713 //Led_clk2 = 0; // Turn off LED2, on docking station
nbaker 10:eaea844e763c 2714 Accel_INT1.rise(&fall_det_end); // look for end of fall by reseting accel sensor's int#1 to active high
nbaker 10:eaea844e763c 2715 // Accel_INT1.fall(&fall_detect); // Accel sensor's int#1 calls interupt routine
nbaker 10:eaea844e763c 2716 Accel_INT2.fall(&impact_detect); //Start looking for vector impacts
nbaker 10:eaea844e763c 2717 // Gyro_INT1.fall(&motion_detect); // Gyro sensor's int#1 (PTD1) calls interupt routine
nbaker 10:eaea844e763c 2718 chk_fall.attach(&chkfall,(0.5)); //initialize ticker to check for end of fall every half second
nbaker 10:eaea844e763c 2719
nbaker 10:eaea844e763c 2720 }// end if
nbaker 10:eaea844e763c 2721 }//end fall_detect interupt routine
nbaker 10:eaea844e763c 2722
nbaker 10:eaea844e763c 2723
nbaker 10:eaea844e763c 2724 /*****************************************************************************
nbaker 10:eaea844e763c 2725 Name: chkfall()
nbaker 10:eaea844e763c 2726 Purpose: Ticker interupt routine called every 0.5 Seconds (after a free-fall has been detected)
nbaker 10:eaea844e763c 2727 to check to see if we've missed the interupt indicating the free-fall event is over.
nbaker 10:eaea844e763c 2728 Inputs: chk_fall Ticker
nbaker 10:eaea844e763c 2729 ******************************************************************************/
nbaker 10:eaea844e763c 2730 void chkfall(){// Ticker fall-end detect routine to see if we missed interupt
nbaker 10:eaea844e763c 2731 if(Accel_INT1 == 0){//fall still active
nbaker 10:eaea844e763c 2732 accel.acquire_accel_data_g(Accel_Data_Event);
nbaker 10:eaea844e763c 2733 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 10:eaea844e763c 2734 if (Accel_Mag < Fall_Event_Data[0]){
nbaker 10:eaea844e763c 2735 Fall_Event_Data[0] = Accel_Mag;// if fall is less than previous re-store value
nbaker 10:eaea844e763c 2736 }//endif
nbaker 10:eaea844e763c 2737 }//endif
nbaker 10:eaea844e763c 2738 else{//fall interupt off
nbaker 10:eaea844e763c 2739 f_time.stop(); // stop fall timer
nbaker 10:eaea844e763c 2740 chk_fall.detach(); //stop ticker, interupt caught end of fall
nbaker 10:eaea844e763c 2741 chk_fall.attach(&clear_fall,(2.0)); //initialize ticker to check no impact in 2 seconds
nbaker 10:eaea844e763c 2742 Accel_INT1.fall(NULL); // turn off accel sensor's int#1
nbaker 10:eaea844e763c 2743 }//end else
nbaker 10:eaea844e763c 2744
nbaker 10:eaea844e763c 2745 }//end chkfall ticker interupt routine
nbaker 10:eaea844e763c 2746
nbaker 10:eaea844e763c 2747 /*****************************************************************************
nbaker 10:eaea844e763c 2748 Name: interupt_off()
nbaker 10:eaea844e763c 2749 Purpose: Interupts are supposed to be turned off by using "Int_name.fall(NULL);", but
nbaker 10:eaea844e763c 2750 that doesn't seem to work.
nbaker 10:eaea844e763c 2751 ******************************************************************************/
nbaker 10:eaea844e763c 2752 void interupt_off(){// turn off an interupt by substituting this one
nbaker 10:eaea844e763c 2753 // Do nothing
nbaker 10:eaea844e763c 2754 }//end interupt_off routine
nbaker 10:eaea844e763c 2755
nbaker 10:eaea844e763c 2756
nbaker 10:eaea844e763c 2757 /*****************************************************************************
nbaker 10:eaea844e763c 2758 Name: fall_det_end()
nbaker 10:eaea844e763c 2759 Purpose: Interupt routine called when accelerometer IC has detected that the
nbaker 10:eaea844e763c 2760 free-fall acceleration has ended (accel now >0.5g)
nbaker 10:eaea844e763c 2761 Inputs: interupt1 of accel sensor
nbaker 10:eaea844e763c 2762 ******************************************************************************/
nbaker 10:eaea844e763c 2763 void fall_det_end(){ // accel detected end of free-fall
nbaker 10:eaea844e763c 2764 f_time.stop(); // stop fall timer
nbaker 10:eaea844e763c 2765 chk_fall.detach(); //stop ticker, interupt caught end of fall
nbaker 10:eaea844e763c 2766 chk_fall.attach(&clear_fall,(Fall_Impact_Max_Wait_Time)); //initialize ticker to check no impact in 2 seconds
nbaker 10:eaea844e763c 2767 // fall_config(21); // reads interrupts to clear old interupt
nbaker 10:eaea844e763c 2768 Accel_INT1.fall(NULL); // Turn off accel sensor's int#1
nbaker 10:eaea844e763c 2769 } //end fall_det_end interupt routine
nbaker 10:eaea844e763c 2770
nbaker 10:eaea844e763c 2771
nbaker 10:eaea844e763c 2772 /*****************************************************************************
nbaker 10:eaea844e763c 2773 Name: clear_fall()
nbaker 10:eaea844e763c 2774 Purpose: Ticker interupt routine called to clear/cancel fall detection routine if
nbaker 10:eaea844e763c 2775 no impact was detected withing 2.0 seconds after the free-fall event
nbaker 10:eaea844e763c 2776 Inputs: chk_fall Ticker
nbaker 10:eaea844e763c 2777 ******************************************************************************/
nbaker 10:eaea844e763c 2778 void clear_fall(){// Ticker routine to clear_fall detect routine if no impact in 2.0 seconds after free-fall event is over
nbaker 10:eaea844e763c 2779 if(Led_clk2 == 1){// have we detected an impact?
nbaker 10:eaea844e763c 2780 chk_fall.detach(); //just stop ticker
nbaker 10:eaea844e763c 2781 }//endif
nbaker 10:eaea844e763c 2782 else{
nbaker 10:eaea844e763c 2783 Accel_INT1.fall(&fall_detect); // reset accel sensor's int#1 to active low and reset for next fall
nbaker 10:eaea844e763c 2784 Accel_INT2.fall(NULL); //Stop looking for vector impacts,
nbaker 10:eaea844e763c 2785 Led_clk1 = 0; // Turn off LED1, on docking station
nbaker 10:eaea844e763c 2786 }//end else
nbaker 10:eaea844e763c 2787 }//end clear_fall ticker interupt routine
nbaker 10:eaea844e763c 2788
nbaker 10:eaea844e763c 2789
nbaker 10:eaea844e763c 2790 /*****************************************************************************
nbaker 10:eaea844e763c 2791 Name: impact_detect()
nbaker 10:eaea844e763c 2792 Purpose: Interupt routine called when accelerometer IC has detected a vector
nbaker 10:eaea844e763c 2793 magnitude acceleration >= 3.0g
nbaker 10:eaea844e763c 2794 Inputs: interupt2 of accel sensor
nbaker 10:eaea844e763c 2795 ******************************************************************************/
nbaker 10:eaea844e763c 2796 void impact_detect(){// we may detect multiple impacts, this needs to work from last impact detected
nbaker 10:eaea844e763c 2797 if(Fall_Alert == 1){
nbaker 10:eaea844e763c 2798 f_time.stop(); // stop fall timer
nbaker 10:eaea844e763c 2799 accel.acquire_accel_data_g(Accel_Data_Event);
nbaker 10:eaea844e763c 2800 chk_fall.detach(); //detach/stop ticker, impact was detected
nbaker 10:eaea844e763c 2801 wait(0.1);
nbaker 10:eaea844e763c 2802 Fall_Event_Data[1] = f_time;// store free-fall time
nbaker 10:eaea844e763c 2803 Led_clk2 = 1; // Turn on LED2, on docking station
nbaker 10:eaea844e763c 2804 gyro_sensor_config(13); // reset motion counter
nbaker 10:eaea844e763c 2805 Gyro_INT1.fall(&motion_detect); // Start looking for motion
nbaker 10:eaea844e763c 2806 chk_motion.attach(&chkmotion,(Min_Movement_duration)); //initialize ticker to check for motion during Min_Movement_duration
nbaker 10:eaea844e763c 2807 } // endif
nbaker 10:eaea844e763c 2808 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 10:eaea844e763c 2809 if(Accel_Mag>Fall_Event_Data[2]){
nbaker 10:eaea844e763c 2810 Fall_Event_Data[2] = Accel_Mag; // if impact accel is higher than last measured, update
nbaker 10:eaea844e763c 2811 }//endif
nbaker 10:eaea844e763c 2812 //wait(0.1);
nbaker 10:eaea844e763c 2813 //Led_clk3 = 1; // Turn on LED3, on docking station - we're looking for motion
nbaker 10:eaea844e763c 2814 }//end impact_detect interupt routine
nbaker 10:eaea844e763c 2815
nbaker 10:eaea844e763c 2816 /*****************************************************************************
nbaker 10:eaea844e763c 2817 Name: motion_detect()
nbaker 10:eaea844e763c 2818 Purpose: Interupt routine called when gyro IC has detected motion >= 50 deg/sec
nbaker 10:eaea844e763c 2819 in order to see if fall-impact resulted in motion-less person.
nbaker 10:eaea844e763c 2820 Inputs: interupt1 of gyro sensor
nbaker 10:eaea844e763c 2821 ******************************************************************************/
nbaker 10:eaea844e763c 2822 void motion_detect(){// 2 seconds of motion was detected
nbaker 10:eaea844e763c 2823 chk_motion.detach(); //stop ticker, we've detected motion
nbaker 10:eaea844e763c 2824 Accel_INT1.fall(&fall_detect); // Accel sensor's int#1 calls interupt routine
nbaker 10:eaea844e763c 2825 Accel_INT2.fall(NULL); //Reset for next event
nbaker 10:eaea844e763c 2826 Gyro_INT1.fall(NULL); //Reset for next event
nbaker 10:eaea844e763c 2827 //wait(0.1);
nbaker 10:eaea844e763c 2828 Led_clk1 = 0; // Turn off LED1, on docking station
nbaker 10:eaea844e763c 2829 Led_clk2 = 0; // Turn off LED2, on docking station
nbaker 10:eaea844e763c 2830
nbaker 9:d2e39ee9fedd 2831 }//end motion_detect interupt routine
nbaker 9:d2e39ee9fedd 2832
nbaker 10:eaea844e763c 2833
nbaker 10:eaea844e763c 2834 /*****************************************************************************
nbaker 10:eaea844e763c 2835 Name: chkmotion()
nbaker 10:eaea844e763c 2836 Purpose: Ticker interupt routine called when 60sec window has elapsed without
nbaker 10:eaea844e763c 2837 2seconds of motion being detected.
nbaker 10:eaea844e763c 2838 Inputs: chk_motion Ticker
nbaker 10:eaea844e763c 2839 ******************************************************************************/
nbaker 10:eaea844e763c 2840 void chkmotion(){// if we got here we didn't detect motion
nbaker 10:eaea844e763c 2841 //
nbaker 10:eaea844e763c 2842 chk_motion.detach(); //stop ticker
nbaker 10:eaea844e763c 2843 Screen_Num = 47; //Change to screen 47 (Fall diag screen)
nbaker 10:eaea844e763c 2844 Screen_Timer.attach(&timout_timer,(SCRN_TIME));// Reset/restart ticker timer for OLED
nbaker 10:eaea844e763c 2845 if (OLED_ON == 0) {
nbaker 10:eaea844e763c 2846 OLED_ON = 1; // Screen was off, set to On
nbaker 10:eaea844e763c 2847 } // endif
nbaker 10:eaea844e763c 2848 update_display(); //
nbaker 10:eaea844e763c 2849 chk_motion.attach(&chk_help_needed,(Do_You_Need_Help_Time)); //initialize ticker to send automatic alert
nbaker 10:eaea844e763c 2850 haptic = 1;
nbaker 10:eaea844e763c 2851 wait(0.2);// very aggressive hapic
nbaker 10:eaea844e763c 2852 haptic = 0;
nbaker 10:eaea844e763c 2853 wait(0.2);
nbaker 10:eaea844e763c 2854 haptic = 1;
nbaker 10:eaea844e763c 2855 wait(0.2);// very aggressive hapic
nbaker 10:eaea844e763c 2856 haptic = 0;
nbaker 10:eaea844e763c 2857 wait(0.2);
nbaker 10:eaea844e763c 2858 haptic = 1;
nbaker 10:eaea844e763c 2859 wait(0.2);// very aggressive hapic
nbaker 10:eaea844e763c 2860 haptic = 0;
nbaker 10:eaea844e763c 2861
nbaker 10:eaea844e763c 2862 }//end of chkmotion ticker interupt routine
nbaker 10:eaea844e763c 2863
nbaker 10:eaea844e763c 2864 /*****************************************************************************
nbaker 10:eaea844e763c 2865 Name: chk_help_needed()
nbaker 10:eaea844e763c 2866 Purpose: Ticker interupt routine called when X sec window has elapsed without
nbaker 10:eaea844e763c 2867 user dimissing "Are you OK" screen, sends automatic alert.
nbaker 10:eaea844e763c 2868 Inputs: chk_motion Ticker
nbaker 10:eaea844e763c 2869 ******************************************************************************/
nbaker 10:eaea844e763c 2870 void chk_help_needed(){// Were they able to dismiss on their own?
nbaker 10:eaea844e763c 2871 //
nbaker 10:eaea844e763c 2872 chk_motion.detach(); //stop ticker
nbaker 10:eaea844e763c 2873 if (Screen_Num == 47){// are we still on screen 47?
nbaker 10:eaea844e763c 2874 Screen_Num = 48; //Change to screen 48 and send alert
nbaker 10:eaea844e763c 2875 Screen_Timer.attach(&timout_timer,(SCRN_TIME));// Reset/restart ticker timer for OLED to keep it on
nbaker 10:eaea844e763c 2876 if (OLED_ON == 0) {
nbaker 10:eaea844e763c 2877 OLED_ON = 1; // Screen was off, set to On
nbaker 10:eaea844e763c 2878 } // endif
nbaker 10:eaea844e763c 2879 update_display();
nbaker 10:eaea844e763c 2880 oled_text_properties_t textProperties = {0};
nbaker 10:eaea844e763c 2881 oled.GetTextProperties(&textProperties);
nbaker 10:eaea844e763c 2882 textProperties.fontColor = COLOR_RED;
nbaker 10:eaea844e763c 2883 oled.SetTextProperties(&textProperties);
nbaker 10:eaea844e763c 2884 oled.Label((uint8_t *)"No responce!", 5, 20);
nbaker 10:eaea844e763c 2885 textProperties.fontColor = COLOR_WHITE;
nbaker 10:eaea844e763c 2886 oled.SetTextProperties(&textProperties);
nbaker 10:eaea844e763c 2887 Send_Alert(2); // send alert type two
nbaker 10:eaea844e763c 2888 haptic = 1;
nbaker 10:eaea844e763c 2889 wait(0.5);// very aggressive hapic
nbaker 10:eaea844e763c 2890 haptic = 0;
nbaker 10:eaea844e763c 2891 wait(0.2);
nbaker 10:eaea844e763c 2892 haptic = 1;
nbaker 10:eaea844e763c 2893 wait(0.5);// very aggressive hapic
nbaker 10:eaea844e763c 2894 haptic = 0;
nbaker 10:eaea844e763c 2895 wait(0.2);
nbaker 10:eaea844e763c 2896 haptic = 1;
nbaker 10:eaea844e763c 2897 wait(0.5);// very aggressive hapic
nbaker 10:eaea844e763c 2898 haptic = 0;
nbaker 10:eaea844e763c 2899 } // endif
nbaker 10:eaea844e763c 2900
nbaker 10:eaea844e763c 2901 }//end of chkmotion ticker interupt routine
nbaker 10:eaea844e763c 2902
nbaker 10:eaea844e763c 2903
nbaker 10:eaea844e763c 2904 /*****************************************************************************
nbaker 10:eaea844e763c 2905 Name: Send_Alert()
nbaker 10:eaea844e763c 2906 Purpose: routine used to store and send alert
nbaker 10:eaea844e763c 2907 Inputs: int value from 0 to 256
nbaker 10:eaea844e763c 2908 0=Panic, 1=Fall+asked for help, 2=Fall+No responce, 3=?
nbaker 10:eaea844e763c 2909 Returns: None
nbaker 10:eaea844e763c 2910 ******************************************************************************/
nbaker 10:eaea844e763c 2911 void Send_Alert(uint8_t Num){
nbaker 10:eaea844e763c 2912
nbaker 10:eaea844e763c 2913 // store alert
nbaker 10:eaea844e763c 2914 // transmit alert
nbaker 10:eaea844e763c 2915
nbaker 10:eaea844e763c 2916 }//end Send_Alert routine
nbaker 10:eaea844e763c 2917
nbaker 9:d2e39ee9fedd 2918 /*****************************************************************************
nbaker 4:0803151bc5e4 2919 Name: fall_config()
nbaker 10:eaea844e763c 2920 Purpose: routine used to set accelerometer and gyro sensors' internal registers for chip
nbaker 10:eaea844e763c 2921 level interrupts
nbaker 10:eaea844e763c 2922 Inputs: int value from 0 to 256
nbaker 10:eaea844e763c 2923 Returns: None
nbaker 10:eaea844e763c 2924 ******************************************************************************/
nbaker 10:eaea844e763c 2925 void fall_config(uint8_t Num){ // this is more than just accel config
nbaker 10:eaea844e763c 2926 // use case switches here to configure for
nbaker 10:eaea844e763c 2927 switch(Num) {
nbaker 10:eaea844e763c 2928 case 0: {// put in standby
nbaker 10:eaea844e763c 2929 accel_sensor_config(0); // set accel sensor to standby
nbaker 10:eaea844e763c 2930 /*For lowest accel power ~2uA in standby mode */
nbaker 10:eaea844e763c 2931 gyro_sensor_config(0); // set gyro sensor to standby
nbaker 10:eaea844e763c 2932 /*For lowest gyro power ~2.8uA in standby mode */
nbaker 10:eaea844e763c 2933 Accel_INT1.fall(NULL); // Turn off Accel sensor's int#1
nbaker 10:eaea844e763c 2934 Accel_INT2.fall(NULL); // Turn off Accel sensor's int#2
nbaker 10:eaea844e763c 2935 Gyro_INT1.fall(NULL); // Turn off Gyro sensor's int#1
nbaker 10:eaea844e763c 2936 break;
nbaker 10:eaea844e763c 2937 }// end of case 0
nbaker 10:eaea844e763c 2938
nbaker 10:eaea844e763c 2939 case 1: {// configure for free-fall int only
nbaker 10:eaea844e763c 2940 accel_sensor_config(1); // set accel sensor for free-fall
nbaker 10:eaea844e763c 2941 gyro_sensor_config(0); // set gyro sensor to standby
nbaker 10:eaea844e763c 2942 Accel_INT1.fall(NULL); // Turn off Accel sensor's int#1
nbaker 10:eaea844e763c 2943 Accel_INT2.fall(NULL); // Turn off Accel sensor's int#2
nbaker 10:eaea844e763c 2944 Gyro_INT1.fall(NULL); // Turn off Gyro sensor's int#1
nbaker 10:eaea844e763c 2945
nbaker 10:eaea844e763c 2946 Accel_INT1.fall(&fall_detect_debug); // Accel sensor's int#1 calls interupt routine
nbaker 10:eaea844e763c 2947 break;
nbaker 10:eaea844e763c 2948 }// end of case 1
nbaker 10:eaea844e763c 2949
nbaker 10:eaea844e763c 2950 case 2: {// configure for vector impact only
nbaker 10:eaea844e763c 2951 accel_sensor_config(2); // set accel sensor vector impact only
nbaker 10:eaea844e763c 2952 gyro_sensor_config(0); // set gyro sensor to standby
nbaker 10:eaea844e763c 2953 Accel_INT1.fall(NULL); // Turn off Accel sensor's int#1
nbaker 10:eaea844e763c 2954 // Accel_INT2.fall(NULL); // Turn off Accel sensor's int#2
nbaker 10:eaea844e763c 2955 Gyro_INT1.fall(NULL); // Turn off Gyro sensor's int#1
nbaker 10:eaea844e763c 2956 Accel_INT2.fall(&impact_detect_debug); //Accel sensor's int#2 calls interupt routine
nbaker 10:eaea844e763c 2957
nbaker 10:eaea844e763c 2958 break;
nbaker 10:eaea844e763c 2959 }// end of case 2
nbaker 10:eaea844e763c 2960
nbaker 10:eaea844e763c 2961 case 3: {// configure for motion int only
nbaker 10:eaea844e763c 2962 accel_sensor_config(0); // set accel sensor vector impact only
nbaker 10:eaea844e763c 2963 gyro_sensor_config(3); // set gyro sensor to standby
nbaker 10:eaea844e763c 2964 Accel_INT1.fall(NULL); // Turn off Accel sensor's int#1
nbaker 10:eaea844e763c 2965 Accel_INT2.fall(NULL); // Turn off Accel sensor's int#2
nbaker 10:eaea844e763c 2966 Gyro_INT1.fall(&motion_detect_debug); // Gyro sensor's int#1 (PTD1) calls interupt routine
nbaker 10:eaea844e763c 2967 break;
nbaker 10:eaea844e763c 2968 }// end of case 3
nbaker 10:eaea844e763c 2969
nbaker 10:eaea844e763c 2970 case 4: {// configure FFMT for free-fall event AND config for vector impact
nbaker 10:eaea844e763c 2971 accel_sensor_config(4); // set accel sensor Free-fall and vector impact
nbaker 10:eaea844e763c 2972 gyro_sensor_config(3); // set gyro sensor motion
nbaker 10:eaea844e763c 2973 Accel_INT1.fall(&fall_detect_debug); // Accel sensor's int#1 calls interupt routine
nbaker 10:eaea844e763c 2974 Accel_INT2.fall(&impact_detect_debug); //Accel sensor's int#2 calls interupt routine
nbaker 10:eaea844e763c 2975 Gyro_INT1.fall(&motion_detect_debug); // Gyro sensor's int#1 (PTD1) calls interupt routine
nbaker 10:eaea844e763c 2976 break;
nbaker 10:eaea844e763c 2977 }// end of case 4
nbaker 10:eaea844e763c 2978
nbaker 10:eaea844e763c 2979 case 5: {// configure for sequential free-fall, vector impact then motion
nbaker 10:eaea844e763c 2980 accel_sensor_config(4); // set accel sensor Free-fall and vector impact
nbaker 10:eaea844e763c 2981 gyro_sensor_config(3); // set gyro sensor motion
nbaker 10:eaea844e763c 2982 Accel_INT1.fall(&fall_detect); // Accel sensor's int#1 calls interupt routine
nbaker 10:eaea844e763c 2983 Accel_INT2.fall(NULL); //Accel sensor's int#2 calls interupt routine
nbaker 10:eaea844e763c 2984 Gyro_INT1.fall(NULL); // Gyro sensor's int#1 (PTD1) calls interupt routine
nbaker 10:eaea844e763c 2985 break;
nbaker 10:eaea844e763c 2986 }// end of case 4
nbaker 10:eaea844e763c 2987
nbaker 10:eaea844e763c 2988 case 10: {// reset IC
nbaker 10:eaea844e763c 2989 accel_sensor_config(10); // reset accel sensor
nbaker 10:eaea844e763c 2990 gyro_sensor_config(10); // reset gyro sensor
nbaker 10:eaea844e763c 2991 break;
nbaker 10:eaea844e763c 2992 }// end case 10
nbaker 10:eaea844e763c 2993
nbaker 10:eaea844e763c 2994 case 11: {// wake both sensors for simple data read, they were in stanby
nbaker 10:eaea844e763c 2995 accel_sensor_config(11); // set accel sensor active for read
nbaker 10:eaea844e763c 2996 gyro_sensor_config(11); // set accel sensor active for read
nbaker 10:eaea844e763c 2997 break;
nbaker 10:eaea844e763c 2998 }// end of case 11
nbaker 10:eaea844e763c 2999
nbaker 10:eaea844e763c 3000 case 12: {// put into standby for low power
nbaker 10:eaea844e763c 3001 accel_sensor_config(12); // set accel sensor to standby
nbaker 10:eaea844e763c 3002 gyro_sensor_config(12); // set gyro sensor to standby
nbaker 10:eaea844e763c 3003 break;
nbaker 10:eaea844e763c 3004 }// end of case 112
nbaker 10:eaea844e763c 3005
nbaker 10:eaea844e763c 3006 case 20: {// read INT_Source to clear VECM int, shouldn't have to do this
nbaker 10:eaea844e763c 3007 // This was not working for me but it was due to me using the wrong FXOS8700_I2C_ADDRESS_
nbaker 10:eaea844e763c 3008 char d[2];//, data_byte_[1];
nbaker 10:eaea844e763c 3009 d[0] = 0x0c; // 0x0c is INT_Source Reg
nbaker 10:eaea844e763c 3010 i2c_bus1.write(FXOS8700_I2C_ADDRESS_,d,1,true); // "true" is needed to prevent stop
nbaker 10:eaea844e763c 3011 wait(0.01);
nbaker 10:eaea844e763c 3012 if(i2c_bus1.read(FXOS8700_I2C_ADDRESS_,d,1) == 1){ // read Who am I Reg for debug
nbaker 10:eaea844e763c 3013 sprintf(text_1," INT_Read_Err ");
nbaker 10:eaea844e763c 3014 oled.Label((uint8_t *)text_1,5,50); // Display error at x,y
nbaker 10:eaea844e763c 3015 wait(1); // wait 1 seconds
nbaker 10:eaea844e763c 3016 }//endif
nbaker 10:eaea844e763c 3017 break;
nbaker 10:eaea844e763c 3018 }// end of case 20
nbaker 10:eaea844e763c 3019
nbaker 10:eaea844e763c 3020 case 21: {// read A_FFMT_SRC reg to clear FFMT int, shouldn't have to do this
nbaker 10:eaea844e763c 3021 // This was not working for me but it was due to me using the wrong FXOS8700_I2C_ADDRESS_
nbaker 10:eaea844e763c 3022 char d[2];//, data_byte_[1];
nbaker 10:eaea844e763c 3023 d[0] = 0x16; // 0x16 is A_FFMT_SRC Reg
nbaker 10:eaea844e763c 3024 i2c_bus1.write(FXOS8700_I2C_ADDRESS_,d,1,true); // "true" is needed to prevent stop
nbaker 10:eaea844e763c 3025 wait(0.01);
nbaker 10:eaea844e763c 3026 if(i2c_bus1.read(FXOS8700_I2C_ADDRESS_,d,1) == 1){ // read Who am I Reg for debug
nbaker 10:eaea844e763c 3027 sprintf(text_1," INT_Read_Err ");
nbaker 10:eaea844e763c 3028 oled.Label((uint8_t *)text_1,5,50); // Display error at x,y
nbaker 10:eaea844e763c 3029 wait(1); // wait 1 seconds
nbaker 10:eaea844e763c 3030 }//endif
nbaker 10:eaea844e763c 3031 break;
nbaker 10:eaea844e763c 3032 }// end of case 21
nbaker 10:eaea844e763c 3033
nbaker 10:eaea844e763c 3034 default: {
nbaker 10:eaea844e763c 3035 oled.Label((uint8_t *)" Mode? ",30,60); // Display "mode" at x,y
nbaker 10:eaea844e763c 3036 // unknown config
nbaker 10:eaea844e763c 3037 break;
nbaker 10:eaea844e763c 3038 }
nbaker 10:eaea844e763c 3039 }// end switch
nbaker 10:eaea844e763c 3040
nbaker 10:eaea844e763c 3041 }// end Fall_config
nbaker 10:eaea844e763c 3042
nbaker 10:eaea844e763c 3043
nbaker 10:eaea844e763c 3044 /*****************************************************************************
nbaker 10:eaea844e763c 3045 Name: accel_sensor_config()
nbaker 4:0803151bc5e4 3046 Purpose: Used to set accelerometer IC's internal registers to set up chip level
nbaker 4:0803151bc5e4 3047 interrupts
nbaker 4:0803151bc5e4 3048 Inputs: int value from 0 to 256
nbaker 4:0803151bc5e4 3049 Returns: None
nbaker 4:0803151bc5e4 3050 ******************************************************************************/
nbaker 4:0803151bc5e4 3051
nbaker 10:eaea844e763c 3052 void accel_sensor_config(uint8_t Num){
nbaker 4:0803151bc5e4 3053 // use case switches here to configure for
nbaker 8:a5c77b45008d 3054 switch(Num) {
nbaker 8:a5c77b45008d 3055 case 0: {// put in standby
nbaker 4:0803151bc5e4 3056 char d[2];
nbaker 4:0803151bc5e4 3057 d[0] = FXOS8700_CTRL_REG1; //Puts device in Standby mode
nbaker 4:0803151bc5e4 3058 d[1] = 0x00;
nbaker 9:d2e39ee9fedd 3059 i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2);
nbaker 8:a5c77b45008d 3060 /*For lowest power ~8uA, set ODR-12.5Hz,(low-pwr accel mode) or 2uA in standby mode */
nbaker 8:a5c77b45008d 3061 break;
nbaker 8:a5c77b45008d 3062 }// end of case 0
nbaker 8:a5c77b45008d 3063
nbaker 8:a5c77b45008d 3064 case 1: {// configure for free-fall int only
nbaker 4:0803151bc5e4 3065 char d[2];
nbaker 8:a5c77b45008d 3066 d[0] = 0x2a; //0x2a Config reg1
nbaker 4:0803151bc5e4 3067 d[1] = 0x00; //Put device in Standby mode
nbaker 4:0803151bc5e4 3068 if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
nbaker 9:d2e39ee9fedd 3069 oled.Label((uint8_t *)"Acc1a err",30,05); // Display "error" at x,y
nbaker 4:0803151bc5e4 3070 wait(3.0); // display for 3 seconds
nbaker 4:0803151bc5e4 3071 }//end if
nbaker 4:0803151bc5e4 3072
nbaker 4:0803151bc5e4 3073 d[0] = 0x0e; //XYZ_DATA_CFG (set full-scall range)
nbaker 8:a5c77b45008d 3074 d[1] = 0b00000001; //Set data to default range of +/-2g for full range (2x0.488mg/LSB), High-pass filter off
nbaker 4:0803151bc5e4 3075 if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
nbaker 9:d2e39ee9fedd 3076 oled.Label((uint8_t *)"Acc1b err",30,05); // Display "error" at x,y
nbaker 4:0803151bc5e4 3077 wait(3.0); // display for 3 seconds
nbaker 4:0803151bc5e4 3078 }//end if
nbaker 8:a5c77b45008d 3079 /*
nbaker 8:a5c77b45008d 3080 d[0] = 0x0a; //TRIG_CFG (address of FIFO trigger config reg)
nbaker 4:0803151bc5e4 3081 d[1] = 0b00000100; //Trigger on freefall
nbaker 4:0803151bc5e4 3082 if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
nbaker 4:0803151bc5e4 3083 oled.Label((uint8_t *)" Step2 error ",30,05); // Display "error" at x,y
nbaker 4:0803151bc5e4 3084 wait(3.0); // display for 3 seconds
nbaker 4:0803151bc5e4 3085 }//end if
nbaker 8:a5c77b45008d 3086 */
nbaker 4:0803151bc5e4 3087 d[0] = 0x15; //A_FFMT_CFG (address of Free fall trigger config reg), write in Standby only
nbaker 4:0803151bc5e4 3088 d[1] = 0b00111000; //set to freefall, and look at all axis.
nbaker 4:0803151bc5e4 3089 if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
nbaker 9:d2e39ee9fedd 3090 oled.Label((uint8_t *)"Acc1c err",30,05); // Display "error" at x,y
nbaker 4:0803151bc5e4 3091 wait(3.0); // display for 3 seconds
nbaker 4:0803151bc5e4 3092 }//end if
nbaker 4:0803151bc5e4 3093
nbaker 4:0803151bc5e4 3094 d[0] = 0x17; //A_FFMT_THS (address of Free fall threshold reg), write in Active or Standby
nbaker 9:d2e39ee9fedd 3095 // d[1] = 0b00001000; //set freefall threshold to about 756mg for now
nbaker 9:d2e39ee9fedd 3096 d[1] = (uint8_t)(1000*Fall_Thresh/63); //set freefall threshold - Resolution is 63mg/LSB, 0b111_1111 is maximum value
nbaker 4:0803151bc5e4 3097 if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
nbaker 9:d2e39ee9fedd 3098 oled.Label((uint8_t *)"Acc1d err",30,05); // Display "error" at x,y
nbaker 4:0803151bc5e4 3099 wait(3.0); // display for 3 seconds
nbaker 4:0803151bc5e4 3100 }//end if
nbaker 4:0803151bc5e4 3101
nbaker 4:0803151bc5e4 3102 d[0] = 0x18; //A_FFMT_COUNT (address of Free fall debounce counter), write in Active or Standby
nbaker 4:0803151bc5e4 3103 d[1] = 0b00000110; //with ODR at 100Hz, should equal 60mS debounce time or 120mS in Sleep
nbaker 4:0803151bc5e4 3104 if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
nbaker 9:d2e39ee9fedd 3105 oled.Label((uint8_t *)"Acc1e err",30,05); // Display "error" at x,y
nbaker 4:0803151bc5e4 3106 wait(3.0); // display for 3 seconds
nbaker 4:0803151bc5e4 3107 }//end if
nbaker 4:0803151bc5e4 3108
nbaker 4:0803151bc5e4 3109 d[0] = 0x2b; //CTRL_REG2 (address of control reg), write in Standby only
nbaker 9:d2e39ee9fedd 3110 // d[1] = 0b00001101; //Turns Auto-Sleep mode on and low-noise, low power
nbaker 9:d2e39ee9fedd 3111 d[1] = 0b00001001; //Turns Auto-Sleep mode off (b/c it wasn't waking on int) and low-noise, low power
nbaker 4:0803151bc5e4 3112 if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
nbaker 9:d2e39ee9fedd 3113 oled.Label((uint8_t *)"Acc1f err",30,05); // Display "error" at x,y
nbaker 4:0803151bc5e4 3114 wait(3.0); // display for 3 seconds
nbaker 4:0803151bc5e4 3115 }//end if
nbaker 4:0803151bc5e4 3116
nbaker 4:0803151bc5e4 3117 d[0] = 0x2c; //CTRL_REG3 (address of Int control reg), write in Standby only
nbaker 4:0803151bc5e4 3118 d[1] = 0b00001000; //FFMT will wake chip from sleep, int are active high
nbaker 4:0803151bc5e4 3119 if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
nbaker 9:d2e39ee9fedd 3120 oled.Label((uint8_t *)"Acc1g err",30,05); // Display "error" at x,y
nbaker 4:0803151bc5e4 3121 wait(3.0); // display for 3 seconds
nbaker 4:0803151bc5e4 3122 }//end if
nbaker 4:0803151bc5e4 3123
nbaker 4:0803151bc5e4 3124 d[0] = 0x2d; //CTRL_REG4 (address of Int enable reg), write in Standby only
nbaker 9:d2e39ee9fedd 3125 d[1] = 0b10000100; // FFMT int enabled and for debug I'm using a sleep int
nbaker 4:0803151bc5e4 3126 if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
nbaker 9:d2e39ee9fedd 3127 oled.Label((uint8_t *)"Acc1h err",30,05); // Display "error" at x,y
nbaker 4:0803151bc5e4 3128 wait(3.0); // display for 3 seconds
nbaker 4:0803151bc5e4 3129 }//end if
nbaker 8:a5c77b45008d 3130
nbaker 4:0803151bc5e4 3131 d[0] = 0x2e; //CTRL_REG5 (Int routing reg), write in Standby only
nbaker 4:0803151bc5e4 3132 d[1] = 0b00000100; // Make FFMT int output on pin INT1(PTC1)
nbaker 4:0803151bc5e4 3133 if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
nbaker 9:d2e39ee9fedd 3134 oled.Label((uint8_t *)"Acc1i err",30,05); // Display "error" at x,y
nbaker 4:0803151bc5e4 3135 wait(3.0); // display for 3 seconds
nbaker 4:0803151bc5e4 3136 }//end if
nbaker 4:0803151bc5e4 3137
nbaker 9:d2e39ee9fedd 3138 d[0] = 0x29; //ASLP_Count (counter used to go to sleep reg), write in Standby only
nbaker 9:d2e39ee9fedd 3139 d[1] = 0b00001010; // 10*320mS=3.2S of no inturrupts to go to sleep
nbaker 9:d2e39ee9fedd 3140 if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
nbaker 9:d2e39ee9fedd 3141 oled.Label((uint8_t *)"Acc1j err",30,05); // Display "error" at x,y
nbaker 9:d2e39ee9fedd 3142 wait(3.0); // display for 3 seconds
nbaker 9:d2e39ee9fedd 3143 }//end if
nbaker 9:d2e39ee9fedd 3144
nbaker 8:a5c77b45008d 3145 d[0] = 0x2a; //0x2a Config reg1, write in Standby only except for bit[0]
nbaker 4:0803151bc5e4 3146 d[1] = 0b00011001; //Auto-Sleep mode on set to 50Hz, ODR set to 100Hz Puts device back into Active mode
nbaker 4:0803151bc5e4 3147 if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
nbaker 9:d2e39ee9fedd 3148 oled.Label((uint8_t *)"Acc1k err",30,05); // Display "error" at x,y
nbaker 4:0803151bc5e4 3149 wait(3.0); // display for 3 seconds
nbaker 4:0803151bc5e4 3150 }//end if
nbaker 9:d2e39ee9fedd 3151
nbaker 4:0803151bc5e4 3152 break;
nbaker 7:3d5a8aea0b63 3153 }// end of case 1
nbaker 7:3d5a8aea0b63 3154
nbaker 8:a5c77b45008d 3155 case 2: {// configure for vector impact only
nbaker 7:3d5a8aea0b63 3156 char d[2];
nbaker 7:3d5a8aea0b63 3157
nbaker 7:3d5a8aea0b63 3158 d[0] = FXOS8700_CTRL_REG1; //Config reg1 0x2a
nbaker 7:3d5a8aea0b63 3159 d[1] = 0x00; //Put device in Standby mode
nbaker 7:3d5a8aea0b63 3160 if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
nbaker 9:d2e39ee9fedd 3161 oled.Label((uint8_t *)"Acc2a err",30,05); // Display "error" at x,y
nbaker 7:3d5a8aea0b63 3162 wait(3.0); // display for 3 seconds
nbaker 7:3d5a8aea0b63 3163 }//end if
nbaker 7:3d5a8aea0b63 3164
nbaker 7:3d5a8aea0b63 3165 d[0] = 0x0e; //XYZ_DATA_CFG (set full-scall range)
nbaker 7:3d5a8aea0b63 3166 d[1] = 0b00000001; //Set data to +/-4g for full range (0.488mg/LSB), High-pass filter off
nbaker 7:3d5a8aea0b63 3167 if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
nbaker 9:d2e39ee9fedd 3168 oled.Label((uint8_t *)"Acc2b err",30,05); // Display "error" at x,y
nbaker 7:3d5a8aea0b63 3169 wait(3.0); // display for 3 seconds
nbaker 7:3d5a8aea0b63 3170 }//end if
nbaker 8:a5c77b45008d 3171 /*
nbaker 8:a5c77b45008d 3172 d[0] = 0x0a; //TRIG_CFG (address of FIFO trigger config reg)
nbaker 7:3d5a8aea0b63 3173 d[1] = 0b00000110; //Trigger on freefall and on Vector
nbaker 7:3d5a8aea0b63 3174 if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
nbaker 7:3d5a8aea0b63 3175 oled.Label((uint8_t *)" Step2 error ",30,05); // Display "error" at x,y
nbaker 7:3d5a8aea0b63 3176 wait(3.0); // display for 3 seconds
nbaker 7:3d5a8aea0b63 3177 }//end if
nbaker 8:a5c77b45008d 3178 */
nbaker 8:a5c77b45008d 3179 d[0] = 0x5f; //A_VECM_CFG (address of Vector config reg), write in Standby only
nbaker 8:a5c77b45008d 3180 d[1] = 0b00111000; //Use reference values, don't update ref, enable.
nbaker 8:a5c77b45008d 3181 if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
nbaker 9:d2e39ee9fedd 3182 oled.Label((uint8_t *)"Acc2c err",30,05); // Display "error" at x,y
nbaker 8:a5c77b45008d 3183 wait(3.0); // display for 3 seconds
nbaker 8:a5c77b45008d 3184 }//end if
nbaker 8:a5c77b45008d 3185
nbaker 8:a5c77b45008d 3186 d[0] = 0x60; //A_VECM_MSB (address of Vector threshold reg), write in Active or Standby
nbaker 9:d2e39ee9fedd 3187 // d[1] = 0b00000111; //set impact threshold to less than 1g for now
nbaker 9:d2e39ee9fedd 3188 d[1] = (uint8_t)((1000*Impact_Thresh/0.488f)/256); //set MSB Impact threshold - Resolution is 0.488mg/LSB so 0.5g=1024.6 => MSB=0b00000100 LSB=0b00000000
nbaker 8:a5c77b45008d 3189 if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
nbaker 9:d2e39ee9fedd 3190 oled.Label((uint8_t *)"Acc2d err",30,05); // Display "error" at x,y
nbaker 8:a5c77b45008d 3191 wait(3.0); // display for 3 seconds
nbaker 8:a5c77b45008d 3192 }//end if
nbaker 8:a5c77b45008d 3193
nbaker 8:a5c77b45008d 3194 d[0] = 0x61; //A_VECM_LSB (address of Vector threshold reg), write in Active or Standby
nbaker 9:d2e39ee9fedd 3195 // d[1] = 0b00000011; //set impact threshold to less than 1g for now
nbaker 9:d2e39ee9fedd 3196 d[1] = (uint8_t)(1000*Impact_Thresh/0.488f);
nbaker 9:d2e39ee9fedd 3197 d[1] = (uint8_t)(d[1]%256); //set MSB Impact threshold - Resolution 0.488mg/LSB so 0.5g=1024.6 => MSB=0b00000100 LSB=0b00000000
nbaker 8:a5c77b45008d 3198 if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
nbaker 9:d2e39ee9fedd 3199 oled.Label((uint8_t *)"Acc2e err",30,05); // Display "error" at x,y
nbaker 8:a5c77b45008d 3200 wait(3.0); // display for 3 seconds
nbaker 9:d2e39ee9fedd 3201 }//end if
nbaker 8:a5c77b45008d 3202
nbaker 8:a5c77b45008d 3203 d[0] = 0x62; //A_VECM_COUNT (address of Vector debounce counter), write in Active or Standby
nbaker 8:a5c77b45008d 3204 d[1] = 0b00000110; //with ODR at 100Hz, should equal ??mS debounce time or ??mS in Sleep
nbaker 8:a5c77b45008d 3205 if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
nbaker 9:d2e39ee9fedd 3206 oled.Label((uint8_t *)"Acc2f err",30,05); // Display "error" at x,y
nbaker 8:a5c77b45008d 3207 wait(3.0); // display for 3 seconds
nbaker 8:a5c77b45008d 3208 }//end if
nbaker 8:a5c77b45008d 3209
nbaker 8:a5c77b45008d 3210 // Registers 0x63 - 0x68 are vector reference values which I'm leaving set to 0 because we want absolute measurements
nbaker 8:a5c77b45008d 3211
nbaker 8:a5c77b45008d 3212 d[0] = 0x2b; //CTRL_REG2 (address of control reg), write in Standby only
nbaker 9:d2e39ee9fedd 3213 // d[1] = 0b00001101; //Turns Auto-Sleep mode on and low-noise, low power
nbaker 9:d2e39ee9fedd 3214 d[1] = 0b00001001; //Turns Auto-Sleep mode off (b/c it wasn't waking on int) and low-noise, low power
nbaker 8:a5c77b45008d 3215 if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
nbaker 9:d2e39ee9fedd 3216 oled.Label((uint8_t *)"Acc2g err",30,05); // Display "error" at x,y
nbaker 8:a5c77b45008d 3217 wait(3.0); // display for 3 seconds
nbaker 8:a5c77b45008d 3218 }//end if
nbaker 7:3d5a8aea0b63 3219
nbaker 8:a5c77b45008d 3220 d[0] = 0x2c; //CTRL_REG3 (address of Int control reg), write in Standby only
nbaker 8:a5c77b45008d 3221 d[1] = 0b00000100; //Vector will wake chip from sleep, int are active high
nbaker 8:a5c77b45008d 3222 // d[1] = 0b00001000; //FFMT will wake chip from sleep, int are active high
nbaker 8:a5c77b45008d 3223 if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
nbaker 9:d2e39ee9fedd 3224 oled.Label((uint8_t *)"Acc2h err",30,05); // Display "error" at x,y
nbaker 8:a5c77b45008d 3225 wait(3.0); // display for 3 seconds
nbaker 8:a5c77b45008d 3226 }//end if
nbaker 8:a5c77b45008d 3227
nbaker 8:a5c77b45008d 3228 d[0] = 0x2d; //CTRL_REG4 (address of Int enable reg), write in Standby only
nbaker 9:d2e39ee9fedd 3229 d[1] = 0b10000010; // Vector int enabled
nbaker 8:a5c77b45008d 3230 // d[1] = 0b00000100; // FFMT int enabled
nbaker 8:a5c77b45008d 3231 if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
nbaker 9:d2e39ee9fedd 3232 oled.Label((uint8_t *)"Acc2i err",30,05); // Display "error" at x,y
nbaker 8:a5c77b45008d 3233 wait(3.0); // display for 3 seconds
nbaker 8:a5c77b45008d 3234 }//end if
nbaker 9:d2e39ee9fedd 3235 //wait(0.2); // people have had a problem here and needed a delay
nbaker 9:d2e39ee9fedd 3236
nbaker 8:a5c77b45008d 3237 d[0] = 0x2e; //CTRL_REG5 (Int routing reg), write in Standby only
nbaker 8:a5c77b45008d 3238 d[1] = 0b00000100; // Make FFMT int output on pin INT1(PTC1) and Vector on INT2(PTD13)
nbaker 8:a5c77b45008d 3239 if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
nbaker 9:d2e39ee9fedd 3240 oled.Label((uint8_t *)"Acc2j err",30,05); // Display "error" at x,y
nbaker 8:a5c77b45008d 3241 wait(3.0); // display for 3 seconds
nbaker 8:a5c77b45008d 3242 }//end if
nbaker 8:a5c77b45008d 3243
nbaker 9:d2e39ee9fedd 3244 d[0] = 0x29; //ASLP_Count (counter used to go to sleep reg), write in Standby only
nbaker 9:d2e39ee9fedd 3245 d[1] = 0b00001010; // 10*320mS=3.2S of no inturrupts to go to sleep
nbaker 9:d2e39ee9fedd 3246 if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
nbaker 9:d2e39ee9fedd 3247 oled.Label((uint8_t *)"Acc2k err",30,05); // Display "error" at x,y
nbaker 9:d2e39ee9fedd 3248 wait(3.0); // display for 3 seconds
nbaker 9:d2e39ee9fedd 3249 }//end if
nbaker 9:d2e39ee9fedd 3250
nbaker 8:a5c77b45008d 3251 d[0] = FXOS8700_CTRL_REG1; //CTRL_REG1, write in Standby only except for bit[0]
nbaker 8:a5c77b45008d 3252 d[1] = 0b00011001; //Auto-Sleep mode on set to 50Hz, ODR set to 100Hz Puts device back into Active mode
nbaker 8:a5c77b45008d 3253 if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
nbaker 9:d2e39ee9fedd 3254 oled.Label((uint8_t *)"Acc2L err",30,05); // Display "error" at x,y
nbaker 8:a5c77b45008d 3255 wait(3.0); // display for 3 seconds
nbaker 8:a5c77b45008d 3256 }//end if
nbaker 8:a5c77b45008d 3257 break;
nbaker 8:a5c77b45008d 3258 }// end of case 2
nbaker 9:d2e39ee9fedd 3259
nbaker 9:d2e39ee9fedd 3260 case 3: {// configure for motion int only
nbaker 8:a5c77b45008d 3261 char d[2];
nbaker 9:d2e39ee9fedd 3262 d[0] = 0x2a; //0x2a Config reg1
nbaker 9:d2e39ee9fedd 3263 d[1] = 0x00; //Put device in Standby mode
nbaker 9:d2e39ee9fedd 3264 if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
nbaker 9:d2e39ee9fedd 3265 oled.Label((uint8_t *)"Acc3a err",30,05); // Display "error" at x,y
nbaker 9:d2e39ee9fedd 3266 wait(3.0); // display for 3 seconds
nbaker 9:d2e39ee9fedd 3267 }//end if
nbaker 8:a5c77b45008d 3268
nbaker 9:d2e39ee9fedd 3269 d[0] = 0x0e; //XYZ_DATA_CFG (set full-scall range)
nbaker 9:d2e39ee9fedd 3270 d[1] = 0b00000001; //Set data to default range of +/-2g for full range (2x0.488mg/LSB), High-pass filter off
nbaker 9:d2e39ee9fedd 3271 if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
nbaker 9:d2e39ee9fedd 3272 oled.Label((uint8_t *)"Acc3b err",30,05); // Display "error" at x,y
nbaker 9:d2e39ee9fedd 3273 wait(3.0); // display for 3 seconds
nbaker 9:d2e39ee9fedd 3274 }//end if
nbaker 9:d2e39ee9fedd 3275
nbaker 9:d2e39ee9fedd 3276 d[0] = 0x2a; //0x2a Config reg1, write in Standby only except for bit[0]
nbaker 9:d2e39ee9fedd 3277 d[1] = 0b00011001; //Auto-Sleep mode on set to 50Hz, ODR set to 100Hz Puts device back into Active mode
nbaker 9:d2e39ee9fedd 3278 if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
nbaker 9:d2e39ee9fedd 3279 oled.Label((uint8_t *)"Acc3c err",30,05); // Display "error" at x,y
nbaker 9:d2e39ee9fedd 3280 wait(3.0); // display for 3 seconds
nbaker 9:d2e39ee9fedd 3281 }//end if
nbaker 9:d2e39ee9fedd 3282 break;
nbaker 9:d2e39ee9fedd 3283 }// end of case 3
nbaker 9:d2e39ee9fedd 3284
nbaker 9:d2e39ee9fedd 3285 case 4: {// configure FFMT for free-fall event AND config for vector impact
nbaker 9:d2e39ee9fedd 3286 char d[2];
nbaker 8:a5c77b45008d 3287 d[0] = 0x2a; //0x2a Config reg1,
nbaker 8:a5c77b45008d 3288 d[1] = 0x00; //Put device in Standby mode
nbaker 8:a5c77b45008d 3289 if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
nbaker 9:d2e39ee9fedd 3290 oled.Label((uint8_t *)"Acc4a err",30,05); // Display "error" at x,y
nbaker 8:a5c77b45008d 3291 wait(3.0); // display for 3 seconds
nbaker 8:a5c77b45008d 3292 }//end if
nbaker 8:a5c77b45008d 3293
nbaker 8:a5c77b45008d 3294 d[0] = 0x0e; //XYZ_DATA_CFG (set full-scall range)
nbaker 8:a5c77b45008d 3295 d[1] = 0b00000001; //Set data to +/-4g for full range (0.488mg/LSB), High-pass filter off
nbaker 8:a5c77b45008d 3296 if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
nbaker 9:d2e39ee9fedd 3297 oled.Label((uint8_t *)"Acc4b err",30,05); // Display "error" at x,y
nbaker 8:a5c77b45008d 3298 wait(3.0); // display for 3 seconds
nbaker 8:a5c77b45008d 3299 }//end if
nbaker 8:a5c77b45008d 3300 /*
nbaker 8:a5c77b45008d 3301 d[0] = 0x0a; //TRIG_CFG (address of FIFO trigger config reg)
nbaker 8:a5c77b45008d 3302 d[1] = 0b00000110; //Trigger on freefall and on Vector
nbaker 8:a5c77b45008d 3303 if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
nbaker 8:a5c77b45008d 3304 oled.Label((uint8_t *)" Step2 error ",30,05); // Display "error" at x,y
nbaker 8:a5c77b45008d 3305 wait(3.0); // display for 3 seconds
nbaker 8:a5c77b45008d 3306 }//end if
nbaker 8:a5c77b45008d 3307 */
nbaker 7:3d5a8aea0b63 3308 d[0] = 0x15; //A_FFMT_CFG (address of Free fall trigger config reg), write in Standby only
nbaker 7:3d5a8aea0b63 3309 d[1] = 0b00111000; //set to freefall, and look at all axis.
nbaker 7:3d5a8aea0b63 3310 if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
nbaker 9:d2e39ee9fedd 3311 oled.Label((uint8_t *)"Acc4c err",30,05); // Display "error" at x,y
nbaker 7:3d5a8aea0b63 3312 wait(3.0); // display for 3 seconds
nbaker 7:3d5a8aea0b63 3313 }//end if
nbaker 7:3d5a8aea0b63 3314
nbaker 7:3d5a8aea0b63 3315 d[0] = 0x17; //A_FFMT_THS (address of Free fall threshold reg), write in Active or Standby
nbaker 9:d2e39ee9fedd 3316 // d[1] = 0b00001000; //set freefall threshold to about 756mg for now
nbaker 9:d2e39ee9fedd 3317 d[1] = (uint8_t)(1000*Fall_Thresh/63); //set freefall threshold - Resolution is 63mg/LSB, 0b111_1111 is maximum value
nbaker 7:3d5a8aea0b63 3318 if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
nbaker 9:d2e39ee9fedd 3319 oled.Label((uint8_t *)"Acc4d err",30,05); // Display "error" at x,y
nbaker 7:3d5a8aea0b63 3320 wait(3.0); // display for 3 seconds
nbaker 7:3d5a8aea0b63 3321 }//end if
nbaker 7:3d5a8aea0b63 3322
nbaker 7:3d5a8aea0b63 3323 d[0] = 0x18; //A_FFMT_COUNT (address of Free fall debounce counter), write in Active or Standby
nbaker 7:3d5a8aea0b63 3324 d[1] = 0b00000110; //with ODR at 100Hz, should equal 60mS debounce time or 120mS in Sleep
nbaker 7:3d5a8aea0b63 3325 if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
nbaker 9:d2e39ee9fedd 3326 oled.Label((uint8_t *)"Acc4e err",30,05); // Display "error" at x,y
nbaker 7:3d5a8aea0b63 3327 wait(3.0); // display for 3 seconds
nbaker 7:3d5a8aea0b63 3328 }//end if
nbaker 7:3d5a8aea0b63 3329
nbaker 7:3d5a8aea0b63 3330 d[0] = 0x5f; //A_VECM_CFG (address of Vector config reg), write in Standby only
nbaker 7:3d5a8aea0b63 3331 d[1] = 0b00111000; //Use reference values, don't update ref, enable.
nbaker 7:3d5a8aea0b63 3332 if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
nbaker 9:d2e39ee9fedd 3333 oled.Label((uint8_t *)"Acc4f err",30,05); // Display "error" at x,y
nbaker 7:3d5a8aea0b63 3334 wait(3.0); // display for 3 seconds
nbaker 7:3d5a8aea0b63 3335 }//end if
nbaker 7:3d5a8aea0b63 3336
nbaker 7:3d5a8aea0b63 3337 d[0] = 0x60; //A_VECM_MSB (address of Vector threshold reg), write in Active or Standby
nbaker 9:d2e39ee9fedd 3338 // d[1] = 0b00000111; //set impact threshold to less than 1g for now
nbaker 9:d2e39ee9fedd 3339 d[1] = (uint8_t)((1000*Impact_Thresh/0.488f)/256); //set MSB Impact threshold - Resolution is 0.488mg/LSB so 0.5g=1024.6 => MSB=0b00000100 LSB=0b00000000
nbaker 7:3d5a8aea0b63 3340 if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
nbaker 9:d2e39ee9fedd 3341 oled.Label((uint8_t *)"Acc4g err",30,05); // Display "error" at x,y
nbaker 7:3d5a8aea0b63 3342 wait(3.0); // display for 3 seconds
nbaker 7:3d5a8aea0b63 3343 }//end if
nbaker 7:3d5a8aea0b63 3344
nbaker 7:3d5a8aea0b63 3345 d[0] = 0x61; //A_VECM_LSB (address of Vector threshold reg), write in Active or Standby
nbaker 9:d2e39ee9fedd 3346 // d[1] = 0b00000011; //set impact threshold to less than 1g for now
nbaker 9:d2e39ee9fedd 3347 d[1] = (uint8_t)(1000*Impact_Thresh/0.488f);
nbaker 9:d2e39ee9fedd 3348 d[1] = (uint8_t)(d[1]%256); //set MSB Impact threshold - Resolution 0.488mg/LSB so 0.5g=1024.6 => MSB=0b00000100 LSB=0b00000000
nbaker 7:3d5a8aea0b63 3349 if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
nbaker 9:d2e39ee9fedd 3350 oled.Label((uint8_t *)"Acc4h err",30,05); // Display "error" at x,y
nbaker 7:3d5a8aea0b63 3351 wait(3.0); // display for 3 seconds
nbaker 7:3d5a8aea0b63 3352 }//end if
nbaker 7:3d5a8aea0b63 3353
nbaker 7:3d5a8aea0b63 3354 d[0] = 0x62; //A_VECM_COUNT (address of Vector debounce counter), write in Active or Standby
nbaker 9:d2e39ee9fedd 3355 d[1] = 0b00000100; //with ODR at 100Hz, 0x04 should equal 40mS debounce time or 80mS in 50Hz Sleep
nbaker 7:3d5a8aea0b63 3356 if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
nbaker 9:d2e39ee9fedd 3357 oled.Label((uint8_t *)"Acc4i err",30,05); // Display "error" at x,y
nbaker 7:3d5a8aea0b63 3358 wait(3.0); // display for 3 seconds
nbaker 7:3d5a8aea0b63 3359 }//end if
nbaker 7:3d5a8aea0b63 3360
nbaker 7:3d5a8aea0b63 3361 // Registers 0x63 - 0x68 are vector reference values which I'm leaving set to 0 because we want absolute measurements
nbaker 7:3d5a8aea0b63 3362
nbaker 7:3d5a8aea0b63 3363 d[0] = 0x2b; //CTRL_REG2 (address of control reg), write in Standby only
nbaker 9:d2e39ee9fedd 3364 // d[1] = 0b00001101; //Turns Auto-Sleep mode on and low-noise, low power
nbaker 9:d2e39ee9fedd 3365 d[1] = 0b00001001; //Turns Auto-Sleep mode off (b/c it wasn't waking on int) and low-noise, low power
nbaker 7:3d5a8aea0b63 3366 if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
nbaker 9:d2e39ee9fedd 3367 oled.Label((uint8_t *)"Acc4jerr",30,05); // Display "error" at x,y
nbaker 7:3d5a8aea0b63 3368 wait(3.0); // display for 3 seconds
nbaker 7:3d5a8aea0b63 3369 }//end if
nbaker 7:3d5a8aea0b63 3370
nbaker 7:3d5a8aea0b63 3371 d[0] = 0x2c; //CTRL_REG3 (address of Int control reg), write in Standby only
nbaker 7:3d5a8aea0b63 3372 d[1] = 0b00001100; //FFMT or Vector will wake chip from sleep, int are active high
nbaker 7:3d5a8aea0b63 3373 if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
nbaker 9:d2e39ee9fedd 3374 oled.Label((uint8_t *)"Acc4k err",30,05); // Display "error" at x,y
nbaker 7:3d5a8aea0b63 3375 wait(3.0); // display for 3 seconds
nbaker 7:3d5a8aea0b63 3376 }//end if
nbaker 7:3d5a8aea0b63 3377
nbaker 7:3d5a8aea0b63 3378 d[0] = 0x2d; //CTRL_REG4 (address of Int enable reg), write in Standby only
nbaker 9:d2e39ee9fedd 3379 d[1] = 0b10000110; // FFMT and Vector int enabled
nbaker 7:3d5a8aea0b63 3380 if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
nbaker 9:d2e39ee9fedd 3381 oled.Label((uint8_t *)"Acc4L err",30,05); // Display "error" at x,y
nbaker 7:3d5a8aea0b63 3382 wait(3.0); // display for 3 seconds
nbaker 7:3d5a8aea0b63 3383 }//end if
nbaker 9:d2e39ee9fedd 3384 // wait(0.2); // people have had a problem here and needed a delay
nbaker 8:a5c77b45008d 3385
nbaker 7:3d5a8aea0b63 3386 d[0] = 0x2e; //CTRL_REG5 (Int routing reg), write in Standby only
nbaker 7:3d5a8aea0b63 3387 d[1] = 0b00000100; // Make FFMT int output on pin INT1(PTC1) and Vector on INT2(PTD13)
nbaker 7:3d5a8aea0b63 3388 if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
nbaker 9:d2e39ee9fedd 3389 oled.Label((uint8_t *)"Acc4m err",30,05); // Display "error" at x,y
nbaker 9:d2e39ee9fedd 3390 wait(3.0); // display for 3 seconds
nbaker 9:d2e39ee9fedd 3391 }//end if
nbaker 9:d2e39ee9fedd 3392
nbaker 9:d2e39ee9fedd 3393 d[0] = 0x29; //ASLP_Count (counter used to go to sleep reg), write in Standby only
nbaker 9:d2e39ee9fedd 3394 d[1] = 0b00001010; // 10*320mS=3.2S of no inturrupts to go to sleep
nbaker 9:d2e39ee9fedd 3395 if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
nbaker 9:d2e39ee9fedd 3396 oled.Label((uint8_t *)"Acc4n err",30,05); // Display "error" at x,y
nbaker 7:3d5a8aea0b63 3397 wait(3.0); // display for 3 seconds
nbaker 7:3d5a8aea0b63 3398 }//end if
nbaker 7:3d5a8aea0b63 3399
nbaker 8:a5c77b45008d 3400 d[0] = 0x2a; //0x2a Config reg1, write in Standby only except for bit[0]
nbaker 7:3d5a8aea0b63 3401 d[1] = 0b00011001; //Auto-Sleep mode on set to 50Hz, ODR set to 100Hz Puts device back into Active mode
nbaker 7:3d5a8aea0b63 3402 if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
nbaker 9:d2e39ee9fedd 3403 oled.Label((uint8_t *)"Acc4o err",30,05); // Display "error" at x,y
nbaker 7:3d5a8aea0b63 3404 wait(3.0); // display for 3 seconds
nbaker 9:d2e39ee9fedd 3405 }//end if
nbaker 7:3d5a8aea0b63 3406 break;
nbaker 9:d2e39ee9fedd 3407 }// end of case 4
nbaker 7:3d5a8aea0b63 3408
nbaker 7:3d5a8aea0b63 3409 case 10: {// reset IC
nbaker 7:3d5a8aea0b63 3410 char d[2];
nbaker 8:a5c77b45008d 3411 d[0] = 0x2a; //0x2a Config reg1
nbaker 8:a5c77b45008d 3412 d[1] = 0x00; //Put device in Standby mode
nbaker 8:a5c77b45008d 3413 if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
nbaker 9:d2e39ee9fedd 3414 oled.Label((uint8_t *)" Step10a err",30,05); // Display "error" at x,y
nbaker 8:a5c77b45008d 3415 wait(3.0); // display for 3 seconds
nbaker 8:a5c77b45008d 3416 }//end if
nbaker 8:a5c77b45008d 3417
nbaker 7:3d5a8aea0b63 3418 d[0] = 0x2b; //CTRL_REG2
nbaker 7:3d5a8aea0b63 3419 d[1] = 0b01000000; // set bit to force reset of FXOS8700
nbaker 7:3d5a8aea0b63 3420 if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){
nbaker 7:3d5a8aea0b63 3421 oled.Label((uint8_t *)" Reset error ",30,05); // Display "error" at x,y
nbaker 7:3d5a8aea0b63 3422 wait(3.0); // display for 3 seconds
nbaker 7:3d5a8aea0b63 3423 }//end if
nbaker 10:eaea844e763c 3424 // oled.Label((uint8_t *)"Acc_Reset",20,60); // Display "reset" at x,y
nbaker 7:3d5a8aea0b63 3425 break;
nbaker 7:3d5a8aea0b63 3426 }// end case 10
nbaker 7:3d5a8aea0b63 3427
nbaker 9:d2e39ee9fedd 3428 case 11: {// wake for simple data read, was in stanby
nbaker 8:a5c77b45008d 3429 char d[2];
nbaker 8:a5c77b45008d 3430 d[0] = FXOS8700_CTRL_REG1; //Puts device in Standby mode just in case
nbaker 8:a5c77b45008d 3431 d[1] = 0x00;
nbaker 8:a5c77b45008d 3432 i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2);
nbaker 8:a5c77b45008d 3433
nbaker 8:a5c77b45008d 3434 d[0] = 0x0e; //XYZ_DATA_CFG (set full-scall range)
nbaker 8:a5c77b45008d 3435 d[1] = 0b00000001; //Set data to +/-4g for full range (0.488mg/LSB), High-pass filter off
nbaker 8:a5c77b45008d 3436 i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2);
nbaker 8:a5c77b45008d 3437
nbaker 8:a5c77b45008d 3438 /*For lowest power ~8uA, set ODR-12.5Hz,(low-pwr accel mode) or 2uA in standby mode */
nbaker 8:a5c77b45008d 3439 d[0] = 0x2a; //0x2a Config reg1, write in Standby only except for bit[0]
nbaker 8:a5c77b45008d 3440 d[1] = 0b00011001; //Auto-Sleep mode on set to 50Hz, ODR set to 100Hz Puts device back into Active mode
nbaker 8:a5c77b45008d 3441 i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d, 2);
nbaker 8:a5c77b45008d 3442 break;
nbaker 8:a5c77b45008d 3443 }// end of case 11
nbaker 8:a5c77b45008d 3444
nbaker 9:d2e39ee9fedd 3445 case 12: {// put into standby for low power
nbaker 8:a5c77b45008d 3446 char d[2];
nbaker 8:a5c77b45008d 3447 d[0] = FXOS8700_CTRL_REG1; //Puts device in Standby mode
nbaker 8:a5c77b45008d 3448 d[1] = 0x00;
nbaker 9:d2e39ee9fedd 3449 i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d, 2);
nbaker 8:a5c77b45008d 3450 /*For lowest power ~8uA, set ODR-12.5Hz,(low-pwr accel mode) or 2uA in standby mode */
nbaker 8:a5c77b45008d 3451 break;
nbaker 8:a5c77b45008d 3452 }// end of case 11
nbaker 8:a5c77b45008d 3453
nbaker 9:d2e39ee9fedd 3454 case 20: {// read INT_Source to clear VECM int, shouldn't have to do this
nbaker 9:d2e39ee9fedd 3455 // This was not working for me but it was due to me using the wrong FXOS8700_I2C_ADDRESS_
nbaker 9:d2e39ee9fedd 3456 char d[2];//, data_byte_[1];
nbaker 9:d2e39ee9fedd 3457 d[0] = 0x0c; // 0x0c is INT_Source Reg
nbaker 9:d2e39ee9fedd 3458 i2c_bus1.write(FXOS8700_I2C_ADDRESS_,d,1,true); // "true" is needed to prevent stop
nbaker 9:d2e39ee9fedd 3459 wait(0.01);
nbaker 9:d2e39ee9fedd 3460 if(i2c_bus1.read(FXOS8700_I2C_ADDRESS_,d,1) == 1){ // read Who am I Reg for debug
nbaker 9:d2e39ee9fedd 3461 sprintf(text_1," INT_Read_Err ");
nbaker 9:d2e39ee9fedd 3462 oled.Label((uint8_t *)text_1,5,50); // Display error at x,y
nbaker 9:d2e39ee9fedd 3463 wait(1); // wait 1 seconds
nbaker 9:d2e39ee9fedd 3464 }//endif
nbaker 9:d2e39ee9fedd 3465 break;
nbaker 9:d2e39ee9fedd 3466 }// end of case 20
nbaker 9:d2e39ee9fedd 3467
nbaker 9:d2e39ee9fedd 3468 case 21: {// read A_FFMT_SRC reg to clear FFMT int, shouldn't have to do this
nbaker 9:d2e39ee9fedd 3469 // This was not working for me but it was due to me using the wrong FXOS8700_I2C_ADDRESS_
nbaker 9:d2e39ee9fedd 3470 char d[2];//, data_byte_[1];
nbaker 9:d2e39ee9fedd 3471 d[0] = 0x16; // 0x16 is A_FFMT_SRC Reg
nbaker 9:d2e39ee9fedd 3472 i2c_bus1.write(FXOS8700_I2C_ADDRESS_,d,1,true); // "true" is needed to prevent stop
nbaker 9:d2e39ee9fedd 3473 wait(0.01);
nbaker 9:d2e39ee9fedd 3474 if(i2c_bus1.read(FXOS8700_I2C_ADDRESS_,d,1) == 1){ // read Who am I Reg for debug
nbaker 9:d2e39ee9fedd 3475 sprintf(text_1," INT_Read_Err ");
nbaker 9:d2e39ee9fedd 3476 oled.Label((uint8_t *)text_1,5,50); // Display error at x,y
nbaker 9:d2e39ee9fedd 3477 wait(1); // wait 1 seconds
nbaker 9:d2e39ee9fedd 3478 }//endif
nbaker 9:d2e39ee9fedd 3479 break;
nbaker 9:d2e39ee9fedd 3480 }// end of case 21
nbaker 8:a5c77b45008d 3481
nbaker 4:0803151bc5e4 3482 default: {
nbaker 9:d2e39ee9fedd 3483 oled.Label((uint8_t *)" Mode? ",30,60); // Display "mode" at x,y
nbaker 4:0803151bc5e4 3484 // unknown config
nbaker 4:0803151bc5e4 3485 break;
nbaker 4:0803151bc5e4 3486 }
nbaker 4:0803151bc5e4 3487 }// end switch
nbaker 4:0803151bc5e4 3488
nbaker 10:eaea844e763c 3489 }// end accel_sensor_cconfig
nbaker 4:0803151bc5e4 3490
nbaker 8:a5c77b45008d 3491 /*****************************************************************************
nbaker 9:d2e39ee9fedd 3492 Name: gyro_sensor_config()
nbaker 9:d2e39ee9fedd 3493 Purpose: Used to set gyro IC's internal registers for chip level
nbaker 9:d2e39ee9fedd 3494 interrupts and power modes
nbaker 9:d2e39ee9fedd 3495 Inputs: int value from 0 to 256
nbaker 9:d2e39ee9fedd 3496 Returns: None
nbaker 9:d2e39ee9fedd 3497 ******************************************************************************/
nbaker 9:d2e39ee9fedd 3498
nbaker 9:d2e39ee9fedd 3499 void gyro_sensor_config(uint8_t Num){
nbaker 9:d2e39ee9fedd 3500 // use case switches here to configure for
nbaker 9:d2e39ee9fedd 3501 switch(Num) {
nbaker 9:d2e39ee9fedd 3502 case 0: {// put in standby
nbaker 9:d2e39ee9fedd 3503 /*For lowest power ~2.8uA in standby mode */
nbaker 9:d2e39ee9fedd 3504 char d[2];
nbaker 9:d2e39ee9fedd 3505 d[0] = FXAS21002_CTRL_REG1; //CTRL_REG1=0x13
nbaker 10:eaea844e763c 3506 d[1] = 0b00001100; //puts device in standby mode and leaves ODR set to 100Hz
nbaker 9:d2e39ee9fedd 3507 if(i2c_bus1.write(FXAS21002_I2C_ADDRESS_, d,2) ==1){
nbaker 9:d2e39ee9fedd 3508 oled.Label((uint8_t *)"gyr_err0a",20,45); // Display "error" at x,y
nbaker 9:d2e39ee9fedd 3509 wait(3.0); // display for 3 seconds
nbaker 9:d2e39ee9fedd 3510 }//end if
nbaker 9:d2e39ee9fedd 3511 break;
nbaker 9:d2e39ee9fedd 3512 }// end of case 0
nbaker 9:d2e39ee9fedd 3513
nbaker 10:eaea844e763c 3514 case 1: {// Fall_Alert mode=1, put in active mode se we can read gyro measurments
nbaker 9:d2e39ee9fedd 3515 char d[2];
nbaker 9:d2e39ee9fedd 3516 d[0] = FXAS21002_CTRL_REG1; //CTRL_REG1=0x13
nbaker 9:d2e39ee9fedd 3517 d[1] = 0x00; //Puts device in standby mode
nbaker 9:d2e39ee9fedd 3518 if(i2c_bus1.write(FXAS21002_I2C_ADDRESS_, d,2) ==1){
nbaker 9:d2e39ee9fedd 3519 oled.Label((uint8_t *)"gyr_err1a",20,45); // Display "error" at x,y
nbaker 9:d2e39ee9fedd 3520 wait(3.0); // display for 3 seconds
nbaker 9:d2e39ee9fedd 3521 }//end if
nbaker 9:d2e39ee9fedd 3522 d[0] = FXAS21002_CTRL_REG0; //CTRL_REG0=0x0d
nbaker 9:d2e39ee9fedd 3523 d[1] = 0x00; //sets FS =+/- 2000 dps
nbaker 9:d2e39ee9fedd 3524 if(i2c_bus1.write(FXAS21002_I2C_ADDRESS_, d,2) ==1){
nbaker 9:d2e39ee9fedd 3525 oled.Label((uint8_t *)"gyr_err1b",20,45); // Display "error" at x,y
nbaker 9:d2e39ee9fedd 3526 wait(3.0); // display for 3 seconds
nbaker 9:d2e39ee9fedd 3527 }//end if
nbaker 9:d2e39ee9fedd 3528 d[0] = FXAS21002_CTRL_REG1; //CTRL_REG1=0x13
nbaker 9:d2e39ee9fedd 3529 d[1] = 0x0e; //0x0e puts device in active mode with ODR = 100Hz
nbaker 9:d2e39ee9fedd 3530 if(i2c_bus1.write(FXAS21002_I2C_ADDRESS_, d,2) ==1){
nbaker 9:d2e39ee9fedd 3531 oled.Label((uint8_t *)"gyr_err1c",20,45); // Display "error" at x,y
nbaker 9:d2e39ee9fedd 3532 wait(3.0); // display for 3 seconds
nbaker 9:d2e39ee9fedd 3533 }//end if
nbaker 9:d2e39ee9fedd 3534 break;
nbaker 9:d2e39ee9fedd 3535 }// end of case 1
nbaker 9:d2e39ee9fedd 3536
nbaker 10:eaea844e763c 3537 case 3: {// Fall_Alert mode 3, set up interupt, put in active mode
nbaker 9:d2e39ee9fedd 3538 char d[2];
nbaker 9:d2e39ee9fedd 3539 d[0] = FXAS21002_CTRL_REG1; //CTRL_REG1=0x13
nbaker 9:d2e39ee9fedd 3540 d[1] = 0x00; //0x08 puts device in standby mode
nbaker 9:d2e39ee9fedd 3541 if(i2c_bus1.write(FXAS21002_I2C_ADDRESS_, d,2) ==1){
nbaker 9:d2e39ee9fedd 3542 oled.Label((uint8_t *)"gyr_err3",20,45); // Display "error" at x,y
nbaker 9:d2e39ee9fedd 3543 wait(3.0); // display for 3 seconds
nbaker 9:d2e39ee9fedd 3544 }//end if
nbaker 9:d2e39ee9fedd 3545
nbaker 9:d2e39ee9fedd 3546 // set RT_CFG reg 0x0e - Rate int config
nbaker 9:d2e39ee9fedd 3547 d[0] = 0x0e; //set RT_CFG reg 0x0e - Rate int config
nbaker 9:d2e39ee9fedd 3548 d[1] = 0b00000111; // enable x,y,z axis
nbaker 9:d2e39ee9fedd 3549 if(i2c_bus1.write(FXAS21002_I2C_ADDRESS_, d,2) ==1){
nbaker 9:d2e39ee9fedd 3550 oled.Label((uint8_t *)"gyr_err3a",20,45); // Display "error" at x,y
nbaker 9:d2e39ee9fedd 3551 wait(3.0); // display for 3 seconds
nbaker 9:d2e39ee9fedd 3552 }//end if
nbaker 9:d2e39ee9fedd 3553
nbaker 9:d2e39ee9fedd 3554 // set RT_THS reg 0x10 - Rate Threshold value
nbaker 9:d2e39ee9fedd 3555 d[0] = 0x10; //set RT_THS reg 0x10 - Rate Threshold config
nbaker 9:d2e39ee9fedd 3556 // d[1] = 0b00000111; // bit7=couter mode(1=clr,0=dec), rate Tresh(dps)=(THS+1)*Sensitivity(dps/LSB
nbaker 9:d2e39ee9fedd 3557 // Sensitivity(dps/LSB), we should have mdps/LSB=62.50 or a full range of +/- 2000 dps
nbaker 9:d2e39ee9fedd 3558 // Movement_Thresh 50 dps=(THS+1)*256*Sensitivity(dps/LSB) => THS = Movement_Thresh/(16.0f)-1
nbaker 9:d2e39ee9fedd 3559 // We specified that 50 dps was the magnitude some of all 3 axis so THS is 1/3 of that
nbaker 9:d2e39ee9fedd 3560 d[1] = (uint8_t)((Movement_Thresh/(3*16.0f))-1); // Movement_Thresh 50 dps setting Tresh(dps)=(THS+1)*256*Sensitivity(dps/LSB)
nbaker 9:d2e39ee9fedd 3561 if(i2c_bus1.write(FXAS21002_I2C_ADDRESS_, d,2) ==1){
nbaker 9:d2e39ee9fedd 3562 oled.Label((uint8_t *)"gyr_err3b",20,45); // Display "error" at x,y
nbaker 9:d2e39ee9fedd 3563 wait(3.0); // display for 3 seconds
nbaker 9:d2e39ee9fedd 3564 }//end if
nbaker 9:d2e39ee9fedd 3565
nbaker 9:d2e39ee9fedd 3566 // set RT_COUNT reg 0x11 - Rate Threshold counter
nbaker 9:d2e39ee9fedd 3567 d[0] = 0x11; //set RT_COUNT reg 0x11 - Rate Threshold counter
nbaker 9:d2e39ee9fedd 3568 // d[1] = 0b10000000; // debounce count value (Count=10, ODR=100Hz => 100mS)
nbaker 9:d2e39ee9fedd 3569 d[1] = (uint8_t)(Min_Movement_Time/0.01f); // debounce count value (at ODR=100Hz, each count = 10mS) 2.55s=255
nbaker 9:d2e39ee9fedd 3570 // need to calculate and store this value
nbaker 9:d2e39ee9fedd 3571 if(i2c_bus1.write(FXAS21002_I2C_ADDRESS_, d,2) ==1){
nbaker 9:d2e39ee9fedd 3572 oled.Label((uint8_t *)"gyr_err3c",20,45); // Display "error" at x,y
nbaker 9:d2e39ee9fedd 3573 wait(3.0); // display for 3 seconds
nbaker 9:d2e39ee9fedd 3574 }//end if
nbaker 9:d2e39ee9fedd 3575
nbaker 9:d2e39ee9fedd 3576 // set CTRL_REG2 reg 0x14 - Int config
nbaker 9:d2e39ee9fedd 3577 d[0] = 0x14; //set CTRL_REG2 reg 0x14 - Int config
nbaker 9:d2e39ee9fedd 3578 d[1] = 0b01110000; // enable RT &FIFO interupts, int=act_low, push/pull
nbaker 9:d2e39ee9fedd 3579 if(i2c_bus1.write(FXAS21002_I2C_ADDRESS_, d,2) ==1){
nbaker 9:d2e39ee9fedd 3580 oled.Label((uint8_t *)"gyr_err3d",20,45); // Display "error" at x,y
nbaker 9:d2e39ee9fedd 3581 wait(3.0); // display for 3 seconds
nbaker 9:d2e39ee9fedd 3582 }//end if
nbaker 9:d2e39ee9fedd 3583
nbaker 9:d2e39ee9fedd 3584 // set CTRL_REG3 reg 0x15 - Auto inc config, external power, FSR <=don't need?
nbaker 9:d2e39ee9fedd 3585 d[0] = 0x15; //CTRL_REG3 reg 0x15
nbaker 9:d2e39ee9fedd 3586 d[1] = 0x00; //Auto inc config, external power, FSR
nbaker 9:d2e39ee9fedd 3587 if(i2c_bus1.write(FXAS21002_I2C_ADDRESS_, d,2) ==1){
nbaker 9:d2e39ee9fedd 3588 oled.Label((uint8_t *)"gyr_err3e",20,45); // Display "error" at x,y
nbaker 9:d2e39ee9fedd 3589 wait(3.0); // display for 3 seconds
nbaker 9:d2e39ee9fedd 3590 }//end if
nbaker 9:d2e39ee9fedd 3591
nbaker 9:d2e39ee9fedd 3592 d[0] = FXAS21002_CTRL_REG0; //CTRL_REG0=0x0d
nbaker 9:d2e39ee9fedd 3593 d[1] = 0x00; //sets FS=0,mdps/LSB=62.50 => +/- 2000 dps
nbaker 9:d2e39ee9fedd 3594 if(i2c_bus1.write(FXAS21002_I2C_ADDRESS_, d,2) ==1){
nbaker 9:d2e39ee9fedd 3595 oled.Label((uint8_t *)"gyr_err3f",20,45); // Display "error" at x,y
nbaker 9:d2e39ee9fedd 3596 wait(3.0); // display for 3 seconds
nbaker 9:d2e39ee9fedd 3597 }//end if
nbaker 9:d2e39ee9fedd 3598 d[0] = FXAS21002_CTRL_REG1; //CTRL_REG1 0x13 - Op mode, ODR selection, reset
nbaker 9:d2e39ee9fedd 3599 d[1] = 0b00001110; //0x0e puts device in active mode and sets ODR to 100Hz
nbaker 9:d2e39ee9fedd 3600 if(i2c_bus1.write(FXAS21002_I2C_ADDRESS_, d,2) ==1){
nbaker 9:d2e39ee9fedd 3601 oled.Label((uint8_t *)"gyr_err3g",20,45); // Display "error" at x,y
nbaker 9:d2e39ee9fedd 3602 wait(3.0); // display for 3 seconds
nbaker 9:d2e39ee9fedd 3603 }//end if
nbaker 9:d2e39ee9fedd 3604 break;
nbaker 10:eaea844e763c 3605 }// end of case 3
nbaker 9:d2e39ee9fedd 3606
nbaker 9:d2e39ee9fedd 3607 case 10: {// reset Gyro IC
nbaker 9:d2e39ee9fedd 3608 char d[2];
nbaker 9:d2e39ee9fedd 3609 d[0] = FXAS21002_CTRL_REG1; //CTRL_REG1 0x13 - Op mode, ODR selection, reset
nbaker 9:d2e39ee9fedd 3610 d[1] = 0b01000000; //resets IC
nbaker 9:d2e39ee9fedd 3611 if(i2c_bus1.write(FXAS21002_I2C_ADDRESS_, d,2) ==1){
nbaker 9:d2e39ee9fedd 3612 oled.Label((uint8_t *)"gyr_err10a",20,45); // Display "error" at x,y
nbaker 9:d2e39ee9fedd 3613 wait(3.0); // display for 3 seconds
nbaker 9:d2e39ee9fedd 3614 }//end if
nbaker 10:eaea844e763c 3615 // oled.Label((uint8_t *)"G_Reset ",30,45); // Display "reset" at x,y
nbaker 9:d2e39ee9fedd 3616 break;
nbaker 9:d2e39ee9fedd 3617 }// end case 10
nbaker 9:d2e39ee9fedd 3618
nbaker 10:eaea844e763c 3619 case 11: {// set sensor to active to read gyro measurments
nbaker 9:d2e39ee9fedd 3620 char d[2];
nbaker 9:d2e39ee9fedd 3621 d[0] = FXAS21002_CTRL_REG1; //CTRL_REG1=0x13
nbaker 10:eaea844e763c 3622 d[1] = 0b00001110; //0x0e puts device in active mode with ODR = 100Hz
nbaker 9:d2e39ee9fedd 3623 if(i2c_bus1.write(FXAS21002_I2C_ADDRESS_, d,2) ==1){
nbaker 9:d2e39ee9fedd 3624 oled.Label((uint8_t *)"gyr_err11a",20,45); // Display "error" at x,y
nbaker 9:d2e39ee9fedd 3625 wait(3.0); // display for 3 seconds
nbaker 9:d2e39ee9fedd 3626 }//end if
nbaker 9:d2e39ee9fedd 3627 break;
nbaker 9:d2e39ee9fedd 3628 }// end of case 11
nbaker 9:d2e39ee9fedd 3629
nbaker 9:d2e39ee9fedd 3630 case 12: {// put in standby
nbaker 9:d2e39ee9fedd 3631 /*For lowest power ~2.8uA in standby mode */
nbaker 9:d2e39ee9fedd 3632 char d[2];
nbaker 9:d2e39ee9fedd 3633 d[0] = FXAS21002_CTRL_REG1; //CTRL_REG1=0x13
nbaker 10:eaea844e763c 3634 d[1] = 0b00001100; //puts device in standby mode and leaves ODR set to 100Hz
nbaker 9:d2e39ee9fedd 3635 if(i2c_bus1.write(FXAS21002_I2C_ADDRESS_, d,2) ==1){
nbaker 9:d2e39ee9fedd 3636 oled.Label((uint8_t *)"gyr_err12a",20,45); // Display "error" at x,y
nbaker 9:d2e39ee9fedd 3637 wait(3.0); // display for 3 seconds
nbaker 9:d2e39ee9fedd 3638 }//end if
nbaker 9:d2e39ee9fedd 3639 break;
nbaker 9:d2e39ee9fedd 3640 }// end of case 12
nbaker 10:eaea844e763c 3641
nbaker 10:eaea844e763c 3642 case 13: {// put in standby then back to active, to clear counter
nbaker 10:eaea844e763c 3643 /*For lowest power ~2.8uA in standby mode */
nbaker 10:eaea844e763c 3644 char d[2];
nbaker 10:eaea844e763c 3645 d[0] = FXAS21002_CTRL_REG1; //CTRL_REG1=0x13
nbaker 10:eaea844e763c 3646 d[1] = 0b00001100; //puts device in standby mode and leaves ODR set to 100Hz
nbaker 10:eaea844e763c 3647 if(i2c_bus1.write(FXAS21002_I2C_ADDRESS_, d,2) ==1){
nbaker 10:eaea844e763c 3648 oled.Label((uint8_t *)"gyr_err12a",20,45); // Display "error" at x,y
nbaker 10:eaea844e763c 3649 wait(3.0); // display for 3 seconds
nbaker 10:eaea844e763c 3650 }//end if
nbaker 10:eaea844e763c 3651 d[1] = 0b00001110; //0x0e puts device in active mode with ODR = 100Hz
nbaker 10:eaea844e763c 3652 if(i2c_bus1.write(FXAS21002_I2C_ADDRESS_, d,2) ==1){
nbaker 10:eaea844e763c 3653 oled.Label((uint8_t *)"gyr_err11a",20,45); // Display "error" at x,y
nbaker 10:eaea844e763c 3654 wait(3.0); // display for 3 seconds
nbaker 10:eaea844e763c 3655 }//end if
nbaker 10:eaea844e763c 3656
nbaker 10:eaea844e763c 3657 break;
nbaker 10:eaea844e763c 3658 }// end of case 13
nbaker 9:d2e39ee9fedd 3659
nbaker 9:d2e39ee9fedd 3660 default: {
nbaker 9:d2e39ee9fedd 3661 oled.Label((uint8_t *)"Gyro_Mode?",20,45); // Display "mode" at x,y
nbaker 9:d2e39ee9fedd 3662 // unknown config
nbaker 9:d2e39ee9fedd 3663 break;
nbaker 9:d2e39ee9fedd 3664 }
nbaker 9:d2e39ee9fedd 3665 }// end switch
nbaker 9:d2e39ee9fedd 3666 }// end gyro_sensor_config
nbaker 9:d2e39ee9fedd 3667
nbaker 9:d2e39ee9fedd 3668 /*****************************************************************************
nbaker 9:d2e39ee9fedd 3669 Name: press_config()
nbaker 9:d2e39ee9fedd 3670 Purpose: Used to set pressure sensor's internal registers for power modes
nbaker 9:d2e39ee9fedd 3671 Inputs: int value from 0 to 256
nbaker 9:d2e39ee9fedd 3672 Returns: None
nbaker 9:d2e39ee9fedd 3673 ******************************************************************************/
nbaker 9:d2e39ee9fedd 3674
nbaker 9:d2e39ee9fedd 3675 void press_config(uint8_t Num){
nbaker 9:d2e39ee9fedd 3676 // use case switches here to configure
nbaker 9:d2e39ee9fedd 3677 switch(Num) {
nbaker 9:d2e39ee9fedd 3678 case 0: {// put in standby (AKA powered down) mode
nbaker 9:d2e39ee9fedd 3679 //For lowest power ~2.8uA in standby mode, sensor should default to this after reset
nbaker 9:d2e39ee9fedd 3680 char d[2];
nbaker 9:d2e39ee9fedd 3681 d[0] = 0x26; //CTRL_REG1=0x26
nbaker 9:d2e39ee9fedd 3682 d[1] = 0x00; //Puts device in powered down mode
nbaker 9:d2e39ee9fedd 3683 if(i2c_bus1.write(0xC0, d,2) ==1){ // 0xc0 is MPL3115A2 address
nbaker 9:d2e39ee9fedd 3684 oled.Label((uint8_t *)"press_err0a",20,30); // Display "error" at x,y
nbaker 9:d2e39ee9fedd 3685 wait(3.0); // display for 3 seconds
nbaker 9:d2e39ee9fedd 3686 }//end if
nbaker 9:d2e39ee9fedd 3687 break;
nbaker 9:d2e39ee9fedd 3688 }// end of case 0
nbaker 9:d2e39ee9fedd 3689
nbaker 9:d2e39ee9fedd 3690 default: {
nbaker 9:d2e39ee9fedd 3691 oled.Label((uint8_t *)"PRESS_Mode?",20,45); // Display "mode" at x,y
nbaker 9:d2e39ee9fedd 3692 // unknown config
nbaker 9:d2e39ee9fedd 3693 break;
nbaker 9:d2e39ee9fedd 3694 }
nbaker 9:d2e39ee9fedd 3695 }// end switch
nbaker 9:d2e39ee9fedd 3696 }// end press_config
nbaker 9:d2e39ee9fedd 3697
nbaker 9:d2e39ee9fedd 3698 /*****************************************************************************
nbaker 9:d2e39ee9fedd 3699 Name: MAX30101_test_config()
nbaker 9:d2e39ee9fedd 3700 Purpose: Used to test operation of the MAX30101 heart-rate sensor
nbaker 9:d2e39ee9fedd 3701 Inputs: int value from 0 to 256
nbaker 9:d2e39ee9fedd 3702 Returns: None
nbaker 9:d2e39ee9fedd 3703 ******************************************************************************/
nbaker 9:d2e39ee9fedd 3704 void MAX30101_test_config(uint8_t Num){
nbaker 9:d2e39ee9fedd 3705 // use case switches here to configure
nbaker 9:d2e39ee9fedd 3706 switch(Num) {
nbaker 9:d2e39ee9fedd 3707 case 0: {// test
nbaker 9:d2e39ee9fedd 3708 char d[2] = {0xfe, 0x07};
nbaker 9:d2e39ee9fedd 3709 if(i2c_bus0.read(0xae, d, 2) == 1){ // read RevID value 0-255
nbaker 9:d2e39ee9fedd 3710 sprintf(text_1,"M_R_Er %i %i",d[0],d[1]);
nbaker 9:d2e39ee9fedd 3711 oled.Label((uint8_t *)text_1,5,16); // Display error at x,y
nbaker 9:d2e39ee9fedd 3712 }//end if
nbaker 9:d2e39ee9fedd 3713 else{
nbaker 9:d2e39ee9fedd 3714 sprintf(text_1,"M_R_data %i %i",d[0],d[1]);
nbaker 9:d2e39ee9fedd 3715 oled.Label((uint8_t *)text_1,5,16); // Display good data at x,y
nbaker 9:d2e39ee9fedd 3716 }
nbaker 9:d2e39ee9fedd 3717 wait(1); // wait 1 seconds
nbaker 9:d2e39ee9fedd 3718 d[0] = 0x09; // Mod_conf reg - SHDN, reset, modes
nbaker 9:d2e39ee9fedd 3719 d[1] = 0b00000111; // set mode to red, green and/or IR LEDs
nbaker 9:d2e39ee9fedd 3720 if(i2c_bus0.write(0xaf, d, 1) ==1){; // "true" is needed to prevent stop, MAX30101 address is 0xae but left shifted
nbaker 9:d2e39ee9fedd 3721 oled.Label((uint8_t *)"MAX_W_err0a",5,30); // Display "error" at x,y
nbaker 9:d2e39ee9fedd 3722 wait(3.0); // display for 3 seconds
nbaker 9:d2e39ee9fedd 3723 }//end if
nbaker 9:d2e39ee9fedd 3724 wait(5); // wait 5 seconds
nbaker 9:d2e39ee9fedd 3725
nbaker 9:d2e39ee9fedd 3726 /*
nbaker 9:d2e39ee9fedd 3727 d[0] = 0xfe; //lets try to read revID value 0-255
nbaker 9:d2e39ee9fedd 3728 d[1] = 0x00; //Puts device in powered down mode
nbaker 9:d2e39ee9fedd 3729 if(i2c_bus0.write(0xae<<1, d,2) ==1){ // MAX30101 address is 0xae but left shifted
nbaker 9:d2e39ee9fedd 3730 oled.Label((uint8_t *)"Max_err0a",20,30); // Display "error" at x,y
nbaker 9:d2e39ee9fedd 3731 wait(3.0); // display for 3 seconds
nbaker 9:d2e39ee9fedd 3732 }//end if
nbaker 9:d2e39ee9fedd 3733 */
nbaker 9:d2e39ee9fedd 3734 break;
nbaker 9:d2e39ee9fedd 3735 }// end of case 0
nbaker 9:d2e39ee9fedd 3736
nbaker 9:d2e39ee9fedd 3737
nbaker 9:d2e39ee9fedd 3738 case 10: {// reset
nbaker 9:d2e39ee9fedd 3739 char d[2];
nbaker 9:d2e39ee9fedd 3740 d[0] = 0x09; // Mod_conf reg - SHDN, reset, modes
nbaker 9:d2e39ee9fedd 3741 d[1] = 0b01000000; //resets IC
nbaker 9:d2e39ee9fedd 3742 if(i2c_bus0.write(0xaf, d, 2) ==1){
nbaker 9:d2e39ee9fedd 3743 oled.Label((uint8_t *)"MAX_W_Err10a",5,1); // Display "error" at x,y
nbaker 10:eaea844e763c 3744 wait(2.0); // wait 0 seconds
nbaker 9:d2e39ee9fedd 3745 }//end if
nbaker 9:d2e39ee9fedd 3746 else {
nbaker 10:eaea844e763c 3747 // oled.Label((uint8_t *)"MAX_Reset",20,30); // Display "reset" at x,y
nbaker 9:d2e39ee9fedd 3748 }
nbaker 10:eaea844e763c 3749 wait(0.01); // wait 0.01 seconds
nbaker 9:d2e39ee9fedd 3750 break;
nbaker 9:d2e39ee9fedd 3751 }// end of case 10
nbaker 9:d2e39ee9fedd 3752
nbaker 9:d2e39ee9fedd 3753 default: {
nbaker 9:d2e39ee9fedd 3754 oled.Label((uint8_t *)"MAX_Mode?",20,45); // Display "mode" at x,y
nbaker 9:d2e39ee9fedd 3755 // unknown config
nbaker 9:d2e39ee9fedd 3756 break;
nbaker 9:d2e39ee9fedd 3757 }
nbaker 9:d2e39ee9fedd 3758 }// end switch
nbaker 9:d2e39ee9fedd 3759 }// end light_config
nbaker 9:d2e39ee9fedd 3760
nbaker 9:d2e39ee9fedd 3761 /*****************************************************************************
nbaker 9:d2e39ee9fedd 3762 Name: light_config()
nbaker 9:d2e39ee9fedd 3763 Purpose: Used to set ambient light sensor's internal registers for power modes
nbaker 9:d2e39ee9fedd 3764 Inputs: int value from 0 to 256
nbaker 9:d2e39ee9fedd 3765 Returns: None
nbaker 9:d2e39ee9fedd 3766 ******************************************************************************/
nbaker 9:d2e39ee9fedd 3767 /*
nbaker 9:d2e39ee9fedd 3768 void light_config(uint8_t Num){
nbaker 9:d2e39ee9fedd 3769 // use case switches here to configure
nbaker 9:d2e39ee9fedd 3770 switch(Num) {
nbaker 9:d2e39ee9fedd 3771 case 0: {// put in standby (AKA powered down) mode
nbaker 9:d2e39ee9fedd 3772 //For lowest power ~2.8uA in standby mode, sensor should default to this after reset
nbaker 9:d2e39ee9fedd 3773 char d[2];
nbaker 9:d2e39ee9fedd 3774 d[0] = TSL2561_CONTROL; //CTRL_REG0=0x00
nbaker 9:d2e39ee9fedd 3775 d[1] = 0x00; //Puts device in powered down mode
nbaker 9:d2e39ee9fedd 3776 if(i2c_bus0.write(TSL2561_I2C_ADDRESS_, d,2) ==1){
nbaker 9:d2e39ee9fedd 3777 oled.Label((uint8_t *)"light_err0a",20,30); // Display "error" at x,y
nbaker 9:d2e39ee9fedd 3778 wait(3.0); // display for 3 seconds
nbaker 9:d2e39ee9fedd 3779 }//end if
nbaker 9:d2e39ee9fedd 3780 break;
nbaker 9:d2e39ee9fedd 3781 }// end of case 0
nbaker 9:d2e39ee9fedd 3782
nbaker 9:d2e39ee9fedd 3783 case 1: {// put in active
nbaker 9:d2e39ee9fedd 3784 char d[2];
nbaker 9:d2e39ee9fedd 3785 d[0] = TSL2561_CONTROL; //CTRL_REG=0x00
nbaker 9:d2e39ee9fedd 3786 d[1] = 0x03; //Puts device in powered up mode
nbaker 9:d2e39ee9fedd 3787 if(i2c_bus0.write(TSL2561_I2C_ADDRESS_, d,2) ==1){
nbaker 9:d2e39ee9fedd 3788 oled.Label((uint8_t *)"light_err0a",20,30); // Display "error" at x,y
nbaker 9:d2e39ee9fedd 3789 wait(3.0); // display for 3 seconds
nbaker 9:d2e39ee9fedd 3790 }//end if
nbaker 9:d2e39ee9fedd 3791 break;
nbaker 9:d2e39ee9fedd 3792 }// end of case 1
nbaker 9:d2e39ee9fedd 3793
nbaker 9:d2e39ee9fedd 3794 default: {
nbaker 9:d2e39ee9fedd 3795 oled.Label((uint8_t *)"LGHT_Mode?",20,45); // Display "mode" at x,y
nbaker 9:d2e39ee9fedd 3796 // unknown config
nbaker 9:d2e39ee9fedd 3797 break;
nbaker 9:d2e39ee9fedd 3798 }
nbaker 9:d2e39ee9fedd 3799 }// end switch
nbaker 9:d2e39ee9fedd 3800 }// end light_config
nbaker 9:d2e39ee9fedd 3801 */
nbaker 9:d2e39ee9fedd 3802
nbaker 9:d2e39ee9fedd 3803 /*****************************************************************************
nbaker 8:a5c77b45008d 3804 Name: update_display_date
nbaker 8:a5c77b45008d 3805 Purpose: Updating display data without updating any data labels. This keeps
nbaker 8:a5c77b45008d 3806 measurements and time values current while reducing screen flicker.
nbaker 8:a5c77b45008d 3807 ******************************************************************************/
nbaker 8:a5c77b45008d 3808 void update_display_date(void)
nbaker 8:a5c77b45008d 3809 {
nbaker 8:a5c77b45008d 3810 oled_text_properties_t textProperties = {0}; // Need these to change font color
nbaker 8:a5c77b45008d 3811 oled.GetTextProperties(&textProperties); // Need these to change font color
nbaker 8:a5c77b45008d 3812 __disable_irq(); // Disable all Interrupts
nbaker 8:a5c77b45008d 3813
nbaker 8:a5c77b45008d 3814 switch(Screen_Num) {
nbaker 8:a5c77b45008d 3815 case 0: {// Main Screen
nbaker 8:a5c77b45008d 3816 HexiwearBattery battery;
nbaker 8:a5c77b45008d 3817 battery.sensorOn();
nbaker 8:a5c77b45008d 3818 if (battery.isBatteryCharging()) {
nbaker 8:a5c77b45008d 3819 textProperties.fontColor = COLOR_GREEN;
nbaker 8:a5c77b45008d 3820 oled.SetTextProperties(&textProperties);
nbaker 8:a5c77b45008d 3821
nbaker 8:a5c77b45008d 3822 sprintf(text_1, "%i%%+", (uint8_t)battery.readLevelPercent());
nbaker 8:a5c77b45008d 3823 // Screen_Timer.attach(&timout_timer,(SCRN_TIME));// Reset/restart ticker timer for OLED while fully charged
nbaker 8:a5c77b45008d 3824 } else {
nbaker 8:a5c77b45008d 3825 sprintf(text_1, "%i%%", (uint8_t)battery.readLevelPercent());
nbaker 8:a5c77b45008d 3826 }
nbaker 8:a5c77b45008d 3827 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 3828
nbaker 8:a5c77b45008d 3829 textProperties.fontColor = COLOR_WHITE;
nbaker 8:a5c77b45008d 3830 oled.SetTextProperties(&textProperties);
nbaker 8:a5c77b45008d 3831
nbaker 8:a5c77b45008d 3832 // added real time and date information
nbaker 8:a5c77b45008d 3833 char buffer[32];
nbaker 8:a5c77b45008d 3834 time_t seconds = time(NULL);
nbaker 8:a5c77b45008d 3835 strftime(buffer,32, "%a,%d %m %Y.%H:%M:%S\r", localtime(&seconds));
nbaker 8:a5c77b45008d 3836 // 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 3837 // oled.Label((uint8_t *)text_1,20,20);// Date at x,y
nbaker 8:a5c77b45008d 3838 sprintf(text_1,"%c%c:%c%c:%c%c ",buffer[15],buffer[16],buffer[18],buffer[19],buffer[21],buffer[22]);
nbaker 9:d2e39ee9fedd 3839
nbaker 9:d2e39ee9fedd 3840
nbaker 9:d2e39ee9fedd 3841 textProperties.font = OpenSans_12x18_Regular; // Max Width of Character = 12px, Max Height of Character = 18px
nbaker 9:d2e39ee9fedd 3842 textProperties.fontColor = COLOR_WHITE;
nbaker 9:d2e39ee9fedd 3843 oled.SetTextProperties(&textProperties);
nbaker 8:a5c77b45008d 3844 oled.Label((uint8_t *)text_1,25,40);// Time at x,y
nbaker 9:d2e39ee9fedd 3845 textProperties.font = OpenSans_10x15_Regular; // Max Width of Character = 10px, Max Height of Character = 15px
nbaker 9:d2e39ee9fedd 3846 textProperties.fontColor = COLOR_WHITE;
nbaker 9:d2e39ee9fedd 3847 oled.SetTextProperties(&textProperties);
nbaker 9:d2e39ee9fedd 3848
nbaker 8:a5c77b45008d 3849 Heat_Index_Calculation();
nbaker 8:a5c77b45008d 3850 sprintf(text,"%i",heat_index);
nbaker 8:a5c77b45008d 3851 oled.TextBox((uint8_t *)text,3,80,15,15); //show HI in a 15px by 15px text box at x=3, y=80
nbaker 10:eaea844e763c 3852
nbaker 10:eaea844e763c 3853 textProperties.fontColor = COLOR_GRAY;
nbaker 10:eaea844e763c 3854 if(Fall_Alert == 1){
nbaker 10:eaea844e763c 3855 textProperties.fontColor = COLOR_GREEN; // is Fall protection on?
nbaker 10:eaea844e763c 3856 }
nbaker 10:eaea844e763c 3857 if(Fall_Alert == 1 && Led_clk1 == 1){
nbaker 10:eaea844e763c 3858 textProperties.fontColor = COLOR_YELLOW; // is Fall detected?
nbaker 10:eaea844e763c 3859 }
nbaker 10:eaea844e763c 3860 if(Fall_Alert == 1 && Led_clk1 == 1 && Led_clk2 == 1){
nbaker 10:eaea844e763c 3861 textProperties.fontColor = COLOR_RED; // is impact detected?
nbaker 10:eaea844e763c 3862 }
nbaker 10:eaea844e763c 3863 oled.SetTextProperties(&textProperties);
nbaker 10:eaea844e763c 3864 oled.Label((uint8_t *)"FAP",1,0); //Display "FAP" at x,y
nbaker 10:eaea844e763c 3865 textProperties.fontColor = COLOR_WHITE;
nbaker 10:eaea844e763c 3866 oled.SetTextProperties(&textProperties);
nbaker 10:eaea844e763c 3867
nbaker 8:a5c77b45008d 3868 break;
nbaker 8:a5c77b45008d 3869 }// end case 0
nbaker 8:a5c77b45008d 3870
nbaker 8:a5c77b45008d 3871 case 21: {// Fall Alert Diagnostic Screen
nbaker 8:a5c77b45008d 3872 if(Fall_Alert_Mode == 0){
nbaker 9:d2e39ee9fedd 3873 fall_config(11); // turn accel sensor to active mode to take a reading, may take 80mS to 300mS
nbaker 8:a5c77b45008d 3874 }
nbaker 8:a5c77b45008d 3875 textProperties.fontColor = COLOR_WHITE;
nbaker 8:a5c77b45008d 3876 oled.SetTextProperties(&textProperties);
nbaker 8:a5c77b45008d 3877 gyro.acquire_gyro_data_dps(Gyro_Data);
nbaker 8:a5c77b45008d 3878 Gyro_Mag = (abs(Gyro_Data[0])+abs(Gyro_Data[1])+abs(Gyro_Data[2]));
nbaker 8:a5c77b45008d 3879 sprintf(text_1," %4.0f D/S ",Gyro_Mag);
nbaker 9:d2e39ee9fedd 3880 oled.Label((uint8_t *)text_1,37,60);// text_1 at x,y
nbaker 8:a5c77b45008d 3881
nbaker 8:a5c77b45008d 3882 accel.acquire_accel_data_g(Accel_Data);
nbaker 8:a5c77b45008d 3883 if(Fall_Alert_Mode == 0){
nbaker 8:a5c77b45008d 3884 fall_config(12); // turn accel sensor back to standby
nbaker 8:a5c77b45008d 3885 }
nbaker 8:a5c77b45008d 3886 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 3887 sprintf(text_1," %2.2f g ",Accel_Mag);
nbaker 9:d2e39ee9fedd 3888 oled.Label((uint8_t *)text_1,39,40);// text_1 at x,y
nbaker 9:d2e39ee9fedd 3889 if(Accel_Mag > Fall_Thresh + 0.05f && Led_clk2 == 1){// are we stuck in limbo?
nbaker 8:a5c77b45008d 3890 fall_det_end();
nbaker 8:a5c77b45008d 3891 }
nbaker 8:a5c77b45008d 3892 break;
nbaker 8:a5c77b45008d 3893 }//end case 21
nbaker 8:a5c77b45008d 3894
nbaker 8:a5c77b45008d 3895 default: {
nbaker 8:a5c77b45008d 3896 // do nothing for other screens
nbaker 8:a5c77b45008d 3897 break;
nbaker 8:a5c77b45008d 3898 }
nbaker 8:a5c77b45008d 3899 }// end switch
nbaker 8:a5c77b45008d 3900 __enable_irq(); // Enable all Interrupts
nbaker 8:a5c77b45008d 3901 }// end of update_display_date
nbaker 8:a5c77b45008d 3902
nbaker 8:a5c77b45008d 3903
nbaker 8:a5c77b45008d 3904 /*****************************************************************************
nbaker 8:a5c77b45008d 3905 Name: BLUETOOTH
nbaker 8:a5c77b45008d 3906 Purpose: HexiHeart Connecction
nbaker 8:a5c77b45008d 3907 Inputs: None
nbaker 8:a5c77b45008d 3908 Returns: None
nbaker 8:a5c77b45008d 3909 ******************************************************************************/
nbaker 8:a5c77b45008d 3910
nbaker 8:a5c77b45008d 3911
nbaker 8:a5c77b45008d 3912 void txTask(void)
nbaker 8:a5c77b45008d 3913 {
nbaker 8:a5c77b45008d 3914
nbaker 8:a5c77b45008d 3915 while (true) {
nbaker 8:a5c77b45008d 3916 /*Notify Hexiwear App that it is running Sensor Tag mode*/
nbaker 8:a5c77b45008d 3917 /* This part was not compiling
nbaker 8:a5c77b45008d 3918 kw40z_device.SendSetApplicationMode(GUI_CURRENT_APP_SENSOR_TAG);
nbaker 8:a5c77b45008d 3919 */
nbaker 8:a5c77b45008d 3920 }
nbaker 8:a5c77b45008d 3921 }