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