Changes done in ECG and BT
Dependencies: SDFileSystem ds3231 eeprom_Nikita mbed testUniGraphic_150217
Fork of merged_code2_20sept_2017_4th_oct_2017 by
Diff: main.cpp
- Revision:
- 44:05dbea558c9a
- Parent:
- 43:85a7f399cb9d
- Child:
- 45:067673dae242
--- a/main.cpp Mon Sep 11 13:09:29 2017 +0000 +++ b/main.cpp Tue Sep 12 04:16:41 2017 +0000 @@ -13,13 +13,16 @@ #include "struct.h" #include "battery.h" #include "main.h" +#define TIMER_RXACK_BTCONNECTION 10000 Serial gc(USBTX, USBRX); DigitalIn q1(PTB11); DigitalIn q(PTC5); DigitalIn q3(PTC12); DigitalIn BT(PTA5); - //bluetooth status pin +Serial blue1(PTC4,PTC3); +uint32_t get_timer_bluetooth(); + //bluetooth status pin uint8_t touch(uint8_t state); // touch state uint8_t display(uint8_t state1); // display state static uint8_t nstate=0; @@ -29,6 +32,9 @@ static uint32_t pid = 0; // patient ID static bool file_created_status = false; //initialise file created to 0 static uint32_t filepid_btpid[2] = {}; +Timer bt_t; // timer + + int main() { @@ -37,7 +43,7 @@ static uint8_t state_touch = 1; static uint8_t state_t = 1; // state to transmit to bluetooth static uint8_t state_r = 0; // state to receive from bluetooth - uint8_t battery_voltage_condition = 0; +// uint8_t battery_voltage_condition = 0; DisableTouch(); @@ -70,30 +76,102 @@ case 3: - DisableTouch(); // bluetooth send - if(BT==1) + DisableTouch(); // bluetooth send + bt_t.start(); + if(get_timer_bluetooth()<TIMER_RXACK_BTCONNECTION) // bluetooth connection timer 15 sec { - BT_connection() ; // displaying connection on bluetooth - state_r=bt_send(state_t); - main_state=4; - } - else - BT_no_connection(); - - break; + + if(BT==1) // checking for bluetooth connection + { + + bt_t.stop(); // stop the timer once connected to app + bt_t.reset(); + BT_connection() ; // displaying connection on bluetooth + state_r=bt_send(state_t); + bt_t.start(); + + if (state_r==0) // if the state received is zero, then there is no new file to send + { + bt_t.stop(); // stop the timer once connected to app + bt_t.reset(); + BT_finished(); // screen to display communication finished + screen_BT_return(); //screen to return back + EnableTouch(); + main_state=1; + state_touch=12; + break; + } + + else + { + main_state=4; // move to receving stste of bluetooth + } + + } + + else + { + BT_no_connection(); // display screen to show that there is no connection + } + } + + + + else + { + BT_no_connection(); // display screen to show that there is no connection + gc.printf("stopped"); + screen_BT_return(); // button to return + EnableTouch(); + main_state=1; + state_touch=12; + bt_t.stop(); + bt_t.reset(); + } + break; - case 4: DisableTouch(); - state_t=bt_receive(state_r); // bluetooth receive - main_state=3; - if(state_t ==0) - { - BT_finished(); - screen_BT_return(); - EnableTouch(); - main_state=1; - state_touch=12; // jumping to touch case 12 - } - break; + case 4: DisableTouch(); + + if(get_timer_bluetooth()<TIMER_RXACK_BTCONNECTION) + { + if (blue1.readable()) // if there is data to receive enter the loop + { + bt_t.stop(); + bt_t.reset(); + state_t=bt_receive(state_r); + if(state_t ==0) // if state_t is zero, there is no other file to send + { + //bt_t.stop(); + //bt_t.reset(); + BT_finished(); + screen_BT_return(); + EnableTouch(); + main_state=1; + state_touch=12; // jumping to touch case 12 + break; + } + else // move to bluetooth transmit if the states are 1,2,3,4 + { + main_state=3; + + } } + } + + + else + { + DisableTouch(); + BT_no_connection(); // display screen to show that there is no connection + gc.printf("stopped"); + screen_BT_return(); // button to return + EnableTouch(); + main_state=1; + state_touch=12; + bt_t.stop(); + bt_t.reset(); + } + + break; } } @@ -454,3 +532,7 @@ } +uint32_t get_timer_bluetooth() +{ + return bt_t.read_ms(); +}