PARA IRDA

Dependents:   irda irda1 Tarea5 irda ... more

Fork of Pulse by Nick Ryder

Revision:
1:48651f86a80c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Pulse1.cpp	Thu Nov 07 03:34:00 2013 +0000
@@ -0,0 +1,118 @@
+ 
+#include "Pulse1.h"
+
+PulseInOut::PulseInOut(PinName pin):
+        startval(0), pulsetime(), runtime(), io(pin)    {
+}
+
+
+PulseInOut::~PulseInOut() {
+}
+
+void PulseInOut::write(int val) {
+    io.output();
+    io = val;
+}
+
+void PulseInOut::write_us(int val, int time)   {
+    io.output();
+    io = val;
+    wait_us(time);
+    io = !val;
+}
+
+int PulseInOut::read_high_us()  {
+    pulsetime.reset();
+    io.input();
+    while (io == 1) {
+    }
+    while (io == 0) {
+    }
+    pulsetime.start();
+    while (io == 1) {
+    }
+    pulsetime.stop();
+    return pulsetime.read_us();
+}
+
+int PulseInOut::read_high_us(int timeout)  {
+    runtime.reset();
+    runtime.start();
+    pulsetime.reset();
+    io.input();
+    while (io == 1) {
+        if (runtime.read_us() > timeout)   return -1;
+    }
+    while (io == 0) {
+        if (runtime.read_us() > timeout)   return -1;
+    }
+    pulsetime.start();
+    while (io == 1) {
+        if (runtime.read_us() > timeout)   return -1;
+    }
+    pulsetime.stop();
+    return pulsetime.read_us();
+}
+
+int PulseInOut::read_low_us()   {
+    pulsetime.reset();
+    io.input();
+    while (io == 0) {
+    }
+    while (io == 1) {
+    }
+    pulsetime.start();
+    while (io == 0) {
+    }
+    pulsetime.stop();
+    return pulsetime.read_us();
+}
+
+int PulseInOut::read_low_us(int timeout)   {
+    runtime.reset();
+    runtime.start();
+    pulsetime.reset();
+    io.input();
+    while (io == 0) {
+        if (runtime.read_us() > timeout)   return -1;
+    }
+    while (io == 1) {
+        if (runtime.read_us() > timeout)   return -1;
+    }
+    pulsetime.start();
+    while (io == 0) {
+        if (runtime.read_us() > timeout)   return -1;
+    }
+    pulsetime.stop();
+    return pulsetime.read_us();
+}
+
+int PulseInOut::read_us()  {
+    pulsetime.reset();
+    io.input();
+    startval = io;
+    while (io == startval)   {
+    }
+    pulsetime.start();
+    while (io != startval)  {
+    }
+    pulsetime.stop();
+    return pulsetime.read_us();
+}
+
+int PulseInOut::read_us(int timeout)   {
+    runtime.reset();
+    runtime.start();
+    pulsetime.reset();
+    io.input();
+    startval = io;
+    while (io == startval)  {
+        if (runtime.read_us() > timeout)   return -1;
+    }
+    pulsetime.start();
+    while (io != startval)   {
+        if (runtime.read_us() > timeout)   return -1;
+    }
+    pulsetime.stop();
+    return pulsetime.read_us();
+}
\ No newline at end of file