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

Dependencies:   FXAS21002 FXOS8700 Hexi_KW40Z Hexi_OLED_SSD1351 MAXIM W25Q64FVSSIG HTU21D MPL3115A2 TSL2561

Fork of HexiHeart_Alex by Hexiwear_zeta

Committer:
asong
Date:
Wed Apr 11 02:23:07 2018 +0000
Revision:
15:330794a9f347
Parent:
14:c3b080cdf36b
Child:
16:537ef0c72084
Fixed issues from previous upload. Also fixed the heat index display on the home screen to show regardless of the value. WDT causes heart rate measurement to restart the device. WDT causes manual hr in/decrementing slow.

Who changed what in which revision?

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