Hopkins (Henry) / Mbed 2 deprecated DFEB_New_Sync

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Functions.cpp Source File

Functions.cpp

00001 #include "Functions.h"
00002 
00003 
00004 bool syncShockReady = false;
00005 
00006 //Delivering the HFAC and Dfeb Shock
00007 void Delivering (int amplitude, int duration)
00008 {
00009 
00010     uint16_t sample = 0;
00011     double step= (amplitude*220)/duration;
00012 
00013     for(int HFAC_Count=1; HFAC_Count<= duration; ++HFAC_Count)
00014     {
00015         sample = (uint16_t)(offset + (step*HFAC_Count));
00016         HFAC.write_u16(sample);
00017         wait_us(500);
00018         
00019         //pc.printf("%d\r\n",duration - HFAC_Count);
00020         if((duration - HFAC_Count) == 11){
00021             led1 = 0;
00022             SyncOut = 1;
00023         }
00024         
00025         sample = (uint16_t)(offset - (step*HFAC_Count));
00026         HFAC.write_u16(sample);
00027         wait_us(500);
00028     }
00029     
00030     HFAC_Relay = 0;
00031     M_Relay = 1;
00032     R_Relay = 0;
00033     wait_ms(1);
00034     M_Relay = 0;
00035     SyncOut =0;
00036     shock = 0;
00037     HFAC.write_u16(offset);
00038     buttonLEDs(shockButtonRedLED, Disable);
00039     
00040 }
00041 
00042 //Delivering the HFAC and Dfeb Shock in the sync mode
00043 void SyncDelivering()
00044 {
00045     if (byPassStatus)
00046         Delivering (HFAC_Amplitude, HFAC_Duration);
00047     else
00048         Delivering (10, 100);
00049 
00050     wait_ms(1000);
00051 }
00052 
00053 //Check the by Pass mode "HFAC ON or OFF"
00054 void checkByPass()
00055 {
00056     wait_ms(100);
00057     if (byPassButton){
00058         LCD.putc('A');
00059         byPassStatus = false;
00060     }
00061     else{
00062         LCD.putc('B');
00063         byPassStatus = true;
00064     }
00065     led4 = !led4;
00066 }
00067 
00068 //Interrupt function for R wave fall time 
00069 void  syncInFuncFall()
00070 {
00071     wait_ms(100);
00072     if (syncShock){
00073             buttonLEDs(shockButtonGreenLED, Disable);
00074     }
00075 }
00076 //Interrupt function for R wave raise time (Also calculating the average of 
00077 // HeartRateAvg samples of R wave signals
00078 void syncInFunc()
00079 {
00080    if (syncShock) 
00081         if(heartRateTimerStart){
00082             if (heartMeanCounter < HeartRateAvg){
00083                 buttonLEDs(shockButtonGreenLED, Enable);
00084                 heartRateTemp += heartRateTimer.read_us();
00085                 //pc.printf("%d   ", heartMeanCounter); 
00086                 heartMeanCounter ++;
00087             }
00088             else{
00089                 syncShock = false;
00090                 buttonLEDs(shockButtonRedLED, Enable);
00091 
00092                 heartRate = heartRateTemp / HeartRateAvg;
00093                 heartMeanCounter = 0;
00094                 heartRateTemp = 0;
00095                 int fireTime =  heartRate - ((HFAC_Duration*1000) % heartRate)- 013.8* HFAC_Duration - 23625;//- ( -0.011*HFAC_Duration + 45.278)-10; 
00096                 //pc.printf("%d   ", heartRate);
00097                 //pc.printf("%d   ", HFAC_Duration);
00098                 //pc.printf("%d   ", fireTime); 
00099                 deliverTimeout.attach_us(&SyncDelivering, fireTime);
00100                 
00101             } 
00102             heartRateTimer.reset();
00103         }
00104         else{
00105             heartRateTimerStart = true;
00106             heartRateTimer.start();
00107             heartMeanCounter = 0;
00108         }
00109 
00110     
00111 }
00112 
00113 //Shock and Charge button LEDS
00114 void buttonLEDs(int led, bool enable)
00115 {
00116     switch (led) {
00117         case 0:
00118             if(enable) {
00119                 shockRedLED = 1;
00120                 shockGreenLED = 0;
00121             } else {
00122                 shockRedLED = 0;
00123                 shockGreenLED = 0;
00124             }
00125             break;
00126         case 1:
00127             if(enable) {
00128                 shockRedLED = 0;
00129                 shockGreenLED = 1;
00130             } else {
00131                 shockRedLED = 0;
00132                 shockGreenLED = 0;
00133             }
00134             break;
00135         case 2:
00136             if(enable) {
00137                 chargeRedLED = 1;
00138                 chargeGreenLED = 0;
00139             } else {
00140                 chargeRedLED = 0;
00141                 chargeGreenLED = 0;
00142             }
00143             break;
00144         case 3:
00145             if(enable) {
00146                 chargeRedLED = 0;
00147                 chargeGreenLED = 1;
00148             } else {
00149                 chargeRedLED = 0;
00150                 chargeGreenLED = 1;
00151             }
00152             break;
00153     }
00154 }