h

Dependencies:   mbed

Fork of HelloWorld by judo ~

Files at this revision

API Documentation at this revision

Comitter:
oopakhooo
Date:
Wed Nov 16 21:44:03 2016 +0000
Parent:
4:f0a11480f39f
Commit message:
serial params to interface

Changed in this revision

Hardware.cpp Show annotated file Show diff for this revision Revisions of this file
Hardware.h Show annotated file Show diff for this revision Revisions of this file
PaceHeart.cpp Show annotated file Show diff for this revision Revisions of this file
PaceHeart.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- 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
--- a/Hardware.h	Mon Nov 14 19:59:54 2016 +0000
+++ b/Hardware.h	Wed Nov 16 21:44:03 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 send_data(Serial &pc,PaceHeart &Pacer);
+void request_data(Serial &pc,PaceHeart &Pacer);
+void Check_serial(Serial &pc,PaceHeart &Pacer);
 #endif
\ No newline at end of file
--- a/PaceHeart.cpp	Mon Nov 14 19:59:54 2016 +0000
+++ b/PaceHeart.cpp	Wed Nov 16 21:44:03 2016 +0000
@@ -6,30 +6,41 @@
 
 
 PaceHeart::PaceHeart(){
-    p_pacingState = 0;
-    p_pacingMode = 0;
-    int p_hysteresis = 0;
-    int p_hysteresisInterval = 300;
-    int lowrateInterval = 1000;
-    int uprateInterval = 500; //upper rate limit
+    p_pacingState = 1;
+    p_pacingMode = 2;
+    p_hysteresis = 0;
+    p_hysteresisInterval = 300;
+    lowrateInterval = 1000;
+    uprateInterval = 500; //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;
 }
 
 int PaceHeart::get_p_pacingState()
 {
     return p_pacingState;
 }
+
+void PaceHeart::set_p_pacingState(int x)
+{
+    p_pacingState = x;
+    return;
+}
 int PaceHeart::get_p_pacingMode()
 {
     return p_pacingMode;
 }
+void PaceHeart::set_p_pacingMode(int x)
+{
+    p_pacingMode = x;
+    return;
+}
 int PaceHeart::get_p_hysteresis()
 {
     return p_hysteresis;
@@ -133,9 +144,43 @@
 {   
     output_pin_A = !output_pin_A ;
     wait(1);
+    //e_gram(amp,wid); //
+   /*
    
+   
+    //default double e_amp[1]; double e_wid[1];int e_size=0; ->get_egram_wid // get_egram_size // get_egram_amp
+    void e_gram(double amp, double wid){
+    if(size==e_amp.length){
+        double e_amp_new[2*size];
+        double e_wid_new[2*size];
+        for(int i = 0;i<size;i++){
+            e_amp_new[i] = amp[i];
+            e_wid_new[i] = wid[i];
+        }
+        e_amp = e_amp_new;
+        e_wid = e_wid_new;
+    }
+    if(size==0){
+        e_amp[0] = amp; //storing egram history;
+        e_wid[0] = wid;
+    }
+    else {
+        e_amp[size] = amp;
+        e_wid[size] = wid;
+    }
+    }
+    double* PaceHeart::get_egram_amp(){
+        return e_amp;
+    }
+    double* PaceHeart::get_egram_wid(){
+        return e_wid;
+    }
+    int PaceHeart::get_egram_size(){
+        return e_size;    
+    }
     
-   
+    
+   */
     return;
 }
 
@@ -183,4 +228,39 @@
     int mode = get_p_pacingMode();
     pace(mode);
     return;
-}
+}/*
+void PaceHeart::send_data(Serial &pc){
+    
+             pc.printf ("%c",(char)get_p_pacingState());
+             pc.printf ("%c",(char)get_p_pacingMode());
+             pc.printf ("%c",(char)get_p_hysteresis());
+             pc.printf ("%c%c",(char)((int)(get_p_hysteresisInterval()/128)),(char)(get_p_hysteresisInterval()%128));
+             pc.printf ("%c%c",(char)((int)(get_lowrateInterval()/128)),(char)(get_lowrateInterval()%128));
+             pc.printf ("%c%c",(char)((int)(get_p_vPaceAmp())/128),(char)((int)(get_p_vPaceAmp())%128));
+             pc.printf ("%c%c",(char)((int)(10.0*get_p_vPaceWidth())/128),(char)((int)(10.0*get_p_vPaceWidth())%128));//10*pace width
+             pc.printf ("%c%c\n",(char)((int)(get_p_VRP()/128)),(char)(get_p_VRP()%128));
+             return;
+}*/
+/*    
+void PaceHeart::request_data(Serial &pc){ //implement limit later
+            char d[14];
+            int e = 0;
+            pc.scanf("%s",&d);
+            pc.printf("%c",'e');//end
+            e = (int)d[0];
+            set_p_pacingState(e);
+            e = (int)d[1];
+            set_p_pacingMode(e);
+            e = (int)d[2];
+            set_p_hysteresis(e);
+            e = (int)d[3]*128+(int)d[4];
+            set_p_hysteresisInterval(e);
+            e = (int)d[5]*128+(int)d[6];
+            set_lowrateInterval(e);
+            e = (int)d[7]*128+(int)d[8];
+            set_p_vPaceAmp((double)e);
+            e = (int)d[9]*128+(int)d[10];
+            set_p_vPaceWidth((double)e/10.0);
+            e = (int)d[11]*128+(int)d[12];
+            set_p_VRP(e);
+}*/
\ No newline at end of file
--- a/PaceHeart.h	Mon Nov 14 19:59:54 2016 +0000
+++ b/PaceHeart.h	Wed Nov 16 21:44:03 2016 +0000
@@ -1,54 +1,56 @@
 #include <string>
 using namespace std;
