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

Dependencies:   FXAS21002 FXOS8700 Hexi_KW40Z Hexi_OLED_SSD1351 MAXIM W25Q64FVSSIG HTU21D MPL3115A2 TSL2561

Fork of HexiHeart_Alex by Hexiwear_zeta

Committer:
nbaker
Date:
Thu Mar 29 16:55:40 2018 +0000
Revision:
12:fd39a7983e06
Parent:
11:ccda4d44bd8e
Child:
13:37cd579208e9
v2.11 - Added Send_Alert(0) to turn off alerts by sending amb_light=0, ; added WDT and added WDT testing screens, changed fall Min_Movement_duration from 60s to 10s, added subtle vibration after impact for diagnostic purposes.

Who changed what in which revision?

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