
reeeeeeeeeeeeeee
Dependencies: MotionSensor mbed
Fork of Assignment2_ver3 by
Revision 7:6dc42e1a2a81, committed 2016-11-29
- Comitter:
- weebgrammers
- Date:
- Tue Nov 29 20:21:45 2016 +0000
- Parent:
- 6:9b8fee13549c
- Child:
- 8:45befd2bb1e5
- Commit message:
- s
Changed in this revision
--- a/Hardware.cpp Mon Nov 14 22:47:00 2016 +0000 +++ b/Hardware.cpp Tue Nov 29 20:21:45 2016 +0000 @@ -1,5 +1,196 @@ #include "Hardware.h" #include "mbed.h" +#define LOW 0 +#define HIGH 1 DigitalOut output_pin_A(LED3); -DigitalOut output_pin_V(LED2); \ No newline at end of file +DigitalOut output_pin_V(LED2); +/*=== Analog In ===*/ +AnalogIn atrialIn (A0); // Pin A0 +AnalogIn ventricleIn (A1); // Pin A1 +AnalogIn leadImpedence (A2); // Pin A2 +AnalogIn atr_rect_signal (A3); // Pin A3 +AnalogIn vent_rect_signal (A4); // Pin A4 + +/*=== Digital In ===*/ +DigitalIn atria_cmp_detect (PTC16); // Pin D0 +DigitalIn vent_cmp_detect (PTC17); // Pin D1 + +/*=== PWM Out ===*/ +/* DigitalOut is used for the REF Signal + * due to absence of PWM capabilities of Pins D2 and D4 + * on the FRDM-K64F Board + */ +DigitalOut pacing_ref_pwm (PTB9); // Pin D2 (PTB9) +PwmOut vent_ref_pwm (PTA1); // Pin D3 +DigitalOut atria_ref_pwm (PTB23); // Pin D4 + + +/*=== Digital Out ===*/ +DigitalOut pace_charge_ctrl (PTA2); // Pin D5 +DigitalOut z_atria_ctrl (PTC2); // Pin D6 +DigitalOut z_vent_ctrl (PTC3); // Pin D7 + +DigitalOut atr_pace_ctrl (PTC12); // Pin D8 +DigitalOut vent_pace_ctrl (PTC4); // Pin D9 +DigitalOut pace_grnd_ctrl (PTD0); // Pin D10 +DigitalOut atr_grnd_ctrl (PTD2); // Pin D11 +DigitalOut vent_grnd_ctrl (PTD3); // Pin D12 +DigitalOut frontend_ctrl (PTD1); // Pin D13 + +/*=== On-Board Tri-LED ===*/ +DigitalOut rled (LED_RED); +DigitalOut gled (LED_GREEN); +DigitalOut bled (LED_BLUE); + + +void send_data(Serial &pc,PaceHeart &Pacer){ + + pc.printf ("%c",(char)Pacer.get_p_pacingState()); + pc.printf ("%c",(char)Pacer.get_p_pacingMode()); + pc.printf ("%c",(char)Pacer.get_p_hysteresis()); + pc.printf ("%c%c",(char)((int)(Pacer.get_p_hysteresisInterval()/128)),(char)(Pacer.get_p_hysteresisInterval()%128)); + pc.printf ("%c%c",(char)((int)(Pacer.get_p_lowrateInterval()/128)),(char)((int)(Pacer.get_p_lowrateInterval())%128)); + pc.printf ("%c%c",(char)((int)(Pacer.get_p_vPaceAmp())/128),(char)((int)(Pacer.get_p_vPaceAmp())%128)); + pc.printf ("%c%c",(char)((int)(10.0*Pacer.get_p_vPaceWidth())/128),(char)((int)(10.0*Pacer.get_p_vPaceWidth())%128));//10*pace width + pc.printf ("%c%c\n",(char)((int)(Pacer.get_p_VRP()/128)),(char)(Pacer.get_p_VRP()%128)); + return; +} +void request_data(Serial &pc,PaceHeart &Pacer){ //implement limit later + char d[14]; + int e = 0; + pc.scanf("%s",&d); + pc.printf("%c",'e');//end + e = (int)d[0]; + //Pacer.set_p_pacingState(e); + e = (int)d[1]; + // Pacer.set_p_pacingMode(e); + e = (int)d[2]; + Pacer.set_p_hysteresis(e); + e = (int)d[3]*128+(int)d[4]; + Pacer.set_p_hysteresisInterval(e); + e = (int)d[5]*128+(int)d[6]; + Pacer.set_p_lowrateInterval(e); + e = (int)d[7]*128+(int)d[8]; + Pacer.set_p_vPaceAmp((double)e); + e = (int)d[9]*128+(int)d[10]; + Pacer.set_p_vPaceWidth((double)e/10.0); + e = (int)d[11]*128+(int)d[12]; + Pacer.set_p_VRP(e); +} + + +void stream_A(Serial &pc){ + int amp = (int)(3450*vent_rect_signal); + pc.printf("%c%c\n",(char)(amp/128),(char)(amp%128)); +} + +void stream_V(Serial &pc){ + int amp = (int)(3450*ventricleIn); + pc.printf("%c%c\n",(char)(amp/128),(char)(amp%128)); +} + +void stream(Serial &pc, char mode){ + char c; + while(1){ + if(pc.readable()!=0){ + c = pc.getc(); + if(c=='q'){ + stream_A(pc); + output_pin_V=!output_pin_V; + } + else if(c=='w'){ + return; + } + } + } +} + +void Check_serial(Serial &pc,PaceHeart &Pacer){ + char c = pc.getc(); + if(c=='r'){//send params + send_data(pc,Pacer); + } + else if(c=='s') {//set params + request_data(pc,Pacer); + } + else if(c=='q'){ //stream egram + stream(pc,c); + } +} + + +void Output_A(double amp, double wid){ + vent_ref_pwm = 0.5f; + vent_ref_pwm.pulsewidth(2); + /*AnalogOut aout(p18); //sets up pin 18 as an analogue output + AnalogueIn ain(p15); //sets up pin 15 and an analogue input + + int main(){ + aout=0.5; //sets output to 0.5*VCC + while(1){ //sets up a loop + if (ain>0.3){ //tests whether the input is above 0.3 + aout=0; //sets the output to 0 + } + aout = 0.5; + wait(1); + aout = 0;*/ + // test the voltage on the initialized analog pin + // and if greater than 0.3 * VCC set the digital pin + // to a logic 1 otherwise a logic 0 +} +void Output_V(double amp,double wid){ + //vent_ref_pwm = 0.5f; + //vent_ref_pwm.pulsewidth(2); + atr_grnd_ctrl = LOW; + vent_grnd_ctrl = LOW; + + /* Stage 1: Ref PWM On */ + pacing_ref_pwm = HIGH; + wait_ms(10); + + /* Stage 2: Charge CTRL on */ + pace_charge_ctrl = HIGH; + wait_ms(10); + + vent_pace_ctrl = HIGH; + + // Pace Duration + wait_us(wid/10); + + // Shut off Pace + vent_pace_ctrl = LOW; + + atr_pace_ctrl = LOW; + vent_pace_ctrl = LOW; + atr_grnd_ctrl = HIGH; + vent_grnd_ctrl = HIGH; + wait_ms(50); + + + /* Stage 2: Ref PWM LOW */ + pacing_ref_pwm = LOW; + wait_ms(100); + + /* Stage 3: Charge CTRL off */ + pace_charge_ctrl = LOW; + wait_ms(10); + + /* Stage 4: Ground OFF */ + atr_grnd_ctrl = LOW; + vent_grnd_ctrl = LOW; + + output_pin_V=!output_pin_V; + /*AnalogOut aout(p18); //sets up pin 18 as an analogue output + AnalogueIn ain(p15); //sets up pin 15 and an analogue input + + int main(){ + aout=0.5; //sets output to 0.5*VCC + while(1){ //sets up a loop + if (ain>0.3){ //tests whether the input is above 0.3 + aout=0; //sets the output to 0 + } + aout = 0.5; + wait(1); + aout = 0;*/ +} \ No newline at end of file
--- a/Hardware.h Mon Nov 14 22:47:00 2016 +0000 +++ b/Hardware.h Tue Nov 29 20:21:45 2016 +0000 @@ -1,12 +1,13 @@ #include <string> using namespace std; #include "mbed.h" - +#include "PaceHeart.h" #ifndef HARDWARE_H #define HARDWARE_H -int get_(); - extern DigitalOut output_pin_A; extern DigitalOut output_pin_V; +void Check_serial(Serial &pc,PaceHeart &Pacer); +void Output_A(double amp,double wid); +void Output_V(double amp,double wid); #endif \ No newline at end of file
--- a/PaceHeart.cpp Mon Nov 14 22:47:00 2016 +0000 +++ b/PaceHeart.cpp Tue Nov 29 20:21:45 2016 +0000 @@ -9,41 +9,48 @@ p_pacingState = 0; p_pacingMode = 0; - int p_hysteresis = 0; - int p_hysteresisInterval = 300; - double p_lowrateInterval = 1000.0; - double p_uprateInterval = 500.0; //upper rate limit + p_hysteresis = 0; + p_hysteresisInterval = 300; + p_lowrateInterval = 1000.0; + p_uprateInterval = 500.0; //upper rate limit //Ventricle - double p_vPaceAmp = 3500.0; - double p_vPaceWidth = 0.4; - int p_VRP = 320; + p_vPaceAmp = 3500.0; + p_vPaceWidth = 0.4; + p_VRP = 320; //Atrium (change defaults) - double p_aPaceAmp = 3500.0; - double p_aPaceWidth = 0.4; - int p_ARP = 320; + p_aPaceAmp = 3500.0; + p_aPaceWidth = 0.4; + p_ARP = 320; } PaceHeart::PaceHeart(int mode){ p_pacingState = 0; p_pacingMode = mode; - double p_lowrateInterval = 1000.0; //30-50->5 50-90->1 90-175->5 ppm - double p_uprateInterval = 2000.0; //upper rate limit 50-175->5 ppm - double p_maxSensorRate = 2000.0; //50-175->5 ppm + p_lowrateInterval = 1000.0; //30-50->5 50-90->1 90-175->5 ppm + p_uprateInterval = 2000.0; //upper rate limit 50-175->5 ppm + p_maxSensorRate = 2000.0; //50-175->5 ppm //Ventricle - double p_vPaceAmp = 3750.0; //3750 can change to 0, 1250, 2500, 3750, 5000 - double p_vPaceWidth = 0.4; //0.05->no change 0.1-1.9 0.1 + p_vPaceAmp = 3500.0; //3500->0.1 + p_vPaceWidth = 0.4; //0.05->no change 0.1-1.9 0.1 - int p_activityThresh = 4; //1-7 print out string with level ie. Med - int p_reactionTime = 30; //10-50->10 seconds - int p_responseFactor = 8; //1-16->1 - int p_recoveryTime = 5; //2-16->1 minutes + p_activityThresh = 4; //1-7 print out string with level ie. Med + p_reactionTime = 30000; //10-50->10 seconds + p_responseFactor = 8; //1-16->1 + p_recoveryTime = 300000; //2-16->1 minutes } int PaceHeart::get_p_pacingState() { return p_pacingState; } -int PaceHeart::get_p_pacingMode() + +void PaceHeart::set_p_pacingMode(int x) +{ + p_pacingMode = x; + return; +} + +int PaceHeart::get_p_pacingMode()//lets make it string in future { return p_pacingMode; } @@ -71,19 +78,37 @@ } void PaceHeart::set_p_lowrateInterval(double x) { - if (p_pacingmode == 1) { + if (p_pacingMode == 1) { - if (x >= 500 && x < 833.33) { - p_lowrateInterval = x+83.33; + if (dir ==1) // Change values to take into account for user inputs + { + if (p_lowrateInterval >=833.33 && p_lowrateInterval<=1483.33) + { + p_lowrateInterval += 16.67; + } + else if (p_lowrateInterval >2833.33) + { + return; + } + else + { + p_lowrateInterval += 83.33; + } } - else if (x >= 833.33 && x < 1000) { - p_lowrateInterval = x+16.67; - } - else if (x >= 1000 && x < 1500) { - p_lowrateInterval = x-16.67; - } - else if (x >= 1500 && x < 2916.67) { - p_lowrateInterval = x-83.33; + else if (dir==0) + { + if (p_lowrateInterval >=850 && p_lowrateInterval<=1500) + { + p_lowrateInterval -= 16.67; + } + else if (p_lowrateInterval<583.33) + { + return; + } + else + { + p_lowrateInterval -= 83.33; + } } } else { @@ -97,12 +122,28 @@ } void PaceHeart::set_p_uprateInterval(double x) { - if (p_pacingmode == 1) { - if (x >= 833.33 && x < 2000) { - p_uprateInterval = x+83.33; + if (p_pacingMode == 1) { + if (dir ==1) // Change values to take into account for user inputs + { + if (p_uprateInterval >=833.33 && p_uprateInterval<=2833.33) + { + p_uprateInterval += 83.33; + } + else if (p_uprateInterval >2833.33) + { + return; + } } - else if (x >= 2000 && x <= 2916.67) { - p_uprateInterval = x-83.33; + else if (dir==0) + { + if (p_uprateInterval >=916.67 && p_uprateInterval<=2916.67) + { + p_uprateInterval -= 83.33; + } + else if (p_uprateInterval<916.67) + { + return; + } } } else { @@ -111,16 +152,32 @@ return; } double PaceHeart::get_p_maxSensorRate(){ - return + return p_maxSensorRate; } void PaceHeart::set_p_maxSensorRate(double x) { - if (p_pacingmode == 1) { - if (x >= 833.33 && x < 2000) { - p_maxSensorRate = x+83.33; + if (p_pacingMode == 1) { + if (dir ==1) // Change values to take into account for user inputs + { + if (p_maxSensorRate >=833.33 && p_maxSensorRate<=2833.33) + { + p_maxSensorRate += 83.33; + } + else if (p_maxSensorRate >2833.33) + { + return; + } } - else if (x >= 2000 && x <= 2916.67) { - p_maxSensorRate = x-83.33; + else if (dir==0) + { + if (p_maxSensorRate >=916.67 && p_maxSensorRate<=2916.67) + { + p_maxSensorRate -= 83.33; + } + else if (p_maxSensorRate<916.67) + { + return; + } } } else { @@ -135,7 +192,42 @@ } void PaceHeart::set_p_vPaceAmp(double x) { + if (p_pacingMode == 1) { + + if (dir ==1) // Change values to take into account for user inputs + { + if (p_vPaceAmp >=500 && p_vPaceAmp<=3100) + { + p_vPaceAmp += 100; + } + else if (p_vPaceAmp >= 3500 && p_vPaceAmp<=6500) + { + p_vPaceAmp += 500; + } + else + { + return; + } + } + else if (dir==0) + { + if (p_vPaceAmp >=600 && p_vPaceAmp<3200) + { + p_vPaceAmp -= 100; + } + else if (p_vPaceAmp >= 4000 && p_vPaceAmp<=7000) + { + p_vPaceAmp -= 500; + } + else + { + return; + } + } + } + else { p_vPaceAmp = x; + } return; } @@ -145,7 +237,30 @@ } void PaceHeart::set_p_vPaceWidth(double x) { - p_vPaceWidth = x; + if (p_pacingMode == 1) { + if (p_vPaceWidth == 0.05) { + p_vPaceWidth = 0.4; + } + if (dir ==1){ + if (p_vPaceWidth >= 0.1 && p_vPaceWidth <= 1.8){ + p_vPaceWidth += 0.1; + } + else { + return; + } + } + else if (dir ==0) { + if (p_vPaceWidth >= 0.2 && p_vPaceWidth <= 1.9){ + p_vPaceWidth -= 0.1; + } + else { + return; + } + } + } + else { + p_vPaceWidth = x; + } return; } @@ -191,13 +306,9 @@ -void PaceHeart::pace_A(double amp, double wid,int pin) +void PaceHeart::pace_A(double amp, double wid) { - output_pin_A = !output_pin_A ; - wait(1); - - - + Output_A(amp,wid); return; } @@ -205,17 +316,14 @@ { double amplitude = get_p_aPaceAmp(); double width = get_p_aPaceWidth(); - // int output_pin = hardware.get_output_pin; //include the hardware module - pace_A(amplitude,width,output_pin_A); + pace_A(amplitude,width); return; } -void PaceHeart::pace_V(double amp, double wid, int pin) +void PaceHeart::pace_V(double amp, double wid) { - output_pin_V = !output_pin_V ; - wait(2); - + Output_V(amp,wid); return; } @@ -223,8 +331,7 @@ { double amplitude = get_p_vPaceAmp(); double width = get_p_vPaceWidth(); - // int output_pin = hardware.get_output_pin; //include the hardware module - pace_V(amplitude,width,output_pin_V); + pace_V(amplitude,width); return; } @@ -232,9 +339,9 @@ void PaceHeart::pace(int mode) { switch(mode){ - case 1: //AOO - pace_A(); - case 2: //VOO + case 1: //VOOR + pace_V(); + case 0: //VOO pace_V(); } return; @@ -264,21 +371,106 @@ } void PaceHeart::set_p_activityThresh(int x) { - p_activityThresh=x; + if (p_pacingMode == 1) { + p_activityThresh=x; //no increment set at beginning + } + else { + p_activityThresh=x; + } return; } void PaceHeart::set_p_reactionTime(int x) { - p_reactionTime=x; + if (p_pacingMode == 1) { + + if (dir ==1){ + if (p_reactionTime >= 10000 && p_reactionTime <= 40000) { + p_reactionTime += 10000; + } + else if (p_reactionTime >40000) + { + return; + } + } + else if (dir==0) + { + if (p_reactionTime >=20000 && p_reactionTime <=50000) + { + p_reactionTime -= 10000; + } + else if (p_reactionTime < 20000) + { + return; + } + } + } + else { + p_reactionTime = x; + } return; } void PaceHeart::set_p_responseFactor(int x) { - p_responseFactor=x; + if (p_pacingMode == 1) { + + if (dir ==1){ + if (p_responseFactor >= 1 && p_responseFactor <= 15) { + p_responseFactor += 1; + } + else if (p_responseFactor >15) + { + return; + } + } + else if (dir==0) + { + if (p_responseFactor >=2 && p_responseFactor <=16) + { + p_responseFactor -= 1; + } + else if (p_responseFactor < 2) + { + return; + } + } + } + else { + p_responseFactor=x; + } return; } void PaceHeart::set_p_recoveryTime(int x) { - p_recoveryTime=x; + if (p_pacingMode == 1) { + + if (dir ==1){ + if (p_recoveryTime >= 120000 && p_recoveryTime <= 900000) { + p_recoveryTime += 60000; + } + else if (p_recoveryTime >900000) + { + return; + } + } + else if (dir==0) + { + if (p_recoveryTime >=180000 && p_recoveryTime <=960000) + { + p_recoveryTime -= 60000; + } + else if (p_recoveryTime < 180000) + { + return; + } + } + } + else { + p_recoveryTime=x; + } + return; +} +void PaceHeart::set_dir(int x) +{ + dir=x; return; } \ No newline at end of file
--- a/PaceHeart.h Mon Nov 14 22:47:00 2016 +0000 +++ b/PaceHeart.h Tue Nov 29 20:21:45 2016 +0000 @@ -24,18 +24,20 @@ int p_activityThresh; int p_reactionTime; int p_responseFactor; - int p_recoveryTime; + int p_recoveryTime; + int dir; // variable to track direction of increment public: PaceHeart(); PaceHeart(int mode); void pace_A(); -void pace_A(double amp, double wid,int pin); -void pace_V(double amp, double wid,int pin); +void pace_A(double amp, double wid); +void pace_V(double amp, double wid); void pace_V(); void pace(); void pace(int x); int get_p_pacingState(); int get_p_pacingMode(); +void set_p_pacingMode(int x); int get_p_hysteresis(); void set_p_hysteresis(int x); int get_p_hysteresisInterval(); @@ -66,5 +68,6 @@ void set_p_reactionTime(int x); void set_p_responseFactor(int x); void set_p_recoveryTime(int x); +void set_dir(int x); }; #endif \ No newline at end of file
--- a/main.cpp Mon Nov 14 22:47:00 2016 +0000 +++ b/main.cpp Tue Nov 29 20:21:45 2016 +0000 @@ -1,79 +1,21 @@ #include "mbed.h" #include "PaceHeart.h" - +#include "Hardware.h" //DigitalOut output_pin_A(LED1); PaceHeart* Pacer = new PaceHeart; DigitalOut led(LED1); -Serial s(USBTX, USBRX); -void baud(int baudrate) { - - s.baud(baudrate); +Serial pc(USBTX, USBRX); +void setup() { + pc.baud(57600); } int main() { - /* - baud(57600); - s.printf("Press 'u' to turn LED1 brightness up, 'd' to turn it down\n"); - while(1) { - char c = s.getc(); - pc.putc(pc.getc()); //echoes back input - if((c == 'u')) { - - led = !led; - } - if((c == 'd')) { - led = 0; - } - }*/ - Pacer-> pace_A(); - /* PwmOut out(PTA0); pulse width thingy - PwmIn in(PTD1); - float pe,pw,ds; - - // set the PwmOut in seconds - out.pulsewidth(2); - out.period(4); - - while (true) { - pe= in.period(); - pw= in.pulsewidth(); - ds= in.dutycycle(); - pc.printf("A period= %f, pulsewidth= %f, duty cycle= %f\n\r",pe, pw, ds); - - wait(1); - } - - AnalogOut aout(p18); //sets up pin 18 as an analogue output - AnalogueIn ain(p15); //sets up pin 15 and an analogue input - - int main(){ - aout=0.5; //sets output to 0.5*VCC - while(1){ //sets up a loop - if (ain>0.3){ //tests whether the input is above 0.3 - aout=0; //sets the output to 0 - } - aout = 0.5; - wait(1); - aout = 0; - - } - - sine wave output - const double pi = 3.141592653589793238462; - const double amplitude = 0.5f; - const double offset = 65535/2; - double rads = 0.0; - uint16_t sample = 0; - - while(1) { - // sinewave output - for (int i = 0; i < 360; i++) { - rads = (pi * i) / 180.0f; - sample = (uint16_t)(amplitude * (offset * (cos(rads + pi))) + offset); - aout.write_u16(sample); - } - } - */ + setup(); + while(1){ + Output_V(1.0,0.4); + //Check_serial(pc,*Pacer); + } + //Pacer-> pace_A(); }