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
Diff: main.cpp
- Revision:
- 9:d2e39ee9fedd
- Parent:
- 8:a5c77b45008d
- Child:
- 10:eaea844e763c
diff -r a5c77b45008d -r d2e39ee9fedd main.cpp --- a/main.cpp Mon Feb 19 05:11:42 2018 +0000 +++ b/main.cpp Tue Mar 06 00:22:47 2018 +0000 @@ -1,7 +1,27 @@ /********************************************************************** -Texas State University Senior Project - HexiHeart +Texas State University Senior Project - HexiHeart Team Zeta: Alex Song, Jasmine Rounsaville, Issam Hichami, Neil Baker -Version: HexiHeart_1st 11/12/17 + +Program layout: +Declarations +Up Button routines +Down Button routines +Right Button routines +Left Button routines +Main() +Main display screen routines +Function and interupt routines +Display data screen update routines + +v2.08 - Fixed impact detect functionality, all fall detect parameters are now adjustable, +added motion detect function, incorporated new heat index calc, increased font by 20% for time/date. +Added SW and power resetting to initialize sensors in known state. + +v2.07 - 2/18/18 - Added fall mode option to test fall/impact separately, Added global +interrupt disable prevent button interrupts while refreshing screen, this caused haptic +timer to stop working right. + +v1.0 - 11/12/17 This version has basic menu layout and screen timeout feature. The menu are just placeholders (for the most part) and will be either adjusted or replaced with graphic images. @@ -10,26 +30,23 @@ #include "mbed.h" #include "Hexi_KW40Z.h" // Button and BLE fuctions -#include "FXOS8700.h" // 3D Accelorometer & Mag -#include "FXAS21002.h" // 3-Axis Gyroscope +#include "FXOS8700.h" // Freescale/NXP FXOS8700CQ - 3D Accelorometer & Mag +#include "FXAS21002.h" // Freescale/NXP FXAS21002CQ - 3-Axis Gyroscope +//#include "MPL3115A2.h" // Freescale/NXP MPL3115A2 - pressure sensor +#include "HTU21D.h" // Non-Freescale/NXP - HTU21D - combo temperature and Humidity +#include "W25Q64FV.h" // Non-Freescale/NXP - W25Q64FVSSIG - 8MB/64Mbit Serial Flash memory +#include "MAX30101.h" // Non-Freescale MAX30101 - Optical Heart rate sensor +//#include "TSL2561.h" // Non-Freescale/NXP TSL2561 - light sensor +#include "Hexi_Battery/hexi_battery.h" // Battery status #include "Hexi_OLED_SSD1351.h" // OLED fuctions -#include "HTU21D.h" // Non-Freescale HTU21D - combo temperature and Humidity -#include "W25Q64FV.h" // W25Q64FVSSIG Serial Flash - // Non-Freescale MPL3115A2 - pressure sensor -#include "Hexi_Battery/hexi_battery.h" // Battery status #include "OLED_types.h" // Text attributs #include "string.h" #include "OpenSans_Font.h" -#include "MAX30101.h" // Non-Freescale MAX30101 - Optical Heart rate sensor +#include "images.h" -/* We need to confirm whether it's better to include and -configure every module for lowest power, or whether it's -better to save memory by not doing that -*/ - // Definitions -#define SW_Ver 2.07 // For displaying software version +#define SW_Ver 2.08 // For displaying software version #define LED_ON 0 #define LED_OFF 1 #define SCRN_TIME 10.0 @@ -42,12 +59,14 @@ #define EXIT_ABOVE 100 #define VIB_OPT_2 75 #define FXOS8700_I2C_ADDRESS_ (0x1E<<1) //pins SA0,SA1=0 - +#define FXAS21002_I2C_ADDRESS_ 0x40 // +//#define TSL2561_I2C_ADDRESS_ (0x29 << 1) // Address select line is grounded +//#define MPL3115A2_I2C_ADDRESS_ ? // void StartHaptic(void); void StartHaptic(int x); void StopHaptic(void const *n); -void error_screen(void); +void error_screen(void); // display error screen void update_display(void);// Screen lables refreshed void update_display_date(void); // Screen data(only)refreshed void Decrement_Age(); @@ -67,10 +86,16 @@ void Led_Zone_Indicator(); void Heat_Index_Calculation(); void fall_config(uint8_t); +void gyro_sensor_config(uint8_t); +void light_config(uint8_t); +void press_config(uint8_t); void fall_detect(void); void fall_det_end(void); void fall_detect_off(void); void impact_detect(void); +void motion_detect(); +void MAX30101_test_config(uint8_t); + // ***************** Global variables *********************** char text_1[20]; // Text buffer - Do we need more? @@ -83,7 +108,7 @@ bool OLED_ON = 1; // Turn OLED power on/off bool Fall_Alert = 1; // Initialize as no active alert bool Panic_Alert = 0; // Initialize as no active alert -uint8_t Fall_Alert_Mode = 1; // Initialize with fall alert mode on +uint8_t Fall_Alert_Mode = 4; // Initialize with fall alert mode on bool Heart_Rate_Mode = 0; // Initialize with Heart rate off float Accel_Mag=0.0; // Vector magnitude calculated from sensor data float Accel_Data[3]; // Accel Data from sensor @@ -93,6 +118,8 @@ float Fall_Thresh=0.5; // Initialize Fall detect Threshold float Impact_Thresh=3.0; // Initialize Impact detect Threshold float Movement_Thresh=50.0; // Initialize Movement detect Threshold +float Min_Movement_Time=5.0; // Initialize Movement minimum movement time to 5 sec +float Min_Movement_duration=60.0; // Initialize Movement min-movement testing duration to 60 sec uint8_t Current_Zone = 1; uint8_t Prev_Zone = 1; uint8_t Heart_Rate = 100; @@ -108,20 +135,39 @@ uint8_t HR_Zone2[2] = {HR_Zone1[1] + 1, Max_Bpm * .70}; //Heart Rate Zone 2 uint8_t HR_Zone3[2] = {HR_Zone2[1] + 1, Max_Bpm * .80}; //Heart Rate Zone 3 uint8_t HR_Zone4[2] = {HR_Zone3[1] + 1, Max_Bpm}; //Heart Rate Zone 4 -int sample_ftemp; -int sample_humid; -int heat_index; +int sample_ftemp; // used in Heat index calc +int sample_humid; // used in Heat index calc +int heat_index; // used in Heat index calc +int hi_calc; // used in Heat index calc +int adjustment; // used in Heat index calc + +// Pointers for screen images +const uint8_t *Hexi_Heart_ = Hexi_Heart_bmp; +//const uint8_t *NB_Linkedin = NB_Linkedin_bmp; +//const uint8_t *AS_Linkedin = NB_Linkedin_bmp; +//const uint8_t *IR_Linkedin = NB_Linkedin_bmp; +//const uint8_t *IH_Linkedin = NB_Linkedin_bmp; + // ***************** Define pins ***************************** -FXAS21002 gyro(PTC11,PTC10); // Gyroscope -SSD1351 oled(PTB22,PTB21,PTC13,PTB20,PTE6, PTD15); // SSD1351 OLED Driver (MOSI,SCLK,POWER,CS,RST,DC) -FXOS8700 accel(PTC11, PTC10); // Accelorometer -FXOS8700 mag(PTC11, PTC10); // Mag (same chip as Accel) -//MAX30101 heart(PTB1, PTB0); //Heart Rate Chip -HTU21D temphumid(PTB1,PTB0); // HTU21D Sensor +//W25Q64FVSSIG - 8MB/64Mbit Serial Flash memory (SPI1)(MOSI,SCLK,POWER,CS,RST,DC) +//W25Q64FV(PinName mosi, PinName miso, PinName sclk, PinName cs, int frequency=10000000); +//MKW40Z (SPI1) +SSD1351 oled(PTB22,PTB21,PTC13,PTB20,PTE6, PTD15); // SSD1351 OLED Driver SPI2(MOSI,SCLK,POWER,CS,RST,DC) +FXAS21002 gyro(PTC11,PTC10); // Gyroscope (I2C1 data bus(SDA, SCL)) +FXOS8700 accel(PTC11, PTC10); // Accelorometer (I2C1 data bus(SDA, SCL)) +FXOS8700 mag(PTC11, PTC10); // Mag (same chip as Accel) (I2C1 data bus(SDA, SCL)) +//MAX30101 heart(PTB1, PTB0); //Heart Rate Chip (I2C0 data bus(SDA, SCL)) +HTU21D temphumid(PTB1,PTB0); // HTU21D Sensor (I2C0 data bus(SDA, SCL)) +//TSL2561 - (PTB1, PTB0); //Amb light sensor (I2C0 data bus(SDA, SCL)) // initialize I2C bus for FXOS8700, FXAS-Gyro, MPL-Pressure I2C i2c_bus1(PTC11, PTC10); // (SDA, SCL) +// initialize I2C bus for MAX30101, HTU21D, TSL2561 + I2C i2c_bus0(PTB1, PTB0); // (SDA, SCL) + +// initialize SPI bus for W25Q64FVSSIG, (and MKW40Z if needed) +// SPI spi_bus1(PTD6, PTD7, PTD5); // (MOSI, MISO, SCLK) CS=PTD4?(low=select) DigitalOut RED_Led(LED1); DigitalOut GRN_Led(LED2); @@ -131,10 +177,9 @@ DigitalOut Led_clk2(PTA13); DigitalOut Led_clk3(PTA14); -DigitalOut OLED_PWR(PTC13); // this pin turns on/off 15V to OLED display -DigitalOut Non_Free_PWR(PTB13); // this pin turns on/off non-freescale sensors (Pres/Temp/Hum/Light) -DigitalOut powerEN (PTB12); // Power Enable HTU21D Sensor -DigitalOut HR_PWR(PTA29); // this pin turns on/off Heart rate sensor +DigitalOut OLED_PWR(PTC13); // this pin turns on/off 15V supply to OLED display +DigitalOut PowerEN (PTB12); // 3V3B Power Enable for HTU21D (Temp/Hum sensor) and Light sensor Sensor supply +DigitalOut HR_PWR(PTA29); // this pin turns on/off power to heart rate sensor //DigitalIn Sw1(PTA12); //Switch 'T1' on docking station AND Led_clk1!! //DigitalIn Sw2(PTA13); //Switch 'T2' on docking station AND Led_clk2!! DigitalIn Sw3(PTA15); //Switch 'T3' on docking station @@ -147,17 +192,35 @@ RtosTimer hapticTimer(StopHaptic, osTimerOnce); //***************** Interrups ***************** -InterruptIn Accel_INT1(PTC1); // Accel sensor's interupt 1 -InterruptIn Accel_INT2(PTD13); // Accel sensor's interupt 2 +InterruptIn Accel_INT1(PTC1); // Accel sensor's interupt 1 +InterruptIn Accel_INT2(PTD13); // Accel sensor's interupt 2 +InterruptIn Gyro_INT1(PTD1); // Gyro sensor's interupt 1 +InterruptIn Gyro_INT2(PTC18); // Gyro sensor's interupt 2 +//InterruptIn Amb_Light_INT1(PTC0); // TSL2561- Light sensor's interupt +//InterruptIn HR_INT1(PTB18); // MAX30101 - Heart rate sensor's interupt +//InterruptIn Pressure_INT1(PTD12); // MPL3115A2 pressure sensor's interupt 1 +//InterruptIn Pressure_INT2(PTD10); // MPL3115A2 pressure sensor's interupt 2 //***************** Tickers and Timers ***************** Ticker Screen_Timer;// use ticker to turn off OLED void timout_timer(){ // turn off display mode +#ifdef Debug // in debug keep screens on for demo + HexiwearBattery battery; + battery.sensorOn(); + + if (battery.isBatteryCharging() || (uint8_t)battery.readLevelPercent()> 99) { + Screen_Timer.attach(&timout_timer,(SCRN_TIME));// Reset/restart ticker timer for OLED while fully charged + } //end if + else { +#endif // oled.FillScreen(COLOR_BLACK); // Clear screen.. is there a better command for this? OLED_PWR = 0; // Turn off OLED power supply OLED_ON = 0; // set flag to off Screen_Timer.detach(); // detach Ticker +#ifdef Debug // in debug keep screens on for demo + } // endelse +#endif }//end routine void ButtonUp(void) @@ -310,16 +373,19 @@ break; } - case 41: {//Fall mode 0,1,2,3 + case 41: {//Fall mode 0,1,2,3,4 + // 0=nothing, 1=fall_only, 2=impact only, 3=motion_only, 4=all StartHaptic(); Fall_Alert_Mode++; - if(Fall_Alert_Mode > 3){ + if(Fall_Alert_Mode > 4){ Fall_Alert_Mode = 0; }//endif update_display(); __disable_irq(); // Disable all Interrupts - fall_config(10); // reset sensor + fall_config(10); // reset accel sensor + gyro_sensor_config(10); // reset gyro sensor wait(0.1); + gyro_sensor_config(Fall_Alert_Mode); // leave gyro sensor active fall_config(Fall_Alert_Mode); wait(0.1); __enable_irq(); // Enable all Interrupts @@ -329,8 +395,8 @@ } case 42: {// F-Th adj StartHaptic(); - Fall_Thresh = Fall_Thresh + 0.05; - if(Fall_Thresh > 0.9){ + Fall_Thresh = Fall_Thresh + 0.05f; + if(Fall_Thresh > 0.9f){ Fall_Thresh = 0.9; }//endif update_display(); @@ -338,8 +404,8 @@ } case 43: {// I-Th adj StartHaptic(); - Impact_Thresh = Impact_Thresh + 0.1; - if(Impact_Thresh > 3.9){ + Impact_Thresh = Impact_Thresh + 0.1f; + if(Impact_Thresh > 3.9f){ Impact_Thresh = 3.9; }//endif update_display(); @@ -347,13 +413,31 @@ } case 44: {// M-Th adj StartHaptic(); - Movement_Thresh = Movement_Thresh + 5.0; - if(Movement_Thresh > 300.0){ + Movement_Thresh = Movement_Thresh + 5.0f; + if(Movement_Thresh > 300.0f){ Movement_Thresh = 300.0; }//endif update_display(); break; } + case 45: {// Min_Movement_Time adj + StartHaptic(); + Min_Movement_Time = Min_Movement_Time + 0.1f; + if(Min_Movement_Time > 2.4f){ + Min_Movement_Time = 2.4; + }//endif + update_display(); + break; + } + case 46: {// Min_Movement_duration adj + StartHaptic(); + Min_Movement_duration = Min_Movement_duration + 5.0f; + if(Min_Movement_duration > 300.0f){ + Min_Movement_duration = 300.0; + }//endif + update_display(); + break; + } case 71: {// BLE StartHaptic(); @@ -525,14 +609,18 @@ break; } case 41: {//Fall mode 0,1,2,3 + // 0=nothing, 1=fall_only, 2=impact only, 3=motion_only, 4=all + StartHaptic(); Fall_Alert_Mode--; if(Fall_Alert_Mode > 3){// should be 0xff if decr from zero Fall_Alert_Mode = 3; } //endif update_display(); __disable_irq(); // Disable all Interrupts - fall_config(10); // reset sensor + fall_config(10); // reset accel sensor + gyro_sensor_config(10); // reset gyro sensor wait(0.1); + gyro_sensor_config(Fall_Alert_Mode); // leave gyro sensor active fall_config(Fall_Alert_Mode); wait(0.1); __enable_irq(); // Enable all Interrupts @@ -542,8 +630,8 @@ } case 42: {// F-Th adj StartHaptic(); - Fall_Thresh = Fall_Thresh - 0.05; - if(Fall_Thresh < 0.1){ + Fall_Thresh = Fall_Thresh - 0.05f; + if(Fall_Thresh < 0.1f){ Fall_Thresh = 0.1; }//endif update_display(); @@ -551,8 +639,8 @@ } case 43: {// I-Th adj StartHaptic(); - Impact_Thresh = Impact_Thresh - 0.1; - if(Impact_Thresh < 0.9){ + Impact_Thresh = Impact_Thresh - 0.1f; + if(Impact_Thresh < 0.9f){ Impact_Thresh = 0.9; }//endif update_display(); @@ -560,14 +648,32 @@ } case 44: {// M-Th adj StartHaptic(); - Movement_Thresh = Movement_Thresh - 5.0; - if(Movement_Thresh < 5.0){ + Movement_Thresh = Movement_Thresh - 5.0f; + if(Movement_Thresh < 5.0f){ Movement_Thresh = 5.0; }//endif update_display(); break; } - + case 45: {// Min_Movement_Time adj + StartHaptic(); + Min_Movement_Time = Min_Movement_Time - 0.1f; + if(Min_Movement_Time < 0.5f){ + Min_Movement_Time = 0.5; + }//endif + update_display(); + break; + } + case 46: {// Min_Movement_duration adj + StartHaptic(); + Min_Movement_duration = Min_Movement_duration - 5.0f; + if(Min_Movement_duration < 5.0f){ + Min_Movement_duration = 5.0; + }//endif + update_display(); + break; + } + case 71: {// BLE StartHaptic(); Screen_Num = 2; //Change to screen 2 @@ -721,9 +827,22 @@ break; } case 44: {// M-Th adj - // do nothing for now + StartHaptic(); + Screen_Num = 45; //Change to screen 44 + update_display(); break; } + case 45: {// Min_time adj + StartHaptic(); + Screen_Num = 46; //Change to screen 44 + update_display(); + break; + } + case 46: {// Time_dur adj + //do nothing for now + break; + } + case 71: {// BLE StartHaptic(); Screen_Num = 72; //Change to screen 72 @@ -923,7 +1042,20 @@ Screen_Num = 43; //Change to screen 43 update_display(); break; - } + } + case 45: {// M-time adj + StartHaptic(); + Screen_Num = 44; //Change to screen 44 + update_display(); + break; + } + case 46: {// M-dur adj + StartHaptic(); + Screen_Num = 45; //Change to screen 45 + update_display(); + break; + } + case 71: {// BLE StartHaptic(); Screen_Num = 0; //Change to screen 0 @@ -961,32 +1093,53 @@ int main() { // set_time(1256729737); // Set RTC time to Wed, 28 Oct 2009 11:35:37 - set_time(48*365*24*3600+61*24*3600+10*3600-4); // Set RTC time to Mon, 19 Feb 2018 10:00 - OLED_PWR = 1; // Turn on OLED power supply + // 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 + // set_time(48*365*24*3600 + 61*24*3600 + 10*3600-4); // Set RTC time to Mon, 19 Feb 2018 10:00 + set_time((2018-1970)*365.25f*24*3600 + (31+28+1-1)*24*3600 + (16)*3600 + (5)*60+ (1) + 38); // Set RTC time + RED_Led = LED_OFF; + GRN_Led = LED_OFF; + BLU_Led = LED_OFF; + Led_clk1 = 0; // LEDs on docking station default to off, need to turn on with a 1 + Led_clk2 = 0; // LEDs on docking station default to off, need to turn on with a 1 + Led_clk3 = 0; // LEDs on docking station default to off, need to turn on with a 1 +// ***************** Reset sensors *********************** + OLED_PWR = 0; // Turn off OLED power supply + PowerEN = 1; // Turn off (=1)HTU21(Temp/Hum) and TSL2561(Light) sensors to reset them + HR_PWR = 0; // Turn off (=0) Heart rate sensor 1.8V and HRM(3.3V) supply to reset + wait(0.2); // how long should we wait for sensors to power down? - oled.FillScreen(COLOR_BLACK); // Clear screen + PowerEN = 0; // Turn on (=0) HTU21(Temp/Hum) and TSL2561(Light) sensors to reset them + HR_PWR = 1; // Turn on (=1)Heart rate sensor + OLED_PWR = 1; // Turn on OLED power supply + wait(0.2); // how long should we wait for sensors to power up? + + oled.FillScreen(COLOR_BLACK); // Clear screen + fall_config(10); // SW reset accell sensor + gyro_sensor_config(10); // SW reset gyro sensor + press_config(0); // put pressure sensor into 2uA standby, we're not using it + MAX30101_test_config(10); // SW reset accell sensor + oled.FillScreen(COLOR_BLACK); // Clear screen + // ***************** Local variables *********************** // float accel_data[3]; float accel_rms=0.0; int i; // ************** configure sensor modules ****************** - // accel.accel_config(); // configure sensor - // fall_config(1); // configure sensor for fall detect - fall_config(Fall_Alert_Mode); // configure sensor for current fall mode -// mag.mag_config(); - gyro.gyro_config(); - RED_Led = LED_OFF; - GRN_Led = LED_OFF; - BLU_Led = LED_OFF; - Led_clk1 = 0; // LEDs on docking station default to off, need to turn on with a 1 - Led_clk2 = 0; // LEDs on docking station default to off, need to turn on with a 1 - Led_clk3 = 0; // LEDs on docking station default to off, need to turn on with a 1 - Non_Free_PWR = 1; // Start with non-freescale sensors (Pres/Temp/Hum/Light)on +// accel.accel_config(); // original configure accel sensor + fall_config(Fall_Alert_Mode); // configure sensor (I2C1) for current fall mode + //Fall_Alert_Mode: 0=none, 1=fall_only, 2=impact only, 3=motion_only, 4=all +// gyro.gyro_config(); // original configure gyro sensor + gyro_sensor_config(Fall_Alert_Mode); // configure gyro sensor (I2C1) 0=standby, 1=active, 2=interupt set up +// mag.mag_config(); // we don't need mag +// light_config(0); // config TSL2561 ambient light sensor (I2C0) for lowest power - cycling PowerEn should have reset it to state +// Configure HTU21(Temp/Hum)? No need, it seems to draw 0.02uA when not being activly read over data bus - HR_PWR = 0; // Start with Heart rate sensor powered off - +// need to configure MAX30101 at some point + // MAX30101_test_config(0); + + // ***** Register callbacks/interupts to application functions ********* kw40z_device.attach_buttonUp(&ButtonUp); kw40z_device.attach_buttonDown(&ButtonDown); @@ -995,20 +1148,29 @@ // kw40z_device.attach_buttonSlide(&ButtonSlide); // ***** attaching interupts to functions ********* - Accel_INT1.fall(&fall_detect); // Accel sensor's int#1 calls interupt routine - Accel_INT2.fall(&impact_detect); //Accel sensor's int#2 calls interupt routine - + Accel_INT1.fall(&fall_detect); // Accel sensor's int#1 calls interupt routine + Accel_INT2.fall(&impact_detect); //Accel sensor's int#2 calls interupt routine + Gyro_INT1.fall(&motion_detect); // Gyro sensor's int#1 (PTD1) calls interupt routine + //Gyro_INT2.fall(&motion_detect); // Gyro sensor's int#2 (PTC18) calls interupt routine + //HR_INT1.fall(&some_HR_read_function_yet_to_be_named); // MAX30101 - Heart rate sensor's interupt // **** Get OLED Class Default Text Properties **************** oled_text_properties_t textProperties = {0}; oled.GetTextProperties(&textProperties); // *********Set text color and screen alignment ************** + //textProperties.font = OpenSans_12x18_Regular; // Max Width of Character = 12px, Max Height of Character = 18px + //textProperties.font = OpenSans_10x15_Regular; // <-This is default Font, Max Width of Character = 10px, Max Height of Character = 15px textProperties.fontColor = COLOR_WHITE; textProperties.alignParam = OLED_TEXT_ALIGN_LEFT; oled.SetTextProperties(&textProperties); // ************** Display spash screen ********************** +/* + oled.FillScreen(COLOR_BLACK); // Clear screen + oled.DrawImage(Hexi_Heart_,0,0); // my Hexi_Heart image is offset for some reason + wait(0.5); // wait 3 seconds +*/ oled.FillScreen(COLOR_BLACK); // Clear screen oled.Label((uint8_t *)"Hexi",20,5); // Display white "Hexi" at x,y textProperties.fontColor = COLOR_RED; @@ -1017,15 +1179,19 @@ #ifdef Debug // if this is non-production version - do this strcpy((char *) text_1,"This is Debug"); - oled.Label((uint8_t *)text_1,15,50); // text_1 at x,y - sprintf(text_1," Ver:%2.2f ",SW_Ver); - oled.Label((uint8_t *)text_1,30,70);// text_1 at x,y + oled.Label((uint8_t *)text_1,15,45); // text_1 at x,y + strcpy((char *) text_1,"Ver:"); + oled.Label((uint8_t *)text_1,15,60); // text_1 at x,y + sprintf(text_1,"%2.2f ",SW_Ver); + oled.Label((uint8_t *)text_1,60,60);// text_1 at x,y StartHaptic(); #endif textProperties.fontColor = COLOR_WHITE; oled.SetTextProperties(&textProperties); - wait(3); // wait 3 seconds + wait(2); // wait 3 seconds + + update_display(); // Displays current screen (screen 0) Screen_Timer.attach(&timout_timer,(SCRN_TIME));//start ticker timer for turning off LCD // ******************* Main Loop ************************* @@ -1037,6 +1203,7 @@ if(OLED_PWR==1){ update_display_date(); // refresh display date w/o updating entire display }// end if + i++; }// end while(i<20) @@ -1044,10 +1211,11 @@ RED_Led = LED_ON; // Used only for diagnostic of wait command Led_clk3 = 1; // Used only for diagnostic of wait command wait(0.01); // BLIP led 1/10 sec each loop +/// VLPW(0.01); // BLIP led 1/10 sec each loop RED_Led = LED_OFF; // Used only for diagnostic of wait command Led_clk3 = 0; Thread::wait(490); // keep up the pace, at 0.5 sec (0.01s+0.49s) update date - + } // end of while(true) } @@ -1080,8 +1248,8 @@ oled.SetTextProperties(&textProperties); oled.Label((uint8_t *)"Batt",35,0); // Display "Batt" at x,y - oled.Label((uint8_t *)"Date",35,20); // Display "Date" at x,y - oled.Label((uint8_t *)"Time",35,40); // Display "Time" at x,y +// oled.Label((uint8_t *)"Date",35,20); // Display "Date" at x,y +// oled.Label((uint8_t *)"Time",35,40); // Display "Time" at x,y // oled.Label((uint8_t *)"H.I.",10,80); // Display "H.I." at x,y oled.Label((uint8_t *)"BT",40,80); //Display "BT" at x,y @@ -1089,7 +1257,7 @@ textProperties.fontColor = COLOR_GRAY; if(BLE_On == 1){ - textProperties.fontColor = COLOR_BLUE; + textProperties.fontColor = COLOR_BLUE; // If BLE on make "BT" blue! } oled.SetTextProperties(&textProperties); @@ -1100,14 +1268,21 @@ // added real time and date information char buffer[32]; time_t seconds = time(NULL); - strftime(buffer,32, "%a,%d %m %Y.%H:%M:%S\r", localtime(&seconds)); + strftime(buffer,32, "%a,%d %m %Y.%H:%M:%S\r", localtime(&seconds)); //format local time and store in buffer + + textProperties.font = OpenSans_12x18_Regular; // Max Width of Character = 12px, Max Height of Character = 18px + textProperties.fontColor = COLOR_WHITE; + oled.SetTextProperties(&textProperties); + 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]); - oled.Label((uint8_t *)text_1,20,20);// Date at x,y + oled.Label((uint8_t *)text_1,15,25);// Date at x,y sprintf(text_1,"%c%c:%c%c:%c%c ",buffer[15],buffer[16],buffer[18],buffer[19],buffer[21],buffer[22]); oled.Label((uint8_t *)text_1,25,40);// Time at x,y - - - + + textProperties.font = OpenSans_10x15_Regular; // Max Width of Character = 10px, Max Height of Character = 15px + textProperties.fontColor = COLOR_WHITE; + oled.SetTextProperties(&textProperties); + Heat_Index_Calculation(); sprintf(text,"%i",heat_index); oled.TextBox((uint8_t *)text,3,80,15,15); //show HI in a 15px by 15px text box at x=3, y=80 @@ -1130,17 +1305,25 @@ case 2: {// Fall Alert option oled.FillScreen(COLOR_BLACK); // Clear screen oled.Label((uint8_t *)"Fall Alert",20,5); // Display at x,y - oled.Label((uint8_t *)"Protection",15,25); + oled.Label((uint8_t *)"Protection",15,20); if (Fall_Alert == 1){ - oled.Label((uint8_t *)" On ",40,40); + + textProperties.fontColor = COLOR_GREEN; + oled.SetTextProperties(&textProperties); + oled.Label((uint8_t *)" On ",32,40); } else { - oled.Label((uint8_t *)" Off ",40,40); + textProperties.fontColor = COLOR_GRAY; + oled.SetTextProperties(&textProperties); + oled.Label((uint8_t *)" Off ",30,40); + } + textProperties.fontColor = COLOR_WHITE; + oled.SetTextProperties(&textProperties); oled.Label((uint8_t *)"*",85,15); // "*" at x,y oled.Label((uint8_t *)"*",85,60); // "*" at x,y oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y - oled.Label((uint8_t *)"Toggle",60,80); //Display "Toggle" at x,y + oled.Label((uint8_t *)"Toggle",59,80); //Display "Toggle" at x,y break; } case 3: {// Heart Rate Monitoring option @@ -1174,8 +1357,8 @@ oled.Label((uint8_t *)text_1,30,5); // text_1 at x,y oled.Label((uint8_t *)"*",85,15); // "*" at x,y oled.Label((uint8_t *)"*",85,60); // "*" at x,y - oled.Label((uint8_t *)" Back ",9,80); // Display "Back" at x,y - oled.Label((uint8_t *)" Enter ",59,80); //Display at x,y + oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y + oled.Label((uint8_t *)"Enter",60,80); //Display at x,y break; } @@ -1212,7 +1395,7 @@ oled.Label((uint8_t *)"On",80,15); // "+" at x,y oled.Label((uint8_t *)"Off",78,60); // "-" at x,y oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y - oled.Label((uint8_t *)"Next",59,80); // Display "Next" at x,y + oled.Label((uint8_t *)"Next",60,80); // Display "Next" at x,y //heart.enable(); //sprintf(display_buff, "%u", heart.getRevisionID()); //Convert int to char array for displaying user age @@ -1240,7 +1423,7 @@ textProperties.fontColor = COLOR_WHITE; oled.SetTextProperties(&textProperties); oled.Label((uint8_t *)"Senior Proj",5,15); // - oled.Label((uint8_t *)"Team Zeta E1.7",5,30); // + oled.Label((uint8_t *)"Team Zeta E2.7",5,30); // oled.Label((uint8_t *)"Texas State Univ",0,45); // oled.Label((uint8_t *)"+",85,15); // "*" at x,y oled.Label((uint8_t *)"-",85,60); // "*" at x,y @@ -1256,9 +1439,10 @@ oled.Label((uint8_t *)"Heart",45,0); // Display red "Heart" at x,y textProperties.fontColor = COLOR_WHITE; oled.SetTextProperties(&textProperties); - oled.Label((uint8_t *)"E2.7 Team Zeta",2,12); // - oled.Label((uint8_t *)"Alex Song",5,25); // - oled.Label((uint8_t *)"Jasmine Rounsav",5,38); // Jasmine Rounsaville is to long + // oled.Label((uint8_t *)"E2.7 Team Zeta",2,12); // + oled.Label((uint8_t *)"Alex Song",5,12); // + oled.Label((uint8_t *)"Jasmine ",5,24); // Jasmine Rounsaville is to long + oled.Label((uint8_t *)"Rounsaville",15,37); // Jasmine Rounsaville is to long oled.Label((uint8_t *)"Issam Hichami",5,51); // oled.Label((uint8_t *)"Neil Baker",5,64); // @@ -1303,12 +1487,12 @@ textProperties.fontColor = COLOR_RED; oled.SetTextProperties(&textProperties); oled.Label((uint8_t *)"Diagnostics",10,5); // Display at x,y - oled.Label((uint8_t *)" Enter ",59,80); //Display at x,y + oled.Label((uint8_t *)"Enter",60,80); //Display at x,y textProperties.fontColor = COLOR_WHITE; oled.SetTextProperties(&textProperties); oled.Label((uint8_t *)"*",85,15); // "*" at x,y oled.Label((uint8_t *)"*",85,60); // "*" at x,y - oled.Label((uint8_t *)" Back ",9,80); // Display "Back" at x,y + oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y break; } @@ -1331,9 +1515,9 @@ } Accel_Mag = 2*sqrt(((Accel_Data[0]*Accel_Data[0])+(Accel_Data[1]*Accel_Data[1])+(Accel_Data[2]*Accel_Data[2]))); sprintf(text_1," Accel:%2.2f g ",Accel_Mag); - oled.Label((uint8_t *)text_1,10,40);// text_1 at x,y + oled.Label((uint8_t *)text_1,5,40);// text_1 at x,y sprintf(text_1," Gyro:%4.0f D/S ",Gyro_Mag); - oled.Label((uint8_t *)text_1,10,60);// text_1 at x,y + oled.Label((uint8_t *)text_1,5,60);// text_1 at x,y oled.Label((uint8_t *)"*",85,15); // "*" at x,y oled.Label((uint8_t *)"*",85,60); // "*" at x,y oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y @@ -1349,22 +1533,22 @@ sprintf(text_1," %i ",Fall_Alert_Mode); oled.Label((uint8_t *)text_1,35,20);// text_1 at x,y textProperties.fontColor = COLOR_GRAY; - if(Fall_Alert_Mode == 1 || Fall_Alert_Mode == 3){ - textProperties.fontColor = COLOR_GREEN; + if(Fall_Alert_Mode == 1 || Fall_Alert_Mode == 4){ + textProperties.fontColor = COLOR_GREEN; } oled.SetTextProperties(&textProperties); sprintf(text_1," %1.2f g ",Fall_Thresh); oled.Label((uint8_t *)text_1,35,35);// text_1 at x,y textProperties.fontColor = COLOR_GRAY; - if(Fall_Alert_Mode == 2 || Fall_Alert_Mode == 3){ - textProperties.fontColor = COLOR_GREEN; + if(Fall_Alert_Mode == 2 || Fall_Alert_Mode == 4){ + textProperties.fontColor = COLOR_GREEN; } oled.SetTextProperties(&textProperties); sprintf(text_1," %2.2f g ",Impact_Thresh); oled.Label((uint8_t *)text_1,35,50);// text_1 at x,y textProperties.fontColor = COLOR_GRAY; - if(Fall_Alert_Mode == 3){ - //textProperties.fontColor = COLOR_GREEN; + if(Fall_Alert_Mode == 3 || Fall_Alert_Mode == 4){ + textProperties.fontColor = COLOR_GREEN; } oled.SetTextProperties(&textProperties); sprintf(text_1," %3.0f D/S ",Movement_Thresh); @@ -1377,8 +1561,8 @@ oled.Label((uint8_t *)"M-Th:",5,65); // "*" at x,y oled.Label((uint8_t *)"*",85,15); // "*" at x,y oled.Label((uint8_t *)"*",85,60); // "*" at x,y - oled.Label((uint8_t *)" Back ",9,80); // Display "Back" at x,y - oled.Label((uint8_t *)" Enter ",59,80); //Display at x,y + oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y + oled.Label((uint8_t *)"Enter",60,80); //Display at x,y break; } case 23: {// Heart Rate Diagnostic Screen @@ -1390,7 +1574,7 @@ oled.SetTextProperties(&textProperties); oled.Label((uint8_t *)"*",85,15); // "*" at x,y oled.Label((uint8_t *)"*",85,60); // "*" at x,y - oled.Label((uint8_t *)" Back ",9,80); // Display "Back" at x,y + oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y // oled.Label((uint8_t *)" Enter ",59,80); //Display at x,y break; } @@ -1403,7 +1587,7 @@ oled.SetTextProperties(&textProperties); oled.Label((uint8_t *)"*",85,15); // "*" at x,y oled.Label((uint8_t *)"*",85,60); // "*" at x,y - oled.Label((uint8_t *)" Back ",9,80); // Display "Back" at x,y + oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y // oled.Label((uint8_t *)" Enter ",59,80); //Display at x,y break; } @@ -1416,7 +1600,7 @@ oled.SetTextProperties(&textProperties); oled.Label((uint8_t *)"*",85,15); // "*" at x,y oled.Label((uint8_t *)"*",85,60); // "*" at x,y - oled.Label((uint8_t *)" Back ",9,80); // Display "Back" at x,y + oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y // oled.Label((uint8_t *)" Enter ",59,80); //Display at x,y Heat_Index_Calculation(); @@ -1792,25 +1976,58 @@ oled.Label((uint8_t *)"+",85,15); // "*" at x,y oled.Label((uint8_t *)"-",85,60); // "*" at x,y oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y - // oled.Label((uint8_t *)"Next",60,80); //Display "Next" at x,y + oled.Label((uint8_t *)"Next",60,80); //Display "Next" at x,y + textProperties.fontColor = COLOR_GREEN; + oled.SetTextProperties(&textProperties); + oled.Label((uint8_t *)display_buff,43,30); // Display at x,y + textProperties.fontColor = COLOR_WHITE; + oled.SetTextProperties(&textProperties); + break; + }//end case 44 + case 45: { //Min_Movement_Time + oled.FillScreen(COLOR_BLACK); + oled.Label((uint8_t *)"Adj MinM_Tim", 10, 5); + sprintf(display_buff, "%1.2fSec", Min_Movement_Time); //Convert int to char array for displaying mode + oled.Label((uint8_t *)"m_Tm:", 5, 30); + oled.Label((uint8_t *)"+",85,15); // "*" at x,y + oled.Label((uint8_t *)"-",85,60); // "*" at x,y + oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y + oled.Label((uint8_t *)"Next",60,80); //Display "Next" at x,y textProperties.fontColor = COLOR_GREEN; oled.SetTextProperties(&textProperties); oled.Label((uint8_t *)display_buff,43,30); // Display at x,y textProperties.fontColor = COLOR_WHITE; oled.SetTextProperties(&textProperties); break; - } + }//end case 45 + case 46: { //Min_Movement_Time + oled.FillScreen(COLOR_BLACK); + oled.Label((uint8_t *)"Adj MinM_Dur", 10, 5); + sprintf(display_buff, "%2.1fSec", Min_Movement_duration); //Convert int to char array for displaying mode + oled.Label((uint8_t *)"mDur:", 5, 30); + oled.Label((uint8_t *)"+",85,15); // "*" at x,y + oled.Label((uint8_t *)"-",85,60); // "*" at x,y + oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y + // oled.Label((uint8_t *)"Next",60,80); //Display "Next" at x,y + textProperties.fontColor = COLOR_GREEN; + oled.SetTextProperties(&textProperties); + oled.Label((uint8_t *)display_buff,43,30); // Display at x,y + textProperties.fontColor = COLOR_WHITE; + oled.SetTextProperties(&textProperties); + break; + }//end case 46 + #endif // end of non-production/debug version code case 71: {// BLE oled.FillScreen(COLOR_BLACK); // Clear screen oled.Label((uint8_t *)"BLUETOOTH",5,5); // Display at x,y - oled.Label((uint8_t *)" Enter ",59,80); //Display at x,y + oled.Label((uint8_t *)"Enter",60,80); //Display at x,y textProperties.fontColor = COLOR_WHITE; oled.SetTextProperties(&textProperties); oled.Label((uint8_t *)"*",85,15); // "*" at x,y oled.Label((uint8_t *)"*",85,60); // "*" at x,y - oled.Label((uint8_t *)" Back ",9,80); // Display "Back" at x,y + oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y break; } @@ -1833,7 +2050,7 @@ // oled.Label((uint8_t *)"*",85,15); // "*" at x,y // oled.Label((uint8_t *)"*",85,60); // "*" at x,y oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y - oled.Label((uint8_t *)"Toggle",60,80); //Display "Toggle" at x,y + oled.Label((uint8_t *)"Toggle",59,80); //Display "Toggle" at x,y break; } @@ -2220,7 +2437,7 @@ sample_humid = temphumid.sample_humid(); - heat_index = -42.379 + + hi_calc = -42.379 + 2.04901523 * sample_ftemp + 10.14333127 * sample_humid - 0.22475541 * sample_ftemp * sample_humid - @@ -2229,6 +2446,22 @@ 0.00122874 * sample_ftemp * sample_ftemp * sample_humid + 0.00085282 * sample_ftemp * sample_humid * sample_humid - 0.00000199 * sample_ftemp * sample_ftemp * sample_humid * sample_humid; + + if (sample_humid < 13 && sample_ftemp > 80 && sample_ftemp < 112){ + adjustment = ((13 - sample_humid) / 4) * sqrt((17-abs(sample_ftemp-95.0))/17); + heat_index = hi_calc - adjustment; + } + + else if (sample_humid > 85 && sample_ftemp > 80 && sample_ftemp < 87){ + adjustment = ((sample_humid - 85) / 10) * ((87 - sample_ftemp)/5); + heat_index = hi_calc + adjustment; + } + + else if (hi_calc < 80){ + heat_index = 0.5 * (sample_ftemp + 61.0 + ((sample_ftemp - 68.0) * 1.2) + (sample_humid * 0.094)); + } + + else {heat_index = hi_calc;} } /***************************************************************************** @@ -2241,18 +2474,23 @@ if(Fall_Alert == 1){ accel.acquire_accel_data_g(Accel_Data_Event); // for now just turn on display and give haptic feedback - Screen_Num = 21; //Change to screen 21 (Fall diag screen) Screen_Timer.attach(&timout_timer,(SCRN_TIME));// Reset/restart ticker timer for OLED + if (OLED_ON == 0) { OLED_ON = 1; // Scree was off, set to On - } // endif + update_display(); + } // endif + if (Screen_Num != 21){ + Screen_Num = 21; //Change to screen 21 (Fall diag screen) + update_display(); + } // endif //__disable_irq(); // Disable all Interrupts // oled.Label((uint8_t *)" Fall Detected ",05,70); // Display at x,y - update_display(); - 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]))); - sprintf(text_1,"Free-Fall:%2.2fg",Accel_Mag); - oled.Label((uint8_t *)text_1,2,5);// text_1 at x,y + + 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]))); + sprintf(text_1,"Free-Fall:%2.2fg",Accel_Mag); + oled.Label((uint8_t *)text_1,2,5);// text_1 at x,y BLU_Led = LED_ON; // LEDs default to on, need to turn off Led_clk2 = 1; // Turn LED2 on docking station on @@ -2271,6 +2509,7 @@ haptic = 0; // Turn off Haptic BLU_Led = LED_OFF; // Turn off HexiHeart Blue LED Led_clk2 = 0; // Turn off LED2 on docking station on + fall_config(21); // reads interrupts to clear old interupt // oled.Label((uint8_t *)" ",05,70); // clear display at x,y Accel_INT1.fall(&fall_detect); // Accel sensor's int#1 calls interupt routine } //end fall_det_end interupt routine @@ -2285,24 +2524,61 @@ void impact_detect(){ if(Fall_Alert == 1){ accel.acquire_accel_data_g(Accel_Data_Event); -// for now just turn on display and give haptic feedback - Screen_Num = 21; //Change to screen 21 (Fall diag screen) + haptic = 1; + Led_clk3 = 1; // Turn LED2 on docking station on + Screen_Timer.attach(&timout_timer,(SCRN_TIME));// Reset/restart ticker timer for OLED if (OLED_ON == 0) { - OLED_ON = 1; // Scree was off, set to On - } // endif - // update_display(); - - accel.acquire_accel_data_g(Accel_Data); - 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]))); - sprintf(text_1,"Impact:%2.2fg",Accel_Mag); - oled.Label((uint8_t *)text_1,3,20);// text_1 at x,y - - Led_clk3 = 1; // Turn LED2 on docking station on + OLED_ON = 1; // Screen was off, set to On + update_display(); + } // endif + + if (Screen_Num != 21){ + Screen_Num = 21; //Change to screen 21 (Fall diag screen) + update_display(); + } // endif + accel.acquire_accel_data_g(Accel_Data); + 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]))); + sprintf(text_1,"Impact:%2.2fg",Accel_Mag); + oled.Label((uint8_t *)text_1,3,20);// text_1 at x,y + wait(0.1); + Led_clk3 = 0; // Turn LED2 off docking station on + haptic = 0; }// end if }//end impact_detect interupt routine /***************************************************************************** +Name: motion_detect() +Purpose: Interupt rutine called when gyro IC has detected motion >= 50 deg/sec +in order to see if fall-impact resulted in motion-less person. +******************************************************************************/ +void motion_detect(){ + float Gyro_Data_Event[3]; // store right away to see what it was + if(Fall_Alert == 1 && Fall_Alert_Mode > 2){// only service interupt if automatic fall detect is selected by user + gyro.acquire_gyro_data_dps(Gyro_Data_Event); + Gyro_Mag = (abs(Gyro_Data_Event[0])+abs(Gyro_Data_Event[1])+abs(Gyro_Data_Event[2])); + haptic = 1; + Led_clk1 = 1; // Turn LED1 on docking station on + + Screen_Timer.attach(&timout_timer,(SCRN_TIME));// Reset/restart ticker timer for OLED + if (OLED_ON == 0) { + OLED_ON = 1; // Screen was off, set to On + update_display(); + } // endif + + if (Screen_Num != 21){ + Screen_Num = 21; //Change to screen 21 (Fall diag screen) + update_display(); + } // endif + sprintf(text_1,"Motion:%4.0f d/s",Gyro_Mag); + oled.Label((uint8_t *)text_1,3,20);// text_1 at x,y + wait(0.1); + Led_clk1 = 0; // Turn LED1 off docking station on + haptic = 0; + }// end if +}//end motion_detect interupt routine + +/***************************************************************************** Name: fall_config() Purpose: Used to set accelerometer IC's internal registers to set up chip level interrupts @@ -2310,18 +2586,15 @@ Returns: None ******************************************************************************/ -void fall_config(uint8_t Num){ +void fall_config(uint8_t Num){ // this is more than just accel config // use case switches here to configure for switch(Num) { case 0: {// put in standby char d[2]; d[0] = FXOS8700_CTRL_REG1; //Puts device in Standby mode d[1] = 0x00; - i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2); - + i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2); /*For lowest power ~8uA, set ODR-12.5Hz,(low-pwr accel mode) or 2uA in standby mode */ - oled.Label((uint8_t *)" Mode 0 ",30,60); // Display "mode" at x,y - oled.Label((uint8_t *)" No Int",30,75); // Display "mode" at x,y break; }// end of case 0 @@ -2330,14 +2603,14 @@ d[0] = 0x2a; //0x2a Config reg1 d[1] = 0x00; //Put device in Standby mode if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ - oled.Label((uint8_t *)" Step1 error ",30,05); // Display "error" at x,y + oled.Label((uint8_t *)"Acc1a err",30,05); // Display "error" at x,y wait(3.0); // display for 3 seconds }//end if d[0] = 0x0e; //XYZ_DATA_CFG (set full-scall range) d[1] = 0b00000001; //Set data to default range of +/-2g for full range (2x0.488mg/LSB), High-pass filter off if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ - oled.Label((uint8_t *)" Step1a error ",30,05); // Display "error" at x,y + oled.Label((uint8_t *)"Acc1b err",30,05); // Display "error" at x,y wait(3.0); // display for 3 seconds }//end if /* @@ -2351,64 +2624,68 @@ d[0] = 0x15; //A_FFMT_CFG (address of Free fall trigger config reg), write in Standby only d[1] = 0b00111000; //set to freefall, and look at all axis. if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ - oled.Label((uint8_t *)" Step3 error ",30,05); // Display "error" at x,y + oled.Label((uint8_t *)"Acc1c err",30,05); // Display "error" at x,y wait(3.0); // display for 3 seconds }//end if d[0] = 0x17; //A_FFMT_THS (address of Free fall threshold reg), write in Active or Standby - d[1] = 0b00001000; //set freefall threshold to about 756mg for now - // d[1] = uint8_t(1000*Fall_Thresh/63); //set freefall threshold - Resolution is 63mg/LSB, 0b111_1111 is maximum value + // d[1] = 0b00001000; //set freefall threshold to about 756mg for now + d[1] = (uint8_t)(1000*Fall_Thresh/63); //set freefall threshold - Resolution is 63mg/LSB, 0b111_1111 is maximum value if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ - oled.Label((uint8_t *)" Step4 error ",30,05); // Display "error" at x,y + oled.Label((uint8_t *)"Acc1d err",30,05); // Display "error" at x,y wait(3.0); // display for 3 seconds }//end if d[0] = 0x18; //A_FFMT_COUNT (address of Free fall debounce counter), write in Active or Standby d[1] = 0b00000110; //with ODR at 100Hz, should equal 60mS debounce time or 120mS in Sleep if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ - oled.Label((uint8_t *)" Step5 error ",30,05); // Display "error" at x,y + oled.Label((uint8_t *)"Acc1e err",30,05); // Display "error" at x,y wait(3.0); // display for 3 seconds }//end if d[0] = 0x2b; //CTRL_REG2 (address of control reg), write in Standby only - d[1] = 0b00001101; //Turns Auto-Sleep mode on and low-noise, low power + // d[1] = 0b00001101; //Turns Auto-Sleep mode on and low-noise, low power + d[1] = 0b00001001; //Turns Auto-Sleep mode off (b/c it wasn't waking on int) and low-noise, low power if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ - oled.Label((uint8_t *)" Step6 error ",30,05); // Display "error" at x,y + oled.Label((uint8_t *)"Acc1f err",30,05); // Display "error" at x,y wait(3.0); // display for 3 seconds }//end if d[0] = 0x2c; //CTRL_REG3 (address of Int control reg), write in Standby only d[1] = 0b00001000; //FFMT will wake chip from sleep, int are active high if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ - oled.Label((uint8_t *)" Step7 error ",30,05); // Display "error" at x,y + oled.Label((uint8_t *)"Acc1g err",30,05); // Display "error" at x,y wait(3.0); // display for 3 seconds }//end if d[0] = 0x2d; //CTRL_REG4 (address of Int enable reg), write in Standby only - d[1] = 0b00000100; // FFMT int enabled and for debug I'm using a sleep int + d[1] = 0b10000100; // FFMT int enabled and for debug I'm using a sleep int if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ - oled.Label((uint8_t *)" Step8 error ",30,05); // Display "error" at x,y + oled.Label((uint8_t *)"Acc1h err",30,05); // Display "error" at x,y wait(3.0); // display for 3 seconds }//end if d[0] = 0x2e; //CTRL_REG5 (Int routing reg), write in Standby only d[1] = 0b00000100; // Make FFMT int output on pin INT1(PTC1) if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ - oled.Label((uint8_t *)" Step9 error ",30,05); // Display "error" at x,y + oled.Label((uint8_t *)"Acc1i err",30,05); // Display "error" at x,y wait(3.0); // display for 3 seconds }//end if + d[0] = 0x29; //ASLP_Count (counter used to go to sleep reg), write in Standby only + d[1] = 0b00001010; // 10*320mS=3.2S of no inturrupts to go to sleep + if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ + oled.Label((uint8_t *)"Acc1j err",30,05); // Display "error" at x,y + wait(3.0); // display for 3 seconds + }//end if + d[0] = 0x2a; //0x2a Config reg1, write in Standby only except for bit[0] d[1] = 0b00011001; //Auto-Sleep mode on set to 50Hz, ODR set to 100Hz Puts device back into Active mode if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ - oled.Label((uint8_t *)" Step10 error ",30,05); // Display "error" at x,y + oled.Label((uint8_t *)"Acc1k err",30,05); // Display "error" at x,y wait(3.0); // display for 3 seconds }//end if - - //oled.FillScreen(COLOR_BLACK); // Clear screen - oled.Label((uint8_t *)" Mode 1 ",30,60); // Display "mode" at x,y - oled.Label((uint8_t *)" FF ",30,75); // Display "mode" at x,y - + break; }// end of case 1 @@ -2418,14 +2695,14 @@ d[0] = FXOS8700_CTRL_REG1; //Config reg1 0x2a d[1] = 0x00; //Put device in Standby mode if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ - oled.Label((uint8_t *)" Step1 error ",30,05); // Display "error" at x,y + oled.Label((uint8_t *)"Acc2a err",30,05); // Display "error" at x,y wait(3.0); // display for 3 seconds }//end if d[0] = 0x0e; //XYZ_DATA_CFG (set full-scall range) d[1] = 0b00000001; //Set data to +/-4g for full range (0.488mg/LSB), High-pass filter off if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ - oled.Label((uint8_t *)" Step1a error ",30,05); // Display "error" at x,y + oled.Label((uint8_t *)"Acc2b err",30,05); // Display "error" at x,y wait(3.0); // display for 3 seconds }//end if /* @@ -2439,39 +2716,41 @@ d[0] = 0x5f; //A_VECM_CFG (address of Vector config reg), write in Standby only d[1] = 0b00111000; //Use reference values, don't update ref, enable. if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ - oled.Label((uint8_t *)" Step3 error ",30,05); // Display "error" at x,y + oled.Label((uint8_t *)"Acc2c err",30,05); // Display "error" at x,y wait(3.0); // display for 3 seconds }//end if d[0] = 0x60; //A_VECM_MSB (address of Vector threshold reg), write in Active or Standby - d[1] = 0b00000111; //set impact threshold to less than 1g for now - // d[1] = uint8_t((1000*Impact_Thresh/0.488)/256); //set MSB Impact threshold - Resolution is 0.488mg/LSB so 0.5g=1024.6 => MSB=0b00000100 LSB=0b00000000 + // d[1] = 0b00000111; //set impact threshold to less than 1g for now + 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 if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ - oled.Label((uint8_t *)" Step4a error ",30,05); // Display "error" at x,y + oled.Label((uint8_t *)"Acc2d err",30,05); // Display "error" at x,y wait(3.0); // display for 3 seconds }//end if d[0] = 0x61; //A_VECM_LSB (address of Vector threshold reg), write in Active or Standby - d[1] = 0b00000011; //set impact threshold to less than 1g for now - // d[1] = uint8_t(256*((1000*Impact_Thresh/0.488)%256)); //set MSB Impact threshold - Resolution 0.488mg/LSB so 0.5g=1024.6 => MSB=0b00000100 LSB=0b00000000 +// d[1] = 0b00000011; //set impact threshold to less than 1g for now + d[1] = (uint8_t)(1000*Impact_Thresh/0.488f); + d[1] = (uint8_t)(d[1]%256); //set MSB Impact threshold - Resolution 0.488mg/LSB so 0.5g=1024.6 => MSB=0b00000100 LSB=0b00000000 if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ - oled.Label((uint8_t *)" Step4b error ",30,05); // Display "error" at x,y + oled.Label((uint8_t *)"Acc2e err",30,05); // Display "error" at x,y wait(3.0); // display for 3 seconds - }//end if + }//end if d[0] = 0x62; //A_VECM_COUNT (address of Vector debounce counter), write in Active or Standby d[1] = 0b00000110; //with ODR at 100Hz, should equal ??mS debounce time or ??mS in Sleep if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ - oled.Label((uint8_t *)" Step5 error ",30,05); // Display "error" at x,y + oled.Label((uint8_t *)"Acc2f err",30,05); // Display "error" at x,y wait(3.0); // display for 3 seconds }//end if // Registers 0x63 - 0x68 are vector reference values which I'm leaving set to 0 because we want absolute measurements d[0] = 0x2b; //CTRL_REG2 (address of control reg), write in Standby only - d[1] = 0b00001101; //Turns Auto-Sleep mode on and low-noise, low power + // d[1] = 0b00001101; //Turns Auto-Sleep mode on and low-noise, low power + d[1] = 0b00001001; //Turns Auto-Sleep mode off (b/c it wasn't waking on int) and low-noise, low power if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ - oled.Label((uint8_t *)" Step6 error ",30,05); // Display "error" at x,y + oled.Label((uint8_t *)"Acc2g err",30,05); // Display "error" at x,y wait(3.0); // display for 3 seconds }//end if @@ -2479,53 +2758,80 @@ d[1] = 0b00000100; //Vector will wake chip from sleep, int are active high // d[1] = 0b00001000; //FFMT will wake chip from sleep, int are active high if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ - oled.Label((uint8_t *)" Step7 error ",30,05); // Display "error" at x,y + oled.Label((uint8_t *)"Acc2h err",30,05); // Display "error" at x,y wait(3.0); // display for 3 seconds }//end if d[0] = 0x2d; //CTRL_REG4 (address of Int enable reg), write in Standby only - d[1] = 0b00000010; // Vector int enabled + d[1] = 0b10000010; // Vector int enabled // d[1] = 0b00000100; // FFMT int enabled if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ - oled.Label((uint8_t *)" Step8 error ",30,05); // Display "error" at x,y + oled.Label((uint8_t *)"Acc2i err",30,05); // Display "error" at x,y wait(3.0); // display for 3 seconds }//end if - wait(0.2); // people have had a problem here and needed a delay + //wait(0.2); // people have had a problem here and needed a delay + d[0] = 0x2e; //CTRL_REG5 (Int routing reg), write in Standby only d[1] = 0b00000100; // Make FFMT int output on pin INT1(PTC1) and Vector on INT2(PTD13) if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ - oled.Label((uint8_t *)" Step9 error ",30,05); // Display "error" at x,y + oled.Label((uint8_t *)"Acc2j err",30,05); // Display "error" at x,y wait(3.0); // display for 3 seconds }//end if + d[0] = 0x29; //ASLP_Count (counter used to go to sleep reg), write in Standby only + d[1] = 0b00001010; // 10*320mS=3.2S of no inturrupts to go to sleep + if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ + oled.Label((uint8_t *)"Acc2k err",30,05); // Display "error" at x,y + wait(3.0); // display for 3 seconds + }//end if + d[0] = FXOS8700_CTRL_REG1; //CTRL_REG1, write in Standby only except for bit[0] d[1] = 0b00011001; //Auto-Sleep mode on set to 50Hz, ODR set to 100Hz Puts device back into Active mode if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ - oled.Label((uint8_t *)" Step10 error ",30,05); // Display "error" at x,y + oled.Label((uint8_t *)"Acc2L err",30,05); // Display "error" at x,y wait(3.0); // display for 3 seconds }//end if - - //oled.FillScreen(COLOR_BLACK); // Clear screen - oled.Label((uint8_t *)" Mode 2 ",30,60); // Display "mode" at x,y - oled.Label((uint8_t *)"Imp ",30,75); // Display "mode" at x,y break; }// end of case 2 - - case 3: {// configure FFMT for free-fall event AND config for vector impact - + + case 3: {// configure for motion int only char d[2]; + d[0] = 0x2a; //0x2a Config reg1 + d[1] = 0x00; //Put device in Standby mode + if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ + oled.Label((uint8_t *)"Acc3a err",30,05); // Display "error" at x,y + wait(3.0); // display for 3 seconds + }//end if + d[0] = 0x0e; //XYZ_DATA_CFG (set full-scall range) + d[1] = 0b00000001; //Set data to default range of +/-2g for full range (2x0.488mg/LSB), High-pass filter off + if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ + oled.Label((uint8_t *)"Acc3b err",30,05); // Display "error" at x,y + wait(3.0); // display for 3 seconds + }//end if + + d[0] = 0x2a; //0x2a Config reg1, write in Standby only except for bit[0] + d[1] = 0b00011001; //Auto-Sleep mode on set to 50Hz, ODR set to 100Hz Puts device back into Active mode + if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ + oled.Label((uint8_t *)"Acc3c err",30,05); // Display "error" at x,y + wait(3.0); // display for 3 seconds + }//end if + break; + }// end of case 3 + + case 4: {// configure FFMT for free-fall event AND config for vector impact + char d[2]; d[0] = 0x2a; //0x2a Config reg1, d[1] = 0x00; //Put device in Standby mode if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ - oled.Label((uint8_t *)" Step1 error ",30,05); // Display "error" at x,y + oled.Label((uint8_t *)"Acc4a err",30,05); // Display "error" at x,y wait(3.0); // display for 3 seconds }//end if d[0] = 0x0e; //XYZ_DATA_CFG (set full-scall range) d[1] = 0b00000001; //Set data to +/-4g for full range (0.488mg/LSB), High-pass filter off if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ - oled.Label((uint8_t *)" Step1a error ",30,05); // Display "error" at x,y + oled.Label((uint8_t *)"Acc4b err",30,05); // Display "error" at x,y wait(3.0); // display for 3 seconds }//end if /* @@ -2539,105 +2845,110 @@ d[0] = 0x15; //A_FFMT_CFG (address of Free fall trigger config reg), write in Standby only d[1] = 0b00111000; //set to freefall, and look at all axis. if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ - oled.Label((uint8_t *)" Step3 error ",30,05); // Display "error" at x,y + oled.Label((uint8_t *)"Acc4c err",30,05); // Display "error" at x,y wait(3.0); // display for 3 seconds }//end if d[0] = 0x17; //A_FFMT_THS (address of Free fall threshold reg), write in Active or Standby - d[1] = 0b00001000; //set freefall threshold to about 756mg for now - // d[1] = uint8_t(1000*Fall_Thresh/63); //set freefall threshold - Resolution is 63mg/LSB, 0b111_1111 is maximum value + // d[1] = 0b00001000; //set freefall threshold to about 756mg for now + d[1] = (uint8_t)(1000*Fall_Thresh/63); //set freefall threshold - Resolution is 63mg/LSB, 0b111_1111 is maximum value if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ - oled.Label((uint8_t *)" Step4 error ",30,05); // Display "error" at x,y + oled.Label((uint8_t *)"Acc4d err",30,05); // Display "error" at x,y wait(3.0); // display for 3 seconds }//end if d[0] = 0x18; //A_FFMT_COUNT (address of Free fall debounce counter), write in Active or Standby d[1] = 0b00000110; //with ODR at 100Hz, should equal 60mS debounce time or 120mS in Sleep if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ - oled.Label((uint8_t *)" Step5 error ",30,05); // Display "error" at x,y + oled.Label((uint8_t *)"Acc4e err",30,05); // Display "error" at x,y wait(3.0); // display for 3 seconds }//end if d[0] = 0x5f; //A_VECM_CFG (address of Vector config reg), write in Standby only d[1] = 0b00111000; //Use reference values, don't update ref, enable. if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ - oled.Label((uint8_t *)" Step3 error ",30,05); // Display "error" at x,y + oled.Label((uint8_t *)"Acc4f err",30,05); // Display "error" at x,y wait(3.0); // display for 3 seconds }//end if d[0] = 0x60; //A_VECM_MSB (address of Vector threshold reg), write in Active or Standby - d[1] = 0b00000111; //set impact threshold to less than 1g for now - // d[1] = uint8_t((1000*Impact_Thresh/0.488)/256); //set MSB Impact threshold - Resolution is 0.488mg/LSB so 0.5g=1024.6 => MSB=0b00000100 LSB=0b00000000 + // d[1] = 0b00000111; //set impact threshold to less than 1g for now + 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 if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ - oled.Label((uint8_t *)" Step4a error ",30,05); // Display "error" at x,y + oled.Label((uint8_t *)"Acc4g err",30,05); // Display "error" at x,y wait(3.0); // display for 3 seconds }//end if d[0] = 0x61; //A_VECM_LSB (address of Vector threshold reg), write in Active or Standby - d[1] = 0b00000011; //set impact threshold to less than 1g for now - // d[1] = uint8_t(256*((1000*Impact_Thresh/0.488)%256)); //set MSB Impact threshold - Resolution 0.488mg/LSB so 0.5g=1024.6 => MSB=0b00000100 LSB=0b00000000 +// d[1] = 0b00000011; //set impact threshold to less than 1g for now + d[1] = (uint8_t)(1000*Impact_Thresh/0.488f); + d[1] = (uint8_t)(d[1]%256); //set MSB Impact threshold - Resolution 0.488mg/LSB so 0.5g=1024.6 => MSB=0b00000100 LSB=0b00000000 if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ - oled.Label((uint8_t *)" Step4b error ",30,05); // Display "error" at x,y + oled.Label((uint8_t *)"Acc4h err",30,05); // Display "error" at x,y wait(3.0); // display for 3 seconds }//end if d[0] = 0x62; //A_VECM_COUNT (address of Vector debounce counter), write in Active or Standby - d[1] = 0b00000110; //with ODR at 100Hz, should equal ??mS debounce time or ??mS in Sleep + d[1] = 0b00000100; //with ODR at 100Hz, 0x04 should equal 40mS debounce time or 80mS in 50Hz Sleep if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ - oled.Label((uint8_t *)" Step5 error ",30,05); // Display "error" at x,y + oled.Label((uint8_t *)"Acc4i err",30,05); // Display "error" at x,y wait(3.0); // display for 3 seconds }//end if // Registers 0x63 - 0x68 are vector reference values which I'm leaving set to 0 because we want absolute measurements d[0] = 0x2b; //CTRL_REG2 (address of control reg), write in Standby only - d[1] = 0b00001101; //Turns Auto-Sleep mode on and low-noise, low power + // d[1] = 0b00001101; //Turns Auto-Sleep mode on and low-noise, low power + d[1] = 0b00001001; //Turns Auto-Sleep mode off (b/c it wasn't waking on int) and low-noise, low power if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ - oled.Label((uint8_t *)" Step6 error ",30,05); // Display "error" at x,y + oled.Label((uint8_t *)"Acc4jerr",30,05); // Display "error" at x,y wait(3.0); // display for 3 seconds }//end if d[0] = 0x2c; //CTRL_REG3 (address of Int control reg), write in Standby only d[1] = 0b00001100; //FFMT or Vector will wake chip from sleep, int are active high if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ - oled.Label((uint8_t *)" Step7 error ",30,05); // Display "error" at x,y + oled.Label((uint8_t *)"Acc4k err",30,05); // Display "error" at x,y wait(3.0); // display for 3 seconds }//end if d[0] = 0x2d; //CTRL_REG4 (address of Int enable reg), write in Standby only - d[1] = 0b00000110; // FFMT and Vector int enabled + d[1] = 0b10000110; // FFMT and Vector int enabled if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ - oled.Label((uint8_t *)" Step8 error ",30,05); // Display "error" at x,y + oled.Label((uint8_t *)"Acc4L err",30,05); // Display "error" at x,y wait(3.0); // display for 3 seconds }//end if - wait(0.2); // people have had a problem here and needed a delay + // wait(0.2); // people have had a problem here and needed a delay d[0] = 0x2e; //CTRL_REG5 (Int routing reg), write in Standby only d[1] = 0b00000100; // Make FFMT int output on pin INT1(PTC1) and Vector on INT2(PTD13) if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ - oled.Label((uint8_t *)" Step9 error ",30,05); // Display "error" at x,y + oled.Label((uint8_t *)"Acc4m err",30,05); // Display "error" at x,y + wait(3.0); // display for 3 seconds + }//end if + + d[0] = 0x29; //ASLP_Count (counter used to go to sleep reg), write in Standby only + d[1] = 0b00001010; // 10*320mS=3.2S of no inturrupts to go to sleep + if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ + oled.Label((uint8_t *)"Acc4n err",30,05); // Display "error" at x,y wait(3.0); // display for 3 seconds }//end if d[0] = 0x2a; //0x2a Config reg1, write in Standby only except for bit[0] d[1] = 0b00011001; //Auto-Sleep mode on set to 50Hz, ODR set to 100Hz Puts device back into Active mode if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ - oled.Label((uint8_t *)" Step10 error ",30,05); // Display "error" at x,y + oled.Label((uint8_t *)"Acc4o err",30,05); // Display "error" at x,y wait(3.0); // display for 3 seconds - }//end if - - //oled.FillScreen(COLOR_BLACK); // Clear screen - oled.Label((uint8_t *)" Mode 3 ",30,60); // Display "mode" at x,y - oled.Label((uint8_t *)"FF & Imp",30,75); // Display "mode" at x,y + }//end if break; - }// end of case 3 + }// end of case 4 case 10: {// reset IC char d[2]; d[0] = 0x2a; //0x2a Config reg1 d[1] = 0x00; //Put device in Standby mode if(i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2) ==1){ - oled.Label((uint8_t *)" Step1 error ",30,05); // Display "error" at x,y + oled.Label((uint8_t *)" Step10a err",30,05); // Display "error" at x,y wait(3.0); // display for 3 seconds }//end if @@ -2647,11 +2958,11 @@ oled.Label((uint8_t *)" Reset error ",30,05); // Display "error" at x,y wait(3.0); // display for 3 seconds }//end if - oled.Label((uint8_t *)" Reset ",30,45); // Display "reset" at x,y + oled.Label((uint8_t *)"Acc_Reset",20,60); // Display "reset" at x,y break; }// end case 10 - case 11: {// wake for read, was in stanby + case 11: {// wake for simple data read, was in stanby char d[2]; d[0] = FXOS8700_CTRL_REG1; //Puts device in Standby mode just in case d[1] = 0x00; @@ -2668,21 +2979,45 @@ break; }// end of case 11 - case 12: {// put into standby + case 12: {// put into standby for low power char d[2]; d[0] = FXOS8700_CTRL_REG1; //Puts device in Standby mode d[1] = 0x00; - i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d,2); - + i2c_bus1.write(FXOS8700_I2C_ADDRESS_, d, 2); /*For lowest power ~8uA, set ODR-12.5Hz,(low-pwr accel mode) or 2uA in standby mode */ - - break; }// end of case 11 + case 20: {// read INT_Source to clear VECM int, shouldn't have to do this + // This was not working for me but it was due to me using the wrong FXOS8700_I2C_ADDRESS_ + char d[2];//, data_byte_[1]; + d[0] = 0x0c; // 0x0c is INT_Source Reg + i2c_bus1.write(FXOS8700_I2C_ADDRESS_,d,1,true); // "true" is needed to prevent stop + wait(0.01); + if(i2c_bus1.read(FXOS8700_I2C_ADDRESS_,d,1) == 1){ // read Who am I Reg for debug + sprintf(text_1," INT_Read_Err "); + oled.Label((uint8_t *)text_1,5,50); // Display error at x,y + wait(1); // wait 1 seconds + }//endif + break; + }// end of case 20 + + case 21: {// read A_FFMT_SRC reg to clear FFMT int, shouldn't have to do this + // This was not working for me but it was due to me using the wrong FXOS8700_I2C_ADDRESS_ + char d[2];//, data_byte_[1]; + d[0] = 0x16; // 0x16 is A_FFMT_SRC Reg + i2c_bus1.write(FXOS8700_I2C_ADDRESS_,d,1,true); // "true" is needed to prevent stop + wait(0.01); + if(i2c_bus1.read(FXOS8700_I2C_ADDRESS_,d,1) == 1){ // read Who am I Reg for debug + sprintf(text_1," INT_Read_Err "); + oled.Label((uint8_t *)text_1,5,50); // Display error at x,y + wait(1); // wait 1 seconds + }//endif + break; + }// end of case 21 default: { - oled.Label((uint8_t *)" Mode ? ",30,60); // Display "mode" at x,y + oled.Label((uint8_t *)" Mode? ",30,60); // Display "mode" at x,y // unknown config break; } @@ -2691,6 +3026,393 @@ }// end Fall_config /***************************************************************************** +Name: gyro_sensor_config() +Purpose: Used to set gyro IC's internal registers for chip level +interrupts and power modes +Inputs: int value from 0 to 256 +Returns: None +******************************************************************************/ + +void gyro_sensor_config(uint8_t Num){ +// use case switches here to configure for +switch(Num) { + case 0: {// put in standby + /*For lowest power ~2.8uA in standby mode */ + char d[2]; + d[0] = FXAS21002_CTRL_REG1; //CTRL_REG1=0x13 + d[1] = 0x08; //Puts device in standby mode + if(i2c_bus1.write(FXAS21002_I2C_ADDRESS_, d,2) ==1){ + oled.Label((uint8_t *)"gyr_err0a",20,45); // Display "error" at x,y + wait(3.0); // display for 3 seconds + }//end if + break; + }// end of case 0 + + case 1: {// Fall_Alert mode=1 or 2, put in active mode se we can read gyro measurments + char d[2]; + d[0] = FXAS21002_CTRL_REG1; //CTRL_REG1=0x13 + d[1] = 0x00; //Puts device in standby mode + if(i2c_bus1.write(FXAS21002_I2C_ADDRESS_, d,2) ==1){ + oled.Label((uint8_t *)"gyr_err1a",20,45); // Display "error" at x,y + wait(3.0); // display for 3 seconds + }//end if + d[0] = FXAS21002_CTRL_REG0; //CTRL_REG0=0x0d + d[1] = 0x00; //sets FS =+/- 2000 dps + if(i2c_bus1.write(FXAS21002_I2C_ADDRESS_, d,2) ==1){ + oled.Label((uint8_t *)"gyr_err1b",20,45); // Display "error" at x,y + wait(3.0); // display for 3 seconds + }//end if + d[0] = FXAS21002_CTRL_REG1; //CTRL_REG1=0x13 + d[1] = 0x0e; //0x0e puts device in active mode with ODR = 100Hz + if(i2c_bus1.write(FXAS21002_I2C_ADDRESS_, d,2) ==1){ + oled.Label((uint8_t *)"gyr_err1c",20,45); // Display "error" at x,y + wait(3.0); // display for 3 seconds + }//end if + break; + }// end of case 1 + + case 2: {// Fall_Alert mode=1 or 2, put in active mode se we can read gyro measurments + char d[2]; + d[0] = FXAS21002_CTRL_REG1; //CTRL_REG1=0x13 + d[1] = 0x00; //Puts device in standby mode + if(i2c_bus1.write(FXAS21002_I2C_ADDRESS_, d,2) ==1){ + oled.Label((uint8_t *)"gyr_err2a",20,45); // Display "error" at x,y + wait(3.0); // display for 3 seconds + }//end if + d[0] = FXAS21002_CTRL_REG0; //CTRL_REG0=0x0d + d[1] = 0x00; //sets FS =+/- 2000 dps + if(i2c_bus1.write(FXAS21002_I2C_ADDRESS_, d,2) ==1){ + oled.Label((uint8_t *)"gyr_err2b",20,45); // Display "error" at x,y + wait(3.0); // display for 3 seconds + }//end if + d[0] = FXAS21002_CTRL_REG1; //CTRL_REG1=0x13 + d[1] = 0x0e; //0x0e puts device in active mode with ODR = 100Hz + if(i2c_bus1.write(FXAS21002_I2C_ADDRESS_, d,2) ==1){ + oled.Label((uint8_t *)"gyr_err2c",20,45); // Display "error" at x,y + wait(3.0); // display for 3 seconds + }//end if + break; + }// end of case 2 + + case 3: {// Fall_Alert mode 3 or 4, set up interupt, put in active mode + char d[2]; + d[0] = FXAS21002_CTRL_REG1; //CTRL_REG1=0x13 + d[1] = 0x00; //0x08 puts device in standby mode + if(i2c_bus1.write(FXAS21002_I2C_ADDRESS_, d,2) ==1){ + oled.Label((uint8_t *)"gyr_err3",20,45); // Display "error" at x,y + wait(3.0); // display for 3 seconds + }//end if + + // set RT_CFG reg 0x0e - Rate int config + d[0] = 0x0e; //set RT_CFG reg 0x0e - Rate int config + d[1] = 0b00000111; // enable x,y,z axis + if(i2c_bus1.write(FXAS21002_I2C_ADDRESS_, d,2) ==1){ + oled.Label((uint8_t *)"gyr_err3a",20,45); // Display "error" at x,y + wait(3.0); // display for 3 seconds + }//end if + + // set RT_THS reg 0x10 - Rate Threshold value + d[0] = 0x10; //set RT_THS reg 0x10 - Rate Threshold config + // d[1] = 0b00000111; // bit7=couter mode(1=clr,0=dec), rate Tresh(dps)=(THS+1)*Sensitivity(dps/LSB + // Sensitivity(dps/LSB), we should have mdps/LSB=62.50 or a full range of +/- 2000 dps + // Movement_Thresh 50 dps=(THS+1)*256*Sensitivity(dps/LSB) => THS = Movement_Thresh/(16.0f)-1 + // We specified that 50 dps was the magnitude some of all 3 axis so THS is 1/3 of that + d[1] = (uint8_t)((Movement_Thresh/(3*16.0f))-1); // Movement_Thresh 50 dps setting Tresh(dps)=(THS+1)*256*Sensitivity(dps/LSB) + if(i2c_bus1.write(FXAS21002_I2C_ADDRESS_, d,2) ==1){ + oled.Label((uint8_t *)"gyr_err3b",20,45); // Display "error" at x,y + wait(3.0); // display for 3 seconds + }//end if + + // set RT_COUNT reg 0x11 - Rate Threshold counter + d[0] = 0x11; //set RT_COUNT reg 0x11 - Rate Threshold counter + // d[1] = 0b10000000; // debounce count value (Count=10, ODR=100Hz => 100mS) + d[1] = (uint8_t)(Min_Movement_Time/0.01f); // debounce count value (at ODR=100Hz, each count = 10mS) 2.55s=255 + // need to calculate and store this value + if(i2c_bus1.write(FXAS21002_I2C_ADDRESS_, d,2) ==1){ + oled.Label((uint8_t *)"gyr_err3c",20,45); // Display "error" at x,y + wait(3.0); // display for 3 seconds + }//end if + + // set CTRL_REG2 reg 0x14 - Int config + d[0] = 0x14; //set CTRL_REG2 reg 0x14 - Int config + d[1] = 0b01110000; // enable RT &FIFO interupts, int=act_low, push/pull + if(i2c_bus1.write(FXAS21002_I2C_ADDRESS_, d,2) ==1){ + oled.Label((uint8_t *)"gyr_err3d",20,45); // Display "error" at x,y + wait(3.0); // display for 3 seconds + }//end if + + // set CTRL_REG3 reg 0x15 - Auto inc config, external power, FSR <=don't need? + d[0] = 0x15; //CTRL_REG3 reg 0x15 + d[1] = 0x00; //Auto inc config, external power, FSR + if(i2c_bus1.write(FXAS21002_I2C_ADDRESS_, d,2) ==1){ + oled.Label((uint8_t *)"gyr_err3e",20,45); // Display "error" at x,y + wait(3.0); // display for 3 seconds + }//end if + + d[0] = FXAS21002_CTRL_REG0; //CTRL_REG0=0x0d + d[1] = 0x00; //sets FS=0,mdps/LSB=62.50 => +/- 2000 dps + if(i2c_bus1.write(FXAS21002_I2C_ADDRESS_, d,2) ==1){ + oled.Label((uint8_t *)"gyr_err3f",20,45); // Display "error" at x,y + wait(3.0); // display for 3 seconds + }//end if + d[0] = FXAS21002_CTRL_REG1; //CTRL_REG1 0x13 - Op mode, ODR selection, reset + d[1] = 0b00001110; //0x0e puts device in active mode and sets ODR to 100Hz + if(i2c_bus1.write(FXAS21002_I2C_ADDRESS_, d,2) ==1){ + oled.Label((uint8_t *)"gyr_err3g",20,45); // Display "error" at x,y + wait(3.0); // display for 3 seconds + }//end if + break; + }// end of case 2 + + case 4: {// Fall_Alert mode 3 or 4, set up interupt, put in active mode + char d[2]; + d[0] = FXAS21002_CTRL_REG1; //CTRL_REG1=0x13 + d[1] = 0x00; //0x08 puts device in standby mode + if(i2c_bus1.write(FXAS21002_I2C_ADDRESS_, d,2) ==1){ + oled.Label((uint8_t *)"gyr_err4",20,45); // Display "error" at x,y + wait(3.0); // display for 3 seconds + }//end if + + // set RT_CFG reg 0x0e - Rate int config + d[0] = 0x0e; //set RT_CFG reg 0x0e - Rate int config + d[1] = 0b00000111; // enable x,y,z axis + if(i2c_bus1.write(FXAS21002_I2C_ADDRESS_, d,2) ==1){ + oled.Label((uint8_t *)"gyr_err4a",20,45); // Display "error" at x,y + wait(3.0); // display for 3 seconds + }//end if + + // set RT_THS reg 0x10 - Rate Threshold value + d[0] = 0x10; //set RT_THS reg 0x10 - Rate Threshold config + // d[1] = 0b00000111; // bit7=couter mode(1=clr,0=dec), rate Tresh(dps)=(THS+1)*Sensitivity(dps/LSB + // Sensitivity(dps/LSB), we should have mdps/LSB=62.50 or a full range of +/- 2000 dps + // Movement_Thresh 50 dps=(THS+1)*256*Sensitivity(dps/LSB) => THS = Movement_Thresh/(16.0f)-1 + // We specified that 50 dps was the magnitude some of all 3 axis so THS is 1/3 of that + d[1] = (uint8_t)((Movement_Thresh/(3*16.0f))-1); // Movement_Thresh 50 dps setting Tresh(dps)=(THS+1)*256*Sensitivity(dps/LSB) + if(i2c_bus1.write(FXAS21002_I2C_ADDRESS_, d,2) ==1){ + oled.Label((uint8_t *)"gyr_err4b",20,45); // Display "error" at x,y + wait(3.0); // display for 3 seconds + }//end if + + // set RT_COUNT reg 0x11 - Rate Threshold counter + d[0] = 0x11; //set RT_COUNT reg 0x11 - Rate Threshold counter + // d[1] = 0b10000000; // debounce count value (Count=10, ODR=100Hz => 100mS) + d[1] = (uint8_t)(Min_Movement_Time/0.01f); // debounce count value (at ODR=100Hz, each count = 10mS) 2.55s=255 + // need to calculate and store this value + if(i2c_bus1.write(FXAS21002_I2C_ADDRESS_, d,2) ==1){ + oled.Label((uint8_t *)"gyr_err4c",20,45); // Display "error" at x,y + wait(3.0); // display for 3 seconds + }//end if + + // set CTRL_REG2 reg 0x14 - Int config + d[0] = 0x14; //set CTRL_REG2 reg 0x14 - Int config + d[1] = 0b01110000; // enable RT &FIFO interupts, int=act_low, push/pull + if(i2c_bus1.write(FXAS21002_I2C_ADDRESS_, d,2) ==1){ + oled.Label((uint8_t *)"gyr_err4d",20,45); // Display "error" at x,y + wait(3.0); // display for 3 seconds + }//end if + + // set CTRL_REG3 reg 0x15 - Auto inc config, external power, FSR <=don't need? + d[0] = 0x15; //CTRL_REG3 reg 0x15 + d[1] = 0x00; //Auto inc config, external power, FSR + if(i2c_bus1.write(FXAS21002_I2C_ADDRESS_, d,2) ==1){ + oled.Label((uint8_t *)"gyr_err4e",20,45); // Display "error" at x,y + wait(3.0); // display for 3 seconds + }//end if + + d[0] = FXAS21002_CTRL_REG0; //CTRL_REG0=0x0d + d[1] = 0x00; //sets FS=0,mdps/LSB=62.50 => +/- 2000 dps + if(i2c_bus1.write(FXAS21002_I2C_ADDRESS_, d,2) ==1){ + oled.Label((uint8_t *)"gyr_err4f",20,45); // Display "error" at x,y + wait(3.0); // display for 3 seconds + }//end if + d[0] = FXAS21002_CTRL_REG1; //CTRL_REG1 0x13 - Op mode, ODR selection, reset + d[1] = 0b00001110; //0x0e puts device in active mode and sets ODR to 100Hz + if(i2c_bus1.write(FXAS21002_I2C_ADDRESS_, d,2) ==1){ + oled.Label((uint8_t *)"gyr_err4g",20,45); // Display "error" at x,y + wait(3.0); // display for 3 seconds + }//end if + break; + }// end of case 4 + + + case 10: {// reset Gyro IC + char d[2]; + d[0] = FXAS21002_CTRL_REG1; //CTRL_REG1 0x13 - Op mode, ODR selection, reset + d[1] = 0b01000000; //resets IC + if(i2c_bus1.write(FXAS21002_I2C_ADDRESS_, d,2) ==1){ + oled.Label((uint8_t *)"gyr_err10a",20,45); // Display "error" at x,y + wait(3.0); // display for 3 seconds + }//end if + oled.Label((uint8_t *)"G_Reset ",30,45); // Display "reset" at x,y + break; + }// end case 10 + + case 11: {// read gyro measurments + char d[2]; + d[0] = FXAS21002_CTRL_REG1; //CTRL_REG1=0x13 + d[1] = 0x0e; //0x0e puts device in active mode with ODR = 100Hz + if(i2c_bus1.write(FXAS21002_I2C_ADDRESS_, d,2) ==1){ + oled.Label((uint8_t *)"gyr_err11a",20,45); // Display "error" at x,y + wait(3.0); // display for 3 seconds + }//end if + break; + }// end of case 11 + + case 12: {// put in standby + /*For lowest power ~2.8uA in standby mode */ + char d[2]; + d[0] = FXAS21002_CTRL_REG1; //CTRL_REG1=0x13 + d[1] = 0x08; //Puts device in standby mode + if(i2c_bus1.write(FXAS21002_I2C_ADDRESS_, d,2) ==1){ + oled.Label((uint8_t *)"gyr_err12a",20,45); // Display "error" at x,y + wait(3.0); // display for 3 seconds + }//end if + break; + }// end of case 12 + + default: { + oled.Label((uint8_t *)"Gyro_Mode?",20,45); // Display "mode" at x,y + // unknown config + break; + } + }// end switch +}// end gyro_sensor_config + +/***************************************************************************** +Name: press_config() +Purpose: Used to set pressure sensor's internal registers for power modes +Inputs: int value from 0 to 256 +Returns: None +******************************************************************************/ + +void press_config(uint8_t Num){ +// use case switches here to configure +switch(Num) { + case 0: {// put in standby (AKA powered down) mode + //For lowest power ~2.8uA in standby mode, sensor should default to this after reset + char d[2]; + d[0] = 0x26; //CTRL_REG1=0x26 + d[1] = 0x00; //Puts device in powered down mode + if(i2c_bus1.write(0xC0, d,2) ==1){ // 0xc0 is MPL3115A2 address + oled.Label((uint8_t *)"press_err0a",20,30); // Display "error" at x,y + wait(3.0); // display for 3 seconds + }//end if + break; + }// end of case 0 + + default: { + oled.Label((uint8_t *)"PRESS_Mode?",20,45); // Display "mode" at x,y + // unknown config + break; + } + }// end switch +}// end press_config + +/***************************************************************************** +Name: MAX30101_test_config() +Purpose: Used to test operation of the MAX30101 heart-rate sensor +Inputs: int value from 0 to 256 +Returns: None +******************************************************************************/ +void MAX30101_test_config(uint8_t Num){ +// use case switches here to configure +switch(Num) { + case 0: {// test + char d[2] = {0xfe, 0x07}; + if(i2c_bus0.read(0xae, d, 2) == 1){ // read RevID value 0-255 + sprintf(text_1,"M_R_Er %i %i",d[0],d[1]); + oled.Label((uint8_t *)text_1,5,16); // Display error at x,y + }//end if + else{ + sprintf(text_1,"M_R_data %i %i",d[0],d[1]); + oled.Label((uint8_t *)text_1,5,16); // Display good data at x,y + } + wait(1); // wait 1 seconds + d[0] = 0x09; // Mod_conf reg - SHDN, reset, modes + d[1] = 0b00000111; // set mode to red, green and/or IR LEDs + if(i2c_bus0.write(0xaf, d, 1) ==1){; // "true" is needed to prevent stop, MAX30101 address is 0xae but left shifted + oled.Label((uint8_t *)"MAX_W_err0a",5,30); // Display "error" at x,y + wait(3.0); // display for 3 seconds + }//end if + wait(5); // wait 5 seconds + + /* + d[0] = 0xfe; //lets try to read revID value 0-255 + d[1] = 0x00; //Puts device in powered down mode + if(i2c_bus0.write(0xae<<1, d,2) ==1){ // MAX30101 address is 0xae but left shifted + oled.Label((uint8_t *)"Max_err0a",20,30); // Display "error" at x,y + wait(3.0); // display for 3 seconds + }//end if + */ + break; + }// end of case 0 + + + case 10: {// reset + char d[2]; + d[0] = 0x09; // Mod_conf reg - SHDN, reset, modes + d[1] = 0b01000000; //resets IC + if(i2c_bus0.write(0xaf, d, 2) ==1){ + oled.Label((uint8_t *)"MAX_W_Err10a",5,1); // Display "error" at x,y + }//end if + else { + oled.Label((uint8_t *)"MAX_Reset",20,30); // Display "reset" at x,y + } + wait(0.1); // wait 5 seconds + break; + }// end of case 10 + + default: { + oled.Label((uint8_t *)"MAX_Mode?",20,45); // Display "mode" at x,y + // unknown config + break; + } + }// end switch +}// end light_config + +/***************************************************************************** +Name: light_config() +Purpose: Used to set ambient light sensor's internal registers for power modes +Inputs: int value from 0 to 256 +Returns: None +******************************************************************************/ +/* +void light_config(uint8_t Num){ +// use case switches here to configure +switch(Num) { + case 0: {// put in standby (AKA powered down) mode + //For lowest power ~2.8uA in standby mode, sensor should default to this after reset + char d[2]; + d[0] = TSL2561_CONTROL; //CTRL_REG0=0x00 + d[1] = 0x00; //Puts device in powered down mode + if(i2c_bus0.write(TSL2561_I2C_ADDRESS_, d,2) ==1){ + oled.Label((uint8_t *)"light_err0a",20,30); // Display "error" at x,y + wait(3.0); // display for 3 seconds + }//end if + break; + }// end of case 0 + + case 1: {// put in active + char d[2]; + d[0] = TSL2561_CONTROL; //CTRL_REG=0x00 + d[1] = 0x03; //Puts device in powered up mode + if(i2c_bus0.write(TSL2561_I2C_ADDRESS_, d,2) ==1){ + oled.Label((uint8_t *)"light_err0a",20,30); // Display "error" at x,y + wait(3.0); // display for 3 seconds + }//end if + break; + }// end of case 1 + + default: { + oled.Label((uint8_t *)"LGHT_Mode?",20,45); // Display "mode" at x,y + // unknown config + break; + } + }// end switch +}// end light_config +*/ + +/***************************************************************************** Name: update_display_date Purpose: Updating display data without updating any data labels. This keeps measurements and time values current while reducing screen flicker. @@ -2726,8 +3448,16 @@ // 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]); // oled.Label((uint8_t *)text_1,20,20);// Date at x,y sprintf(text_1,"%c%c:%c%c:%c%c ",buffer[15],buffer[16],buffer[18],buffer[19],buffer[21],buffer[22]); + + + textProperties.font = OpenSans_12x18_Regular; // Max Width of Character = 12px, Max Height of Character = 18px + textProperties.fontColor = COLOR_WHITE; + oled.SetTextProperties(&textProperties); oled.Label((uint8_t *)text_1,25,40);// Time at x,y - + textProperties.font = OpenSans_10x15_Regular; // Max Width of Character = 10px, Max Height of Character = 15px + textProperties.fontColor = COLOR_WHITE; + oled.SetTextProperties(&textProperties); + Heat_Index_Calculation(); sprintf(text,"%i",heat_index); oled.TextBox((uint8_t *)text,3,80,15,15); //show HI in a 15px by 15px text box at x=3, y=80 @@ -2736,14 +3466,14 @@ case 21: {// Fall Alert Diagnostic Screen if(Fall_Alert_Mode == 0){ - fall_config(11); // turn accel sensor to active to take reading + fall_config(11); // turn accel sensor to active mode to take a reading, may take 80mS to 300mS } textProperties.fontColor = COLOR_WHITE; oled.SetTextProperties(&textProperties); gyro.acquire_gyro_data_dps(Gyro_Data); Gyro_Mag = (abs(Gyro_Data[0])+abs(Gyro_Data[1])+abs(Gyro_Data[2])); sprintf(text_1," %4.0f D/S ",Gyro_Mag); - oled.Label((uint8_t *)text_1,42,60);// text_1 at x,y + oled.Label((uint8_t *)text_1,37,60);// text_1 at x,y accel.acquire_accel_data_g(Accel_Data); if(Fall_Alert_Mode == 0){ @@ -2751,8 +3481,8 @@ } Accel_Mag = 2*sqrt(((Accel_Data[0]*Accel_Data[0])+(Accel_Data[1]*Accel_Data[1])+(Accel_Data[2]*Accel_Data[2]))); sprintf(text_1," %2.2f g ",Accel_Mag); - oled.Label((uint8_t *)text_1,44,40);// text_1 at x,y - if(Accel_Mag > Fall_Thresh + 0.1 && Led_clk2 == 1){// are we stuck in limbo? + oled.Label((uint8_t *)text_1,39,40);// text_1 at x,y + if(Accel_Mag > Fall_Thresh + 0.05f && Led_clk2 == 1){// are we stuck in limbo? fall_det_end(); } break;