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@22:3de592f8e696, 2018-05-10 (annotated)
- Committer:
- asong
- Date:
- Thu May 10 03:44:47 2018 +0000
- Revision:
- 22:3de592f8e696
- Parent:
- 21:76237b62466b
Added stages to the heart rate simulation
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 | 19:87ab6daf98e5 | 11 | |
nbaker | 19:87ab6daf98e5 | 12 | ******Basic Program layout******** |
nbaker | 9:d2e39ee9fedd | 13 | Declarations |
nbaker | 9:d2e39ee9fedd | 14 | Up Button routines |
nbaker | 9:d2e39ee9fedd | 15 | Down Button routines |
nbaker | 9:d2e39ee9fedd | 16 | Right Button routines |
nbaker | 9:d2e39ee9fedd | 17 | Left Button routines |
nbaker | 9:d2e39ee9fedd | 18 | Main() |
nbaker | 9:d2e39ee9fedd | 19 | Main display screen routines |
nbaker | 12:fd39a7983e06 | 20 | Function and interrupt routines |
nbaker | 9:d2e39ee9fedd | 21 | Display data screen update routines |
nbaker | 9:d2e39ee9fedd | 22 | |
nbaker | 11:ccda4d44bd8e | 23 | ************** Versions **************** |
asong | 21:76237b62466b | 24 | V2.17 - Added heart rate measurement to the main screen when any of the heart |
asong | 21:76237b62466b | 25 | rate features are enabled. Fixed some WDT resets with certain heart rate |
asong | 21:76237b62466b | 26 | vibrations. |
asong | 21:76237b62466b | 27 | |
nbaker | 19:87ab6daf98e5 | 28 | v2.16 - Cast rolling average calculations as float to reduce rounding error. |
nbaker | 19:87ab6daf98e5 | 29 | removed two screens from diagnostic because we don't use them. |
nbaker | 19:87ab6daf98e5 | 30 | Changed FAP to AFP in two locations. |
nbaker | 19:87ab6daf98e5 | 31 | |
nbaker | 19:87ab6daf98e5 | 32 | v2.15 - added display screens 41 and 42 back in. |
nbaker | 18:1f28eca85e3f | 33 | |
nbaker | 16:537ef0c72084 | 34 | v2.14 - Retasked hr_led Ticker to turn off heart rate zone LEDs thereby preventing the |
nbaker | 16:537ef0c72084 | 35 | system from having to spend half its time in a wait state. added HR screen #7 to |
nbaker | 16:537ef0c72084 | 36 | screens that get refreshed with new data twice a second. Reduced WDT back to 2 seconds. |
nbaker | 16:537ef0c72084 | 37 | Increased rolling average to 10 samples. removed 0.05s wait during HR read. |
nbaker | 16:537ef0c72084 | 38 | |
asong | 14:c3b080cdf36b | 39 | v2.13 - Added heart rate measurement, heart rate simulation, |
asong | 14:c3b080cdf36b | 40 | improved heart rate leds, and optimized heart rate functionalities |
asong | 14:c3b080cdf36b | 41 | |
nbaker | 13:37cd579208e9 | 42 | v2.12 - Added hidden reset feature (push left button 9+ times, on screen zero, to reset), added line that |
nbaker | 13:37cd579208e9 | 43 | might put K64 into low power run mode, added dimming feature to display, changed humid/temp and battery |
nbaker | 13:37cd579208e9 | 44 | measurement to a rolling average. Made new screen for sending panic alert. |
nbaker | 13:37cd579208e9 | 45 | |
nbaker | 13:37cd579208e9 | 46 | v2.11 - 4/1/18 - Added Send_Alert(0) to turn off alerts by sending amb_light=0, |
nbaker | 12:fd39a7983e06 | 47 | added WDT and added WDT testing screens, changed fall Min_Movement_duration |
nbaker | 12:fd39a7983e06 | 48 | from 60s to 10s, added subtle vibration after impact for diagnostic purposes. |
nbaker | 12:fd39a7983e06 | 49 | |
nbaker | 11:ccda4d44bd8e | 50 | v2.10 - Adding BLE pairing code, spoofing amb light sensor data for alert status |
nbaker | 12:fd39a7983e06 | 51 | light=10 =>Panic Alert, 20=Fall+asked for help, 30=Fall+No response, 40=?... |
nbaker | 11:ccda4d44bd8e | 52 | |
nbaker | 13:37cd579208e9 | 53 | v2.09 - 3/25/18 - Added final fall mode (full sequential fall algorithm), including alert screen |
nbaker | 10:eaea844e763c | 54 | and dismiss alert screen. Added FAP (Fall Alert Protection) to main screen. fixed "aggressive Haptic" problem by using a Ticker to |
nbaker | 10:eaea844e763c | 55 | turn off Haptic instead of RTOS timer. |
nbaker | 10:eaea844e763c | 56 | |
nbaker | 9:d2e39ee9fedd | 57 | v2.08 - Fixed impact detect functionality, all fall detect parameters are now adjustable, |
nbaker | 9:d2e39ee9fedd | 58 | added motion detect function, incorporated new heat index calc, increased font by 20% for time/date. |
nbaker | 9:d2e39ee9fedd | 59 | Added SW and power resetting to initialize sensors in known state. |
nbaker | 9:d2e39ee9fedd | 60 | |
nbaker | 9:d2e39ee9fedd | 61 | v2.07 - 2/18/18 - Added fall mode option to test fall/impact separately, Added global |
nbaker | 9:d2e39ee9fedd | 62 | interrupt disable prevent button interrupts while refreshing screen, this caused haptic |
nbaker | 9:d2e39ee9fedd | 63 | timer to stop working right. |
nbaker | 9:d2e39ee9fedd | 64 | |
nbaker | 9:d2e39ee9fedd | 65 | v1.0 - 11/12/17 |
nbaker | 0:d1d36a3da39b | 66 | This version has basic menu layout and screen timeout feature. The menu |
asong | 1:e4b38d6918ba | 67 | are just placeholders (for the most part) and will be either adjusted or |
nbaker | 0:d1d36a3da39b | 68 | replaced with graphic images. |
nbaker | 0:d1d36a3da39b | 69 | ***********************************************************************/ |
nbaker | 0:d1d36a3da39b | 70 | |
nbaker | 0:d1d36a3da39b | 71 | #include "mbed.h" |
nbaker | 0:d1d36a3da39b | 72 | #include "Hexi_KW40Z.h" // Button and BLE fuctions |
nbaker | 9:d2e39ee9fedd | 73 | #include "FXOS8700.h" // Freescale/NXP FXOS8700CQ - 3D Accelorometer & Mag |
nbaker | 9:d2e39ee9fedd | 74 | #include "FXAS21002.h" // Freescale/NXP FXAS21002CQ - 3-Axis Gyroscope |
nbaker | 9:d2e39ee9fedd | 75 | //#include "MPL3115A2.h" // Freescale/NXP MPL3115A2 - pressure sensor |
nbaker | 9:d2e39ee9fedd | 76 | #include "HTU21D.h" // Non-Freescale/NXP - HTU21D - combo temperature and Humidity |
nbaker | 9:d2e39ee9fedd | 77 | #include "W25Q64FV.h" // Non-Freescale/NXP - W25Q64FVSSIG - 8MB/64Mbit Serial Flash memory |
nbaker | 9:d2e39ee9fedd | 78 | #include "MAX30101.h" // Non-Freescale MAX30101 - Optical Heart rate sensor |
nbaker | 9:d2e39ee9fedd | 79 | //#include "TSL2561.h" // Non-Freescale/NXP TSL2561 - light sensor |
nbaker | 9:d2e39ee9fedd | 80 | #include "Hexi_Battery/hexi_battery.h" // Battery status |
nbaker | 0:d1d36a3da39b | 81 | #include "Hexi_OLED_SSD1351.h" // OLED fuctions |
nbaker | 0:d1d36a3da39b | 82 | #include "OLED_types.h" // Text attributs |
nbaker | 0:d1d36a3da39b | 83 | #include "string.h" |
nbaker | 0:d1d36a3da39b | 84 | #include "OpenSans_Font.h" |
nbaker | 9:d2e39ee9fedd | 85 | #include "images.h" |
asong | 1:e4b38d6918ba | 86 | |
asong | 2:824ed4ae8d52 | 87 | |
asong | 14:c3b080cdf36b | 88 | /* General Definitions */ |
asong | 21:76237b62466b | 89 | #define SW_Ver 2.17 // For displaying software version |
asong | 2:824ed4ae8d52 | 90 | #define LED_ON 0 |
asong | 2:824ed4ae8d52 | 91 | #define LED_OFF 1 |
nbaker | 12:fd39a7983e06 | 92 | #define SCRN_TIME 10.0 // Set OLED screen turn off time to 10.0 seconds |
nbaker | 16:537ef0c72084 | 93 | #define WDT_TIME 2.0 // Set Watch Dog timer to 1.5 seconds (1.5s reset in certain subroutines) |
nbaker | 19:87ab6daf98e5 | 94 | #define MAX_AVE_NUM 10.0f // maximum averaging depth of rolling average for batt, temp and humid |
nbaker | 12:fd39a7983e06 | 95 | #define Debug 1 // If "Debug" is defined, our code will compile for debug. Comment out for Production code. |
asong | 14:c3b080cdf36b | 96 | |
nbaker | 19:87ab6daf98e5 | 97 | #define FXOS8700_I2C_ADDRESS_ (0x1E<<1) //I2C address, pins SA0,SA1=0 |
nbaker | 19:87ab6daf98e5 | 98 | #define FXAS21002_I2C_ADDRESS_ 0x40 //I2C address |
asong | 14:c3b080cdf36b | 99 | //#define TSL2561_I2C_ADDRESS_ (0x29 << 1) // Address select line is grounded |
asong | 14:c3b080cdf36b | 100 | //#define MPL3115A2_I2C_ADDRESS_ ? // |
asong | 14:c3b080cdf36b | 101 | |
asong | 14:c3b080cdf36b | 102 | /*Heart Rate Definitions */ |
nbaker | 12:fd39a7983e06 | 103 | #define HIGHEST_ZONE 4 // Highest heart rate zone |
asong | 2:824ed4ae8d52 | 104 | #define LOWEST_ZONE 1 |
asong | 2:824ed4ae8d52 | 105 | #define ENTER_BELOW 25 |
asong | 2:824ed4ae8d52 | 106 | #define ENTER_ABOVE 50 |
asong | 2:824ed4ae8d52 | 107 | #define EXIT_BELOW 75 |
asong | 2:824ed4ae8d52 | 108 | #define EXIT_ABOVE 100 |
nbaker | 12:fd39a7983e06 | 109 | #define VIB_OPT_2 75 // Haptic vibration pattern option for heart rate functions |
nbaker | 16:537ef0c72084 | 110 | #define HR_LED_on_time 0.5 //how long should zone LED stay on for? |
nbaker | 16:537ef0c72084 | 111 | #define HR_LED_period 1.0 //how often should zone LED blink? |
asong | 14:c3b080cdf36b | 112 | /* I2C Address */ |
asong | 14:c3b080cdf36b | 113 | #define HR_W_ADDR 0xAE |
asong | 14:c3b080cdf36b | 114 | #define HR_R_ADDR 0xAF |
asong | 14:c3b080cdf36b | 115 | |
asong | 14:c3b080cdf36b | 116 | /* Status */ |
asong | 14:c3b080cdf36b | 117 | #define REG_INT_MSB 0x00 /* Interrupt Status 1 */ |
asong | 14:c3b080cdf36b | 118 | #define REG_INT_LSB 0x01 /* Interrupt Status 2 */ |
asong | 14:c3b080cdf36b | 119 | #define REG_INT_ENB_MSB 0x02 /* Interrupt Enable 1 */ |
asong | 14:c3b080cdf36b | 120 | #define REG_INT_ENB_LSB 0x03 /* Interrupt Enable 2 */ |
asong | 14:c3b080cdf36b | 121 | /* FIFO */ |
asong | 14:c3b080cdf36b | 122 | #define REG_FIFO_WR_PTR 0x04 /* FIFO Write Pointer */ |
asong | 14:c3b080cdf36b | 123 | #define REG_OVF_COUNTER 0x05 /* Overflow Counter */ |
asong | 14:c3b080cdf36b | 124 | #define REG_FIFO_RD_PTR 0x06 /* FIFO Read Pointer */ |
asong | 14:c3b080cdf36b | 125 | #define REG_FIFO_DATA 0x07 /* FIFO Data Register */ |
asong | 14:c3b080cdf36b | 126 | /* Configuration */ |
asong | 14:c3b080cdf36b | 127 | #define REG_FIFO_CONFIG 0x08 /* FIFO Configuration */ |
asong | 14:c3b080cdf36b | 128 | #define REG_MODE_CONFIG 0x09 /* Mode Configuration */ |
asong | 14:c3b080cdf36b | 129 | #define REG_SPO2_CONFIG 0x0A /* SpO2 Configuration */ |
asong | 14:c3b080cdf36b | 130 | /* reserved 0x0B */ |
asong | 14:c3b080cdf36b | 131 | #define REG_LED1_PA 0x0C /* RED LED Pulse Amplitude 1 */ |
asong | 14:c3b080cdf36b | 132 | #define REG_LED2_PA 0x0D /* IR LED Pulse Amplitude 2 */ |
asong | 14:c3b080cdf36b | 133 | #define REG_LED3_PA 0x0E /* GREEN LED Pulse Amplitude 3 */ |
asong | 14:c3b080cdf36b | 134 | /* reserved 0x0F */ |
asong | 14:c3b080cdf36b | 135 | #define REG_PILOT_PA 0x10 /* Proximity LED Pulse Amplitude */ |
asong | 14:c3b080cdf36b | 136 | #define REG_SLOT_MSB 0x11 /* Multi-LED Mode Control Registers 2, 1 */ |
asong | 14:c3b080cdf36b | 137 | #define REG_SLOT_LSB 0x12 /* Multi-LED Mode Control Registers 4, 3 */ |
asong | 14:c3b080cdf36b | 138 | /* DIE Temperature */ |
asong | 14:c3b080cdf36b | 139 | #define REG_TEMP_INT 0x1F /* Die Temperature Integer */ |
asong | 14:c3b080cdf36b | 140 | #define REG_TEMP_FRAC 0x20 /* Die Temperature Fraction */ |
asong | 14:c3b080cdf36b | 141 | #define REG_TEMP_EN 0x21 /* Die Temperature Config */ |
asong | 14:c3b080cdf36b | 142 | /* Proximity Function */ |
asong | 14:c3b080cdf36b | 143 | #define REG_PROX_INT_THR 0x30 /* Proximity Interrupt Threshold */ |
asong | 14:c3b080cdf36b | 144 | /* Part ID */ |
asong | 14:c3b080cdf36b | 145 | #define REG_REV_ID 0xFE /* Revision ID */ |
asong | 14:c3b080cdf36b | 146 | #define REG_PART_ID 0xFF /* Part ID: 0x15 */ |
asong | 14:c3b080cdf36b | 147 | /* Depth of FIFO */ |
asong | 14:c3b080cdf36b | 148 | #define FIFO_DEPTH 32 |
asong | 14:c3b080cdf36b | 149 | /* End of heart rate definitions */ |
asong | 1:e4b38d6918ba | 150 | |
nbaker | 13:37cd579208e9 | 151 | |
nbaker | 0:d1d36a3da39b | 152 | void StartHaptic(void); |
nbaker | 10:eaea844e763c | 153 | void Haptic_Off_(void); // added by NRB |
asong | 1:e4b38d6918ba | 154 | void StartHaptic(int x); |
nbaker | 0:d1d36a3da39b | 155 | void StopHaptic(void const *n); |
nbaker | 9:d2e39ee9fedd | 156 | void error_screen(void); // display error screen |
nbaker | 4:0803151bc5e4 | 157 | void update_display(void);// Screen lables refreshed |
nbaker | 8:a5c77b45008d | 158 | void update_display_date(void); // Screen data(only)refreshed |
nbaker | 13:37cd579208e9 | 159 | void Screen_timer1(void); |
asong | 2:824ed4ae8d52 | 160 | void Decrement_Age(); |
asong | 2:824ed4ae8d52 | 161 | void Set_Max_Bpm(); |
asong | 2:824ed4ae8d52 | 162 | void Set_Zone_Boundaries(); |
asong | 2:824ed4ae8d52 | 163 | void Increment_Age(); |
asong | 2:824ed4ae8d52 | 164 | void Increment_Target_Zone(); |
asong | 2:824ed4ae8d52 | 165 | void Decrement_Target_Zone(); |
asong | 2:824ed4ae8d52 | 166 | void Increment_HR_Vibr_Pref(); |
asong | 2:824ed4ae8d52 | 167 | void Decrement_HR_Vibr_Pref(); |
asong | 2:824ed4ae8d52 | 168 | void Determine_Current_Zone(); |
asong | 2:824ed4ae8d52 | 169 | void Heart_Rate_Vibrations(); |
asong | 2:824ed4ae8d52 | 170 | void Increment_Heart_Rate(); |
asong | 2:824ed4ae8d52 | 171 | void Decrement_Heart_Rate(); |
asong | 2:824ed4ae8d52 | 172 | void Enable_Heart_Rate(); |
asong | 2:824ed4ae8d52 | 173 | void Disable_Heart_Rate(); |
asong | 2:824ed4ae8d52 | 174 | void Led_Zone_Indicator(); |
nbaker | 16:537ef0c72084 | 175 | void Led_Zone_Indicator_off(); // turns off LEDs after 0.5 seconds instead of using a wait command |
jmr274 | 5:e1431272be79 | 176 | void Heat_Index_Calculation(); |
nbaker | 10:eaea844e763c | 177 | void fall_config(uint8_t); //function call to setup fall detecting modes |
nbaker | 10:eaea844e763c | 178 | void accel_sensor_config(uint8_t); |
nbaker | 10:eaea844e763c | 179 | void gyro_sensor_config(uint8_t); |
nbaker | 9:d2e39ee9fedd | 180 | void light_config(uint8_t); |
nbaker | 9:d2e39ee9fedd | 181 | void press_config(uint8_t); |
nbaker | 10:eaea844e763c | 182 | void fall_detect(void); // Interupt routine |
nbaker | 10:eaea844e763c | 183 | void fall_detect_debug(void); // Interupt routine |
nbaker | 10:eaea844e763c | 184 | void fall_det_end(void); // Interupt routine |
nbaker | 10:eaea844e763c | 185 | void fall_det_end_debug(void); // Interupt routine |
nbaker | 10:eaea844e763c | 186 | void chkfall(void); // Routine used with Ticker |
nbaker | 10:eaea844e763c | 187 | void interupt_off(void); |
nbaker | 10:eaea844e763c | 188 | void clear_fall(void); // Routine used with Ticker |
nbaker | 10:eaea844e763c | 189 | void impact_detect(void); // Interupt routine |
nbaker | 10:eaea844e763c | 190 | void impact_detect_debug(void); // Interupt routine |
nbaker | 10:eaea844e763c | 191 | void motion_detect(); // Interupt routine |
nbaker | 10:eaea844e763c | 192 | void motion_detect_debug(); // Interupt routine |
nbaker | 10:eaea844e763c | 193 | void chkmotion(void); // Routine used with Ticker |
nbaker | 13:37cd579208e9 | 194 | void chk_help_needed(void); // Routine used with Ticker |
nbaker | 11:ccda4d44bd8e | 195 | void txTask(void); |
nbaker | 13:37cd579208e9 | 196 | void PassKey(void); |
nbaker | 9:d2e39ee9fedd | 197 | void MAX30101_test_config(uint8_t); |
nbaker | 13:37cd579208e9 | 198 | void Send_Alert(uint8_t); // function to store and send alert |
nbaker | 13:37cd579208e9 | 199 | void WDT_Timeout(void); // WDT Routine used reset |
nbaker | 13:37cd579208e9 | 200 | void CLRWDT(void); // function to clear WDT |
nbaker | 13:37cd579208e9 | 201 | void UpDate_Ave(void); // function used to update slow changing measurments |
asong | 14:c3b080cdf36b | 202 | void HR_Simulation(void); // Step through a constrained random heart rate simulation to demo zones |
asong | 14:c3b080cdf36b | 203 | void readRegs(int, uint8_t *, int); //I2c read for maxim chip |
asong | 14:c3b080cdf36b | 204 | void writeRegs(uint8_t, int); //I2c write for maxim chip |
asong | 14:c3b080cdf36b | 205 | /* Functions for setting maxim chip values */ |
asong | 14:c3b080cdf36b | 206 | void setIntEnable(uint16_t); |
asong | 14:c3b080cdf36b | 207 | void setFIFO_WR_PTR(uint8_t); |
asong | 14:c3b080cdf36b | 208 | void setOVF_COUNTER(uint8_t); |
asong | 14:c3b080cdf36b | 209 | void setFIFO_RD_PTR(uint8_t); |
asong | 14:c3b080cdf36b | 210 | void setFIFO_DATA(uint8_t); |
asong | 14:c3b080cdf36b | 211 | void setFIFO_CONFIG(uint8_t); |
asong | 14:c3b080cdf36b | 212 | void setMODE_CONFIG(uint8_t); |
asong | 14:c3b080cdf36b | 213 | void setSPO2_CONFIG(uint8_t); |
asong | 14:c3b080cdf36b | 214 | void setLED1_PA(uint8_t); |
asong | 14:c3b080cdf36b | 215 | void setLED2_PA(uint8_t); |
asong | 14:c3b080cdf36b | 216 | void setLED3_PA(uint8_t); |
asong | 14:c3b080cdf36b | 217 | void setPILOT_PA(uint8_t); |
asong | 14:c3b080cdf36b | 218 | void setSLOT(uint16_t); |
asong | 14:c3b080cdf36b | 219 | void setPROX_INT_THR(uint8_t); |
asong | 14:c3b080cdf36b | 220 | void clearFIFO(void); |
asong | 14:c3b080cdf36b | 221 | uint32_t readFIFO(void); //Read from the maxim chips fifo |
asong | 14:c3b080cdf36b | 222 | void maxReset(void); //Reset maxim chip |
asong | 14:c3b080cdf36b | 223 | void maxInit(void); //Initialize the maxim chip with necessary values |
asong | 14:c3b080cdf36b | 224 | uint16_t getIntEnable(void); |
asong | 14:c3b080cdf36b | 225 | void maxEnable(void); //Begin the maxim chip light measurements |
asong | 14:c3b080cdf36b | 226 | void maxDeinit(void); //Turn off the maxim chip |
asong | 14:c3b080cdf36b | 227 | uint32_t isPeak(uint32_t *); //Calculate the peak of a sample from the maxim chip |
asong | 14:c3b080cdf36b | 228 | void processHeartRate(void); //Calculate the heart rate measurement |
asong | 1:e4b38d6918ba | 229 | |
nbaker | 0:d1d36a3da39b | 230 | // ***************** Global variables *********************** |
nbaker | 0:d1d36a3da39b | 231 | char text_1[20]; // Text buffer - Do we need more? |
asong | 2:824ed4ae8d52 | 232 | char display_buff[30]; //Buffer for conversion to char to display |
jmr274 | 5:e1431272be79 | 233 | char text[20]; // Text Buffer for dynamic value displayed |
nbaker | 11:ccda4d44bd8e | 234 | bool BLE_On = 1; // Initialize as BLE on |
nbaker | 8:a5c77b45008d | 235 | char pass [20]; // Passcode |
asong | 2:824ed4ae8d52 | 236 | bool Led_Zones = 1; |
asong | 1:e4b38d6918ba | 237 | bool HR_Enable = 0; |
nbaker | 0:d1d36a3da39b | 238 | bool OLED_ON = 1; // Turn OLED power on/off |
nbaker | 4:0803151bc5e4 | 239 | bool Fall_Alert = 1; // Initialize as no active alert |
jmr274 | 5:e1431272be79 | 240 | bool Panic_Alert = 0; // Initialize as no active alert |
nbaker | 10:eaea844e763c | 241 | uint8_t Fall_Alert_Mode = 5; // Initialize with fall alert mode on |
jmr274 | 5:e1431272be79 | 242 | bool Heart_Rate_Mode = 0; // Initialize with Heart rate off |
nbaker | 0:d1d36a3da39b | 243 | float Accel_Mag=0.0; // Vector magnitude calculated from sensor data |
nbaker | 0:d1d36a3da39b | 244 | float Accel_Data[3]; // Accel Data from sensor |
nbaker | 7:3d5a8aea0b63 | 245 | float Accel_Data_Event[3]; // Accel Data from sensor at interupt |
nbaker | 10:eaea844e763c | 246 | float Fall_Event_Data[7]; // Fall event Data ff-value, ff-time, impact-value, 4byte timestamp |
jmr274 | 5:e1431272be79 | 247 | float Gyro_Mag=0.0; // Vector magnitude calculated from sensor data |
nbaker | 10:eaea844e763c | 248 | float Gyro_Data[3]; // Gyro data from sensor |
nbaker | 10:eaea844e763c | 249 | float Fall_Thresh=0.5; // Initialize Free-Fall detect Threshold as being <= 0.5g |
nbaker | 10:eaea844e763c | 250 | float Fall_Impact_Max_Wait_Time=2.0;// maximum wait time from end of fall detect to impact detect |
nbaker | 10:eaea844e763c | 251 | float Impact_Thresh=3.0; // Initialize Impact detect Threshold |
nbaker | 10:eaea844e763c | 252 | float Movement_Thresh=50.0; // Initialize Movement detect Threshold |
nbaker | 9:d2e39ee9fedd | 253 | float Min_Movement_Time=5.0; // Initialize Movement minimum movement time to 5 sec |
nbaker | 12:fd39a7983e06 | 254 | float Min_Movement_duration=10.0; // Initialize Movement min-movement testing duration to 60 sec |
nbaker | 10:eaea844e763c | 255 | float Do_You_Need_Help_Time=10.0; // Time to dismiss "Do you need Help" screen |
nbaker | 13:37cd579208e9 | 256 | uint8_t Reset_Count = 0; |
asong | 2:824ed4ae8d52 | 257 | uint8_t Current_Zone = 1; |
asong | 2:824ed4ae8d52 | 258 | uint8_t Prev_Zone = 1; |
asong | 15:330794a9f347 | 259 | uint8_t Heart_Rate = 0; |
asong | 22:3de592f8e696 | 260 | uint8_t rand_stage; |
asong | 1:e4b38d6918ba | 261 | uint8_t *HR_return; |
asong | 15:330794a9f347 | 262 | uint8_t Age = 25; // Initialize age |
asong | 2:824ed4ae8d52 | 263 | uint8_t Max_Bpm = 220 - Age; // Initialize Max BPM |
nbaker | 0:d1d36a3da39b | 264 | uint8_t Screen_Num = 0; // Initialize to main screen |
asong | 1:e4b38d6918ba | 265 | uint8_t Error_Num = 0; // Error num for debug |
asong | 2:824ed4ae8d52 | 266 | uint8_t HR_Vibration = 2; //Choose Heart Rate Vibration Options |
asong | 2:824ed4ae8d52 | 267 | uint8_t Target_Zone = 2; //Initialize Target Heart Rate Zone to Zone 3 |
asong | 2:824ed4ae8d52 | 268 | uint8_t HR_Zone1[2] = {Max_Bpm * .50, Max_Bpm * .60}; //Heart Rate Zone 1 |
asong | 2:824ed4ae8d52 | 269 | uint8_t HR_Zone2[2] = {HR_Zone1[1] + 1, Max_Bpm * .70}; //Heart Rate Zone 2 |
asong | 2:824ed4ae8d52 | 270 | uint8_t HR_Zone3[2] = {HR_Zone2[1] + 1, Max_Bpm * .80}; //Heart Rate Zone 3 |
asong | 2:824ed4ae8d52 | 271 | uint8_t HR_Zone4[2] = {HR_Zone3[1] + 1, Max_Bpm}; //Heart Rate Zone 4 |
asong | 15:330794a9f347 | 272 | uint8_t heat_index; // used in Heat index calc |
nbaker | 9:d2e39ee9fedd | 273 | int hi_calc; // used in Heat index calc |
nbaker | 9:d2e39ee9fedd | 274 | int adjustment; // used in Heat index calc |
nbaker | 16:537ef0c72084 | 275 | bool randomized = 0; //Initialize to 0, since srand has not been called |
nbaker | 16:537ef0c72084 | 276 | int simulation_stage = 0; |
nbaker | 16:537ef0c72084 | 277 | uint32_t hr_data[100]; |
nbaker | 13:37cd579208e9 | 278 | // slow changing variables |
nbaker | 13:37cd579208e9 | 279 | int sample_ftemp = 0; // used in Heat index calc |
nbaker | 13:37cd579208e9 | 280 | int sample_humid = 0; // used in Heat index calc |
nbaker | 13:37cd579208e9 | 281 | uint8_t batt_per_level = 0; // |
nbaker | 19:87ab6daf98e5 | 282 | float Ave_Num = 0.0; |
nbaker | 16:537ef0c72084 | 283 | |
nbaker | 16:537ef0c72084 | 284 | |
nbaker | 9:d2e39ee9fedd | 285 | // Pointers for screen images |
nbaker | 9:d2e39ee9fedd | 286 | const uint8_t *Hexi_Heart_ = Hexi_Heart_bmp; |
nbaker | 9:d2e39ee9fedd | 287 | //const uint8_t *NB_Linkedin = NB_Linkedin_bmp; |
nbaker | 9:d2e39ee9fedd | 288 | //const uint8_t *AS_Linkedin = NB_Linkedin_bmp; |
nbaker | 9:d2e39ee9fedd | 289 | //const uint8_t *IR_Linkedin = NB_Linkedin_bmp; |
nbaker | 9:d2e39ee9fedd | 290 | //const uint8_t *IH_Linkedin = NB_Linkedin_bmp; |
nbaker | 9:d2e39ee9fedd | 291 | |
jmr274 | 5:e1431272be79 | 292 | |
nbaker | 0:d1d36a3da39b | 293 | // ***************** Define pins ***************************** |
nbaker | 9:d2e39ee9fedd | 294 | //W25Q64FVSSIG - 8MB/64Mbit Serial Flash memory (SPI1)(MOSI,SCLK,POWER,CS,RST,DC) |
nbaker | 9:d2e39ee9fedd | 295 | //W25Q64FV(PinName mosi, PinName miso, PinName sclk, PinName cs, int frequency=10000000); |
nbaker | 9:d2e39ee9fedd | 296 | //MKW40Z (SPI1) |
nbaker | 9:d2e39ee9fedd | 297 | SSD1351 oled(PTB22,PTB21,PTC13,PTB20,PTE6, PTD15); // SSD1351 OLED Driver SPI2(MOSI,SCLK,POWER,CS,RST,DC) |
nbaker | 9:d2e39ee9fedd | 298 | FXAS21002 gyro(PTC11,PTC10); // Gyroscope (I2C1 data bus(SDA, SCL)) |
nbaker | 9:d2e39ee9fedd | 299 | FXOS8700 accel(PTC11, PTC10); // Accelorometer (I2C1 data bus(SDA, SCL)) |
nbaker | 9:d2e39ee9fedd | 300 | FXOS8700 mag(PTC11, PTC10); // Mag (same chip as Accel) (I2C1 data bus(SDA, SCL)) |
nbaker | 9:d2e39ee9fedd | 301 | //MAX30101 heart(PTB1, PTB0); //Heart Rate Chip (I2C0 data bus(SDA, SCL)) |
nbaker | 9:d2e39ee9fedd | 302 | HTU21D temphumid(PTB1,PTB0); // HTU21D Sensor (I2C0 data bus(SDA, SCL)) |
nbaker | 9:d2e39ee9fedd | 303 | //TSL2561 - (PTB1, PTB0); //Amb light sensor (I2C0 data bus(SDA, SCL)) |
nbaker | 0:d1d36a3da39b | 304 | |
nbaker | 4:0803151bc5e4 | 305 | // initialize I2C bus for FXOS8700, FXAS-Gyro, MPL-Pressure |
nbaker | 4:0803151bc5e4 | 306 | I2C i2c_bus1(PTC11, PTC10); // (SDA, SCL) |
nbaker | 9:d2e39ee9fedd | 307 | // initialize I2C bus for MAX30101, HTU21D, TSL2561 |
nbaker | 9:d2e39ee9fedd | 308 | I2C i2c_bus0(PTB1, PTB0); // (SDA, SCL) |
nbaker | 9:d2e39ee9fedd | 309 | |
nbaker | 9:d2e39ee9fedd | 310 | // initialize SPI bus for W25Q64FVSSIG, (and MKW40Z if needed) |
nbaker | 9:d2e39ee9fedd | 311 | // SPI spi_bus1(PTD6, PTD7, PTD5); // (MOSI, MISO, SCLK) CS=PTD4?(low=select) |
nbaker | 4:0803151bc5e4 | 312 | |
nbaker | 0:d1d36a3da39b | 313 | DigitalOut RED_Led(LED1); |
nbaker | 0:d1d36a3da39b | 314 | DigitalOut GRN_Led(LED2); |
nbaker | 0:d1d36a3da39b | 315 | DigitalOut BLU_Led(LED3); |
nbaker | 0:d1d36a3da39b | 316 | DigitalOut haptic(PTB9); |
nbaker | 4:0803151bc5e4 | 317 | DigitalOut Led_clk1(PTA12); |
nbaker | 4:0803151bc5e4 | 318 | DigitalOut Led_clk2(PTA13); |
nbaker | 4:0803151bc5e4 | 319 | DigitalOut Led_clk3(PTA14); |
nbaker | 4:0803151bc5e4 | 320 | |
nbaker | 9:d2e39ee9fedd | 321 | DigitalOut OLED_PWR(PTC13); // this pin turns on/off 15V supply to OLED display |
nbaker | 9:d2e39ee9fedd | 322 | DigitalOut PowerEN (PTB12); // 3V3B Power Enable for HTU21D (Temp/Hum sensor) and Light sensor Sensor supply |
asong | 14:c3b080cdf36b | 323 | DigitalOut maxim(PTA29); // this pin turns on/off power to heart rate sensor |
jmr274 | 5:e1431272be79 | 324 | //DigitalIn Sw1(PTA12); //Switch 'T1' on docking station AND Led_clk1!! |
jmr274 | 5:e1431272be79 | 325 | //DigitalIn Sw2(PTA13); //Switch 'T2' on docking station AND Led_clk2!! |
jmr274 | 5:e1431272be79 | 326 | DigitalIn Sw3(PTA15); //Switch 'T3' on docking station |
nbaker | 4:0803151bc5e4 | 327 | |
nbaker | 0:d1d36a3da39b | 328 | |
asong | 1:e4b38d6918ba | 329 | /* Instantiate the Hexi KW40Z Driver (UART TX, UART RX) */ |
nbaker | 0:d1d36a3da39b | 330 | KW40Z kw40z_device(PTE24, PTE25); |
nbaker | 0:d1d36a3da39b | 331 | |
nbaker | 0:d1d36a3da39b | 332 | /* Define timer for haptic feedback */ |
nbaker | 0:d1d36a3da39b | 333 | RtosTimer hapticTimer(StopHaptic, osTimerOnce); |
nbaker | 0:d1d36a3da39b | 334 | |
nbaker | 11:ccda4d44bd8e | 335 | /*Create a Thread to handle sending BLE Sensor Data */ |
nbaker | 11:ccda4d44bd8e | 336 | //Thread txThread; |
nbaker | 11:ccda4d44bd8e | 337 | |
nbaker | 4:0803151bc5e4 | 338 | //***************** Interrups ***************** |
nbaker | 9:d2e39ee9fedd | 339 | InterruptIn Accel_INT1(PTC1); // Accel sensor's interupt 1 |
nbaker | 9:d2e39ee9fedd | 340 | InterruptIn Accel_INT2(PTD13); // Accel sensor's interupt 2 |
nbaker | 9:d2e39ee9fedd | 341 | InterruptIn Gyro_INT1(PTD1); // Gyro sensor's interupt 1 |
nbaker | 9:d2e39ee9fedd | 342 | InterruptIn Gyro_INT2(PTC18); // Gyro sensor's interupt 2 |
nbaker | 9:d2e39ee9fedd | 343 | //InterruptIn Amb_Light_INT1(PTC0); // TSL2561- Light sensor's interupt |
nbaker | 9:d2e39ee9fedd | 344 | //InterruptIn HR_INT1(PTB18); // MAX30101 - Heart rate sensor's interupt |
nbaker | 9:d2e39ee9fedd | 345 | //InterruptIn Pressure_INT1(PTD12); // MPL3115A2 pressure sensor's interupt 1 |
nbaker | 9:d2e39ee9fedd | 346 | //InterruptIn Pressure_INT2(PTD10); // MPL3115A2 pressure sensor's interupt 2 |
nbaker | 4:0803151bc5e4 | 347 | |
nbaker | 0:d1d36a3da39b | 348 | //***************** Tickers and Timers ***************** |
nbaker | 0:d1d36a3da39b | 349 | Ticker Screen_Timer;// use ticker to turn off OLED |
nbaker | 13:37cd579208e9 | 350 | Timer f_time; // Timer used to measure fall |
nbaker | 13:37cd579208e9 | 351 | Ticker chk_fall; // Ticker used to check on active fall |
nbaker | 13:37cd579208e9 | 352 | Ticker chk_motion; // Ticker used to check on post fall motion |
nbaker | 10:eaea844e763c | 353 | Ticker Haptic_Timer; |
nbaker | 12:fd39a7983e06 | 354 | Ticker WDT_Timer; |
asong | 14:c3b080cdf36b | 355 | Ticker hr_led; |
asong | 14:c3b080cdf36b | 356 | Ticker hr_simulation; |
asong | 14:c3b080cdf36b | 357 | Ticker hr_ticker; |
asong | 14:c3b080cdf36b | 358 | Ticker hr_measure_ticker; |
nbaker | 12:fd39a7983e06 | 359 | |
nbaker | 19:87ab6daf98e5 | 360 | |
nbaker | 19:87ab6daf98e5 | 361 | |
nbaker | 19:87ab6daf98e5 | 362 | |
nbaker | 12:fd39a7983e06 | 363 | /***************************************************************************** |
nbaker | 12:fd39a7983e06 | 364 | Name: timout_timer() |
nbaker | 13:37cd579208e9 | 365 | Purpose: Ticker interupt routine used to dim the OLED screen 3s before turning screen off |
nbaker | 13:37cd579208e9 | 366 | Inputs: Screen_Timer Ticker |
nbaker | 12:fd39a7983e06 | 367 | ******************************************************************************/ |
nbaker | 4:0803151bc5e4 | 368 | void timout_timer(){ // turn off display mode |
nbaker | 13:37cd579208e9 | 369 | HexiwearBattery battery; |
nbaker | 13:37cd579208e9 | 370 | battery.sensorOn(); |
nbaker | 16:537ef0c72084 | 371 | if (battery.isBatteryCharging() || (uint8_t)battery.readLevelPercent() > 99) { |
nbaker | 13:37cd579208e9 | 372 | oled.DimScreenOFF(); |
nbaker | 13:37cd579208e9 | 373 | Screen_Timer.attach(&timout_timer,(SCRN_TIME));// Reset/restart ticker timer for OLED while fully charged |
nbaker | 13:37cd579208e9 | 374 | } //end if |
nbaker | 13:37cd579208e9 | 375 | else { |
nbaker | 13:37cd579208e9 | 376 | Screen_Timer.attach(&Screen_timer1,(3));// Dim display for 3 seconds befor turning off display |
nbaker | 13:37cd579208e9 | 377 | oled.DimScreenON(); //Dim display if 3 seconds from turning off |
nbaker | 13:37cd579208e9 | 378 | }//end else |
nbaker | 13:37cd579208e9 | 379 | }// end Screen_timer1() |
nbaker | 13:37cd579208e9 | 380 | |
nbaker | 13:37cd579208e9 | 381 | /***************************************************************************** |
nbaker | 13:37cd579208e9 | 382 | Name: Screen_timer1(() |
nbaker | 13:37cd579208e9 | 383 | Purpose: Ticker interupt routine used to turn off the OLED screen after ~13s to save power |
nbaker | 13:37cd579208e9 | 384 | Inputs: Screen_Timer Ticker |
nbaker | 13:37cd579208e9 | 385 | ******************************************************************************/ |
nbaker | 13:37cd579208e9 | 386 | void Screen_timer1(){ // turn off display mode |
nbaker | 9:d2e39ee9fedd | 387 | #ifdef Debug // in debug keep screens on for demo |
nbaker | 9:d2e39ee9fedd | 388 | HexiwearBattery battery; |
nbaker | 9:d2e39ee9fedd | 389 | battery.sensorOn(); |
nbaker | 9:d2e39ee9fedd | 390 | |
nbaker | 13:37cd579208e9 | 391 | if (battery.isBatteryCharging() || batt_per_level > 99) { |
nbaker | 9:d2e39ee9fedd | 392 | Screen_Timer.attach(&timout_timer,(SCRN_TIME));// Reset/restart ticker timer for OLED while fully charged |
nbaker | 13:37cd579208e9 | 393 | oled.DimScreenOFF(); |
nbaker | 9:d2e39ee9fedd | 394 | } //end if |
nbaker | 9:d2e39ee9fedd | 395 | else { |
nbaker | 9:d2e39ee9fedd | 396 | #endif |
nbaker | 11:ccda4d44bd8e | 397 | /* Turn on the backlight of the OLED Display */ |
nbaker | 11:ccda4d44bd8e | 398 | //oled.DimScreenON(); just dim display for debug |
nbaker | 4:0803151bc5e4 | 399 | OLED_PWR = 0; // Turn off OLED power supply |
nbaker | 4:0803151bc5e4 | 400 | OLED_ON = 0; // set flag to off |
nbaker | 4:0803151bc5e4 | 401 | Screen_Timer.detach(); // detach Ticker |
nbaker | 9:d2e39ee9fedd | 402 | #ifdef Debug // in debug keep screens on for demo |
nbaker | 9:d2e39ee9fedd | 403 | } // endelse |
nbaker | 9:d2e39ee9fedd | 404 | #endif |
nbaker | 12:fd39a7983e06 | 405 | }//end timout_timer routine |
asong | 1:e4b38d6918ba | 406 | |
nbaker | 11:ccda4d44bd8e | 407 | |
nbaker | 12:fd39a7983e06 | 408 | /***************************************************************************** |
nbaker | 12:fd39a7983e06 | 409 | Name: ButtonUp() |
nbaker | 12:fd39a7983e06 | 410 | Purpose: Routine called when MK46 recieves a ButtonUP interrupt from KW40 |
nbaker | 12:fd39a7983e06 | 411 | Inputs: Uses global Screen_Num value and other status varibles |
nbaker | 12:fd39a7983e06 | 412 | Returns: None |
nbaker | 12:fd39a7983e06 | 413 | ******************************************************************************/ |
nbaker | 0:d1d36a3da39b | 414 | void ButtonUp(void) |
nbaker | 0:d1d36a3da39b | 415 | { |
asong | 1:e4b38d6918ba | 416 | Screen_Timer.attach(&timout_timer,(SCRN_TIME));//Is this sufficient to reset/restart ticker timer for OLED? |
nbaker | 13:37cd579208e9 | 417 | oled.DimScreenOFF(); |
asong | 1:e4b38d6918ba | 418 | if (OLED_ON == 0) { |
asong | 1:e4b38d6918ba | 419 | OLED_ON = 1; // Scree was off, set to On |
asong | 1:e4b38d6918ba | 420 | update_display(); |
asong | 1:e4b38d6918ba | 421 | } else { |
asong | 1:e4b38d6918ba | 422 | switch(Screen_Num) { |
asong | 1:e4b38d6918ba | 423 | case 0: {// We're in Main Screen |
asong | 1:e4b38d6918ba | 424 | // do nothing, wrong button |
asong | 1:e4b38d6918ba | 425 | break; |
asong | 1:e4b38d6918ba | 426 | } |
asong | 1:e4b38d6918ba | 427 | case 1: {// Panic Alert option |
asong | 1:e4b38d6918ba | 428 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 429 | Screen_Num = 5; //Change to screen 5 |
nbaker | 0:d1d36a3da39b | 430 | #ifdef Debug // in debug show debug/diagnostic screens |
asong | 1:e4b38d6918ba | 431 | Screen_Num = 26; //Change to screen 20 |
nbaker | 0:d1d36a3da39b | 432 | #endif |
nbaker | 0:d1d36a3da39b | 433 | |
asong | 1:e4b38d6918ba | 434 | update_display(); |
asong | 1:e4b38d6918ba | 435 | break; |
asong | 1:e4b38d6918ba | 436 | } |
asong | 1:e4b38d6918ba | 437 | case 2: {// Fall Alert option |
asong | 1:e4b38d6918ba | 438 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 439 | Screen_Num = 71; //Change to screen 71 |
asong | 1:e4b38d6918ba | 440 | update_display(); |
asong | 1:e4b38d6918ba | 441 | break; |
asong | 1:e4b38d6918ba | 442 | } |
asong | 1:e4b38d6918ba | 443 | case 3: {// Heart Rate Monitoring option |
asong | 1:e4b38d6918ba | 444 | StartHaptic(); |
asong | 1:e4b38d6918ba | 445 | Screen_Num = 2; //Change to screen 2 |
asong | 1:e4b38d6918ba | 446 | update_display(); |
asong | 1:e4b38d6918ba | 447 | break; |
asong | 1:e4b38d6918ba | 448 | } |
asong | 1:e4b38d6918ba | 449 | case 4: {// Alert History option |
asong | 1:e4b38d6918ba | 450 | StartHaptic(); |
asong | 1:e4b38d6918ba | 451 | Screen_Num = 3; //Change to screen 3 |
asong | 1:e4b38d6918ba | 452 | update_display(); |
asong | 1:e4b38d6918ba | 453 | break; |
asong | 1:e4b38d6918ba | 454 | } |
asong | 1:e4b38d6918ba | 455 | case 5: {// About HexiHeart |
asong | 1:e4b38d6918ba | 456 | StartHaptic(); |
nbaker | 12:fd39a7983e06 | 457 | Screen_Num = 3; //Change to screen 3, skip 4 |
asong | 1:e4b38d6918ba | 458 | update_display(); |
asong | 1:e4b38d6918ba | 459 | break; |
asong | 1:e4b38d6918ba | 460 | } |
asong | 1:e4b38d6918ba | 461 | case 6: {// Panic Alert |
asong | 1:e4b38d6918ba | 462 | StartHaptic(); |
nbaker | 13:37cd579208e9 | 463 | Screen_Num = 51; |
nbaker | 13:37cd579208e9 | 464 | Panic_Alert = 1; |
nbaker | 11:ccda4d44bd8e | 465 | Send_Alert(10); // send/store alert type zero |
asong | 1:e4b38d6918ba | 466 | update_display(); |
asong | 1:e4b38d6918ba | 467 | break; |
asong | 1:e4b38d6918ba | 468 | } |
asong | 1:e4b38d6918ba | 469 | case 7: {// Heart Rate Zone |
asong | 14:c3b080cdf36b | 470 | StartHaptic(); |
asong | 14:c3b080cdf36b | 471 | maxInit(); |
asong | 14:c3b080cdf36b | 472 | maxEnable(); |
nbaker | 16:537ef0c72084 | 473 | hr_led.attach(&Led_Zone_Indicator, HR_LED_period); // blink every second |
nbaker | 16:537ef0c72084 | 474 | hr_ticker.attach(&processHeartRate, 5); |
asong | 1:e4b38d6918ba | 475 | break; |
asong | 1:e4b38d6918ba | 476 | } |
asong | 1:e4b38d6918ba | 477 | case 8: {// Alert History |
asong | 1:e4b38d6918ba | 478 | StartHaptic(); |
asong | 1:e4b38d6918ba | 479 | //Increment alert index |
asong | 1:e4b38d6918ba | 480 | break; |
asong | 1:e4b38d6918ba | 481 | } |
nbaker | 8:a5c77b45008d | 482 | case 9: {// HexiHeart About info1 |
nbaker | 8:a5c77b45008d | 483 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 484 | Screen_Num = 11; //Change to screen 11 |
nbaker | 8:a5c77b45008d | 485 | update_display(); |
nbaker | 8:a5c77b45008d | 486 | break; |
nbaker | 8:a5c77b45008d | 487 | } |
nbaker | 8:a5c77b45008d | 488 | case 10: {// HexiHeart About info2 |
nbaker | 8:a5c77b45008d | 489 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 490 | Screen_Num = 9; //Change to screen 9 |
nbaker | 8:a5c77b45008d | 491 | update_display(); |
nbaker | 8:a5c77b45008d | 492 | break; |
nbaker | 8:a5c77b45008d | 493 | } |
nbaker | 8:a5c77b45008d | 494 | case 11: {// HexiHeart About info3 |
nbaker | 8:a5c77b45008d | 495 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 496 | Screen_Num = 10; //Change to screen 9 |
nbaker | 8:a5c77b45008d | 497 | update_display(); |
nbaker | 8:a5c77b45008d | 498 | break; |
nbaker | 8:a5c77b45008d | 499 | } |
asong | 1:e4b38d6918ba | 500 | case 20: {// Diagnostic/Debug Screens |
asong | 1:e4b38d6918ba | 501 | StartHaptic(); |
asong | 1:e4b38d6918ba | 502 | Screen_Num = 5; //Change to screen 5 |
asong | 1:e4b38d6918ba | 503 | update_display(); |
asong | 1:e4b38d6918ba | 504 | break; |
asong | 1:e4b38d6918ba | 505 | } |
asong | 1:e4b38d6918ba | 506 | case 21: {// Fall Diagnostic |
asong | 1:e4b38d6918ba | 507 | StartHaptic(); |
nbaker | 12:fd39a7983e06 | 508 | Screen_Num = 49; //Change to screen 49 |
asong | 1:e4b38d6918ba | 509 | update_display(); |
asong | 1:e4b38d6918ba | 510 | break; |
asong | 1:e4b38d6918ba | 511 | } |
asong | 1:e4b38d6918ba | 512 | case 22: {// Fall Debug |
asong | 1:e4b38d6918ba | 513 | StartHaptic(); |
asong | 1:e4b38d6918ba | 514 | Screen_Num = 21; //Change to screen 21 |
asong | 1:e4b38d6918ba | 515 | update_display(); |
asong | 1:e4b38d6918ba | 516 | break; |
asong | 1:e4b38d6918ba | 517 | } |
nbaker | 19:87ab6daf98e5 | 518 | case 23: {// Heart Rate Diagnostic - not used |
asong | 1:e4b38d6918ba | 519 | StartHaptic(); |
asong | 1:e4b38d6918ba | 520 | Screen_Num = 22; //Change to screen 22 |
asong | 1:e4b38d6918ba | 521 | update_display(); |
asong | 1:e4b38d6918ba | 522 | break; |
asong | 1:e4b38d6918ba | 523 | } |
nbaker | 19:87ab6daf98e5 | 524 | case 24: {// Heart Rate Debug - not used |
asong | 1:e4b38d6918ba | 525 | StartHaptic(); |
asong | 1:e4b38d6918ba | 526 | Screen_Num = 23; //Change to screen 23 |
asong | 1:e4b38d6918ba | 527 | update_display(); |
asong | 1:e4b38d6918ba | 528 | break; |
asong | 1:e4b38d6918ba | 529 | } |
asong | 1:e4b38d6918ba | 530 | case 25: {// Heat Index Diagnostic |
asong | 1:e4b38d6918ba | 531 | StartHaptic(); |
nbaker | 19:87ab6daf98e5 | 532 | Screen_Num = 21; //Change to screen 24 |
asong | 1:e4b38d6918ba | 533 | update_display(); |
asong | 1:e4b38d6918ba | 534 | break; |
asong | 1:e4b38d6918ba | 535 | } |
asong | 1:e4b38d6918ba | 536 | case 26: {//Heart Rate Config Option |
asong | 1:e4b38d6918ba | 537 | StartHaptic(); |
asong | 1:e4b38d6918ba | 538 | Screen_Num = 20; |
asong | 1:e4b38d6918ba | 539 | update_display(); |
asong | 1:e4b38d6918ba | 540 | break; |
asong | 1:e4b38d6918ba | 541 | } |
asong | 1:e4b38d6918ba | 542 | case 27: {//Incrementing Age |
asong | 2:824ed4ae8d52 | 543 | Increment_Age(); |
asong | 2:824ed4ae8d52 | 544 | Set_Zone_Boundaries(); |
asong | 1:e4b38d6918ba | 545 | update_display(); |
asong | 1:e4b38d6918ba | 546 | break; |
asong | 1:e4b38d6918ba | 547 | } |
asong | 1:e4b38d6918ba | 548 | case 28: {//Changing Heart Rate Vibration Preferences |
asong | 2:824ed4ae8d52 | 549 | Increment_HR_Vibr_Pref(); |
asong | 1:e4b38d6918ba | 550 | update_display(); |
asong | 1:e4b38d6918ba | 551 | break; |
asong | 1:e4b38d6918ba | 552 | } |
asong | 1:e4b38d6918ba | 553 | case 30: {//Change Target Heart Rate Zone Preference |
asong | 2:824ed4ae8d52 | 554 | Increment_Target_Zone(); |
asong | 2:824ed4ae8d52 | 555 | update_display(); |
asong | 2:824ed4ae8d52 | 556 | break; |
asong | 2:824ed4ae8d52 | 557 | } |
asong | 2:824ed4ae8d52 | 558 | case 31: { //Manually Increment Heart Rate by 1 |
asong | 14:c3b080cdf36b | 559 | //StartHaptic(); |
asong | 14:c3b080cdf36b | 560 | if(maxim == 0) |
asong | 14:c3b080cdf36b | 561 | { |
asong | 14:c3b080cdf36b | 562 | Increment_Heart_Rate(); |
asong | 14:c3b080cdf36b | 563 | // Determine_Current_Zone(); |
asong | 14:c3b080cdf36b | 564 | update_display(); |
asong | 14:c3b080cdf36b | 565 | } |
asong | 14:c3b080cdf36b | 566 | break; |
asong | 14:c3b080cdf36b | 567 | } |
asong | 14:c3b080cdf36b | 568 | case 32: {//Turn on HR led blinking for manual demonstration |
nbaker | 16:537ef0c72084 | 569 | hr_led.attach(&Led_Zone_Indicator, HR_LED_period); |
asong | 20:990951205fbd | 570 | Heart_Rate_Mode = 1; |
asong | 20:990951205fbd | 571 | break; |
asong | 14:c3b080cdf36b | 572 | } |
asong | 14:c3b080cdf36b | 573 | case 33:{//Start heart rate simulation |
asong | 14:c3b080cdf36b | 574 | StartHaptic(); |
asong | 14:c3b080cdf36b | 575 | if(maxim == 0) |
asong | 14:c3b080cdf36b | 576 | { |
asong | 22:3de592f8e696 | 577 | simulation_stage = 0; |
asong | 20:990951205fbd | 578 | Heart_Rate_Mode = 1; |
nbaker | 16:537ef0c72084 | 579 | hr_led.attach(&Led_Zone_Indicator, HR_LED_period); |
asong | 14:c3b080cdf36b | 580 | hr_simulation.attach(&HR_Simulation, 5.0); |
asong | 14:c3b080cdf36b | 581 | } |
asong | 1:e4b38d6918ba | 582 | update_display(); |
asong | 1:e4b38d6918ba | 583 | break; |
asong | 1:e4b38d6918ba | 584 | } |
nbaker | 8:a5c77b45008d | 585 | |
nbaker | 10:eaea844e763c | 586 | case 41: {//Fall mode 0,1,2,3,4,5 |
nbaker | 10:eaea844e763c | 587 | // 0=nothing, 1=fall_only, 2=impact only, 3=motion_only, 4=all, 5=main sequence |
nbaker | 8:a5c77b45008d | 588 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 589 | Fall_Alert_Mode++; |
nbaker | 10:eaea844e763c | 590 | if(Fall_Alert_Mode > 5){ |
nbaker | 8:a5c77b45008d | 591 | Fall_Alert_Mode = 0; |
nbaker | 8:a5c77b45008d | 592 | }//endif |
nbaker | 8:a5c77b45008d | 593 | update_display(); |
nbaker | 8:a5c77b45008d | 594 | __disable_irq(); // Disable all Interrupts |
nbaker | 9:d2e39ee9fedd | 595 | fall_config(10); // reset accel sensor |
nbaker | 10:eaea844e763c | 596 | //gyro_sensor_config(10); // reset gyro sensor |
nbaker | 8:a5c77b45008d | 597 | wait(0.1); |
nbaker | 10:eaea844e763c | 598 | //gyro_sensor_config(Fall_Alert_Mode); // leave gyro sensor active |
nbaker | 8:a5c77b45008d | 599 | fall_config(Fall_Alert_Mode); |
nbaker | 8:a5c77b45008d | 600 | wait(0.1); |
nbaker | 8:a5c77b45008d | 601 | __enable_irq(); // Enable all Interrupts |
nbaker | 8:a5c77b45008d | 602 | wait(0.3); |
nbaker | 8:a5c77b45008d | 603 | update_display(); |
nbaker | 8:a5c77b45008d | 604 | break; |
nbaker | 8:a5c77b45008d | 605 | } |
nbaker | 8:a5c77b45008d | 606 | case 42: {// F-Th adj |
nbaker | 8:a5c77b45008d | 607 | StartHaptic(); |
nbaker | 9:d2e39ee9fedd | 608 | Fall_Thresh = Fall_Thresh + 0.05f; |
nbaker | 9:d2e39ee9fedd | 609 | if(Fall_Thresh > 0.9f){ |
nbaker | 8:a5c77b45008d | 610 | Fall_Thresh = 0.9; |
nbaker | 8:a5c77b45008d | 611 | }//endif |
nbaker | 8:a5c77b45008d | 612 | update_display(); |
nbaker | 8:a5c77b45008d | 613 | break; |
nbaker | 8:a5c77b45008d | 614 | } |
nbaker | 8:a5c77b45008d | 615 | case 43: {// I-Th adj |
nbaker | 8:a5c77b45008d | 616 | StartHaptic(); |
nbaker | 9:d2e39ee9fedd | 617 | Impact_Thresh = Impact_Thresh + 0.1f; |
nbaker | 9:d2e39ee9fedd | 618 | if(Impact_Thresh > 3.9f){ |
nbaker | 8:a5c77b45008d | 619 | Impact_Thresh = 3.9; |
nbaker | 8:a5c77b45008d | 620 | }//endif |
nbaker | 8:a5c77b45008d | 621 | update_display(); |
nbaker | 8:a5c77b45008d | 622 | break; |
nbaker | 8:a5c77b45008d | 623 | } |
nbaker | 8:a5c77b45008d | 624 | case 44: {// M-Th adj |
nbaker | 8:a5c77b45008d | 625 | StartHaptic(); |
nbaker | 9:d2e39ee9fedd | 626 | Movement_Thresh = Movement_Thresh + 5.0f; |
nbaker | 9:d2e39ee9fedd | 627 | if(Movement_Thresh > 300.0f){ |
nbaker | 8:a5c77b45008d | 628 | Movement_Thresh = 300.0; |
nbaker | 8:a5c77b45008d | 629 | }//endif |
nbaker | 8:a5c77b45008d | 630 | update_display(); |
nbaker | 8:a5c77b45008d | 631 | break; |
nbaker | 8:a5c77b45008d | 632 | } |
nbaker | 9:d2e39ee9fedd | 633 | case 45: {// Min_Movement_Time adj |
nbaker | 9:d2e39ee9fedd | 634 | StartHaptic(); |
nbaker | 9:d2e39ee9fedd | 635 | Min_Movement_Time = Min_Movement_Time + 0.1f; |
nbaker | 9:d2e39ee9fedd | 636 | if(Min_Movement_Time > 2.4f){ |
nbaker | 9:d2e39ee9fedd | 637 | Min_Movement_Time = 2.4; |
nbaker | 9:d2e39ee9fedd | 638 | }//endif |
nbaker | 9:d2e39ee9fedd | 639 | update_display(); |
nbaker | 9:d2e39ee9fedd | 640 | break; |
nbaker | 9:d2e39ee9fedd | 641 | } |
nbaker | 9:d2e39ee9fedd | 642 | case 46: {// Min_Movement_duration adj |
nbaker | 9:d2e39ee9fedd | 643 | StartHaptic(); |
nbaker | 9:d2e39ee9fedd | 644 | Min_Movement_duration = Min_Movement_duration + 5.0f; |
nbaker | 9:d2e39ee9fedd | 645 | if(Min_Movement_duration > 300.0f){ |
nbaker | 9:d2e39ee9fedd | 646 | Min_Movement_duration = 300.0; |
nbaker | 9:d2e39ee9fedd | 647 | }//endif |
nbaker | 9:d2e39ee9fedd | 648 | update_display(); |
nbaker | 9:d2e39ee9fedd | 649 | break; |
nbaker | 9:d2e39ee9fedd | 650 | } |
nbaker | 12:fd39a7983e06 | 651 | case 49: {// WDT debug test screen |
nbaker | 12:fd39a7983e06 | 652 | StartHaptic(); |
nbaker | 12:fd39a7983e06 | 653 | Screen_Num = 25; //Change to screen 25 |
nbaker | 12:fd39a7983e06 | 654 | update_display(); |
nbaker | 12:fd39a7983e06 | 655 | break; |
nbaker | 12:fd39a7983e06 | 656 | } |
nbaker | 8:a5c77b45008d | 657 | case 71: {// BLE |
nbaker | 8:a5c77b45008d | 658 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 659 | Screen_Num = 1; //Change to screen 1 |
nbaker | 8:a5c77b45008d | 660 | update_display(); |
nbaker | 8:a5c77b45008d | 661 | break; |
nbaker | 8:a5c77b45008d | 662 | } |
nbaker | 8:a5c77b45008d | 663 | case 72: {// BlueTooth on/off |
nbaker | 8:a5c77b45008d | 664 | // do nothing, wrong button or change to another screen number if you're making more BLE type screens |
nbaker | 8:a5c77b45008d | 665 | break; |
nbaker | 8:a5c77b45008d | 666 | } |
asong | 1:e4b38d6918ba | 667 | default: { |
asong | 1:e4b38d6918ba | 668 | break; |
asong | 1:e4b38d6918ba | 669 | } |
nbaker | 12:fd39a7983e06 | 670 | }// end case switch |
nbaker | 12:fd39a7983e06 | 671 | }// end if |
nbaker | 12:fd39a7983e06 | 672 | }// end ButtonUp |
nbaker | 12:fd39a7983e06 | 673 | |
asong | 1:e4b38d6918ba | 674 | |
nbaker | 12:fd39a7983e06 | 675 | /***************************************************************************** |
nbaker | 12:fd39a7983e06 | 676 | Name: ButtonDown() |
nbaker | 12:fd39a7983e06 | 677 | Purpose: Routine called when MK46 recieves a ButtonDown interrupt from KW40 |
nbaker | 12:fd39a7983e06 | 678 | Inputs: Uses global Screen_Num value and other status varibles |
nbaker | 12:fd39a7983e06 | 679 | Returns: None |
nbaker | 12:fd39a7983e06 | 680 | ******************************************************************************/ |
nbaker | 0:d1d36a3da39b | 681 | void ButtonDown(void) |
nbaker | 0:d1d36a3da39b | 682 | { |
asong | 1:e4b38d6918ba | 683 | Screen_Timer.attach(&timout_timer,(SCRN_TIME));//Is this sufficient to reset/restart ticker timer for OLED? |
nbaker | 13:37cd579208e9 | 684 | oled.DimScreenOFF(); |
asong | 1:e4b38d6918ba | 685 | if (OLED_ON == 0) { |
asong | 1:e4b38d6918ba | 686 | OLED_ON = 1; // Screen was off, set to On |
asong | 1:e4b38d6918ba | 687 | update_display(); |
asong | 1:e4b38d6918ba | 688 | } else { |
nbaker | 0:d1d36a3da39b | 689 | |
asong | 1:e4b38d6918ba | 690 | switch(Screen_Num) { |
asong | 1:e4b38d6918ba | 691 | case 0: {// We're in Main Screen |
asong | 1:e4b38d6918ba | 692 | // do nothing, wrong button |
asong | 1:e4b38d6918ba | 693 | break; |
asong | 1:e4b38d6918ba | 694 | } |
asong | 1:e4b38d6918ba | 695 | case 1: {// Panic Alert option |
asong | 1:e4b38d6918ba | 696 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 697 | Screen_Num = 71; //Change to screen 71 |
asong | 1:e4b38d6918ba | 698 | update_display(); |
asong | 1:e4b38d6918ba | 699 | break; |
asong | 1:e4b38d6918ba | 700 | } |
asong | 1:e4b38d6918ba | 701 | case 2: {// Fall Alert option |
asong | 1:e4b38d6918ba | 702 | StartHaptic(); |
asong | 1:e4b38d6918ba | 703 | Screen_Num = 3; //Change to screen 3 |
asong | 1:e4b38d6918ba | 704 | update_display(); |
asong | 1:e4b38d6918ba | 705 | break; |
asong | 1:e4b38d6918ba | 706 | } |
asong | 1:e4b38d6918ba | 707 | case 3: {// Heart Rate Monitoring option |
asong | 1:e4b38d6918ba | 708 | StartHaptic(); |
nbaker | 12:fd39a7983e06 | 709 | Screen_Num = 5; //Change to screen 5, skip 4 |
asong | 1:e4b38d6918ba | 710 | update_display(); |
asong | 1:e4b38d6918ba | 711 | break; |
asong | 1:e4b38d6918ba | 712 | } |
asong | 1:e4b38d6918ba | 713 | case 4: {// Alert History option |
asong | 1:e4b38d6918ba | 714 | StartHaptic(); |
asong | 1:e4b38d6918ba | 715 | Screen_Num = 5; //Change to screen 5 |
asong | 1:e4b38d6918ba | 716 | update_display(); |
asong | 1:e4b38d6918ba | 717 | break; |
asong | 1:e4b38d6918ba | 718 | } |
asong | 1:e4b38d6918ba | 719 | case 5: {// About HexiHeart option |
asong | 1:e4b38d6918ba | 720 | StartHaptic(); |
asong | 1:e4b38d6918ba | 721 | Screen_Num = 26; //Change to screen 1 |
nbaker | 0:d1d36a3da39b | 722 | #ifdef Debug // in debug show debug/diagnostic screens |
asong | 1:e4b38d6918ba | 723 | Screen_Num = 20; //Change to screen 20 |
nbaker | 0:d1d36a3da39b | 724 | #endif |
asong | 1:e4b38d6918ba | 725 | update_display(); |
asong | 1:e4b38d6918ba | 726 | break; |
asong | 1:e4b38d6918ba | 727 | } |
asong | 1:e4b38d6918ba | 728 | case 6: {// Panic Alert |
asong | 1:e4b38d6918ba | 729 | // do nothing, wrong button |
asong | 1:e4b38d6918ba | 730 | break; |
asong | 1:e4b38d6918ba | 731 | } |
asong | 1:e4b38d6918ba | 732 | case 7: {// Heart Rate Zone |
asong | 14:c3b080cdf36b | 733 | StartHaptic(); |
asong | 14:c3b080cdf36b | 734 | maxDeinit(); |
asong | 1:e4b38d6918ba | 735 | break; |
asong | 1:e4b38d6918ba | 736 | } |
asong | 1:e4b38d6918ba | 737 | case 8: {// Alert History |
asong | 1:e4b38d6918ba | 738 | StartHaptic(); |
asong | 1:e4b38d6918ba | 739 | //decriment alert index |
asong | 1:e4b38d6918ba | 740 | break; |
asong | 1:e4b38d6918ba | 741 | } |
nbaker | 8:a5c77b45008d | 742 | case 9: {// HexiHeart About info1 |
nbaker | 8:a5c77b45008d | 743 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 744 | Screen_Num = 10; //Change to screen 10 |
nbaker | 8:a5c77b45008d | 745 | update_display(); |
nbaker | 8:a5c77b45008d | 746 | break; |
nbaker | 8:a5c77b45008d | 747 | } |
nbaker | 8:a5c77b45008d | 748 | case 10: {// HexiHeart About info2 |
nbaker | 8:a5c77b45008d | 749 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 750 | Screen_Num = 11; //Change to screen 11 |
nbaker | 8:a5c77b45008d | 751 | update_display(); |
nbaker | 8:a5c77b45008d | 752 | break; |
nbaker | 8:a5c77b45008d | 753 | } |
nbaker | 8:a5c77b45008d | 754 | case 11: {// HexiHeart About info3 |
nbaker | 8:a5c77b45008d | 755 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 756 | Screen_Num = 9; //Change to screen 9 |
nbaker | 8:a5c77b45008d | 757 | update_display(); |
nbaker | 8:a5c77b45008d | 758 | break; |
nbaker | 8:a5c77b45008d | 759 | } |
asong | 1:e4b38d6918ba | 760 | case 20: {// Diagnostic/Debug Screens |
asong | 1:e4b38d6918ba | 761 | StartHaptic(); |
asong | 1:e4b38d6918ba | 762 | Screen_Num = 26; //Change to screen 1 |
asong | 1:e4b38d6918ba | 763 | update_display(); |
asong | 1:e4b38d6918ba | 764 | break; |
asong | 1:e4b38d6918ba | 765 | } |
asong | 1:e4b38d6918ba | 766 | case 21: {// Fall Diagnostic |
asong | 1:e4b38d6918ba | 767 | StartHaptic(); |
asong | 1:e4b38d6918ba | 768 | Screen_Num = 22; //Change to screen 22 |
asong | 1:e4b38d6918ba | 769 | update_display(); |
asong | 1:e4b38d6918ba | 770 | break; |
asong | 1:e4b38d6918ba | 771 | } |
asong | 1:e4b38d6918ba | 772 | case 22: {// Fall Debug |
asong | 1:e4b38d6918ba | 773 | StartHaptic(); |
nbaker | 19:87ab6daf98e5 | 774 | Screen_Num = 25; //Change to screen 23 |
asong | 1:e4b38d6918ba | 775 | update_display(); |
asong | 1:e4b38d6918ba | 776 | break; |
asong | 1:e4b38d6918ba | 777 | } |
nbaker | 19:87ab6daf98e5 | 778 | case 23: {// Heart Rate Diagnostic - not used |
asong | 1:e4b38d6918ba | 779 | StartHaptic(); |
asong | 1:e4b38d6918ba | 780 | Screen_Num = 24; //Change to screen 24 |
asong | 1:e4b38d6918ba | 781 | update_display(); |
asong | 1:e4b38d6918ba | 782 | break; |
asong | 1:e4b38d6918ba | 783 | } |
nbaker | 19:87ab6daf98e5 | 784 | case 24: {// Heart Rate Debug - not used |
asong | 1:e4b38d6918ba | 785 | StartHaptic(); |
asong | 1:e4b38d6918ba | 786 | Screen_Num = 25; //Change to screen 25 |
asong | 1:e4b38d6918ba | 787 | update_display(); |
asong | 1:e4b38d6918ba | 788 | break; |
asong | 1:e4b38d6918ba | 789 | } |
asong | 1:e4b38d6918ba | 790 | case 25: {// Heat Index Diagnostic |
asong | 1:e4b38d6918ba | 791 | StartHaptic(); |
nbaker | 12:fd39a7983e06 | 792 | Screen_Num = 49; //Change to screen 49 |
asong | 1:e4b38d6918ba | 793 | update_display(); |
asong | 1:e4b38d6918ba | 794 | break; |
asong | 1:e4b38d6918ba | 795 | } |
asong | 1:e4b38d6918ba | 796 | case 26: {//Heart Rate Configs |
asong | 1:e4b38d6918ba | 797 | StartHaptic(); |
asong | 1:e4b38d6918ba | 798 | Screen_Num = 1; |
asong | 1:e4b38d6918ba | 799 | update_display(); |
asong | 1:e4b38d6918ba | 800 | break; |
asong | 1:e4b38d6918ba | 801 | } |
asong | 1:e4b38d6918ba | 802 | case 27: { //Decrement Age |
asong | 2:824ed4ae8d52 | 803 | Decrement_Age(); |
asong | 2:824ed4ae8d52 | 804 | Set_Zone_Boundaries(); |
asong | 1:e4b38d6918ba | 805 | update_display(); |
asong | 1:e4b38d6918ba | 806 | break; |
asong | 1:e4b38d6918ba | 807 | |
asong | 1:e4b38d6918ba | 808 | } |
asong | 1:e4b38d6918ba | 809 | case 28: { //Changing Heart Rate Vibration Preference |
asong | 2:824ed4ae8d52 | 810 | /* |
asong | 2:824ed4ae8d52 | 811 | StartHaptic(); |
asong | 2:824ed4ae8d52 | 812 | if(HR_Vibration == 1) { |
asong | 2:824ed4ae8d52 | 813 | HR_Vibration = 3; |
asong | 2:824ed4ae8d52 | 814 | } else { |
asong | 2:824ed4ae8d52 | 815 | HR_Vibration -= 1; |
asong | 2:824ed4ae8d52 | 816 | } |
asong | 2:824ed4ae8d52 | 817 | */ |
asong | 2:824ed4ae8d52 | 818 | Decrement_HR_Vibr_Pref(); |
asong | 1:e4b38d6918ba | 819 | update_display(); |
asong | 1:e4b38d6918ba | 820 | break; |
asong | 1:e4b38d6918ba | 821 | } |
asong | 1:e4b38d6918ba | 822 | case 30: {//Change Target Heart Rate Zone Preference |
asong | 2:824ed4ae8d52 | 823 | Decrement_Target_Zone(); |
asong | 2:824ed4ae8d52 | 824 | update_display(); |
asong | 2:824ed4ae8d52 | 825 | break; |
asong | 2:824ed4ae8d52 | 826 | } |
asong | 2:824ed4ae8d52 | 827 | case 31: { //Manually decrement heart rate by 1 |
asong | 14:c3b080cdf36b | 828 | if(maxim == 0) |
asong | 14:c3b080cdf36b | 829 | { |
asong | 14:c3b080cdf36b | 830 | Decrement_Heart_Rate(); |
asong | 14:c3b080cdf36b | 831 | // Determine_Current_Zone(); |
asong | 14:c3b080cdf36b | 832 | update_display(); |
asong | 14:c3b080cdf36b | 833 | } |
asong | 14:c3b080cdf36b | 834 | |
asong | 14:c3b080cdf36b | 835 | break; |
asong | 14:c3b080cdf36b | 836 | } |
asong | 14:c3b080cdf36b | 837 | case 32: {//End HR led used for manual demonstration |
asong | 20:990951205fbd | 838 | hr_led.detach(); |
asong | 20:990951205fbd | 839 | Heart_Rate_Mode = 0; |
nbaker | 16:537ef0c72084 | 840 | RED_Led = LED_OFF; |
nbaker | 16:537ef0c72084 | 841 | GRN_Led = LED_OFF; |
nbaker | 16:537ef0c72084 | 842 | BLU_Led = LED_OFF; |
asong | 14:c3b080cdf36b | 843 | break; |
asong | 14:c3b080cdf36b | 844 | } |
asong | 14:c3b080cdf36b | 845 | case 33: {//End HR Simulation early |
asong | 14:c3b080cdf36b | 846 | StartHaptic(); |
asong | 14:c3b080cdf36b | 847 | if(maxim == 0) |
asong | 14:c3b080cdf36b | 848 | { |
asong | 20:990951205fbd | 849 | Heart_Rate_Mode = 0; |
asong | 14:c3b080cdf36b | 850 | hr_simulation.detach(); |
asong | 14:c3b080cdf36b | 851 | simulation_stage = 0; |
asong | 14:c3b080cdf36b | 852 | hr_led.detach(); |
nbaker | 16:537ef0c72084 | 853 | RED_Led = LED_OFF; |
nbaker | 16:537ef0c72084 | 854 | GRN_Led = LED_OFF; |
nbaker | 16:537ef0c72084 | 855 | BLU_Led = LED_OFF; |
asong | 14:c3b080cdf36b | 856 | } |
asong | 1:e4b38d6918ba | 857 | update_display(); |
asong | 1:e4b38d6918ba | 858 | break; |
asong | 1:e4b38d6918ba | 859 | } |
nbaker | 10:eaea844e763c | 860 | case 41: {//Fall mode 0,1,2,3,4,5 |
nbaker | 10:eaea844e763c | 861 | // 0=nothing, 1=fall_only, 2=impact only, 3=motion_only, 4=all, 5=main sequence |
nbaker | 9:d2e39ee9fedd | 862 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 863 | Fall_Alert_Mode--; |
nbaker | 10:eaea844e763c | 864 | if(Fall_Alert_Mode > 5){// should be 0xff if decr from zero |
nbaker | 10:eaea844e763c | 865 | Fall_Alert_Mode = 5; |
nbaker | 8:a5c77b45008d | 866 | } //endif |
nbaker | 8:a5c77b45008d | 867 | update_display(); |
nbaker | 8:a5c77b45008d | 868 | __disable_irq(); // Disable all Interrupts |
nbaker | 9:d2e39ee9fedd | 869 | fall_config(10); // reset accel sensor |
nbaker | 10:eaea844e763c | 870 | //gyro_sensor_config(10); // reset gyro sensor |
nbaker | 8:a5c77b45008d | 871 | wait(0.1); |
nbaker | 10:eaea844e763c | 872 | //gyro_sensor_config(Fall_Alert_Mode); // leave gyro sensor active |
nbaker | 8:a5c77b45008d | 873 | fall_config(Fall_Alert_Mode); |
nbaker | 8:a5c77b45008d | 874 | wait(0.1); |
nbaker | 8:a5c77b45008d | 875 | __enable_irq(); // Enable all Interrupts |
nbaker | 8:a5c77b45008d | 876 | wait(0.2); |
nbaker | 8:a5c77b45008d | 877 | update_display(); |
nbaker | 8:a5c77b45008d | 878 | break; |
nbaker | 8:a5c77b45008d | 879 | } |
nbaker | 8:a5c77b45008d | 880 | case 42: {// F-Th adj |
nbaker | 8:a5c77b45008d | 881 | StartHaptic(); |
nbaker | 9:d2e39ee9fedd | 882 | Fall_Thresh = Fall_Thresh - 0.05f; |
nbaker | 9:d2e39ee9fedd | 883 | if(Fall_Thresh < 0.1f){ |
nbaker | 8:a5c77b45008d | 884 | Fall_Thresh = 0.1; |
nbaker | 8:a5c77b45008d | 885 | }//endif |
nbaker | 8:a5c77b45008d | 886 | update_display(); |
nbaker | 8:a5c77b45008d | 887 | break; |
nbaker | 8:a5c77b45008d | 888 | } |
nbaker | 8:a5c77b45008d | 889 | case 43: {// I-Th adj |
nbaker | 8:a5c77b45008d | 890 | StartHaptic(); |
nbaker | 9:d2e39ee9fedd | 891 | Impact_Thresh = Impact_Thresh - 0.1f; |
nbaker | 9:d2e39ee9fedd | 892 | if(Impact_Thresh < 0.9f){ |
nbaker | 8:a5c77b45008d | 893 | Impact_Thresh = 0.9; |
nbaker | 8:a5c77b45008d | 894 | }//endif |
nbaker | 8:a5c77b45008d | 895 | update_display(); |
nbaker | 8:a5c77b45008d | 896 | break; |
nbaker | 8:a5c77b45008d | 897 | } |
nbaker | 8:a5c77b45008d | 898 | case 44: {// M-Th adj |
nbaker | 8:a5c77b45008d | 899 | StartHaptic(); |
nbaker | 9:d2e39ee9fedd | 900 | Movement_Thresh = Movement_Thresh - 5.0f; |
nbaker | 9:d2e39ee9fedd | 901 | if(Movement_Thresh < 5.0f){ |
nbaker | 8:a5c77b45008d | 902 | Movement_Thresh = 5.0; |
nbaker | 8:a5c77b45008d | 903 | }//endif |
nbaker | 8:a5c77b45008d | 904 | update_display(); |
nbaker | 8:a5c77b45008d | 905 | break; |
nbaker | 8:a5c77b45008d | 906 | } |
nbaker | 9:d2e39ee9fedd | 907 | case 45: {// Min_Movement_Time adj |
nbaker | 9:d2e39ee9fedd | 908 | StartHaptic(); |
nbaker | 9:d2e39ee9fedd | 909 | Min_Movement_Time = Min_Movement_Time - 0.1f; |
nbaker | 9:d2e39ee9fedd | 910 | if(Min_Movement_Time < 0.5f){ |
nbaker | 9:d2e39ee9fedd | 911 | Min_Movement_Time = 0.5; |
nbaker | 9:d2e39ee9fedd | 912 | }//endif |
nbaker | 9:d2e39ee9fedd | 913 | update_display(); |
nbaker | 9:d2e39ee9fedd | 914 | break; |
nbaker | 9:d2e39ee9fedd | 915 | } |
nbaker | 9:d2e39ee9fedd | 916 | case 46: {// Min_Movement_duration adj |
nbaker | 9:d2e39ee9fedd | 917 | StartHaptic(); |
nbaker | 9:d2e39ee9fedd | 918 | Min_Movement_duration = Min_Movement_duration - 5.0f; |
nbaker | 9:d2e39ee9fedd | 919 | if(Min_Movement_duration < 5.0f){ |
nbaker | 9:d2e39ee9fedd | 920 | Min_Movement_duration = 5.0; |
nbaker | 9:d2e39ee9fedd | 921 | }//endif |
nbaker | 9:d2e39ee9fedd | 922 | update_display(); |
nbaker | 9:d2e39ee9fedd | 923 | break; |
nbaker | 9:d2e39ee9fedd | 924 | } |
nbaker | 12:fd39a7983e06 | 925 | case 49: {// WDT diagnostic test screen |
nbaker | 12:fd39a7983e06 | 926 | StartHaptic(); |
nbaker | 12:fd39a7983e06 | 927 | Screen_Num = 21; //Change to screen 21 |
nbaker | 12:fd39a7983e06 | 928 | update_display(); |
nbaker | 12:fd39a7983e06 | 929 | break; |
nbaker | 12:fd39a7983e06 | 930 | } |
nbaker | 8:a5c77b45008d | 931 | case 71: {// BLE |
nbaker | 8:a5c77b45008d | 932 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 933 | Screen_Num = 2; //Change to screen 2 |
nbaker | 8:a5c77b45008d | 934 | update_display(); |
nbaker | 8:a5c77b45008d | 935 | break; |
nbaker | 8:a5c77b45008d | 936 | } |
nbaker | 8:a5c77b45008d | 937 | case 72: {// BlueTooth on/off |
nbaker | 8:a5c77b45008d | 938 | // do nothing, wrong button or change to another screen number if you're making more BLE type screens |
nbaker | 8:a5c77b45008d | 939 | break; |
nbaker | 8:a5c77b45008d | 940 | } |
nbaker | 8:a5c77b45008d | 941 | |
asong | 1:e4b38d6918ba | 942 | default: { |
asong | 1:e4b38d6918ba | 943 | break; |
asong | 1:e4b38d6918ba | 944 | } |
nbaker | 12:fd39a7983e06 | 945 | }//end case switch |
nbaker | 12:fd39a7983e06 | 946 | }//end if |
nbaker | 12:fd39a7983e06 | 947 | }// end ButtonDown() |
nbaker | 12:fd39a7983e06 | 948 | |
nbaker | 0:d1d36a3da39b | 949 | |
nbaker | 12:fd39a7983e06 | 950 | /***************************************************************************** |
nbaker | 12:fd39a7983e06 | 951 | Name: ButtonRight() |
nbaker | 12:fd39a7983e06 | 952 | Purpose: Routine called when MK46 recieves a ButtonRight interrupt from KW40 |
nbaker | 12:fd39a7983e06 | 953 | Inputs: Uses global Screen_Num value and other status varibles |
nbaker | 12:fd39a7983e06 | 954 | Returns: None |
nbaker | 12:fd39a7983e06 | 955 | ******************************************************************************/ |
nbaker | 0:d1d36a3da39b | 956 | void ButtonRight(void) |
nbaker | 0:d1d36a3da39b | 957 | { |
nbaker | 13:37cd579208e9 | 958 | Reset_Count = 0; |
asong | 1:e4b38d6918ba | 959 | Screen_Timer.attach(&timout_timer,(SCRN_TIME));//Is this sufficient to reset/restart ticker timer for OLED? |
nbaker | 13:37cd579208e9 | 960 | oled.DimScreenOFF(); |
asong | 1:e4b38d6918ba | 961 | if (OLED_ON == 0) { |
asong | 1:e4b38d6918ba | 962 | OLED_ON = 1; // Screen was off, set to On |
asong | 1:e4b38d6918ba | 963 | update_display(); |
asong | 1:e4b38d6918ba | 964 | } else { |
asong | 1:e4b38d6918ba | 965 | switch(Screen_Num) { |
asong | 1:e4b38d6918ba | 966 | case 0: {// We're in Main Screen |
asong | 1:e4b38d6918ba | 967 | StartHaptic(); |
asong | 1:e4b38d6918ba | 968 | Screen_Num = 1; //Change to screen 1 |
asong | 1:e4b38d6918ba | 969 | update_display(); |
asong | 1:e4b38d6918ba | 970 | break; |
asong | 1:e4b38d6918ba | 971 | } |
asong | 1:e4b38d6918ba | 972 | case 1: {// Panic Alert option |
asong | 1:e4b38d6918ba | 973 | StartHaptic(); |
asong | 1:e4b38d6918ba | 974 | Screen_Num = 6; //Change to screen 6 |
asong | 1:e4b38d6918ba | 975 | update_display(); |
asong | 1:e4b38d6918ba | 976 | break; |
asong | 1:e4b38d6918ba | 977 | } |
asong | 1:e4b38d6918ba | 978 | case 2: {// Fall Alert option |
asong | 1:e4b38d6918ba | 979 | StartHaptic(); |
nbaker | 4:0803151bc5e4 | 980 | if(Fall_Alert == 1){ |
nbaker | 4:0803151bc5e4 | 981 | Fall_Alert = 0; |
nbaker | 10:eaea844e763c | 982 | fall_config(0); // configure sensors for standby |
nbaker | 4:0803151bc5e4 | 983 | } |
nbaker | 4:0803151bc5e4 | 984 | else{ |
nbaker | 10:eaea844e763c | 985 | //Accel_INT1.fall(&fall_detect); // Accel sensor's int#1 calls interupt routine |
nbaker | 4:0803151bc5e4 | 986 | Fall_Alert = 1; |
nbaker | 10:eaea844e763c | 987 | fall_config(Fall_Alert_Mode); // configure sensors for current fall mode |
nbaker | 4:0803151bc5e4 | 988 | } |
nbaker | 4:0803151bc5e4 | 989 | update_display(); |
asong | 1:e4b38d6918ba | 990 | break; |
asong | 1:e4b38d6918ba | 991 | } |
asong | 1:e4b38d6918ba | 992 | case 3: {// Heart Rate Monitoring option |
asong | 1:e4b38d6918ba | 993 | StartHaptic(); |
asong | 1:e4b38d6918ba | 994 | Screen_Num = 7; //Change to screen 7 |
asong | 1:e4b38d6918ba | 995 | update_display(); |
asong | 1:e4b38d6918ba | 996 | break; |
asong | 1:e4b38d6918ba | 997 | } |
asong | 1:e4b38d6918ba | 998 | case 4: {// Alert History option |
asong | 1:e4b38d6918ba | 999 | StartHaptic(); |
asong | 1:e4b38d6918ba | 1000 | Screen_Num = 8; //Change to screen 8 |
asong | 1:e4b38d6918ba | 1001 | update_display(); |
asong | 1:e4b38d6918ba | 1002 | break; |
asong | 1:e4b38d6918ba | 1003 | } |
asong | 1:e4b38d6918ba | 1004 | case 5: {// About HexiHeart option |
asong | 1:e4b38d6918ba | 1005 | StartHaptic(); |
asong | 1:e4b38d6918ba | 1006 | Screen_Num = 9; //Change to screen 9 |
asong | 1:e4b38d6918ba | 1007 | update_display(); |
asong | 1:e4b38d6918ba | 1008 | break; |
asong | 1:e4b38d6918ba | 1009 | } |
nbaker | 0:d1d36a3da39b | 1010 | |
asong | 1:e4b38d6918ba | 1011 | case 6: {// Panic Alert |
asong | 1:e4b38d6918ba | 1012 | // do nothing, wrong button |
asong | 1:e4b38d6918ba | 1013 | break; |
asong | 1:e4b38d6918ba | 1014 | } |
asong | 1:e4b38d6918ba | 1015 | case 7: {// Heart Rate Zone |
asong | 1:e4b38d6918ba | 1016 | StartHaptic(); |
asong | 2:824ed4ae8d52 | 1017 | Screen_Num = 31; |
asong | 2:824ed4ae8d52 | 1018 | update_display(); |
asong | 1:e4b38d6918ba | 1019 | break; |
asong | 1:e4b38d6918ba | 1020 | } |
asong | 1:e4b38d6918ba | 1021 | case 20: {// Diagnostic/Debug Screens |
asong | 1:e4b38d6918ba | 1022 | StartHaptic(); |
asong | 1:e4b38d6918ba | 1023 | Screen_Num = 21; //Change to screen 21 |
asong | 1:e4b38d6918ba | 1024 | update_display(); |
asong | 1:e4b38d6918ba | 1025 | break; |
asong | 1:e4b38d6918ba | 1026 | } |
nbaker | 8:a5c77b45008d | 1027 | case 22: {// Fall Debug |
nbaker | 8:a5c77b45008d | 1028 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 1029 | Screen_Num = 41; //Change to screen 41 |
nbaker | 8:a5c77b45008d | 1030 | update_display(); |
nbaker | 8:a5c77b45008d | 1031 | break; |
nbaker | 8:a5c77b45008d | 1032 | } |
asong | 1:e4b38d6918ba | 1033 | case 26: {//Change to Heart Rate Config Screen |
asong | 1:e4b38d6918ba | 1034 | StartHaptic(); |
asong | 1:e4b38d6918ba | 1035 | Screen_Num = 27; |
asong | 1:e4b38d6918ba | 1036 | update_display(); |
asong | 1:e4b38d6918ba | 1037 | break; |
asong | 1:e4b38d6918ba | 1038 | } |
asong | 1:e4b38d6918ba | 1039 | case 27: {//Change to Heart Rate Vibration Preferences |
asong | 1:e4b38d6918ba | 1040 | StartHaptic(); |
asong | 1:e4b38d6918ba | 1041 | Screen_Num = 28; |
asong | 1:e4b38d6918ba | 1042 | update_display(); |
asong | 1:e4b38d6918ba | 1043 | break; |
asong | 1:e4b38d6918ba | 1044 | } |
asong | 1:e4b38d6918ba | 1045 | case 28: {//Change to Heart Rate Zone Boundary Info |
asong | 1:e4b38d6918ba | 1046 | StartHaptic(); |
asong | 1:e4b38d6918ba | 1047 | Screen_Num = 29; |
asong | 1:e4b38d6918ba | 1048 | update_display(); |
asong | 1:e4b38d6918ba | 1049 | break; |
asong | 1:e4b38d6918ba | 1050 | } |
asong | 2:824ed4ae8d52 | 1051 | case 29: {//Change Target Heart Rate Zone Preference |
asong | 1:e4b38d6918ba | 1052 | StartHaptic(); |
asong | 1:e4b38d6918ba | 1053 | Screen_Num = 30; |
asong | 1:e4b38d6918ba | 1054 | update_display(); |
asong | 1:e4b38d6918ba | 1055 | break; |
asong | 1:e4b38d6918ba | 1056 | } |
asong | 1:e4b38d6918ba | 1057 | case 30: {//Change to Heart Rate Config Screen |
asong | 1:e4b38d6918ba | 1058 | StartHaptic(); |
asong | 1:e4b38d6918ba | 1059 | Screen_Num = 27; |
asong | 1:e4b38d6918ba | 1060 | update_display(); |
asong | 1:e4b38d6918ba | 1061 | break; |
asong | 1:e4b38d6918ba | 1062 | } |
asong | 15:330794a9f347 | 1063 | case 31: { |
asong | 15:330794a9f347 | 1064 | StartHaptic(); |
asong | 15:330794a9f347 | 1065 | Screen_Num = 32; |
asong | 15:330794a9f347 | 1066 | update_display(); |
asong | 15:330794a9f347 | 1067 | break; |
asong | 15:330794a9f347 | 1068 | } |
asong | 14:c3b080cdf36b | 1069 | case 32: { |
asong | 2:824ed4ae8d52 | 1070 | StartHaptic(); |
asong | 14:c3b080cdf36b | 1071 | Screen_Num = 33; |
asong | 2:824ed4ae8d52 | 1072 | update_display(); |
asong | 2:824ed4ae8d52 | 1073 | break; |
asong | 2:824ed4ae8d52 | 1074 | } |
asong | 14:c3b080cdf36b | 1075 | case 33: { |
asong | 2:824ed4ae8d52 | 1076 | StartHaptic(); |
asong | 2:824ed4ae8d52 | 1077 | Screen_Num = 7; |
asong | 2:824ed4ae8d52 | 1078 | update_display(); |
asong | 15:330794a9f347 | 1079 | break; |
asong | 14:c3b080cdf36b | 1080 | } |
nbaker | 8:a5c77b45008d | 1081 | case 41: {// Fall-Mode adj |
nbaker | 8:a5c77b45008d | 1082 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 1083 | Screen_Num = 42; //Change to screen 42 |
nbaker | 8:a5c77b45008d | 1084 | update_display(); |
nbaker | 8:a5c77b45008d | 1085 | break; |
nbaker | 8:a5c77b45008d | 1086 | } |
nbaker | 8:a5c77b45008d | 1087 | case 42: {// F-Th adj |
nbaker | 8:a5c77b45008d | 1088 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 1089 | Screen_Num = 43; //Change to screen 43 |
nbaker | 8:a5c77b45008d | 1090 | update_display(); |
nbaker | 8:a5c77b45008d | 1091 | break; |
nbaker | 8:a5c77b45008d | 1092 | } |
nbaker | 8:a5c77b45008d | 1093 | case 43: {// I-Th adj |
nbaker | 8:a5c77b45008d | 1094 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 1095 | Screen_Num = 44; //Change to screen 44 |
nbaker | 8:a5c77b45008d | 1096 | update_display(); |
nbaker | 8:a5c77b45008d | 1097 | break; |
nbaker | 8:a5c77b45008d | 1098 | } |
nbaker | 8:a5c77b45008d | 1099 | case 44: {// M-Th adj |
nbaker | 9:d2e39ee9fedd | 1100 | StartHaptic(); |
nbaker | 9:d2e39ee9fedd | 1101 | Screen_Num = 45; //Change to screen 44 |
nbaker | 9:d2e39ee9fedd | 1102 | update_display(); |
nbaker | 8:a5c77b45008d | 1103 | break; |
nbaker | 8:a5c77b45008d | 1104 | } |
nbaker | 9:d2e39ee9fedd | 1105 | case 45: {// Min_time adj |
nbaker | 9:d2e39ee9fedd | 1106 | StartHaptic(); |
nbaker | 9:d2e39ee9fedd | 1107 | Screen_Num = 46; //Change to screen 44 |
nbaker | 9:d2e39ee9fedd | 1108 | update_display(); |
nbaker | 9:d2e39ee9fedd | 1109 | break; |
nbaker | 9:d2e39ee9fedd | 1110 | } |
nbaker | 9:d2e39ee9fedd | 1111 | case 46: {// Time_dur adj |
nbaker | 9:d2e39ee9fedd | 1112 | //do nothing for now |
nbaker | 9:d2e39ee9fedd | 1113 | break; |
nbaker | 9:d2e39ee9fedd | 1114 | } |
nbaker | 10:eaea844e763c | 1115 | case 47: {// Fall-Detected screen "are you ok?" |
nbaker | 10:eaea844e763c | 1116 | StartHaptic(); |
nbaker | 12:fd39a7983e06 | 1117 | Send_Alert(20); // send/store alert type 20 |
nbaker | 10:eaea844e763c | 1118 | Screen_Num = 48; //Change to screen 48 (send alert screen) |
nbaker | 10:eaea844e763c | 1119 | update_display(); |
nbaker | 10:eaea844e763c | 1120 | break; |
nbaker | 10:eaea844e763c | 1121 | } |
nbaker | 12:fd39a7983e06 | 1122 | case 49: {// start WDT test |
nbaker | 12:fd39a7983e06 | 1123 | StartHaptic(); |
nbaker | 12:fd39a7983e06 | 1124 | Screen_Num = 50; //Change to screen 50 |
nbaker | 12:fd39a7983e06 | 1125 | update_display(); |
nbaker | 12:fd39a7983e06 | 1126 | break; |
nbaker | 12:fd39a7983e06 | 1127 | } |
nbaker | 8:a5c77b45008d | 1128 | case 71: {// BLE |
nbaker | 8:a5c77b45008d | 1129 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 1130 | Screen_Num = 72; //Change to screen 72 |
nbaker | 8:a5c77b45008d | 1131 | update_display(); |
nbaker | 8:a5c77b45008d | 1132 | break; |
nbaker | 8:a5c77b45008d | 1133 | } |
nbaker | 8:a5c77b45008d | 1134 | case 72: {// BlueTooth on/off |
nbaker | 8:a5c77b45008d | 1135 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 1136 | BLE_On = !BLE_On; |
nbaker | 11:ccda4d44bd8e | 1137 | kw40z_device.ToggleAdvertisementMode(); |
nbaker | 8:a5c77b45008d | 1138 | update_display(); |
nbaker | 8:a5c77b45008d | 1139 | break; |
nbaker | 8:a5c77b45008d | 1140 | } |
nbaker | 8:a5c77b45008d | 1141 | |
asong | 1:e4b38d6918ba | 1142 | default: { |
asong | 1:e4b38d6918ba | 1143 | break; |
asong | 1:e4b38d6918ba | 1144 | } |
nbaker | 12:fd39a7983e06 | 1145 | }//end case switch |
nbaker | 12:fd39a7983e06 | 1146 | }//end if |
nbaker | 12:fd39a7983e06 | 1147 | }//end ButtonRight |
nbaker | 12:fd39a7983e06 | 1148 | |
nbaker | 0:d1d36a3da39b | 1149 | |
nbaker | 12:fd39a7983e06 | 1150 | /***************************************************************************** |
nbaker | 12:fd39a7983e06 | 1151 | Name: ButtonLeft() |
nbaker | 12:fd39a7983e06 | 1152 | Purpose: Routine called when MK46 recieves a ButtonLeft interrupt from KW40 |
nbaker | 12:fd39a7983e06 | 1153 | Inputs: Uses global Screen_Num value and other status varibles |
nbaker | 12:fd39a7983e06 | 1154 | Returns: None |
nbaker | 12:fd39a7983e06 | 1155 | ******************************************************************************/ |
nbaker | 0:d1d36a3da39b | 1156 | void ButtonLeft(void) |
nbaker | 0:d1d36a3da39b | 1157 | { |
asong | 1:e4b38d6918ba | 1158 | Screen_Timer.attach(&timout_timer,(SCRN_TIME));//Is this sufficient to reset/restart ticker timer for OLED? |
nbaker | 13:37cd579208e9 | 1159 | oled.DimScreenOFF(); |
asong | 1:e4b38d6918ba | 1160 | if (OLED_ON == 0) { |
asong | 1:e4b38d6918ba | 1161 | OLED_ON = 1; // Screen was off, set to On |
asong | 1:e4b38d6918ba | 1162 | update_display(); |
asong | 1:e4b38d6918ba | 1163 | } else { |
asong | 1:e4b38d6918ba | 1164 | switch(Screen_Num) { |
asong | 1:e4b38d6918ba | 1165 | case 0: {// We're in Main Screen |
nbaker | 13:37cd579208e9 | 1166 | Reset_Count++; |
nbaker | 13:37cd579208e9 | 1167 | if(Reset_Count >= 8){ |
nbaker | 13:37cd579208e9 | 1168 | __disable_irq(); // Disable all Interrupts |
nbaker | 13:37cd579208e9 | 1169 | oled_text_properties_t textProperties = {0}; // Need these to change font color |
nbaker | 13:37cd579208e9 | 1170 | oled.GetTextProperties(&textProperties); // Need these to change font color |
nbaker | 13:37cd579208e9 | 1171 | textProperties.font = OpenSans_12x18_Regular; // Max Width of Character = 12px, Max Height of Character = 18px |
nbaker | 13:37cd579208e9 | 1172 | textProperties.fontColor = COLOR_WHITE; |
nbaker | 13:37cd579208e9 | 1173 | oled.SetTextProperties(&textProperties); |
nbaker | 13:37cd579208e9 | 1174 | wait_ms(100); |
nbaker | 13:37cd579208e9 | 1175 | oled.FillScreen(COLOR_BLACK); // Clear screen |
nbaker | 13:37cd579208e9 | 1176 | wait_ms(100); |
nbaker | 13:37cd579208e9 | 1177 | oled.Label((uint8_t *)"Hidden",20,20); // Display "Back" at x,y |
nbaker | 13:37cd579208e9 | 1178 | oled.Label((uint8_t *)" Reset ",20,40); // Display "Back" at x,y |
nbaker | 13:37cd579208e9 | 1179 | oled.Label((uint8_t *)"Feature",20,60); // Display "Back" at x,y |
nbaker | 13:37cd579208e9 | 1180 | wait_ms(500);// display for 100ms |
nbaker | 13:37cd579208e9 | 1181 | NVIC_SystemReset(); // software reset |
nbaker | 13:37cd579208e9 | 1182 | wait(3.0);// should never get here |
nbaker | 13:37cd579208e9 | 1183 | }//end if |
asong | 1:e4b38d6918ba | 1184 | break; |
asong | 1:e4b38d6918ba | 1185 | } |
asong | 1:e4b38d6918ba | 1186 | case 1: {// Panic Alert option |
asong | 1:e4b38d6918ba | 1187 | StartHaptic(); |
asong | 1:e4b38d6918ba | 1188 | Screen_Num = 0; //Change to screen 0 |
asong | 1:e4b38d6918ba | 1189 | update_display(); |
asong | 1:e4b38d6918ba | 1190 | break; |
asong | 1:e4b38d6918ba | 1191 | } |
asong | 1:e4b38d6918ba | 1192 | case 2: {// Fall Alert option |
asong | 1:e4b38d6918ba | 1193 | StartHaptic(); |
asong | 1:e4b38d6918ba | 1194 | Screen_Num = 0; //Change to screen 0 |
asong | 1:e4b38d6918ba | 1195 | update_display(); |
asong | 1:e4b38d6918ba | 1196 | break; |
asong | 1:e4b38d6918ba | 1197 | } |
asong | 1:e4b38d6918ba | 1198 | case 3: {// Heart Rate Monitoring option |
asong | 1:e4b38d6918ba | 1199 | StartHaptic(); |
asong | 1:e4b38d6918ba | 1200 | Screen_Num = 0; //Change to screen 0 |
asong | 1:e4b38d6918ba | 1201 | update_display(); |
asong | 1:e4b38d6918ba | 1202 | break; |
asong | 1:e4b38d6918ba | 1203 | } |
asong | 1:e4b38d6918ba | 1204 | case 4: {// Alert History option |
asong | 1:e4b38d6918ba | 1205 | StartHaptic(); |
asong | 1:e4b38d6918ba | 1206 | Screen_Num = 0; //Change to screen 0 |
asong | 1:e4b38d6918ba | 1207 | update_display(); |
asong | 1:e4b38d6918ba | 1208 | break; |
asong | 1:e4b38d6918ba | 1209 | } |
asong | 1:e4b38d6918ba | 1210 | case 5: {// About HexiHeart option |
asong | 1:e4b38d6918ba | 1211 | StartHaptic(); |
asong | 1:e4b38d6918ba | 1212 | Screen_Num = 0; //Change to screen 0 |
asong | 1:e4b38d6918ba | 1213 | update_display(); |
asong | 1:e4b38d6918ba | 1214 | break; |
asong | 1:e4b38d6918ba | 1215 | } |
asong | 1:e4b38d6918ba | 1216 | case 6: {// Panic Alert |
asong | 1:e4b38d6918ba | 1217 | StartHaptic(); |
asong | 1:e4b38d6918ba | 1218 | Screen_Num = 1; //Change to screen 1 |
asong | 1:e4b38d6918ba | 1219 | update_display(); |
asong | 1:e4b38d6918ba | 1220 | break; |
asong | 1:e4b38d6918ba | 1221 | } |
asong | 1:e4b38d6918ba | 1222 | case 7: {// Heart Rate Zone |
asong | 1:e4b38d6918ba | 1223 | StartHaptic(); |
asong | 1:e4b38d6918ba | 1224 | Screen_Num = 3; //Change to screen 3 |
asong | 1:e4b38d6918ba | 1225 | update_display(); |
asong | 1:e4b38d6918ba | 1226 | break; |
asong | 1:e4b38d6918ba | 1227 | } |
asong | 1:e4b38d6918ba | 1228 | case 8: {// Alert History |
asong | 1:e4b38d6918ba | 1229 | StartHaptic(); |
asong | 1:e4b38d6918ba | 1230 | Screen_Num = 4; //Change to screen 4 |
asong | 1:e4b38d6918ba | 1231 | update_display(); |
asong | 1:e4b38d6918ba | 1232 | break; |
asong | 1:e4b38d6918ba | 1233 | } |
nbaker | 8:a5c77b45008d | 1234 | case 9: {// About HexiHeart info1 |
nbaker | 8:a5c77b45008d | 1235 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 1236 | Screen_Num = 5; //Change to screen 5 |
nbaker | 8:a5c77b45008d | 1237 | update_display(); |
nbaker | 8:a5c77b45008d | 1238 | break; |
nbaker | 8:a5c77b45008d | 1239 | } |
nbaker | 8:a5c77b45008d | 1240 | case 10: {// HexiHeart About info2 |
nbaker | 8:a5c77b45008d | 1241 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 1242 | Screen_Num = 5; //Change to screen 5 |
nbaker | 8:a5c77b45008d | 1243 | update_display(); |
nbaker | 8:a5c77b45008d | 1244 | break; |
nbaker | 8:a5c77b45008d | 1245 | } |
nbaker | 8:a5c77b45008d | 1246 | case 11: {// HexiHeart About info3 |
nbaker | 8:a5c77b45008d | 1247 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 1248 | Screen_Num = 5; //Change to screen 5 |
nbaker | 8:a5c77b45008d | 1249 | update_display(); |
nbaker | 8:a5c77b45008d | 1250 | break; |
nbaker | 8:a5c77b45008d | 1251 | } |
asong | 1:e4b38d6918ba | 1252 | case 20: {// Diagnostic/Debug Screens |
asong | 1:e4b38d6918ba | 1253 | StartHaptic(); |
asong | 1:e4b38d6918ba | 1254 | Screen_Num = 0; //Change to screen 0 |
asong | 1:e4b38d6918ba | 1255 | update_display(); |
asong | 1:e4b38d6918ba | 1256 | break; |
asong | 1:e4b38d6918ba | 1257 | } |
asong | 1:e4b38d6918ba | 1258 | case 21: {// Fall Diagnostic |
asong | 1:e4b38d6918ba | 1259 | StartHaptic(); |
asong | 1:e4b38d6918ba | 1260 | Screen_Num = 20; //Change to screen 20 |
asong | 1:e4b38d6918ba | 1261 | update_display(); |
asong | 1:e4b38d6918ba | 1262 | break; |
asong | 1:e4b38d6918ba | 1263 | } |
asong | 1:e4b38d6918ba | 1264 | case 22: {// Fall Debug |
asong | 1:e4b38d6918ba | 1265 | StartHaptic(); |
asong | 1:e4b38d6918ba | 1266 | Screen_Num = 20; //Change to screen 20 |
asong | 1:e4b38d6918ba | 1267 | update_display(); |
asong | 1:e4b38d6918ba | 1268 | break; |
asong | 1:e4b38d6918ba | 1269 | } |
asong | 1:e4b38d6918ba | 1270 | case 23: {// Heart Rate Diagnostic |
asong | 1:e4b38d6918ba | 1271 | StartHaptic(); |
asong | 1:e4b38d6918ba | 1272 | Screen_Num = 20; //Change to screen 20 |
asong | 1:e4b38d6918ba | 1273 | update_display(); |
asong | 1:e4b38d6918ba | 1274 | break; |
asong | 1:e4b38d6918ba | 1275 | } |
asong | 1:e4b38d6918ba | 1276 | case 24: {// Heart Rate Debug |
asong | 1:e4b38d6918ba | 1277 | StartHaptic(); |
asong | 1:e4b38d6918ba | 1278 | Screen_Num = 20; //Change to screen 20 |
asong | 1:e4b38d6918ba | 1279 | update_display(); |
asong | 1:e4b38d6918ba | 1280 | break; |
asong | 1:e4b38d6918ba | 1281 | } |
asong | 1:e4b38d6918ba | 1282 | case 25: {// Heat Index Diagnostic |
asong | 1:e4b38d6918ba | 1283 | StartHaptic(); |
asong | 1:e4b38d6918ba | 1284 | Screen_Num = 20; //Change to screen 20 |
asong | 1:e4b38d6918ba | 1285 | update_display(); |
asong | 1:e4b38d6918ba | 1286 | break; |
asong | 1:e4b38d6918ba | 1287 | } |
asong | 1:e4b38d6918ba | 1288 | case 26: {//Heart Rate Config Option |
asong | 1:e4b38d6918ba | 1289 | StartHaptic(); |
asong | 1:e4b38d6918ba | 1290 | Screen_Num = 0; |
asong | 1:e4b38d6918ba | 1291 | update_display(); |
asong | 1:e4b38d6918ba | 1292 | break; |
asong | 1:e4b38d6918ba | 1293 | } |
asong | 1:e4b38d6918ba | 1294 | case 27: {//Enter Age |
asong | 1:e4b38d6918ba | 1295 | StartHaptic(); |
asong | 1:e4b38d6918ba | 1296 | Screen_Num = 26; |
asong | 1:e4b38d6918ba | 1297 | update_display(); |
asong | 1:e4b38d6918ba | 1298 | break; |
asong | 1:e4b38d6918ba | 1299 | } |
asong | 1:e4b38d6918ba | 1300 | case 28: {//Heart Rate Vibration Preference Screen |
asong | 1:e4b38d6918ba | 1301 | StartHaptic(); |
asong | 1:e4b38d6918ba | 1302 | Screen_Num = 27; |
asong | 1:e4b38d6918ba | 1303 | update_display(); |
asong | 1:e4b38d6918ba | 1304 | break; |
asong | 1:e4b38d6918ba | 1305 | } |
asong | 1:e4b38d6918ba | 1306 | case 29: {//Heart Rate Zone Boundary Info |
asong | 1:e4b38d6918ba | 1307 | StartHaptic(); |
asong | 1:e4b38d6918ba | 1308 | Screen_Num = 28; |
asong | 1:e4b38d6918ba | 1309 | update_display(); |
asong | 1:e4b38d6918ba | 1310 | break; |
asong | 1:e4b38d6918ba | 1311 | } |
asong | 2:824ed4ae8d52 | 1312 | case 30: {//Change Target Heart Rate Zone Preference |
asong | 1:e4b38d6918ba | 1313 | StartHaptic(); |
asong | 1:e4b38d6918ba | 1314 | Screen_Num = 29; |
asong | 1:e4b38d6918ba | 1315 | update_display(); |
asong | 1:e4b38d6918ba | 1316 | break; |
asong | 1:e4b38d6918ba | 1317 | } |
asong | 2:824ed4ae8d52 | 1318 | case 31: { |
asong | 2:824ed4ae8d52 | 1319 | StartHaptic(); |
asong | 2:824ed4ae8d52 | 1320 | Screen_Num = 7; |
asong | 2:824ed4ae8d52 | 1321 | update_display(); |
asong | 2:824ed4ae8d52 | 1322 | break; |
asong | 2:824ed4ae8d52 | 1323 | } |
asong | 2:824ed4ae8d52 | 1324 | case 32: { |
asong | 2:824ed4ae8d52 | 1325 | StartHaptic(); |
asong | 2:824ed4ae8d52 | 1326 | Screen_Num = 31; |
asong | 2:824ed4ae8d52 | 1327 | update_display(); |
asong | 2:824ed4ae8d52 | 1328 | break; |
asong | 2:824ed4ae8d52 | 1329 | } |
asong | 14:c3b080cdf36b | 1330 | case 33: { |
asong | 14:c3b080cdf36b | 1331 | StartHaptic(); |
asong | 14:c3b080cdf36b | 1332 | Screen_Num = 32; |
asong | 14:c3b080cdf36b | 1333 | update_display(); |
asong | 14:c3b080cdf36b | 1334 | break; |
asong | 14:c3b080cdf36b | 1335 | } |
nbaker | 8:a5c77b45008d | 1336 | case 41: {// Fall mode screen |
nbaker | 8:a5c77b45008d | 1337 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 1338 | Screen_Num = 22; |
nbaker | 8:a5c77b45008d | 1339 | update_display(); |
nbaker | 8:a5c77b45008d | 1340 | break; |
nbaker | 8:a5c77b45008d | 1341 | } |
nbaker | 8:a5c77b45008d | 1342 | case 42: {// F-Th adj |
nbaker | 8:a5c77b45008d | 1343 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 1344 | Screen_Num = 41; //Change to screen 41 |
nbaker | 8:a5c77b45008d | 1345 | update_display(); |
nbaker | 8:a5c77b45008d | 1346 | break; |
nbaker | 8:a5c77b45008d | 1347 | } |
nbaker | 8:a5c77b45008d | 1348 | case 43: {// I-Th adj |
nbaker | 8:a5c77b45008d | 1349 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 1350 | Screen_Num = 42; //Change to screen 42 |
nbaker | 8:a5c77b45008d | 1351 | update_display(); |
nbaker | 8:a5c77b45008d | 1352 | break; |
nbaker | 8:a5c77b45008d | 1353 | } |
nbaker | 8:a5c77b45008d | 1354 | case 44: {// M-Th adj |
nbaker | 8:a5c77b45008d | 1355 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 1356 | Screen_Num = 43; //Change to screen 43 |
nbaker | 8:a5c77b45008d | 1357 | update_display(); |
nbaker | 8:a5c77b45008d | 1358 | break; |
nbaker | 9:d2e39ee9fedd | 1359 | } |
nbaker | 9:d2e39ee9fedd | 1360 | case 45: {// M-time adj |
nbaker | 9:d2e39ee9fedd | 1361 | StartHaptic(); |
nbaker | 9:d2e39ee9fedd | 1362 | Screen_Num = 44; //Change to screen 44 |
nbaker | 9:d2e39ee9fedd | 1363 | update_display(); |
nbaker | 9:d2e39ee9fedd | 1364 | break; |
nbaker | 9:d2e39ee9fedd | 1365 | } |
nbaker | 9:d2e39ee9fedd | 1366 | case 46: {// M-dur adj |
nbaker | 9:d2e39ee9fedd | 1367 | StartHaptic(); |
nbaker | 9:d2e39ee9fedd | 1368 | Screen_Num = 45; //Change to screen 45 |
nbaker | 9:d2e39ee9fedd | 1369 | update_display(); |
nbaker | 9:d2e39ee9fedd | 1370 | break; |
nbaker | 10:eaea844e763c | 1371 | } |
nbaker | 10:eaea844e763c | 1372 | case 47: {// Fall-detected screen |
nbaker | 10:eaea844e763c | 1373 | StartHaptic(); |
nbaker | 10:eaea844e763c | 1374 | Led_clk1 = 0; // Turn off LED1, on docking station |
nbaker | 10:eaea844e763c | 1375 | Led_clk2 = 0; // Turn off LED2, on docking station |
nbaker | 10:eaea844e763c | 1376 | Screen_Num = 0; //Change to screen 0 |
nbaker | 10:eaea844e763c | 1377 | update_display(); |
nbaker | 10:eaea844e763c | 1378 | break; |
nbaker | 10:eaea844e763c | 1379 | } |
nbaker | 10:eaea844e763c | 1380 | case 48: {// Sending Fall-Alert screen |
nbaker | 10:eaea844e763c | 1381 | StartHaptic(); |
nbaker | 10:eaea844e763c | 1382 | Led_clk1 = 0; // Turn off LED1, on docking station |
nbaker | 10:eaea844e763c | 1383 | Led_clk2 = 0; // Turn off LED2, on docking station |
nbaker | 10:eaea844e763c | 1384 | // stop/dismiss alert |
nbaker | 12:fd39a7983e06 | 1385 | Send_Alert(0); |
nbaker | 10:eaea844e763c | 1386 | Screen_Num = 0; //Change to screen 0 |
nbaker | 10:eaea844e763c | 1387 | update_display(); |
nbaker | 10:eaea844e763c | 1388 | break; |
nbaker | 10:eaea844e763c | 1389 | } |
nbaker | 13:37cd579208e9 | 1390 | case 51: {// Sending Panic Alert |
nbaker | 13:37cd579208e9 | 1391 | StartHaptic(); |
nbaker | 13:37cd579208e9 | 1392 | Screen_Num = 6; //Change to screen 6 |
nbaker | 13:37cd579208e9 | 1393 | Panic_Alert = 0; |
nbaker | 13:37cd579208e9 | 1394 | Send_Alert(0); // send/store alert type zero |
nbaker | 13:37cd579208e9 | 1395 | update_display(); |
nbaker | 13:37cd579208e9 | 1396 | break; |
nbaker | 13:37cd579208e9 | 1397 | } |
nbaker | 8:a5c77b45008d | 1398 | case 71: {// BLE |
nbaker | 8:a5c77b45008d | 1399 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 1400 | Screen_Num = 0; //Change to screen 0 |
nbaker | 8:a5c77b45008d | 1401 | update_display(); |
nbaker | 8:a5c77b45008d | 1402 | break; |
nbaker | 8:a5c77b45008d | 1403 | } |
nbaker | 8:a5c77b45008d | 1404 | |
nbaker | 8:a5c77b45008d | 1405 | case 72: {// BlueTooth on/off |
nbaker | 8:a5c77b45008d | 1406 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 1407 | Screen_Num = 71; //Change to screen 71 |
nbaker | 8:a5c77b45008d | 1408 | update_display(); |
nbaker | 8:a5c77b45008d | 1409 | break; |
nbaker | 8:a5c77b45008d | 1410 | } |
nbaker | 8:a5c77b45008d | 1411 | |
asong | 1:e4b38d6918ba | 1412 | default: { |
asong | 1:e4b38d6918ba | 1413 | break; |
asong | 1:e4b38d6918ba | 1414 | } |
nbaker | 12:fd39a7983e06 | 1415 | }// end case switch |
nbaker | 12:fd39a7983e06 | 1416 | }// end if |
nbaker | 12:fd39a7983e06 | 1417 | }// end ButtonLeft |
nbaker | 0:d1d36a3da39b | 1418 | |
nbaker | 12:fd39a7983e06 | 1419 | /***************************************************************************** |
nbaker | 12:fd39a7983e06 | 1420 | Name: ButtonSlide() |
nbaker | 12:fd39a7983e06 | 1421 | Purpose: Routine called when MK46 recieves a ButtonSlide interrupt from KW40, which |
nbaker | 12:fd39a7983e06 | 1422 | we never get. |
nbaker | 12:fd39a7983e06 | 1423 | Inputs: None |
nbaker | 12:fd39a7983e06 | 1424 | Returns: None |
nbaker | 12:fd39a7983e06 | 1425 | ******************************************************************************/ |
nbaker | 0:d1d36a3da39b | 1426 | void ButtonSlide(void) // What is this Slide button??? |
nbaker | 0:d1d36a3da39b | 1427 | { |
asong | 1:e4b38d6918ba | 1428 | Screen_Timer.attach(&timout_timer,(SCRN_TIME));//Is this sufficient to reset/restart ticker timer for OLED? |
nbaker | 13:37cd579208e9 | 1429 | oled.DimScreenOFF(); |
asong | 1:e4b38d6918ba | 1430 | if (OLED_ON == 0) { |
asong | 1:e4b38d6918ba | 1431 | OLED_ON = 1; // Screen was off, set to On |
asong | 1:e4b38d6918ba | 1432 | } |
nbaker | 0:d1d36a3da39b | 1433 | StartHaptic(); |
nbaker | 0:d1d36a3da39b | 1434 | oled.FillScreen(COLOR_BLACK); // Clear screen |
nbaker | 0:d1d36a3da39b | 1435 | strcpy((char *) text_1,"Slide Button"); |
nbaker | 0:d1d36a3da39b | 1436 | oled.Label((uint8_t *)text_1,0,40); |
nbaker | 12:fd39a7983e06 | 1437 | }// end ButtonSlide |
asong | 1:e4b38d6918ba | 1438 | |
nbaker | 0:d1d36a3da39b | 1439 | int main() |
nbaker | 0:d1d36a3da39b | 1440 | { |
nbaker | 13:37cd579208e9 | 1441 | //__STATIC_INLINE void __set_PMCTRL(0b01000000);// set K64 SMC_PMCTRL register to VLPR (Very low power run) mode |
nbaker | 13:37cd579208e9 | 1442 | // SMC->PMCTRL = (uint8_t)((SYSTEM_SMC_PMCTRL_VALUE) & (SMC_PMCTRL_RUNM_MASK)); // Enable VLPR mode |
nbaker | 16:537ef0c72084 | 1443 | // SMC->PMCTRL = (0b01000000);// set K64 SMC_PMCTRL register to VLPR (Very low power run) mode << did nothing for battery time |
nbaker | 13:37cd579208e9 | 1444 | |
nbaker | 13:37cd579208e9 | 1445 | //set_time(1256729737); // Set RTC time to Wed, 28 Oct 2009 11:35:37 |
nbaker | 13:37cd579208e9 | 1446 | //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 | 1447 | //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 | 1448 | //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 | 1449 | //set_time((2018-1970)*365.25f*24*3600 + (31+28+26-1)*24*3600 + (10)*3600 + (0)*60+ (0) + 28); // Set RTC time to 3/26/2018 9:59:31 |
nbaker | 19:87ab6daf98e5 | 1450 | // set_time((2018-1970)*365.25f*24*3600 + (31+28+31+18-1)*24*3600 + (10)*3600 + (0)*60+ (0) + 29); // Set RTC time to 4/18/2018 9:59:31 |
nbaker | 19:87ab6daf98e5 | 1451 | set_time((2018-1970)*365.25f*24*3600 + (31+28+31+30+10-1)*24*3600 + (13)*3600 + (15)*60+ (0) + 29); // Set RTC time to 5/10/2018 9:59:31 |
nbaker | 9:d2e39ee9fedd | 1452 | RED_Led = LED_OFF; |
nbaker | 9:d2e39ee9fedd | 1453 | GRN_Led = LED_OFF; |
nbaker | 9:d2e39ee9fedd | 1454 | BLU_Led = LED_OFF; |
nbaker | 9:d2e39ee9fedd | 1455 | Led_clk1 = 0; // LEDs on docking station default to off, need to turn on with a 1 |
nbaker | 9:d2e39ee9fedd | 1456 | Led_clk2 = 0; // LEDs on docking station default to off, need to turn on with a 1 |
nbaker | 9:d2e39ee9fedd | 1457 | Led_clk3 = 0; // LEDs on docking station default to off, need to turn on with a 1 |
jmr274 | 5:e1431272be79 | 1458 | |
nbaker | 9:d2e39ee9fedd | 1459 | // ***************** Reset sensors *********************** |
nbaker | 9:d2e39ee9fedd | 1460 | OLED_PWR = 0; // Turn off OLED power supply |
nbaker | 9:d2e39ee9fedd | 1461 | PowerEN = 1; // Turn off (=1)HTU21(Temp/Hum) and TSL2561(Light) sensors to reset them |
asong | 14:c3b080cdf36b | 1462 | maxim = 0; // Turn off (=0) Heart rate sensor 1.8V and HRM(3.3V) supply to reset |
nbaker | 9:d2e39ee9fedd | 1463 | wait(0.2); // how long should we wait for sensors to power down? |
jmr274 | 5:e1431272be79 | 1464 | |
nbaker | 9:d2e39ee9fedd | 1465 | PowerEN = 0; // Turn on (=0) HTU21(Temp/Hum) and TSL2561(Light) sensors to reset them |
asong | 14:c3b080cdf36b | 1466 | // maxim = 1; // Turn on (=1)Heart rate sensor |
nbaker | 9:d2e39ee9fedd | 1467 | OLED_PWR = 1; // Turn on OLED power supply |
nbaker | 9:d2e39ee9fedd | 1468 | wait(0.2); // how long should we wait for sensors to power up? |
nbaker | 9:d2e39ee9fedd | 1469 | |
nbaker | 9:d2e39ee9fedd | 1470 | oled.FillScreen(COLOR_BLACK); // Clear screen |
nbaker | 10:eaea844e763c | 1471 | fall_config(10); // SW reset accell and gyro sensor |
nbaker | 10:eaea844e763c | 1472 | // gyro_sensor_config(10); // SW reset gyro sensor |
nbaker | 9:d2e39ee9fedd | 1473 | press_config(0); // put pressure sensor into 2uA standby, we're not using it |
nbaker | 16:537ef0c72084 | 1474 | // MAX30101_test_config(10); // SW reset HR sensor << power is off |
nbaker | 9:d2e39ee9fedd | 1475 | oled.FillScreen(COLOR_BLACK); // Clear screen |
nbaker | 9:d2e39ee9fedd | 1476 | |
asong | 1:e4b38d6918ba | 1477 | // ***************** Local variables *********************** |
asong | 1:e4b38d6918ba | 1478 | // float accel_data[3]; float accel_rms=0.0; |
nbaker | 4:0803151bc5e4 | 1479 | int i; |
nbaker | 4:0803151bc5e4 | 1480 | |
nbaker | 0:d1d36a3da39b | 1481 | // ************** configure sensor modules ****************** |
asong | 1:e4b38d6918ba | 1482 | |
nbaker | 10:eaea844e763c | 1483 | //accel.accel_config(); // original configure accel sensor |
nbaker | 9:d2e39ee9fedd | 1484 | fall_config(Fall_Alert_Mode); // configure sensor (I2C1) for current fall mode |
nbaker | 10:eaea844e763c | 1485 | //Fall_Alert_Mode: 0=none, 1=fall_only, 2=impact only, 3=motion_only, 4=all three, 5=full sequencial |
nbaker | 10:eaea844e763c | 1486 | //gyro.gyro_config(); // original configure gyro sensor |
nbaker | 10:eaea844e763c | 1487 | //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 | 1488 | //mag.mag_config(); // we don't need mag |
nbaker | 10:eaea844e763c | 1489 | //light_config(0); // config TSL2561 ambient light sensor (I2C0) for lowest power - cycling PowerEn should have reset it to state |
nbaker | 10:eaea844e763c | 1490 | //Configure HTU21(Temp/Hum)? No need, it seems to draw 0.02uA when not being activly read over data bus |
nbaker | 8:a5c77b45008d | 1491 | |
nbaker | 9:d2e39ee9fedd | 1492 | // need to configure MAX30101 at some point |
nbaker | 9:d2e39ee9fedd | 1493 | // MAX30101_test_config(0); |
nbaker | 9:d2e39ee9fedd | 1494 | |
nbaker | 9:d2e39ee9fedd | 1495 | |
nbaker | 0:d1d36a3da39b | 1496 | // ***** Register callbacks/interupts to application functions ********* |
nbaker | 0:d1d36a3da39b | 1497 | kw40z_device.attach_buttonUp(&ButtonUp); |
nbaker | 0:d1d36a3da39b | 1498 | kw40z_device.attach_buttonDown(&ButtonDown); |
nbaker | 0:d1d36a3da39b | 1499 | kw40z_device.attach_buttonLeft(&ButtonLeft); |
nbaker | 0:d1d36a3da39b | 1500 | kw40z_device.attach_buttonRight(&ButtonRight); |
nbaker | 4:0803151bc5e4 | 1501 | // kw40z_device.attach_buttonSlide(&ButtonSlide); |
nbaker | 19:87ab6daf98e5 | 1502 | // kw40z_device.attach_alert(&TimeSet); |
nbaker | 19:87ab6daf98e5 | 1503 | //kw40z_device.attach_alertIn(&TimeSet); |
nbaker | 11:ccda4d44bd8e | 1504 | kw40z_device.attach_passkey(&PassKey); |
nbaker | 4:0803151bc5e4 | 1505 | |
nbaker | 4:0803151bc5e4 | 1506 | // ***** attaching interupts to functions ********* |
nbaker | 10:eaea844e763c | 1507 | //Accel_INT1.fall(&fall_detect); // Accel sensor's int#1 (PTC1) calls interupt routine (now setup in fall_config()) |
nbaker | 10:eaea844e763c | 1508 | //Accel_INT2.fall(&impact_detect); //Accel sensor's int#2 (PTD13) calls interupt routine(now setup in fall_config()) |
nbaker | 10:eaea844e763c | 1509 | //Gyro_INT1.fall(&motion_detect); // Gyro sensor's int#1 (PTD1) calls interupt routine (now setup in fall_config()) |
nbaker | 10:eaea844e763c | 1510 | //Gyro_INT2.fall(&motion_detect); // Gyro sensor's int#2 (PTC18) calls interupt routine (not used) |
nbaker | 10:eaea844e763c | 1511 | //HR_INT1.fall(&some_HR_read_function_yet_to_be_named); // MAX30101 - Heart rate sensor's interupt (PTB18) |
nbaker | 0:d1d36a3da39b | 1512 | |
nbaker | 11:ccda4d44bd8e | 1513 | |
nbaker | 11:ccda4d44bd8e | 1514 | |
nbaker | 0:d1d36a3da39b | 1515 | // **** Get OLED Class Default Text Properties **************** |
asong | 1:e4b38d6918ba | 1516 | oled_text_properties_t textProperties = {0}; |
asong | 1:e4b38d6918ba | 1517 | oled.GetTextProperties(&textProperties); |
asong | 1:e4b38d6918ba | 1518 | |
nbaker | 0:d1d36a3da39b | 1519 | // *********Set text color and screen alignment ************** |
nbaker | 9:d2e39ee9fedd | 1520 | //textProperties.font = OpenSans_12x18_Regular; // Max Width of Character = 12px, Max Height of Character = 18px |
nbaker | 9:d2e39ee9fedd | 1521 | //textProperties.font = OpenSans_10x15_Regular; // <-This is default Font, Max Width of Character = 10px, Max Height of Character = 15px |
asong | 1:e4b38d6918ba | 1522 | textProperties.fontColor = COLOR_WHITE; |
asong | 1:e4b38d6918ba | 1523 | textProperties.alignParam = OLED_TEXT_ALIGN_LEFT; |
asong | 1:e4b38d6918ba | 1524 | oled.SetTextProperties(&textProperties); |
asong | 1:e4b38d6918ba | 1525 | |
nbaker | 0:d1d36a3da39b | 1526 | // ************** Display spash screen ********************** |
nbaker | 9:d2e39ee9fedd | 1527 | /* |
nbaker | 9:d2e39ee9fedd | 1528 | oled.FillScreen(COLOR_BLACK); // Clear screen |
nbaker | 9:d2e39ee9fedd | 1529 | oled.DrawImage(Hexi_Heart_,0,0); // my Hexi_Heart image is offset for some reason |
nbaker | 16:537ef0c72084 | 1530 | wait(0.5); // wait 0.5 seconds |
nbaker | 9:d2e39ee9fedd | 1531 | */ |
nbaker | 8:a5c77b45008d | 1532 | oled.FillScreen(COLOR_BLACK); // Clear screen |
nbaker | 12:fd39a7983e06 | 1533 | |
nbaker | 12:fd39a7983e06 | 1534 | textProperties.font = OpenSans_12x18_Regular; // Max Width of Character = 12px, Max Height of Character = 18px |
nbaker | 12:fd39a7983e06 | 1535 | oled.SetTextProperties(&textProperties); |
nbaker | 12:fd39a7983e06 | 1536 | oled.Label((uint8_t *)"Hexi",18,5); // Display white "Hexi" at x,y |
nbaker | 0:d1d36a3da39b | 1537 | textProperties.fontColor = COLOR_RED; |
asong | 1:e4b38d6918ba | 1538 | oled.SetTextProperties(&textProperties); |
nbaker | 12:fd39a7983e06 | 1539 | oled.Label((uint8_t *)"Heart",47,5); // Display red "Heart" at x,y |
nbaker | 12:fd39a7983e06 | 1540 | textProperties.font = OpenSans_10x15_Regular; // Max Width of Character = 10px, Max Height of Character = 15px |
nbaker | 12:fd39a7983e06 | 1541 | oled.SetTextProperties(&textProperties); |
nbaker | 0:d1d36a3da39b | 1542 | |
nbaker | 12:fd39a7983e06 | 1543 | strcpy((char *) text_1,"This is a"); |
nbaker | 12:fd39a7983e06 | 1544 | oled.Label((uint8_t *)text_1,19,25); // text_1 at x,y |
nbaker | 12:fd39a7983e06 | 1545 | strcpy((char *) text_1,"Demo Proj"); |
nbaker | 12:fd39a7983e06 | 1546 | oled.Label((uint8_t *)text_1,15,40); // text_1 at x,y |
nbaker | 12:fd39a7983e06 | 1547 | strcpy((char *) text_1,"SW_Ver:"); |
nbaker | 12:fd39a7983e06 | 1548 | oled.Label((uint8_t *)text_1,10,70); // text_1 at x,y |
nbaker | 12:fd39a7983e06 | 1549 | textProperties.fontColor = COLOR_MAGENTA; |
nbaker | 12:fd39a7983e06 | 1550 | oled.SetTextProperties(&textProperties); |
nbaker | 9:d2e39ee9fedd | 1551 | sprintf(text_1,"%2.2f ",SW_Ver); |
nbaker | 12:fd39a7983e06 | 1552 | oled.Label((uint8_t *)text_1,60,70);// text_1 at x,y |
nbaker | 8:a5c77b45008d | 1553 | StartHaptic(); |
nbaker | 8:a5c77b45008d | 1554 | |
nbaker | 0:d1d36a3da39b | 1555 | textProperties.fontColor = COLOR_WHITE; |
nbaker | 0:d1d36a3da39b | 1556 | oled.SetTextProperties(&textProperties); |
nbaker | 9:d2e39ee9fedd | 1557 | wait(2); // wait 3 seconds |
nbaker | 9:d2e39ee9fedd | 1558 | |
nbaker | 11:ccda4d44bd8e | 1559 | // txThread.start(txTask); /*Start transmitting Sensor Tag Data */ |
nbaker | 13:37cd579208e9 | 1560 | oled.DimScreenOFF(); |
asong | 1:e4b38d6918ba | 1561 | update_display(); // Displays current screen (screen 0) |
nbaker | 13:37cd579208e9 | 1562 | UpDate_Ave(); // Update slow changing measurements once every 30 seconds |
nbaker | 12:fd39a7983e06 | 1563 | Screen_Timer.attach(&timout_timer,(SCRN_TIME)); //start ticker timer for turning off LCD |
nbaker | 12:fd39a7983e06 | 1564 | WDT_Timer.attach(&WDT_Timeout,(WDT_TIME)); //attach/start WDT |
asong | 1:e4b38d6918ba | 1565 | // ******************* Main Loop ************************* |
nbaker | 0:d1d36a3da39b | 1566 | while (true) { |
nbaker | 4:0803151bc5e4 | 1567 | i=0; |
nbaker | 4:0803151bc5e4 | 1568 | while (i<20)// used for "Heart beat flash and updated any displayed data) |
nbaker | 4:0803151bc5e4 | 1569 | { |
nbaker | 4:0803151bc5e4 | 1570 | Thread::wait(500); // wait 0.5 sec each loop |
nbaker | 12:fd39a7983e06 | 1571 | CLRWDT(); |
nbaker | 16:537ef0c72084 | 1572 | |
nbaker | 4:0803151bc5e4 | 1573 | if(OLED_PWR==1){ |
nbaker | 16:537ef0c72084 | 1574 | update_display_date(); // refresh display data twice a second w/o updating entire display |
nbaker | 4:0803151bc5e4 | 1575 | }// end if |
nbaker | 9:d2e39ee9fedd | 1576 | |
nbaker | 4:0803151bc5e4 | 1577 | i++; |
nbaker | 16:537ef0c72084 | 1578 | }// end 10 second while(i<20) loop |
nbaker | 16:537ef0c72084 | 1579 | if(maxim==0){// don't use red LED while heart rate zone routine is active |
nbaker | 4:0803151bc5e4 | 1580 | RED_Led = LED_ON; // Used only for diagnostic of wait command |
nbaker | 16:537ef0c72084 | 1581 | } |
nbaker | 4:0803151bc5e4 | 1582 | Led_clk3 = 1; // Used only for diagnostic of wait command |
nbaker | 4:0803151bc5e4 | 1583 | wait(0.01); // BLIP led 1/10 sec each loop |
nbaker | 16:537ef0c72084 | 1584 | if(maxim==0){// don't use red LED while heart rate zone routine is active |
nbaker | 4:0803151bc5e4 | 1585 | RED_Led = LED_OFF; // Used only for diagnostic of wait command |
nbaker | 16:537ef0c72084 | 1586 | } |
nbaker | 4:0803151bc5e4 | 1587 | Led_clk3 = 0; |
nbaker | 16:537ef0c72084 | 1588 | |
nbaker | 8:a5c77b45008d | 1589 | Thread::wait(490); // keep up the pace, at 0.5 sec (0.01s+0.49s) update date |
nbaker | 13:37cd579208e9 | 1590 | |
nbaker | 12:fd39a7983e06 | 1591 | CLRWDT(); |
nbaker | 16:537ef0c72084 | 1592 | UpDate_Ave(); // Update slow changing measurements once every 10.5 seconds |
nbaker | 4:0803151bc5e4 | 1593 | } // end of while(true) |
nbaker | 4:0803151bc5e4 | 1594 | |
nbaker | 0:d1d36a3da39b | 1595 | } |
nbaker | 0:d1d36a3da39b | 1596 | // ************** end of main() |
nbaker | 0:d1d36a3da39b | 1597 | |
nbaker | 0:d1d36a3da39b | 1598 | void update_display(void) |
nbaker | 0:d1d36a3da39b | 1599 | { |
nbaker | 4:0803151bc5e4 | 1600 | OLED_PWR = 1; // make sure OLED power supply is on |
asong | 1:e4b38d6918ba | 1601 | oled_text_properties_t textProperties = {0}; // Need these to change font color |
asong | 1:e4b38d6918ba | 1602 | oled.GetTextProperties(&textProperties); // Need these to change font color |
nbaker | 8:a5c77b45008d | 1603 | __disable_irq(); // Disable all Interrupts |
asong | 1:e4b38d6918ba | 1604 | switch(Screen_Num) { |
asong | 1:e4b38d6918ba | 1605 | case 0: {// Main Screen |
nbaker | 4:0803151bc5e4 | 1606 | HexiwearBattery battery; |
nbaker | 4:0803151bc5e4 | 1607 | battery.sensorOn(); |
asong | 1:e4b38d6918ba | 1608 | oled.FillScreen(COLOR_BLACK); // Clear screen |
nbaker | 4:0803151bc5e4 | 1609 | |
nbaker | 4:0803151bc5e4 | 1610 | if (battery.isBatteryCharging()) { |
nbaker | 4:0803151bc5e4 | 1611 | textProperties.fontColor = COLOR_GREEN; |
nbaker | 4:0803151bc5e4 | 1612 | oled.SetTextProperties(&textProperties); |
nbaker | 4:0803151bc5e4 | 1613 | // sprintf(text_1, "%s", "chrg"); |
nbaker | 13:37cd579208e9 | 1614 | sprintf(text_1, "%i%%+", batt_per_level); |
nbaker | 4:0803151bc5e4 | 1615 | Screen_Timer.attach(&timout_timer,(SCRN_TIME));// Reset/restart ticker timer for OLED while fully charged |
nbaker | 13:37cd579208e9 | 1616 | oled.DimScreenOFF(); |
nbaker | 4:0803151bc5e4 | 1617 | } else { |
nbaker | 13:37cd579208e9 | 1618 | sprintf(text_1, "%i%%", batt_per_level); |
nbaker | 4:0803151bc5e4 | 1619 | } |
nbaker | 8:a5c77b45008d | 1620 | 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 | 1621 | |
nbaker | 4:0803151bc5e4 | 1622 | textProperties.fontColor = COLOR_WHITE; |
nbaker | 4:0803151bc5e4 | 1623 | oled.SetTextProperties(&textProperties); |
nbaker | 4:0803151bc5e4 | 1624 | |
nbaker | 4:0803151bc5e4 | 1625 | oled.Label((uint8_t *)"Batt",35,0); // Display "Batt" at x,y |
nbaker | 9:d2e39ee9fedd | 1626 | // oled.Label((uint8_t *)"Date",35,20); // Display "Date" at x,y |
nbaker | 9:d2e39ee9fedd | 1627 | // oled.Label((uint8_t *)"Time",35,40); // Display "Time" at x,y |
jmr274 | 5:e1431272be79 | 1628 | // oled.Label((uint8_t *)"H.I.",10,80); // Display "H.I." at x,y |
nbaker | 7:3d5a8aea0b63 | 1629 | |
asong | 1:e4b38d6918ba | 1630 | oled.Label((uint8_t *)"BT",40,80); //Display "BT" at x,y |
asong | 1:e4b38d6918ba | 1631 | oled.Label((uint8_t *)"Menu",60,80); //Display "Menu" at x,y |
jmr274 | 5:e1431272be79 | 1632 | |
nbaker | 7:3d5a8aea0b63 | 1633 | textProperties.fontColor = COLOR_GRAY; |
nbaker | 8:a5c77b45008d | 1634 | if(BLE_On == 1){ |
nbaker | 9:d2e39ee9fedd | 1635 | textProperties.fontColor = COLOR_BLUE; // If BLE on make "BT" blue! |
nbaker | 8:a5c77b45008d | 1636 | } |
nbaker | 7:3d5a8aea0b63 | 1637 | oled.SetTextProperties(&textProperties); |
nbaker | 8:a5c77b45008d | 1638 | |
nbaker | 7:3d5a8aea0b63 | 1639 | oled.Label((uint8_t *)"BT",40,80); //Display "BT" at x,y |
nbaker | 7:3d5a8aea0b63 | 1640 | textProperties.fontColor = COLOR_WHITE; |
nbaker | 7:3d5a8aea0b63 | 1641 | oled.SetTextProperties(&textProperties); |
nbaker | 10:eaea844e763c | 1642 | |
nbaker | 10:eaea844e763c | 1643 | textProperties.fontColor = COLOR_GRAY; |
nbaker | 10:eaea844e763c | 1644 | if(Fall_Alert == 1){ |
nbaker | 10:eaea844e763c | 1645 | textProperties.fontColor = COLOR_GREEN; // is Fall protection on? |
nbaker | 10:eaea844e763c | 1646 | } |
nbaker | 10:eaea844e763c | 1647 | if(Fall_Alert == 1 && Led_clk1 == 1){ |
nbaker | 10:eaea844e763c | 1648 | textProperties.fontColor = COLOR_YELLOW; // is Fall detected? |
nbaker | 10:eaea844e763c | 1649 | } |
nbaker | 10:eaea844e763c | 1650 | if(Fall_Alert == 1 && Led_clk1 == 1 && Led_clk2 == 1){ |
nbaker | 10:eaea844e763c | 1651 | textProperties.fontColor = COLOR_RED; // is impact detected? |
nbaker | 10:eaea844e763c | 1652 | } |
nbaker | 10:eaea844e763c | 1653 | oled.SetTextProperties(&textProperties); |
nbaker | 19:87ab6daf98e5 | 1654 | oled.Label((uint8_t *)"AFP",3,0); //Display "FAP" at x,y |
nbaker | 10:eaea844e763c | 1655 | textProperties.fontColor = COLOR_WHITE; |
nbaker | 10:eaea844e763c | 1656 | oled.SetTextProperties(&textProperties); |
nbaker | 7:3d5a8aea0b63 | 1657 | |
nbaker | 7:3d5a8aea0b63 | 1658 | // added real time and date information |
nbaker | 7:3d5a8aea0b63 | 1659 | char buffer[32]; |
nbaker | 7:3d5a8aea0b63 | 1660 | time_t seconds = time(NULL); |
nbaker | 9:d2e39ee9fedd | 1661 | strftime(buffer,32, "%a,%d %m %Y.%H:%M:%S\r", localtime(&seconds)); //format local time and store in buffer |
nbaker | 9:d2e39ee9fedd | 1662 | |
nbaker | 9:d2e39ee9fedd | 1663 | textProperties.font = OpenSans_12x18_Regular; // Max Width of Character = 12px, Max Height of Character = 18px |
nbaker | 9:d2e39ee9fedd | 1664 | textProperties.fontColor = COLOR_WHITE; |
nbaker | 9:d2e39ee9fedd | 1665 | oled.SetTextProperties(&textProperties); |
nbaker | 9:d2e39ee9fedd | 1666 | |
nbaker | 7:3d5a8aea0b63 | 1667 | 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 | 1668 | oled.Label((uint8_t *)text_1,15,25);// Date at x,y |
nbaker | 7:3d5a8aea0b63 | 1669 | sprintf(text_1,"%c%c:%c%c:%c%c ",buffer[15],buffer[16],buffer[18],buffer[19],buffer[21],buffer[22]); |
nbaker | 7:3d5a8aea0b63 | 1670 | oled.Label((uint8_t *)text_1,25,40);// Time at x,y |
nbaker | 9:d2e39ee9fedd | 1671 | |
nbaker | 9:d2e39ee9fedd | 1672 | textProperties.font = OpenSans_10x15_Regular; // Max Width of Character = 10px, Max Height of Character = 15px |
nbaker | 9:d2e39ee9fedd | 1673 | textProperties.fontColor = COLOR_WHITE; |
nbaker | 9:d2e39ee9fedd | 1674 | oled.SetTextProperties(&textProperties); |
nbaker | 9:d2e39ee9fedd | 1675 | |
jmr274 | 5:e1431272be79 | 1676 | Heat_Index_Calculation(); |
jmr274 | 5:e1431272be79 | 1677 | sprintf(text,"%i",heat_index); |
asong | 15:330794a9f347 | 1678 | oled.Label((uint8_t *)text,3,80);// HI at x,y |
asong | 15:330794a9f347 | 1679 | //oled.TextBox((uint8_t *)text,3,80); //show HI in a 15px by 15px text box at x=3, y=80 |
asong | 15:330794a9f347 | 1680 | strcpy((char *) text,"F"); |
asong | 15:330794a9f347 | 1681 | oled.Label((uint8_t *)text,25,80); // was "dF" at 18,80 |
jmr274 | 5:e1431272be79 | 1682 | |
asong | 1:e4b38d6918ba | 1683 | if(Heart_Rate_Mode == 1) { |
asong | 20:990951205fbd | 1684 | sprintf(text,"%i",Heart_Rate); |
asong | 20:990951205fbd | 1685 | if(Current_Zone == 1) { |
asong | 20:990951205fbd | 1686 | textProperties.fontColor = COLOR_YELLOW; |
asong | 20:990951205fbd | 1687 | oled.SetTextProperties(&textProperties); |
asong | 20:990951205fbd | 1688 | } else if(Current_Zone == 2) { |
asong | 20:990951205fbd | 1689 | textProperties.fontColor = COLOR_BLUE; |
asong | 20:990951205fbd | 1690 | oled.SetTextProperties(&textProperties); |
asong | 20:990951205fbd | 1691 | } else if(Current_Zone == 3) { |
asong | 20:990951205fbd | 1692 | textProperties.fontColor = COLOR_GREEN; |
asong | 20:990951205fbd | 1693 | oled.SetTextProperties(&textProperties); |
asong | 20:990951205fbd | 1694 | } else if(Current_Zone == 4) { |
asong | 20:990951205fbd | 1695 | textProperties.fontColor = COLOR_RED; |
asong | 20:990951205fbd | 1696 | oled.SetTextProperties(&textProperties); |
asong | 20:990951205fbd | 1697 | } |
asong | 20:990951205fbd | 1698 | oled.Label((uint8_t *)text,35,60); |
asong | 20:990951205fbd | 1699 | textProperties.fontColor = COLOR_WHITE; |
asong | 20:990951205fbd | 1700 | oled.SetTextProperties(&textProperties); |
asong | 1:e4b38d6918ba | 1701 | } |
asong | 1:e4b38d6918ba | 1702 | break; |
asong | 1:e4b38d6918ba | 1703 | } |
asong | 1:e4b38d6918ba | 1704 | case 1: {// Panic Alert option |
asong | 1:e4b38d6918ba | 1705 | oled.FillScreen(COLOR_BLACK); // Clear screen |
nbaker | 12:fd39a7983e06 | 1706 | oled.Label((uint8_t *)"Panic Alert",18,5); // Display at x,y |
asong | 1:e4b38d6918ba | 1707 | oled.Label((uint8_t *)"*",85,15); // "*" at x,y |
asong | 1:e4b38d6918ba | 1708 | oled.Label((uint8_t *)"*",85,60); // "*" at x,y |
asong | 1:e4b38d6918ba | 1709 | oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y |
asong | 1:e4b38d6918ba | 1710 | oled.Label((uint8_t *)"Enter",60,80); //Display "enter" at x,y |
asong | 1:e4b38d6918ba | 1711 | break; |
asong | 1:e4b38d6918ba | 1712 | } |
asong | 1:e4b38d6918ba | 1713 | case 2: {// Fall Alert option |
asong | 1:e4b38d6918ba | 1714 | oled.FillScreen(COLOR_BLACK); // Clear screen |
asong | 1:e4b38d6918ba | 1715 | oled.Label((uint8_t *)"Fall Alert",20,5); // Display at x,y |
nbaker | 9:d2e39ee9fedd | 1716 | oled.Label((uint8_t *)"Protection",15,20); |
nbaker | 19:87ab6daf98e5 | 1717 | oled.Label((uint8_t *)"AFP",15,40); |
nbaker | 4:0803151bc5e4 | 1718 | if (Fall_Alert == 1){ |
nbaker | 9:d2e39ee9fedd | 1719 | |
nbaker | 9:d2e39ee9fedd | 1720 | textProperties.fontColor = COLOR_GREEN; |
nbaker | 9:d2e39ee9fedd | 1721 | oled.SetTextProperties(&textProperties); |
nbaker | 10:eaea844e763c | 1722 | oled.Label((uint8_t *)" On ",42,40); |
nbaker | 4:0803151bc5e4 | 1723 | } |
nbaker | 4:0803151bc5e4 | 1724 | else { |
nbaker | 9:d2e39ee9fedd | 1725 | textProperties.fontColor = COLOR_GRAY; |
nbaker | 9:d2e39ee9fedd | 1726 | oled.SetTextProperties(&textProperties); |
nbaker | 10:eaea844e763c | 1727 | oled.Label((uint8_t *)" Off ",40,40); |
nbaker | 9:d2e39ee9fedd | 1728 | |
nbaker | 4:0803151bc5e4 | 1729 | } |
nbaker | 9:d2e39ee9fedd | 1730 | textProperties.fontColor = COLOR_WHITE; |
nbaker | 9:d2e39ee9fedd | 1731 | oled.SetTextProperties(&textProperties); |
asong | 1:e4b38d6918ba | 1732 | oled.Label((uint8_t *)"*",85,15); // "*" at x,y |
asong | 1:e4b38d6918ba | 1733 | oled.Label((uint8_t *)"*",85,60); // "*" at x,y |
asong | 1:e4b38d6918ba | 1734 | oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y |
nbaker | 9:d2e39ee9fedd | 1735 | oled.Label((uint8_t *)"Toggle",59,80); //Display "Toggle" at x,y |
asong | 1:e4b38d6918ba | 1736 | break; |
asong | 1:e4b38d6918ba | 1737 | } |
asong | 1:e4b38d6918ba | 1738 | case 3: {// Heart Rate Monitoring option |
asong | 1:e4b38d6918ba | 1739 | oled.FillScreen(COLOR_BLACK); // Clear screen |
nbaker | 12:fd39a7983e06 | 1740 | oled.Label((uint8_t *)"Heart Rate",18,5); // Display at x,y |
asong | 1:e4b38d6918ba | 1741 | oled.Label((uint8_t *)"*",85,15); // "*" at x,y |
asong | 1:e4b38d6918ba | 1742 | oled.Label((uint8_t *)"*",85,60); // "*" at x,y |
asong | 1:e4b38d6918ba | 1743 | oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y |
asong | 1:e4b38d6918ba | 1744 | oled.Label((uint8_t *)"Enter",60,80); //Display at x,y |
asong | 1:e4b38d6918ba | 1745 | break; |
asong | 1:e4b38d6918ba | 1746 | } |
asong | 1:e4b38d6918ba | 1747 | case 4: {// Alert History option |
asong | 1:e4b38d6918ba | 1748 | oled.FillScreen(COLOR_BLACK); // Clear screen |
nbaker | 7:3d5a8aea0b63 | 1749 | oled.Label((uint8_t *)"Alert History",10,5); // Display at x,y |
asong | 1:e4b38d6918ba | 1750 | oled.Label((uint8_t *)"*",85,15); // "*" at x,y |
asong | 1:e4b38d6918ba | 1751 | oled.Label((uint8_t *)"*",85,60); // "*" at x,y |
asong | 1:e4b38d6918ba | 1752 | oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y |
asong | 1:e4b38d6918ba | 1753 | oled.Label((uint8_t *)"Enter",60,80); //Display at x,y |
asong | 1:e4b38d6918ba | 1754 | break; |
asong | 1:e4b38d6918ba | 1755 | } |
asong | 1:e4b38d6918ba | 1756 | case 5: {// About HexiHeart Screen |
nbaker | 0:d1d36a3da39b | 1757 | |
asong | 1:e4b38d6918ba | 1758 | oled.FillScreen(COLOR_BLACK); // Clear screen |
asong | 1:e4b38d6918ba | 1759 | oled.Label((uint8_t *)"Hexi",20,20); // Display white "Hexi" at x,y |
asong | 1:e4b38d6918ba | 1760 | textProperties.fontColor = COLOR_RED; |
asong | 1:e4b38d6918ba | 1761 | oled.SetTextProperties(&textProperties); |
asong | 1:e4b38d6918ba | 1762 | oled.Label((uint8_t *)"Heart",45,20); // Display red "Heart" at x,y |
asong | 1:e4b38d6918ba | 1763 | textProperties.fontColor = COLOR_WHITE; |
asong | 1:e4b38d6918ba | 1764 | oled.SetTextProperties(&textProperties); |
asong | 1:e4b38d6918ba | 1765 | strcpy((char *) text_1,"About"); |
asong | 1:e4b38d6918ba | 1766 | oled.Label((uint8_t *)text_1,30,5); // text_1 at x,y |
asong | 1:e4b38d6918ba | 1767 | oled.Label((uint8_t *)"*",85,15); // "*" at x,y |
asong | 1:e4b38d6918ba | 1768 | oled.Label((uint8_t *)"*",85,60); // "*" at x,y |
nbaker | 9:d2e39ee9fedd | 1769 | oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y |
nbaker | 9:d2e39ee9fedd | 1770 | oled.Label((uint8_t *)"Enter",60,80); //Display at x,y |
asong | 1:e4b38d6918ba | 1771 | break; |
asong | 1:e4b38d6918ba | 1772 | } |
asong | 1:e4b38d6918ba | 1773 | |
asong | 1:e4b38d6918ba | 1774 | case 6: {// Panic Alert |
asong | 1:e4b38d6918ba | 1775 | oled.FillScreen(COLOR_BLACK); // Clear screen |
nbaker | 13:37cd579208e9 | 1776 | oled.Label((uint8_t *)"Send ",20,10); // Display at x,y |
asong | 1:e4b38d6918ba | 1777 | oled.Label((uint8_t *)"Panic Alert",15,40); // Display at x,y |
asong | 1:e4b38d6918ba | 1778 | oled.Label((uint8_t *)"-->",80,15); // "*" at x,y |
asong | 1:e4b38d6918ba | 1779 | oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y |
asong | 1:e4b38d6918ba | 1780 | break; |
asong | 1:e4b38d6918ba | 1781 | } |
asong | 14:c3b080cdf36b | 1782 | case 7: {// Heart Rate Zone |
asong | 1:e4b38d6918ba | 1783 | |
asong | 1:e4b38d6918ba | 1784 | oled.FillScreen(COLOR_BLACK); // Clear screen |
asong | 14:c3b080cdf36b | 1785 | textProperties.fontColor = COLOR_WHITE; |
asong | 14:c3b080cdf36b | 1786 | oled.SetTextProperties(&textProperties); |
nbaker | 12:fd39a7983e06 | 1787 | oled.Label((uint8_t *)"Heart Rate",18,5); // Display at x,y |
asong | 14:c3b080cdf36b | 1788 | oled.Label((uint8_t *)"HR:",10,25); // Display at x,y |
asong | 2:824ed4ae8d52 | 1789 | sprintf(display_buff, "%u", Heart_Rate); |
asong | 21:76237b62466b | 1790 | if(Current_Zone == 1) { |
asong | 21:76237b62466b | 1791 | textProperties.fontColor = COLOR_YELLOW; |
asong | 21:76237b62466b | 1792 | oled.SetTextProperties(&textProperties); |
asong | 21:76237b62466b | 1793 | } else if(Current_Zone == 2) { |
asong | 21:76237b62466b | 1794 | textProperties.fontColor = COLOR_BLUE; |
asong | 21:76237b62466b | 1795 | oled.SetTextProperties(&textProperties); |
asong | 21:76237b62466b | 1796 | } else if(Current_Zone == 3) { |
asong | 21:76237b62466b | 1797 | textProperties.fontColor = COLOR_GREEN; |
asong | 21:76237b62466b | 1798 | oled.SetTextProperties(&textProperties); |
asong | 21:76237b62466b | 1799 | } else if(Current_Zone == 4) { |
asong | 21:76237b62466b | 1800 | textProperties.fontColor = COLOR_RED; |
asong | 21:76237b62466b | 1801 | oled.SetTextProperties(&textProperties); |
asong | 21:76237b62466b | 1802 | } |
asong | 2:824ed4ae8d52 | 1803 | oled.Label((uint8_t *)display_buff,43,25); // Display at x,y |
asong | 2:824ed4ae8d52 | 1804 | textProperties.fontColor = COLOR_WHITE; |
asong | 2:824ed4ae8d52 | 1805 | oled.SetTextProperties(&textProperties); |
asong | 14:c3b080cdf36b | 1806 | oled.Label((uint8_t *)"Age: ",10,45); // Display at x,y |
asong | 1:e4b38d6918ba | 1807 | textProperties.fontColor = COLOR_GREEN; |
asong | 1:e4b38d6918ba | 1808 | oled.SetTextProperties(&textProperties); //implements the color change |
asong | 1:e4b38d6918ba | 1809 | sprintf(display_buff, "%u", Age); //Convert int to char array for displaying user age |
asong | 1:e4b38d6918ba | 1810 | oled.Label((uint8_t *)display_buff,43,45); // Display at x,y |
asong | 1:e4b38d6918ba | 1811 | textProperties.fontColor = COLOR_WHITE; |
asong | 1:e4b38d6918ba | 1812 | oled.SetTextProperties(&textProperties); |
asong | 2:824ed4ae8d52 | 1813 | oled.Label((uint8_t *)"On",80,15); // "+" at x,y |
asong | 2:824ed4ae8d52 | 1814 | oled.Label((uint8_t *)"Off",78,60); // "-" at x,y |
asong | 14:c3b080cdf36b | 1815 | oled.Label((uint8_t *)"Menu",10,80); // Display "Back" at x,y |
nbaker | 9:d2e39ee9fedd | 1816 | oled.Label((uint8_t *)"Next",60,80); // Display "Next" at x,y |
asong | 1:e4b38d6918ba | 1817 | break; |
asong | 1:e4b38d6918ba | 1818 | } |
asong | 1:e4b38d6918ba | 1819 | case 8: {// Alert History |
asong | 1:e4b38d6918ba | 1820 | oled.FillScreen(COLOR_BLACK); // Clear screen |
asong | 1:e4b38d6918ba | 1821 | oled.Label((uint8_t *)"Alert History",5,5); // Display at x,y |
asong | 1:e4b38d6918ba | 1822 | oled.Label((uint8_t *)"Date - Time",20,40); // Display at x,y |
asong | 1:e4b38d6918ba | 1823 | oled.Label((uint8_t *)"Alert Type:",20,60); // Display at x,y |
asong | 1:e4b38d6918ba | 1824 | oled.Label((uint8_t *)"+",85,15); // "*" at x,y |
asong | 1:e4b38d6918ba | 1825 | oled.Label((uint8_t *)"-",85,60); // "*" at x,y |
asong | 1:e4b38d6918ba | 1826 | oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y |
asong | 1:e4b38d6918ba | 1827 | break; |
asong | 1:e4b38d6918ba | 1828 | } |
nbaker | 8:a5c77b45008d | 1829 | |
nbaker | 8:a5c77b45008d | 1830 | case 9: {// About HexiHeart info1 |
nbaker | 8:a5c77b45008d | 1831 | oled.FillScreen(COLOR_BLACK); // Clear screen |
nbaker | 8:a5c77b45008d | 1832 | oled.Label((uint8_t *)"Hexi",20,1); // Display white "Hexi" at x,y |
nbaker | 8:a5c77b45008d | 1833 | textProperties.fontColor = COLOR_RED; |
nbaker | 8:a5c77b45008d | 1834 | oled.SetTextProperties(&textProperties); |
nbaker | 8:a5c77b45008d | 1835 | oled.Label((uint8_t *)"Heart",45,0); // Display red "Heart" at x,y |
nbaker | 8:a5c77b45008d | 1836 | textProperties.fontColor = COLOR_WHITE; |
nbaker | 8:a5c77b45008d | 1837 | oled.SetTextProperties(&textProperties); |
nbaker | 8:a5c77b45008d | 1838 | oled.Label((uint8_t *)"Senior Proj",5,15); // |
nbaker | 9:d2e39ee9fedd | 1839 | oled.Label((uint8_t *)"Team Zeta E2.7",5,30); // |
nbaker | 8:a5c77b45008d | 1840 | oled.Label((uint8_t *)"Texas State Univ",0,45); // |
nbaker | 12:fd39a7983e06 | 1841 | oled.Label((uint8_t *)"*",85,15); // "*" at x,y |
nbaker | 12:fd39a7983e06 | 1842 | oled.Label((uint8_t *)"*",85,60); // "*" at x,y |
nbaker | 8:a5c77b45008d | 1843 | oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y |
nbaker | 8:a5c77b45008d | 1844 | break; |
nbaker | 8:a5c77b45008d | 1845 | } |
nbaker | 8:a5c77b45008d | 1846 | |
nbaker | 8:a5c77b45008d | 1847 | case 10: {// About HexiHeart info2 |
nbaker | 8:a5c77b45008d | 1848 | oled.FillScreen(COLOR_BLACK); // Clear screen |
nbaker | 8:a5c77b45008d | 1849 | oled.Label((uint8_t *)"Hexi",20,0); // Display white "Hexi" at x,y |
nbaker | 8:a5c77b45008d | 1850 | textProperties.fontColor = COLOR_RED; |
nbaker | 8:a5c77b45008d | 1851 | oled.SetTextProperties(&textProperties); |
nbaker | 8:a5c77b45008d | 1852 | oled.Label((uint8_t *)"Heart",45,0); // Display red "Heart" at x,y |
nbaker | 8:a5c77b45008d | 1853 | textProperties.fontColor = COLOR_WHITE; |
nbaker | 8:a5c77b45008d | 1854 | oled.SetTextProperties(&textProperties); |
nbaker | 9:d2e39ee9fedd | 1855 | // oled.Label((uint8_t *)"E2.7 Team Zeta",2,12); // |
nbaker | 9:d2e39ee9fedd | 1856 | oled.Label((uint8_t *)"Alex Song",5,12); // |
nbaker | 9:d2e39ee9fedd | 1857 | oled.Label((uint8_t *)"Jasmine ",5,24); // Jasmine Rounsaville is to long |
nbaker | 9:d2e39ee9fedd | 1858 | oled.Label((uint8_t *)"Rounsaville",15,37); // Jasmine Rounsaville is to long |
nbaker | 8:a5c77b45008d | 1859 | oled.Label((uint8_t *)"Issam Hichami",5,51); // |
nbaker | 8:a5c77b45008d | 1860 | oled.Label((uint8_t *)"Neil Baker",5,64); // |
nbaker | 8:a5c77b45008d | 1861 | |
nbaker | 12:fd39a7983e06 | 1862 | oled.Label((uint8_t *)"*",85,15); // "*" at x,y |
nbaker | 12:fd39a7983e06 | 1863 | oled.Label((uint8_t *)"*",85,60); // "*" at x,y |
nbaker | 8:a5c77b45008d | 1864 | oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y |
nbaker | 8:a5c77b45008d | 1865 | break; |
nbaker | 8:a5c77b45008d | 1866 | } |
nbaker | 8:a5c77b45008d | 1867 | |
nbaker | 8:a5c77b45008d | 1868 | case 11: {// About HexiHeart info3 |
nbaker | 8:a5c77b45008d | 1869 | oled.FillScreen(COLOR_BLACK); // Clear screen |
nbaker | 12:fd39a7983e06 | 1870 | |
nbaker | 12:fd39a7983e06 | 1871 | textProperties.font = OpenSans_12x18_Regular; // Max Width of Character = 12px, Max Height of Character = 18px |
nbaker | 12:fd39a7983e06 | 1872 | oled.SetTextProperties(&textProperties); |
nbaker | 12:fd39a7983e06 | 1873 | oled.Label((uint8_t *)"Hexi",17,5); // Display white "Hexi" at x,y |
nbaker | 8:a5c77b45008d | 1874 | textProperties.fontColor = COLOR_RED; |
nbaker | 12:fd39a7983e06 | 1875 | oled.SetTextProperties(&textProperties); |
nbaker | 12:fd39a7983e06 | 1876 | oled.Label((uint8_t *)"Heart",46,5); // Display red "Heart" at x,y |
nbaker | 12:fd39a7983e06 | 1877 | textProperties.font = OpenSans_10x15_Regular; // Max Width of Character = 10px, Max Height of Character = 15px |
nbaker | 12:fd39a7983e06 | 1878 | oled.SetTextProperties(&textProperties); |
nbaker | 12:fd39a7983e06 | 1879 | |
nbaker | 12:fd39a7983e06 | 1880 | strcpy((char *) text_1,"This is a"); |
nbaker | 12:fd39a7983e06 | 1881 | oled.Label((uint8_t *)text_1,19,25); // text_1 at x,y |
nbaker | 12:fd39a7983e06 | 1882 | strcpy((char *) text_1,"Demo Proj"); |
nbaker | 12:fd39a7983e06 | 1883 | oled.Label((uint8_t *)text_1,15,40); // text_1 at x,y |
nbaker | 12:fd39a7983e06 | 1884 | strcpy((char *) text_1,"SW_Ver:"); |
nbaker | 12:fd39a7983e06 | 1885 | oled.Label((uint8_t *)text_1,10,65); // text_1 at x,y |
nbaker | 12:fd39a7983e06 | 1886 | textProperties.fontColor = COLOR_MAGENTA; |
nbaker | 12:fd39a7983e06 | 1887 | oled.SetTextProperties(&textProperties); |
nbaker | 12:fd39a7983e06 | 1888 | sprintf(text_1,"%2.2f ",SW_Ver); |
nbaker | 12:fd39a7983e06 | 1889 | oled.Label((uint8_t *)text_1,60,65);// text_1 at x,y |
nbaker | 8:a5c77b45008d | 1890 | textProperties.fontColor = COLOR_WHITE; |
nbaker | 12:fd39a7983e06 | 1891 | oled.SetTextProperties(&textProperties); |
nbaker | 12:fd39a7983e06 | 1892 | oled.Label((uint8_t *)"*",85,15); // "*" at x,y |
nbaker | 12:fd39a7983e06 | 1893 | oled.Label((uint8_t *)"*",85,60); // "*" at x,y |
nbaker | 8:a5c77b45008d | 1894 | oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y |
nbaker | 8:a5c77b45008d | 1895 | break; |
nbaker | 8:a5c77b45008d | 1896 | } |
nbaker | 8:a5c77b45008d | 1897 | |
asong | 1:e4b38d6918ba | 1898 | #ifdef Debug // if this is non-production/debug version - do this |
asong | 1:e4b38d6918ba | 1899 | case 20: {// Diagnostic/Debug Screens |
asong | 1:e4b38d6918ba | 1900 | oled.FillScreen(COLOR_BLACK); // Clear screen |
asong | 1:e4b38d6918ba | 1901 | textProperties.fontColor = COLOR_RED; |
asong | 1:e4b38d6918ba | 1902 | oled.SetTextProperties(&textProperties); |
nbaker | 12:fd39a7983e06 | 1903 | oled.Label((uint8_t *)"Diagnostics",18,5); // Display at x,y |
nbaker | 9:d2e39ee9fedd | 1904 | oled.Label((uint8_t *)"Enter",60,80); //Display at x,y |
asong | 1:e4b38d6918ba | 1905 | textProperties.fontColor = COLOR_WHITE; |
asong | 1:e4b38d6918ba | 1906 | oled.SetTextProperties(&textProperties); |
asong | 1:e4b38d6918ba | 1907 | oled.Label((uint8_t *)"*",85,15); // "*" at x,y |
asong | 1:e4b38d6918ba | 1908 | oled.Label((uint8_t *)"*",85,60); // "*" at x,y |
nbaker | 9:d2e39ee9fedd | 1909 | oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y |
nbaker | 0:d1d36a3da39b | 1910 | |
asong | 1:e4b38d6918ba | 1911 | break; |
asong | 1:e4b38d6918ba | 1912 | } |
asong | 1:e4b38d6918ba | 1913 | case 21: {// Fall Alert Diagnostic Screen |
nbaker | 8:a5c77b45008d | 1914 | if(Fall_Alert_Mode == 0){ |
nbaker | 8:a5c77b45008d | 1915 | fall_config(11); // turn accel sensor to active to take reading |
nbaker | 8:a5c77b45008d | 1916 | } |
asong | 1:e4b38d6918ba | 1917 | oled.FillScreen(COLOR_BLACK); // Clear screen |
asong | 1:e4b38d6918ba | 1918 | textProperties.fontColor = COLOR_RED; |
asong | 1:e4b38d6918ba | 1919 | oled.SetTextProperties(&textProperties); |
nbaker | 7:3d5a8aea0b63 | 1920 | oled.Label((uint8_t *)"Fall-Diag",25,5); // Display at x,y |
nbaker | 7:3d5a8aea0b63 | 1921 | // oled.Label((uint8_t *)"Diagnostic",25,5); // Display at x,y |
asong | 1:e4b38d6918ba | 1922 | textProperties.fontColor = COLOR_WHITE; |
asong | 1:e4b38d6918ba | 1923 | oled.SetTextProperties(&textProperties); |
nbaker | 8:a5c77b45008d | 1924 | gyro.acquire_gyro_data_dps(Gyro_Data); |
nbaker | 8:a5c77b45008d | 1925 | Gyro_Mag = (abs(Gyro_Data[0])+abs(Gyro_Data[1])+abs(Gyro_Data[2])); |
asong | 1:e4b38d6918ba | 1926 | accel.acquire_accel_data_g(Accel_Data); |
nbaker | 8:a5c77b45008d | 1927 | if(Fall_Alert_Mode == 0){ |
nbaker | 8:a5c77b45008d | 1928 | fall_config(12); // turn accel sensor to standby |
nbaker | 8:a5c77b45008d | 1929 | } |
nbaker | 8:a5c77b45008d | 1930 | 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 | 1931 | sprintf(text_1," Accel:%2.2f g ",Accel_Mag); |
nbaker | 9:d2e39ee9fedd | 1932 | oled.Label((uint8_t *)text_1,5,40);// text_1 at x,y |
asong | 1:e4b38d6918ba | 1933 | sprintf(text_1," Gyro:%4.0f D/S ",Gyro_Mag); |
nbaker | 9:d2e39ee9fedd | 1934 | oled.Label((uint8_t *)text_1,5,60);// text_1 at x,y |
nbaker | 8:a5c77b45008d | 1935 | oled.Label((uint8_t *)"*",85,15); // "*" at x,y |
nbaker | 8:a5c77b45008d | 1936 | oled.Label((uint8_t *)"*",85,60); // "*" at x,y |
asong | 1:e4b38d6918ba | 1937 | oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y |
asong | 1:e4b38d6918ba | 1938 | break; |
asong | 1:e4b38d6918ba | 1939 | } |
asong | 1:e4b38d6918ba | 1940 | case 22: {// Fall Alert Debug Screen |
asong | 1:e4b38d6918ba | 1941 | oled.FillScreen(COLOR_BLACK); // Clear screen |
asong | 1:e4b38d6918ba | 1942 | textProperties.fontColor = COLOR_RED; |
asong | 1:e4b38d6918ba | 1943 | oled.SetTextProperties(&textProperties); |
asong | 1:e4b38d6918ba | 1944 | oled.Label((uint8_t *)"Fall Debug",15,5); // Display at x,y |
asong | 1:e4b38d6918ba | 1945 | textProperties.fontColor = COLOR_GREEN; |
asong | 1:e4b38d6918ba | 1946 | oled.SetTextProperties(&textProperties); |
nbaker | 8:a5c77b45008d | 1947 | sprintf(text_1," %i ",Fall_Alert_Mode); |
nbaker | 10:eaea844e763c | 1948 | oled.Label((uint8_t *)text_1,36,20);// text_1 at x,y |
nbaker | 8:a5c77b45008d | 1949 | textProperties.fontColor = COLOR_GRAY; |
nbaker | 10:eaea844e763c | 1950 | if(Fall_Alert_Mode == 1 || Fall_Alert_Mode >= 4){ |
nbaker | 9:d2e39ee9fedd | 1951 | textProperties.fontColor = COLOR_GREEN; |
nbaker | 8:a5c77b45008d | 1952 | } |
nbaker | 8:a5c77b45008d | 1953 | oled.SetTextProperties(&textProperties); |
nbaker | 8:a5c77b45008d | 1954 | sprintf(text_1," %1.2f g ",Fall_Thresh); |
asong | 1:e4b38d6918ba | 1955 | oled.Label((uint8_t *)text_1,35,35);// text_1 at x,y |
nbaker | 8:a5c77b45008d | 1956 | textProperties.fontColor = COLOR_GRAY; |
nbaker | 10:eaea844e763c | 1957 | if(Fall_Alert_Mode == 2 || Fall_Alert_Mode >= 4){ |
nbaker | 9:d2e39ee9fedd | 1958 | textProperties.fontColor = COLOR_GREEN; |
nbaker | 8:a5c77b45008d | 1959 | } |
nbaker | 8:a5c77b45008d | 1960 | oled.SetTextProperties(&textProperties); |
nbaker | 8:a5c77b45008d | 1961 | sprintf(text_1," %2.2f g ",Impact_Thresh); |
nbaker | 8:a5c77b45008d | 1962 | oled.Label((uint8_t *)text_1,35,50);// text_1 at x,y |
nbaker | 8:a5c77b45008d | 1963 | textProperties.fontColor = COLOR_GRAY; |
nbaker | 10:eaea844e763c | 1964 | if(Fall_Alert_Mode == 3 || Fall_Alert_Mode >= 4){ |
nbaker | 9:d2e39ee9fedd | 1965 | textProperties.fontColor = COLOR_GREEN; |
nbaker | 8:a5c77b45008d | 1966 | } |
nbaker | 8:a5c77b45008d | 1967 | oled.SetTextProperties(&textProperties); |
asong | 1:e4b38d6918ba | 1968 | sprintf(text_1," %3.0f D/S ",Movement_Thresh); |
nbaker | 8:a5c77b45008d | 1969 | oled.Label((uint8_t *)text_1,35,65);// text_1 at x,y |
asong | 1:e4b38d6918ba | 1970 | textProperties.fontColor = COLOR_WHITE; |
asong | 1:e4b38d6918ba | 1971 | oled.SetTextProperties(&textProperties); |
nbaker | 8:a5c77b45008d | 1972 | oled.Label((uint8_t *)"Mode:",5,20); // "*" at x,y |
nbaker | 8:a5c77b45008d | 1973 | oled.Label((uint8_t *)"F-Th:",5,35); // "*" at x,y |
nbaker | 8:a5c77b45008d | 1974 | oled.Label((uint8_t *)"I-Th:",5,50); // "*" at x,y |
nbaker | 8:a5c77b45008d | 1975 | oled.Label((uint8_t *)"M-Th:",5,65); // "*" at x,y |
asong | 1:e4b38d6918ba | 1976 | oled.Label((uint8_t *)"*",85,15); // "*" at x,y |
asong | 1:e4b38d6918ba | 1977 | oled.Label((uint8_t *)"*",85,60); // "*" at x,y |
nbaker | 9:d2e39ee9fedd | 1978 | oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y |
nbaker | 9:d2e39ee9fedd | 1979 | oled.Label((uint8_t *)"Enter",60,80); //Display at x,y |
asong | 1:e4b38d6918ba | 1980 | break; |
asong | 1:e4b38d6918ba | 1981 | } |
asong | 1:e4b38d6918ba | 1982 | case 23: {// Heart Rate Diagnostic Screen |
asong | 1:e4b38d6918ba | 1983 | oled.FillScreen(COLOR_BLACK); // Clear screen |
asong | 1:e4b38d6918ba | 1984 | textProperties.fontColor = COLOR_RED; |
asong | 1:e4b38d6918ba | 1985 | oled.SetTextProperties(&textProperties); |
asong | 1:e4b38d6918ba | 1986 | oled.Label((uint8_t *)"H.R. Diagnostic",5,5); // Display at x,y |
asong | 1:e4b38d6918ba | 1987 | textProperties.fontColor = COLOR_WHITE; |
asong | 1:e4b38d6918ba | 1988 | oled.SetTextProperties(&textProperties); |
asong | 1:e4b38d6918ba | 1989 | oled.Label((uint8_t *)"*",85,15); // "*" at x,y |
asong | 1:e4b38d6918ba | 1990 | oled.Label((uint8_t *)"*",85,60); // "*" at x,y |
nbaker | 9:d2e39ee9fedd | 1991 | oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y |
asong | 1:e4b38d6918ba | 1992 | // oled.Label((uint8_t *)" Enter ",59,80); //Display at x,y |
asong | 1:e4b38d6918ba | 1993 | break; |
asong | 1:e4b38d6918ba | 1994 | } |
asong | 1:e4b38d6918ba | 1995 | case 24: {// Heart Rate Debug Screen |
asong | 1:e4b38d6918ba | 1996 | oled.FillScreen(COLOR_BLACK); // Clear screen |
asong | 1:e4b38d6918ba | 1997 | textProperties.fontColor = COLOR_RED; |
asong | 1:e4b38d6918ba | 1998 | oled.SetTextProperties(&textProperties); |
asong | 1:e4b38d6918ba | 1999 | oled.Label((uint8_t *)"H.R. Debug",10,5); // Display at x,y |
asong | 1:e4b38d6918ba | 2000 | textProperties.fontColor = COLOR_WHITE; |
asong | 1:e4b38d6918ba | 2001 | oled.SetTextProperties(&textProperties); |
asong | 1:e4b38d6918ba | 2002 | oled.Label((uint8_t *)"*",85,15); // "*" at x,y |
asong | 1:e4b38d6918ba | 2003 | oled.Label((uint8_t *)"*",85,60); // "*" at x,y |
nbaker | 9:d2e39ee9fedd | 2004 | oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y |
asong | 1:e4b38d6918ba | 2005 | // oled.Label((uint8_t *)" Enter ",59,80); //Display at x,y |
asong | 1:e4b38d6918ba | 2006 | break; |
asong | 1:e4b38d6918ba | 2007 | } |
asong | 1:e4b38d6918ba | 2008 | case 25: {// Heat Index Diagnostic Screen |
asong | 1:e4b38d6918ba | 2009 | oled.FillScreen(COLOR_BLACK); // Clear screen |
asong | 1:e4b38d6918ba | 2010 | textProperties.fontColor = COLOR_RED; |
asong | 1:e4b38d6918ba | 2011 | oled.SetTextProperties(&textProperties); |
asong | 1:e4b38d6918ba | 2012 | oled.Label((uint8_t *)"H.I. Diagnostic",5,5); // Display at x,y |
asong | 1:e4b38d6918ba | 2013 | textProperties.fontColor = COLOR_WHITE; |
asong | 1:e4b38d6918ba | 2014 | oled.SetTextProperties(&textProperties); |
asong | 1:e4b38d6918ba | 2015 | oled.Label((uint8_t *)"*",85,15); // "*" at x,y |
asong | 1:e4b38d6918ba | 2016 | oled.Label((uint8_t *)"*",85,60); // "*" at x,y |
nbaker | 9:d2e39ee9fedd | 2017 | oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y |
asong | 1:e4b38d6918ba | 2018 | // oled.Label((uint8_t *)" Enter ",59,80); //Display at x,y |
jmr274 | 5:e1431272be79 | 2019 | |
jmr274 | 6:84e3ba00b995 | 2020 | Heat_Index_Calculation(); |
jmr274 | 5:e1431272be79 | 2021 | |
jmr274 | 5:e1431272be79 | 2022 | oled_text_properties_t textProperties = {0}; |
jmr274 | 5:e1431272be79 | 2023 | oled.GetTextProperties(&textProperties); |
jmr274 | 5:e1431272be79 | 2024 | |
jmr274 | 5:e1431272be79 | 2025 | strcpy((char *) text,"Temp."); |
jmr274 | 5:e1431272be79 | 2026 | oled.Label((uint8_t *)text,5,40); |
jmr274 | 5:e1431272be79 | 2027 | strcpy((char *) text,"Humidity"); |
jmr274 | 5:e1431272be79 | 2028 | oled.Label((uint8_t *)text,5,57); |
jmr274 | 5:e1431272be79 | 2029 | strcpy((char *) text,"H.I."); |
jmr274 | 5:e1431272be79 | 2030 | oled.Label((uint8_t *)text,5,23); |
jmr274 | 5:e1431272be79 | 2031 | |
jmr274 | 5:e1431272be79 | 2032 | /* Set text properties to white and right aligned for the dynamic text */ |
jmr274 | 5:e1431272be79 | 2033 | textProperties.fontColor = COLOR_GREEN; |
jmr274 | 5:e1431272be79 | 2034 | textProperties.alignParam = OLED_TEXT_ALIGN_RIGHT; |
jmr274 | 5:e1431272be79 | 2035 | oled.SetTextProperties(&textProperties); |
jmr274 | 5:e1431272be79 | 2036 | |
jmr274 | 5:e1431272be79 | 2037 | /* Format the value */ |
jmr274 | 5:e1431272be79 | 2038 | sprintf(text,"%i",sample_ftemp); |
jmr274 | 5:e1431272be79 | 2039 | |
nbaker | 8:a5c77b45008d | 2040 | /* Display temp reading in 15px by 15px textbox at(x=55, y=40) */ |
jmr274 | 5:e1431272be79 | 2041 | oled.TextBox((uint8_t *)text,55,40,15,15); //Increase textbox for more digits |
jmr274 | 5:e1431272be79 | 2042 | |
jmr274 | 5:e1431272be79 | 2043 | /* Display Units */ |
jmr274 | 5:e1431272be79 | 2044 | strcpy((char *) text,"dF"); |
jmr274 | 5:e1431272be79 | 2045 | oled.Label((uint8_t *)text,71,40); |
jmr274 | 5:e1431272be79 | 2046 | |
jmr274 | 5:e1431272be79 | 2047 | /* Format the value */ |
jmr274 | 5:e1431272be79 | 2048 | sprintf(text,"%i",sample_humid); |
jmr274 | 5:e1431272be79 | 2049 | |
nbaker | 8:a5c77b45008d | 2050 | /* Display Hum reading in 15px by 15px textbox at(x=55, y=57) */ |
jmr274 | 5:e1431272be79 | 2051 | oled.TextBox((uint8_t *)text,55,57,15,15); //Increase textbox for more digits |
jmr274 | 5:e1431272be79 | 2052 | |
jmr274 | 5:e1431272be79 | 2053 | /* Display Units */ |
jmr274 | 5:e1431272be79 | 2054 | strcpy((char *) text,"%"); |
jmr274 | 5:e1431272be79 | 2055 | oled.Label((uint8_t *)text,71,57); |
jmr274 | 5:e1431272be79 | 2056 | |
jmr274 | 5:e1431272be79 | 2057 | /* Set text properties to white and right aligned for the dynamic text */ |
jmr274 | 5:e1431272be79 | 2058 | textProperties.fontColor = COLOR_BLUE; |
jmr274 | 5:e1431272be79 | 2059 | textProperties.alignParam = OLED_TEXT_ALIGN_RIGHT; |
jmr274 | 5:e1431272be79 | 2060 | oled.SetTextProperties(&textProperties); |
jmr274 | 5:e1431272be79 | 2061 | |
jmr274 | 5:e1431272be79 | 2062 | /* Format the value */ |
jmr274 | 5:e1431272be79 | 2063 | sprintf(text,"%i",heat_index); |
jmr274 | 5:e1431272be79 | 2064 | |
nbaker | 8:a5c77b45008d | 2065 | /* Display HI reading in 15px by 15px textbox at(x=55, y=23) */ |
jmr274 | 5:e1431272be79 | 2066 | oled.TextBox((uint8_t *)text,55,23,15,15); //Increase textbox for more digits |
jmr274 | 5:e1431272be79 | 2067 | |
jmr274 | 5:e1431272be79 | 2068 | /* Display Units */ |
nbaker | 16:537ef0c72084 | 2069 | strcpy((char *) text,"dF"); |
nbaker | 16:537ef0c72084 | 2070 | oled.Label((uint8_t *)text,71,23); |
jmr274 | 5:e1431272be79 | 2071 | |
asong | 1:e4b38d6918ba | 2072 | break; |
asong | 1:e4b38d6918ba | 2073 | } |
asong | 1:e4b38d6918ba | 2074 | case 26: {//Heart Rate Config Option |
asong | 1:e4b38d6918ba | 2075 | oled.FillScreen(COLOR_BLACK); // Clear screen |
nbaker | 12:fd39a7983e06 | 2076 | oled.Label((uint8_t *)"HR Config",18,5); // Display at x,y |
asong | 1:e4b38d6918ba | 2077 | oled.Label((uint8_t *)"*",85,15); // "*" at x,y |
asong | 1:e4b38d6918ba | 2078 | oled.Label((uint8_t *)"*",85,60); // "*" at x,y |
asong | 1:e4b38d6918ba | 2079 | oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y |
asong | 1:e4b38d6918ba | 2080 | oled.Label((uint8_t *)"Enter",60,80); //Display "enter" at x,y |
asong | 1:e4b38d6918ba | 2081 | break; |
asong | 1:e4b38d6918ba | 2082 | } |
asong | 1:e4b38d6918ba | 2083 | case 27: { //Enter Age Screen |
asong | 1:e4b38d6918ba | 2084 | oled.FillScreen(COLOR_BLACK); |
asong | 1:e4b38d6918ba | 2085 | oled.Label((uint8_t *)"Input Age", 10, 5); |
asong | 1:e4b38d6918ba | 2086 | sprintf(display_buff, "%u", Age); //Convert int to char array for displaying user age |
asong | 1:e4b38d6918ba | 2087 | oled.Label((uint8_t *)"Age:", 10, 30); |
asong | 1:e4b38d6918ba | 2088 | oled.Label((uint8_t *)"+",85,15); // "*" at x,y |
asong | 1:e4b38d6918ba | 2089 | oled.Label((uint8_t *)"-",85,60); // "*" at x,y |
asong | 1:e4b38d6918ba | 2090 | oled.Label((uint8_t *)"Menu",10,80); // Display "Menu" at x,y |
asong | 1:e4b38d6918ba | 2091 | oled.Label((uint8_t *)"Next",60,80); //Display "Next" at x,y |
asong | 1:e4b38d6918ba | 2092 | textProperties.fontColor = COLOR_GREEN; |
asong | 1:e4b38d6918ba | 2093 | oled.SetTextProperties(&textProperties); |
asong | 1:e4b38d6918ba | 2094 | oled.Label((uint8_t *)display_buff,43,30); // Display at x,y |
asong | 1:e4b38d6918ba | 2095 | textProperties.fontColor = COLOR_WHITE; |
asong | 1:e4b38d6918ba | 2096 | oled.SetTextProperties(&textProperties); |
asong | 1:e4b38d6918ba | 2097 | oled.Label((uint8_t *)"Max bpm:",10,50); |
asong | 1:e4b38d6918ba | 2098 | textProperties.fontColor = COLOR_RED; |
asong | 1:e4b38d6918ba | 2099 | oled.SetTextProperties(&textProperties); //implements the color change |
asong | 2:824ed4ae8d52 | 2100 | sprintf(display_buff, "%u", Max_Bpm); //Convert int to char array for displaying user max bpm |
asong | 1:e4b38d6918ba | 2101 | oled.Label((uint8_t *)display_buff, 65, 50); |
asong | 1:e4b38d6918ba | 2102 | textProperties.fontColor = COLOR_WHITE; |
asong | 1:e4b38d6918ba | 2103 | oled.SetTextProperties(&textProperties); |
asong | 1:e4b38d6918ba | 2104 | break; |
asong | 1:e4b38d6918ba | 2105 | } |
asong | 1:e4b38d6918ba | 2106 | case 28: {//Choose Heart Rate Vibration Option |
asong | 1:e4b38d6918ba | 2107 | oled.FillScreen(COLOR_BLACK); |
asong | 1:e4b38d6918ba | 2108 | oled.Label((uint8_t *)"Vibrate Pref", 10, 10); |
asong | 1:e4b38d6918ba | 2109 | oled.Label((uint8_t *)"Option:", 10, 25); |
asong | 1:e4b38d6918ba | 2110 | oled.Label((uint8_t *)"+",85,15); // "+" at x,y |
asong | 1:e4b38d6918ba | 2111 | oled.Label((uint8_t *)"-",85,60); // "-" at x,y |
asong | 1:e4b38d6918ba | 2112 | oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y |
asong | 1:e4b38d6918ba | 2113 | oled.Label((uint8_t *)"Next",60,80); //Display "Next" at x,y |
asong | 1:e4b38d6918ba | 2114 | sprintf(display_buff, "%u", HR_Vibration); //Convert int to char array for displaying user preference |
asong | 1:e4b38d6918ba | 2115 | textProperties.fontColor = COLOR_GREEN; //Change font to green |
asong | 1:e4b38d6918ba | 2116 | oled.SetTextProperties(&textProperties);//Implement color change |
asong | 1:e4b38d6918ba | 2117 | oled.Label((uint8_t *)display_buff,55,25); // Display at x,y |
asong | 1:e4b38d6918ba | 2118 | if(HR_Vibration == 1) { |
asong | 1:e4b38d6918ba | 2119 | textProperties.fontColor = COLOR_RED; //Change font to red |
asong | 1:e4b38d6918ba | 2120 | oled.SetTextProperties(&textProperties); //Implement color change |
asong | 1:e4b38d6918ba | 2121 | oled.Label((uint8_t *)"All On",10,45); // Display at x,y |
asong | 1:e4b38d6918ba | 2122 | } else if(HR_Vibration == 2) { |
asong | 1:e4b38d6918ba | 2123 | textProperties.fontColor = COLOR_RED; //Change font to red |
asong | 1:e4b38d6918ba | 2124 | oled.SetTextProperties(&textProperties);//Implement color change |
asong | 1:e4b38d6918ba | 2125 | oled.Label((uint8_t *)"Only Entering",10,38);// Display at x,y |
asong | 1:e4b38d6918ba | 2126 | oled.Label((uint8_t *)"And Exiting",10,53);// Display at x,y |
asong | 1:e4b38d6918ba | 2127 | oled.Label((uint8_t *)"Target Zone",10,68);// Display at x,y |
nbaker | 0:d1d36a3da39b | 2128 | |
asong | 1:e4b38d6918ba | 2129 | } else if(HR_Vibration == 3) { |
asong | 1:e4b38d6918ba | 2130 | textProperties.fontColor = COLOR_RED; //Change font to red |
asong | 1:e4b38d6918ba | 2131 | oled.SetTextProperties(&textProperties); //Implement color change |
asong | 1:e4b38d6918ba | 2132 | oled.Label((uint8_t *)"All Off",10,45);// Display at x,y |
asong | 1:e4b38d6918ba | 2133 | } |
asong | 1:e4b38d6918ba | 2134 | textProperties.fontColor = COLOR_WHITE; |
asong | 1:e4b38d6918ba | 2135 | oled.SetTextProperties(&textProperties); |
asong | 1:e4b38d6918ba | 2136 | break; |
asong | 1:e4b38d6918ba | 2137 | } |
asong | 1:e4b38d6918ba | 2138 | case 29: { //Zone Boundary Info |
asong | 1:e4b38d6918ba | 2139 | oled.FillScreen(COLOR_BLACK); |
asong | 17:746dc1b7b218 | 2140 | textProperties.fontColor = COLOR_WHITE; //Change font to yellow |
asong | 17:746dc1b7b218 | 2141 | oled.SetTextProperties(&textProperties);//Implement color change |
asong | 1:e4b38d6918ba | 2142 | oled.Label((uint8_t *)"HR Zone Info", 10, 5);// Display at x,y |
asong | 1:e4b38d6918ba | 2143 | textProperties.fontColor = COLOR_YELLOW; //Change font to yellow |
asong | 1:e4b38d6918ba | 2144 | oled.SetTextProperties(&textProperties);//Implement color change |
asong | 1:e4b38d6918ba | 2145 | oled.Label((uint8_t *)"Z1:", 10, 20);// Display at x,y |
asong | 1:e4b38d6918ba | 2146 | sprintf(display_buff, "%u", HR_Zone1[0]); // Convert int to char to display |
asong | 1:e4b38d6918ba | 2147 | oled.Label((uint8_t *)display_buff, 30, 20);// Display at x,y |
asong | 1:e4b38d6918ba | 2148 | oled.Label((uint8_t *)"-", 52, 20);// Display at x,y |
asong | 1:e4b38d6918ba | 2149 | sprintf(display_buff, "%u", HR_Zone1[1]); // Convert int to char to display |
asong | 1:e4b38d6918ba | 2150 | oled.Label((uint8_t *)display_buff, 60, 20);// Display at x,y |
asong | 1:e4b38d6918ba | 2151 | textProperties.fontColor = COLOR_BLUE; //Change font to blue |
asong | 1:e4b38d6918ba | 2152 | oled.SetTextProperties(&textProperties);//Implement color change |
asong | 1:e4b38d6918ba | 2153 | oled.Label((uint8_t *)"Z2:", 10, 35);// Display at x,y |
asong | 1:e4b38d6918ba | 2154 | sprintf(display_buff, "%u", HR_Zone2[0]); // Convert int to char to display |
asong | 1:e4b38d6918ba | 2155 | oled.Label((uint8_t *)display_buff, 30, 35);// Display at x,y |
asong | 1:e4b38d6918ba | 2156 | oled.Label((uint8_t *)"-", 52, 35);// Display at x,y |
asong | 1:e4b38d6918ba | 2157 | sprintf(display_buff, "%u", HR_Zone2[1]); // Convert int to char to display |
asong | 1:e4b38d6918ba | 2158 | oled.Label((uint8_t *)display_buff, 60, 35);// Display at x,y |
asong | 1:e4b38d6918ba | 2159 | textProperties.fontColor = COLOR_GREEN; //Change font to green |
asong | 1:e4b38d6918ba | 2160 | oled.SetTextProperties(&textProperties);//Implement color change |
asong | 1:e4b38d6918ba | 2161 | oled.Label((uint8_t *)"Z3:", 10, 50);// Display at x,y |
asong | 1:e4b38d6918ba | 2162 | sprintf(display_buff, "%u", HR_Zone3[0]); // Convert int to char to display |
asong | 1:e4b38d6918ba | 2163 | oled.Label((uint8_t *)display_buff, 30, 50);// Display at x,y |
asong | 1:e4b38d6918ba | 2164 | oled.Label((uint8_t *)"-", 52, 50);// Display at x,y |
asong | 1:e4b38d6918ba | 2165 | sprintf(display_buff, "%u", HR_Zone3[1]); // Convert int to char to display |
asong | 1:e4b38d6918ba | 2166 | oled.Label((uint8_t *)display_buff, 60, 50);// Display at x,y |
asong | 1:e4b38d6918ba | 2167 | textProperties.fontColor = COLOR_RED; //Change font to red |
asong | 1:e4b38d6918ba | 2168 | oled.SetTextProperties(&textProperties);//Implement color change |
asong | 1:e4b38d6918ba | 2169 | oled.Label((uint8_t *)"Z4:", 10, 65);// Display at x,y |
asong | 1:e4b38d6918ba | 2170 | sprintf(display_buff, "%u", HR_Zone4[0]); // Convert int to char to display |
asong | 1:e4b38d6918ba | 2171 | oled.Label((uint8_t *)display_buff, 30, 65);// Display at x,y |
asong | 1:e4b38d6918ba | 2172 | oled.Label((uint8_t *)"-", 52, 65);// Display at x,y |
asong | 1:e4b38d6918ba | 2173 | sprintf(display_buff, "%u", HR_Zone4[1]); // Convert int to char to display |
asong | 1:e4b38d6918ba | 2174 | oled.Label((uint8_t *)display_buff, 60, 65);// Display at x,y |
asong | 1:e4b38d6918ba | 2175 | textProperties.fontColor = COLOR_WHITE; //Change font to white |
asong | 1:e4b38d6918ba | 2176 | oled.SetTextProperties(&textProperties);//Implement color change |
asong | 1:e4b38d6918ba | 2177 | oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y |
asong | 1:e4b38d6918ba | 2178 | oled.Label((uint8_t *)"Next",60,80); //Display "Next" at x,y |
asong | 1:e4b38d6918ba | 2179 | break; |
asong | 2:824ed4ae8d52 | 2180 | } |
asong | 2:824ed4ae8d52 | 2181 | case 30: { //Enter Target Heart Rate Zone Preference |
asong | 1:e4b38d6918ba | 2182 | oled.FillScreen(COLOR_BLACK); |
asong | 1:e4b38d6918ba | 2183 | oled.Label((uint8_t *)"Zone Pref", 10, 5);// Display at x,y |
asong | 1:e4b38d6918ba | 2184 | oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y |
asong | 1:e4b38d6918ba | 2185 | oled.Label((uint8_t *)"Next",60,80); //Display "Next" at x,y |
asong | 1:e4b38d6918ba | 2186 | oled.Label((uint8_t *)"+",85,15); // "+" at x,y |
asong | 1:e4b38d6918ba | 2187 | oled.Label((uint8_t *)"-",85,60); // "-" at x,y |
asong | 1:e4b38d6918ba | 2188 | oled.Label((uint8_t *)"Target:", 10, 25);// Display at x,y |
asong | 1:e4b38d6918ba | 2189 | sprintf(display_buff, "%u", Target_Zone); // Convert int to char to display |
asong | 2:824ed4ae8d52 | 2190 | if(Target_Zone == 1) { |
asong | 1:e4b38d6918ba | 2191 | textProperties.fontColor = COLOR_YELLOW; //Change font to yellow |
asong | 1:e4b38d6918ba | 2192 | oled.SetTextProperties(&textProperties);//Implement color change |
asong | 2:824ed4ae8d52 | 2193 | } else if(Target_Zone == 2) { |
asong | 1:e4b38d6918ba | 2194 | textProperties.fontColor = COLOR_BLUE; //Change font to blue |
asong | 1:e4b38d6918ba | 2195 | oled.SetTextProperties(&textProperties);//Implement color change |
asong | 2:824ed4ae8d52 | 2196 | } else if(Target_Zone == 3) { |
asong | 1:e4b38d6918ba | 2197 | textProperties.fontColor = COLOR_GREEN; //Change font to green |
asong | 1:e4b38d6918ba | 2198 | oled.SetTextProperties(&textProperties);//Implement color change |
asong | 2:824ed4ae8d52 | 2199 | } else if(Target_Zone == 4) { |
asong | 1:e4b38d6918ba | 2200 | textProperties.fontColor = COLOR_RED; //Change font to red |
asong | 1:e4b38d6918ba | 2201 | oled.SetTextProperties(&textProperties);//Implement color change |
asong | 1:e4b38d6918ba | 2202 | } |
asong | 1:e4b38d6918ba | 2203 | oled.Label((uint8_t *)display_buff, 55, 25);// Display at x,y |
asong | 1:e4b38d6918ba | 2204 | textProperties.fontColor = COLOR_WHITE; //Change font to white |
asong | 1:e4b38d6918ba | 2205 | oled.SetTextProperties(&textProperties);//Implement color change |
asong | 1:e4b38d6918ba | 2206 | oled.Label((uint8_t *)"Bounds:", 10, 45);// Display at x,y |
asong | 2:824ed4ae8d52 | 2207 | if(Target_Zone == 1) { |
asong | 1:e4b38d6918ba | 2208 | textProperties.fontColor = COLOR_YELLOW; //Change font to yellow |
asong | 1:e4b38d6918ba | 2209 | oled.SetTextProperties(&textProperties);//Implement color change |
asong | 1:e4b38d6918ba | 2210 | sprintf(display_buff, "%u", HR_Zone1[0]); // Convert int to char to display |
asong | 1:e4b38d6918ba | 2211 | oled.Label((uint8_t *)display_buff, 10, 60);// Display at x,y |
asong | 1:e4b38d6918ba | 2212 | oled.Label((uint8_t *)"-", 32, 60);// Display at x,y |
asong | 1:e4b38d6918ba | 2213 | sprintf(display_buff, "%u", HR_Zone1[1]); // Convert int to char to display |
asong | 1:e4b38d6918ba | 2214 | oled.Label((uint8_t *)display_buff, 40, 60);// Display at x,y |
asong | 2:824ed4ae8d52 | 2215 | } else if(Target_Zone == 2) { |
asong | 1:e4b38d6918ba | 2216 | textProperties.fontColor = COLOR_BLUE; //Change font to blue |
asong | 1:e4b38d6918ba | 2217 | oled.SetTextProperties(&textProperties);//Implement color change |
asong | 1:e4b38d6918ba | 2218 | sprintf(display_buff, "%u", HR_Zone2[0]); // Convert int to char to display |
asong | 1:e4b38d6918ba | 2219 | oled.Label((uint8_t *)display_buff, 10, 60);// Display at x,y |
asong | 1:e4b38d6918ba | 2220 | oled.Label((uint8_t *)"-", 32, 60);// Display at x,y |
asong | 1:e4b38d6918ba | 2221 | sprintf(display_buff, "%u", HR_Zone2[1]); // Convert int to char to display |
asong | 1:e4b38d6918ba | 2222 | oled.Label((uint8_t *)display_buff, 40, 60);// Display at x,y |
asong | 2:824ed4ae8d52 | 2223 | } else if(Target_Zone == 3) { |
asong | 1:e4b38d6918ba | 2224 | textProperties.fontColor = COLOR_GREEN; //Change font to green |
asong | 1:e4b38d6918ba | 2225 | oled.SetTextProperties(&textProperties);//Implement color change |
asong | 1:e4b38d6918ba | 2226 | sprintf(display_buff, "%u", HR_Zone3[0]); // Convert int to char to display |
asong | 1:e4b38d6918ba | 2227 | oled.Label((uint8_t *)display_buff, 10, 60); // Display at x,y |
asong | 1:e4b38d6918ba | 2228 | oled.Label((uint8_t *)"-", 32, 60); // Display at x,y |
asong | 1:e4b38d6918ba | 2229 | sprintf(display_buff, "%u", HR_Zone3[1]); // Convert int to char to display |
asong | 1:e4b38d6918ba | 2230 | oled.Label((uint8_t *)display_buff, 40, 60);// Display at x,y |
asong | 2:824ed4ae8d52 | 2231 | } else if(Target_Zone == 4) { |
asong | 1:e4b38d6918ba | 2232 | textProperties.fontColor = COLOR_RED; //Change font to red |
asong | 1:e4b38d6918ba | 2233 | oled.SetTextProperties(&textProperties);//Implement color change |
asong | 1:e4b38d6918ba | 2234 | sprintf(display_buff, "%u", HR_Zone4[0]); // Convert int to char to display |
asong | 1:e4b38d6918ba | 2235 | oled.Label((uint8_t *)display_buff, 10, 60); // Display at x,y |
asong | 1:e4b38d6918ba | 2236 | oled.Label((uint8_t *)"-", 32, 60); // Display at x,y |
asong | 1:e4b38d6918ba | 2237 | sprintf(display_buff, "%u", HR_Zone4[1]); // Convert int to char to display |
asong | 1:e4b38d6918ba | 2238 | oled.Label((uint8_t *)display_buff, 40, 60); // Display at x,y |
asong | 1:e4b38d6918ba | 2239 | } |
asong | 1:e4b38d6918ba | 2240 | textProperties.fontColor = COLOR_WHITE; //Change font to white |
asong | 1:e4b38d6918ba | 2241 | oled.SetTextProperties(&textProperties);//Implement color change |
asong | 2:824ed4ae8d52 | 2242 | break; |
asong | 2:824ed4ae8d52 | 2243 | } |
asong | 2:824ed4ae8d52 | 2244 | case 31: { |
asong | 2:824ed4ae8d52 | 2245 | oled.FillScreen(COLOR_BLACK); |
asong | 2:824ed4ae8d52 | 2246 | oled.Label((uint8_t *)"Enter HR", 10, 5);// Display at x,y |
asong | 2:824ed4ae8d52 | 2247 | oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y |
asong | 2:824ed4ae8d52 | 2248 | oled.Label((uint8_t *)"Next",60,80); //Display "Next" at x,y |
asong | 2:824ed4ae8d52 | 2249 | oled.Label((uint8_t *)"HR:", 10, 25); |
asong | 2:824ed4ae8d52 | 2250 | sprintf(display_buff, "%u", Heart_Rate); // Convert int to char to display |
asong | 2:824ed4ae8d52 | 2251 | textProperties.fontColor = COLOR_RED; //Change font to red |
asong | 2:824ed4ae8d52 | 2252 | oled.SetTextProperties(&textProperties);//Implement color change |
asong | 2:824ed4ae8d52 | 2253 | oled.Label((uint8_t *)display_buff, 40, 25); |
asong | 2:824ed4ae8d52 | 2254 | textProperties.fontColor = COLOR_WHITE; //Change font to white |
asong | 2:824ed4ae8d52 | 2255 | oled.SetTextProperties(&textProperties);//Implement color change |
asong | 2:824ed4ae8d52 | 2256 | oled.Label((uint8_t *)"Cur Zone:", 10, 45); |
asong | 2:824ed4ae8d52 | 2257 | if(Current_Zone == 1) { |
asong | 2:824ed4ae8d52 | 2258 | textProperties.fontColor = COLOR_YELLOW; |
asong | 2:824ed4ae8d52 | 2259 | oled.SetTextProperties(&textProperties); |
asong | 2:824ed4ae8d52 | 2260 | } else if(Current_Zone == 2) { |
asong | 2:824ed4ae8d52 | 2261 | textProperties.fontColor = COLOR_BLUE; |
asong | 2:824ed4ae8d52 | 2262 | oled.SetTextProperties(&textProperties); |
asong | 2:824ed4ae8d52 | 2263 | } else if(Current_Zone == 3) { |
asong | 2:824ed4ae8d52 | 2264 | textProperties.fontColor = COLOR_GREEN; |
asong | 2:824ed4ae8d52 | 2265 | oled.SetTextProperties(&textProperties); |
asong | 2:824ed4ae8d52 | 2266 | } else if(Current_Zone == 4) { |
asong | 2:824ed4ae8d52 | 2267 | textProperties.fontColor = COLOR_RED; |
asong | 2:824ed4ae8d52 | 2268 | oled.SetTextProperties(&textProperties); |
asong | 2:824ed4ae8d52 | 2269 | } |
asong | 2:824ed4ae8d52 | 2270 | sprintf(display_buff, "%u", Current_Zone); // Convert int to char to display |
asong | 2:824ed4ae8d52 | 2271 | oled.Label((uint8_t *)display_buff, 71, 45); |
asong | 2:824ed4ae8d52 | 2272 | textProperties.fontColor = COLOR_WHITE; //Change font to white |
asong | 2:824ed4ae8d52 | 2273 | oled.SetTextProperties(&textProperties);//Implement color change |
asong | 2:824ed4ae8d52 | 2274 | oled.Label((uint8_t *)"Prev Zone:", 10, 60); |
asong | 2:824ed4ae8d52 | 2275 | if(Prev_Zone == 1) { |
asong | 2:824ed4ae8d52 | 2276 | textProperties.fontColor = COLOR_YELLOW; |
asong | 2:824ed4ae8d52 | 2277 | oled.SetTextProperties(&textProperties); |
asong | 2:824ed4ae8d52 | 2278 | } else if(Prev_Zone == 2) { |
asong | 2:824ed4ae8d52 | 2279 | textProperties.fontColor = COLOR_BLUE; |
asong | 2:824ed4ae8d52 | 2280 | oled.SetTextProperties(&textProperties); |
asong | 2:824ed4ae8d52 | 2281 | } else if(Prev_Zone == 3) { |
asong | 2:824ed4ae8d52 | 2282 | textProperties.fontColor = COLOR_GREEN; |
asong | 2:824ed4ae8d52 | 2283 | oled.SetTextProperties(&textProperties); |
asong | 2:824ed4ae8d52 | 2284 | } else if(Prev_Zone == 4) { |
asong | 2:824ed4ae8d52 | 2285 | textProperties.fontColor = COLOR_RED; |
asong | 2:824ed4ae8d52 | 2286 | oled.SetTextProperties(&textProperties); |
asong | 2:824ed4ae8d52 | 2287 | } |
asong | 2:824ed4ae8d52 | 2288 | sprintf(display_buff, "%u", Prev_Zone); // Convert int to char to display |
asong | 2:824ed4ae8d52 | 2289 | oled.Label((uint8_t *)display_buff, 71, 60); |
asong | 2:824ed4ae8d52 | 2290 | textProperties.fontColor = COLOR_WHITE; //Change font to white |
asong | 2:824ed4ae8d52 | 2291 | oled.SetTextProperties(&textProperties);//Implement color change |
asong | 2:824ed4ae8d52 | 2292 | break; |
asong | 2:824ed4ae8d52 | 2293 | } |
asong | 2:824ed4ae8d52 | 2294 | case 32: { |
asong | 2:824ed4ae8d52 | 2295 | //Zone Boundary Info |
asong | 2:824ed4ae8d52 | 2296 | oled.FillScreen(COLOR_BLACK); |
asong | 2:824ed4ae8d52 | 2297 | oled.Label((uint8_t *)"HR Zone Info", 10, 5);// Display at x,y |
asong | 2:824ed4ae8d52 | 2298 | textProperties.fontColor = COLOR_YELLOW; //Change font to yellow |
asong | 2:824ed4ae8d52 | 2299 | oled.SetTextProperties(&textProperties);//Implement color change |
asong | 2:824ed4ae8d52 | 2300 | oled.Label((uint8_t *)"Z1:", 10, 20);// Display at x,y |
asong | 2:824ed4ae8d52 | 2301 | sprintf(display_buff, "%u", HR_Zone1[0]); // Convert int to char to display |
asong | 2:824ed4ae8d52 | 2302 | oled.Label((uint8_t *)display_buff, 30, 20);// Display at x,y |
asong | 2:824ed4ae8d52 | 2303 | oled.Label((uint8_t *)"-", 52, 20);// Display at x,y |
asong | 2:824ed4ae8d52 | 2304 | sprintf(display_buff, "%u", HR_Zone1[1]); // Convert int to char to display |
asong | 2:824ed4ae8d52 | 2305 | oled.Label((uint8_t *)display_buff, 60, 20);// Display at x,y |
asong | 2:824ed4ae8d52 | 2306 | textProperties.fontColor = COLOR_BLUE; //Change font to blue |
asong | 2:824ed4ae8d52 | 2307 | oled.SetTextProperties(&textProperties);//Implement color change |
asong | 2:824ed4ae8d52 | 2308 | oled.Label((uint8_t *)"Z2:", 10, 35);// Display at x,y |
asong | 2:824ed4ae8d52 | 2309 | sprintf(display_buff, "%u", HR_Zone2[0]); // Convert int to char to display |
asong | 2:824ed4ae8d52 | 2310 | oled.Label((uint8_t *)display_buff, 30, 35);// Display at x,y |
asong | 2:824ed4ae8d52 | 2311 | oled.Label((uint8_t *)"-", 52, 35);// Display at x,y |
asong | 2:824ed4ae8d52 | 2312 | sprintf(display_buff, "%u", HR_Zone2[1]); // Convert int to char to display |
asong | 2:824ed4ae8d52 | 2313 | oled.Label((uint8_t *)display_buff, 60, 35);// Display at x,y |
asong | 2:824ed4ae8d52 | 2314 | textProperties.fontColor = COLOR_GREEN; //Change font to green |
asong | 2:824ed4ae8d52 | 2315 | oled.SetTextProperties(&textProperties);//Implement color change |
asong | 2:824ed4ae8d52 | 2316 | oled.Label((uint8_t *)"Z3:", 10, 50);// Display at x,y |
asong | 2:824ed4ae8d52 | 2317 | sprintf(display_buff, "%u", HR_Zone3[0]); // Convert int to char to display |
asong | 2:824ed4ae8d52 | 2318 | oled.Label((uint8_t *)display_buff, 30, 50);// Display at x,y |
asong | 2:824ed4ae8d52 | 2319 | oled.Label((uint8_t *)"-", 52, 50);// Display at x,y |
asong | 2:824ed4ae8d52 | 2320 | sprintf(display_buff, "%u", HR_Zone3[1]); // Convert int to char to display |
asong | 2:824ed4ae8d52 | 2321 | oled.Label((uint8_t *)display_buff, 60, 50);// Display at x,y |
asong | 2:824ed4ae8d52 | 2322 | textProperties.fontColor = COLOR_RED; //Change font to red |
asong | 2:824ed4ae8d52 | 2323 | oled.SetTextProperties(&textProperties);//Implement color change |
asong | 2:824ed4ae8d52 | 2324 | oled.Label((uint8_t *)"Z4:", 10, 65);// Display at x,y |
asong | 2:824ed4ae8d52 | 2325 | sprintf(display_buff, "%u", HR_Zone4[0]); // Convert int to char to display |
asong | 2:824ed4ae8d52 | 2326 | oled.Label((uint8_t *)display_buff, 30, 65);// Display at x,y |
asong | 2:824ed4ae8d52 | 2327 | oled.Label((uint8_t *)"-", 52, 65);// Display at x,y |
asong | 2:824ed4ae8d52 | 2328 | sprintf(display_buff, "%u", HR_Zone4[1]); // Convert int to char to display |
asong | 2:824ed4ae8d52 | 2329 | oled.Label((uint8_t *)display_buff, 60, 65);// Display at x,y |
asong | 2:824ed4ae8d52 | 2330 | textProperties.fontColor = COLOR_WHITE; //Change font to white |
asong | 2:824ed4ae8d52 | 2331 | oled.SetTextProperties(&textProperties);//Implement color change |
asong | 2:824ed4ae8d52 | 2332 | oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y |
asong | 2:824ed4ae8d52 | 2333 | oled.Label((uint8_t *)"Next",60,80); //Display "Next" at x,y |
asong | 2:824ed4ae8d52 | 2334 | break; |
nbaker | 8:a5c77b45008d | 2335 | } |
asong | 14:c3b080cdf36b | 2336 | case 33: {//Heart rate simulator |
nbaker | 8:a5c77b45008d | 2337 | oled.FillScreen(COLOR_BLACK); |
asong | 14:c3b080cdf36b | 2338 | textProperties.fontColor = COLOR_WHITE; |
asong | 14:c3b080cdf36b | 2339 | oled.Label((uint8_t *)"HR Simulation", 10, 5);// Display at x,y |
asong | 14:c3b080cdf36b | 2340 | oled.Label((uint8_t *)"HR: ", 10, 40);// Display at x,y |
nbaker | 8:a5c77b45008d | 2341 | oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y |
nbaker | 8:a5c77b45008d | 2342 | oled.Label((uint8_t *)"Next",60,80); //Display "Next" at x,y |
asong | 14:c3b080cdf36b | 2343 | oled.Label((uint8_t *)"On",75,25); // "*" at x,y |
asong | 14:c3b080cdf36b | 2344 | oled.Label((uint8_t *)"Off",75,55); // "*" at x,y |
asong | 14:c3b080cdf36b | 2345 | sprintf(display_buff, "%u", Heart_Rate); // Convert int to char to display |
asong | 14:c3b080cdf36b | 2346 | if(Current_Zone == 1) { |
asong | 14:c3b080cdf36b | 2347 | textProperties.fontColor = COLOR_YELLOW; |
asong | 14:c3b080cdf36b | 2348 | oled.SetTextProperties(&textProperties); |
asong | 14:c3b080cdf36b | 2349 | } else if(Current_Zone == 2) { |
asong | 14:c3b080cdf36b | 2350 | textProperties.fontColor = COLOR_BLUE; |
asong | 14:c3b080cdf36b | 2351 | oled.SetTextProperties(&textProperties); |
asong | 14:c3b080cdf36b | 2352 | } else if(Current_Zone == 3) { |
asong | 14:c3b080cdf36b | 2353 | textProperties.fontColor = COLOR_GREEN; |
asong | 14:c3b080cdf36b | 2354 | oled.SetTextProperties(&textProperties); |
asong | 14:c3b080cdf36b | 2355 | } else if(Current_Zone == 4) { |
asong | 14:c3b080cdf36b | 2356 | textProperties.fontColor = COLOR_RED; |
asong | 14:c3b080cdf36b | 2357 | oled.SetTextProperties(&textProperties); |
asong | 14:c3b080cdf36b | 2358 | } |
asong | 14:c3b080cdf36b | 2359 | oled.Label((uint8_t *)display_buff, 35, 40);// Display at x,y |
nbaker | 8:a5c77b45008d | 2360 | textProperties.fontColor = COLOR_WHITE; |
nbaker | 8:a5c77b45008d | 2361 | oled.SetTextProperties(&textProperties); |
asong | 14:c3b080cdf36b | 2362 | break; |
nbaker | 8:a5c77b45008d | 2363 | } |
nbaker | 18:1f28eca85e3f | 2364 | case 41: { //Fall mode |
nbaker | 18:1f28eca85e3f | 2365 | oled.FillScreen(COLOR_BLACK); |
nbaker | 18:1f28eca85e3f | 2366 | oled.Label((uint8_t *)"Adj Fall Mode", 10, 5); |
nbaker | 18:1f28eca85e3f | 2367 | sprintf(display_buff, "%u", Fall_Alert_Mode); //Convert int to char array for displaying mode |
nbaker | 18:1f28eca85e3f | 2368 | oled.Label((uint8_t *)"Mode:", 5, 30); |
nbaker | 18:1f28eca85e3f | 2369 | oled.Label((uint8_t *)"+",85,15); // "*" at x,y |
nbaker | 18:1f28eca85e3f | 2370 | oled.Label((uint8_t *)"-",85,60); // "*" at x,y |
nbaker | 18:1f28eca85e3f | 2371 | oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y |
nbaker | 18:1f28eca85e3f | 2372 | oled.Label((uint8_t *)"Next",60,80); //Display "Next" at x,y |
nbaker | 18:1f28eca85e3f | 2373 | textProperties.fontColor = COLOR_GREEN; |
nbaker | 18:1f28eca85e3f | 2374 | oled.SetTextProperties(&textProperties); |
nbaker | 18:1f28eca85e3f | 2375 | oled.Label((uint8_t *)display_buff,43,30); // Display at x,y |
nbaker | 18:1f28eca85e3f | 2376 | textProperties.fontColor = COLOR_WHITE; |
nbaker | 18:1f28eca85e3f | 2377 | oled.SetTextProperties(&textProperties); |
nbaker | 18:1f28eca85e3f | 2378 | break; |
nbaker | 18:1f28eca85e3f | 2379 | } |
nbaker | 18:1f28eca85e3f | 2380 | case 42: { //Fall Thresh |
nbaker | 18:1f28eca85e3f | 2381 | oled.FillScreen(COLOR_BLACK); |
nbaker | 18:1f28eca85e3f | 2382 | oled.Label((uint8_t *)"Adj F-Th", 10, 5); |
nbaker | 18:1f28eca85e3f | 2383 | sprintf(display_buff, "%2.2f g", Fall_Thresh); //Convert int to char array for displaying mode |
nbaker | 18:1f28eca85e3f | 2384 | oled.Label((uint8_t *)"F_Th:", 5, 30); |
nbaker | 18:1f28eca85e3f | 2385 | oled.Label((uint8_t *)"+",85,15); // "*" at x,y |
nbaker | 18:1f28eca85e3f | 2386 | oled.Label((uint8_t *)"-",85,60); // "*" at x,y |
nbaker | 18:1f28eca85e3f | 2387 | oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y |
nbaker | 18:1f28eca85e3f | 2388 | oled.Label((uint8_t *)"Next",60,80); //Display "Next" at x,y |
nbaker | 18:1f28eca85e3f | 2389 | textProperties.fontColor = COLOR_GREEN; |
nbaker | 18:1f28eca85e3f | 2390 | oled.SetTextProperties(&textProperties); |
nbaker | 18:1f28eca85e3f | 2391 | oled.Label((uint8_t *)display_buff,43,30); // Display at x,y |
nbaker | 18:1f28eca85e3f | 2392 | textProperties.fontColor = COLOR_WHITE; |
nbaker | 18:1f28eca85e3f | 2393 | oled.SetTextProperties(&textProperties); |
nbaker | 18:1f28eca85e3f | 2394 | break; |
nbaker | 18:1f28eca85e3f | 2395 | } |
nbaker | 18:1f28eca85e3f | 2396 | |
nbaker | 8:a5c77b45008d | 2397 | case 43: { //Impact Thresh |
nbaker | 8:a5c77b45008d | 2398 | oled.FillScreen(COLOR_BLACK); |
nbaker | 8:a5c77b45008d | 2399 | oled.Label((uint8_t *)"Adj I-Th", 10, 5); |
nbaker | 8:a5c77b45008d | 2400 | sprintf(display_buff, "%2.2f g", Impact_Thresh); //Convert int to char array for displaying mode |
nbaker | 8:a5c77b45008d | 2401 | oled.Label((uint8_t *)"I_Th:", 5, 30); |
nbaker | 8:a5c77b45008d | 2402 | oled.Label((uint8_t *)"+",85,15); // "*" at x,y |
nbaker | 8:a5c77b45008d | 2403 | oled.Label((uint8_t *)"-",85,60); // "*" at x,y |
nbaker | 8:a5c77b45008d | 2404 | oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y |
nbaker | 8:a5c77b45008d | 2405 | oled.Label((uint8_t *)"Next",60,80); //Display "Next" at x,y |
nbaker | 8:a5c77b45008d | 2406 | textProperties.fontColor = COLOR_GREEN; |
nbaker | 8:a5c77b45008d | 2407 | oled.SetTextProperties(&textProperties); |
nbaker | 8:a5c77b45008d | 2408 | oled.Label((uint8_t *)display_buff,43,30); // Display at x,y |
nbaker | 8:a5c77b45008d | 2409 | textProperties.fontColor = COLOR_WHITE; |
nbaker | 8:a5c77b45008d | 2410 | oled.SetTextProperties(&textProperties); |
nbaker | 8:a5c77b45008d | 2411 | break; |
nbaker | 8:a5c77b45008d | 2412 | } |
nbaker | 8:a5c77b45008d | 2413 | case 44: { //Motion Thresh |
nbaker | 8:a5c77b45008d | 2414 | oled.FillScreen(COLOR_BLACK); |
nbaker | 8:a5c77b45008d | 2415 | oled.Label((uint8_t *)"Adj M-Th", 10, 5); |
nbaker | 8:a5c77b45008d | 2416 | sprintf(display_buff, "%4.0f D/S", Movement_Thresh); //Convert int to char array for displaying mode |
nbaker | 8:a5c77b45008d | 2417 | oled.Label((uint8_t *)"M_Th:", 5, 30); |
nbaker | 8:a5c77b45008d | 2418 | oled.Label((uint8_t *)"+",85,15); // "*" at x,y |
nbaker | 8:a5c77b45008d | 2419 | oled.Label((uint8_t *)"-",85,60); // "*" at x,y |
nbaker | 8:a5c77b45008d | 2420 | oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y |
nbaker | 9:d2e39ee9fedd | 2421 | oled.Label((uint8_t *)"Next",60,80); //Display "Next" at x,y |
nbaker | 9:d2e39ee9fedd | 2422 | textProperties.fontColor = COLOR_GREEN; |
nbaker | 9:d2e39ee9fedd | 2423 | oled.SetTextProperties(&textProperties); |
nbaker | 9:d2e39ee9fedd | 2424 | oled.Label((uint8_t *)display_buff,43,30); // Display at x,y |
nbaker | 9:d2e39ee9fedd | 2425 | textProperties.fontColor = COLOR_WHITE; |
nbaker | 9:d2e39ee9fedd | 2426 | oled.SetTextProperties(&textProperties); |
nbaker | 9:d2e39ee9fedd | 2427 | break; |
nbaker | 9:d2e39ee9fedd | 2428 | }//end case 44 |
nbaker | 9:d2e39ee9fedd | 2429 | case 45: { //Min_Movement_Time |
nbaker | 9:d2e39ee9fedd | 2430 | oled.FillScreen(COLOR_BLACK); |
nbaker | 9:d2e39ee9fedd | 2431 | oled.Label((uint8_t *)"Adj MinM_Tim", 10, 5); |
nbaker | 9:d2e39ee9fedd | 2432 | sprintf(display_buff, "%1.2fSec", Min_Movement_Time); //Convert int to char array for displaying mode |
nbaker | 9:d2e39ee9fedd | 2433 | oled.Label((uint8_t *)"m_Tm:", 5, 30); |
nbaker | 9:d2e39ee9fedd | 2434 | oled.Label((uint8_t *)"+",85,15); // "*" at x,y |
nbaker | 9:d2e39ee9fedd | 2435 | oled.Label((uint8_t *)"-",85,60); // "*" at x,y |
nbaker | 9:d2e39ee9fedd | 2436 | oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y |
nbaker | 9:d2e39ee9fedd | 2437 | oled.Label((uint8_t *)"Next",60,80); //Display "Next" at x,y |
nbaker | 8:a5c77b45008d | 2438 | textProperties.fontColor = COLOR_GREEN; |
nbaker | 8:a5c77b45008d | 2439 | oled.SetTextProperties(&textProperties); |
nbaker | 8:a5c77b45008d | 2440 | oled.Label((uint8_t *)display_buff,43,30); // Display at x,y |
nbaker | 8:a5c77b45008d | 2441 | textProperties.fontColor = COLOR_WHITE; |
nbaker | 8:a5c77b45008d | 2442 | oled.SetTextProperties(&textProperties); |
nbaker | 8:a5c77b45008d | 2443 | break; |
nbaker | 9:d2e39ee9fedd | 2444 | }//end case 45 |
nbaker | 9:d2e39ee9fedd | 2445 | case 46: { //Min_Movement_Time |
nbaker | 9:d2e39ee9fedd | 2446 | oled.FillScreen(COLOR_BLACK); |
nbaker | 9:d2e39ee9fedd | 2447 | oled.Label((uint8_t *)"Adj MinM_Dur", 10, 5); |
nbaker | 9:d2e39ee9fedd | 2448 | sprintf(display_buff, "%2.1fSec", Min_Movement_duration); //Convert int to char array for displaying mode |
nbaker | 9:d2e39ee9fedd | 2449 | oled.Label((uint8_t *)"mDur:", 5, 30); |
nbaker | 9:d2e39ee9fedd | 2450 | oled.Label((uint8_t *)"+",85,15); // "*" at x,y |
nbaker | 9:d2e39ee9fedd | 2451 | oled.Label((uint8_t *)"-",85,60); // "*" at x,y |
nbaker | 9:d2e39ee9fedd | 2452 | oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y |
nbaker | 9:d2e39ee9fedd | 2453 | // oled.Label((uint8_t *)"Next",60,80); //Display "Next" at x,y |
nbaker | 9:d2e39ee9fedd | 2454 | textProperties.fontColor = COLOR_GREEN; |
nbaker | 9:d2e39ee9fedd | 2455 | oled.SetTextProperties(&textProperties); |
nbaker | 9:d2e39ee9fedd | 2456 | oled.Label((uint8_t *)display_buff,43,30); // Display at x,y |
nbaker | 9:d2e39ee9fedd | 2457 | textProperties.fontColor = COLOR_WHITE; |
nbaker | 9:d2e39ee9fedd | 2458 | oled.SetTextProperties(&textProperties); |
nbaker | 9:d2e39ee9fedd | 2459 | break; |
nbaker | 9:d2e39ee9fedd | 2460 | }//end case 46 |
nbaker | 10:eaea844e763c | 2461 | |
nbaker | 10:eaea844e763c | 2462 | case 47: { //Post fall "are you OK?" screen |
nbaker | 10:eaea844e763c | 2463 | oled.FillScreen(COLOR_BLACK); |
nbaker | 10:eaea844e763c | 2464 | textProperties.fontColor = COLOR_RED; |
nbaker | 10:eaea844e763c | 2465 | oled.SetTextProperties(&textProperties); |
nbaker | 10:eaea844e763c | 2466 | oled.Label((uint8_t *)"Fall Detected!", 5, 5); |
nbaker | 10:eaea844e763c | 2467 | textProperties.font = OpenSans_12x18_Regular; // Max Width of Character = 12px, Max Height of Character = 18px |
nbaker | 10:eaea844e763c | 2468 | textProperties.fontColor = COLOR_WHITE; |
nbaker | 10:eaea844e763c | 2469 | oled.SetTextProperties(&textProperties); |
nbaker | 10:eaea844e763c | 2470 | oled.Label((uint8_t *)"Do you need", 5, 20); |
nbaker | 10:eaea844e763c | 2471 | oled.Label((uint8_t *)"Help?", 10, 35); |
nbaker | 10:eaea844e763c | 2472 | //oled.Label((uint8_t *)"+",85,15); // "*" at x,y |
nbaker | 10:eaea844e763c | 2473 | //oled.Label((uint8_t *)"-",85,60); // "*" at x,y |
nbaker | 10:eaea844e763c | 2474 | oled.Label((uint8_t *)"No",10,75); // Display "Back" at x,y |
nbaker | 10:eaea844e763c | 2475 | oled.Label((uint8_t *)"YES!",60,75); //Display "Next" at x,y |
nbaker | 10:eaea844e763c | 2476 | textProperties.font = OpenSans_10x15_Regular; // Max Width of Character = 10px, Max Height of Character = 15px |
nbaker | 10:eaea844e763c | 2477 | textProperties.fontColor = COLOR_WHITE; |
nbaker | 10:eaea844e763c | 2478 | oled.SetTextProperties(&textProperties); |
nbaker | 10:eaea844e763c | 2479 | break; |
nbaker | 10:eaea844e763c | 2480 | }//end case 47 |
nbaker | 10:eaea844e763c | 2481 | |
nbaker | 10:eaea844e763c | 2482 | case 48: { //Sending Fall alert screen |
nbaker | 10:eaea844e763c | 2483 | oled.FillScreen(COLOR_BLACK); |
nbaker | 10:eaea844e763c | 2484 | textProperties.fontColor = COLOR_RED; |
nbaker | 10:eaea844e763c | 2485 | oled.SetTextProperties(&textProperties); |
nbaker | 10:eaea844e763c | 2486 | oled.Label((uint8_t *)"Fall Detected!", 5, 5); |
nbaker | 10:eaea844e763c | 2487 | textProperties.font = OpenSans_12x18_Regular; // Max Width of Character = 12px, Max Height of Character = 18px |
nbaker | 10:eaea844e763c | 2488 | textProperties.fontColor = COLOR_WHITE; |
nbaker | 10:eaea844e763c | 2489 | oled.SetTextProperties(&textProperties); |
nbaker | 10:eaea844e763c | 2490 | oled.Label((uint8_t *)"Sending", 20, 40); |
nbaker | 10:eaea844e763c | 2491 | oled.Label((uint8_t *)"Alert", 25, 55); |
nbaker | 10:eaea844e763c | 2492 | oled.Label((uint8_t *)"Dismiss?",5,75); // Display "Back" at x,y |
nbaker | 10:eaea844e763c | 2493 | //oled.Label((uint8_t *)"YES!",60,80); //Display "Next" at x,y |
nbaker | 10:eaea844e763c | 2494 | textProperties.font = OpenSans_10x15_Regular; // Max Width of Character = 10px, Max Height of Character = 15px |
nbaker | 10:eaea844e763c | 2495 | textProperties.fontColor = COLOR_WHITE; |
nbaker | 10:eaea844e763c | 2496 | oled.SetTextProperties(&textProperties); |
nbaker | 10:eaea844e763c | 2497 | break; |
nbaker | 10:eaea844e763c | 2498 | }//end case 48 |
nbaker | 12:fd39a7983e06 | 2499 | |
nbaker | 12:fd39a7983e06 | 2500 | case 49: { //Testing WDT diagnostic screen |
nbaker | 12:fd39a7983e06 | 2501 | oled.FillScreen(COLOR_BLACK); // Clear screen |
nbaker | 12:fd39a7983e06 | 2502 | textProperties.fontColor = COLOR_RED; |
nbaker | 12:fd39a7983e06 | 2503 | oled.SetTextProperties(&textProperties); |
nbaker | 12:fd39a7983e06 | 2504 | oled.Label((uint8_t *)"WDT Test",15,5); // Display at x,y |
nbaker | 12:fd39a7983e06 | 2505 | textProperties.fontColor = COLOR_WHITE; |
nbaker | 12:fd39a7983e06 | 2506 | oled.SetTextProperties(&textProperties); |
nbaker | 12:fd39a7983e06 | 2507 | oled.Label((uint8_t *)"This will",16,25); // Display at x,y |
nbaker | 12:fd39a7983e06 | 2508 | oled.Label((uint8_t *)"Cause a",17,40); // Display at x,y |
nbaker | 12:fd39a7983e06 | 2509 | oled.Label((uint8_t *)"SW Reset",15,55); // Display at x,y |
nbaker | 12:fd39a7983e06 | 2510 | |
nbaker | 12:fd39a7983e06 | 2511 | oled.Label((uint8_t *)"*",85,15); // "*" at x,y |
nbaker | 12:fd39a7983e06 | 2512 | oled.Label((uint8_t *)"*",85,60); // "*" at x,y |
nbaker | 12:fd39a7983e06 | 2513 | oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y |
nbaker | 12:fd39a7983e06 | 2514 | oled.Label((uint8_t *)"Enter",60,80); //Display at x,y |
nbaker | 12:fd39a7983e06 | 2515 | break; |
nbaker | 12:fd39a7983e06 | 2516 | }//end case 49 |
nbaker | 12:fd39a7983e06 | 2517 | |
nbaker | 12:fd39a7983e06 | 2518 | case 50: { //WDT timeout screen |
nbaker | 12:fd39a7983e06 | 2519 | CLRWDT(); |
nbaker | 12:fd39a7983e06 | 2520 | oled.FillScreen(COLOR_BLACK); // Clear screen |
nbaker | 12:fd39a7983e06 | 2521 | textProperties.fontColor = COLOR_RED; |
nbaker | 12:fd39a7983e06 | 2522 | oled.SetTextProperties(&textProperties); |
nbaker | 12:fd39a7983e06 | 2523 | oled.Label((uint8_t *)"WDT Test",15,5); // Display at x,y |
nbaker | 12:fd39a7983e06 | 2524 | textProperties.fontColor = COLOR_WHITE; |
nbaker | 12:fd39a7983e06 | 2525 | oled.SetTextProperties(&textProperties); |
nbaker | 12:fd39a7983e06 | 2526 | oled.Label((uint8_t *)"Reset in",17,25); // Display at x,y |
nbaker | 12:fd39a7983e06 | 2527 | |
nbaker | 12:fd39a7983e06 | 2528 | sprintf(display_buff, "%2.1f Sec", WDT_TIME); //Convert int to char array for displaying mode |
nbaker | 12:fd39a7983e06 | 2529 | oled.Label((uint8_t *)display_buff,18,40); // Display at x,y |
nbaker | 12:fd39a7983e06 | 2530 | |
nbaker | 12:fd39a7983e06 | 2531 | //oled.Label((uint8_t *)"*",85,15); // "*" at x,y |
nbaker | 12:fd39a7983e06 | 2532 | //oled.Label((uint8_t *)"*",85,60); // "*" at x,y |
nbaker | 12:fd39a7983e06 | 2533 | //oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y |
nbaker | 12:fd39a7983e06 | 2534 | //oled.Label((uint8_t *)"Enter",60,80); //Display at x,y |
nbaker | 12:fd39a7983e06 | 2535 | haptic = 0; |
nbaker | 12:fd39a7983e06 | 2536 | wait(WDT_TIME+1.0); |
nbaker | 12:fd39a7983e06 | 2537 | break; |
nbaker | 12:fd39a7983e06 | 2538 | }//end case 50 |
nbaker | 13:37cd579208e9 | 2539 | |
nbaker | 13:37cd579208e9 | 2540 | case 51: { //Sending panic alert screen |
nbaker | 13:37cd579208e9 | 2541 | oled.FillScreen(COLOR_BLACK); |
nbaker | 13:37cd579208e9 | 2542 | textProperties.fontColor = COLOR_RED; |
nbaker | 13:37cd579208e9 | 2543 | oled.SetTextProperties(&textProperties); |
nbaker | 13:37cd579208e9 | 2544 | oled.Label((uint8_t *)"Panic Alert!", 5, 5); |
nbaker | 13:37cd579208e9 | 2545 | textProperties.font = OpenSans_12x18_Regular; // Max Width of Character = 12px, Max Height of Character = 18px |
nbaker | 13:37cd579208e9 | 2546 | textProperties.fontColor = COLOR_WHITE; |
nbaker | 13:37cd579208e9 | 2547 | oled.SetTextProperties(&textProperties); |
nbaker | 13:37cd579208e9 | 2548 | oled.Label((uint8_t *)"Sending", 20, 40); |
nbaker | 13:37cd579208e9 | 2549 | oled.Label((uint8_t *)"Alert", 25, 55); |
nbaker | 13:37cd579208e9 | 2550 | oled.Label((uint8_t *)"Dismiss?",5,75); // Display "Back" at x,y |
nbaker | 13:37cd579208e9 | 2551 | //oled.Label((uint8_t *)"YES!",60,80); //Display "Next" at x,y |
nbaker | 13:37cd579208e9 | 2552 | textProperties.font = OpenSans_10x15_Regular; // Max Width of Character = 10px, Max Height of Character = 15px |
nbaker | 13:37cd579208e9 | 2553 | textProperties.fontColor = COLOR_WHITE; |
nbaker | 13:37cd579208e9 | 2554 | oled.SetTextProperties(&textProperties); |
nbaker | 13:37cd579208e9 | 2555 | break; |
nbaker | 13:37cd579208e9 | 2556 | }//end case 51 |
nbaker | 9:d2e39ee9fedd | 2557 | |
nbaker | 0:d1d36a3da39b | 2558 | #endif // end of non-production/debug version code |
nbaker | 8:a5c77b45008d | 2559 | |
nbaker | 8:a5c77b45008d | 2560 | case 71: {// BLE |
nbaker | 8:a5c77b45008d | 2561 | oled.FillScreen(COLOR_BLACK); // Clear screen |
nbaker | 11:ccda4d44bd8e | 2562 | textProperties.fontColor = COLOR_BLUE; |
nbaker | 11:ccda4d44bd8e | 2563 | oled.SetTextProperties(&textProperties); |
nbaker | 12:fd39a7983e06 | 2564 | oled.Label((uint8_t *)"BLUETOOTH",15,5); // Display at x,y |
nbaker | 8:a5c77b45008d | 2565 | textProperties.fontColor = COLOR_WHITE; |
nbaker | 8:a5c77b45008d | 2566 | oled.SetTextProperties(&textProperties); |
nbaker | 11:ccda4d44bd8e | 2567 | oled.Label((uint8_t *)"Enter",60,80); //Display at x,y |
nbaker | 8:a5c77b45008d | 2568 | oled.Label((uint8_t *)"*",85,15); // "*" at x,y |
nbaker | 8:a5c77b45008d | 2569 | oled.Label((uint8_t *)"*",85,60); // "*" at x,y |
nbaker | 9:d2e39ee9fedd | 2570 | oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y |
nbaker | 8:a5c77b45008d | 2571 | break; |
nbaker | 8:a5c77b45008d | 2572 | } |
nbaker | 8:a5c77b45008d | 2573 | |
nbaker | 8:a5c77b45008d | 2574 | case 72: {// BlueTooth on/off |
nbaker | 11:ccda4d44bd8e | 2575 | oled.FillScreen(COLOR_BLACK); // Clear screen |
nbaker | 11:ccda4d44bd8e | 2576 | textProperties.fontColor = COLOR_BLUE; |
nbaker | 11:ccda4d44bd8e | 2577 | oled.SetTextProperties(&textProperties); |
nbaker | 11:ccda4d44bd8e | 2578 | oled.Label((uint8_t *)"BLUETOOTH",10,5); // Display at x,y |
nbaker | 11:ccda4d44bd8e | 2579 | textProperties.fontColor = COLOR_WHITE; |
nbaker | 11:ccda4d44bd8e | 2580 | oled.SetTextProperties(&textProperties); |
nbaker | 8:a5c77b45008d | 2581 | if (BLE_On == 1) { |
nbaker | 8:a5c77b45008d | 2582 | |
nbaker | 11:ccda4d44bd8e | 2583 | /* Display PAIR CODE in a 90px by 18px textbox at x=0,y=25 */ |
nbaker | 11:ccda4d44bd8e | 2584 | strcpy((char *) text,"PAIR CODE"); |
nbaker | 11:ccda4d44bd8e | 2585 | oled.TextBox((uint8_t *)text,10,25,80,18); |
nbaker | 11:ccda4d44bd8e | 2586 | |
nbaker | 11:ccda4d44bd8e | 2587 | /* Display Bond Pass Key in a 90px by 18px textbox at x=0,y=40 */ |
nbaker | 8:a5c77b45008d | 2588 | sprintf(text,"%d", kw40z_device.GetPassKey()); |
nbaker | 11:ccda4d44bd8e | 2589 | oled.TextBox((uint8_t *)text,10,45,80,18); |
nbaker | 8:a5c77b45008d | 2590 | } else { |
nbaker | 11:ccda4d44bd8e | 2591 | oled.Label((uint8_t *)" Off ",40,45); |
nbaker | 8:a5c77b45008d | 2592 | } |
nbaker | 8:a5c77b45008d | 2593 | // oled.Label((uint8_t *)"*",85,15); // "*" at x,y |
nbaker | 8:a5c77b45008d | 2594 | // oled.Label((uint8_t *)"*",85,60); // "*" at x,y |
nbaker | 8:a5c77b45008d | 2595 | oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y |
nbaker | 9:d2e39ee9fedd | 2596 | oled.Label((uint8_t *)"Toggle",59,80); //Display "Toggle" at x,y |
nbaker | 8:a5c77b45008d | 2597 | break; |
nbaker | 8:a5c77b45008d | 2598 | } |
nbaker | 8:a5c77b45008d | 2599 | |
nbaker | 8:a5c77b45008d | 2600 | |
asong | 1:e4b38d6918ba | 2601 | default: { |
asong | 2:824ed4ae8d52 | 2602 | Error_Num=1; |
asong | 2:824ed4ae8d52 | 2603 | error_screen(); // Clear screen |
asong | 2:824ed4ae8d52 | 2604 | break; |
asong | 2:824ed4ae8d52 | 2605 | } |
nbaker | 8:a5c77b45008d | 2606 | }//end of switch |
nbaker | 8:a5c77b45008d | 2607 | __enable_irq(); // Enable all Interrupts |
nbaker | 8:a5c77b45008d | 2608 | }// end upday_display() |
nbaker | 8:a5c77b45008d | 2609 | |
asong | 1:e4b38d6918ba | 2610 | void error_screen(void) |
asong | 1:e4b38d6918ba | 2611 | { |
asong | 1:e4b38d6918ba | 2612 | oled.FillScreen(COLOR_RED); // Clear screen |
asong | 1:e4b38d6918ba | 2613 | oled.Label((uint8_t *)"Error! ",30,30); // Display error at x,y |
asong | 1:e4b38d6918ba | 2614 | sprintf(text_1," %i ",Error_Num); |
asong | 1:e4b38d6918ba | 2615 | oled.Label((uint8_t *)text_1,30,60); // Display error at x,y |
asong | 1:e4b38d6918ba | 2616 | wait(3); // wait 3 seconds |
asong | 1:e4b38d6918ba | 2617 | oled.FillScreen(COLOR_BLACK); // Clear screen |
nbaker | 0:d1d36a3da39b | 2618 | } |
asong | 2:824ed4ae8d52 | 2619 | |
asong | 2:824ed4ae8d52 | 2620 | /***************************************************************************** |
asong | 2:824ed4ae8d52 | 2621 | Name: StartHaptic |
asong | 2:824ed4ae8d52 | 2622 | Purpose: Cause the HexiHeart device to vibrate for a predetermined amount of |
asong | 2:824ed4ae8d52 | 2623 | time |
asong | 2:824ed4ae8d52 | 2624 | Inputs: None |
asong | 2:824ed4ae8d52 | 2625 | Returns: None |
asong | 2:824ed4ae8d52 | 2626 | ******************************************************************************/ |
nbaker | 0:d1d36a3da39b | 2627 | void StartHaptic(void) |
nbaker | 0:d1d36a3da39b | 2628 | { |
nbaker | 10:eaea844e763c | 2629 | Haptic_Timer.attach(&Haptic_Off_,(0.05)); |
nbaker | 10:eaea844e763c | 2630 | // hapticTimer.start(30); // was originaly 50, then 30 |
nbaker | 8:a5c77b45008d | 2631 | /* this 30 value seems to not work after Neil added a global |
nbaker | 8:a5c77b45008d | 2632 | __disable_irq() and __enable_irq() for the update_display() functions on 2/18/18 |
nbaker | 8:a5c77b45008d | 2633 | */ |
nbaker | 0:d1d36a3da39b | 2634 | haptic = 1; |
nbaker | 0:d1d36a3da39b | 2635 | } |
nbaker | 10:eaea844e763c | 2636 | void Haptic_Off_(void) |
nbaker | 10:eaea844e763c | 2637 | { |
nbaker | 10:eaea844e763c | 2638 | haptic = 0; |
nbaker | 10:eaea844e763c | 2639 | } |
nbaker | 0:d1d36a3da39b | 2640 | |
asong | 2:824ed4ae8d52 | 2641 | /***************************************************************************** |
asong | 2:824ed4ae8d52 | 2642 | Name: StartHaptic |
asong | 2:824ed4ae8d52 | 2643 | Purpose: Cause the HexiHeart device to vibrate for x amount of time |
asong | 2:824ed4ae8d52 | 2644 | Inputs: An int representing the duration of the vibration |
asong | 2:824ed4ae8d52 | 2645 | Returns: None |
asong | 2:824ed4ae8d52 | 2646 | ******************************************************************************/ |
nbaker | 8:a5c77b45008d | 2647 | |
asong | 1:e4b38d6918ba | 2648 | void StartHaptic(int x) |
nbaker | 8:a5c77b45008d | 2649 | { |
asong | 1:e4b38d6918ba | 2650 | hapticTimer.start(x); |
asong | 2:824ed4ae8d52 | 2651 | haptic = 1; |
asong | 1:e4b38d6918ba | 2652 | } |
asong | 1:e4b38d6918ba | 2653 | |
asong | 1:e4b38d6918ba | 2654 | void StopHaptic(void const *n) |
asong | 1:e4b38d6918ba | 2655 | { |
nbaker | 0:d1d36a3da39b | 2656 | haptic = 0; |
nbaker | 0:d1d36a3da39b | 2657 | hapticTimer.stop(); |
nbaker | 0:d1d36a3da39b | 2658 | } |
asong | 2:824ed4ae8d52 | 2659 | |
asong | 2:824ed4ae8d52 | 2660 | /***************************************************************************** |
asong | 2:824ed4ae8d52 | 2661 | Name: Increment_Age |
asong | 2:824ed4ae8d52 | 2662 | Purpose: Increment the user's age by 1 |
asong | 2:824ed4ae8d52 | 2663 | Inputs: None |
asong | 2:824ed4ae8d52 | 2664 | Returns: None |
asong | 2:824ed4ae8d52 | 2665 | ******************************************************************************/ |
asong | 2:824ed4ae8d52 | 2666 | void Increment_Age() |
asong | 2:824ed4ae8d52 | 2667 | { |
asong | 2:824ed4ae8d52 | 2668 | StartHaptic(); |
asong | 2:824ed4ae8d52 | 2669 | if(Age < 100) { |
asong | 2:824ed4ae8d52 | 2670 | Age += 1; |
asong | 2:824ed4ae8d52 | 2671 | Screen_Num = 27; |
asong | 2:824ed4ae8d52 | 2672 | } else { |
asong | 2:824ed4ae8d52 | 2673 | Age = 1; |
asong | 2:824ed4ae8d52 | 2674 | } |
asong | 2:824ed4ae8d52 | 2675 | } |
asong | 2:824ed4ae8d52 | 2676 | |
asong | 2:824ed4ae8d52 | 2677 | /***************************************************************************** |
asong | 2:824ed4ae8d52 | 2678 | Name: Decrement_Age |
asong | 2:824ed4ae8d52 | 2679 | Purpose: Decrement the user's age by 1 |
asong | 2:824ed4ae8d52 | 2680 | Inputs: None |
asong | 2:824ed4ae8d52 | 2681 | Returns: None |
asong | 2:824ed4ae8d52 | 2682 | ******************************************************************************/ |
asong | 2:824ed4ae8d52 | 2683 | void Decrement_Age() |
asong | 2:824ed4ae8d52 | 2684 | { |
asong | 2:824ed4ae8d52 | 2685 | StartHaptic(); |
asong | 2:824ed4ae8d52 | 2686 | if(Age == 1) { |
asong | 2:824ed4ae8d52 | 2687 | Age = 100; |
asong | 2:824ed4ae8d52 | 2688 | } else { |
asong | 2:824ed4ae8d52 | 2689 | Age -= 1; |
asong | 2:824ed4ae8d52 | 2690 | Screen_Num = 27; |
asong | 2:824ed4ae8d52 | 2691 | } |
asong | 2:824ed4ae8d52 | 2692 | } |
asong | 2:824ed4ae8d52 | 2693 | |
asong | 2:824ed4ae8d52 | 2694 | /***************************************************************************** |
asong | 2:824ed4ae8d52 | 2695 | Name: Set_Max_Bpm |
asong | 2:824ed4ae8d52 | 2696 | Purpose: Calculates the user's maximum heart rate based on their age |
asong | 2:824ed4ae8d52 | 2697 | Inputs: None |
asong | 2:824ed4ae8d52 | 2698 | Returns: None |
asong | 2:824ed4ae8d52 | 2699 | ******************************************************************************/ |
asong | 2:824ed4ae8d52 | 2700 | void Set_Max_Bpm() |
asong | 2:824ed4ae8d52 | 2701 | { |
asong | 2:824ed4ae8d52 | 2702 | Max_Bpm = 220 - Age; |
asong | 2:824ed4ae8d52 | 2703 | } |
asong | 2:824ed4ae8d52 | 2704 | |
asong | 2:824ed4ae8d52 | 2705 | /***************************************************************************** |
asong | 2:824ed4ae8d52 | 2706 | Name: Set_Zone_Boundaries |
asong | 2:824ed4ae8d52 | 2707 | Purpose: Calculates the user's heart rate zones' boundaries based on the user's |
asong | 2:824ed4ae8d52 | 2708 | maximum heart rate |
asong | 2:824ed4ae8d52 | 2709 | Inputs: None |
asong | 2:824ed4ae8d52 | 2710 | Returns: None |
asong | 2:824ed4ae8d52 | 2711 | ******************************************************************************/ |
asong | 2:824ed4ae8d52 | 2712 | void Set_Zone_Boundaries() |
asong | 2:824ed4ae8d52 | 2713 | { |
asong | 2:824ed4ae8d52 | 2714 | Set_Max_Bpm(); |
asong | 2:824ed4ae8d52 | 2715 | HR_Zone1[0] = Max_Bpm * .50; //Set Heart Rate Zone 1 |
asong | 2:824ed4ae8d52 | 2716 | HR_Zone1[1] = Max_Bpm * .60; //Set Heart Rate Zone 1 |
asong | 2:824ed4ae8d52 | 2717 | HR_Zone2[0] = HR_Zone1[1] + 1; //Set Heart Rate Zone 2 |
asong | 2:824ed4ae8d52 | 2718 | HR_Zone2[1] = Max_Bpm * .70; //Set Heart Rate Zone 2 |
asong | 2:824ed4ae8d52 | 2719 | HR_Zone3[0] = HR_Zone2[1] + 1; //Set Heart Rate Zone 3 |
asong | 2:824ed4ae8d52 | 2720 | HR_Zone3[1] = Max_Bpm * .80; //Set Heart Rate Zone 3 |
asong | 2:824ed4ae8d52 | 2721 | HR_Zone4[0] = HR_Zone3[1] + 1; //Set Heart Rate Zone 4 |
asong | 2:824ed4ae8d52 | 2722 | HR_Zone4[1] = Max_Bpm; //Set Heart Rate Zone 4 |
asong | 2:824ed4ae8d52 | 2723 | } |
asong | 2:824ed4ae8d52 | 2724 | |
asong | 2:824ed4ae8d52 | 2725 | /***************************************************************************** |
asong | 2:824ed4ae8d52 | 2726 | Name: Increment_Target_Zone |
asong | 2:824ed4ae8d52 | 2727 | Purpose: Imcrements the user's target heart rate zone preference by 1 |
asong | 2:824ed4ae8d52 | 2728 | Inputs: None |
asong | 2:824ed4ae8d52 | 2729 | Returns: None |
asong | 2:824ed4ae8d52 | 2730 | ******************************************************************************/ |
asong | 2:824ed4ae8d52 | 2731 | void Increment_Target_Zone() |
asong | 2:824ed4ae8d52 | 2732 | { |
asong | 2:824ed4ae8d52 | 2733 | StartHaptic(); |
asong | 2:824ed4ae8d52 | 2734 | if(Target_Zone == 4) { |
asong | 2:824ed4ae8d52 | 2735 | Target_Zone = 1; |
asong | 2:824ed4ae8d52 | 2736 | } else { |
asong | 2:824ed4ae8d52 | 2737 | Target_Zone += 1; |
asong | 2:824ed4ae8d52 | 2738 | } |
asong | 2:824ed4ae8d52 | 2739 | } |
asong | 2:824ed4ae8d52 | 2740 | |
asong | 2:824ed4ae8d52 | 2741 | /***************************************************************************** |
asong | 2:824ed4ae8d52 | 2742 | Name: Decrement_Target_Zone |
asong | 2:824ed4ae8d52 | 2743 | Purpose: Decrements the user's target heart rate zone preference by 1 |
asong | 2:824ed4ae8d52 | 2744 | Inputs: None |
asong | 2:824ed4ae8d52 | 2745 | Returns: None |
asong | 2:824ed4ae8d52 | 2746 | ******************************************************************************/ |
asong | 2:824ed4ae8d52 | 2747 | void Decrement_Target_Zone() |
asong | 2:824ed4ae8d52 | 2748 | { |
asong | 2:824ed4ae8d52 | 2749 | StartHaptic(); |
asong | 2:824ed4ae8d52 | 2750 | if(Target_Zone == 1) { |
asong | 2:824ed4ae8d52 | 2751 | Target_Zone = 4; |
asong | 2:824ed4ae8d52 | 2752 | } else { |
asong | 2:824ed4ae8d52 | 2753 | Target_Zone -= 1; |
asong | 2:824ed4ae8d52 | 2754 | } |
asong | 2:824ed4ae8d52 | 2755 | } |
asong | 2:824ed4ae8d52 | 2756 | |
asong | 2:824ed4ae8d52 | 2757 | /***************************************************************************** |
asong | 2:824ed4ae8d52 | 2758 | Name: Increment_HR_Vibr_Pref |
asong | 2:824ed4ae8d52 | 2759 | Purpose: Increment the user's heart rate vibration preference by 1 |
asong | 2:824ed4ae8d52 | 2760 | Inputs: None |
asong | 2:824ed4ae8d52 | 2761 | Returns: None |
asong | 2:824ed4ae8d52 | 2762 | ******************************************************************************/ |
asong | 2:824ed4ae8d52 | 2763 | void Increment_HR_Vibr_Pref() |
asong | 2:824ed4ae8d52 | 2764 | { |
asong | 2:824ed4ae8d52 | 2765 | StartHaptic(); |
asong | 2:824ed4ae8d52 | 2766 | if(HR_Vibration == 3) { |
asong | 2:824ed4ae8d52 | 2767 | HR_Vibration = 1; |
asong | 2:824ed4ae8d52 | 2768 | } else { |
asong | 2:824ed4ae8d52 | 2769 | HR_Vibration += 1; |
asong | 2:824ed4ae8d52 | 2770 | } |
asong | 2:824ed4ae8d52 | 2771 | } |
asong | 2:824ed4ae8d52 | 2772 | |
asong | 2:824ed4ae8d52 | 2773 | /***************************************************************************** |
asong | 2:824ed4ae8d52 | 2774 | Name: Decrement_HR_Vibr_Pref |
asong | 2:824ed4ae8d52 | 2775 | Purpose: Decrement the user's heart rate vibration preference by 1 |
asong | 2:824ed4ae8d52 | 2776 | Inputs: None |
asong | 2:824ed4ae8d52 | 2777 | Returns: None |
asong | 2:824ed4ae8d52 | 2778 | ******************************************************************************/ |
asong | 2:824ed4ae8d52 | 2779 | void Decrement_HR_Vibr_Pref() |
asong | 2:824ed4ae8d52 | 2780 | { |
asong | 2:824ed4ae8d52 | 2781 | StartHaptic(); |
asong | 2:824ed4ae8d52 | 2782 | if(HR_Vibration == 1) { |
asong | 2:824ed4ae8d52 | 2783 | HR_Vibration = 3; |
asong | 2:824ed4ae8d52 | 2784 | } else { |
asong | 2:824ed4ae8d52 | 2785 | HR_Vibration -= 1; |
asong | 2:824ed4ae8d52 | 2786 | } |
asong | 2:824ed4ae8d52 | 2787 | } |
asong | 2:824ed4ae8d52 | 2788 | |
asong | 2:824ed4ae8d52 | 2789 | /***************************************************************************** |
asong | 2:824ed4ae8d52 | 2790 | Name: Enable_Heart_Rate |
asong | 2:824ed4ae8d52 | 2791 | Purpose: Turn on the HexiHeart heart rate function |
asong | 2:824ed4ae8d52 | 2792 | Inputs: None |
asong | 2:824ed4ae8d52 | 2793 | Returns: None |
asong | 2:824ed4ae8d52 | 2794 | ******************************************************************************/ |
asong | 2:824ed4ae8d52 | 2795 | void Enable_Heart_Rate() |
asong | 2:824ed4ae8d52 | 2796 | { |
asong | 2:824ed4ae8d52 | 2797 | Heart_Rate_Mode = true; |
asong | 2:824ed4ae8d52 | 2798 | } |
asong | 2:824ed4ae8d52 | 2799 | |
asong | 2:824ed4ae8d52 | 2800 | /***************************************************************************** |
asong | 2:824ed4ae8d52 | 2801 | Name: Disable_Heart_Rate |
asong | 2:824ed4ae8d52 | 2802 | Purpose: Turn off the HexiHeart heart rate function |
asong | 2:824ed4ae8d52 | 2803 | Inputs: None |
asong | 2:824ed4ae8d52 | 2804 | Returns: None |
asong | 2:824ed4ae8d52 | 2805 | ******************************************************************************/ |
asong | 2:824ed4ae8d52 | 2806 | void Disable_Heart_Rate() |
asong | 2:824ed4ae8d52 | 2807 | { |
asong | 15:330794a9f347 | 2808 | Heart_Rate_Mode = false; |
asong | 2:824ed4ae8d52 | 2809 | } |
asong | 2:824ed4ae8d52 | 2810 | |
asong | 2:824ed4ae8d52 | 2811 | /***************************************************************************** |
asong | 2:824ed4ae8d52 | 2812 | Name: Determine_Current_Zone |
asong | 2:824ed4ae8d52 | 2813 | Purpose: Determines which zone the heart rate is in and assigns the curent |
asong | 2:824ed4ae8d52 | 2814 | zone and previous zone |
asong | 2:824ed4ae8d52 | 2815 | Inputs: None |
asong | 2:824ed4ae8d52 | 2816 | Returns: None |
asong | 2:824ed4ae8d52 | 2817 | ******************************************************************************/ |
asong | 2:824ed4ae8d52 | 2818 | void Determine_Current_Zone() |
asong | 2:824ed4ae8d52 | 2819 | { |
asong | 2:824ed4ae8d52 | 2820 | Prev_Zone = Current_Zone; |
asong | 2:824ed4ae8d52 | 2821 | |
asong | 2:824ed4ae8d52 | 2822 | if(Heart_Rate >= HR_Zone1[0] && Heart_Rate <= HR_Zone1[1]) { |
asong | 2:824ed4ae8d52 | 2823 | Current_Zone = 1; |
asong | 2:824ed4ae8d52 | 2824 | } else if(Heart_Rate >= HR_Zone2[0] && Heart_Rate <= HR_Zone2[1]) { |
asong | 2:824ed4ae8d52 | 2825 | Current_Zone = 2; |
asong | 2:824ed4ae8d52 | 2826 | } else if(Heart_Rate >= HR_Zone3[0] && Heart_Rate <= HR_Zone3[1]) { |
asong | 2:824ed4ae8d52 | 2827 | Current_Zone = 3; |
asong | 2:824ed4ae8d52 | 2828 | } else if(Heart_Rate >= HR_Zone4[0] && Heart_Rate <= HR_Zone4[1]) { |
asong | 2:824ed4ae8d52 | 2829 | Current_Zone = 4; |
asong | 2:824ed4ae8d52 | 2830 | } else { |
asong | 2:824ed4ae8d52 | 2831 | //error reading, don't change anything |
asong | 2:824ed4ae8d52 | 2832 | } |
asong | 15:330794a9f347 | 2833 | Heart_Rate_Vibrations(); |
asong | 2:824ed4ae8d52 | 2834 | |
asong | 2:824ed4ae8d52 | 2835 | |
asong | 2:824ed4ae8d52 | 2836 | } |
asong | 2:824ed4ae8d52 | 2837 | /***************************************************************************** |
asong | 2:824ed4ae8d52 | 2838 | Name: Run_Heart_Vibrations |
asong | 2:824ed4ae8d52 | 2839 | Purpose: Performs the HexiHeart heart rate function |
asong | 2:824ed4ae8d52 | 2840 | Inputs: None |
asong | 2:824ed4ae8d52 | 2841 | Returns: None |
asong | 2:824ed4ae8d52 | 2842 | ******************************************************************************/ |
asong | 2:824ed4ae8d52 | 2843 | void Heart_Rate_Vibrations() |
asong | 2:824ed4ae8d52 | 2844 | { |
asong | 15:330794a9f347 | 2845 | |
asong | 2:824ed4ae8d52 | 2846 | if(HR_Vibration == 1) { |
asong | 2:824ed4ae8d52 | 2847 | //All Pre-loaded vibrations enabled |
asong | 2:824ed4ae8d52 | 2848 | if(Current_Zone == Prev_Zone) { |
asong | 2:824ed4ae8d52 | 2849 | // Do nothing if no zone change |
asong | 2:824ed4ae8d52 | 2850 | } else if(Current_Zone == Target_Zone) { //Changed to target zone |
asong | 2:824ed4ae8d52 | 2851 | if(Target_Zone == LOWEST_ZONE || Prev_Zone > Target_Zone) { //must have entered from above |
asong | 20:990951205fbd | 2852 | CLRWDT(); |
asong | 15:330794a9f347 | 2853 | haptic = 1; |
asong | 15:330794a9f347 | 2854 | wait(0.5); |
asong | 15:330794a9f347 | 2855 | haptic = 0; |
asong | 15:330794a9f347 | 2856 | wait(0.5); |
asong | 20:990951205fbd | 2857 | CLRWDT(); |
asong | 15:330794a9f347 | 2858 | haptic = 1; |
asong | 15:330794a9f347 | 2859 | wait(0.5); |
asong | 15:330794a9f347 | 2860 | haptic = 0; |
asong | 2:824ed4ae8d52 | 2861 | } else if(Target_Zone == HIGHEST_ZONE || Prev_Zone < Target_Zone) { //must have entered from below |
asong | 20:990951205fbd | 2862 | CLRWDT(); |
asong | 15:330794a9f347 | 2863 | haptic = 1; |
asong | 15:330794a9f347 | 2864 | wait(0.5); |
asong | 15:330794a9f347 | 2865 | haptic = 0; |
asong | 2:824ed4ae8d52 | 2866 | } |
asong | 2:824ed4ae8d52 | 2867 | } else if(Current_Zone != Target_Zone && Prev_Zone == Target_Zone) { |
asong | 2:824ed4ae8d52 | 2868 | if(Target_Zone == HIGHEST_ZONE || Current_Zone < Target_Zone) { //must have exited below |
asong | 20:990951205fbd | 2869 | CLRWDT(); |
asong | 15:330794a9f347 | 2870 | haptic = 1; |
asong | 15:330794a9f347 | 2871 | wait(1); |
asong | 15:330794a9f347 | 2872 | haptic = 0; |
asong | 2:824ed4ae8d52 | 2873 | } else if(Target_Zone == LOWEST_ZONE || Current_Zone > Target_Zone) { //must have exited above |
asong | 15:330794a9f347 | 2874 | haptic = 1; |
asong | 20:990951205fbd | 2875 | CLRWDT(); |
asong | 15:330794a9f347 | 2876 | wait(1); |
asong | 15:330794a9f347 | 2877 | haptic = 0; |
asong | 15:330794a9f347 | 2878 | wait(1); |
asong | 20:990951205fbd | 2879 | CLRWDT(); |
asong | 15:330794a9f347 | 2880 | haptic = 1; |
asong | 15:330794a9f347 | 2881 | wait(1); |
asong | 15:330794a9f347 | 2882 | haptic = 0; |
asong | 2:824ed4ae8d52 | 2883 | } |
asong | 2:824ed4ae8d52 | 2884 | } |
asong | 2:824ed4ae8d52 | 2885 | } else if(HR_Vibration == 2) { |
asong | 2:824ed4ae8d52 | 2886 | //Only Entering and Exiting target zone |
asong | 2:824ed4ae8d52 | 2887 | if(Current_Zone == Prev_Zone) { |
asong | 2:824ed4ae8d52 | 2888 | //do nothing |
asong | 2:824ed4ae8d52 | 2889 | } else if(Current_Zone == Target_Zone) { |
asong | 20:990951205fbd | 2890 | CLRWDT(); |
asong | 15:330794a9f347 | 2891 | haptic = 1; |
asong | 15:330794a9f347 | 2892 | wait(0.2); |
asong | 15:330794a9f347 | 2893 | haptic = 0; |
asong | 15:330794a9f347 | 2894 | wait(0.2); |
asong | 20:990951205fbd | 2895 | CLRWDT(); |
asong | 15:330794a9f347 | 2896 | haptic = 1; |
asong | 15:330794a9f347 | 2897 | wait(0.2); |
asong | 15:330794a9f347 | 2898 | haptic = 0; |
asong | 2:824ed4ae8d52 | 2899 | } else if(Current_Zone != Target_Zone && Prev_Zone == Target_Zone) { |
asong | 15:330794a9f347 | 2900 | haptic = 1; |
asong | 20:990951205fbd | 2901 | CLRWDT(); |
asong | 15:330794a9f347 | 2902 | wait(1); |
asong | 15:330794a9f347 | 2903 | haptic = 0; |
asong | 2:824ed4ae8d52 | 2904 | } |
asong | 2:824ed4ae8d52 | 2905 | |
asong | 2:824ed4ae8d52 | 2906 | } else if(HR_Vibration == 3) { |
asong | 2:824ed4ae8d52 | 2907 | //No Vibrations |
asong | 2:824ed4ae8d52 | 2908 | |
asong | 2:824ed4ae8d52 | 2909 | } else { |
asong | 2:824ed4ae8d52 | 2910 | //Error, can only be choices 1-3 |
asong | 2:824ed4ae8d52 | 2911 | error_screen(); |
asong | 2:824ed4ae8d52 | 2912 | } |
asong | 15:330794a9f347 | 2913 | |
asong | 2:824ed4ae8d52 | 2914 | } |
asong | 2:824ed4ae8d52 | 2915 | |
asong | 2:824ed4ae8d52 | 2916 | /***************************************************************************** |
asong | 2:824ed4ae8d52 | 2917 | Name: Increment_Heart_Rate |
asong | 2:824ed4ae8d52 | 2918 | Purpose: Manually increment the the heart rate measurement by 1 for testing |
asong | 2:824ed4ae8d52 | 2919 | purposes |
asong | 2:824ed4ae8d52 | 2920 | Inputs: None |
asong | 2:824ed4ae8d52 | 2921 | Returns: None |
asong | 2:824ed4ae8d52 | 2922 | ******************************************************************************/ |
asong | 2:824ed4ae8d52 | 2923 | void Increment_Heart_Rate() |
asong | 2:824ed4ae8d52 | 2924 | { |
asong | 2:824ed4ae8d52 | 2925 | //StartHaptic(); |
asong | 2:824ed4ae8d52 | 2926 | if(Heart_Rate == HR_Zone4[1]) { |
asong | 2:824ed4ae8d52 | 2927 | Heart_Rate = HR_Zone1[0]; |
asong | 2:824ed4ae8d52 | 2928 | } else { |
asong | 2:824ed4ae8d52 | 2929 | Heart_Rate += 1; |
asong | 2:824ed4ae8d52 | 2930 | } |
asong | 15:330794a9f347 | 2931 | Determine_Current_Zone(); |
asong | 2:824ed4ae8d52 | 2932 | } |
asong | 2:824ed4ae8d52 | 2933 | |
asong | 2:824ed4ae8d52 | 2934 | /***************************************************************************** |
asong | 2:824ed4ae8d52 | 2935 | Name: Decrement_Heart_Rate |
asong | 2:824ed4ae8d52 | 2936 | Purpose: Manually decrement the the heart rate measurement by 1 for testing |
asong | 2:824ed4ae8d52 | 2937 | purposes |
asong | 2:824ed4ae8d52 | 2938 | Inputs: None |
asong | 2:824ed4ae8d52 | 2939 | Returns: None |
asong | 2:824ed4ae8d52 | 2940 | ******************************************************************************/ |
asong | 2:824ed4ae8d52 | 2941 | void Decrement_Heart_Rate() |
asong | 2:824ed4ae8d52 | 2942 | { |
asong | 2:824ed4ae8d52 | 2943 | //StartHaptic(); |
asong | 2:824ed4ae8d52 | 2944 | if(Heart_Rate == HR_Zone1[0]) { |
asong | 2:824ed4ae8d52 | 2945 | Heart_Rate = HR_Zone4[1]; |
asong | 2:824ed4ae8d52 | 2946 | } else { |
asong | 2:824ed4ae8d52 | 2947 | Heart_Rate -= 1; |
asong | 2:824ed4ae8d52 | 2948 | } |
asong | 15:330794a9f347 | 2949 | Determine_Current_Zone(); |
asong | 15:330794a9f347 | 2950 | } |
asong | 2:824ed4ae8d52 | 2951 | |
nbaker | 16:537ef0c72084 | 2952 | /***************************************************************************** |
nbaker | 16:537ef0c72084 | 2953 | Name: Led_Zone_Indicator() |
nbaker | 16:537ef0c72084 | 2954 | Purpose: Ticker interupt routine called every 1.0 Seconds in order to Blink LED to indicate current Heart Rate zone |
nbaker | 16:537ef0c72084 | 2955 | Inputs: hr_led Ticker |
nbaker | 16:537ef0c72084 | 2956 | ******************************************************************************/ |
asong | 2:824ed4ae8d52 | 2957 | void Led_Zone_Indicator() |
asong | 2:824ed4ae8d52 | 2958 | { |
nbaker | 16:537ef0c72084 | 2959 | CLRWDT();// Reset watchdog timer before we do this long opperation |
asong | 2:824ed4ae8d52 | 2960 | if(Led_Zones == true) |
asong | 2:824ed4ae8d52 | 2961 | { |
asong | 2:824ed4ae8d52 | 2962 | if(Current_Zone == 1) |
asong | 2:824ed4ae8d52 | 2963 | { |
asong | 2:824ed4ae8d52 | 2964 | BLU_Led = LED_OFF; |
asong | 2:824ed4ae8d52 | 2965 | RED_Led = LED_ON; |
asong | 2:824ed4ae8d52 | 2966 | GRN_Led = LED_ON; |
nbaker | 16:537ef0c72084 | 2967 | hr_led.attach(&Led_Zone_Indicator_off, HR_LED_on_time); // in 0.5 seconds turn off LED |
nbaker | 16:537ef0c72084 | 2968 | //wait(0.5); |
nbaker | 16:537ef0c72084 | 2969 | //RED_Led = LED_OFF; |
nbaker | 16:537ef0c72084 | 2970 | // GRN_Led = LED_OFF; |
asong | 2:824ed4ae8d52 | 2971 | } |
asong | 2:824ed4ae8d52 | 2972 | else if(Current_Zone == 2) |
asong | 2:824ed4ae8d52 | 2973 | { |
asong | 2:824ed4ae8d52 | 2974 | if(Prev_Zone == 1) |
asong | 2:824ed4ae8d52 | 2975 | { |
asong | 2:824ed4ae8d52 | 2976 | RED_Led = LED_OFF; |
asong | 2:824ed4ae8d52 | 2977 | GRN_Led = LED_OFF; |
asong | 2:824ed4ae8d52 | 2978 | } |
asong | 2:824ed4ae8d52 | 2979 | else if(Prev_Zone == 3) |
asong | 2:824ed4ae8d52 | 2980 | { |
asong | 2:824ed4ae8d52 | 2981 | GRN_Led = LED_OFF; |
asong | 2:824ed4ae8d52 | 2982 | } |
asong | 2:824ed4ae8d52 | 2983 | BLU_Led = LED_ON; |
nbaker | 16:537ef0c72084 | 2984 | hr_led.attach(&Led_Zone_Indicator_off, HR_LED_on_time); // in 0.5 seconds turn off LED |
nbaker | 16:537ef0c72084 | 2985 | // wait(0.5); |
nbaker | 16:537ef0c72084 | 2986 | // BLU_Led = LED_OFF; |
asong | 2:824ed4ae8d52 | 2987 | } |
asong | 2:824ed4ae8d52 | 2988 | else if(Current_Zone == 3) |
asong | 2:824ed4ae8d52 | 2989 | { |
asong | 2:824ed4ae8d52 | 2990 | if(Prev_Zone == 2) |
asong | 2:824ed4ae8d52 | 2991 | { |
asong | 2:824ed4ae8d52 | 2992 | BLU_Led = LED_OFF; |
asong | 2:824ed4ae8d52 | 2993 | } |
asong | 2:824ed4ae8d52 | 2994 | else if(Prev_Zone == 4) |
asong | 2:824ed4ae8d52 | 2995 | { |
asong | 2:824ed4ae8d52 | 2996 | RED_Led = LED_OFF; |
asong | 2:824ed4ae8d52 | 2997 | } |
asong | 2:824ed4ae8d52 | 2998 | GRN_Led = LED_ON; |
nbaker | 16:537ef0c72084 | 2999 | hr_led.attach(&Led_Zone_Indicator_off, HR_LED_on_time); // in 0.5 seconds turn off LED |
nbaker | 16:537ef0c72084 | 3000 | // wait(0.5); |
nbaker | 16:537ef0c72084 | 3001 | // GRN_Led = LED_OFF; |
asong | 2:824ed4ae8d52 | 3002 | } |
asong | 2:824ed4ae8d52 | 3003 | else if(Current_Zone == 4) |
asong | 2:824ed4ae8d52 | 3004 | { |
asong | 2:824ed4ae8d52 | 3005 | GRN_Led = LED_OFF; |
asong | 2:824ed4ae8d52 | 3006 | RED_Led = LED_ON; |
nbaker | 16:537ef0c72084 | 3007 | hr_led.attach(&Led_Zone_Indicator_off, HR_LED_on_time); // in 0.5 seconds turn off LED |
nbaker | 16:537ef0c72084 | 3008 | // wait(0.5); |
nbaker | 16:537ef0c72084 | 3009 | // RED_Led = LED_OFF; |
asong | 2:824ed4ae8d52 | 3010 | } |
nbaker | 4:0803151bc5e4 | 3011 | } |
nbaker | 4:0803151bc5e4 | 3012 | }//end of Led_Zone_Indicator |
jmr274 | 5:e1431272be79 | 3013 | |
jmr274 | 5:e1431272be79 | 3014 | /***************************************************************************** |
nbaker | 16:537ef0c72084 | 3015 | Name: Led_Zone_Indicator_off() |
nbaker | 16:537ef0c72084 | 3016 | Purpose: Ticker interupt routine called every 0.5 Seconds after LEDs turned on to turn them back |
nbaker | 16:537ef0c72084 | 3017 | off. This avoids the 0.5 wait every second, freeing up the system. |
nbaker | 16:537ef0c72084 | 3018 | Inputs: hr_led Ticker |
nbaker | 16:537ef0c72084 | 3019 | ******************************************************************************/ |
nbaker | 16:537ef0c72084 | 3020 | //turns off LEDs after 0.5 seconds instead of using a wait command |
nbaker | 16:537ef0c72084 | 3021 | void Led_Zone_Indicator_off(){ |
nbaker | 16:537ef0c72084 | 3022 | RED_Led = LED_OFF; |
nbaker | 16:537ef0c72084 | 3023 | GRN_Led = LED_OFF; |
nbaker | 16:537ef0c72084 | 3024 | BLU_Led = LED_OFF; |
nbaker | 16:537ef0c72084 | 3025 | hr_led.attach(&Led_Zone_Indicator, HR_LED_period); // blink every second |
nbaker | 16:537ef0c72084 | 3026 | }//end void Led_Zone_Indicator_off() |
nbaker | 16:537ef0c72084 | 3027 | |
nbaker | 16:537ef0c72084 | 3028 | /***************************************************************************** |
jmr274 | 5:e1431272be79 | 3029 | Name: Heat_Index_Calculation() |
jmr274 | 5:e1431272be79 | 3030 | Purpose: Calculates the heat index using the temperature and humidity sensors |
jmr274 | 5:e1431272be79 | 3031 | Inputs: None |
jmr274 | 5:e1431272be79 | 3032 | Returns: None |
jmr274 | 5:e1431272be79 | 3033 | ******************************************************************************/ |
jmr274 | 5:e1431272be79 | 3034 | void Heat_Index_Calculation(){ |
nbaker | 19:87ab6daf98e5 | 3035 | //sample_ftemp = temphumid.sample_ftemp(); // sampling is now done in rolling UpDate_Ave() function |
jmr274 | 5:e1431272be79 | 3036 | |
nbaker | 19:87ab6daf98e5 | 3037 | //sample_humid = temphumid.sample_humid(); // sampling is now done in rolling UpDate_Ave() function |
jmr274 | 5:e1431272be79 | 3038 | |
nbaker | 9:d2e39ee9fedd | 3039 | hi_calc = -42.379 + |
jmr274 | 5:e1431272be79 | 3040 | 2.04901523 * sample_ftemp + |
jmr274 | 5:e1431272be79 | 3041 | 10.14333127 * sample_humid - |
jmr274 | 5:e1431272be79 | 3042 | 0.22475541 * sample_ftemp * sample_humid - |
jmr274 | 5:e1431272be79 | 3043 | 0.00683783 * sample_ftemp * sample_ftemp - |
jmr274 | 5:e1431272be79 | 3044 | 0.05481717 * sample_humid * sample_humid + |
jmr274 | 5:e1431272be79 | 3045 | 0.00122874 * sample_ftemp * sample_ftemp * sample_humid + |
jmr274 | 5:e1431272be79 | 3046 | 0.00085282 * sample_ftemp * sample_humid * sample_humid - |
jmr274 | 5:e1431272be79 | 3047 | 0.00000199 * sample_ftemp * sample_ftemp * sample_humid * sample_humid; |
nbaker | 9:d2e39ee9fedd | 3048 | |
nbaker | 9:d2e39ee9fedd | 3049 | if (sample_humid < 13 && sample_ftemp > 80 && sample_ftemp < 112){ |
nbaker | 9:d2e39ee9fedd | 3050 | adjustment = ((13 - sample_humid) / 4) * sqrt((17-abs(sample_ftemp-95.0))/17); |
nbaker | 9:d2e39ee9fedd | 3051 | heat_index = hi_calc - adjustment; |
nbaker | 9:d2e39ee9fedd | 3052 | } |
nbaker | 9:d2e39ee9fedd | 3053 | |
nbaker | 9:d2e39ee9fedd | 3054 | else if (sample_humid > 85 && sample_ftemp > 80 && sample_ftemp < 87){ |
nbaker | 9:d2e39ee9fedd | 3055 | adjustment = ((sample_humid - 85) / 10) * ((87 - sample_ftemp)/5); |
nbaker | 9:d2e39ee9fedd | 3056 | heat_index = hi_calc + adjustment; |
nbaker | 9:d2e39ee9fedd | 3057 | } |
nbaker | 9:d2e39ee9fedd | 3058 | |
nbaker | 9:d2e39ee9fedd | 3059 | else if (hi_calc < 80){ |
nbaker | 9:d2e39ee9fedd | 3060 | heat_index = 0.5 * (sample_ftemp + 61.0 + ((sample_ftemp - 68.0) * 1.2) + (sample_humid * 0.094)); |
nbaker | 9:d2e39ee9fedd | 3061 | } |
nbaker | 9:d2e39ee9fedd | 3062 | |
nbaker | 9:d2e39ee9fedd | 3063 | else {heat_index = hi_calc;} |
jmr274 | 5:e1431272be79 | 3064 | } |
jmr274 | 5:e1431272be79 | 3065 | |
nbaker | 4:0803151bc5e4 | 3066 | /***************************************************************************** |
nbaker | 10:eaea844e763c | 3067 | Name: fall_detect_debug() |
nbaker | 10:eaea844e763c | 3068 | Purpose: Debug Interupt routine called when accelerometer IC has detected a |
nbaker | 10:eaea844e763c | 3069 | free-fall (accel <= 0.5g) |
nbaker | 10:eaea844e763c | 3070 | Inputs: interupt1 of accel sensor |
nbaker | 4:0803151bc5e4 | 3071 | ******************************************************************************/ |
nbaker | 10:eaea844e763c | 3072 | void fall_detect_debug(){// fall detect interupt routine |
nbaker | 4:0803151bc5e4 | 3073 | if(Fall_Alert == 1){ |
nbaker | 7:3d5a8aea0b63 | 3074 | accel.acquire_accel_data_g(Accel_Data_Event); |
nbaker | 4:0803151bc5e4 | 3075 | // for now just turn on display and give haptic feedback |
nbaker | 4:0803151bc5e4 | 3076 | Screen_Timer.attach(&timout_timer,(SCRN_TIME));// Reset/restart ticker timer for OLED |
nbaker | 13:37cd579208e9 | 3077 | oled.DimScreenOFF(); |
nbaker | 4:0803151bc5e4 | 3078 | if (OLED_ON == 0) { |
nbaker | 4:0803151bc5e4 | 3079 | OLED_ON = 1; // Scree was off, set to On |
nbaker | 9:d2e39ee9fedd | 3080 | update_display(); |
nbaker | 9:d2e39ee9fedd | 3081 | } // endif |
nbaker | 9:d2e39ee9fedd | 3082 | if (Screen_Num != 21){ |
nbaker | 9:d2e39ee9fedd | 3083 | Screen_Num = 21; //Change to screen 21 (Fall diag screen) |
nbaker | 9:d2e39ee9fedd | 3084 | update_display(); |
nbaker | 9:d2e39ee9fedd | 3085 | } // endif |
nbaker | 4:0803151bc5e4 | 3086 | |
nbaker | 4:0803151bc5e4 | 3087 | //__disable_irq(); // Disable all Interrupts |
nbaker | 4:0803151bc5e4 | 3088 | // oled.Label((uint8_t *)" Fall Detected ",05,70); // Display at x,y |
nbaker | 9:d2e39ee9fedd | 3089 | |
nbaker | 9:d2e39ee9fedd | 3090 | 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 | 3091 | sprintf(text_1,"Free-Fall:%2.2fg",Accel_Mag); |
nbaker | 9:d2e39ee9fedd | 3092 | oled.Label((uint8_t *)text_1,2,5);// text_1 at x,y |
nbaker | 7:3d5a8aea0b63 | 3093 | |
nbaker | 4:0803151bc5e4 | 3094 | BLU_Led = LED_ON; // LEDs default to on, need to turn off |
nbaker | 10:eaea844e763c | 3095 | Led_clk1 = 1; // Turn on LED1, on docking station |
nbaker | 10:eaea844e763c | 3096 | StartHaptic(); |
nbaker | 10:eaea844e763c | 3097 | // haptic = 1; |
nbaker | 10:eaea844e763c | 3098 | Accel_INT1.rise(&fall_det_end_debug); // reset accel sensor's int#1 to active high and proper int routine |
nbaker | 4:0803151bc5e4 | 3099 | //__enable_irq(); // Enable all Interrupts |
nbaker | 4:0803151bc5e4 | 3100 | }// end if |
nbaker | 10:eaea844e763c | 3101 | }//end fall_detect_debug interupt routine |
nbaker | 4:0803151bc5e4 | 3102 | |
nbaker | 10:eaea844e763c | 3103 | /***************************************************************************** |
nbaker | 10:eaea844e763c | 3104 | Name: fall_det_end_debug() |
nbaker | 10:eaea844e763c | 3105 | Purpose: Debug interupt routine called when accelerometer IC has detected that the |
nbaker | 10:eaea844e763c | 3106 | free-fall acceleration has ended (accel now >0.5g) |
nbaker | 10:eaea844e763c | 3107 | Inputs: interupt1 of accel sensor |
nbaker | 10:eaea844e763c | 3108 | ******************************************************************************/ |
nbaker | 10:eaea844e763c | 3109 | void fall_det_end_debug(){ |
nbaker | 4:0803151bc5e4 | 3110 | haptic = 0; // Turn off Haptic |
nbaker | 4:0803151bc5e4 | 3111 | BLU_Led = LED_OFF; // Turn off HexiHeart Blue LED |
nbaker | 10:eaea844e763c | 3112 | Led_clk1 = 0; // Turn off LED1, on docking station |
nbaker | 9:d2e39ee9fedd | 3113 | fall_config(21); // reads interrupts to clear old interupt |
nbaker | 8:a5c77b45008d | 3114 | // oled.Label((uint8_t *)" ",05,70); // clear display at x,y |
nbaker | 10:eaea844e763c | 3115 | Accel_INT1.fall(&fall_detect_debug); // reset accel sensor's int#1 to active low and proper int routine |
nbaker | 10:eaea844e763c | 3116 | } //end fall_det_end_debug interupt routine |
nbaker | 4:0803151bc5e4 | 3117 | |
nbaker | 4:0803151bc5e4 | 3118 | /***************************************************************************** |
nbaker | 10:eaea844e763c | 3119 | Name: impact_detect_debug() |
nbaker | 10:eaea844e763c | 3120 | Purpose: Debug Interupt routine called when accelerometer IC has detected a vector |
nbaker | 4:0803151bc5e4 | 3121 | magnitude acceleration >= 3.0g |
nbaker | 10:eaea844e763c | 3122 | Inputs: interupt2 of accel sensor |
nbaker | 4:0803151bc5e4 | 3123 | ******************************************************************************/ |
nbaker | 10:eaea844e763c | 3124 | void impact_detect_debug(){ |
nbaker | 7:3d5a8aea0b63 | 3125 | if(Fall_Alert == 1){ |
nbaker | 7:3d5a8aea0b63 | 3126 | accel.acquire_accel_data_g(Accel_Data_Event); |
nbaker | 9:d2e39ee9fedd | 3127 | haptic = 1; |
nbaker | 10:eaea844e763c | 3128 | Led_clk2 = 1; // Turn LED2 on docking station on |
nbaker | 9:d2e39ee9fedd | 3129 | |
nbaker | 7:3d5a8aea0b63 | 3130 | Screen_Timer.attach(&timout_timer,(SCRN_TIME));// Reset/restart ticker timer for OLED |
nbaker | 13:37cd579208e9 | 3131 | oled.DimScreenOFF(); |
nbaker | 7:3d5a8aea0b63 | 3132 | if (OLED_ON == 0) { |
nbaker | 9:d2e39ee9fedd | 3133 | OLED_ON = 1; // Screen was off, set to On |
nbaker | 9:d2e39ee9fedd | 3134 | update_display(); |
nbaker | 9:d2e39ee9fedd | 3135 | } // endif |
nbaker | 9:d2e39ee9fedd | 3136 | |
nbaker | 9:d2e39ee9fedd | 3137 | if (Screen_Num != 21){ |
nbaker | 9:d2e39ee9fedd | 3138 | Screen_Num = 21; //Change to screen 21 (Fall diag screen) |
nbaker | 9:d2e39ee9fedd | 3139 | update_display(); |
nbaker | 9:d2e39ee9fedd | 3140 | } // endif |
nbaker | 9:d2e39ee9fedd | 3141 | accel.acquire_accel_data_g(Accel_Data); |
nbaker | 9:d2e39ee9fedd | 3142 | 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 | 3143 | sprintf(text_1,"Impact:%2.2fg",Accel_Mag); |
nbaker | 9:d2e39ee9fedd | 3144 | oled.Label((uint8_t *)text_1,3,20);// text_1 at x,y |
nbaker | 9:d2e39ee9fedd | 3145 | wait(0.1); |
nbaker | 10:eaea844e763c | 3146 | Led_clk2 = 0; // Turn LED2 off docking station on |
nbaker | 9:d2e39ee9fedd | 3147 | haptic = 0; |
nbaker | 7:3d5a8aea0b63 | 3148 | }// end if |
nbaker | 10:eaea844e763c | 3149 | }//end impact_detect_debug interupt routine |
nbaker | 4:0803151bc5e4 | 3150 | |
nbaker | 4:0803151bc5e4 | 3151 | /***************************************************************************** |
nbaker | 10:eaea844e763c | 3152 | Name: motion_detect_debug() |
nbaker | 10:eaea844e763c | 3153 | Purpose: Debug Interupt routine called when gyro IC has detected motion >= 50 deg/sec |
nbaker | 9:d2e39ee9fedd | 3154 | in order to see if fall-impact resulted in motion-less person. |
nbaker | 10:eaea844e763c | 3155 | Inputs: interupt1 of gyro sensor |
nbaker | 9:d2e39ee9fedd | 3156 | ******************************************************************************/ |
nbaker | 10:eaea844e763c | 3157 | void motion_detect_debug(){ |
nbaker | 9:d2e39ee9fedd | 3158 | float Gyro_Data_Event[3]; // store right away to see what it was |
nbaker | 9:d2e39ee9fedd | 3159 | if(Fall_Alert == 1 && Fall_Alert_Mode > 2){// only service interupt if automatic fall detect is selected by user |
nbaker | 9:d2e39ee9fedd | 3160 | gyro.acquire_gyro_data_dps(Gyro_Data_Event); |
nbaker | 9:d2e39ee9fedd | 3161 | Gyro_Mag = (abs(Gyro_Data_Event[0])+abs(Gyro_Data_Event[1])+abs(Gyro_Data_Event[2])); |
nbaker | 9:d2e39ee9fedd | 3162 | haptic = 1; |
nbaker | 10:eaea844e763c | 3163 | Led_clk3 = 1; // Turn on LED3, on docking station |
nbaker | 9:d2e39ee9fedd | 3164 | |
nbaker | 9:d2e39ee9fedd | 3165 | Screen_Timer.attach(&timout_timer,(SCRN_TIME));// Reset/restart ticker timer for OLED |
nbaker | 13:37cd579208e9 | 3166 | oled.DimScreenOFF(); |
nbaker | 9:d2e39ee9fedd | 3167 | if (OLED_ON == 0) { |
nbaker | 9:d2e39ee9fedd | 3168 | OLED_ON = 1; // Screen was off, set to On |
nbaker | 9:d2e39ee9fedd | 3169 | update_display(); |
nbaker | 9:d2e39ee9fedd | 3170 | } // endif |
nbaker | 9:d2e39ee9fedd | 3171 | |
nbaker | 9:d2e39ee9fedd | 3172 | if (Screen_Num != 21){ |
nbaker | 9:d2e39ee9fedd | 3173 | Screen_Num = 21; //Change to screen 21 (Fall diag screen) |
nbaker | 9:d2e39ee9fedd | 3174 | update_display(); |
nbaker | 9:d2e39ee9fedd | 3175 | } // endif |
nbaker | 9:d2e39ee9fedd | 3176 | sprintf(text_1,"Motion:%4.0f d/s",Gyro_Mag); |
nbaker | 9:d2e39ee9fedd | 3177 | oled.Label((uint8_t *)text_1,3,20);// text_1 at x,y |
nbaker | 10:eaea844e763c | 3178 | gyro_sensor_config(13); // reset motion counter |
nbaker | 9:d2e39ee9fedd | 3179 | wait(0.1); |
nbaker | 10:eaea844e763c | 3180 | Led_clk3 = 0; // Turn LED3 off docking station on |
nbaker | 9:d2e39ee9fedd | 3181 | haptic = 0; |
nbaker | 9:d2e39ee9fedd | 3182 | }// end if |
nbaker | 10:eaea844e763c | 3183 | }//end motion_detect_debug interupt routine |
nbaker | 10:eaea844e763c | 3184 | |
nbaker | 10:eaea844e763c | 3185 | //********** Full sequential fall interup routines below ********************* |
nbaker | 10:eaea844e763c | 3186 | /***************************************************************************** |
nbaker | 10:eaea844e763c | 3187 | Name: fall_detect() |
nbaker | 10:eaea844e763c | 3188 | Purpose: Interupt routine called when accelerometer IC has detected a |
nbaker | 10:eaea844e763c | 3189 | free-fall (accel <= 0.5g) |
nbaker | 10:eaea844e763c | 3190 | Inputs: interupt1 of accel sensor |
nbaker | 10:eaea844e763c | 3191 | ******************************************************************************/ |
nbaker | 10:eaea844e763c | 3192 | void fall_detect(){// fall detect interupt routine |
nbaker | 10:eaea844e763c | 3193 | if(Fall_Alert == 1 && Led_clk2 == 0){// are we looking for falls? Have we already det impact? |
nbaker | 10:eaea844e763c | 3194 | accel.acquire_accel_data_g(Accel_Data_Event); |
nbaker | 10:eaea844e763c | 3195 | f_time.reset(); |
nbaker | 10:eaea844e763c | 3196 | f_time.start(); //start measuring fall time |
nbaker | 10:eaea844e763c | 3197 | for (int i=0; i<7; i++){ |
nbaker | 10:eaea844e763c | 3198 | Fall_Event_Data[i] = 0; // clear any old information |
nbaker | 10:eaea844e763c | 3199 | }//end for loop |
nbaker | 10:eaea844e763c | 3200 | |
nbaker | 10:eaea844e763c | 3201 | // Screen_Timer.attach(&timout_timer,(SCRN_TIME));// Reset/restart ticker timer for OLED |
nbaker | 10:eaea844e763c | 3202 | //time_t seconds = time(NULL); |
nbaker | 10:eaea844e763c | 3203 | //store time into Fall_Event_Data buffer |
nbaker | 10:eaea844e763c | 3204 | 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 | 3205 | Led_clk1 = 1; // Turn on LED1, on docking station |
nbaker | 10:eaea844e763c | 3206 | //Led_clk2 = 0; // Turn off LED2, on docking station |
nbaker | 10:eaea844e763c | 3207 | Accel_INT1.rise(&fall_det_end); // look for end of fall by reseting accel sensor's int#1 to active high |
nbaker | 10:eaea844e763c | 3208 | // Accel_INT1.fall(&fall_detect); // Accel sensor's int#1 calls interupt routine |
nbaker | 10:eaea844e763c | 3209 | Accel_INT2.fall(&impact_detect); //Start looking for vector impacts |
nbaker | 10:eaea844e763c | 3210 | // Gyro_INT1.fall(&motion_detect); // Gyro sensor's int#1 (PTD1) calls interupt routine |
nbaker | 10:eaea844e763c | 3211 | chk_fall.attach(&chkfall,(0.5)); //initialize ticker to check for end of fall every half second |
nbaker | 10:eaea844e763c | 3212 | |
nbaker | 10:eaea844e763c | 3213 | }// end if |
nbaker | 10:eaea844e763c | 3214 | }//end fall_detect interupt routine |
nbaker | 10:eaea844e763c | 3215 | |
nbaker | 10:eaea844e763c | 3216 | |
nbaker | 10:eaea844e763c | 3217 | /***************************************************************************** |
nbaker | 10:eaea844e763c | 3218 | Name: chkfall() |
nbaker | 10:eaea844e763c | 3219 | Purpose: Ticker interupt routine called every 0.5 Seconds (after a free-fall has been detected) |
nbaker | 10:eaea844e763c | 3220 | to check to see if we've missed the interupt indicating the free-fall event is over. |
nbaker | 10:eaea844e763c | 3221 | Inputs: chk_fall Ticker |
nbaker | 10:eaea844e763c | 3222 | ******************************************************************************/ |
nbaker | 10:eaea844e763c | 3223 | void chkfall(){// Ticker fall-end detect routine to see if we missed interupt |
nbaker | 10:eaea844e763c | 3224 | if(Accel_INT1 == 0){//fall still active |
nbaker | 10:eaea844e763c | 3225 | accel.acquire_accel_data_g(Accel_Data_Event); |
nbaker | 10:eaea844e763c | 3226 | 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 | 3227 | if (Accel_Mag < Fall_Event_Data[0]){ |
nbaker | 10:eaea844e763c | 3228 | Fall_Event_Data[0] = Accel_Mag;// if fall is less than previous re-store value |
nbaker | 10:eaea844e763c | 3229 | }//endif |
nbaker | 10:eaea844e763c | 3230 | }//endif |
nbaker | 10:eaea844e763c | 3231 | else{//fall interupt off |
nbaker | 10:eaea844e763c | 3232 | f_time.stop(); // stop fall timer |
nbaker | 10:eaea844e763c | 3233 | chk_fall.detach(); //stop ticker, interupt caught end of fall |
nbaker | 10:eaea844e763c | 3234 | chk_fall.attach(&clear_fall,(2.0)); //initialize ticker to check no impact in 2 seconds |
nbaker | 10:eaea844e763c | 3235 | Accel_INT1.fall(NULL); // turn off accel sensor's int#1 |
nbaker | 10:eaea844e763c | 3236 | }//end else |
nbaker | 10:eaea844e763c | 3237 | |
nbaker | 10:eaea844e763c | 3238 | }//end chkfall ticker interupt routine |
nbaker | 10:eaea844e763c | 3239 | |
nbaker | 10:eaea844e763c | 3240 | /***************************************************************************** |
nbaker | 10:eaea844e763c | 3241 | Name: interupt_off() |
nbaker | 10:eaea844e763c | 3242 | Purpose: Interupts are supposed to be turned off by using "Int_name.fall(NULL);", but |
nbaker | 10:eaea844e763c | 3243 | that doesn't seem to work. |
nbaker | 10:eaea844e763c | 3244 | ******************************************************************************/ |
nbaker | 10:eaea844e763c | 3245 | void interupt_off(){// turn off an interupt by substituting this one |
nbaker | 10:eaea844e763c | 3246 | // Do nothing |
nbaker | 10:eaea844e763c | 3247 | }//end interupt_off routine |
nbaker | 10:eaea844e763c | 3248 | |
nbaker | 10:eaea844e763c | 3249 | |
nbaker | 10:eaea844e763c | 3250 | /***************************************************************************** |
nbaker | 10:eaea844e763c | 3251 | Name: fall_det_end() |
nbaker | 10:eaea844e763c | 3252 | Purpose: Interupt routine called when accelerometer IC has detected that the |
nbaker | 10:eaea844e763c | 3253 | free-fall acceleration has ended (accel now >0.5g) |
nbaker | 10:eaea844e763c | 3254 | Inputs: interupt1 of accel sensor |
nbaker | 10:eaea844e763c | 3255 | ******************************************************************************/ |
nbaker | 10:eaea844e763c | 3256 | void fall_det_end(){ // accel detected end of free-fall |
nbaker | 10:eaea844e763c | 3257 | f_time.stop(); // stop fall timer |
nbaker | 10:eaea844e763c | 3258 | chk_fall.detach(); //stop ticker, interupt caught end of fall |
nbaker | 10:eaea844e763c | 3259 | chk_fall.attach(&clear_fall,(Fall_Impact_Max_Wait_Time)); //initialize ticker to check no impact in 2 seconds |
nbaker | 10:eaea844e763c | 3260 | // fall_config(21); // reads interrupts to clear old interupt |
nbaker | 10:eaea844e763c | 3261 | Accel_INT1.fall(NULL); // Turn off accel sensor's int#1 |
nbaker | 10:eaea844e763c | 3262 | } //end fall_det_end interupt routine |
nbaker | 10:eaea844e763c | 3263 | |
nbaker | 10:eaea844e763c | 3264 | |
nbaker | 10:eaea844e763c | 3265 | /***************************************************************************** |
nbaker | 10:eaea844e763c | 3266 | Name: clear_fall() |
nbaker | 10:eaea844e763c | 3267 | Purpose: Ticker interupt routine called to clear/cancel fall detection routine if |
nbaker | 10:eaea844e763c | 3268 | no impact was detected withing 2.0 seconds after the free-fall event |
nbaker | 10:eaea844e763c | 3269 | Inputs: chk_fall Ticker |
nbaker | 10:eaea844e763c | 3270 | ******************************************************************************/ |
nbaker | 10:eaea844e763c | 3271 | 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 | 3272 | if(Led_clk2 == 1){// have we detected an impact? |
nbaker | 10:eaea844e763c | 3273 | chk_fall.detach(); //just stop ticker |
nbaker | 10:eaea844e763c | 3274 | }//endif |
nbaker | 10:eaea844e763c | 3275 | else{ |
nbaker | 10:eaea844e763c | 3276 | Accel_INT1.fall(&fall_detect); // reset accel sensor's int#1 to active low and reset for next fall |
nbaker | 10:eaea844e763c | 3277 | Accel_INT2.fall(NULL); //Stop looking for vector impacts, |
nbaker | 10:eaea844e763c | 3278 | Led_clk1 = 0; // Turn off LED1, on docking station |
nbaker | 10:eaea844e763c | 3279 | }//end else |
nbaker | 10:eaea844e763c | 3280 | }//end clear_fall ticker interupt routine |
nbaker | 10:eaea844e763c | 3281 | |
nbaker | 10:eaea844e763c | 3282 | |
nbaker | 10:eaea844e763c | 3283 | /***************************************************************************** |
nbaker | 10:eaea844e763c | 3284 | Name: impact_detect() |
nbaker | 10:eaea844e763c | 3285 | Purpose: Interupt routine called when accelerometer IC has detected a vector |
nbaker | 10:eaea844e763c | 3286 | magnitude acceleration >= 3.0g |
nbaker | 10:eaea844e763c | 3287 | Inputs: interupt2 of accel sensor |
nbaker | 10:eaea844e763c | 3288 | ******************************************************************************/ |
nbaker | 10:eaea844e763c | 3289 | void impact_detect(){// we may detect multiple impacts, this needs to work from last impact detected |
nbaker | 10:eaea844e763c | 3290 | if(Fall_Alert == 1){ |
nbaker | 10:eaea844e763c | 3291 | f_time.stop(); // stop fall timer |
nbaker | 10:eaea844e763c | 3292 | accel.acquire_accel_data_g(Accel_Data_Event); |
nbaker | 10:eaea844e763c | 3293 | chk_fall.detach(); //detach/stop ticker, impact was detected |
nbaker | 10:eaea844e763c | 3294 | wait(0.1); |
nbaker | 10:eaea844e763c | 3295 | Fall_Event_Data[1] = f_time;// store free-fall time |
nbaker | 10:eaea844e763c | 3296 | Led_clk2 = 1; // Turn on LED2, on docking station |
nbaker | 10:eaea844e763c | 3297 | gyro_sensor_config(13); // reset motion counter |
nbaker | 10:eaea844e763c | 3298 | Gyro_INT1.fall(&motion_detect); // Start looking for motion |
nbaker | 10:eaea844e763c | 3299 | chk_motion.attach(&chkmotion,(Min_Movement_duration)); //initialize ticker to check for motion during Min_Movement_duration |
nbaker | 10:eaea844e763c | 3300 | } // endif |
nbaker | 10:eaea844e763c | 3301 | 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 | 3302 | if(Accel_Mag>Fall_Event_Data[2]){ |
nbaker | 12:fd39a7983e06 | 3303 | Fall_Event_Data[2] = Accel_Mag; // if impact accel is higher than last measured, update |
nbaker | 10:eaea844e763c | 3304 | }//endif |
nbaker | 12:fd39a7983e06 | 3305 | haptic = 1;// vibrate a little |
nbaker | 12:fd39a7983e06 | 3306 | wait_ms(50); |
nbaker | 12:fd39a7983e06 | 3307 | haptic = 0; |
nbaker | 10:eaea844e763c | 3308 | //wait(0.1); |
nbaker | 10:eaea844e763c | 3309 | //Led_clk3 = 1; // Turn on LED3, on docking station - we're looking for motion |
nbaker | 10:eaea844e763c | 3310 | }//end impact_detect interupt routine |
nbaker | 10:eaea844e763c | 3311 | |
nbaker | 10:eaea844e763c | 3312 | /***************************************************************************** |
nbaker | 10:eaea844e763c | 3313 | Name: motion_detect() |
nbaker | 10:eaea844e763c | 3314 | Purpose: Interupt routine called when gyro IC has detected motion >= 50 deg/sec |
nbaker | 10:eaea844e763c | 3315 | in order to see if fall-impact resulted in motion-less person. |
nbaker | 10:eaea844e763c | 3316 | Inputs: interupt1 of gyro sensor |
nbaker | 10:eaea844e763c | 3317 | ******************************************************************************/ |
nbaker | 10:eaea844e763c | 3318 | void motion_detect(){// 2 seconds of motion was detected |
nbaker | 10:eaea844e763c | 3319 | chk_motion.detach(); //stop ticker, we've detected motion |
nbaker | 10:eaea844e763c | 3320 | Accel_INT1.fall(&fall_detect); // Accel sensor's int#1 calls interupt routine |
nbaker | 10:eaea844e763c | 3321 | Accel_INT2.fall(NULL); //Reset for next event |
nbaker | 10:eaea844e763c | 3322 | Gyro_INT1.fall(NULL); //Reset for next event |
nbaker | 10:eaea844e763c | 3323 | //wait(0.1); |
nbaker | 10:eaea844e763c | 3324 | Led_clk1 = 0; // Turn off LED1, on docking station |
nbaker | 10:eaea844e763c | 3325 | Led_clk2 = 0; // Turn off LED2, on docking station |
nbaker | 10:eaea844e763c | 3326 | |
nbaker | 9:d2e39ee9fedd | 3327 | }//end motion_detect interupt routine |
nbaker | 9:d2e39ee9fedd | 3328 | |
nbaker | 10:eaea844e763c | 3329 | |
nbaker | 10:eaea844e763c | 3330 | /***************************************************************************** |
nbaker | 10:eaea844e763c | 3331 | Name: chkmotion() |
nbaker | 10:eaea844e763c | 3332 | Purpose: Ticker interupt routine called when 60sec window has elapsed without |
nbaker | 10:eaea844e763c | 3333 | 2seconds of motion being detected. |
nbaker | 10:eaea844e763c | 3334 | Inputs: chk_motion Ticker |
nbaker | 10:eaea844e763c | 3335 | ******************************************************************************/ |
nbaker | 10:eaea844e763c | 3336 | void chkmotion(){// if we got here we didn't detect motion |
nbaker | 10:eaea844e763c | 3337 | // |
nbaker | 10:eaea844e763c | 3338 | chk_motion.detach(); //stop ticker |
nbaker | 10:eaea844e763c | 3339 | Screen_Num = 47; //Change to screen 47 (Fall diag screen) |
nbaker | 10:eaea844e763c | 3340 | Screen_Timer.attach(&timout_timer,(SCRN_TIME));// Reset/restart ticker timer for OLED |
nbaker | 10:eaea844e763c | 3341 | if (OLED_ON == 0) { |
nbaker | 10:eaea844e763c | 3342 | OLED_ON = 1; // Screen was off, set to On |
nbaker | 10:eaea844e763c | 3343 | } // endif |
nbaker | 13:37cd579208e9 | 3344 | oled.DimScreenOFF(); |
nbaker | 10:eaea844e763c | 3345 | update_display(); // |
nbaker | 10:eaea844e763c | 3346 | chk_motion.attach(&chk_help_needed,(Do_You_Need_Help_Time)); //initialize ticker to send automatic alert |
nbaker | 12:fd39a7983e06 | 3347 | CLRWDT(); |
nbaker | 10:eaea844e763c | 3348 | haptic = 1; |
nbaker | 12:fd39a7983e06 | 3349 | wait(0.2);// aggressive hapic |
nbaker | 10:eaea844e763c | 3350 | haptic = 0; |
nbaker | 10:eaea844e763c | 3351 | wait(0.2); |
nbaker | 10:eaea844e763c | 3352 | haptic = 1; |
nbaker | 12:fd39a7983e06 | 3353 | wait(0.2);// aggressive hapic |
nbaker | 12:fd39a7983e06 | 3354 | CLRWDT(); |
nbaker | 10:eaea844e763c | 3355 | haptic = 0; |
nbaker | 10:eaea844e763c | 3356 | wait(0.2); |
nbaker | 10:eaea844e763c | 3357 | haptic = 1; |
nbaker | 12:fd39a7983e06 | 3358 | wait(0.2);// aggressive hapic |
nbaker | 10:eaea844e763c | 3359 | haptic = 0; |
nbaker | 10:eaea844e763c | 3360 | |
nbaker | 10:eaea844e763c | 3361 | }//end of chkmotion ticker interupt routine |
nbaker | 10:eaea844e763c | 3362 | |
nbaker | 10:eaea844e763c | 3363 | /***************************************************************************** |
nbaker | 10:eaea844e763c | 3364 | Name: chk_help_needed() |
nbaker | 10:eaea844e763c | 3365 | Purpose: Ticker interupt routine called when X sec window has elapsed without |
nbaker | 10:eaea844e763c | 3366 | user dimissing "Are you OK" screen, sends automatic alert. |
nbaker | 10:eaea844e763c | 3367 | Inputs: chk_motion Ticker |
nbaker | 10:eaea844e763c | 3368 | ******************************************************************************/ |
nbaker | 10:eaea844e763c | 3369 | void chk_help_needed(){// Were they able to dismiss on their own? |
nbaker | 10:eaea844e763c | 3370 | // |
nbaker | 10:eaea844e763c | 3371 | chk_motion.detach(); //stop ticker |
nbaker | 10:eaea844e763c | 3372 | if (Screen_Num == 47){// are we still on screen 47? |
nbaker | 10:eaea844e763c | 3373 | Screen_Num = 48; //Change to screen 48 and send alert |
nbaker | 10:eaea844e763c | 3374 | Screen_Timer.attach(&timout_timer,(SCRN_TIME));// Reset/restart ticker timer for OLED to keep it on |
nbaker | 10:eaea844e763c | 3375 | if (OLED_ON == 0) { |
nbaker | 10:eaea844e763c | 3376 | OLED_ON = 1; // Screen was off, set to On |
nbaker | 10:eaea844e763c | 3377 | } // endif |
nbaker | 13:37cd579208e9 | 3378 | oled.DimScreenOFF(); |
nbaker | 10:eaea844e763c | 3379 | update_display(); |
nbaker | 10:eaea844e763c | 3380 | oled_text_properties_t textProperties = {0}; |
nbaker | 10:eaea844e763c | 3381 | oled.GetTextProperties(&textProperties); |
nbaker | 10:eaea844e763c | 3382 | textProperties.fontColor = COLOR_RED; |
nbaker | 10:eaea844e763c | 3383 | oled.SetTextProperties(&textProperties); |
nbaker | 12:fd39a7983e06 | 3384 | oled.Label((uint8_t *)"No response!", 5, 20); |
nbaker | 10:eaea844e763c | 3385 | textProperties.fontColor = COLOR_WHITE; |
nbaker | 10:eaea844e763c | 3386 | oled.SetTextProperties(&textProperties); |
nbaker | 12:fd39a7983e06 | 3387 | Send_Alert(30); // send alert type two |
nbaker | 12:fd39a7983e06 | 3388 | CLRWDT(); |
nbaker | 10:eaea844e763c | 3389 | haptic = 1; |
nbaker | 10:eaea844e763c | 3390 | wait(0.5);// very aggressive hapic |
nbaker | 10:eaea844e763c | 3391 | haptic = 0; |
nbaker | 10:eaea844e763c | 3392 | wait(0.2); |
nbaker | 10:eaea844e763c | 3393 | haptic = 1; |
nbaker | 12:fd39a7983e06 | 3394 | CLRWDT(); |
nbaker | 10:eaea844e763c | 3395 | wait(0.5);// very aggressive hapic |
nbaker | 10:eaea844e763c | 3396 | haptic = 0; |
nbaker | 10:eaea844e763c | 3397 | wait(0.2); |
nbaker | 10:eaea844e763c | 3398 | haptic = 1; |
nbaker | 12:fd39a7983e06 | 3399 | CLRWDT(); |
nbaker | 10:eaea844e763c | 3400 | wait(0.5);// very aggressive hapic |
nbaker | 10:eaea844e763c | 3401 | haptic = 0; |
nbaker | 10:eaea844e763c | 3402 | } // endif |
nbaker | 10:eaea844e763c | 3403 | |
nbaker | 10:eaea844e763c | 3404 | }//end of chkmotion ticker interupt routine |
nbaker | 10:eaea844e763c | 3405 | |
nbaker | 10:eaea844e763c | 3406 | |
nbaker | 10:eaea844e763c | 3407 | /***************************************************************************** |
nbaker | 10:eaea844e763c | 3408 | Name: Send_Alert() |
nbaker | 10:eaea844e763c | 3409 | Purpose: routine used to store and send alert |
nbaker | 10:eaea844e763c | 3410 | Inputs: int value from 0 to 256 |
nbaker | 12:fd39a7983e06 | 3411 | 10=Panic, 20=Fall+asked for help, 30=Fall+No response, 40=?... |
nbaker | 10:eaea844e763c | 3412 | Returns: None |
nbaker | 10:eaea844e763c | 3413 | ******************************************************************************/ |
nbaker | 10:eaea844e763c | 3414 | void Send_Alert(uint8_t Num){ |
nbaker | 10:eaea844e763c | 3415 | |
nbaker | 10:eaea844e763c | 3416 | // store alert |
nbaker | 11:ccda4d44bd8e | 3417 | |
nbaker | 11:ccda4d44bd8e | 3418 | |
nbaker | 11:ccda4d44bd8e | 3419 | // ************ transmit alert |
nbaker | 11:ccda4d44bd8e | 3420 | /*Notify Hexiwear App that it is running Sensor Tag mode*/ |
nbaker | 11:ccda4d44bd8e | 3421 | kw40z_device.SendSetApplicationMode(GUI_CURRENT_APP_SENSOR_TAG); |
nbaker | 11:ccda4d44bd8e | 3422 | |
nbaker | 11:ccda4d44bd8e | 3423 | /*Send Ambient Light Level at with aler number */ |
nbaker | 12:fd39a7983e06 | 3424 | //10=Panic, 20=Fall+asked for help, 30=Fall+No response, 40=?... |
nbaker | 11:ccda4d44bd8e | 3425 | kw40z_device.SendAmbientLight(Num); |
nbaker | 10:eaea844e763c | 3426 | |
nbaker | 10:eaea844e763c | 3427 | }//end Send_Alert routine |
nbaker | 10:eaea844e763c | 3428 | |
nbaker | 9:d2e39ee9fedd | 3429 | /***************************************************************************** |
nbaker | 4:0803151bc5e4 | 3430 | Name: fall_config() |
nbaker | 10:eaea844e763c | 3431 | Purpose: routine used to set accelerometer and gyro sensors' internal registers for chip |
nbaker | 10:eaea844e763c | 3432 | level interrupts |
nbaker | 10:eaea844e763c | 3433 | Inputs: int value from 0 to 256 |
nbaker | 10:eaea844e763c | 3434 | Returns: None |
nbaker | 10:eaea844e763c | 3435 | ******************************************************************************/ |
nbaker | 10:eaea844e763c | 3436 | void fall_config(uint8_t Num){ // this is more than just accel config |
nbaker | 10:eaea844e763c | 3437 | // use case switches here to configure for |
nbaker | 10:eaea844e763c | 3438 | switch(Num) { |
nbaker | 10:eaea844e763c | 3439 | case 0: {// put in standby |
nbaker | 10:eaea844e763c | 3440 | accel_sensor_config(0); // set accel sensor to standby |
nbaker | 10:eaea844e763c | 3441 | /*For lowest accel power ~2uA in standby mode */ |
nbaker | 10:eaea844e763c | 3442 | gyro_sensor_config(0); // set gyro sensor to standby |
nbaker | 10:eaea844e763c | 3443 | /*For lowest gyro power ~2.8uA in standby mode */ |
nbaker | 10:eaea844e763c | 3444 | Accel_INT1.fall(NULL); // Turn off Accel sensor's int#1 |
nbaker | 10:eaea844e763c | 3445 | Accel_INT2.fall(NULL); // Turn off Accel sensor's int#2 |
nbaker | 10:eaea844e763c | 3446 | Gyro_INT1.fall(NULL); // Turn off Gyro sensor's int#1 |
nbaker | 10:eaea844e763c | 3447 | break; |
nbaker | 10:eaea844e763c | 3448 | }// end of case 0 |
nbaker | 10:eaea844e763c | 3449 | |
nbaker | 10:eaea844e763c | 3450 | case 1: {// configure for free-fall int only |
nbaker | 10:eaea844e763c | 3451 | accel_sensor_config(1); // set accel sensor for free-fall |
nbaker | 10:eaea844e763c | 3452 | gyro_sensor_config(0); // set gyro sensor to standby |
nbaker | 10:eaea844e763c | 3453 | Accel_INT1.fall(NULL); // Turn off Accel sensor's int#1 |
nbaker | 10:eaea844e763c | 3454 | Accel_INT2.fall(NULL); // Turn off Accel sensor's int#2 |
nbaker | 10:eaea844e763c | 3455 | Gyro_INT1.fall(NULL); // Turn off Gyro sensor's int#1 |
nbaker | 10:eaea844e763c | 3456 | |
nbaker | 10:eaea844e763c | 3457 | Accel_INT1.fall(&fall_detect_debug); // Accel sensor's int#1 calls interupt routine |
nbaker | 10:eaea844e763c | 3458 | break; |
nbaker | 10:eaea844e763c | 3459 | }// end of case 1 |
nbaker | 10:eaea844e763c | 3460 | |
nbaker | 10:eaea844e763c | 3461 | case 2: {// configure for vector impact only |
nbaker | 10:eaea844e763c | 3462 | accel_sensor_config(2); // set accel sensor vector impact only |
nbaker | 10:eaea844e763c | 3463 | gyro_sensor_config(0); // set gyro sensor to standby |
nbaker | 10:eaea844e763c | 3464 | Accel_INT1.fall(NULL); // Turn off Accel sensor's int#1 |
nbaker | 10:eaea844e763c | 3465 | // Accel_INT2.fall(NULL); // Turn off Accel sensor's int#2 |
nbaker | 10:eaea844e763c | 3466 | Gyro_INT1.fall(NULL); // Turn off Gyro sensor's int#1 |
nbaker | 10:eaea844e763c | 3467 | Accel_INT2.fall(&impact_detect_debug); //Accel sensor's int#2 calls interupt routine |
nbaker | 10:eaea844e763c | 3468 | |
nbaker | 10:eaea844e763c | 3469 | break; |
nbaker | 10:eaea844e763c | 3470 | }// end of case 2 |
nbaker | 10:eaea844e763c | 3471 | |
nbaker | 10:eaea844e763c | 3472 | case 3: {// configure for motion int only |
nbaker | 10:eaea844e763c | 3473 | accel_sensor_config(0); // set accel sensor vector impact only |
nbaker | 10:eaea844e763c | 3474 | gyro_sensor_config(3); // set gyro sensor to standby |
nbaker | 10:eaea844e763c | 3475 | Accel_INT1.fall(NULL); // Turn off Accel sensor's int#1 |
nbaker | 10:eaea844e763c | 3476 | Accel_INT2.fall(NULL); // Turn off Accel sensor's int#2 |
nbaker | 10:eaea844e763c | 3477 | Gyro_INT1.fall(&motion_detect_debug); // Gyro sensor's int#1 (PTD1) calls interupt routine |
nbaker | 10:eaea844e763c | 3478 | break; |
nbaker | 10:eaea844e763c | 3479 | }// end of case 3 |
nbaker | 10:eaea844e763c | 3480 | |
nbaker | 10:eaea844e763c | 3481 | case 4: {// configure FFMT for free-fall event AND config for vector impact |
nbaker | 10:eaea844e763c | 3482 | accel_sensor_config(4); // set accel sensor Free-fall and vector impact |
nbaker | 10:eaea844e763c | 3483 | gyro_sensor_config(3); // set gyro sensor motion |
nbaker | 10:eaea844e763c | 3484 | Accel_INT1.fall(&fall_detect_debug); // Accel sensor's int#1 calls interupt routine |
nbaker | 10:eaea844e763c | 3485 | Accel_INT2.fall(&impact_detect_debug); //Accel sensor's int#2 calls interupt routine |
nbaker | 10:eaea844e763c | 3486 | Gyro_INT1.fall(&motion_detect_debug); // Gyro sensor's int#1 (PTD1) calls interupt routine |
nbaker | 10:eaea844e763c | 3487 | break; |
nbaker | 10:eaea844e763c | 3488 | }// end of case 4 |
nbaker | 10:eaea844e763c | 3489 | |
nbaker | 10:eaea844e763c | 3490 | case 5: {// configure for sequential free-fall, vector impact then motion |
nbaker | 10:eaea844e763c | 3491 | accel_sensor_config(4); // set accel sensor Free-fall and vector impact |
nbaker | 10:eaea844e763c | 3492 | gyro_sensor_config(3); // set gyro sensor motion |
nbaker | 10:eaea844e763c | 3493 | Accel_INT1.fall(&fall_detect); // Accel sensor's int#1 calls interupt routine |
nbaker | 10:eaea844e763c | 3494 | Accel_INT2.fall(NULL); //Accel sensor's int#2 calls interupt routine |
nbaker | 10:eaea844e763c | 3495 | Gyro_INT1.fall(NULL); // Gyro sensor's int#1 (PTD1) calls interupt routine |
nbaker | 10:eaea844e763c | 3496 | break; |
nbaker | 10:eaea844e763c | 3497 | }// end of case 4 |
nbaker | 10:eaea844e763c | 3498 | |
nbaker | 10:eaea844e763c | 3499 | case 10: {// reset IC |
nbaker | 10:eaea844e763c | 3500 | accel_sensor_config(10); // reset accel sensor |
nbaker | 10:eaea844e763c | 3501 | gyro_sensor_config(10); // reset gyro sensor |
nbaker | 10:eaea844e763c | 3502 | break; |
nbaker | 10:eaea844e763c | 3503 | }// end case 10 |
nbaker | 10:eaea844e763c | 3504 | |
nbaker | 10:eaea844e763c | 3505 | case 11: {// wake both sensors for simple data read, they were in stanby |
nbaker | 10:eaea844e763c | 3506 | accel_sensor_config(11); // set accel sensor active for read |
nbaker | 10:eaea844e763c | 3507 | gyro_sensor_config(11); // set accel sensor active for read |
nbaker | 10:eaea844e763c | 3508 | break; |
nbaker | 10:eaea844e763c | 3509 | }// end of case 11 |
nbaker | 10:eaea844e763c | 3510 | |
nbaker | 10:eaea844e763c | 3511 | case 12: {// put into standby for low power |
nbaker | 10:eaea844e763c | 3512 | accel_sensor_config(12); // set accel sensor to standby |
nbaker | 10:eaea844e763c | 3513 | gyro_sensor_config(12); // set gyro sensor to standby |
nbaker | 10:eaea844e763c | 3514 | break; |
nbaker | 10:eaea844e763c | 3515 | }// end of case 112 |
nbaker | 10:eaea844e763c | 3516 | |
nbaker | 10:eaea844e763c | 3517 | case 20: {// read INT_Source to clear VECM int, shouldn't have to do this |
nbaker | 10:eaea844e763c | 3518 | // This was not working for me but it was due to me using the wrong FXOS8700_I2C_ADDRESS_ |
nbaker | 10:eaea844e763c | 3519 | char d[2];//, data_byte_[1]; |
nbaker | 10:eaea844e763c | 3520 | d[0] = 0x0c; // 0x0c is INT_Source Reg |
nbaker | 10:eaea844e763c | 3521 | i2c_bus1.write(FXOS8700_I2C_ADDRESS_,d,1,true); // "true" is needed to prevent stop |
nbaker | 10:eaea844e763c | 3522 | wait(0.01); |
nbaker | 10:eaea844e763c | 3523 | if(i2c_bus1.read(FXOS8700_I2C_ADDRESS_,d,1) == 1){ // read Who am I Reg for debug |
nbaker | 10:eaea844e763c | 3524 | sprintf(text_1," INT_Read_Err "); |
nbaker | 10:eaea844e763c | 3525 | oled.Label((uint8_t *)text_1,5,50); // Display error at x,y |
nbaker | 10:eaea844e763c | 3526 | wait(1); // wait 1 seconds |
nbaker | 10:eaea844e763c | 3527 | }//endif |
nbaker | 10:eaea844e763c | 3528 | break; |
nbaker | 10:eaea844e763c | 3529 | }// end of case 20 |
nbaker | 10:eaea844e763c | 3530 | |
nbaker | 10:eaea844e763c | 3531 | case 21: {// read A_FFMT_SRC reg to clear FFMT int, shouldn't have to do this |
nbaker | 10:eaea844e763c | 3532 | // This was not working for me but it was due to me using the wrong FXOS8700_I2C_ADDRESS_ |
nbaker | 10:eaea844e763c | 3533 | char d[2];//, data_byte_[1]; |
nbaker | 10:eaea844e763c | 3534 | d[0] = 0x16; // 0x16 is A_FFMT_SRC Reg |
nbaker | 10:eaea844e763c | 3535 | i2c_bus1.write(FXOS8700_I2C_ADDRESS_,d,1,true); // "true" is needed to prevent stop |
nbaker | 10:eaea844e763c | 3536 | wait(0.01); |
nbaker | 10:eaea844e763c | 3537 | if(i2c_bus1.read(FXOS8700_I2C_ADDRESS_,d,1) == 1){ // read Who am I Reg for debug |
nbaker | 10:eaea844e763c | 3538 | sprintf(text_1," INT_Read_Err "); |
nbaker | 10:eaea844e763c | 3539 | oled.Label((uint8_t *)text_1,5,50); // Display error at x,y |
nbaker | 10:eaea844e763c | 3540 | wait(1); // wait 1 seconds |
nbaker | 10:eaea844e763c | 3541 | }//endif |
nbaker | 10:eaea844e763c | 3542 | break; |
nbaker | 10:eaea844e763c | 3543 | }// end of case 21 |
nbaker | 10:eaea844e763c | 3544 | |
nbaker | 10:eaea844e763c | 3545 | default: { |
nbaker | 10:eaea844e763c | 3546 | oled.Label((uint8_t *)" Mode? ",30,60); // Display "mode" at x,y |
nbaker | 10:eaea844e763c | 3547 | // unknown config |
nbaker | 10:eaea844e763c | 3548 | break; |
nbaker | 10:eaea844e763c | 3549 | } |
nbaker | 10:eaea844e763c | 3550 | }// end switch |
nbaker | 10:eaea844e763c | 3551 | |
nbaker | 10:eaea844e763c | 3552 | }// end Fall_config |
nbaker | 10:eaea844e763c | 3553 | |
nbaker | 10:eaea844e763c | 3554 | |
nbaker | 10:eaea844e763c | 3555 | /***************************************************************************** |
nbaker | 10:eaea844e763c | 3556 | Name: accel_sensor_config() |
nbaker | 4:0803151bc5e4 | 3557 | Purpose: Used to set accelerometer IC's internal registers to set up chip level |
nbaker | 4:0803151bc5e4 | 3558 | interrupts |
nbaker | 4:0803151bc5e4 | 3559 | Inputs: int value from 0 to 256 |
nbaker | 4:0803151bc5e4 | 3560 | Returns: None |
nbaker | 4:0803151bc5e4 | 3561 | ******************************************************************************/ |
nbaker | 4:0803151bc5e4 | 3562 | |
nbaker | 10:eaea844e763c | 3563 | void accel_sensor_config(uint8_t Num){ |
nbaker | 4:0803151bc5e4 | 3564 | // use case switches here to configure for |
nbaker | 8:a5c77b45008d | 3565 | switch(Num) { |
nbaker | 8:a5c77b45008d | 3566 | case 0: {// put in standby |
nbaker | 4:0803151bc5e4 | 3567 | char d[2]; |
nbaker | 4:0803151bc5e4 | 3568 | d[0] = FXOS8700_CTRL_REG1; //Puts device in Standby mode |
nbaker | 4:0803151bc5e4 | 3569 | d[1] = 0x00; |
nbaker | 9:d2e39ee9fedd | 3570 | i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2); |
nbaker | 8:a5c77b45008d | 3571 | /*For lowest power ~8uA, set ODR-12.5Hz,(low-pwr accel mode) or 2uA in standby mode */ |
nbaker | 8:a5c77b45008d | 3572 | break; |
nbaker | 8:a5c77b45008d | 3573 | }// end of case 0 |
nbaker | 8:a5c77b45008d | 3574 | |
nbaker | 8:a5c77b45008d | 3575 | case 1: {// configure for free-fall int only |
nbaker | 4:0803151bc5e4 | 3576 | char d[2]; |
nbaker | 8:a5c77b45008d | 3577 | d[0] = 0x2a; //0x2a Config reg1 |
nbaker | 4:0803151bc5e4 | 3578 | d[1] = 0x00; //Put device in Standby mode |
nbaker | 4:0803151bc5e4 | 3579 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 9:d2e39ee9fedd | 3580 | oled.Label((uint8_t *)"Acc1a err",30,05); // Display "error" at x,y |
nbaker | 4:0803151bc5e4 | 3581 | wait(3.0); // display for 3 seconds |
nbaker | 4:0803151bc5e4 | 3582 | }//end if |
nbaker | 4:0803151bc5e4 | 3583 | |
nbaker | 4:0803151bc5e4 | 3584 | d[0] = 0x0e; //XYZ_DATA_CFG (set full-scall range) |
nbaker | 8:a5c77b45008d | 3585 | d[1] = 0b00000001; //Set data to default range of +/-2g for full range (2x0.488mg/LSB), High-pass filter off |
nbaker | 4:0803151bc5e4 | 3586 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 9:d2e39ee9fedd | 3587 | oled.Label((uint8_t *)"Acc1b err",30,05); // Display "error" at x,y |
nbaker | 4:0803151bc5e4 | 3588 | wait(3.0); // display for 3 seconds |
nbaker | 4:0803151bc5e4 | 3589 | }//end if |
nbaker | 8:a5c77b45008d | 3590 | /* |
nbaker | 8:a5c77b45008d | 3591 | d[0] = 0x0a; //TRIG_CFG (address of FIFO trigger config reg) |
nbaker | 4:0803151bc5e4 | 3592 | d[1] = 0b00000100; //Trigger on freefall |
nbaker | 4:0803151bc5e4 | 3593 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 4:0803151bc5e4 | 3594 | oled.Label((uint8_t *)" Step2 error ",30,05); // Display "error" at x,y |
nbaker | 4:0803151bc5e4 | 3595 | wait(3.0); // display for 3 seconds |
nbaker | 4:0803151bc5e4 | 3596 | }//end if |
nbaker | 8:a5c77b45008d | 3597 | */ |
nbaker | 4:0803151bc5e4 | 3598 | d[0] = 0x15; //A_FFMT_CFG (address of Free fall trigger config reg), write in Standby only |
nbaker | 4:0803151bc5e4 | 3599 | d[1] = 0b00111000; //set to freefall, and look at all axis. |
nbaker | 4:0803151bc5e4 | 3600 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 9:d2e39ee9fedd | 3601 | oled.Label((uint8_t *)"Acc1c err",30,05); // Display "error" at x,y |
nbaker | 4:0803151bc5e4 | 3602 | wait(3.0); // display for 3 seconds |
nbaker | 4:0803151bc5e4 | 3603 | }//end if |
nbaker | 4:0803151bc5e4 | 3604 | |
nbaker | 4:0803151bc5e4 | 3605 | d[0] = 0x17; //A_FFMT_THS (address of Free fall threshold reg), write in Active or Standby |
nbaker | 9:d2e39ee9fedd | 3606 | // d[1] = 0b00001000; //set freefall threshold to about 756mg for now |
nbaker | 9:d2e39ee9fedd | 3607 | d[1] = (uint8_t)(1000*Fall_Thresh/63); //set freefall threshold - Resolution is 63mg/LSB, 0b111_1111 is maximum value |
nbaker | 4:0803151bc5e4 | 3608 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 9:d2e39ee9fedd | 3609 | oled.Label((uint8_t *)"Acc1d err",30,05); // Display "error" at x,y |
nbaker | 4:0803151bc5e4 | 3610 | wait(3.0); // display for 3 seconds |
nbaker | 4:0803151bc5e4 | 3611 | }//end if |
nbaker | 4:0803151bc5e4 | 3612 | |
nbaker | 4:0803151bc5e4 | 3613 | d[0] = 0x18; //A_FFMT_COUNT (address of Free fall debounce counter), write in Active or Standby |
nbaker | 4:0803151bc5e4 | 3614 | d[1] = 0b00000110; //with ODR at 100Hz, should equal 60mS debounce time or 120mS in Sleep |
nbaker | 4:0803151bc5e4 | 3615 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 9:d2e39ee9fedd | 3616 | oled.Label((uint8_t *)"Acc1e err",30,05); // Display "error" at x,y |
nbaker | 4:0803151bc5e4 | 3617 | wait(3.0); // display for 3 seconds |
nbaker | 4:0803151bc5e4 | 3618 | }//end if |
nbaker | 4:0803151bc5e4 | 3619 | |
nbaker | 4:0803151bc5e4 | 3620 | d[0] = 0x2b; //CTRL_REG2 (address of control reg), write in Standby only |
nbaker | 9:d2e39ee9fedd | 3621 | // d[1] = 0b00001101; //Turns Auto-Sleep mode on and low-noise, low power |
nbaker | 9:d2e39ee9fedd | 3622 | d[1] = 0b00001001; //Turns Auto-Sleep mode off (b/c it wasn't waking on int) and low-noise, low power |
nbaker | 4:0803151bc5e4 | 3623 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 9:d2e39ee9fedd | 3624 | oled.Label((uint8_t *)"Acc1f err",30,05); // Display "error" at x,y |
nbaker | 4:0803151bc5e4 | 3625 | wait(3.0); // display for 3 seconds |
nbaker | 4:0803151bc5e4 | 3626 | }//end if |
nbaker | 4:0803151bc5e4 | 3627 | |
nbaker | 4:0803151bc5e4 | 3628 | d[0] = 0x2c; //CTRL_REG3 (address of Int control reg), write in Standby only |
nbaker | 4:0803151bc5e4 | 3629 | d[1] = 0b00001000; //FFMT will wake chip from sleep, int are active high |
nbaker | 4:0803151bc5e4 | 3630 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 9:d2e39ee9fedd | 3631 | oled.Label((uint8_t *)"Acc1g err",30,05); // Display "error" at x,y |
nbaker | 4:0803151bc5e4 | 3632 | wait(3.0); // display for 3 seconds |
nbaker | 4:0803151bc5e4 | 3633 | }//end if |
nbaker | 4:0803151bc5e4 | 3634 | |
nbaker | 4:0803151bc5e4 | 3635 | d[0] = 0x2d; //CTRL_REG4 (address of Int enable reg), write in Standby only |
nbaker | 9:d2e39ee9fedd | 3636 | d[1] = 0b10000100; // FFMT int enabled and for debug I'm using a sleep int |
nbaker | 4:0803151bc5e4 | 3637 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 9:d2e39ee9fedd | 3638 | oled.Label((uint8_t *)"Acc1h err",30,05); // Display "error" at x,y |
nbaker | 4:0803151bc5e4 | 3639 | wait(3.0); // display for 3 seconds |
nbaker | 4:0803151bc5e4 | 3640 | }//end if |
nbaker | 8:a5c77b45008d | 3641 | |
nbaker | 4:0803151bc5e4 | 3642 | d[0] = 0x2e; //CTRL_REG5 (Int routing reg), write in Standby only |
nbaker | 4:0803151bc5e4 | 3643 | d[1] = 0b00000100; // Make FFMT int output on pin INT1(PTC1) |
nbaker | 4:0803151bc5e4 | 3644 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 9:d2e39ee9fedd | 3645 | oled.Label((uint8_t *)"Acc1i err",30,05); // Display "error" at x,y |
nbaker | 4:0803151bc5e4 | 3646 | wait(3.0); // display for 3 seconds |
nbaker | 4:0803151bc5e4 | 3647 | }//end if |
nbaker | 4:0803151bc5e4 | 3648 | |
nbaker | 9:d2e39ee9fedd | 3649 | d[0] = 0x29; //ASLP_Count (counter used to go to sleep reg), write in Standby only |
nbaker | 9:d2e39ee9fedd | 3650 | d[1] = 0b00001010; // 10*320mS=3.2S of no inturrupts to go to sleep |
nbaker | 9:d2e39ee9fedd | 3651 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 9:d2e39ee9fedd | 3652 | oled.Label((uint8_t *)"Acc1j err",30,05); // Display "error" at x,y |
nbaker | 9:d2e39ee9fedd | 3653 | wait(3.0); // display for 3 seconds |
nbaker | 9:d2e39ee9fedd | 3654 | }//end if |
nbaker | 9:d2e39ee9fedd | 3655 | |
nbaker | 8:a5c77b45008d | 3656 | d[0] = 0x2a; //0x2a Config reg1, write in Standby only except for bit[0] |
nbaker | 4:0803151bc5e4 | 3657 | d[1] = 0b00011001; //Auto-Sleep mode on set to 50Hz, ODR set to 100Hz Puts device back into Active mode |
nbaker | 4:0803151bc5e4 | 3658 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 9:d2e39ee9fedd | 3659 | oled.Label((uint8_t *)"Acc1k err",30,05); // Display "error" at x,y |
nbaker | 4:0803151bc5e4 | 3660 | wait(3.0); // display for 3 seconds |
nbaker | 4:0803151bc5e4 | 3661 | }//end if |
nbaker | 9:d2e39ee9fedd | 3662 | |
nbaker | 4:0803151bc5e4 | 3663 | break; |
nbaker | 7:3d5a8aea0b63 | 3664 | }// end of case 1 |
nbaker | 7:3d5a8aea0b63 | 3665 | |
nbaker | 8:a5c77b45008d | 3666 | case 2: {// configure for vector impact only |
nbaker | 7:3d5a8aea0b63 | 3667 | char d[2]; |
nbaker | 7:3d5a8aea0b63 | 3668 | |
nbaker | 7:3d5a8aea0b63 | 3669 | d[0] = FXOS8700_CTRL_REG1; //Config reg1 0x2a |
nbaker | 7:3d5a8aea0b63 | 3670 | d[1] = 0x00; //Put device in Standby mode |
nbaker | 7:3d5a8aea0b63 | 3671 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 9:d2e39ee9fedd | 3672 | oled.Label((uint8_t *)"Acc2a err",30,05); // Display "error" at x,y |
nbaker | 7:3d5a8aea0b63 | 3673 | wait(3.0); // display for 3 seconds |
nbaker | 7:3d5a8aea0b63 | 3674 | }//end if |
nbaker | 7:3d5a8aea0b63 | 3675 | |
nbaker | 7:3d5a8aea0b63 | 3676 | d[0] = 0x0e; //XYZ_DATA_CFG (set full-scall range) |
nbaker | 7:3d5a8aea0b63 | 3677 | d[1] = 0b00000001; //Set data to +/-4g for full range (0.488mg/LSB), High-pass filter off |
nbaker | 7:3d5a8aea0b63 | 3678 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 9:d2e39ee9fedd | 3679 | oled.Label((uint8_t *)"Acc2b err",30,05); // Display "error" at x,y |
nbaker | 7:3d5a8aea0b63 | 3680 | wait(3.0); // display for 3 seconds |
nbaker | 7:3d5a8aea0b63 | 3681 | }//end if |
nbaker | 8:a5c77b45008d | 3682 | /* |
nbaker | 8:a5c77b45008d | 3683 | d[0] = 0x0a; //TRIG_CFG (address of FIFO trigger config reg) |
nbaker | 7:3d5a8aea0b63 | 3684 | d[1] = 0b00000110; //Trigger on freefall and on Vector |
nbaker | 7:3d5a8aea0b63 | 3685 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 7:3d5a8aea0b63 | 3686 | oled.Label((uint8_t *)" Step2 error ",30,05); // Display "error" at x,y |
nbaker | 7:3d5a8aea0b63 | 3687 | wait(3.0); // display for 3 seconds |
nbaker | 7:3d5a8aea0b63 | 3688 | }//end if |
nbaker | 8:a5c77b45008d | 3689 | */ |
nbaker | 8:a5c77b45008d | 3690 | d[0] = 0x5f; //A_VECM_CFG (address of Vector config reg), write in Standby only |
nbaker | 8:a5c77b45008d | 3691 | d[1] = 0b00111000; //Use reference values, don't update ref, enable. |
nbaker | 8:a5c77b45008d | 3692 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 9:d2e39ee9fedd | 3693 | oled.Label((uint8_t *)"Acc2c err",30,05); // Display "error" at x,y |
nbaker | 8:a5c77b45008d | 3694 | wait(3.0); // display for 3 seconds |
nbaker | 8:a5c77b45008d | 3695 | }//end if |
nbaker | 8:a5c77b45008d | 3696 | |
nbaker | 8:a5c77b45008d | 3697 | d[0] = 0x60; //A_VECM_MSB (address of Vector threshold reg), write in Active or Standby |
nbaker | 9:d2e39ee9fedd | 3698 | // d[1] = 0b00000111; //set impact threshold to less than 1g for now |
nbaker | 9:d2e39ee9fedd | 3699 | 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 | 3700 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 9:d2e39ee9fedd | 3701 | oled.Label((uint8_t *)"Acc2d err",30,05); // Display "error" at x,y |
nbaker | 8:a5c77b45008d | 3702 | wait(3.0); // display for 3 seconds |
nbaker | 8:a5c77b45008d | 3703 | }//end if |
nbaker | 8:a5c77b45008d | 3704 | |
nbaker | 8:a5c77b45008d | 3705 | d[0] = 0x61; //A_VECM_LSB (address of Vector threshold reg), write in Active or Standby |
nbaker | 9:d2e39ee9fedd | 3706 | // d[1] = 0b00000011; //set impact threshold to less than 1g for now |
nbaker | 9:d2e39ee9fedd | 3707 | d[1] = (uint8_t)(1000*Impact_Thresh/0.488f); |
nbaker | 9:d2e39ee9fedd | 3708 | 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 | 3709 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 9:d2e39ee9fedd | 3710 | oled.Label((uint8_t *)"Acc2e err",30,05); // Display "error" at x,y |
nbaker | 8:a5c77b45008d | 3711 | wait(3.0); // display for 3 seconds |
nbaker | 9:d2e39ee9fedd | 3712 | }//end if |
nbaker | 8:a5c77b45008d | 3713 | |
nbaker | 8:a5c77b45008d | 3714 | d[0] = 0x62; //A_VECM_COUNT (address of Vector debounce counter), write in Active or Standby |
nbaker | 8:a5c77b45008d | 3715 | d[1] = 0b00000110; //with ODR at 100Hz, should equal ??mS debounce time or ??mS in Sleep |
nbaker | 8:a5c77b45008d | 3716 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 9:d2e39ee9fedd | 3717 | oled.Label((uint8_t *)"Acc2f err",30,05); // Display "error" at x,y |
nbaker | 8:a5c77b45008d | 3718 | wait(3.0); // display for 3 seconds |
nbaker | 8:a5c77b45008d | 3719 | }//end if |
nbaker | 8:a5c77b45008d | 3720 | |
nbaker | 8:a5c77b45008d | 3721 | // Registers 0x63 - 0x68 are vector reference values which I'm leaving set to 0 because we want absolute measurements |
nbaker | 8:a5c77b45008d | 3722 | |
nbaker | 8:a5c77b45008d | 3723 | d[0] = 0x2b; //CTRL_REG2 (address of control reg), write in Standby only |
nbaker | 9:d2e39ee9fedd | 3724 | // d[1] = 0b00001101; //Turns Auto-Sleep mode on and low-noise, low power |
nbaker | 9:d2e39ee9fedd | 3725 | d[1] = 0b00001001; //Turns Auto-Sleep mode off (b/c it wasn't waking on int) and low-noise, low power |
nbaker | 8:a5c77b45008d | 3726 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 9:d2e39ee9fedd | 3727 | oled.Label((uint8_t *)"Acc2g err",30,05); // Display "error" at x,y |
nbaker | 8:a5c77b45008d | 3728 | wait(3.0); // display for 3 seconds |
nbaker | 8:a5c77b45008d | 3729 | }//end if |
nbaker | 7:3d5a8aea0b63 | 3730 | |
nbaker | 8:a5c77b45008d | 3731 | d[0] = 0x2c; //CTRL_REG3 (address of Int control reg), write in Standby only |
nbaker | 8:a5c77b45008d | 3732 | d[1] = 0b00000100; //Vector will wake chip from sleep, int are active high |
nbaker | 8:a5c77b45008d | 3733 | // d[1] = 0b00001000; //FFMT will wake chip from sleep, int are active high |
nbaker | 8:a5c77b45008d | 3734 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 9:d2e39ee9fedd | 3735 | oled.Label((uint8_t *)"Acc2h err",30,05); // Display "error" at x,y |
nbaker | 8:a5c77b45008d | 3736 | wait(3.0); // display for 3 seconds |
nbaker | 8:a5c77b45008d | 3737 | }//end if |
nbaker | 8:a5c77b45008d | 3738 | |
nbaker | 8:a5c77b45008d | 3739 | d[0] = 0x2d; //CTRL_REG4 (address of Int enable reg), write in Standby only |
nbaker | 9:d2e39ee9fedd | 3740 | d[1] = 0b10000010; // Vector int enabled |
nbaker | 8:a5c77b45008d | 3741 | // d[1] = 0b00000100; // FFMT int enabled |
nbaker | 8:a5c77b45008d | 3742 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 9:d2e39ee9fedd | 3743 | oled.Label((uint8_t *)"Acc2i err",30,05); // Display "error" at x,y |
nbaker | 8:a5c77b45008d | 3744 | wait(3.0); // display for 3 seconds |
nbaker | 8:a5c77b45008d | 3745 | }//end if |
nbaker | 9:d2e39ee9fedd | 3746 | //wait(0.2); // people have had a problem here and needed a delay |
nbaker | 9:d2e39ee9fedd | 3747 | |
nbaker | 8:a5c77b45008d | 3748 | d[0] = 0x2e; //CTRL_REG5 (Int routing reg), write in Standby only |
nbaker | 8:a5c77b45008d | 3749 | d[1] = 0b00000100; // Make FFMT int output on pin INT1(PTC1) and Vector on INT2(PTD13) |
nbaker | 8:a5c77b45008d | 3750 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 9:d2e39ee9fedd | 3751 | oled.Label((uint8_t *)"Acc2j err",30,05); // Display "error" at x,y |
nbaker | 8:a5c77b45008d | 3752 | wait(3.0); // display for 3 seconds |
nbaker | 8:a5c77b45008d | 3753 | }//end if |
nbaker | 8:a5c77b45008d | 3754 | |
nbaker | 9:d2e39ee9fedd | 3755 | d[0] = 0x29; //ASLP_Count (counter used to go to sleep reg), write in Standby only |
nbaker | 9:d2e39ee9fedd | 3756 | d[1] = 0b00001010; // 10*320mS=3.2S of no inturrupts to go to sleep |
nbaker | 9:d2e39ee9fedd | 3757 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 9:d2e39ee9fedd | 3758 | oled.Label((uint8_t *)"Acc2k err",30,05); // Display "error" at x,y |
nbaker | 9:d2e39ee9fedd | 3759 | wait(3.0); // display for 3 seconds |
nbaker | 9:d2e39ee9fedd | 3760 | }//end if |
nbaker | 9:d2e39ee9fedd | 3761 | |
nbaker | 8:a5c77b45008d | 3762 | d[0] = FXOS8700_CTRL_REG1; //CTRL_REG1, write in Standby only except for bit[0] |
nbaker | 8:a5c77b45008d | 3763 | d[1] = 0b00011001; //Auto-Sleep mode on set to 50Hz, ODR set to 100Hz Puts device back into Active mode |
nbaker | 8:a5c77b45008d | 3764 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 9:d2e39ee9fedd | 3765 | oled.Label((uint8_t *)"Acc2L err",30,05); // Display "error" at x,y |
nbaker | 8:a5c77b45008d | 3766 | wait(3.0); // display for 3 seconds |
nbaker | 8:a5c77b45008d | 3767 | }//end if |
nbaker | 8:a5c77b45008d | 3768 | break; |
nbaker | 8:a5c77b45008d | 3769 | }// end of case 2 |
nbaker | 9:d2e39ee9fedd | 3770 | |
nbaker | 9:d2e39ee9fedd | 3771 | case 3: {// configure for motion int only |
nbaker | 8:a5c77b45008d | 3772 | char d[2]; |
nbaker | 9:d2e39ee9fedd | 3773 | d[0] = 0x2a; //0x2a Config reg1 |
nbaker | 9:d2e39ee9fedd | 3774 | d[1] = 0x00; //Put device in Standby mode |
nbaker | 9:d2e39ee9fedd | 3775 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 9:d2e39ee9fedd | 3776 | oled.Label((uint8_t *)"Acc3a err",30,05); // Display "error" at x,y |
nbaker | 9:d2e39ee9fedd | 3777 | wait(3.0); // display for 3 seconds |
nbaker | 9:d2e39ee9fedd | 3778 | }//end if |
nbaker | 8:a5c77b45008d | 3779 | |
nbaker | 9:d2e39ee9fedd | 3780 | d[0] = 0x0e; //XYZ_DATA_CFG (set full-scall range) |
nbaker | 9:d2e39ee9fedd | 3781 | d[1] = 0b00000001; //Set data to default range of +/-2g for full range (2x0.488mg/LSB), High-pass filter off |
nbaker | 9:d2e39ee9fedd | 3782 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 9:d2e39ee9fedd | 3783 | oled.Label((uint8_t *)"Acc3b err",30,05); // Display "error" at x,y |
nbaker | 9:d2e39ee9fedd | 3784 | wait(3.0); // display for 3 seconds |
nbaker | 9:d2e39ee9fedd | 3785 | }//end if |
nbaker | 9:d2e39ee9fedd | 3786 | |
nbaker | 9:d2e39ee9fedd | 3787 | d[0] = 0x2a; //0x2a Config reg1, write in Standby only except for bit[0] |
nbaker | 9:d2e39ee9fedd | 3788 | d[1] = 0b00011001; //Auto-Sleep mode on set to 50Hz, ODR set to 100Hz Puts device back into Active mode |
nbaker | 9:d2e39ee9fedd | 3789 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 9:d2e39ee9fedd | 3790 | oled.Label((uint8_t *)"Acc3c err",30,05); // Display "error" at x,y |
nbaker | 9:d2e39ee9fedd | 3791 | wait(3.0); // display for 3 seconds |
nbaker | 9:d2e39ee9fedd | 3792 | }//end if |
nbaker | 9:d2e39ee9fedd | 3793 | break; |
nbaker | 9:d2e39ee9fedd | 3794 | }// end of case 3 |
nbaker | 9:d2e39ee9fedd | 3795 | |
nbaker | 9:d2e39ee9fedd | 3796 | case 4: {// configure FFMT for free-fall event AND config for vector impact |
nbaker | 9:d2e39ee9fedd | 3797 | char d[2]; |
nbaker | 8:a5c77b45008d | 3798 | d[0] = 0x2a; //0x2a Config reg1, |
nbaker | 8:a5c77b45008d | 3799 | d[1] = 0x00; //Put device in Standby mode |
nbaker | 8:a5c77b45008d | 3800 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 9:d2e39ee9fedd | 3801 | oled.Label((uint8_t *)"Acc4a err",30,05); // Display "error" at x,y |
nbaker | 8:a5c77b45008d | 3802 | wait(3.0); // display for 3 seconds |
nbaker | 8:a5c77b45008d | 3803 | }//end if |
nbaker | 8:a5c77b45008d | 3804 | |
nbaker | 8:a5c77b45008d | 3805 | d[0] = 0x0e; //XYZ_DATA_CFG (set full-scall range) |
nbaker | 8:a5c77b45008d | 3806 | d[1] = 0b00000001; //Set data to +/-4g for full range (0.488mg/LSB), High-pass filter off |
nbaker | 8:a5c77b45008d | 3807 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 9:d2e39ee9fedd | 3808 | oled.Label((uint8_t *)"Acc4b err",30,05); // Display "error" at x,y |
nbaker | 8:a5c77b45008d | 3809 | wait(3.0); // display for 3 seconds |
nbaker | 8:a5c77b45008d | 3810 | }//end if |
nbaker | 8:a5c77b45008d | 3811 | /* |
nbaker | 8:a5c77b45008d | 3812 | d[0] = 0x0a; //TRIG_CFG (address of FIFO trigger config reg) |
nbaker | 8:a5c77b45008d | 3813 | d[1] = 0b00000110; //Trigger on freefall and on Vector |
nbaker | 8:a5c77b45008d | 3814 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 8:a5c77b45008d | 3815 | oled.Label((uint8_t *)" Step2 error ",30,05); // Display "error" at x,y |
nbaker | 8:a5c77b45008d | 3816 | wait(3.0); // display for 3 seconds |
nbaker | 8:a5c77b45008d | 3817 | }//end if |
nbaker | 8:a5c77b45008d | 3818 | */ |
nbaker | 7:3d5a8aea0b63 | 3819 | d[0] = 0x15; //A_FFMT_CFG (address of Free fall trigger config reg), write in Standby only |
nbaker | 7:3d5a8aea0b63 | 3820 | d[1] = 0b00111000; //set to freefall, and look at all axis. |
nbaker | 7:3d5a8aea0b63 | 3821 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 9:d2e39ee9fedd | 3822 | oled.Label((uint8_t *)"Acc4c err",30,05); // Display "error" at x,y |
nbaker | 7:3d5a8aea0b63 | 3823 | wait(3.0); // display for 3 seconds |
nbaker | 7:3d5a8aea0b63 | 3824 | }//end if |
nbaker | 7:3d5a8aea0b63 | 3825 | |
nbaker | 7:3d5a8aea0b63 | 3826 | d[0] = 0x17; //A_FFMT_THS (address of Free fall threshold reg), write in Active or Standby |
nbaker | 9:d2e39ee9fedd | 3827 | // d[1] = 0b00001000; //set freefall threshold to about 756mg for now |
nbaker | 9:d2e39ee9fedd | 3828 | d[1] = (uint8_t)(1000*Fall_Thresh/63); //set freefall threshold - Resolution is 63mg/LSB, 0b111_1111 is maximum value |
nbaker | 7:3d5a8aea0b63 | 3829 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 9:d2e39ee9fedd | 3830 | oled.Label((uint8_t *)"Acc4d err",30,05); // Display "error" at x,y |
nbaker | 7:3d5a8aea0b63 | 3831 | wait(3.0); // display for 3 seconds |
nbaker | 7:3d5a8aea0b63 | 3832 | }//end if |
nbaker | 7:3d5a8aea0b63 | 3833 | |
nbaker | 7:3d5a8aea0b63 | 3834 | d[0] = 0x18; //A_FFMT_COUNT (address of Free fall debounce counter), write in Active or Standby |
nbaker | 7:3d5a8aea0b63 | 3835 | d[1] = 0b00000110; //with ODR at 100Hz, should equal 60mS debounce time or 120mS in Sleep |
nbaker | 7:3d5a8aea0b63 | 3836 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 9:d2e39ee9fedd | 3837 | oled.Label((uint8_t *)"Acc4e err",30,05); // Display "error" at x,y |
nbaker | 7:3d5a8aea0b63 | 3838 | wait(3.0); // display for 3 seconds |
nbaker | 7:3d5a8aea0b63 | 3839 | }//end if |
nbaker | 7:3d5a8aea0b63 | 3840 | |
nbaker | 7:3d5a8aea0b63 | 3841 | d[0] = 0x5f; //A_VECM_CFG (address of Vector config reg), write in Standby only |
nbaker | 7:3d5a8aea0b63 | 3842 | d[1] = 0b00111000; //Use reference values, don't update ref, enable. |
nbaker | 7:3d5a8aea0b63 | 3843 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 9:d2e39ee9fedd | 3844 | oled.Label((uint8_t *)"Acc4f err",30,05); // Display "error" at x,y |
nbaker | 7:3d5a8aea0b63 | 3845 | wait(3.0); // display for 3 seconds |
nbaker | 7:3d5a8aea0b63 | 3846 | }//end if |
nbaker | 7:3d5a8aea0b63 | 3847 | |
nbaker | 7:3d5a8aea0b63 | 3848 | d[0] = 0x60; //A_VECM_MSB (address of Vector threshold reg), write in Active or Standby |
nbaker | 9:d2e39ee9fedd | 3849 | // d[1] = 0b00000111; //set impact threshold to less than 1g for now |
nbaker | 9:d2e39ee9fedd | 3850 | 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 | 3851 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 9:d2e39ee9fedd | 3852 | oled.Label((uint8_t *)"Acc4g err",30,05); // Display "error" at x,y |
nbaker | 7:3d5a8aea0b63 | 3853 | wait(3.0); // display for 3 seconds |
nbaker | 7:3d5a8aea0b63 | 3854 | }//end if |
nbaker | 7:3d5a8aea0b63 | 3855 | |
nbaker | 7:3d5a8aea0b63 | 3856 | d[0] = 0x61; //A_VECM_LSB (address of Vector threshold reg), write in Active or Standby |
nbaker | 9:d2e39ee9fedd | 3857 | // d[1] = 0b00000011; //set impact threshold to less than 1g for now |
nbaker | 9:d2e39ee9fedd | 3858 | d[1] = (uint8_t)(1000*Impact_Thresh/0.488f); |
nbaker | 9:d2e39ee9fedd | 3859 | 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 | 3860 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 9:d2e39ee9fedd | 3861 | oled.Label((uint8_t *)"Acc4h err",30,05); // Display "error" at x,y |
nbaker | 7:3d5a8aea0b63 | 3862 | wait(3.0); // display for 3 seconds |
nbaker | 7:3d5a8aea0b63 | 3863 | }//end if |
nbaker | 7:3d5a8aea0b63 | 3864 | |
nbaker | 7:3d5a8aea0b63 | 3865 | d[0] = 0x62; //A_VECM_COUNT (address of Vector debounce counter), write in Active or Standby |
nbaker | 9:d2e39ee9fedd | 3866 | d[1] = 0b00000100; //with ODR at 100Hz, 0x04 should equal 40mS debounce time or 80mS in 50Hz Sleep |
nbaker | 7:3d5a8aea0b63 | 3867 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 9:d2e39ee9fedd | 3868 | oled.Label((uint8_t *)"Acc4i err",30,05); // Display "error" at x,y |
nbaker | 7:3d5a8aea0b63 | 3869 | wait(3.0); // display for 3 seconds |
nbaker | 7:3d5a8aea0b63 | 3870 | }//end if |
nbaker | 7:3d5a8aea0b63 | 3871 | |
nbaker | 7:3d5a8aea0b63 | 3872 | // Registers 0x63 - 0x68 are vector reference values which I'm leaving set to 0 because we want absolute measurements |
nbaker | 7:3d5a8aea0b63 | 3873 | |
nbaker | 7:3d5a8aea0b63 | 3874 | d[0] = 0x2b; //CTRL_REG2 (address of control reg), write in Standby only |
nbaker | 9:d2e39ee9fedd | 3875 | // d[1] = 0b00001101; //Turns Auto-Sleep mode on and low-noise, low power |
nbaker | 9:d2e39ee9fedd | 3876 | d[1] = 0b00001001; //Turns Auto-Sleep mode off (b/c it wasn't waking on int) and low-noise, low power |
nbaker | 7:3d5a8aea0b63 | 3877 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 9:d2e39ee9fedd | 3878 | oled.Label((uint8_t *)"Acc4jerr",30,05); // Display "error" at x,y |
nbaker | 7:3d5a8aea0b63 | 3879 | wait(3.0); // display for 3 seconds |
nbaker | 7:3d5a8aea0b63 | 3880 | }//end if |
nbaker | 7:3d5a8aea0b63 | 3881 | |
nbaker | 7:3d5a8aea0b63 | 3882 | d[0] = 0x2c; //CTRL_REG3 (address of Int control reg), write in Standby only |
nbaker | 7:3d5a8aea0b63 | 3883 | d[1] = 0b00001100; //FFMT or Vector will wake chip from sleep, int are active high |
nbaker | 7:3d5a8aea0b63 | 3884 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 9:d2e39ee9fedd | 3885 | oled.Label((uint8_t *)"Acc4k err",30,05); // Display "error" at x,y |
nbaker | 7:3d5a8aea0b63 | 3886 | wait(3.0); // display for 3 seconds |
nbaker | 7:3d5a8aea0b63 | 3887 | }//end if |
nbaker | 7:3d5a8aea0b63 | 3888 | |
nbaker | 7:3d5a8aea0b63 | 3889 | d[0] = 0x2d; //CTRL_REG4 (address of Int enable reg), write in Standby only |
nbaker | 9:d2e39ee9fedd | 3890 | d[1] = 0b10000110; // FFMT and Vector int enabled |
nbaker | 7:3d5a8aea0b63 | 3891 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 9:d2e39ee9fedd | 3892 | oled.Label((uint8_t *)"Acc4L err",30,05); // Display "error" at x,y |
nbaker | 7:3d5a8aea0b63 | 3893 | wait(3.0); // display for 3 seconds |
nbaker | 7:3d5a8aea0b63 | 3894 | }//end if |
nbaker | 9:d2e39ee9fedd | 3895 | // wait(0.2); // people have had a problem here and needed a delay |
nbaker | 8:a5c77b45008d | 3896 | |
nbaker | 7:3d5a8aea0b63 | 3897 | d[0] = 0x2e; //CTRL_REG5 (Int routing reg), write in Standby only |
nbaker | 7:3d5a8aea0b63 | 3898 | d[1] = 0b00000100; // Make FFMT int output on pin INT1(PTC1) and Vector on INT2(PTD13) |
nbaker | 7:3d5a8aea0b63 | 3899 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 9:d2e39ee9fedd | 3900 | oled.Label((uint8_t *)"Acc4m err",30,05); // Display "error" at x,y |
nbaker | 9:d2e39ee9fedd | 3901 | wait(3.0); // display for 3 seconds |
nbaker | 9:d2e39ee9fedd | 3902 | }//end if |
nbaker | 9:d2e39ee9fedd | 3903 | |
nbaker | 9:d2e39ee9fedd | 3904 | d[0] = 0x29; //ASLP_Count (counter used to go to sleep reg), write in Standby only |
nbaker | 9:d2e39ee9fedd | 3905 | d[1] = 0b00001010; // 10*320mS=3.2S of no inturrupts to go to sleep |
nbaker | 9:d2e39ee9fedd | 3906 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 9:d2e39ee9fedd | 3907 | oled.Label((uint8_t *)"Acc4n err",30,05); // Display "error" at x,y |
nbaker | 7:3d5a8aea0b63 | 3908 | wait(3.0); // display for 3 seconds |
nbaker | 7:3d5a8aea0b63 | 3909 | }//end if |
nbaker | 7:3d5a8aea0b63 | 3910 | |
nbaker | 8:a5c77b45008d | 3911 | d[0] = 0x2a; //0x2a Config reg1, write in Standby only except for bit[0] |
nbaker | 7:3d5a8aea0b63 | 3912 | d[1] = 0b00011001; //Auto-Sleep mode on set to 50Hz, ODR set to 100Hz Puts device back into Active mode |
nbaker | 7:3d5a8aea0b63 | 3913 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 9:d2e39ee9fedd | 3914 | oled.Label((uint8_t *)"Acc4o err",30,05); // Display "error" at x,y |
nbaker | 7:3d5a8aea0b63 | 3915 | wait(3.0); // display for 3 seconds |
nbaker | 9:d2e39ee9fedd | 3916 | }//end if |
nbaker | 7:3d5a8aea0b63 | 3917 | break; |
nbaker | 9:d2e39ee9fedd | 3918 | }// end of case 4 |
nbaker | 7:3d5a8aea0b63 | 3919 | |
nbaker | 7:3d5a8aea0b63 | 3920 | case 10: {// reset IC |
nbaker | 7:3d5a8aea0b63 | 3921 | char d[2]; |
nbaker | 8:a5c77b45008d | 3922 | d[0] = 0x2a; //0x2a Config reg1 |
nbaker | 8:a5c77b45008d | 3923 | d[1] = 0x00; //Put device in Standby mode |
nbaker | 8:a5c77b45008d | 3924 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 9:d2e39ee9fedd | 3925 | oled.Label((uint8_t *)" Step10a err",30,05); // Display "error" at x,y |
nbaker | 8:a5c77b45008d | 3926 | wait(3.0); // display for 3 seconds |
nbaker | 8:a5c77b45008d | 3927 | }//end if |
nbaker | 8:a5c77b45008d | 3928 | |
nbaker | 7:3d5a8aea0b63 | 3929 | d[0] = 0x2b; //CTRL_REG2 |
nbaker | 7:3d5a8aea0b63 | 3930 | d[1] = 0b01000000; // set bit to force reset of FXOS8700 |
nbaker | 7:3d5a8aea0b63 | 3931 | if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 7:3d5a8aea0b63 | 3932 | oled.Label((uint8_t *)" Reset error ",30,05); // Display "error" at x,y |
nbaker | 7:3d5a8aea0b63 | 3933 | wait(3.0); // display for 3 seconds |
nbaker | 7:3d5a8aea0b63 | 3934 | }//end if |
nbaker | 10:eaea844e763c | 3935 | // oled.Label((uint8_t *)"Acc_Reset",20,60); // Display "reset" at x,y |
nbaker | 7:3d5a8aea0b63 | 3936 | break; |
nbaker | 7:3d5a8aea0b63 | 3937 | }// end case 10 |
nbaker | 7:3d5a8aea0b63 | 3938 | |
nbaker | 9:d2e39ee9fedd | 3939 | case 11: {// wake for simple data read, was in stanby |
nbaker | 8:a5c77b45008d | 3940 | char d[2]; |
nbaker | 8:a5c77b45008d | 3941 | d[0] = FXOS8700_CTRL_REG1; //Puts device in Standby mode just in case |
nbaker | 8:a5c77b45008d | 3942 | d[1] = 0x00; |
nbaker | 8:a5c77b45008d | 3943 | i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2); |
nbaker | 8:a5c77b45008d | 3944 | |
nbaker | 8:a5c77b45008d | 3945 | d[0] = 0x0e; //XYZ_DATA_CFG (set full-scall range) |
nbaker | 8:a5c77b45008d | 3946 | d[1] = 0b00000001; //Set data to +/-4g for full range (0.488mg/LSB), High-pass filter off |
nbaker | 8:a5c77b45008d | 3947 | i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2); |
nbaker | 8:a5c77b45008d | 3948 | |
nbaker | 8:a5c77b45008d | 3949 | /*For lowest power ~8uA, set ODR-12.5Hz,(low-pwr accel mode) or 2uA in standby mode */ |
nbaker | 8:a5c77b45008d | 3950 | d[0] = 0x2a; //0x2a Config reg1, write in Standby only except for bit[0] |
nbaker | 8:a5c77b45008d | 3951 | d[1] = 0b00011001; //Auto-Sleep mode on set to 50Hz, ODR set to 100Hz Puts device back into Active mode |
nbaker | 8:a5c77b45008d | 3952 | i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d, 2); |
nbaker | 8:a5c77b45008d | 3953 | break; |
nbaker | 8:a5c77b45008d | 3954 | }// end of case 11 |
nbaker | 8:a5c77b45008d | 3955 | |
nbaker | 9:d2e39ee9fedd | 3956 | case 12: {// put into standby for low power |
nbaker | 8:a5c77b45008d | 3957 | char d[2]; |
nbaker | 8:a5c77b45008d | 3958 | d[0] = FXOS8700_CTRL_REG1; //Puts device in Standby mode |
nbaker | 8:a5c77b45008d | 3959 | d[1] = 0x00; |
nbaker | 9:d2e39ee9fedd | 3960 | i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d, 2); |
nbaker | 8:a5c77b45008d | 3961 | /*For lowest power ~8uA, set ODR-12.5Hz,(low-pwr accel mode) or 2uA in standby mode */ |
nbaker | 8:a5c77b45008d | 3962 | break; |
nbaker | 8:a5c77b45008d | 3963 | }// end of case 11 |
nbaker | 8:a5c77b45008d | 3964 | |
nbaker | 9:d2e39ee9fedd | 3965 | case 20: {// read INT_Source to clear VECM int, shouldn't have to do this |
nbaker | 9:d2e39ee9fedd | 3966 | // This was not working for me but it was due to me using the wrong FXOS8700_I2C_ADDRESS_ |
nbaker | 9:d2e39ee9fedd | 3967 | char d[2];//, data_byte_[1]; |
nbaker | 9:d2e39ee9fedd | 3968 | d[0] = 0x0c; // 0x0c is INT_Source Reg |
nbaker | 9:d2e39ee9fedd | 3969 | i2c_bus1.write(FXOS8700_I2C_ADDRESS_,d,1,true); // "true" is needed to prevent stop |
nbaker | 9:d2e39ee9fedd | 3970 | wait(0.01); |
nbaker | 9:d2e39ee9fedd | 3971 | if(i2c_bus1.read(FXOS8700_I2C_ADDRESS_,d,1) == 1){ // read Who am I Reg for debug |
nbaker | 9:d2e39ee9fedd | 3972 | sprintf(text_1," INT_Read_Err "); |
nbaker | 9:d2e39ee9fedd | 3973 | oled.Label((uint8_t *)text_1,5,50); // Display error at x,y |
nbaker | 9:d2e39ee9fedd | 3974 | wait(1); // wait 1 seconds |
nbaker | 9:d2e39ee9fedd | 3975 | }//endif |
nbaker | 9:d2e39ee9fedd | 3976 | break; |
nbaker | 9:d2e39ee9fedd | 3977 | }// end of case 20 |
nbaker | 9:d2e39ee9fedd | 3978 | |
nbaker | 9:d2e39ee9fedd | 3979 | case 21: {// read A_FFMT_SRC reg to clear FFMT int, shouldn't have to do this |
nbaker | 9:d2e39ee9fedd | 3980 | // This was not working for me but it was due to me using the wrong FXOS8700_I2C_ADDRESS_ |
nbaker | 9:d2e39ee9fedd | 3981 | char d[2];//, data_byte_[1]; |
nbaker | 9:d2e39ee9fedd | 3982 | d[0] = 0x16; // 0x16 is A_FFMT_SRC Reg |
nbaker | 9:d2e39ee9fedd | 3983 | i2c_bus1.write(FXOS8700_I2C_ADDRESS_,d,1,true); // "true" is needed to prevent stop |
nbaker | 9:d2e39ee9fedd | 3984 | wait(0.01); |
nbaker | 9:d2e39ee9fedd | 3985 | if(i2c_bus1.read(FXOS8700_I2C_ADDRESS_,d,1) == 1){ // read Who am I Reg for debug |
nbaker | 9:d2e39ee9fedd | 3986 | sprintf(text_1," INT_Read_Err "); |
nbaker | 9:d2e39ee9fedd | 3987 | oled.Label((uint8_t *)text_1,5,50); // Display error at x,y |
nbaker | 9:d2e39ee9fedd | 3988 | wait(1); // wait 1 seconds |
nbaker | 9:d2e39ee9fedd | 3989 | }//endif |
nbaker | 9:d2e39ee9fedd | 3990 | break; |
nbaker | 9:d2e39ee9fedd | 3991 | }// end of case 21 |
nbaker | 8:a5c77b45008d | 3992 | |
nbaker | 4:0803151bc5e4 | 3993 | default: { |
nbaker | 9:d2e39ee9fedd | 3994 | oled.Label((uint8_t *)" Mode? ",30,60); // Display "mode" at x,y |
nbaker | 4:0803151bc5e4 | 3995 | // unknown config |
nbaker | 4:0803151bc5e4 | 3996 | break; |
nbaker | 4:0803151bc5e4 | 3997 | } |
nbaker | 4:0803151bc5e4 | 3998 | }// end switch |
nbaker | 4:0803151bc5e4 | 3999 | |
nbaker | 10:eaea844e763c | 4000 | }// end accel_sensor_cconfig |
nbaker | 4:0803151bc5e4 | 4001 | |
nbaker | 8:a5c77b45008d | 4002 | /***************************************************************************** |
nbaker | 9:d2e39ee9fedd | 4003 | Name: gyro_sensor_config() |
nbaker | 9:d2e39ee9fedd | 4004 | Purpose: Used to set gyro IC's internal registers for chip level |
nbaker | 9:d2e39ee9fedd | 4005 | interrupts and power modes |
nbaker | 9:d2e39ee9fedd | 4006 | Inputs: int value from 0 to 256 |
nbaker | 9:d2e39ee9fedd | 4007 | Returns: None |
nbaker | 9:d2e39ee9fedd | 4008 | ******************************************************************************/ |
nbaker | 9:d2e39ee9fedd | 4009 | |
nbaker | 9:d2e39ee9fedd | 4010 | void gyro_sensor_config(uint8_t Num){ |
nbaker | 9:d2e39ee9fedd | 4011 | // use case switches here to configure for |
nbaker | 9:d2e39ee9fedd | 4012 | switch(Num) { |
nbaker | 9:d2e39ee9fedd | 4013 | case 0: {// put in standby |
nbaker | 9:d2e39ee9fedd | 4014 | /*For lowest power ~2.8uA in standby mode */ |
nbaker | 9:d2e39ee9fedd | 4015 | char d[2]; |
nbaker | 9:d2e39ee9fedd | 4016 | d[0] = FXAS21002_CTRL_REG1; //CTRL_REG1=0x13 |
nbaker | 10:eaea844e763c | 4017 | d[1] = 0b00001100; //puts device in standby mode and leaves ODR set to 100Hz |
nbaker | 9:d2e39ee9fedd | 4018 | if(i2c_bus1.write(FXAS21002_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 9:d2e39ee9fedd | 4019 | oled.Label((uint8_t *)"gyr_err0a",20,45); // Display "error" at x,y |
nbaker | 9:d2e39ee9fedd | 4020 | wait(3.0); // display for 3 seconds |
nbaker | 9:d2e39ee9fedd | 4021 | }//end if |
nbaker | 9:d2e39ee9fedd | 4022 | break; |
nbaker | 9:d2e39ee9fedd | 4023 | }// end of case 0 |
nbaker | 9:d2e39ee9fedd | 4024 | |
nbaker | 10:eaea844e763c | 4025 | case 1: {// Fall_Alert mode=1, put in active mode se we can read gyro measurments |
nbaker | 9:d2e39ee9fedd | 4026 | char d[2]; |
nbaker | 9:d2e39ee9fedd | 4027 | d[0] = FXAS21002_CTRL_REG1; //CTRL_REG1=0x13 |
nbaker | 9:d2e39ee9fedd | 4028 | d[1] = 0x00; //Puts device in standby mode |
nbaker | 9:d2e39ee9fedd | 4029 | if(i2c_bus1.write(FXAS21002_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 9:d2e39ee9fedd | 4030 | oled.Label((uint8_t *)"gyr_err1a",20,45); // Display "error" at x,y |
nbaker | 9:d2e39ee9fedd | 4031 | wait(3.0); // display for 3 seconds |
nbaker | 9:d2e39ee9fedd | 4032 | }//end if |
nbaker | 9:d2e39ee9fedd | 4033 | d[0] = FXAS21002_CTRL_REG0; //CTRL_REG0=0x0d |
nbaker | 9:d2e39ee9fedd | 4034 | d[1] = 0x00; //sets FS =+/- 2000 dps |
nbaker | 9:d2e39ee9fedd | 4035 | if(i2c_bus1.write(FXAS21002_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 9:d2e39ee9fedd | 4036 | oled.Label((uint8_t *)"gyr_err1b",20,45); // Display "error" at x,y |
nbaker | 9:d2e39ee9fedd | 4037 | wait(3.0); // display for 3 seconds |
nbaker | 9:d2e39ee9fedd | 4038 | }//end if |
nbaker | 9:d2e39ee9fedd | 4039 | d[0] = FXAS21002_CTRL_REG1; //CTRL_REG1=0x13 |
nbaker | 9:d2e39ee9fedd | 4040 | d[1] = 0x0e; //0x0e puts device in active mode with ODR = 100Hz |
nbaker | 9:d2e39ee9fedd | 4041 | if(i2c_bus1.write(FXAS21002_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 9:d2e39ee9fedd | 4042 | oled.Label((uint8_t *)"gyr_err1c",20,45); // Display "error" at x,y |
nbaker | 9:d2e39ee9fedd | 4043 | wait(3.0); // display for 3 seconds |
nbaker | 9:d2e39ee9fedd | 4044 | }//end if |
nbaker | 9:d2e39ee9fedd | 4045 | break; |
nbaker | 9:d2e39ee9fedd | 4046 | }// end of case 1 |
nbaker | 9:d2e39ee9fedd | 4047 | |
nbaker | 10:eaea844e763c | 4048 | case 3: {// Fall_Alert mode 3, set up interupt, put in active mode |
nbaker | 9:d2e39ee9fedd | 4049 | char d[2]; |
nbaker | 9:d2e39ee9fedd | 4050 | d[0] = FXAS21002_CTRL_REG1; //CTRL_REG1=0x13 |
nbaker | 9:d2e39ee9fedd | 4051 | d[1] = 0x00; //0x08 puts device in standby mode |
nbaker | 9:d2e39ee9fedd | 4052 | if(i2c_bus1.write(FXAS21002_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 9:d2e39ee9fedd | 4053 | oled.Label((uint8_t *)"gyr_err3",20,45); // Display "error" at x,y |
nbaker | 9:d2e39ee9fedd | 4054 | wait(3.0); // display for 3 seconds |
nbaker | 9:d2e39ee9fedd | 4055 | }//end if |
nbaker | 9:d2e39ee9fedd | 4056 | |
nbaker | 9:d2e39ee9fedd | 4057 | // set RT_CFG reg 0x0e - Rate int config |
nbaker | 9:d2e39ee9fedd | 4058 | d[0] = 0x0e; //set RT_CFG reg 0x0e - Rate int config |
nbaker | 9:d2e39ee9fedd | 4059 | d[1] = 0b00000111; // enable x,y,z axis |
nbaker | 9:d2e39ee9fedd | 4060 | if(i2c_bus1.write(FXAS21002_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 9:d2e39ee9fedd | 4061 | oled.Label((uint8_t *)"gyr_err3a",20,45); // Display "error" at x,y |
nbaker | 9:d2e39ee9fedd | 4062 | wait(3.0); // display for 3 seconds |
nbaker | 9:d2e39ee9fedd | 4063 | }//end if |
nbaker | 9:d2e39ee9fedd | 4064 | |
nbaker | 9:d2e39ee9fedd | 4065 | // set RT_THS reg 0x10 - Rate Threshold value |
nbaker | 9:d2e39ee9fedd | 4066 | d[0] = 0x10; //set RT_THS reg 0x10 - Rate Threshold config |
nbaker | 9:d2e39ee9fedd | 4067 | // d[1] = 0b00000111; // bit7=couter mode(1=clr,0=dec), rate Tresh(dps)=(THS+1)*Sensitivity(dps/LSB |
nbaker | 9:d2e39ee9fedd | 4068 | // Sensitivity(dps/LSB), we should have mdps/LSB=62.50 or a full range of +/- 2000 dps |
nbaker | 9:d2e39ee9fedd | 4069 | // Movement_Thresh 50 dps=(THS+1)*256*Sensitivity(dps/LSB) => THS = Movement_Thresh/(16.0f)-1 |
nbaker | 9:d2e39ee9fedd | 4070 | // We specified that 50 dps was the magnitude some of all 3 axis so THS is 1/3 of that |
nbaker | 9:d2e39ee9fedd | 4071 | 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 | 4072 | if(i2c_bus1.write(FXAS21002_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 9:d2e39ee9fedd | 4073 | oled.Label((uint8_t *)"gyr_err3b",20,45); // Display "error" at x,y |
nbaker | 9:d2e39ee9fedd | 4074 | wait(3.0); // display for 3 seconds |
nbaker | 9:d2e39ee9fedd | 4075 | }//end if |
nbaker | 9:d2e39ee9fedd | 4076 | |
nbaker | 9:d2e39ee9fedd | 4077 | // set RT_COUNT reg 0x11 - Rate Threshold counter |
nbaker | 9:d2e39ee9fedd | 4078 | d[0] = 0x11; //set RT_COUNT reg 0x11 - Rate Threshold counter |
nbaker | 9:d2e39ee9fedd | 4079 | // d[1] = 0b10000000; // debounce count value (Count=10, ODR=100Hz => 100mS) |
nbaker | 9:d2e39ee9fedd | 4080 | d[1] = (uint8_t)(Min_Movement_Time/0.01f); // debounce count value (at ODR=100Hz, each count = 10mS) 2.55s=255 |
nbaker | 9:d2e39ee9fedd | 4081 | // need to calculate and store this value |
nbaker | 9:d2e39ee9fedd | 4082 | if(i2c_bus1.write(FXAS21002_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 9:d2e39ee9fedd | 4083 | oled.Label((uint8_t *)"gyr_err3c",20,45); // Display "error" at x,y |
nbaker | 9:d2e39ee9fedd | 4084 | wait(3.0); // display for 3 seconds |
nbaker | 9:d2e39ee9fedd | 4085 | }//end if |
nbaker | 9:d2e39ee9fedd | 4086 | |
nbaker | 9:d2e39ee9fedd | 4087 | // set CTRL_REG2 reg 0x14 - Int config |
nbaker | 9:d2e39ee9fedd | 4088 | d[0] = 0x14; //set CTRL_REG2 reg 0x14 - Int config |
nbaker | 9:d2e39ee9fedd | 4089 | d[1] = 0b01110000; // enable RT &FIFO interupts, int=act_low, push/pull |
nbaker | 9:d2e39ee9fedd | 4090 | if(i2c_bus1.write(FXAS21002_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 9:d2e39ee9fedd | 4091 | oled.Label((uint8_t *)"gyr_err3d",20,45); // Display "error" at x,y |
nbaker | 9:d2e39ee9fedd | 4092 | wait(3.0); // display for 3 seconds |
nbaker | 9:d2e39ee9fedd | 4093 | }//end if |
nbaker | 9:d2e39ee9fedd | 4094 | |
nbaker | 9:d2e39ee9fedd | 4095 | // set CTRL_REG3 reg 0x15 - Auto inc config, external power, FSR <=don't need? |
nbaker | 9:d2e39ee9fedd | 4096 | d[0] = 0x15; //CTRL_REG3 reg 0x15 |
nbaker | 9:d2e39ee9fedd | 4097 | d[1] = 0x00; //Auto inc config, external power, FSR |
nbaker | 9:d2e39ee9fedd | 4098 | if(i2c_bus1.write(FXAS21002_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 9:d2e39ee9fedd | 4099 | oled.Label((uint8_t *)"gyr_err3e",20,45); // Display "error" at x,y |
nbaker | 9:d2e39ee9fedd | 4100 | wait(3.0); // display for 3 seconds |
nbaker | 9:d2e39ee9fedd | 4101 | }//end if |
nbaker | 9:d2e39ee9fedd | 4102 | |
nbaker | 9:d2e39ee9fedd | 4103 | d[0] = FXAS21002_CTRL_REG0; //CTRL_REG0=0x0d |
nbaker | 9:d2e39ee9fedd | 4104 | d[1] = 0x00; //sets FS=0,mdps/LSB=62.50 => +/- 2000 dps |
nbaker | 9:d2e39ee9fedd | 4105 | if(i2c_bus1.write(FXAS21002_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 9:d2e39ee9fedd | 4106 | oled.Label((uint8_t *)"gyr_err3f",20,45); // Display "error" at x,y |
nbaker | 9:d2e39ee9fedd | 4107 | wait(3.0); // display for 3 seconds |
nbaker | 9:d2e39ee9fedd | 4108 | }//end if |
nbaker | 9:d2e39ee9fedd | 4109 | d[0] = FXAS21002_CTRL_REG1; //CTRL_REG1 0x13 - Op mode, ODR selection, reset |
nbaker | 9:d2e39ee9fedd | 4110 | d[1] = 0b00001110; //0x0e puts device in active mode and sets ODR to 100Hz |
nbaker | 9:d2e39ee9fedd | 4111 | if(i2c_bus1.write(FXAS21002_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 9:d2e39ee9fedd | 4112 | oled.Label((uint8_t *)"gyr_err3g",20,45); // Display "error" at x,y |
nbaker | 9:d2e39ee9fedd | 4113 | wait(3.0); // display for 3 seconds |
nbaker | 9:d2e39ee9fedd | 4114 | }//end if |
nbaker | 9:d2e39ee9fedd | 4115 | break; |
nbaker | 10:eaea844e763c | 4116 | }// end of case 3 |
nbaker | 9:d2e39ee9fedd | 4117 | |
nbaker | 9:d2e39ee9fedd | 4118 | case 10: {// reset Gyro IC |
nbaker | 9:d2e39ee9fedd | 4119 | char d[2]; |
nbaker | 9:d2e39ee9fedd | 4120 | d[0] = FXAS21002_CTRL_REG1; //CTRL_REG1 0x13 - Op mode, ODR selection, reset |
nbaker | 9:d2e39ee9fedd | 4121 | d[1] = 0b01000000; //resets IC |
nbaker | 9:d2e39ee9fedd | 4122 | if(i2c_bus1.write(FXAS21002_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 9:d2e39ee9fedd | 4123 | oled.Label((uint8_t *)"gyr_err10a",20,45); // Display "error" at x,y |
nbaker | 9:d2e39ee9fedd | 4124 | wait(3.0); // display for 3 seconds |
nbaker | 9:d2e39ee9fedd | 4125 | }//end if |
nbaker | 10:eaea844e763c | 4126 | // oled.Label((uint8_t *)"G_Reset ",30,45); // Display "reset" at x,y |
nbaker | 9:d2e39ee9fedd | 4127 | break; |
nbaker | 9:d2e39ee9fedd | 4128 | }// end case 10 |
nbaker | 9:d2e39ee9fedd | 4129 | |
nbaker | 10:eaea844e763c | 4130 | case 11: {// set sensor to active to read gyro measurments |
nbaker | 9:d2e39ee9fedd | 4131 | char d[2]; |
nbaker | 9:d2e39ee9fedd | 4132 | d[0] = FXAS21002_CTRL_REG1; //CTRL_REG1=0x13 |
nbaker | 10:eaea844e763c | 4133 | d[1] = 0b00001110; //0x0e puts device in active mode with ODR = 100Hz |
nbaker | 9:d2e39ee9fedd | 4134 | if(i2c_bus1.write(FXAS21002_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 9:d2e39ee9fedd | 4135 | oled.Label((uint8_t *)"gyr_err11a",20,45); // Display "error" at x,y |
nbaker | 9:d2e39ee9fedd | 4136 | wait(3.0); // display for 3 seconds |
nbaker | 9:d2e39ee9fedd | 4137 | }//end if |
nbaker | 9:d2e39ee9fedd | 4138 | break; |
nbaker | 9:d2e39ee9fedd | 4139 | }// end of case 11 |
nbaker | 9:d2e39ee9fedd | 4140 | |
nbaker | 9:d2e39ee9fedd | 4141 | case 12: {// put in standby |
nbaker | 9:d2e39ee9fedd | 4142 | /*For lowest power ~2.8uA in standby mode */ |
nbaker | 9:d2e39ee9fedd | 4143 | char d[2]; |
nbaker | 9:d2e39ee9fedd | 4144 | d[0] = FXAS21002_CTRL_REG1; //CTRL_REG1=0x13 |
nbaker | 10:eaea844e763c | 4145 | d[1] = 0b00001100; //puts device in standby mode and leaves ODR set to 100Hz |
nbaker | 9:d2e39ee9fedd | 4146 | if(i2c_bus1.write(FXAS21002_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 9:d2e39ee9fedd | 4147 | oled.Label((uint8_t *)"gyr_err12a",20,45); // Display "error" at x,y |
nbaker | 9:d2e39ee9fedd | 4148 | wait(3.0); // display for 3 seconds |
nbaker | 9:d2e39ee9fedd | 4149 | }//end if |
nbaker | 9:d2e39ee9fedd | 4150 | break; |
nbaker | 9:d2e39ee9fedd | 4151 | }// end of case 12 |
nbaker | 10:eaea844e763c | 4152 | |
nbaker | 10:eaea844e763c | 4153 | case 13: {// put in standby then back to active, to clear counter |
nbaker | 10:eaea844e763c | 4154 | /*For lowest power ~2.8uA in standby mode */ |
nbaker | 10:eaea844e763c | 4155 | char d[2]; |
nbaker | 10:eaea844e763c | 4156 | d[0] = FXAS21002_CTRL_REG1; //CTRL_REG1=0x13 |
nbaker | 10:eaea844e763c | 4157 | d[1] = 0b00001100; //puts device in standby mode and leaves ODR set to 100Hz |
nbaker | 10:eaea844e763c | 4158 | if(i2c_bus1.write(FXAS21002_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 10:eaea844e763c | 4159 | oled.Label((uint8_t *)"gyr_err12a",20,45); // Display "error" at x,y |
nbaker | 10:eaea844e763c | 4160 | wait(3.0); // display for 3 seconds |
nbaker | 10:eaea844e763c | 4161 | }//end if |
nbaker | 10:eaea844e763c | 4162 | d[1] = 0b00001110; //0x0e puts device in active mode with ODR = 100Hz |
nbaker | 10:eaea844e763c | 4163 | if(i2c_bus1.write(FXAS21002_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 10:eaea844e763c | 4164 | oled.Label((uint8_t *)"gyr_err11a",20,45); // Display "error" at x,y |
nbaker | 10:eaea844e763c | 4165 | wait(3.0); // display for 3 seconds |
nbaker | 10:eaea844e763c | 4166 | }//end if |
nbaker | 10:eaea844e763c | 4167 | |
nbaker | 10:eaea844e763c | 4168 | break; |
nbaker | 10:eaea844e763c | 4169 | }// end of case 13 |
nbaker | 9:d2e39ee9fedd | 4170 | |
nbaker | 9:d2e39ee9fedd | 4171 | default: { |
nbaker | 9:d2e39ee9fedd | 4172 | oled.Label((uint8_t *)"Gyro_Mode?",20,45); // Display "mode" at x,y |
nbaker | 9:d2e39ee9fedd | 4173 | // unknown config |
nbaker | 9:d2e39ee9fedd | 4174 | break; |
nbaker | 9:d2e39ee9fedd | 4175 | } |
nbaker | 9:d2e39ee9fedd | 4176 | }// end switch |
nbaker | 9:d2e39ee9fedd | 4177 | }// end gyro_sensor_config |
nbaker | 9:d2e39ee9fedd | 4178 | |
nbaker | 9:d2e39ee9fedd | 4179 | /***************************************************************************** |
nbaker | 9:d2e39ee9fedd | 4180 | Name: press_config() |
nbaker | 9:d2e39ee9fedd | 4181 | Purpose: Used to set pressure sensor's internal registers for power modes |
nbaker | 9:d2e39ee9fedd | 4182 | Inputs: int value from 0 to 256 |
nbaker | 9:d2e39ee9fedd | 4183 | Returns: None |
nbaker | 9:d2e39ee9fedd | 4184 | ******************************************************************************/ |
nbaker | 9:d2e39ee9fedd | 4185 | |
nbaker | 9:d2e39ee9fedd | 4186 | void press_config(uint8_t Num){ |
nbaker | 9:d2e39ee9fedd | 4187 | // use case switches here to configure |
nbaker | 9:d2e39ee9fedd | 4188 | switch(Num) { |
nbaker | 9:d2e39ee9fedd | 4189 | case 0: {// put in standby (AKA powered down) mode |
nbaker | 9:d2e39ee9fedd | 4190 | //For lowest power ~2.8uA in standby mode, sensor should default to this after reset |
nbaker | 9:d2e39ee9fedd | 4191 | char d[2]; |
nbaker | 9:d2e39ee9fedd | 4192 | d[0] = 0x26; //CTRL_REG1=0x26 |
nbaker | 9:d2e39ee9fedd | 4193 | d[1] = 0x00; //Puts device in powered down mode |
nbaker | 9:d2e39ee9fedd | 4194 | if(i2c_bus1.write(0xC0, d,2) ==1){ // 0xc0 is MPL3115A2 address |
nbaker | 9:d2e39ee9fedd | 4195 | oled.Label((uint8_t *)"press_err0a",20,30); // Display "error" at x,y |
nbaker | 9:d2e39ee9fedd | 4196 | wait(3.0); // display for 3 seconds |
nbaker | 9:d2e39ee9fedd | 4197 | }//end if |
nbaker | 9:d2e39ee9fedd | 4198 | break; |
nbaker | 9:d2e39ee9fedd | 4199 | }// end of case 0 |
nbaker | 9:d2e39ee9fedd | 4200 | |
nbaker | 9:d2e39ee9fedd | 4201 | default: { |
nbaker | 9:d2e39ee9fedd | 4202 | oled.Label((uint8_t *)"PRESS_Mode?",20,45); // Display "mode" at x,y |
nbaker | 9:d2e39ee9fedd | 4203 | // unknown config |
nbaker | 9:d2e39ee9fedd | 4204 | break; |
nbaker | 9:d2e39ee9fedd | 4205 | } |
nbaker | 9:d2e39ee9fedd | 4206 | }// end switch |
nbaker | 9:d2e39ee9fedd | 4207 | }// end press_config |
nbaker | 9:d2e39ee9fedd | 4208 | |
nbaker | 9:d2e39ee9fedd | 4209 | /***************************************************************************** |
nbaker | 9:d2e39ee9fedd | 4210 | Name: MAX30101_test_config() |
nbaker | 9:d2e39ee9fedd | 4211 | Purpose: Used to test operation of the MAX30101 heart-rate sensor |
nbaker | 9:d2e39ee9fedd | 4212 | Inputs: int value from 0 to 256 |
nbaker | 9:d2e39ee9fedd | 4213 | Returns: None |
nbaker | 9:d2e39ee9fedd | 4214 | ******************************************************************************/ |
nbaker | 9:d2e39ee9fedd | 4215 | void MAX30101_test_config(uint8_t Num){ |
nbaker | 9:d2e39ee9fedd | 4216 | // use case switches here to configure |
nbaker | 9:d2e39ee9fedd | 4217 | switch(Num) { |
nbaker | 9:d2e39ee9fedd | 4218 | case 0: {// test |
nbaker | 9:d2e39ee9fedd | 4219 | char d[2] = {0xfe, 0x07}; |
nbaker | 9:d2e39ee9fedd | 4220 | if(i2c_bus0.read(0xae, d, 2) == 1){ // read RevID value 0-255 |
nbaker | 9:d2e39ee9fedd | 4221 | sprintf(text_1,"M_R_Er %i %i",d[0],d[1]); |
nbaker | 9:d2e39ee9fedd | 4222 | oled.Label((uint8_t *)text_1,5,16); // Display error at x,y |
nbaker | 9:d2e39ee9fedd | 4223 | }//end if |
nbaker | 9:d2e39ee9fedd | 4224 | else{ |
nbaker | 9:d2e39ee9fedd | 4225 | sprintf(text_1,"M_R_data %i %i",d[0],d[1]); |
nbaker | 9:d2e39ee9fedd | 4226 | oled.Label((uint8_t *)text_1,5,16); // Display good data at x,y |
nbaker | 9:d2e39ee9fedd | 4227 | } |
nbaker | 9:d2e39ee9fedd | 4228 | wait(1); // wait 1 seconds |
nbaker | 9:d2e39ee9fedd | 4229 | d[0] = 0x09; // Mod_conf reg - SHDN, reset, modes |
nbaker | 9:d2e39ee9fedd | 4230 | d[1] = 0b00000111; // set mode to red, green and/or IR LEDs |
nbaker | 9:d2e39ee9fedd | 4231 | if(i2c_bus0.write(0xaf, d, 1) ==1){; // "true" is needed to prevent stop, MAX30101 address is 0xae but left shifted |
nbaker | 9:d2e39ee9fedd | 4232 | oled.Label((uint8_t *)"MAX_W_err0a",5,30); // Display "error" at x,y |
nbaker | 9:d2e39ee9fedd | 4233 | wait(3.0); // display for 3 seconds |
nbaker | 9:d2e39ee9fedd | 4234 | }//end if |
nbaker | 9:d2e39ee9fedd | 4235 | wait(5); // wait 5 seconds |
nbaker | 9:d2e39ee9fedd | 4236 | |
nbaker | 9:d2e39ee9fedd | 4237 | /* |
nbaker | 9:d2e39ee9fedd | 4238 | d[0] = 0xfe; //lets try to read revID value 0-255 |
nbaker | 9:d2e39ee9fedd | 4239 | d[1] = 0x00; //Puts device in powered down mode |
nbaker | 9:d2e39ee9fedd | 4240 | if(i2c_bus0.write(0xae<<1, d,2) ==1){ // MAX30101 address is 0xae but left shifted |
nbaker | 9:d2e39ee9fedd | 4241 | oled.Label((uint8_t *)"Max_err0a",20,30); // Display "error" at x,y |
nbaker | 9:d2e39ee9fedd | 4242 | wait(3.0); // display for 3 seconds |
nbaker | 9:d2e39ee9fedd | 4243 | }//end if |
nbaker | 9:d2e39ee9fedd | 4244 | */ |
nbaker | 9:d2e39ee9fedd | 4245 | break; |
nbaker | 9:d2e39ee9fedd | 4246 | }// end of case 0 |
nbaker | 9:d2e39ee9fedd | 4247 | |
nbaker | 9:d2e39ee9fedd | 4248 | |
nbaker | 9:d2e39ee9fedd | 4249 | case 10: {// reset |
asong | 14:c3b080cdf36b | 4250 | if(maxim == 0) |
asong | 14:c3b080cdf36b | 4251 | { |
nbaker | 9:d2e39ee9fedd | 4252 | } |
asong | 14:c3b080cdf36b | 4253 | else |
asong | 14:c3b080cdf36b | 4254 | { |
asong | 14:c3b080cdf36b | 4255 | char d[2]; |
asong | 14:c3b080cdf36b | 4256 | d[0] = 0x09; // Mod_conf reg - SHDN, reset, modes |
asong | 14:c3b080cdf36b | 4257 | d[1] = 0b01000000; //resets IC |
asong | 14:c3b080cdf36b | 4258 | if(i2c_bus0.write(0xaf, d, 2) ==1){ |
asong | 14:c3b080cdf36b | 4259 | oled.Label((uint8_t *)"MAX_W_Err10a",5,1); // Display "error" at x,y |
asong | 14:c3b080cdf36b | 4260 | wait(2.0); // wait 0 seconds |
asong | 14:c3b080cdf36b | 4261 | }//end if |
asong | 14:c3b080cdf36b | 4262 | else { |
asong | 14:c3b080cdf36b | 4263 | // oled.Label((uint8_t *)"MAX_Reset",20,30); // Display "reset" at x,y |
asong | 14:c3b080cdf36b | 4264 | } |
asong | 14:c3b080cdf36b | 4265 | wait(0.01); // wait 0.01 seconds |
asong | 14:c3b080cdf36b | 4266 | } |
nbaker | 9:d2e39ee9fedd | 4267 | break; |
nbaker | 9:d2e39ee9fedd | 4268 | }// end of case 10 |
nbaker | 9:d2e39ee9fedd | 4269 | |
nbaker | 9:d2e39ee9fedd | 4270 | default: { |
nbaker | 9:d2e39ee9fedd | 4271 | oled.Label((uint8_t *)"MAX_Mode?",20,45); // Display "mode" at x,y |
nbaker | 9:d2e39ee9fedd | 4272 | // unknown config |
nbaker | 9:d2e39ee9fedd | 4273 | break; |
nbaker | 9:d2e39ee9fedd | 4274 | } |
nbaker | 9:d2e39ee9fedd | 4275 | }// end switch |
nbaker | 9:d2e39ee9fedd | 4276 | }// end light_config |
nbaker | 9:d2e39ee9fedd | 4277 | |
nbaker | 9:d2e39ee9fedd | 4278 | /***************************************************************************** |
nbaker | 9:d2e39ee9fedd | 4279 | Name: light_config() |
nbaker | 9:d2e39ee9fedd | 4280 | Purpose: Used to set ambient light sensor's internal registers for power modes |
nbaker | 9:d2e39ee9fedd | 4281 | Inputs: int value from 0 to 256 |
nbaker | 9:d2e39ee9fedd | 4282 | Returns: None |
nbaker | 9:d2e39ee9fedd | 4283 | ******************************************************************************/ |
nbaker | 9:d2e39ee9fedd | 4284 | /* |
nbaker | 9:d2e39ee9fedd | 4285 | void light_config(uint8_t Num){ |
nbaker | 9:d2e39ee9fedd | 4286 | // use case switches here to configure |
nbaker | 9:d2e39ee9fedd | 4287 | switch(Num) { |
nbaker | 9:d2e39ee9fedd | 4288 | case 0: {// put in standby (AKA powered down) mode |
nbaker | 9:d2e39ee9fedd | 4289 | //For lowest power ~2.8uA in standby mode, sensor should default to this after reset |
nbaker | 9:d2e39ee9fedd | 4290 | char d[2]; |
nbaker | 9:d2e39ee9fedd | 4291 | d[0] = TSL2561_CONTROL; //CTRL_REG0=0x00 |
nbaker | 9:d2e39ee9fedd | 4292 | d[1] = 0x00; //Puts device in powered down mode |
nbaker | 9:d2e39ee9fedd | 4293 | if(i2c_bus0.write(TSL2561_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 9:d2e39ee9fedd | 4294 | oled.Label((uint8_t *)"light_err0a",20,30); // Display "error" at x,y |
nbaker | 9:d2e39ee9fedd | 4295 | wait(3.0); // display for 3 seconds |
nbaker | 9:d2e39ee9fedd | 4296 | }//end if |
nbaker | 9:d2e39ee9fedd | 4297 | break; |
nbaker | 9:d2e39ee9fedd | 4298 | }// end of case 0 |
nbaker | 9:d2e39ee9fedd | 4299 | |
nbaker | 9:d2e39ee9fedd | 4300 | case 1: {// put in active |
nbaker | 9:d2e39ee9fedd | 4301 | char d[2]; |
nbaker | 9:d2e39ee9fedd | 4302 | d[0] = TSL2561_CONTROL; //CTRL_REG=0x00 |
nbaker | 9:d2e39ee9fedd | 4303 | d[1] = 0x03; //Puts device in powered up mode |
nbaker | 9:d2e39ee9fedd | 4304 | if(i2c_bus0.write(TSL2561_I2C_ADDRESS_, d,2) ==1){ |
nbaker | 9:d2e39ee9fedd | 4305 | oled.Label((uint8_t *)"light_err0a",20,30); // Display "error" at x,y |
nbaker | 9:d2e39ee9fedd | 4306 | wait(3.0); // display for 3 seconds |
nbaker | 9:d2e39ee9fedd | 4307 | }//end if |
nbaker | 9:d2e39ee9fedd | 4308 | break; |
nbaker | 9:d2e39ee9fedd | 4309 | }// end of case 1 |
nbaker | 9:d2e39ee9fedd | 4310 | |
nbaker | 9:d2e39ee9fedd | 4311 | default: { |
nbaker | 9:d2e39ee9fedd | 4312 | oled.Label((uint8_t *)"LGHT_Mode?",20,45); // Display "mode" at x,y |
nbaker | 9:d2e39ee9fedd | 4313 | // unknown config |
nbaker | 9:d2e39ee9fedd | 4314 | break; |
nbaker | 9:d2e39ee9fedd | 4315 | } |
nbaker | 9:d2e39ee9fedd | 4316 | }// end switch |
nbaker | 9:d2e39ee9fedd | 4317 | }// end light_config |
nbaker | 9:d2e39ee9fedd | 4318 | */ |
nbaker | 9:d2e39ee9fedd | 4319 | |
nbaker | 9:d2e39ee9fedd | 4320 | /***************************************************************************** |
nbaker | 8:a5c77b45008d | 4321 | Name: update_display_date |
nbaker | 8:a5c77b45008d | 4322 | Purpose: Updating display data without updating any data labels. This keeps |
nbaker | 8:a5c77b45008d | 4323 | measurements and time values current while reducing screen flicker. |
nbaker | 8:a5c77b45008d | 4324 | ******************************************************************************/ |
nbaker | 8:a5c77b45008d | 4325 | void update_display_date(void) |
nbaker | 8:a5c77b45008d | 4326 | { |
nbaker | 8:a5c77b45008d | 4327 | oled_text_properties_t textProperties = {0}; // Need these to change font color |
nbaker | 8:a5c77b45008d | 4328 | oled.GetTextProperties(&textProperties); // Need these to change font color |
nbaker | 8:a5c77b45008d | 4329 | __disable_irq(); // Disable all Interrupts |
nbaker | 8:a5c77b45008d | 4330 | |
nbaker | 8:a5c77b45008d | 4331 | switch(Screen_Num) { |
nbaker | 8:a5c77b45008d | 4332 | case 0: {// Main Screen |
nbaker | 8:a5c77b45008d | 4333 | HexiwearBattery battery; |
nbaker | 8:a5c77b45008d | 4334 | battery.sensorOn(); |
nbaker | 8:a5c77b45008d | 4335 | if (battery.isBatteryCharging()) { |
nbaker | 8:a5c77b45008d | 4336 | textProperties.fontColor = COLOR_GREEN; |
nbaker | 8:a5c77b45008d | 4337 | oled.SetTextProperties(&textProperties); |
nbaker | 8:a5c77b45008d | 4338 | |
nbaker | 13:37cd579208e9 | 4339 | sprintf(text_1, "%i%%+", batt_per_level); |
nbaker | 8:a5c77b45008d | 4340 | // Screen_Timer.attach(&timout_timer,(SCRN_TIME));// Reset/restart ticker timer for OLED while fully charged |
nbaker | 8:a5c77b45008d | 4341 | } else { |
nbaker | 13:37cd579208e9 | 4342 | sprintf(text_1, "%i%%", batt_per_level); |
nbaker | 8:a5c77b45008d | 4343 | } |
nbaker | 8:a5c77b45008d | 4344 | 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 | 4345 | |
nbaker | 8:a5c77b45008d | 4346 | textProperties.fontColor = COLOR_WHITE; |
nbaker | 8:a5c77b45008d | 4347 | oled.SetTextProperties(&textProperties); |
nbaker | 8:a5c77b45008d | 4348 | |
nbaker | 8:a5c77b45008d | 4349 | // added real time and date information |
nbaker | 8:a5c77b45008d | 4350 | char buffer[32]; |
nbaker | 8:a5c77b45008d | 4351 | time_t seconds = time(NULL); |
nbaker | 8:a5c77b45008d | 4352 | strftime(buffer,32, "%a,%d %m %Y.%H:%M:%S\r", localtime(&seconds)); |
nbaker | 8:a5c77b45008d | 4353 | // 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 | 4354 | // oled.Label((uint8_t *)text_1,20,20);// Date at x,y |
nbaker | 8:a5c77b45008d | 4355 | sprintf(text_1,"%c%c:%c%c:%c%c ",buffer[15],buffer[16],buffer[18],buffer[19],buffer[21],buffer[22]); |
nbaker | 9:d2e39ee9fedd | 4356 | |
nbaker | 9:d2e39ee9fedd | 4357 | |
nbaker | 9:d2e39ee9fedd | 4358 | textProperties.font = OpenSans_12x18_Regular; // Max Width of Character = 12px, Max Height of Character = 18px |
nbaker | 9:d2e39ee9fedd | 4359 | textProperties.fontColor = COLOR_WHITE; |
nbaker | 9:d2e39ee9fedd | 4360 | oled.SetTextProperties(&textProperties); |
nbaker | 8:a5c77b45008d | 4361 | oled.Label((uint8_t *)text_1,25,40);// Time at x,y |
nbaker | 9:d2e39ee9fedd | 4362 | textProperties.font = OpenSans_10x15_Regular; // Max Width of Character = 10px, Max Height of Character = 15px |
nbaker | 9:d2e39ee9fedd | 4363 | textProperties.fontColor = COLOR_WHITE; |
nbaker | 9:d2e39ee9fedd | 4364 | oled.SetTextProperties(&textProperties); |
nbaker | 9:d2e39ee9fedd | 4365 | |
nbaker | 8:a5c77b45008d | 4366 | Heat_Index_Calculation(); |
nbaker | 8:a5c77b45008d | 4367 | sprintf(text,"%i",heat_index); |
asong | 15:330794a9f347 | 4368 | //oled.TextBox((uint8_t *)text,3,80,15,15); //show HI in a 15px by 15px text box at x=3, y=80 |
asong | 15:330794a9f347 | 4369 | oled.Label((uint8_t *)text,3,80);// HI at x,y |
asong | 15:330794a9f347 | 4370 | |
nbaker | 10:eaea844e763c | 4371 | textProperties.fontColor = COLOR_GRAY; |
nbaker | 10:eaea844e763c | 4372 | if(Fall_Alert == 1){ |
nbaker | 10:eaea844e763c | 4373 | textProperties.fontColor = COLOR_GREEN; // is Fall protection on? |
nbaker | 10:eaea844e763c | 4374 | } |
nbaker | 10:eaea844e763c | 4375 | if(Fall_Alert == 1 && Led_clk1 == 1){ |
nbaker | 10:eaea844e763c | 4376 | textProperties.fontColor = COLOR_YELLOW; // is Fall detected? |
nbaker | 10:eaea844e763c | 4377 | } |
nbaker | 10:eaea844e763c | 4378 | if(Fall_Alert == 1 && Led_clk1 == 1 && Led_clk2 == 1){ |
nbaker | 10:eaea844e763c | 4379 | textProperties.fontColor = COLOR_RED; // is impact detected? |
nbaker | 10:eaea844e763c | 4380 | } |
nbaker | 10:eaea844e763c | 4381 | oled.SetTextProperties(&textProperties); |
asong | 17:746dc1b7b218 | 4382 | oled.Label((uint8_t *)"AFP",3,0); //Display "AFP" at x,y |
nbaker | 10:eaea844e763c | 4383 | textProperties.fontColor = COLOR_WHITE; |
nbaker | 10:eaea844e763c | 4384 | oled.SetTextProperties(&textProperties); |
asong | 20:990951205fbd | 4385 | if(Heart_Rate_Mode == 1) { |
asong | 21:76237b62466b | 4386 | sprintf(text,"%i ",Heart_Rate); |
asong | 20:990951205fbd | 4387 | if(Current_Zone == 1) { |
asong | 20:990951205fbd | 4388 | textProperties.fontColor = COLOR_YELLOW; |
asong | 20:990951205fbd | 4389 | oled.SetTextProperties(&textProperties); |
asong | 20:990951205fbd | 4390 | } else if(Current_Zone == 2) { |
asong | 20:990951205fbd | 4391 | textProperties.fontColor = COLOR_BLUE; |
asong | 20:990951205fbd | 4392 | oled.SetTextProperties(&textProperties); |
asong | 20:990951205fbd | 4393 | } else if(Current_Zone == 3) { |
asong | 20:990951205fbd | 4394 | textProperties.fontColor = COLOR_GREEN; |
asong | 20:990951205fbd | 4395 | oled.SetTextProperties(&textProperties); |
asong | 20:990951205fbd | 4396 | } else if(Current_Zone == 4) { |
asong | 20:990951205fbd | 4397 | textProperties.fontColor = COLOR_RED; |
asong | 20:990951205fbd | 4398 | oled.SetTextProperties(&textProperties); |
asong | 20:990951205fbd | 4399 | } |
asong | 20:990951205fbd | 4400 | oled.Label((uint8_t *)text,35,60); |
asong | 20:990951205fbd | 4401 | textProperties.fontColor = COLOR_WHITE; |
asong | 20:990951205fbd | 4402 | oled.SetTextProperties(&textProperties); |
asong | 20:990951205fbd | 4403 | |
asong | 20:990951205fbd | 4404 | } |
nbaker | 10:eaea844e763c | 4405 | |
nbaker | 8:a5c77b45008d | 4406 | break; |
nbaker | 8:a5c77b45008d | 4407 | }// end case 0 |
nbaker | 16:537ef0c72084 | 4408 | |
nbaker | 16:537ef0c72084 | 4409 | case 7: {// Heart Rate Zone |
nbaker | 16:537ef0c72084 | 4410 | textProperties.fontColor = COLOR_WHITE; |
nbaker | 16:537ef0c72084 | 4411 | oled.SetTextProperties(&textProperties); |
asong | 21:76237b62466b | 4412 | sprintf(display_buff, "%u ", Heart_Rate); |
asong | 21:76237b62466b | 4413 | if(Current_Zone == 1) { |
asong | 21:76237b62466b | 4414 | textProperties.fontColor = COLOR_YELLOW; |
asong | 21:76237b62466b | 4415 | oled.SetTextProperties(&textProperties); |
asong | 21:76237b62466b | 4416 | } else if(Current_Zone == 2) { |
asong | 21:76237b62466b | 4417 | textProperties.fontColor = COLOR_BLUE; |
asong | 21:76237b62466b | 4418 | oled.SetTextProperties(&textProperties); |
asong | 21:76237b62466b | 4419 | } else if(Current_Zone == 3) { |
asong | 21:76237b62466b | 4420 | textProperties.fontColor = COLOR_GREEN; |
asong | 21:76237b62466b | 4421 | oled.SetTextProperties(&textProperties); |
asong | 21:76237b62466b | 4422 | } else if(Current_Zone == 4) { |
asong | 21:76237b62466b | 4423 | textProperties.fontColor = COLOR_RED; |
asong | 21:76237b62466b | 4424 | oled.SetTextProperties(&textProperties); |
asong | 21:76237b62466b | 4425 | } |
nbaker | 16:537ef0c72084 | 4426 | oled.Label((uint8_t *)display_buff,43,25); // Display at x,y |
nbaker | 16:537ef0c72084 | 4427 | textProperties.fontColor = COLOR_GREEN; |
nbaker | 16:537ef0c72084 | 4428 | oled.SetTextProperties(&textProperties); //implements the color change |
nbaker | 16:537ef0c72084 | 4429 | sprintf(display_buff, "%u", Age); //Convert int to char array for displaying user age |
nbaker | 16:537ef0c72084 | 4430 | oled.Label((uint8_t *)display_buff,43,45); // Display at x,y |
nbaker | 16:537ef0c72084 | 4431 | textProperties.fontColor = COLOR_WHITE; |
nbaker | 16:537ef0c72084 | 4432 | oled.SetTextProperties(&textProperties); |
nbaker | 16:537ef0c72084 | 4433 | |
nbaker | 16:537ef0c72084 | 4434 | break; |
nbaker | 16:537ef0c72084 | 4435 | }// end case 7 |
nbaker | 8:a5c77b45008d | 4436 | |
nbaker | 8:a5c77b45008d | 4437 | case 21: {// Fall Alert Diagnostic Screen |
nbaker | 8:a5c77b45008d | 4438 | if(Fall_Alert_Mode == 0){ |
nbaker | 9:d2e39ee9fedd | 4439 | fall_config(11); // turn accel sensor to active mode to take a reading, may take 80mS to 300mS |
nbaker | 8:a5c77b45008d | 4440 | } |
nbaker | 8:a5c77b45008d | 4441 | textProperties.fontColor = COLOR_WHITE; |
nbaker | 8:a5c77b45008d | 4442 | oled.SetTextProperties(&textProperties); |
nbaker | 8:a5c77b45008d | 4443 | gyro.acquire_gyro_data_dps(Gyro_Data); |
nbaker | 8:a5c77b45008d | 4444 | Gyro_Mag = (abs(Gyro_Data[0])+abs(Gyro_Data[1])+abs(Gyro_Data[2])); |
nbaker | 8:a5c77b45008d | 4445 | sprintf(text_1," %4.0f D/S ",Gyro_Mag); |
nbaker | 9:d2e39ee9fedd | 4446 | oled.Label((uint8_t *)text_1,37,60);// text_1 at x,y |
nbaker | 8:a5c77b45008d | 4447 | |
nbaker | 8:a5c77b45008d | 4448 | accel.acquire_accel_data_g(Accel_Data); |
nbaker | 8:a5c77b45008d | 4449 | if(Fall_Alert_Mode == 0){ |
nbaker | 8:a5c77b45008d | 4450 | fall_config(12); // turn accel sensor back to standby |
nbaker | 8:a5c77b45008d | 4451 | } |
nbaker | 8:a5c77b45008d | 4452 | 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 | 4453 | sprintf(text_1," %2.2f g ",Accel_Mag); |
nbaker | 9:d2e39ee9fedd | 4454 | oled.Label((uint8_t *)text_1,39,40);// text_1 at x,y |
nbaker | 9:d2e39ee9fedd | 4455 | if(Accel_Mag > Fall_Thresh + 0.05f && Led_clk2 == 1){// are we stuck in limbo? |
nbaker | 8:a5c77b45008d | 4456 | fall_det_end(); |
nbaker | 8:a5c77b45008d | 4457 | } |
nbaker | 8:a5c77b45008d | 4458 | break; |
asong | 17:746dc1b7b218 | 4459 | }//end case 21 |
asong | 17:746dc1b7b218 | 4460 | case 31: { |
asong | 21:76237b62466b | 4461 | sprintf(display_buff, "%u ", Heart_Rate); // Convert int to char to display |
asong | 17:746dc1b7b218 | 4462 | textProperties.fontColor = COLOR_RED; |
asong | 17:746dc1b7b218 | 4463 | oled.SetTextProperties(&textProperties); |
asong | 17:746dc1b7b218 | 4464 | oled.Label((uint8_t *)display_buff, 40, 25); |
asong | 17:746dc1b7b218 | 4465 | if(Current_Zone == 1) { |
asong | 17:746dc1b7b218 | 4466 | textProperties.fontColor = COLOR_YELLOW; |
asong | 17:746dc1b7b218 | 4467 | oled.SetTextProperties(&textProperties); |
asong | 17:746dc1b7b218 | 4468 | } else if(Current_Zone == 2) { |
asong | 17:746dc1b7b218 | 4469 | textProperties.fontColor = COLOR_BLUE; |
asong | 17:746dc1b7b218 | 4470 | oled.SetTextProperties(&textProperties); |
asong | 17:746dc1b7b218 | 4471 | } else if(Current_Zone == 3) { |
asong | 17:746dc1b7b218 | 4472 | textProperties.fontColor = COLOR_GREEN; |
asong | 17:746dc1b7b218 | 4473 | oled.SetTextProperties(&textProperties); |
asong | 17:746dc1b7b218 | 4474 | } else if(Current_Zone == 4) { |
asong | 17:746dc1b7b218 | 4475 | textProperties.fontColor = COLOR_RED; |
asong | 17:746dc1b7b218 | 4476 | oled.SetTextProperties(&textProperties); |
asong | 17:746dc1b7b218 | 4477 | } |
asong | 17:746dc1b7b218 | 4478 | sprintf(display_buff, "%u", Current_Zone); // Convert int to char to display |
asong | 17:746dc1b7b218 | 4479 | oled.Label((uint8_t *)display_buff, 71, 45); |
asong | 17:746dc1b7b218 | 4480 | if(Prev_Zone == 1) { |
asong | 17:746dc1b7b218 | 4481 | textProperties.fontColor = COLOR_YELLOW; |
asong | 17:746dc1b7b218 | 4482 | oled.SetTextProperties(&textProperties); |
asong | 17:746dc1b7b218 | 4483 | } else if(Prev_Zone == 2) { |
asong | 17:746dc1b7b218 | 4484 | textProperties.fontColor = COLOR_BLUE; |
asong | 17:746dc1b7b218 | 4485 | oled.SetTextProperties(&textProperties); |
asong | 17:746dc1b7b218 | 4486 | } else if(Prev_Zone == 3) { |
asong | 17:746dc1b7b218 | 4487 | textProperties.fontColor = COLOR_GREEN; |
asong | 17:746dc1b7b218 | 4488 | oled.SetTextProperties(&textProperties); |
asong | 17:746dc1b7b218 | 4489 | } else if(Prev_Zone == 4) { |
asong | 17:746dc1b7b218 | 4490 | textProperties.fontColor = COLOR_RED; |
asong | 17:746dc1b7b218 | 4491 | oled.SetTextProperties(&textProperties); |
asong | 17:746dc1b7b218 | 4492 | } |
asong | 17:746dc1b7b218 | 4493 | sprintf(display_buff, "%u", Prev_Zone); // Convert int to char to display |
asong | 17:746dc1b7b218 | 4494 | oled.Label((uint8_t *)display_buff, 71, 60); |
asong | 17:746dc1b7b218 | 4495 | textProperties.fontColor = COLOR_WHITE; //Change font to white |
asong | 17:746dc1b7b218 | 4496 | oled.SetTextProperties(&textProperties);//Implement color change |
asong | 17:746dc1b7b218 | 4497 | break; |
asong | 17:746dc1b7b218 | 4498 | } |
asong | 17:746dc1b7b218 | 4499 | case 33: { |
asong | 21:76237b62466b | 4500 | sprintf(display_buff, "%u ", Heart_Rate); // Convert int to char to display |
asong | 17:746dc1b7b218 | 4501 | if(Current_Zone == 1) { |
asong | 17:746dc1b7b218 | 4502 | textProperties.fontColor = COLOR_YELLOW; |
asong | 17:746dc1b7b218 | 4503 | oled.SetTextProperties(&textProperties); |
asong | 17:746dc1b7b218 | 4504 | } else if(Current_Zone == 2) { |
asong | 17:746dc1b7b218 | 4505 | textProperties.fontColor = COLOR_BLUE; |
asong | 17:746dc1b7b218 | 4506 | oled.SetTextProperties(&textProperties); |
asong | 17:746dc1b7b218 | 4507 | } else if(Current_Zone == 3) { |
asong | 17:746dc1b7b218 | 4508 | textProperties.fontColor = COLOR_GREEN; |
asong | 17:746dc1b7b218 | 4509 | oled.SetTextProperties(&textProperties); |
asong | 17:746dc1b7b218 | 4510 | } else if(Current_Zone == 4) { |
asong | 17:746dc1b7b218 | 4511 | textProperties.fontColor = COLOR_RED; |
asong | 17:746dc1b7b218 | 4512 | oled.SetTextProperties(&textProperties); |
asong | 17:746dc1b7b218 | 4513 | } |
asong | 17:746dc1b7b218 | 4514 | oled.Label((uint8_t *)display_buff, 35, 40);// Display at x,y |
asong | 17:746dc1b7b218 | 4515 | textProperties.fontColor = COLOR_WHITE; |
asong | 17:746dc1b7b218 | 4516 | oled.SetTextProperties(&textProperties); |
asong | 17:746dc1b7b218 | 4517 | break; |
asong | 17:746dc1b7b218 | 4518 | } |
nbaker | 11:ccda4d44bd8e | 4519 | case 72: {// BlueTooth on/off |
nbaker | 11:ccda4d44bd8e | 4520 | textProperties.fontColor = COLOR_WHITE; |
nbaker | 11:ccda4d44bd8e | 4521 | oled.SetTextProperties(&textProperties); |
nbaker | 11:ccda4d44bd8e | 4522 | if (BLE_On == 1) { |
nbaker | 11:ccda4d44bd8e | 4523 | /* re-Display Bond Pass Key in a 90px by 18px textbox at x=0,y=40 */ |
nbaker | 11:ccda4d44bd8e | 4524 | sprintf(text,"%d", kw40z_device.GetPassKey()); |
nbaker | 11:ccda4d44bd8e | 4525 | oled.TextBox((uint8_t *)text,10,45,80,18); |
nbaker | 11:ccda4d44bd8e | 4526 | } else { |
nbaker | 11:ccda4d44bd8e | 4527 | // do nothing, don't update when not active |
nbaker | 11:ccda4d44bd8e | 4528 | } |
nbaker | 11:ccda4d44bd8e | 4529 | |
nbaker | 11:ccda4d44bd8e | 4530 | break; |
nbaker | 11:ccda4d44bd8e | 4531 | }// end case 72 |
nbaker | 8:a5c77b45008d | 4532 | default: { |
nbaker | 8:a5c77b45008d | 4533 | // do nothing for other screens |
nbaker | 8:a5c77b45008d | 4534 | break; |
nbaker | 8:a5c77b45008d | 4535 | } |
nbaker | 8:a5c77b45008d | 4536 | }// end switch |
nbaker | 8:a5c77b45008d | 4537 | __enable_irq(); // Enable all Interrupts |
nbaker | 8:a5c77b45008d | 4538 | }// end of update_display_date |
nbaker | 8:a5c77b45008d | 4539 | |
nbaker | 8:a5c77b45008d | 4540 | |
nbaker | 8:a5c77b45008d | 4541 | /***************************************************************************** |
nbaker | 11:ccda4d44bd8e | 4542 | Name: txTask() |
nbaker | 8:a5c77b45008d | 4543 | Purpose: HexiHeart Connecction |
nbaker | 8:a5c77b45008d | 4544 | Inputs: None |
nbaker | 8:a5c77b45008d | 4545 | Returns: None |
nbaker | 8:a5c77b45008d | 4546 | ******************************************************************************/ |
nbaker | 8:a5c77b45008d | 4547 | |
nbaker | 11:ccda4d44bd8e | 4548 | void txTask(void)// we're not really using this because we arn't always transmitting |
nbaker | 8:a5c77b45008d | 4549 | { |
nbaker | 8:a5c77b45008d | 4550 | while (true) { |
nbaker | 11:ccda4d44bd8e | 4551 | // update sensor data |
nbaker | 11:ccda4d44bd8e | 4552 | |
nbaker | 8:a5c77b45008d | 4553 | /*Notify Hexiwear App that it is running Sensor Tag mode*/ |
nbaker | 11:ccda4d44bd8e | 4554 | kw40z_device.SendSetApplicationMode(GUI_CURRENT_APP_SENSOR_TAG); |
nbaker | 11:ccda4d44bd8e | 4555 | |
nbaker | 11:ccda4d44bd8e | 4556 | /* send sensor data |
nbaker | 11:ccda4d44bd8e | 4557 | |
nbaker | 11:ccda4d44bd8e | 4558 | //Send Battery Level |
nbaker | 11:ccda4d44bd8e | 4559 | kw40z_device.SendBatteryLevel(battery); |
nbaker | 11:ccda4d44bd8e | 4560 | |
nbaker | 11:ccda4d44bd8e | 4561 | //Send Ambient Light Level |
nbaker | 11:ccda4d44bd8e | 4562 | kw40z_device.SendAmbientLight(light); |
nbaker | 11:ccda4d44bd8e | 4563 | |
nbaker | 11:ccda4d44bd8e | 4564 | //Send Humidity |
nbaker | 11:ccda4d44bd8e | 4565 | kw40z_device.SendHumidity(humidity); |
nbaker | 11:ccda4d44bd8e | 4566 | |
nbaker | 11:ccda4d44bd8e | 4567 | //Send Temperature |
nbaker | 11:ccda4d44bd8e | 4568 | kw40z_device.SendTemperature(temperature); |
nbaker | 11:ccda4d44bd8e | 4569 | |
nbaker | 11:ccda4d44bd8e | 4570 | //Send Pressure |
nbaker | 11:ccda4d44bd8e | 4571 | kw40z_device.SendPressure(pressure); |
nbaker | 11:ccda4d44bd8e | 4572 | |
nbaker | 11:ccda4d44bd8e | 4573 | //Send Mag,Accel,Gyro Data. |
nbaker | 11:ccda4d44bd8e | 4574 | kw40z_device.SendGyro(x,y,z); |
nbaker | 11:ccda4d44bd8e | 4575 | kw40z_device.SendAccel(z,x,y); |
nbaker | 11:ccda4d44bd8e | 4576 | kw40z_device.SendMag(y,z,x); |
nbaker | 11:ccda4d44bd8e | 4577 | |
nbaker | 11:ccda4d44bd8e | 4578 | */ |
nbaker | 11:ccda4d44bd8e | 4579 | Thread::wait(1000); |
nbaker | 11:ccda4d44bd8e | 4580 | }// end while |
nbaker | 13:37cd579208e9 | 4581 | }// end TxTask |
nbaker | 13:37cd579208e9 | 4582 | |
nbaker | 13:37cd579208e9 | 4583 | |
nbaker | 13:37cd579208e9 | 4584 | /***************************************************************************** |
nbaker | 13:37cd579208e9 | 4585 | Name: WDT_Timeout() |
nbaker | 13:37cd579208e9 | 4586 | Purpose: Interrupt routine used by Watch Dog timer Ticker. |
nbaker | 13:37cd579208e9 | 4587 | Note that there are a few ways to implement a WDT. The best would be an external |
nbaker | 13:37cd579208e9 | 4588 | circuit that resets the K46 if it became unresponsive. The next best would be using |
nbaker | 13:37cd579208e9 | 4589 | the internal WDT that is built into microprocessor. And lastly there is this |
nbaker | 13:37cd579208e9 | 4590 | method, using a Ticker/timer. |
nbaker | 13:37cd579208e9 | 4591 | Inputs: None |
nbaker | 13:37cd579208e9 | 4592 | Returns: None |
nbaker | 13:37cd579208e9 | 4593 | ******************************************************************************/ |
nbaker | 13:37cd579208e9 | 4594 | void WDT_Timeout(){ // turn off display mode |
nbaker | 13:37cd579208e9 | 4595 | Screen_Timer.attach(&timout_timer,(SCRN_TIME));//Is this sufficient to reset/restart ticker timer for OLED? |
nbaker | 13:37cd579208e9 | 4596 | if (OLED_ON == 0) { |
nbaker | 13:37cd579208e9 | 4597 | OLED_ON = 1; // Screen was off, set to On |
nbaker | 13:37cd579208e9 | 4598 | } |
nbaker | 13:37cd579208e9 | 4599 | oled.DimScreenOFF(); |
nbaker | 13:37cd579208e9 | 4600 | __disable_irq(); // Disable all Interrupts |
nbaker | 13:37cd579208e9 | 4601 | oled_text_properties_t textProperties = {0}; // Need these to change font color |
nbaker | 13:37cd579208e9 | 4602 | oled.GetTextProperties(&textProperties); // Need these to change font color |
nbaker | 13:37cd579208e9 | 4603 | oled.FillScreen(COLOR_BLACK); // Clear screen |
nbaker | 13:37cd579208e9 | 4604 | textProperties.font = OpenSans_12x18_Regular; // Max Width of Character = 12px, Max Height of Character = 18px |
nbaker | 13:37cd579208e9 | 4605 | textProperties.fontColor = COLOR_WHITE; |
nbaker | 13:37cd579208e9 | 4606 | oled.SetTextProperties(&textProperties); |
nbaker | 13:37cd579208e9 | 4607 | oled.Label((uint8_t *)"WatchDog",10,30); // Display "Back" at x,y |
nbaker | 13:37cd579208e9 | 4608 | oled.Label((uint8_t *)" Reset!",20,55); // Display "Back" at x,y |
nbaker | 13:37cd579208e9 | 4609 | wait(0.1);// display for 100ms |
nbaker | 13:37cd579208e9 | 4610 | |
nbaker | 13:37cd579208e9 | 4611 | NVIC_SystemReset(); // software reset |
nbaker | 13:37cd579208e9 | 4612 | }//end WDT_Timeout routine |
nbaker | 13:37cd579208e9 | 4613 | |
nbaker | 13:37cd579208e9 | 4614 | |
nbaker | 13:37cd579208e9 | 4615 | /***************************************************************************** |
nbaker | 13:37cd579208e9 | 4616 | Name: CLRWDT() |
nbaker | 13:37cd579208e9 | 4617 | Purpose: Routine to clear/reset Watch Dog timer Ticker |
nbaker | 13:37cd579208e9 | 4618 | Inputs: None |
nbaker | 13:37cd579208e9 | 4619 | Returns: None |
nbaker | 13:37cd579208e9 | 4620 | ******************************************************************************/ |
nbaker | 13:37cd579208e9 | 4621 | void CLRWDT(){ // turn off display mode |
nbaker | 13:37cd579208e9 | 4622 | WDT_Timer.attach(&WDT_Timeout,(WDT_TIME));//re-attach/reset WDT |
nbaker | 13:37cd579208e9 | 4623 | }//end WDT_Timeout routine |
nbaker | 13:37cd579208e9 | 4624 | |
nbaker | 13:37cd579208e9 | 4625 | |
nbaker | 13:37cd579208e9 | 4626 | /***************************************************************************** |
nbaker | 13:37cd579208e9 | 4627 | Name: PassKey() |
nbaker | 13:37cd579208e9 | 4628 | Purpose: Interrupt routine called when MK46 recieves Passkey from KW40 |
nbaker | 13:37cd579208e9 | 4629 | Inputs: None |
nbaker | 13:37cd579208e9 | 4630 | Returns: None |
nbaker | 13:37cd579208e9 | 4631 | ******************************************************************************/ |
nbaker | 13:37cd579208e9 | 4632 | void PassKey(void)// |
nbaker | 13:37cd579208e9 | 4633 | { |
nbaker | 13:37cd579208e9 | 4634 | Screen_Timer.attach(&timout_timer,(SCRN_TIME));//Is this sufficient to reset/restart ticker timer for OLED? |
nbaker | 13:37cd579208e9 | 4635 | if (OLED_ON == 0) { |
nbaker | 13:37cd579208e9 | 4636 | OLED_ON = 1; // Scree was off, set to On |
nbaker | 13:37cd579208e9 | 4637 | } |
nbaker | 13:37cd579208e9 | 4638 | oled.DimScreenOFF(); |
nbaker | 13:37cd579208e9 | 4639 | Screen_Num = 72; //Change to screen BLE screen 72 |
nbaker | 13:37cd579208e9 | 4640 | StartHaptic(); |
nbaker | 13:37cd579208e9 | 4641 | update_display(); |
nbaker | 13:37cd579208e9 | 4642 | }// PassKey |
nbaker | 13:37cd579208e9 | 4643 | |
nbaker | 13:37cd579208e9 | 4644 | /***************************************************************************** |
nbaker | 13:37cd579208e9 | 4645 | Name: UpDate_Ave() |
nbaker | 13:37cd579208e9 | 4646 | Purpose: Routine called to update rolling average of slow changing sensor readings |
nbaker | 13:37cd579208e9 | 4647 | Inputs: Temp/humid sensor readings and battery measurement |
nbaker | 13:37cd579208e9 | 4648 | Returns: updated global variables |
nbaker | 13:37cd579208e9 | 4649 | ******************************************************************************/ |
nbaker | 13:37cd579208e9 | 4650 | void UpDate_Ave(void)// |
nbaker | 13:37cd579208e9 | 4651 | { |
nbaker | 13:37cd579208e9 | 4652 | //int i = 4; // used in rolling average |
nbaker | 13:37cd579208e9 | 4653 | HexiwearBattery battery; |
nbaker | 13:37cd579208e9 | 4654 | battery.sensorOn(); |
nbaker | 19:87ab6daf98e5 | 4655 | if(Ave_Num == 0.0f){ |
nbaker | 13:37cd579208e9 | 4656 | // this is first measurement since reboot |
nbaker | 13:37cd579208e9 | 4657 | batt_per_level = (uint8_t)battery.readLevelPercent(); |
nbaker | 13:37cd579208e9 | 4658 | sample_ftemp = temphumid.sample_ftemp(); |
nbaker | 13:37cd579208e9 | 4659 | sample_humid = temphumid.sample_humid(); |
nbaker | 13:37cd579208e9 | 4660 | }//end if |
nbaker | 13:37cd579208e9 | 4661 | else{ |
nbaker | 13:37cd579208e9 | 4662 | // updated measurments on a rolling average basis: 1/4 new measurement to 3/4 running average |
nbaker | 19:87ab6daf98e5 | 4663 | batt_per_level = (uint8_t)((Ave_Num-1)*batt_per_level/Ave_Num + battery.readLevelPercent()/Ave_Num); // do calculation as a float but return an uint8 |
nbaker | 19:87ab6daf98e5 | 4664 | sample_ftemp = (int)(Ave_Num-1)*sample_ftemp/Ave_Num + temphumid.sample_ftemp()/Ave_Num; |
nbaker | 19:87ab6daf98e5 | 4665 | sample_humid = (int)(Ave_Num-1)*sample_humid/Ave_Num + temphumid.sample_humid()/Ave_Num; |
nbaker | 13:37cd579208e9 | 4666 | }//end else |
nbaker | 19:87ab6daf98e5 | 4667 | Ave_Num = Ave_Num + 1; |
nbaker | 16:537ef0c72084 | 4668 | if(Ave_Num > MAX_AVE_NUM){ |
nbaker | 19:87ab6daf98e5 | 4669 | Ave_Num = MAX_AVE_NUM; //set limit |
nbaker | 13:37cd579208e9 | 4670 | } |
asong | 14:c3b080cdf36b | 4671 | }// end UpDate_Ave |
nbaker | 16:537ef0c72084 | 4672 | |
asong | 14:c3b080cdf36b | 4673 | void HR_Simulation(void) |
asong | 14:c3b080cdf36b | 4674 | { |
asong | 14:c3b080cdf36b | 4675 | if(randomized == 0) |
asong | 14:c3b080cdf36b | 4676 | { |
asong | 14:c3b080cdf36b | 4677 | srand(hi_calc); |
asong | 14:c3b080cdf36b | 4678 | randomized = 1; |
asong | 14:c3b080cdf36b | 4679 | } |
asong | 14:c3b080cdf36b | 4680 | if(simulation_stage == 0) |
asong | 14:c3b080cdf36b | 4681 | { |
asong | 14:c3b080cdf36b | 4682 | Heart_Rate = HR_Zone1[0] + rand() %( HR_Zone1[1] - HR_Zone1[0] + 1); |
asong | 14:c3b080cdf36b | 4683 | |
asong | 14:c3b080cdf36b | 4684 | } |
asong | 14:c3b080cdf36b | 4685 | else if(simulation_stage == 1) |
asong | 14:c3b080cdf36b | 4686 | { |
asong | 14:c3b080cdf36b | 4687 | Heart_Rate = HR_Zone2[0] + rand() %( HR_Zone2[1] - HR_Zone2[0] + 1); |
asong | 14:c3b080cdf36b | 4688 | |
asong | 14:c3b080cdf36b | 4689 | } |
asong | 14:c3b080cdf36b | 4690 | else if(simulation_stage == 2) |
asong | 14:c3b080cdf36b | 4691 | { |
asong | 14:c3b080cdf36b | 4692 | Heart_Rate = HR_Zone3[0] + rand() %( HR_Zone3[1] - HR_Zone3[0] + 1); |
asong | 14:c3b080cdf36b | 4693 | |
asong | 14:c3b080cdf36b | 4694 | } |
asong | 14:c3b080cdf36b | 4695 | else if(simulation_stage == 3) |
asong | 14:c3b080cdf36b | 4696 | { |
asong | 14:c3b080cdf36b | 4697 | Heart_Rate = HR_Zone4[0] + rand() %( HR_Zone4[1] - HR_Zone4[0] + 1); |
asong | 14:c3b080cdf36b | 4698 | |
asong | 14:c3b080cdf36b | 4699 | } |
asong | 14:c3b080cdf36b | 4700 | else if(simulation_stage == 4) |
asong | 14:c3b080cdf36b | 4701 | { |
asong | 14:c3b080cdf36b | 4702 | Heart_Rate = HR_Zone3[0] + rand() %( HR_Zone3[1] - HR_Zone3[0] + 1); |
asong | 14:c3b080cdf36b | 4703 | |
asong | 14:c3b080cdf36b | 4704 | } |
asong | 22:3de592f8e696 | 4705 | else if(simulation_stage == 5) |
asong | 22:3de592f8e696 | 4706 | { |
asong | 22:3de592f8e696 | 4707 | Heart_Rate = HR_Zone2[0] + rand() %( HR_Zone2[1] - HR_Zone2[0] + 1); |
asong | 22:3de592f8e696 | 4708 | } |
asong | 22:3de592f8e696 | 4709 | else if(simulation_stage == 6) |
asong | 22:3de592f8e696 | 4710 | { |
asong | 22:3de592f8e696 | 4711 | Heart_Rate = HR_Zone1[0] + rand() %( HR_Zone1[1] - HR_Zone1[0] + 1); |
asong | 22:3de592f8e696 | 4712 | } |
asong | 14:c3b080cdf36b | 4713 | else |
asong | 14:c3b080cdf36b | 4714 | { |
asong | 22:3de592f8e696 | 4715 | rand_stage = rand() % 4 + 1; |
asong | 22:3de592f8e696 | 4716 | if(rand_stage == 1) |
asong | 22:3de592f8e696 | 4717 | { |
asong | 22:3de592f8e696 | 4718 | Heart_Rate = HR_Zone1[0] + rand() %( HR_Zone1[1] - HR_Zone1[0] + 1); |
asong | 22:3de592f8e696 | 4719 | } |
asong | 22:3de592f8e696 | 4720 | else if(rand_stage == 2) |
asong | 22:3de592f8e696 | 4721 | { |
asong | 22:3de592f8e696 | 4722 | Heart_Rate = HR_Zone2[0] + rand() %( HR_Zone2[1] - HR_Zone2[0] + 1); |
asong | 22:3de592f8e696 | 4723 | } |
asong | 22:3de592f8e696 | 4724 | else if(rand_stage == 3) |
asong | 22:3de592f8e696 | 4725 | { |
asong | 22:3de592f8e696 | 4726 | Heart_Rate = HR_Zone3[0] + rand() %( HR_Zone3[1] - HR_Zone3[0] + 1); |
asong | 22:3de592f8e696 | 4727 | } |
asong | 22:3de592f8e696 | 4728 | else if(rand_stage == 4) |
asong | 22:3de592f8e696 | 4729 | { |
asong | 22:3de592f8e696 | 4730 | Heart_Rate = HR_Zone4[0] + rand() %( HR_Zone4[1] - HR_Zone4[0] + 1); |
asong | 22:3de592f8e696 | 4731 | } |
asong | 14:c3b080cdf36b | 4732 | } |
asong | 14:c3b080cdf36b | 4733 | simulation_stage++; |
asong | 14:c3b080cdf36b | 4734 | Determine_Current_Zone(); |
nbaker | 16:537ef0c72084 | 4735 | //update_display(); // I don't think we should update display, let update_data() do that |
asong | 14:c3b080cdf36b | 4736 | } |
asong | 14:c3b080cdf36b | 4737 | |
asong | 14:c3b080cdf36b | 4738 | void readRegs(int addr, uint8_t * data, int len) |
asong | 14:c3b080cdf36b | 4739 | { |
asong | 14:c3b080cdf36b | 4740 | char temp[1] = {addr}; |
asong | 14:c3b080cdf36b | 4741 | i2c_bus0.write(HR_W_ADDR, temp, 1, true); |
asong | 14:c3b080cdf36b | 4742 | i2c_bus0.read(HR_R_ADDR, (char*)data, len); |
asong | 14:c3b080cdf36b | 4743 | |
asong | 14:c3b080cdf36b | 4744 | } |
asong | 14:c3b080cdf36b | 4745 | |
asong | 14:c3b080cdf36b | 4746 | void writeRegs(uint8_t * data, int len) |
asong | 14:c3b080cdf36b | 4747 | { |
asong | 14:c3b080cdf36b | 4748 | i2c_bus0.write(HR_W_ADDR, (char*)data, len); |
asong | 14:c3b080cdf36b | 4749 | } |
asong | 14:c3b080cdf36b | 4750 | |
asong | 14:c3b080cdf36b | 4751 | void setIntEnable(uint16_t mask) |
asong | 14:c3b080cdf36b | 4752 | { |
asong | 14:c3b080cdf36b | 4753 | uint8_t res[3]; |
asong | 14:c3b080cdf36b | 4754 | res[0] = REG_INT_ENB_MSB; |
asong | 14:c3b080cdf36b | 4755 | res[1] = (mask >> 8) & 0xFF; |
asong | 14:c3b080cdf36b | 4756 | res[2] = (mask & 0xFF); |
asong | 14:c3b080cdf36b | 4757 | writeRegs(res, 3); |
asong | 14:c3b080cdf36b | 4758 | } |
asong | 14:c3b080cdf36b | 4759 | |
asong | 14:c3b080cdf36b | 4760 | |
asong | 14:c3b080cdf36b | 4761 | void setFIFO_WR_PTR(uint8_t data) |
asong | 14:c3b080cdf36b | 4762 | { |
asong | 14:c3b080cdf36b | 4763 | uint8_t res[2]; |
asong | 14:c3b080cdf36b | 4764 | res[0] = REG_FIFO_WR_PTR; |
asong | 14:c3b080cdf36b | 4765 | res[1] = data; |
asong | 14:c3b080cdf36b | 4766 | writeRegs(res, 2); |
asong | 14:c3b080cdf36b | 4767 | } |
asong | 14:c3b080cdf36b | 4768 | |
asong | 14:c3b080cdf36b | 4769 | void setOVF_COUNTER(uint8_t data) |
asong | 14:c3b080cdf36b | 4770 | { |
asong | 14:c3b080cdf36b | 4771 | uint8_t res[2]; |
asong | 14:c3b080cdf36b | 4772 | res[0] = REG_OVF_COUNTER; |
asong | 14:c3b080cdf36b | 4773 | res[1] = data; |
asong | 14:c3b080cdf36b | 4774 | writeRegs(res, 2); |
asong | 14:c3b080cdf36b | 4775 | } |
asong | 14:c3b080cdf36b | 4776 | |
asong | 14:c3b080cdf36b | 4777 | uint8_t getFIFO_RD_PTR(void) |
asong | 14:c3b080cdf36b | 4778 | { |
asong | 14:c3b080cdf36b | 4779 | uint8_t data; |
asong | 14:c3b080cdf36b | 4780 | readRegs(REG_FIFO_RD_PTR, &data, 1); |
asong | 14:c3b080cdf36b | 4781 | return (data); |
asong | 14:c3b080cdf36b | 4782 | } |
asong | 14:c3b080cdf36b | 4783 | |
asong | 14:c3b080cdf36b | 4784 | void setSLOT(uint16_t data) |
asong | 14:c3b080cdf36b | 4785 | { |
asong | 14:c3b080cdf36b | 4786 | uint8_t res[3]; |
asong | 14:c3b080cdf36b | 4787 | res[0] = REG_SLOT_MSB; |
asong | 14:c3b080cdf36b | 4788 | res[1] = (data >> 8) & 0xFF; |
asong | 14:c3b080cdf36b | 4789 | res[2] = data & 0xFF; |
asong | 14:c3b080cdf36b | 4790 | writeRegs(res, 3); |
asong | 14:c3b080cdf36b | 4791 | } |
asong | 14:c3b080cdf36b | 4792 | |
asong | 14:c3b080cdf36b | 4793 | void setFIFO_RD_PTR(uint8_t data) |
asong | 14:c3b080cdf36b | 4794 | { |
asong | 14:c3b080cdf36b | 4795 | uint8_t res[2]; |
asong | 14:c3b080cdf36b | 4796 | res[0] = REG_FIFO_RD_PTR; |
asong | 14:c3b080cdf36b | 4797 | res[1] = data; |
asong | 14:c3b080cdf36b | 4798 | writeRegs(res, 2); |
asong | 14:c3b080cdf36b | 4799 | } |
asong | 14:c3b080cdf36b | 4800 | |
asong | 14:c3b080cdf36b | 4801 | void setFIFO_DATA(uint8_t data) |
asong | 14:c3b080cdf36b | 4802 | { |
asong | 14:c3b080cdf36b | 4803 | uint8_t res[2]; |
asong | 14:c3b080cdf36b | 4804 | res[0] = REG_FIFO_DATA; |
asong | 14:c3b080cdf36b | 4805 | res[1] = data; |
asong | 14:c3b080cdf36b | 4806 | writeRegs(res, 2); |
asong | 14:c3b080cdf36b | 4807 | } |
asong | 14:c3b080cdf36b | 4808 | |
asong | 14:c3b080cdf36b | 4809 | void setFIFO_CONFIG(uint8_t data) |
asong | 14:c3b080cdf36b | 4810 | { |
asong | 14:c3b080cdf36b | 4811 | uint8_t res[2]; |
asong | 14:c3b080cdf36b | 4812 | res[0] = REG_FIFO_CONFIG; |
asong | 14:c3b080cdf36b | 4813 | res[1] = data; |
asong | 14:c3b080cdf36b | 4814 | writeRegs(res, 2); |
asong | 14:c3b080cdf36b | 4815 | } |
asong | 14:c3b080cdf36b | 4816 | |
asong | 14:c3b080cdf36b | 4817 | |
asong | 14:c3b080cdf36b | 4818 | void setMODE_CONFIG(uint8_t data) |
asong | 14:c3b080cdf36b | 4819 | { |
asong | 14:c3b080cdf36b | 4820 | uint8_t res[2]; |
asong | 14:c3b080cdf36b | 4821 | res[0] = REG_MODE_CONFIG; |
asong | 14:c3b080cdf36b | 4822 | res[1] = data; |
asong | 14:c3b080cdf36b | 4823 | writeRegs (res, 2); |
asong | 14:c3b080cdf36b | 4824 | } |
asong | 14:c3b080cdf36b | 4825 | |
asong | 14:c3b080cdf36b | 4826 | void setSPO2_CONFIG(uint8_t data) |
asong | 14:c3b080cdf36b | 4827 | { |
asong | 14:c3b080cdf36b | 4828 | uint8_t res[2] ; |
asong | 14:c3b080cdf36b | 4829 | res[0] = REG_SPO2_CONFIG ; |
asong | 14:c3b080cdf36b | 4830 | res[1] = data ; |
asong | 14:c3b080cdf36b | 4831 | writeRegs(res, 2) ; |
asong | 14:c3b080cdf36b | 4832 | } |
asong | 14:c3b080cdf36b | 4833 | |
asong | 14:c3b080cdf36b | 4834 | void setLED1_PA(uint8_t data) |
asong | 14:c3b080cdf36b | 4835 | { |
asong | 14:c3b080cdf36b | 4836 | uint8_t res[2] ; |
asong | 14:c3b080cdf36b | 4837 | res[0] = REG_LED1_PA ; |
asong | 14:c3b080cdf36b | 4838 | res[1] = data ; |
asong | 14:c3b080cdf36b | 4839 | writeRegs(res, 2) ; |
asong | 14:c3b080cdf36b | 4840 | } |
asong | 14:c3b080cdf36b | 4841 | |
asong | 14:c3b080cdf36b | 4842 | void setLED2_PA(uint8_t data) |
asong | 14:c3b080cdf36b | 4843 | { |
asong | 14:c3b080cdf36b | 4844 | uint8_t res[2] ; |
asong | 14:c3b080cdf36b | 4845 | res[0] = REG_LED2_PA ; |
asong | 14:c3b080cdf36b | 4846 | res[1] = data ; |
asong | 14:c3b080cdf36b | 4847 | writeRegs(res, 2) ; |
asong | 14:c3b080cdf36b | 4848 | } |
asong | 14:c3b080cdf36b | 4849 | |
asong | 14:c3b080cdf36b | 4850 | void setLED3_PA(uint8_t data) |
asong | 14:c3b080cdf36b | 4851 | { |
asong | 14:c3b080cdf36b | 4852 | uint8_t res[2] ; |
asong | 14:c3b080cdf36b | 4853 | res[0] = REG_LED3_PA ; |
asong | 14:c3b080cdf36b | 4854 | res[1] = data ; |
asong | 14:c3b080cdf36b | 4855 | writeRegs(res, 2) ; |
asong | 14:c3b080cdf36b | 4856 | } |
asong | 14:c3b080cdf36b | 4857 | |
asong | 14:c3b080cdf36b | 4858 | void setPILOT_PA(uint8_t data) |
asong | 14:c3b080cdf36b | 4859 | { |
asong | 14:c3b080cdf36b | 4860 | uint8_t res[2] ; |
asong | 14:c3b080cdf36b | 4861 | res[0] = REG_PILOT_PA ; |
asong | 14:c3b080cdf36b | 4862 | res[1] = data ; |
asong | 14:c3b080cdf36b | 4863 | writeRegs(res, 2) ; |
asong | 14:c3b080cdf36b | 4864 | } |
asong | 14:c3b080cdf36b | 4865 | |
asong | 14:c3b080cdf36b | 4866 | |
asong | 14:c3b080cdf36b | 4867 | |
asong | 14:c3b080cdf36b | 4868 | |
asong | 14:c3b080cdf36b | 4869 | void setPROX_INT_THR(uint8_t data) |
asong | 14:c3b080cdf36b | 4870 | { |
asong | 14:c3b080cdf36b | 4871 | uint8_t res[2] ; |
asong | 14:c3b080cdf36b | 4872 | res[0] = REG_PROX_INT_THR ; |
asong | 14:c3b080cdf36b | 4873 | res[1] = data ; |
asong | 14:c3b080cdf36b | 4874 | writeRegs(res, 2) ; |
asong | 14:c3b080cdf36b | 4875 | } |
asong | 14:c3b080cdf36b | 4876 | |
asong | 14:c3b080cdf36b | 4877 | void clearFIFO(void) |
asong | 14:c3b080cdf36b | 4878 | { |
asong | 14:c3b080cdf36b | 4879 | uint8_t res[5] ; |
asong | 14:c3b080cdf36b | 4880 | res[0] = REG_FIFO_WR_PTR ; |
asong | 14:c3b080cdf36b | 4881 | res[1] = 0x00 ; /* FIFO_WR_PTR */ |
asong | 14:c3b080cdf36b | 4882 | res[2] = 0x00 ; /* OVF_COUNTER */ |
asong | 14:c3b080cdf36b | 4883 | res[3] = 0x00 ; /* FIFO_RD_PTR */ |
asong | 14:c3b080cdf36b | 4884 | res[4] = 0x00 ; /* FIFO_DATA (do we need to clear this?) */ |
asong | 14:c3b080cdf36b | 4885 | writeRegs(res, 5) ; |
asong | 14:c3b080cdf36b | 4886 | } |
asong | 14:c3b080cdf36b | 4887 | |
asong | 14:c3b080cdf36b | 4888 | /* |
asong | 14:c3b080cdf36b | 4889 | * readFIFO(void) |
asong | 14:c3b080cdf36b | 4890 | * FIFO data is always a 3-bytes data |
asong | 14:c3b080cdf36b | 4891 | * byte1[1:0] : FIFO_DATA[17]-FIFO_DATA[16] |
asong | 14:c3b080cdf36b | 4892 | * byte2[7:0] : FIFO_DATA[15]-FIFO_DATA[8] |
asong | 14:c3b080cdf36b | 4893 | * byte3[7:0] : FIFO_DATA[7]-FIFO_DATA[0] |
asong | 14:c3b080cdf36b | 4894 | * The data is left aligned, so FIFO_DATA[17] |
asong | 14:c3b080cdf36b | 4895 | * is always MSB, although the data length |
asong | 14:c3b080cdf36b | 4896 | * can be 18-bit ~ 15-bit |
asong | 14:c3b080cdf36b | 4897 | */ |
asong | 14:c3b080cdf36b | 4898 | uint32_t readFIFO(void) |
asong | 14:c3b080cdf36b | 4899 | { |
asong | 14:c3b080cdf36b | 4900 | uint32_t data = 0 ; |
asong | 14:c3b080cdf36b | 4901 | uint8_t res[3] ; |
asong | 14:c3b080cdf36b | 4902 | readRegs(REG_FIFO_DATA, res, 3) ; |
asong | 14:c3b080cdf36b | 4903 | data = |
asong | 14:c3b080cdf36b | 4904 | ((res[0] & 0x03)<<16) |
asong | 14:c3b080cdf36b | 4905 | | (res[1] << 8) |
asong | 14:c3b080cdf36b | 4906 | | res[2] ; |
asong | 14:c3b080cdf36b | 4907 | return( data ) ; |
asong | 14:c3b080cdf36b | 4908 | } |
asong | 14:c3b080cdf36b | 4909 | |
asong | 14:c3b080cdf36b | 4910 | void maxReset(void) |
asong | 14:c3b080cdf36b | 4911 | { |
asong | 14:c3b080cdf36b | 4912 | uint8_t res[2] ; |
asong | 14:c3b080cdf36b | 4913 | res[0] = REG_MODE_CONFIG ; |
asong | 14:c3b080cdf36b | 4914 | res[1] = 0x40 ; /* reset */ |
asong | 14:c3b080cdf36b | 4915 | writeRegs(res, 2) ; |
asong | 14:c3b080cdf36b | 4916 | } |
asong | 14:c3b080cdf36b | 4917 | |
asong | 14:c3b080cdf36b | 4918 | void maxInit(void) |
asong | 14:c3b080cdf36b | 4919 | { |
asong | 14:c3b080cdf36b | 4920 | maxim = 1; |
asong | 14:c3b080cdf36b | 4921 | maxReset(); |
asong | 20:990951205fbd | 4922 | //wait(0.05); |
asong | 14:c3b080cdf36b | 4923 | setLED1_PA(0xFF); |
asong | 14:c3b080cdf36b | 4924 | setLED2_PA(0x33); |
asong | 14:c3b080cdf36b | 4925 | setLED3_PA(0xFF); |
asong | 14:c3b080cdf36b | 4926 | setPILOT_PA(0x19); |
asong | 20:990951205fbd | 4927 | //wait(0.05); |
asong | 14:c3b080cdf36b | 4928 | setSLOT(0x0300); |
asong | 14:c3b080cdf36b | 4929 | setFIFO_CONFIG(0x06); |
asong | 14:c3b080cdf36b | 4930 | setSPO2_CONFIG(0x42); |
asong | 20:990951205fbd | 4931 | // wait(0.05); |
asong | 14:c3b080cdf36b | 4932 | setPROX_INT_THR(0x14); |
asong | 14:c3b080cdf36b | 4933 | clearFIFO(); |
asong | 20:990951205fbd | 4934 | //wait(0.05); |
asong | 14:c3b080cdf36b | 4935 | } |
asong | 14:c3b080cdf36b | 4936 | |
asong | 14:c3b080cdf36b | 4937 | void maxEnable(void) |
asong | 14:c3b080cdf36b | 4938 | { |
asong | 14:c3b080cdf36b | 4939 | setIntEnable(0x8000); |
asong | 14:c3b080cdf36b | 4940 | setMODE_CONFIG(0x07); |
asong | 14:c3b080cdf36b | 4941 | Enable_Heart_Rate(); |
asong | 14:c3b080cdf36b | 4942 | } |
asong | 14:c3b080cdf36b | 4943 | |
asong | 14:c3b080cdf36b | 4944 | void maxDeinit(void) |
asong | 14:c3b080cdf36b | 4945 | { |
asong | 14:c3b080cdf36b | 4946 | maxim = 0; |
asong | 14:c3b080cdf36b | 4947 | hr_ticker.detach(); |
asong | 14:c3b080cdf36b | 4948 | hr_measure_ticker.detach(); |
asong | 14:c3b080cdf36b | 4949 | Disable_Heart_Rate(); |
asong | 14:c3b080cdf36b | 4950 | hr_led.detach(); |
nbaker | 16:537ef0c72084 | 4951 | RED_Led = LED_OFF; |
nbaker | 16:537ef0c72084 | 4952 | GRN_Led = LED_OFF; |
nbaker | 16:537ef0c72084 | 4953 | BLU_Led = LED_OFF; |
asong | 14:c3b080cdf36b | 4954 | } |
asong | 14:c3b080cdf36b | 4955 | |
asong | 14:c3b080cdf36b | 4956 | void processHeartRate(void) |
asong | 14:c3b080cdf36b | 4957 | { |
asong | 14:c3b080cdf36b | 4958 | |
asong | 14:c3b080cdf36b | 4959 | uint32_t peak; |
asong | 14:c3b080cdf36b | 4960 | |
asong | 14:c3b080cdf36b | 4961 | for(int i = 0; i < 100; i++) |
asong | 14:c3b080cdf36b | 4962 | { |
asong | 14:c3b080cdf36b | 4963 | hr_data[i] = readFIFO(); |
asong | 20:990951205fbd | 4964 | } |
asong | 14:c3b080cdf36b | 4965 | |
asong | 14:c3b080cdf36b | 4966 | |
asong | 14:c3b080cdf36b | 4967 | peak = isPeak(hr_data); |
asong | 14:c3b080cdf36b | 4968 | |
asong | 14:c3b080cdf36b | 4969 | uint8_t hr = (uint8_t)((60 * peak * 50)/ 100); |
asong | 14:c3b080cdf36b | 4970 | if(hr >= HR_Zone1[0] && hr <= HR_Zone4[1]) |
asong | 14:c3b080cdf36b | 4971 | { |
asong | 14:c3b080cdf36b | 4972 | Heart_Rate = hr; |
asong | 20:990951205fbd | 4973 | |
asong | 14:c3b080cdf36b | 4974 | } |
asong | 14:c3b080cdf36b | 4975 | Determine_Current_Zone(); |
asong | 14:c3b080cdf36b | 4976 | |
asong | 14:c3b080cdf36b | 4977 | |
asong | 14:c3b080cdf36b | 4978 | } |
asong | 14:c3b080cdf36b | 4979 | |
asong | 14:c3b080cdf36b | 4980 | uint32_t isPeak(uint32_t hr_array[]) |
asong | 14:c3b080cdf36b | 4981 | { |
asong | 14:c3b080cdf36b | 4982 | uint32_t peaks[100]; |
asong | 14:c3b080cdf36b | 4983 | uint32_t numPeaks = 0; |
asong | 14:c3b080cdf36b | 4984 | uint32_t index = 0; |
asong | 14:c3b080cdf36b | 4985 | uint32_t currentPeak = 0; |
asong | 14:c3b080cdf36b | 4986 | |
asong | 14:c3b080cdf36b | 4987 | for(int i = 1; i < 100; i++) |
asong | 14:c3b080cdf36b | 4988 | { |
asong | 14:c3b080cdf36b | 4989 | if((hr_array[i] > hr_array[i + 1]) && (hr_array[i] > hr_array[i - 1])) |
asong | 14:c3b080cdf36b | 4990 | { |
asong | 14:c3b080cdf36b | 4991 | peaks[index] = hr_array[i]; |
asong | 14:c3b080cdf36b | 4992 | numPeaks++; |
asong | 14:c3b080cdf36b | 4993 | index++; |
asong | 14:c3b080cdf36b | 4994 | } |
asong | 14:c3b080cdf36b | 4995 | } |
asong | 14:c3b080cdf36b | 4996 | if(numPeaks > 0) |
asong | 14:c3b080cdf36b | 4997 | { |
asong | 14:c3b080cdf36b | 4998 | currentPeak = peaks[0]; |
asong | 14:c3b080cdf36b | 4999 | for(int i = 0; i < numPeaks; i++) |
asong | 14:c3b080cdf36b | 5000 | { |
asong | 14:c3b080cdf36b | 5001 | if(currentPeak < peaks[i]) |
asong | 14:c3b080cdf36b | 5002 | { |
asong | 14:c3b080cdf36b | 5003 | currentPeak = peaks[i]; |
asong | 14:c3b080cdf36b | 5004 | } |
asong | 14:c3b080cdf36b | 5005 | } |
asong | 14:c3b080cdf36b | 5006 | } |
asong | 14:c3b080cdf36b | 5007 | |
asong | 14:c3b080cdf36b | 5008 | return currentPeak; |
asong | 14:c3b080cdf36b | 5009 | } |