
Changes done in ECG and BT
Dependencies: SDFileSystem ds3231 eeprom_Nikita mbed testUniGraphic_150217
Fork of merged_code2_20sept_2017_4th_oct_2017 by
Revision 37:92fcbf22bf91, committed 2017-07-29
- Comitter:
- avp2417
- Date:
- Sat Jul 29 12:12:28 2017 +0000
- Parent:
- 36:00d96aa14658
- Child:
- 38:7238f3531ce9
- Commit message:
- Modification carried out by Nikita related to display screen timeout + Battery monitoring.
Changed in this revision
--- a/battery.cpp Sat Jul 29 11:23:19 2017 +0000 +++ b/battery.cpp Sat Jul 29 12:12:28 2017 +0000 @@ -1,17 +1,34 @@ #include "mbed.h" #include "battery.h" - +#include "display_modules.h" AnalogIn A(PTB1); -float battery_voltage() { - // GLC_PWR=1; - // Enable=1;Shutdown=1; +uint8_t battery_voltage() { float b_voltage; - //unsigned int samples1[4]; - //unsigned int data2n; - - b_voltage = A.read_u16()*(3.3/65535)*2; +uint8_t battery_condition=0; + b_voltage = A.read_u16()*(3.3/65535)*2; wait(0.001f); - -return b_voltage; + if (b_voltage>3.64) + { + battery_screen_charge(); + battery_condition=0; + } + else if (3.605>b_voltage>3.57) ///15% to 10% + { + battery_low_charge(); + battery_condition=1; + } + else if (3.57>b_voltage>3.535) /// 10% to 5% + { + battery_critically_low_charge(); + battery_condition=2; + } + else if (3.535>b_voltage) + { + battery_screen_nocharge(); + battery_condition=3; + } + + +return battery_condition; } \ No newline at end of file
--- a/battery.h Sat Jul 29 11:23:19 2017 +0000 +++ b/battery.h Sat Jul 29 12:12:28 2017 +0000 @@ -3,7 +3,7 @@ -float battery_voltage(); +uint8_t battery_voltage(); #endif \ No newline at end of file
--- a/display_modules.cpp Sat Jul 29 11:23:19 2017 +0000 +++ b/display_modules.cpp Sat Jul 29 12:12:28 2017 +0000 @@ -497,40 +497,70 @@ } - void bat_screen_nocharge() + void battery_screen_nocharge() { - - /* lcd.FillRect(10,10,20,40,COLOR_RED); - lcd.FillRect(5,127,230,200,COLOR_BLACK); - lcd.FillRoundRect(60,230,180,300,COLOR_BLACK); - lcd.Print( "Low battery",60,130 ,COLOR_RED,COLOR_BLACK, 0); - lcd.Print( "Connect",60,160 ,COLOR_RED,COLOR_BLACK, 0); - lcd.Print( "Charger",30,205,COLOR_RED,COLOR_BLACK,0); */ - + + + backlight = 0 ; + TFT.BusEnable(true) ; + TFT.background(White) ; + TFT.set_font((unsigned char*) Arial12x12); + TFT.foreground(Red); + TFT.locate(10,8) ; + TFT.printf("No Charge") ; + TFT.set_font((unsigned char*) Arial24x23); + TFT.BusEnable(false) ; + backlight = 1 ; + + + } + + void battery_screen_charge() + { backlight = 0 ; TFT.BusEnable(true) ; - TFT.fillrect(10,10,20,40,Red); - TFT.fillrect(5,127,230,200,White); - TFT.fillrect(60,230,180,300,White); - TFT.locate(60,130) ; - TFT.printf("Low battery") ; - - - - TFT.BusEnable(false) ; - backlight = 1 ; - - } - - void bat_screen_charge() -{ - // lcd.FillRect(10,10,20,40,COLOR_GREEN); - backlight = 0 ; + TFT.background(White) ; + TFT.set_font((unsigned char*) Arial12x12); + TFT.foreground(Green); + TFT.locate(10,8) ; + TFT.printf("Battery Charged") ; + TFT.set_font((unsigned char*) Arial24x23); + TFT.BusEnable(false) ; + backlight = 1 ; + + } + + + + void battery_critically_low_charge() + { + backlight = 0 ; TFT.BusEnable(true) ; - TFT.fillrect(10,10,20,40,Green); - TFT.BusEnable(false) ; - backlight = 1 ; -} + TFT.background(White) ; + TFT.set_font((unsigned char*) Arial12x12); + TFT.foreground(Green); + TFT.locate(10,8) ; + TFT.printf("Critically Low") ; + TFT.set_font((unsigned char*) Arial24x23); + TFT.BusEnable(false) ; + backlight = 1 ; + + } + + void battery_low_charge() + { + backlight = 0 ; + TFT.BusEnable(true) ; + TFT.background(White) ; + TFT.set_font((unsigned char*) Arial12x12); + TFT.foreground(Green); + TFT.locate(10,8) ; + TFT.printf("Low Battery") ; + TFT.set_font((unsigned char*) Arial24x23); + TFT.BusEnable(false) ; + backlight = 1 ; + + } void screen_ecg_error() {
--- a/display_modules.h Sat Jul 29 11:23:19 2017 +0000 +++ b/display_modules.h Sat Jul 29 12:12:28 2017 +0000 @@ -24,8 +24,8 @@ void screen_glc_2(); void screen_bp1(float SBP, float DBP) ; void screen_ecg_lead_bp_fingerdetect(); -void bat_screen_nocharge(); -void bat_screen_charge(); +void battery_screen_nocharge(); +void battery_screen_charge(); void screen_ecg_error(); // display of error condition for Heart rate void screen_bp_error(); // display of error condition for BP void glc_error(); //display of error condition for BG @@ -34,4 +34,6 @@ void BT_finished(); //Files transfer completed void screen_BT_return(); // dispaly of return option to bluetooth void screen_patient_info(uint32_t current_test_pid,uint32_t bt_file_sent_pid); +void battery_critically_low_charge(); +void battery_low_charge(); #endif
--- a/main.cpp Sat Jul 29 11:23:19 2017 +0000 +++ b/main.cpp Sat Jul 29 12:12:28 2017 +0000 @@ -34,41 +34,35 @@ int main(){ - - - - - DisableTouch(); - gc.baud(115200); - - init_screen(); //initialize lcd - screen_main(); // display of main screen - //state=10; - flag=0; - //nstate=state; - EnableTouch(); // enable touch function static uint8_t main_state=1; static uint8_t state_display=0; static uint8_t state_touch=1; static uint8_t state_t=1; static uint8_t state_r=0; - float b_voltage=0; - /* b_voltage=battery_voltage(); - //gc.printf("%f \n", b_voltage ); - if (b_voltage<3.5) - { - bat_screen_nocharge(); - DisableTouch(); - } - - -else - { - // enable touch function - bat_screen_charge(); - EnableTouch();*/ +uint8_t battery_voltage_condition=0; + + + DisableTouch(); + gc.baud(115200); + init_screen(); //initialize lcd + screen_main(); // display of main screen + + while(1) { + DisableTouch(); + battery_voltage_condition=battery_voltage(); + + if (battery_voltage_condition==3) + { + DisableTouch(); + } + + + else + { + + EnableTouch(); switch(main_state) // main state machine { case 1: state_display=touch(state_touch); // touch state @@ -120,7 +114,7 @@ state_touch=12; // jumping to touch case 12 } break; - + } } } @@ -133,7 +127,7 @@ uint8_t touch(uint8_t state) { static uint8_t state1=0; - detect_touch(); // determine the touch points + detect_touch(state); // determine the touch points switch(state) // state for touch {
--- a/touch_modules.cpp Sat Jul 29 11:23:19 2017 +0000 +++ b/touch_modules.cpp Sat Jul 29 12:12:28 2017 +0000 @@ -9,7 +9,7 @@ unsigned int xt=0; unsigned int yt=0; Serial kc(USBTX, USBRX); - +Timer t1; void touch1() //determining the touch co-ordinates { @@ -20,13 +20,32 @@ } -void detect_touch() // detect the touch //debounce +void detect_touch(unsigned char display_state) // detect the touch //debounce { - -while(i==1) -{ - while(Touch_D)//touch detection +kc.printf("display state=%d\n",display_state); +uint32_t time_ms=0; +switch (display_state) + + { + + case 3: time_ms= 3000000; // timer for 5 min + touch_func_with_timer(time_ms); + break; + case 6: time_ms= 60000; // timer for 1 min + touch_func_with_timer(time_ms); + break; + default : touch_func_without_timer(); + break; + + } +} + + void touch_func_without_timer() + { + while(i==1) { + while(Touch_D)//touch detection + { wait_ms(200); ///wait for debounce check if (Touch_D) { @@ -39,11 +58,14 @@ //kc.printf("touch"); } - } - EnableTouch(); + } +} + +void no_touch() +{ + xt=0;yt=0; - } - + } unsigned char touch_main() //determining the touch for home screen @@ -129,10 +151,14 @@ state=1; } - + else if (xt==0 && yt==0) + { + state=1; + } else + { state=10; // default - goes to wait for a valid touch - + } return state; } @@ -182,6 +208,10 @@ state=8; else if (type==2) state=9; + } + else if (xt==0 && yt==0) + { + state=3; } else state=10; @@ -449,4 +479,48 @@ DigitalOut XL(PTC13); DigitalOut YU(PTC0); DigitalOut XR(PTB0); - } \ No newline at end of file + } + +uint32_t get_timer() +{ + kc.printf("time=%d",t1.read_ms()); + return t1.read_ms(); + } + + + +void touch_func_with_timer(uint32_t time_ms) + { + t1.reset(); + while(i==1) + { + t1.start(); + if (get_timer()<time_ms) + { + while(Touch_D)//touch detection + { + wait_ms(200); ///wait for debounce check + if (Touch_D) + { + Touch_D.fall(&touch1); + + //determine the touch co-ordinates + break; + } + DisableTouch(); + //kc.printf("touch"); + + } + } + else + { + t1.stop(); + t1.reset(); + DisableTouch(); + no_touch(); + break; + + } + + } +} \ No newline at end of file
--- a/touch_modules.h Sat Jul 29 11:23:19 2017 +0000 +++ b/touch_modules.h Sat Jul 29 12:12:28 2017 +0000 @@ -106,7 +106,7 @@ unsigned char touch_main_2(); void touch1() ; int readTouchY(void); -void detect_touch(); +void detect_touch(unsigned char display_state); int readTouchX(void); void EnableTouch(void); void DisableTouch (void); @@ -120,5 +120,9 @@ unsigned char touch_again_bp(); void screen_bp2(); unsigned char BT_return(); // //determining the touch for bp main screen +void touch_func_with_timer(uint32_t time_ms); +void touch_func_without_timer(); +uint32_t get_timer(); +void no_touch(); #endif \ No newline at end of file