Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of VLC_decoder_copy_copy_omdatetkan by
Diff: manchester.cpp
- Revision:
- 3:4fad63952e4c
- Parent:
- 2:487a58ce256c
- Child:
- 4:7ef585175a7b
--- 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
