Vincent Cheung
/
HelloWorld
h
Fork of HelloWorld by
Diff: Hardware.cpp
- Revision:
- 5:afabac4fce1b
- Parent:
- 4:f0a11480f39f
--- a/Hardware.cpp Mon Nov 14 19:59:54 2016 +0000 +++ b/Hardware.cpp Wed Nov 16 21:44:03 2016 +0000 @@ -2,4 +2,61 @@ #include "mbed.h" DigitalOut output_pin_A(LED3); -DigitalOut output_pin_V(LED2); \ No newline at end of file +DigitalOut output_pin_V(LED2); + +/* +void send_egram_data(Serial &pc,PaceHeart &Pacer){ + int *amp = Pacer.get_egram_amp; + int *wid = Pacer.get_egram_wid; + int size = Pacer.get_egram_size; + for(int i = 0; i<size;i++){ + pc.printf ("%c%c",(char)((int)(amp[i])/128),(char)((int)(amp[i])%128)); + pc.printf ("%c%c",(char)((int)(10.0*wid[i])/128),(char)((int)(10.0*wid[i])%128)); + } + pc.printf("\n"); + pc.printf("%c\n",(char)size); datachk +} +*/ +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_lowrateInterval()/128)),(char)(Pacer.get_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_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 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); + } +} \ No newline at end of file