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