Vincent Cheung
/
HelloWorld
h
Fork of HelloWorld by
PaceHeart.cpp@5:afabac4fce1b, 2016-11-16 (annotated)
- Committer:
- oopakhooo
- Date:
- Wed Nov 16 21:44:03 2016 +0000
- Revision:
- 5:afabac4fce1b
- Parent:
- 3:641eefd1110b
serial params to interface
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Judorunner | 2:e2ae43e8acab | 1 | #include "PaceHeart.h" |
oopakhooo | 3:641eefd1110b | 2 | #include "mbed.h" |
oopakhooo | 3:641eefd1110b | 3 | #include "Hardware.h" |
oopakhooo | 3:641eefd1110b | 4 | using namespace std; |
oopakhooo | 3:641eefd1110b | 5 | |
oopakhooo | 3:641eefd1110b | 6 | |
Judorunner | 2:e2ae43e8acab | 7 | |
oopakhooo | 3:641eefd1110b | 8 | PaceHeart::PaceHeart(){ |
oopakhooo | 5:afabac4fce1b | 9 | p_pacingState = 1; |
oopakhooo | 5:afabac4fce1b | 10 | p_pacingMode = 2; |
oopakhooo | 5:afabac4fce1b | 11 | p_hysteresis = 0; |
oopakhooo | 5:afabac4fce1b | 12 | p_hysteresisInterval = 300; |
oopakhooo | 5:afabac4fce1b | 13 | lowrateInterval = 1000; |
oopakhooo | 5:afabac4fce1b | 14 | uprateInterval = 500; //upper rate limit |
oopakhooo | 3:641eefd1110b | 15 | //Ventricle |
oopakhooo | 5:afabac4fce1b | 16 | p_vPaceAmp = 3500.0; |
oopakhooo | 5:afabac4fce1b | 17 | p_vPaceWidth = 0.4; |
oopakhooo | 5:afabac4fce1b | 18 | p_VRP = 320; |
oopakhooo | 3:641eefd1110b | 19 | //Atrium (change defaults) |
oopakhooo | 5:afabac4fce1b | 20 | p_aPaceAmp = 3500.0; |
oopakhooo | 5:afabac4fce1b | 21 | p_aPaceWidth = 0.4; |
oopakhooo | 5:afabac4fce1b | 22 | p_ARP = 320; |
oopakhooo | 3:641eefd1110b | 23 | } |
Judorunner | 2:e2ae43e8acab | 24 | |
oopakhooo | 3:641eefd1110b | 25 | int PaceHeart::get_p_pacingState() |
Judorunner | 2:e2ae43e8acab | 26 | { |
Judorunner | 2:e2ae43e8acab | 27 | return p_pacingState; |
Judorunner | 2:e2ae43e8acab | 28 | } |
oopakhooo | 5:afabac4fce1b | 29 | |
oopakhooo | 5:afabac4fce1b | 30 | void PaceHeart::set_p_pacingState(int x) |
oopakhooo | 5:afabac4fce1b | 31 | { |
oopakhooo | 5:afabac4fce1b | 32 | p_pacingState = x; |
oopakhooo | 5:afabac4fce1b | 33 | return; |
oopakhooo | 5:afabac4fce1b | 34 | } |
oopakhooo | 3:641eefd1110b | 35 | int PaceHeart::get_p_pacingMode() |
Judorunner | 2:e2ae43e8acab | 36 | { |
Judorunner | 2:e2ae43e8acab | 37 | return p_pacingMode; |
Judorunner | 2:e2ae43e8acab | 38 | } |
oopakhooo | 5:afabac4fce1b | 39 | void PaceHeart::set_p_pacingMode(int x) |
oopakhooo | 5:afabac4fce1b | 40 | { |
oopakhooo | 5:afabac4fce1b | 41 | p_pacingMode = x; |
oopakhooo | 5:afabac4fce1b | 42 | return; |
oopakhooo | 5:afabac4fce1b | 43 | } |
oopakhooo | 3:641eefd1110b | 44 | int PaceHeart::get_p_hysteresis() |
Judorunner | 2:e2ae43e8acab | 45 | { |
oopakhooo | 3:641eefd1110b | 46 | return p_hysteresis; |
Judorunner | 2:e2ae43e8acab | 47 | } |
oopakhooo | 3:641eefd1110b | 48 | void PaceHeart::set_p_hysteresis(int x) |
Judorunner | 2:e2ae43e8acab | 49 | { |
Judorunner | 2:e2ae43e8acab | 50 | p_hysteresis = x; |
Judorunner | 2:e2ae43e8acab | 51 | return; |
Judorunner | 2:e2ae43e8acab | 52 | } |
oopakhooo | 3:641eefd1110b | 53 | int PaceHeart::get_p_hysteresisInterval() |
Judorunner | 2:e2ae43e8acab | 54 | { |
oopakhooo | 3:641eefd1110b | 55 | return p_hysteresisInterval; |
Judorunner | 2:e2ae43e8acab | 56 | } |
oopakhooo | 3:641eefd1110b | 57 | void PaceHeart::set_p_hysteresisInterval(int x) |
Judorunner | 2:e2ae43e8acab | 58 | { |
oopakhooo | 3:641eefd1110b | 59 | p_hysteresisInterval = x; |
Judorunner | 2:e2ae43e8acab | 60 | return; |
Judorunner | 2:e2ae43e8acab | 61 | } |
oopakhooo | 3:641eefd1110b | 62 | int PaceHeart::get_lowrateInterval() |
Judorunner | 2:e2ae43e8acab | 63 | { |
Judorunner | 2:e2ae43e8acab | 64 | return lowrateInterval; |
Judorunner | 2:e2ae43e8acab | 65 | } |
oopakhooo | 3:641eefd1110b | 66 | void PaceHeart::set_lowrateInterval(int x) |
Judorunner | 2:e2ae43e8acab | 67 | { |
Judorunner | 2:e2ae43e8acab | 68 | lowrateInterval = x; |
Judorunner | 2:e2ae43e8acab | 69 | return; |
Judorunner | 2:e2ae43e8acab | 70 | } |
oopakhooo | 3:641eefd1110b | 71 | int PaceHeart::get_uprateInterval() |
Judorunner | 2:e2ae43e8acab | 72 | { |
oopakhooo | 3:641eefd1110b | 73 | return uprateInterval; |
Judorunner | 2:e2ae43e8acab | 74 | } |
oopakhooo | 3:641eefd1110b | 75 | void PaceHeart::set_uprateInterval(int x) |
Judorunner | 2:e2ae43e8acab | 76 | { |
oopakhooo | 3:641eefd1110b | 77 | uprateInterval = x; |
Judorunner | 2:e2ae43e8acab | 78 | return; |
Judorunner | 2:e2ae43e8acab | 79 | } |
oopakhooo | 3:641eefd1110b | 80 | //Ventricle |
oopakhooo | 3:641eefd1110b | 81 | double PaceHeart::get_p_vPaceAmp() |
oopakhooo | 3:641eefd1110b | 82 | { |
oopakhooo | 3:641eefd1110b | 83 | return p_vPaceAmp; |
oopakhooo | 3:641eefd1110b | 84 | } |
oopakhooo | 3:641eefd1110b | 85 | void PaceHeart::set_p_vPaceAmp(double x) |
oopakhooo | 3:641eefd1110b | 86 | { |
oopakhooo | 3:641eefd1110b | 87 | p_vPaceAmp = x; |
oopakhooo | 3:641eefd1110b | 88 | return; |
oopakhooo | 3:641eefd1110b | 89 | } |
oopakhooo | 3:641eefd1110b | 90 | |
oopakhooo | 3:641eefd1110b | 91 | double PaceHeart::get_p_vPaceWidth() |
Judorunner | 2:e2ae43e8acab | 92 | { |
Judorunner | 2:e2ae43e8acab | 93 | return p_vPaceWidth; |
Judorunner | 2:e2ae43e8acab | 94 | } |
oopakhooo | 3:641eefd1110b | 95 | void PaceHeart::set_p_vPaceWidth(double x) |
Judorunner | 2:e2ae43e8acab | 96 | { |
Judorunner | 2:e2ae43e8acab | 97 | p_vPaceWidth = x; |
Judorunner | 2:e2ae43e8acab | 98 | return; |
Judorunner | 2:e2ae43e8acab | 99 | } |
oopakhooo | 3:641eefd1110b | 100 | |
oopakhooo | 3:641eefd1110b | 101 | int PaceHeart::get_p_VRP() |
Judorunner | 2:e2ae43e8acab | 102 | { |
Judorunner | 2:e2ae43e8acab | 103 | return p_VRP; |
Judorunner | 2:e2ae43e8acab | 104 | } |
oopakhooo | 3:641eefd1110b | 105 | void PaceHeart::set_p_VRP(int x) |
Judorunner | 2:e2ae43e8acab | 106 | { |
Judorunner | 2:e2ae43e8acab | 107 | p_VRP = x; |
Judorunner | 2:e2ae43e8acab | 108 | return; |
oopakhooo | 3:641eefd1110b | 109 | } |
oopakhooo | 3:641eefd1110b | 110 | //Atrium |
oopakhooo | 3:641eefd1110b | 111 | double PaceHeart::get_p_aPaceAmp() |
oopakhooo | 3:641eefd1110b | 112 | { |
oopakhooo | 3:641eefd1110b | 113 | return p_aPaceAmp; |
oopakhooo | 3:641eefd1110b | 114 | } |
oopakhooo | 3:641eefd1110b | 115 | void PaceHeart::set_p_aPaceAmp(double x) |
oopakhooo | 3:641eefd1110b | 116 | { |
oopakhooo | 3:641eefd1110b | 117 | p_aPaceAmp = x; |
oopakhooo | 3:641eefd1110b | 118 | return; |
oopakhooo | 3:641eefd1110b | 119 | } |
oopakhooo | 3:641eefd1110b | 120 | |
oopakhooo | 3:641eefd1110b | 121 | double PaceHeart::get_p_aPaceWidth() |
oopakhooo | 3:641eefd1110b | 122 | { |
oopakhooo | 3:641eefd1110b | 123 | return p_aPaceWidth; |
oopakhooo | 3:641eefd1110b | 124 | } |
oopakhooo | 3:641eefd1110b | 125 | void PaceHeart::set_p_aPaceWidth(double x) |
oopakhooo | 3:641eefd1110b | 126 | { |
oopakhooo | 3:641eefd1110b | 127 | p_aPaceWidth = x; |
oopakhooo | 3:641eefd1110b | 128 | return; |
oopakhooo | 3:641eefd1110b | 129 | } |
oopakhooo | 3:641eefd1110b | 130 | |
oopakhooo | 3:641eefd1110b | 131 | int PaceHeart::get_p_ARP() |
oopakhooo | 3:641eefd1110b | 132 | { |
oopakhooo | 3:641eefd1110b | 133 | return p_ARP; |
oopakhooo | 3:641eefd1110b | 134 | } |
oopakhooo | 3:641eefd1110b | 135 | void PaceHeart::set_p_ARP(int x) |
oopakhooo | 3:641eefd1110b | 136 | { |
oopakhooo | 3:641eefd1110b | 137 | p_ARP = x; |
oopakhooo | 3:641eefd1110b | 138 | return; |
oopakhooo | 3:641eefd1110b | 139 | } |
oopakhooo | 3:641eefd1110b | 140 | |
oopakhooo | 3:641eefd1110b | 141 | |
oopakhooo | 3:641eefd1110b | 142 | |
oopakhooo | 3:641eefd1110b | 143 | void PaceHeart::pace_A(double amp, double wid,int pin) |
oopakhooo | 3:641eefd1110b | 144 | { |
oopakhooo | 3:641eefd1110b | 145 | output_pin_A = !output_pin_A ; |
oopakhooo | 3:641eefd1110b | 146 | wait(1); |
oopakhooo | 5:afabac4fce1b | 147 | //e_gram(amp,wid); // |
oopakhooo | 5:afabac4fce1b | 148 | /* |
oopakhooo | 3:641eefd1110b | 149 | |
oopakhooo | 5:afabac4fce1b | 150 | |
oopakhooo | 5:afabac4fce1b | 151 | //default double e_amp[1]; double e_wid[1];int e_size=0; ->get_egram_wid // get_egram_size // get_egram_amp |
oopakhooo | 5:afabac4fce1b | 152 | void e_gram(double amp, double wid){ |
oopakhooo | 5:afabac4fce1b | 153 | if(size==e_amp.length){ |
oopakhooo | 5:afabac4fce1b | 154 | double e_amp_new[2*size]; |
oopakhooo | 5:afabac4fce1b | 155 | double e_wid_new[2*size]; |
oopakhooo | 5:afabac4fce1b | 156 | for(int i = 0;i<size;i++){ |
oopakhooo | 5:afabac4fce1b | 157 | e_amp_new[i] = amp[i]; |
oopakhooo | 5:afabac4fce1b | 158 | e_wid_new[i] = wid[i]; |
oopakhooo | 5:afabac4fce1b | 159 | } |
oopakhooo | 5:afabac4fce1b | 160 | e_amp = e_amp_new; |
oopakhooo | 5:afabac4fce1b | 161 | e_wid = e_wid_new; |
oopakhooo | 5:afabac4fce1b | 162 | } |
oopakhooo | 5:afabac4fce1b | 163 | if(size==0){ |
oopakhooo | 5:afabac4fce1b | 164 | e_amp[0] = amp; //storing egram history; |
oopakhooo | 5:afabac4fce1b | 165 | e_wid[0] = wid; |
oopakhooo | 5:afabac4fce1b | 166 | } |
oopakhooo | 5:afabac4fce1b | 167 | else { |
oopakhooo | 5:afabac4fce1b | 168 | e_amp[size] = amp; |
oopakhooo | 5:afabac4fce1b | 169 | e_wid[size] = wid; |
oopakhooo | 5:afabac4fce1b | 170 | } |
oopakhooo | 5:afabac4fce1b | 171 | } |
oopakhooo | 5:afabac4fce1b | 172 | double* PaceHeart::get_egram_amp(){ |
oopakhooo | 5:afabac4fce1b | 173 | return e_amp; |
oopakhooo | 5:afabac4fce1b | 174 | } |
oopakhooo | 5:afabac4fce1b | 175 | double* PaceHeart::get_egram_wid(){ |
oopakhooo | 5:afabac4fce1b | 176 | return e_wid; |
oopakhooo | 5:afabac4fce1b | 177 | } |
oopakhooo | 5:afabac4fce1b | 178 | int PaceHeart::get_egram_size(){ |
oopakhooo | 5:afabac4fce1b | 179 | return e_size; |
oopakhooo | 5:afabac4fce1b | 180 | } |
oopakhooo | 3:641eefd1110b | 181 | |
oopakhooo | 5:afabac4fce1b | 182 | |
oopakhooo | 5:afabac4fce1b | 183 | */ |
oopakhooo | 3:641eefd1110b | 184 | return; |
oopakhooo | 3:641eefd1110b | 185 | } |
oopakhooo | 3:641eefd1110b | 186 | |
oopakhooo | 3:641eefd1110b | 187 | void PaceHeart::pace_A() |
oopakhooo | 3:641eefd1110b | 188 | { |
oopakhooo | 3:641eefd1110b | 189 | double amplitude = get_p_aPaceAmp(); |
oopakhooo | 3:641eefd1110b | 190 | double width = get_p_aPaceWidth(); |
oopakhooo | 3:641eefd1110b | 191 | // int output_pin = hardware.get_output_pin; //include the hardware module |
oopakhooo | 3:641eefd1110b | 192 | pace_A(amplitude,width,output_pin_A); |
oopakhooo | 3:641eefd1110b | 193 | return; |
oopakhooo | 3:641eefd1110b | 194 | } |
oopakhooo | 3:641eefd1110b | 195 | |
oopakhooo | 3:641eefd1110b | 196 | |
oopakhooo | 3:641eefd1110b | 197 | void PaceHeart::pace_V(double amp, double wid, int pin) |
oopakhooo | 3:641eefd1110b | 198 | { |
oopakhooo | 3:641eefd1110b | 199 | output_pin_V = !output_pin_V ; |
oopakhooo | 3:641eefd1110b | 200 | wait(2); |
oopakhooo | 3:641eefd1110b | 201 | |
oopakhooo | 3:641eefd1110b | 202 | return; |
oopakhooo | 3:641eefd1110b | 203 | } |
oopakhooo | 3:641eefd1110b | 204 | |
oopakhooo | 3:641eefd1110b | 205 | void PaceHeart::pace_V() |
oopakhooo | 3:641eefd1110b | 206 | { |
oopakhooo | 3:641eefd1110b | 207 | double amplitude = get_p_vPaceAmp(); |
oopakhooo | 3:641eefd1110b | 208 | double width = get_p_vPaceWidth(); |
oopakhooo | 3:641eefd1110b | 209 | // int output_pin = hardware.get_output_pin; //include the hardware module |
oopakhooo | 3:641eefd1110b | 210 | pace_V(amplitude,width,output_pin_V); |
oopakhooo | 3:641eefd1110b | 211 | return; |
oopakhooo | 3:641eefd1110b | 212 | } |
oopakhooo | 3:641eefd1110b | 213 | |
oopakhooo | 3:641eefd1110b | 214 | |
oopakhooo | 3:641eefd1110b | 215 | void PaceHeart::pace(int mode) |
oopakhooo | 3:641eefd1110b | 216 | { |
oopakhooo | 3:641eefd1110b | 217 | switch(mode){ |
oopakhooo | 3:641eefd1110b | 218 | case 1: //AOO |
oopakhooo | 3:641eefd1110b | 219 | pace_A(); |
oopakhooo | 3:641eefd1110b | 220 | case 2: //VOO |
oopakhooo | 3:641eefd1110b | 221 | pace_V(); |
oopakhooo | 3:641eefd1110b | 222 | } |
oopakhooo | 3:641eefd1110b | 223 | return; |
oopakhooo | 3:641eefd1110b | 224 | } |
oopakhooo | 3:641eefd1110b | 225 | |
oopakhooo | 3:641eefd1110b | 226 | void PaceHeart::pace() |
oopakhooo | 3:641eefd1110b | 227 | { |
oopakhooo | 3:641eefd1110b | 228 | int mode = get_p_pacingMode(); |
oopakhooo | 3:641eefd1110b | 229 | pace(mode); |
oopakhooo | 3:641eefd1110b | 230 | return; |
oopakhooo | 5:afabac4fce1b | 231 | }/* |
oopakhooo | 5:afabac4fce1b | 232 | void PaceHeart::send_data(Serial &pc){ |
oopakhooo | 5:afabac4fce1b | 233 | |
oopakhooo | 5:afabac4fce1b | 234 | pc.printf ("%c",(char)get_p_pacingState()); |
oopakhooo | 5:afabac4fce1b | 235 | pc.printf ("%c",(char)get_p_pacingMode()); |
oopakhooo | 5:afabac4fce1b | 236 | pc.printf ("%c",(char)get_p_hysteresis()); |
oopakhooo | 5:afabac4fce1b | 237 | pc.printf ("%c%c",(char)((int)(get_p_hysteresisInterval()/128)),(char)(get_p_hysteresisInterval()%128)); |
oopakhooo | 5:afabac4fce1b | 238 | pc.printf ("%c%c",(char)((int)(get_lowrateInterval()/128)),(char)(get_lowrateInterval()%128)); |
oopakhooo | 5:afabac4fce1b | 239 | pc.printf ("%c%c",(char)((int)(get_p_vPaceAmp())/128),(char)((int)(get_p_vPaceAmp())%128)); |
oopakhooo | 5:afabac4fce1b | 240 | pc.printf ("%c%c",(char)((int)(10.0*get_p_vPaceWidth())/128),(char)((int)(10.0*get_p_vPaceWidth())%128));//10*pace width |
oopakhooo | 5:afabac4fce1b | 241 | pc.printf ("%c%c\n",(char)((int)(get_p_VRP()/128)),(char)(get_p_VRP()%128)); |
oopakhooo | 5:afabac4fce1b | 242 | return; |
oopakhooo | 5:afabac4fce1b | 243 | }*/ |
oopakhooo | 5:afabac4fce1b | 244 | /* |
oopakhooo | 5:afabac4fce1b | 245 | void PaceHeart::request_data(Serial &pc){ //implement limit later |
oopakhooo | 5:afabac4fce1b | 246 | char d[14]; |
oopakhooo | 5:afabac4fce1b | 247 | int e = 0; |
oopakhooo | 5:afabac4fce1b | 248 | pc.scanf("%s",&d); |
oopakhooo | 5:afabac4fce1b | 249 | pc.printf("%c",'e');//end |
oopakhooo | 5:afabac4fce1b | 250 | e = (int)d[0]; |
oopakhooo | 5:afabac4fce1b | 251 | set_p_pacingState(e); |
oopakhooo | 5:afabac4fce1b | 252 | e = (int)d[1]; |
oopakhooo | 5:afabac4fce1b | 253 | set_p_pacingMode(e); |
oopakhooo | 5:afabac4fce1b | 254 | e = (int)d[2]; |
oopakhooo | 5:afabac4fce1b | 255 | set_p_hysteresis(e); |
oopakhooo | 5:afabac4fce1b | 256 | e = (int)d[3]*128+(int)d[4]; |
oopakhooo | 5:afabac4fce1b | 257 | set_p_hysteresisInterval(e); |
oopakhooo | 5:afabac4fce1b | 258 | e = (int)d[5]*128+(int)d[6]; |
oopakhooo | 5:afabac4fce1b | 259 | set_lowrateInterval(e); |
oopakhooo | 5:afabac4fce1b | 260 | e = (int)d[7]*128+(int)d[8]; |
oopakhooo | 5:afabac4fce1b | 261 | set_p_vPaceAmp((double)e); |
oopakhooo | 5:afabac4fce1b | 262 | e = (int)d[9]*128+(int)d[10]; |
oopakhooo | 5:afabac4fce1b | 263 | set_p_vPaceWidth((double)e/10.0); |
oopakhooo | 5:afabac4fce1b | 264 | e = (int)d[11]*128+(int)d[12]; |
oopakhooo | 5:afabac4fce1b | 265 | set_p_VRP(e); |
oopakhooo | 5:afabac4fce1b | 266 | }*/ |