Example of using Hexiwear buttons and declaring screens.
Dependencies: FXOS8700 FXAS21002 Hexi_KW40Z Hexi_OLED_SSD1351
main.cpp
- Committer:
- asong
- Date:
- 2018-02-03
- Revision:
- 1:e4b38d6918ba
- Parent:
- 0:d1d36a3da39b
- Child:
- 2:824ed4ae8d52
File content as of revision 1:e4b38d6918ba:
/********************************************************************** Texas State University Senior Project - HexiHeart Team Zeta: Alex Song, Jasmine Rounsaville, Issam Hichami, Neil Baker Version: HexiHeart_1st 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. ***********************************************************************/ #include "mbed.h" #include "Hexi_KW40Z.h" // Button and BLE fuctions #include "FXOS8700.h" // 3D Accelorometer & Mag #include "FXAS21002.h" // 3-Axis Gyroscope #include "Hexi_OLED_SSD1351.h" // OLED fuctions #include "OLED_types.h" // Text attributs #include "string.h" #include "OpenSans_Font.h" #include "MAX30101.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 LED_ON 0 #define LED_OFF 1 #define SCRN_TIME 10.0 #define Debug 1 // If "Debug" is defined, our code will compile for debug. Comment out for Production code. void StartHaptic(void); void StartHaptic(int x); void StopHaptic(void const *n); void error_screen(void); void update_display(void); // ***************** Global variables *********************** char text_1[20]; // Text buffer - Do we need more? char display_buff[20]; //Buffer for conversion to char to display bool HR_Enable = 0; bool OLED_ON = 1; // Turn OLED power on/off bool Fall_Alert = 0; // Initialize as no active alert bool Panic_Alert = 0; // Initialize as no active alert bool Fall_Alert_Mode = 1; // 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 float Gyro_Mag=0.0; // Vector magnitude calculated from sensor data float Gyro_Data[3]; // Gyro data from sensor 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 uint8_t HR_buff[250]; uint8_t *HR_return; uint8_t Age = 50; // Initialize age uint8_t Max_BPM = 220 - Age; // Initialize Max BPM uint8_t Screen_Num = 0; // Initialize to main screen uint8_t Error_Num = 0; // Error num for debug uint8_t HR_Vibration = 1; //Choose Heart Rate Vibration Options uint8_t Target_Zone = 3; //Initialize Target Heart Rate Zone to Zone 3 uint8_t HR_Zone1[2] = {Max_BPM * .50, Max_BPM * .60}; //Heart Rate Zone 1 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 // ***************** 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 DigitalOut RED_Led(LED1); DigitalOut GRN_Led(LED2); DigitalOut BLU_Led(LED3); DigitalOut haptic(PTB9); /* Instantiate the Hexi KW40Z Driver (UART TX, UART RX) */ KW40Z kw40z_device(PTE24, PTE25); /* Define timer for haptic feedback */ RtosTimer hapticTimer(StopHaptic, osTimerOnce); //***************** Tickers and Timers ***************** Ticker Screen_Timer;// use ticker to turn off OLED void timout_timer() // turn off display mode { oled.FillScreen(COLOR_BLACK); // Clear screen.. is there a better command for this? OLED_ON = 0; // set flag to off Screen_Timer.detach(); }//end routine void ButtonUp(void) { Screen_Timer.attach(&timout_timer,(SCRN_TIME));//Is this sufficient to reset/restart ticker timer for OLED? if (OLED_ON == 0) { OLED_ON = 1; // Scree was off, set to On update_display(); } else { switch(Screen_Num) { case 0: {// We're in Main Screen // do nothing, wrong button break; } case 1: {// Panic Alert option StartHaptic(); Screen_Num = 26; //Change to screen 5 #ifdef Debug // in debug show debug/diagnostic screens Screen_Num = 26; //Change to screen 20 #endif update_display(); break; } case 2: {// Fall Alert option StartHaptic(); Screen_Num = 1; //Change to screen 1 update_display(); break; } case 3: {// Heart Rate Monitoring option StartHaptic(); Screen_Num = 2; //Change to screen 2 update_display(); break; } case 4: {// Alert History option StartHaptic(); Screen_Num = 3; //Change to screen 3 update_display(); break; } case 5: {// About HexiHeart StartHaptic(); Screen_Num = 4; //Change to screen 4 update_display(); break; } case 6: {// Panic Alert StartHaptic(); Panic_Alert = !Panic_Alert; update_display(); break; } case 7: {// Heart Rate Zone StartHaptic(50); //heart.enable(); //HR_Enable = 1; //while(HR_Enable == 1) // heart.readRawData(HR_buff, HR_return); //update_display(); break; } case 8: {// Alert History StartHaptic(); //Increment alert index break; } case 20: {// Diagnostic/Debug Screens StartHaptic(); Screen_Num = 5; //Change to screen 5 update_display(); break; } case 21: {// Fall Diagnostic StartHaptic(); Screen_Num = 25; //Change to screen 25 update_display(); break; } case 22: {// Fall Debug StartHaptic(); Screen_Num = 21; //Change to screen 21 update_display(); break; } case 23: {// Heart Rate Diagnostic StartHaptic(); Screen_Num = 22; //Change to screen 22 update_display(); break; } case 24: {// Heart Rate Debug StartHaptic(); Screen_Num = 23; //Change to screen 23 update_display(); break; } case 25: {// Heat Index Diagnostic StartHaptic(); Screen_Num = 24; //Change to screen 24 update_display(); break; } case 26: {//Heart Rate Config Option StartHaptic(); Screen_Num = 20; update_display(); break; } case 27: {//Incrementing Age StartHaptic(); if(Age < 100) { Age += 1; Screen_Num = 27; } else { Age = 1; } Max_BPM = 220 - Age; //Calculate New Max BPM HR_Zone1[0] = Max_BPM * .50; //Set Heart Rate Zone 1 HR_Zone1[1] = Max_BPM * .60; //Set Heart Rate Zone 1 HR_Zone2[0] = HR_Zone1[1] + 1; //Set Heart Rate Zone 2 HR_Zone2[1] = Max_BPM * .70; //Set Heart Rate Zone 2 HR_Zone3[0] = HR_Zone2[1] + 1; //Set Heart Rate Zone 3 HR_Zone3[1] = Max_BPM * .80; //Set Heart Rate Zone 3 HR_Zone4[0] = HR_Zone3[1] + 1; //Set Heart Rate Zone 4 HR_Zone4[1] = Max_BPM; //Set Heart Rate Zone 4 update_display(); break; } case 28: {//Changing Heart Rate Vibration Preferences StartHaptic(); if(HR_Vibration == 3) { HR_Vibration = 1; } else { HR_Vibration += 1; } update_display(); break; } case 30: {//Change Target Heart Rate Zone Preference StartHaptic(); if(Target_Zone == 4) { Target_Zone = 1; } else { Target_Zone += 1; } update_display(); break; } default: { break; } } } } void ButtonDown(void) { Screen_Timer.attach(&timout_timer,(SCRN_TIME));//Is this sufficient to reset/restart ticker timer for OLED? if (OLED_ON == 0) { OLED_ON = 1; // Screen was off, set to On update_display(); } else { switch(Screen_Num) { case 0: {// We're in Main Screen // do nothing, wrong button break; } case 1: {// Panic Alert option StartHaptic(); Screen_Num = 2; //Change to screen 2 update_display(); break; } case 2: {// Fall Alert option StartHaptic(); Screen_Num = 3; //Change to screen 3 update_display(); break; } case 3: {// Heart Rate Monitoring option StartHaptic(); Screen_Num = 4; //Change to screen 4 update_display(); break; } case 4: {// Alert History option StartHaptic(); Screen_Num = 5; //Change to screen 5 update_display(); break; } case 5: {// About HexiHeart option StartHaptic(); Screen_Num = 26; //Change to screen 1 #ifdef Debug // in debug show debug/diagnostic screens Screen_Num = 20; //Change to screen 20 #endif update_display(); break; } case 6: {// Panic Alert // do nothing, wrong button break; } case 7: {// Heart Rate Zone StartHaptic(100); HR_Enable = 0; break; } case 8: {// Alert History StartHaptic(); //decriment alert index break; } case 20: {// Diagnostic/Debug Screens StartHaptic(); Screen_Num = 26; //Change to screen 1 update_display(); break; } case 21: {// Fall Diagnostic StartHaptic(); Screen_Num = 22; //Change to screen 22 update_display(); break; } case 22: {// Fall Debug StartHaptic(); Screen_Num = 23; //Change to screen 23 update_display(); break; } case 23: {// Heart Rate Diagnostic StartHaptic(); Screen_Num = 24; //Change to screen 24 update_display(); break; } case 24: {// Heart Rate Debug StartHaptic(); Screen_Num = 25; //Change to screen 25 update_display(); break; } case 25: {// Heat Index Diagnostic StartHaptic(); Screen_Num = 21; //Change to screen 21 update_display(); break; } case 26: {//Heart Rate Configs StartHaptic(); Screen_Num = 1; update_display(); break; } case 27: { //Decrement Age StartHaptic(); if(Age == 1) { Age = 100; } else { Age -= 1; Screen_Num = 27; } Max_BPM = 220 - Age; //Calculate New Max BPM HR_Zone1[0] = Max_BPM * .50; //Set Heart Rate Zone 1 HR_Zone1[1] = Max_BPM * .60; //Set Heart Rate Zone 1 HR_Zone2[0] = HR_Zone1[1] + 1; //Set Heart Rate Zone 2 HR_Zone2[1] = Max_BPM * .70; //Set Heart Rate Zone 2 HR_Zone3[0] = HR_Zone2[1] + 1; //Set Heart Rate Zone 3 HR_Zone3[1] = Max_BPM * .80; //Set Heart Rate Zone 3 HR_Zone4[0] = HR_Zone3[1] + 1; //Set Heart Rate Zone 4 HR_Zone4[1] = Max_BPM; //Set Heart Rate Zone 4 update_display(); break; } case 28: { //Changing Heart Rate Vibration Preference StartHaptic(); if(HR_Vibration == 1) { HR_Vibration = 3; } else { HR_Vibration -= 1; } update_display(); break; } case 30: {//Change Target Heart Rate Zone Preference StartHaptic(); if(Target_Zone == 1) { Target_Zone = 4; } else { Target_Zone -= 1; } update_display(); break; } default: { break; } } } } void ButtonRight(void) { Screen_Timer.attach(&timout_timer,(SCRN_TIME));//Is this sufficient to reset/restart ticker timer for OLED? if (OLED_ON == 0) { OLED_ON = 1; // Screen was off, set to On update_display(); } else { switch(Screen_Num) { case 0: {// We're in Main Screen StartHaptic(); Screen_Num = 1; //Change to screen 1 update_display(); break; } case 1: {// Panic Alert option StartHaptic(); Screen_Num = 6; //Change to screen 6 update_display(); break; } case 2: {// Fall Alert option StartHaptic(); // toggle on/off break; } case 3: {// Heart Rate Monitoring option StartHaptic(); Screen_Num = 7; //Change to screen 7 update_display(); break; } case 4: {// Alert History option StartHaptic(); Screen_Num = 8; //Change to screen 8 update_display(); break; } case 5: {// About HexiHeart option StartHaptic(); Screen_Num = 9; //Change to screen 9 update_display(); break; } case 6: {// Panic Alert // do nothing, wrong button break; } case 7: {// Heart Rate Zone StartHaptic(); // toggle on/off break; } case 20: {// Diagnostic/Debug Screens StartHaptic(); Screen_Num = 21; //Change to screen 21 update_display(); break; } case 26: {//Change to Heart Rate Config Screen StartHaptic(); Screen_Num = 27; update_display(); break; } case 27: {//Change to Heart Rate Vibration Preferences StartHaptic(); Screen_Num = 28; update_display(); break; } case 28: {//Change to Heart Rate Zone Boundary Info StartHaptic(); Screen_Num = 29; update_display(); break; } case 29: {//Change Target Heart Rate Zone Preference StartHaptic(); Screen_Num = 30; update_display(); break; } case 30: {//Change to Heart Rate Config Screen StartHaptic(); Screen_Num = 27; update_display(); break; } default: { break; } } } } void ButtonLeft(void) { Screen_Timer.attach(&timout_timer,(SCRN_TIME));//Is this sufficient to reset/restart ticker timer for OLED? if (OLED_ON == 0) { OLED_ON = 1; // Screen was off, set to On update_display(); } else { switch(Screen_Num) { case 0: {// We're in Main Screen // do nothing, wrong button break; } case 1: {// Panic Alert option StartHaptic(); Screen_Num = 0; //Change to screen 0 update_display(); break; } case 2: {// Fall Alert option StartHaptic(); Screen_Num = 0; //Change to screen 0 update_display(); break; } case 3: {// Heart Rate Monitoring option StartHaptic(); Screen_Num = 0; //Change to screen 0 update_display(); break; } case 4: {// Alert History option StartHaptic(); Screen_Num = 0; //Change to screen 0 update_display(); break; } case 5: {// About HexiHeart option StartHaptic(); Screen_Num = 0; //Change to screen 0 update_display(); break; } case 6: {// Panic Alert StartHaptic(); Screen_Num = 1; //Change to screen 1 update_display(); break; } case 7: {// Heart Rate Zone StartHaptic(); Screen_Num = 3; //Change to screen 3 update_display(); break; } case 8: {// Alert History StartHaptic(); Screen_Num = 4; //Change to screen 4 update_display(); break; } case 20: {// Diagnostic/Debug Screens StartHaptic(); Screen_Num = 0; //Change to screen 0 update_display(); break; } case 21: {// Fall Diagnostic StartHaptic(); Screen_Num = 20; //Change to screen 20 update_display(); break; } case 22: {// Fall Debug StartHaptic(); Screen_Num = 20; //Change to screen 20 update_display(); break; } case 23: {// Heart Rate Diagnostic StartHaptic(); Screen_Num = 20; //Change to screen 20 update_display(); break; } case 24: {// Heart Rate Debug StartHaptic(); Screen_Num = 20; //Change to screen 20 update_display(); break; } case 25: {// Heat Index Diagnostic StartHaptic(); Screen_Num = 20; //Change to screen 20 update_display(); break; } case 26: {//Heart Rate Config Option StartHaptic(); Screen_Num = 0; update_display(); break; } case 27: {//Enter Age StartHaptic(); Screen_Num = 26; update_display(); break; } case 28: {//Heart Rate Vibration Preference Screen StartHaptic(); Screen_Num = 27; update_display(); break; } case 29: {//Heart Rate Zone Boundary Info StartHaptic(); Screen_Num = 28; update_display(); break; } case 30: {//Change Target Heart Rate Zone Preference StartHaptic(); Screen_Num = 29; update_display(); break; } default: { break; } } } } void ButtonSlide(void) // What is this Slide button??? { Screen_Timer.attach(&timout_timer,(SCRN_TIME));//Is this sufficient to reset/restart ticker timer for OLED? if (OLED_ON == 0) { OLED_ON = 1; // Screen was off, set to On } StartHaptic(); oled.FillScreen(COLOR_BLACK); // Clear screen strcpy((char *) text_1,"Slide Button"); oled.Label((uint8_t *)text_1,0,40); } int main() { oled.FillScreen(COLOR_BLACK); // Clear screen // ***************** Local variables *********************** // float accel_data[3]; float accel_rms=0.0; // ************** configure sensor modules ****************** accel.accel_config(); mag.mag_config(); // gyro.gyro_config(); RED_Led = LED_OFF; GRN_Led = LED_OFF; BLU_Led = LED_OFF; // ***** Register callbacks/interupts to application functions ********* kw40z_device.attach_buttonUp(&ButtonUp); kw40z_device.attach_buttonDown(&ButtonDown); kw40z_device.attach_buttonLeft(&ButtonLeft); kw40z_device.attach_buttonRight(&ButtonRight); kw40z_device.attach_buttonSlide(&ButtonSlide); // **** Get OLED Class Default Text Properties **************** oled_text_properties_t textProperties = {0}; oled.GetTextProperties(&textProperties); // *********Set text color and screen alignment ************** textProperties.fontColor = COLOR_WHITE; textProperties.alignParam = OLED_TEXT_ALIGN_LEFT; oled.SetTextProperties(&textProperties); // ************** Display spash screen ********************** oled.Label((uint8_t *)"Hexi",20,5); // Display white "Hexi" at x,y textProperties.fontColor = COLOR_RED; oled.SetTextProperties(&textProperties); oled.Label((uint8_t *)"Heart",45,5); // Display red "Heart" at x,y #ifdef Debug // if this is non-production version - do this strcpy((char *) text_1,"This is Debug Ver"); oled.Label((uint8_t *)text_1,0,60); // text_1 at x,y StartHaptic(); #endif textProperties.fontColor = COLOR_WHITE; oled.SetTextProperties(&textProperties); wait(3); // 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 ************************* while (true) { Thread::wait(500); // wait half a sec in each loop } } // ************** end of main() void update_display(void) { oled_text_properties_t textProperties = {0}; // Need these to change font color oled.GetTextProperties(&textProperties); // Need these to change font color switch(Screen_Num) { case 0: {// Main Screen oled.FillScreen(COLOR_BLACK); // Clear screen oled.Label((uint8_t *)"Batt",60,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 *)"H.I.",10,80); // Display "H.I." at x,y oled.Label((uint8_t *)"BT",40,80); //Display "BT" at x,y oled.Label((uint8_t *)"Menu",60,80); //Display "Menu" at x,y if(Heart_Rate_Mode == 1) { oled.Label((uint8_t *)"BPM",35,60); // Display "H.I." at x,y } break; } case 1: {// Panic Alert option oled.FillScreen(COLOR_BLACK); // Clear screen oled.Label((uint8_t *)"Panic Alert",20,5); // Display 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 oled.Label((uint8_t *)"Enter",60,80); //Display "enter" at x,y break; } 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 *)"*",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 break; } case 3: {// Heart Rate Monitoring option oled.FillScreen(COLOR_BLACK); // Clear screen oled.Label((uint8_t *)"Heart Rate",20,5); // Display 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 oled.Label((uint8_t *)"Enter",60,80); //Display at x,y break; } case 4: {// Alert History option oled.FillScreen(COLOR_BLACK); // Clear screen oled.Label((uint8_t *)"Alert History",5,5); // Display 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 oled.Label((uint8_t *)"Enter",60,80); //Display at x,y break; } case 5: {// About HexiHeart Screen oled.FillScreen(COLOR_BLACK); // Clear screen oled.Label((uint8_t *)"Hexi",20,20); // Display white "Hexi" at x,y textProperties.fontColor = COLOR_RED; oled.SetTextProperties(&textProperties); oled.Label((uint8_t *)"Heart",45,20); // Display red "Heart" at x,y textProperties.fontColor = COLOR_WHITE; oled.SetTextProperties(&textProperties); strcpy((char *) text_1,"About"); 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 break; } case 6: {// Panic Alert oled.FillScreen(COLOR_BLACK); // Clear screen if (Panic_Alert == 0) { oled.Label((uint8_t *)"Send ",20,10); // Display at x,y } else { oled.Label((uint8_t *)"Dismiss ",17,10); // Display at x,y } oled.Label((uint8_t *)"Panic Alert",15,40); // Display at x,y oled.Label((uint8_t *)"-->",80,15); // "*" at x,y oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y break; } case 7: {// Heart Rate Zone oled.FillScreen(COLOR_BLACK); // Clear screen oled.Label((uint8_t *)"Heart Rate",15,5); // Display at x,y oled.Label((uint8_t *)"HR:",15,25); // Display at x,y oled.Label((uint8_t *)"Age: ",15,45); // Display at x,y textProperties.fontColor = COLOR_GREEN; oled.SetTextProperties(&textProperties); //implements the color change sprintf(display_buff, "%u", Age); //Convert int to char array for displaying user age oled.Label((uint8_t *)display_buff,43,45); // 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",10,80); // Display "Back" at x,y oled.Label((uint8_t *)"Next",59,80); // Display "Next" at x,y //heart.enable(); //sprintf(display_buff, "%u", heart.getRevisionID()); //Convert int to char array for displaying user age //oled.Label((uint8_t *)display_buff,45,25); // Display at x,y //update_display(); break; } case 8: {// Alert History oled.FillScreen(COLOR_BLACK); // Clear screen oled.Label((uint8_t *)"Alert History",5,5); // Display at x,y oled.Label((uint8_t *)"Date - Time",20,40); // Display at x,y oled.Label((uint8_t *)"Alert Type:",20,60); // Display 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 break; } #ifdef Debug // if this is non-production/debug version - do this case 20: {// Diagnostic/Debug Screens oled.FillScreen(COLOR_BLACK); // Clear screen 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 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 break; } case 21: {// Fall Alert Diagnostic Screen oled.FillScreen(COLOR_BLACK); // Clear screen textProperties.fontColor = COLOR_RED; oled.SetTextProperties(&textProperties); oled.Label((uint8_t *)"Fall",30,5); // Display at x,y oled.Label((uint8_t *)"Diagnostic",25,5); // Display at x,y textProperties.fontColor = COLOR_WHITE; oled.SetTextProperties(&textProperties); accel.acquire_accel_data_g(Accel_Data); // gyro.acquire_gyro_data_g(Gyro_Data); Accel_Mag = sqrt(((Accel_Data[0]*Accel_Data[0])+(Accel_Data[1]*Accel_Data[1])+(Accel_Data[2]*Accel_Data[2]))); // Gyro_Mag = (abs(Gyro_Data[0])+abs(Gyro_Data[1])+abs(Gyro_Data[3])); sprintf(text_1," Accel:%2.2f g ",Accel_Mag); oled.Label((uint8_t *)text_1,10,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 *)"Back",10,80); // Display "Back" at x,y break; } case 22: {// Fall Alert Debug Screen oled.FillScreen(COLOR_BLACK); // Clear screen textProperties.fontColor = COLOR_RED; oled.SetTextProperties(&textProperties); oled.Label((uint8_t *)"Fall Debug",15,5); // Display at x,y textProperties.fontColor = COLOR_GREEN; oled.SetTextProperties(&textProperties); sprintf(text_1," %1.1f g ",Fall_Thresh); oled.Label((uint8_t *)text_1,35,20);// text_1 at x,y sprintf(text_1," %2.1f g ",Impact_Thresh); oled.Label((uint8_t *)text_1,35,35);// text_1 at x,y sprintf(text_1," %3.0f D/S ",Movement_Thresh); oled.Label((uint8_t *)text_1,35,50);// text_1 at x,y textProperties.fontColor = COLOR_WHITE; oled.SetTextProperties(&textProperties); oled.Label((uint8_t *)"F-Th:",5,20); // "*" at x,y oled.Label((uint8_t *)"I-Th:",5,35); // "*" at x,y oled.Label((uint8_t *)"M-Th:",5,50); // "*" 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 break; } case 23: {// Heart Rate Diagnostic Screen oled.FillScreen(COLOR_BLACK); // Clear screen textProperties.fontColor = COLOR_RED; oled.SetTextProperties(&textProperties); oled.Label((uint8_t *)"H.R. Diagnostic",5,5); // 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 *)" Enter ",59,80); //Display at x,y break; } case 24: {// Heart Rate Debug Screen oled.FillScreen(COLOR_BLACK); // Clear screen textProperties.fontColor = COLOR_RED; oled.SetTextProperties(&textProperties); oled.Label((uint8_t *)"H.R. Debug",10,5); // 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 *)" Enter ",59,80); //Display at x,y break; } case 25: {// Heat Index Diagnostic Screen oled.FillScreen(COLOR_BLACK); // Clear screen textProperties.fontColor = COLOR_RED; oled.SetTextProperties(&textProperties); oled.Label((uint8_t *)"H.I. Diagnostic",5,5); // 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 *)" Enter ",59,80); //Display at x,y break; } case 26: {//Heart Rate Config Option oled.FillScreen(COLOR_BLACK); // Clear screen oled.Label((uint8_t *)"HR Config",10,5); // Display 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 oled.Label((uint8_t *)"Enter",60,80); //Display "enter" at x,y break; } case 27: { //Enter Age Screen oled.FillScreen(COLOR_BLACK); oled.Label((uint8_t *)"Input Age", 10, 5); sprintf(display_buff, "%u", Age); //Convert int to char array for displaying user age oled.Label((uint8_t *)"Age:", 10, 30); oled.Label((uint8_t *)"+",85,15); // "*" at x,y oled.Label((uint8_t *)"-",85,60); // "*" at x,y oled.Label((uint8_t *)"Menu",10,80); // Display "Menu" 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); oled.Label((uint8_t *)"Max bpm:",10,50); textProperties.fontColor = COLOR_RED; oled.SetTextProperties(&textProperties); //implements the color change sprintf(display_buff, "%u", Max_BPM); //Convert int to char array for displaying user max bpm oled.Label((uint8_t *)display_buff, 65, 50); textProperties.fontColor = COLOR_WHITE; oled.SetTextProperties(&textProperties); break; } case 28: {//Choose Heart Rate Vibration Option oled.FillScreen(COLOR_BLACK); oled.Label((uint8_t *)"Vibrate Pref", 10, 10); oled.Label((uint8_t *)"Option:", 10, 25); 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 sprintf(display_buff, "%u", HR_Vibration); //Convert int to char array for displaying user preference textProperties.fontColor = COLOR_GREEN; //Change font to green oled.SetTextProperties(&textProperties);//Implement color change oled.Label((uint8_t *)display_buff,55,25); // Display at x,y if(HR_Vibration == 1) { textProperties.fontColor = COLOR_RED; //Change font to red oled.SetTextProperties(&textProperties); //Implement color change oled.Label((uint8_t *)"All On",10,45); // Display at x,y } else if(HR_Vibration == 2) { textProperties.fontColor = COLOR_RED; //Change font to red oled.SetTextProperties(&textProperties);//Implement color change oled.Label((uint8_t *)"Only Entering",10,38);// Display at x,y oled.Label((uint8_t *)"And Exiting",10,53);// Display at x,y oled.Label((uint8_t *)"Target Zone",10,68);// Display at x,y } else if(HR_Vibration == 3) { textProperties.fontColor = COLOR_RED; //Change font to red oled.SetTextProperties(&textProperties); //Implement color change oled.Label((uint8_t *)"All Off",10,45);// Display at x,y } textProperties.fontColor = COLOR_WHITE; oled.SetTextProperties(&textProperties); break; } case 29: { //Zone Boundary Info oled.FillScreen(COLOR_BLACK); oled.Label((uint8_t *)"HR Zone Info", 10, 5);// Display at x,y textProperties.fontColor = COLOR_YELLOW; //Change font to yellow oled.SetTextProperties(&textProperties);//Implement color change oled.Label((uint8_t *)"Z1:", 10, 20);// Display at x,y sprintf(display_buff, "%u", HR_Zone1[0]); // Convert int to char to display oled.Label((uint8_t *)display_buff, 30, 20);// Display at x,y oled.Label((uint8_t *)"-", 52, 20);// Display at x,y sprintf(display_buff, "%u", HR_Zone1[1]); // Convert int to char to display oled.Label((uint8_t *)display_buff, 60, 20);// Display at x,y textProperties.fontColor = COLOR_BLUE; //Change font to blue oled.SetTextProperties(&textProperties);//Implement color change oled.Label((uint8_t *)"Z2:", 10, 35);// Display at x,y sprintf(display_buff, "%u", HR_Zone2[0]); // Convert int to char to display oled.Label((uint8_t *)display_buff, 30, 35);// Display at x,y oled.Label((uint8_t *)"-", 52, 35);// Display at x,y sprintf(display_buff, "%u", HR_Zone2[1]); // Convert int to char to display oled.Label((uint8_t *)display_buff, 60, 35);// Display at x,y textProperties.fontColor = COLOR_GREEN; //Change font to green oled.SetTextProperties(&textProperties);//Implement color change oled.Label((uint8_t *)"Z3:", 10, 50);// Display at x,y sprintf(display_buff, "%u", HR_Zone3[0]); // Convert int to char to display oled.Label((uint8_t *)display_buff, 30, 50);// Display at x,y oled.Label((uint8_t *)"-", 52, 50);// Display at x,y sprintf(display_buff, "%u", HR_Zone3[1]); // Convert int to char to display oled.Label((uint8_t *)display_buff, 60, 50);// Display at x,y textProperties.fontColor = COLOR_RED; //Change font to red oled.SetTextProperties(&textProperties);//Implement color change oled.Label((uint8_t *)"Z4:", 10, 65);// Display at x,y sprintf(display_buff, "%u", HR_Zone4[0]); // Convert int to char to display oled.Label((uint8_t *)display_buff, 30, 65);// Display at x,y oled.Label((uint8_t *)"-", 52, 65);// Display at x,y sprintf(display_buff, "%u", HR_Zone4[1]); // Convert int to char to display oled.Label((uint8_t *)display_buff, 60, 65);// Display at x,y textProperties.fontColor = COLOR_WHITE; //Change font to white oled.SetTextProperties(&textProperties);//Implement color change oled.Label((uint8_t *)"Back",10,80); // Display "Back" at x,y oled.Label((uint8_t *)"Next",60,80); //Display "Next" at x,y break; } case 30:{ //Enter Target Heart Rate Zone Preference oled.FillScreen(COLOR_BLACK); oled.Label((uint8_t *)"Zone Pref", 10, 5);// Display 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 *)"+",85,15); // "+" at x,y oled.Label((uint8_t *)"-",85,60); // "-" at x,y oled.Label((uint8_t *)"Target:", 10, 25);// Display at x,y sprintf(display_buff, "%u", Target_Zone); // Convert int to char to display if(Target_Zone == 1) { textProperties.fontColor = COLOR_YELLOW; //Change font to yellow oled.SetTextProperties(&textProperties);//Implement color change } else if(Target_Zone == 2) { textProperties.fontColor = COLOR_BLUE; //Change font to blue oled.SetTextProperties(&textProperties);//Implement color change } else if(Target_Zone == 3) { textProperties.fontColor = COLOR_GREEN; //Change font to green oled.SetTextProperties(&textProperties);//Implement color change } else if(Target_Zone == 4) { textProperties.fontColor = COLOR_RED; //Change font to red oled.SetTextProperties(&textProperties);//Implement color change } oled.Label((uint8_t *)display_buff, 55, 25);// Display at x,y textProperties.fontColor = COLOR_WHITE; //Change font to white oled.SetTextProperties(&textProperties);//Implement color change oled.Label((uint8_t *)"Bounds:", 10, 45);// Display at x,y if(Target_Zone == 1) { textProperties.fontColor = COLOR_YELLOW; //Change font to yellow oled.SetTextProperties(&textProperties);//Implement color change sprintf(display_buff, "%u", HR_Zone1[0]); // Convert int to char to display oled.Label((uint8_t *)display_buff, 10, 60);// Display at x,y oled.Label((uint8_t *)"-", 32, 60);// Display at x,y sprintf(display_buff, "%u", HR_Zone1[1]); // Convert int to char to display oled.Label((uint8_t *)display_buff, 40, 60);// Display at x,y } else if(Target_Zone == 2) { textProperties.fontColor = COLOR_BLUE; //Change font to blue oled.SetTextProperties(&textProperties);//Implement color change sprintf(display_buff, "%u", HR_Zone2[0]); // Convert int to char to display oled.Label((uint8_t *)display_buff, 10, 60);// Display at x,y oled.Label((uint8_t *)"-", 32, 60);// Display at x,y sprintf(display_buff, "%u", HR_Zone2[1]); // Convert int to char to display oled.Label((uint8_t *)display_buff, 40, 60);// Display at x,y } else if(Target_Zone == 3) { textProperties.fontColor = COLOR_GREEN; //Change font to green oled.SetTextProperties(&textProperties);//Implement color change sprintf(display_buff, "%u", HR_Zone3[0]); // Convert int to char to display oled.Label((uint8_t *)display_buff, 10, 60); // Display at x,y oled.Label((uint8_t *)"-", 32, 60); // Display at x,y sprintf(display_buff, "%u", HR_Zone3[1]); // Convert int to char to display oled.Label((uint8_t *)display_buff, 40, 60);// Display at x,y } else if(Target_Zone == 4) { textProperties.fontColor = COLOR_RED; //Change font to red oled.SetTextProperties(&textProperties);//Implement color change sprintf(display_buff, "%u", HR_Zone4[0]); // Convert int to char to display oled.Label((uint8_t *)display_buff, 10, 60); // Display at x,y oled.Label((uint8_t *)"-", 32, 60); // Display at x,y sprintf(display_buff, "%u", HR_Zone4[1]); // Convert int to char to display oled.Label((uint8_t *)display_buff, 40, 60); // Display at x,y } textProperties.fontColor = COLOR_WHITE; //Change font to white oled.SetTextProperties(&textProperties);//Implement color change break; } #endif // end of non-production/debug version code default: { Error_Num=1; error_screen(); // Clear screen break; } } } void error_screen(void) { oled.FillScreen(COLOR_RED); // Clear screen oled.Label((uint8_t *)"Error! ",30,30); // Display error at x,y sprintf(text_1," %i ",Error_Num); oled.Label((uint8_t *)text_1,30,60); // Display error at x,y wait(3); // wait 3 seconds oled.FillScreen(COLOR_BLACK); // Clear screen } void StartHaptic(void) { hapticTimer.start(30); // was originaly 50 haptic = 1; } void StartHaptic(int x) { hapticTimer.start(x); haptic = 1; } void StopHaptic(void const *n) { haptic = 0; hapticTimer.stop(); }