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

Dependencies:   FXAS21002 FXOS8700 Hexi_KW40Z Hexi_OLED_SSD1351 MAXIM W25Q64FVSSIG HTU21D MPL3115A2 TSL2561

Fork of HexiHeart_Alex by Hexiwear_zeta

Committer:
asong
Date:
Mon May 07 21:49:35 2018 +0000
Revision:
20:990951205fbd
Parent:
19:87ab6daf98e5
Child:
21:76237b62466b
Fixed WDT going off on some of the heart rate vibrations. Heart rate now displays on the main screen when the heart rate mode is active, and is displayed in the color of the zone.

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