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

Dependencies:   FXAS21002 FXOS8700 Hexi_KW40Z Hexi_OLED_SSD1351 MAXIM W25Q64FVSSIG HTU21D MPL3115A2 TSL2561

Fork of HexiHeart_Alex by Hexiwear_zeta

Committer:
nbaker
Date:
Tue May 01 15:13:45 2018 +0000
Revision:
19:87ab6daf98e5
Parent:
18:1f28eca85e3f
Child:
20:990951205fbd
v2.16 - Cast rolling average calculations as float to reduce rounding error. removed two screens from diagnostic because we don't use them.; Changed FAP to AFP in two locations.

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