SSI OpComms 3CM Board RX

Dependencies:   mbed

Fork of Optical3cmRX by Thomas Teisberg

Revision:
3:1235cbe67ec9
Parent:
2:eb447fcd8284
Child:
4:037345932888
--- a/main.cpp	Sat Nov 07 22:21:17 2015 +0000
+++ b/main.cpp	Sun Nov 08 00:45:49 2015 +0000
@@ -5,8 +5,8 @@
 Serial pc(USBTX, USBRX); // tx, rx
 
 static const int N_PPM = 4;
-static const int PULSE_TIME = 1000;
-static const int SAMPLE_RATE = 10; // must be an even divisor of PULSE_TIME
+static const int PULSE_TIME = 10000;
+static const int SAMPLE_RATE = 10; // must be a divisor of PULSE_TIME
 static const int SAMPLE_GAP = PULSE_TIME / SAMPLE_RATE;
 static const int HALF_SAMPLE = SAMPLE_RATE / 2;
 static const int BUF_SIZE = 1024;
@@ -39,17 +39,21 @@
     if(sample_lock) pc.printf("\r\nWarning: Sampling too fast\r\n");
     sample_lock = true;
     float v = rx.read();
-    if(v < 0.001){
+    if(v < THRESH){
         offCount++;
-        if(offCount > HALF_SAMPLE) onCount = 0;
+        if(onCount > HALF_SAMPLE)
+        {
+            pc.printf("0:%d ", onCount);
+            onCount = 0;
+        }
     }else{ // Pulse
-        if(onCount > HALF_SAMPLE && offCount > HALF_SAMPLE)
+        if(offCount > HALF_SAMPLE)
         {
-            int offPulses = (offCount + HALF_SAMPLE) / SAMPLE_RATE;
-            pc.printf("%d:%d ", offCount, offPulses);
+            int offPulses = (offCount + HALF_SAMPLE) / SAMPLE_RATE - 1;
+            pc.printf("1:%d:%d ", offCount, offPulses);
             if(offPulses <= N_PPM)
             {
-                buf[idx] = offPulses - 1;
+                buf[idx] = offPulses;
                 idx++;
                 if(idx == BUF_SIZE) idx = 0;
                 if(idx == start) pc.printf("\r\nWarning: Buffer too small\r\n");