-
+#include "mbed.h"
 #ifndef PACEHEART_H
 #define PACEHEART_H
 class PaceHeart{
     
     private:
-    int p_pacingState;
-    int p_pacingMode;
-    int p_hysteresis;
-    int p_hysteresisInterval;
-    int lowrateInterval;
-    int uprateInterval; //upper rate limit
-    //Ventricle
-    double p_vPaceAmp;
-    double p_vPaceWidth;
-    int p_VRP;
-    //Atrium (change defaults)
-    double p_aPaceAmp;
-    double p_aPaceWidth;
-    int p_ARP;
+        int p_pacingState;
+        int p_pacingMode;
+        int p_hysteresis;
+        int p_hysteresisInterval;
+        int lowrateInterval;
+        int uprateInterval; //upper rate limit
+        //Ventricle
+        double p_vPaceAmp;
+        double p_vPaceWidth;
+        int p_VRP;
+        //Atrium (change defaults)
+        double p_aPaceAmp;
+        double p_aPaceWidth;
+        int p_ARP;
     public:
-PaceHeart();
-void pace_A();
-void pace_A(double amp, double wid,int pin);
-void pace_V(double amp, double wid,int pin);
-void pace_V();
-void pace();
-void pace(int x);
-int get_p_pacingState();
-int get_p_pacingMode();
-int get_p_hysteresis();
-void set_p_hysteresis(int x);
-int get_p_hysteresisInterval();
-void set_p_hysteresisInterval(int x);
-int get_lowrateInterval();
-void set_lowrateInterval(int x);
-int get_uprateInterval();
-void set_uprateInterval(int x);
-double get_p_vPaceAmp();
-void set_p_vPaceAmp(double x);
-double get_p_vPaceWidth();
-void set_p_vPaceWidth(double x);
-int get_p_VRP();
-void set_p_VRP(int x);
-double get_p_aPaceAmp();
-void set_p_aPaceAmp(double x);
-double get_p_aPaceWidth();
-void set_p_aPaceWidth(double x);
-int get_p_ARP();
-void set_p_ARP(int x);
+        PaceHeart();
+        void pace_A();
+        void pace_A(double amp, double wid,int pin);
+        void pace_V(double amp, double wid,int pin);
+        void pace_V();
+        void pace();
+        void pace(int x);
+        int get_p_pacingState();
+        void set_p_pacingState(int x);
+        int get_p_pacingMode();
+        void set_p_pacingMode(int x);
+        int get_p_hysteresis();
+        void set_p_hysteresis(int x);
+        int get_p_hysteresisInterval();
+        void set_p_hysteresisInterval(int x);
+        int get_lowrateInterval();
+        void set_lowrateInterval(int x);
+        int get_uprateInterval();
+        void set_uprateInterval(int x);
+        double get_p_vPaceAmp();
+        void set_p_vPaceAmp(double x);
+        double get_p_vPaceWidth();
+        void set_p_vPaceWidth(double x);
+        int get_p_VRP();
+        void set_p_VRP(int x);
+        double get_p_aPaceAmp();
+        void set_p_aPaceAmp(double x);
+        double get_p_aPaceWidth();
+        void set_p_aPaceWidth(double x);
+        int get_p_ARP();
+        void set_p_ARP(int x);
 };
 #endif
\ No newline at end of file
--- a/main.cpp	Mon Nov 14 19:59:54 2016 +0000
+++ b/main.cpp	Wed Nov 16 21:44:03 2016 +0000
@@ -1,49 +1,25 @@
 #include "mbed.h"
 #include "PaceHeart.h"
+#include "Hardware.h"
 
 //DigitalOut output_pin_A(LED1);
 
-PaceHeart* Pacer = new PaceHeart;
+PaceHeart* Pacer = new PaceHeart();
 DigitalOut led(LED1);
-Serial s(USBTX, USBRX);
+Serial pc(USBTX, USBRX);
 void baud(int baudrate) {
     
-    s.baud(baudrate);
+    pc.baud(baudrate);
 }
     
 
 int main() {
+    baud(57600);
+    while(1){
+    Check_serial(pc,*Pacer);
+    }
+   
     /*
-    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
@@ -58,6 +34,8 @@
       wait(1);
       aout = 0;
       
+      
+      
    }
    
            sine wave output