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

Dependencies:   FXAS21002 FXOS8700 Hexi_KW40Z Hexi_OLED_SSD1351 MAXIM W25Q64FVSSIG HTU21D MPL3115A2 TSL2561

Fork of HexiHeart_Alex by Hexiwear_zeta

Committer:
asong
Date:
Fri Apr 13 00:10:22 2018 +0000
Revision:
17:746dc1b7b218
Parent:
16:537ef0c72084
Child:
18:1f28eca85e3f
Optimized some heart rate displays

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