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:
Tue May 08 03:05:45 2018 +0000
Revision:
21:76237b62466b
Parent:
20:990951205fbd
Child:
22:3de592f8e696
Fixed some refreshing of values

Who changed what in which revision?

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