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

Dependencies:   FXAS21002 FXOS8700 Hexi_KW40Z Hexi_OLED_SSD1351 MAXIM W25Q64FVSSIG HTU21D MPL3115A2 TSL2561

Fork of HexiHeart_Alex by Hexiwear_zeta

Committer:
nbaker
Date:
Mon Apr 16 12:33:00 2018 +0000
Revision:
18:1f28eca85e3f
Parent:
17:746dc1b7b218
Child:
19:87ab6daf98e5
v2.15 - added display screens 41 and 42 back in.

Who changed what in which revision?

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