Dependencies:   mbed

Fork of VLC_manchester_decoder by Jelle Raes

Files at this revision

API Documentation at this revision

Comitter:
JelleRaes
Date:
Tue May 15 08:05:16 2018 +0000
Parent:
2:487a58ce256c
Commit message:
test

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
manchester.cpp Show annotated file Show diff for this revision Revisions of this file
manchester.h Show annotated file Show diff for this revision Revisions of this file
diff -r 487a58ce256c -r 4fad63952e4c main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue May 15 08:05:16 2018 +0000
@@ -0,0 +1,9 @@
+#include "mbed.h"
+#include "manchester.h"
+
+ 
+int main(){
+     manchester fukit;
+     while(1){
+    fukit.decode();}
+}
\ No newline at end of file
diff -r 487a58ce256c -r 4fad63952e4c manchester.cpp
--- a/manchester.cpp	Mon May 14 09:29:08 2018 +0000
+++ b/manchester.cpp	Tue May 15 08:05:16 2018 +0000
@@ -1,23 +1,27 @@
 #include "mbed.h"
 #include "manchester.h"
 
-DigitalIn signal(p16);
+DigitalIn signal(p7);
 Serial pc(USBTX, USBRX);
 Timer timer;
+//Timeout timeout;
 int datal[] = {1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0};
-int datas[] = {1,1,1,1,0,0,0,0,0,0};
+bool notTimedOut;
 
 manchester::manchester()
 {
-
+    //pc.printf("object aag-nga-\r\n");
 }
 
 int manchester::decode()
 {
-
+    //pc.printf("bert zeg et\r\n");
     int previous,current,begin,end=0;
     int time=0;
     int i = 0;
+    int datas[] = {1,1,1,1,0,0,0,0,0,0};
+    notTimedOut = true;
+    //pc.printf("start code\r\n");
     timer.start();
     while(i< DELAY) {
         previous = current;
@@ -29,7 +33,9 @@
         wait_us(100);
     }
     i = 0;
-    while(i<4) {
+    //timeout.attach(callback(this,&manchester::isTimedOut), 3);
+    //pc.printf("start clockcalculation\r\n");
+    while(i<4 ) {
         end = begin;
         previous = current;
         current = signal.read();
@@ -40,37 +46,42 @@
             }
             i++;
         }
-
-
     }
-    float atime=((float)time/3000000);
-    i=4;
-    wait(atime/2);
-
-    while(i<10) {
-        int x = signal.read();
+    //pc.printf("loop is done\r\n");
+    if(notTimedOut == true) {
+        //pc.printf("not timed out\r\n");
+        float atime=((float)time/3000000);
+        i=4;
         wait(atime/2);
-        int y = signal.read();
-        wait(atime/2);
+        //pc.printf("start data\r\n");
+        while(i<10) {
+            int x = signal.read();
+            wait(atime/2);
+            int y = signal.read();
+            wait(atime/2);
 
-        if(x<y) {
-            datas[i]=0;
-        } else if(x>y) {
-            datas[i]=1;
+            if(x<y) {
+                datas[i]=0;
+            } else if(x>y) {
+                datas[i]=1;
+            }
+            i++;
         }
-        i++;
+        wait(1);
+        pc.printf("\n\raverage time is = %f s\n\r",atime);
+        pc.printf("with frequency %f\n\r",1/atime);
+        pc.printf("data is:");
+        int direction = getDirection(datas);
+        for(int j = 0; j<10; j++) {
+            printf("%d",datas[j]);
+        }
+        printf("with direction:%d\r\n",direction);
+        timer.stop();
+        return direction;
+    } else {
+        printf("timed out\r\n");
+        return 4;
     }
-
-    wait(1);
-    printf("\n\raverage time is = %f s\n\r",atime);
-    printf("with frequency %f\n\r",1/atime);
-    printf("data is:");
-    int direction = getDirection(datas);
-    for(int j = 0; j<10; j++) {
-        printf("%d",datas[j]);
-    }
-    printf("with direction:%d",direction);
-    return direction;
 }
 
 int manchester::getDirection(int* data)
@@ -91,14 +102,26 @@
     }
     return direction;
 }
-bool manchester::vlcDetected(){
+
+bool manchester::vlcDetected()
+{
     int i = 0;
     bool detected = false;
-    while(i<DELAY){
-        if(signal.read() != 0){
-            detected = true
+    while(i<DELAY) {
+        if(signal.read() != 0) {
+            detected = true;
         }
-        wait_us(100)   
+        wait_us(100);
     }
     return detected;
 }
+
+void manchester::isTimedOut()
+{
+    notTimedOut = false;
+}
+
+void manchester::printetwuk()
+{
+    pc.printf("test ng e ki\r\n");
+}
\ No newline at end of file
diff -r 487a58ce256c -r 4fad63952e4c manchester.h
--- a/manchester.h	Mon May 14 09:29:08 2018 +0000
+++ b/manchester.h	Tue May 15 08:05:16 2018 +0000
@@ -9,5 +9,7 @@
     int decode();
     int getDirection(int*);
     bool vlcDetected();
+    void isTimedOut();
+    void printetwuk();
 };
 #endif
\ No newline at end of file