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