PARA IRDA

Dependents:   irda irda1 Tarea5 irda ... more

Fork of Pulse by Nick Ryder

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Pulse1.cpp Source File

Pulse1.cpp

00001  
00002 #include "Pulse1.h"
00003 
00004 PulseInOut::PulseInOut(PinName pin):
00005         startval(0), pulsetime(), runtime(), io(pin)    {
00006 }
00007 
00008 
00009 PulseInOut::~PulseInOut() {
00010 }
00011 
00012 void PulseInOut::write(int val) {
00013     io.output();
00014     io = val;
00015 }
00016 
00017 void PulseInOut::write_us(int val, int time)   {
00018     io.output();
00019     io = val;
00020     wait_us(time);
00021     io = !val;
00022 }
00023 
00024 int PulseInOut::read_high_us()  {
00025     pulsetime.reset();
00026     io.input();
00027     while (io == 1) {
00028     }
00029     while (io == 0) {
00030     }
00031     pulsetime.start();
00032     while (io == 1) {
00033     }
00034     pulsetime.stop();
00035     return pulsetime.read_us();
00036 }
00037 
00038 int PulseInOut::read_high_us(int timeout)  {
00039     runtime.reset();
00040     runtime.start();
00041     pulsetime.reset();
00042     io.input();
00043     while (io == 1) {
00044         if (runtime.read_us() > timeout)   return -1;
00045     }
00046     while (io == 0) {
00047         if (runtime.read_us() > timeout)   return -1;
00048     }
00049     pulsetime.start();
00050     while (io == 1) {
00051         if (runtime.read_us() > timeout)   return -1;
00052     }
00053     pulsetime.stop();
00054     return pulsetime.read_us();
00055 }
00056 
00057 int PulseInOut::read_low_us()   {
00058     pulsetime.reset();
00059     io.input();
00060     while (io == 0) {
00061     }
00062     while (io == 1) {
00063     }
00064     pulsetime.start();
00065     while (io == 0) {
00066     }
00067     pulsetime.stop();
00068     return pulsetime.read_us();
00069 }
00070 
00071 int PulseInOut::read_low_us(int timeout)   {
00072     runtime.reset();
00073     runtime.start();
00074     pulsetime.reset();
00075     io.input();
00076     while (io == 0) {
00077         if (runtime.read_us() > timeout)   return -1;
00078     }
00079     while (io == 1) {
00080         if (runtime.read_us() > timeout)   return -1;
00081     }
00082     pulsetime.start();
00083     while (io == 0) {
00084         if (runtime.read_us() > timeout)   return -1;
00085     }
00086     pulsetime.stop();
00087     return pulsetime.read_us();
00088 }
00089 
00090 int PulseInOut::read_us()  {
00091     pulsetime.reset();
00092     io.input();
00093     startval = io;
00094     while (io == startval)   {
00095     }
00096     pulsetime.start();
00097     while (io != startval)  {
00098     }
00099     pulsetime.stop();
00100     return pulsetime.read_us();
00101 }
00102 
00103 int PulseInOut::read_us(int timeout)   {
00104     runtime.reset();
00105     runtime.start();
00106     pulsetime.reset();
00107     io.input();
00108     startval = io;
00109     while (io == startval)  {
00110         if (runtime.read_us() > timeout)   return -1;
00111     }
00112     pulsetime.start();
00113     while (io != startval)   {
00114         if (runtime.read_us() > timeout)   return -1;
00115     }
00116     pulsetime.stop();
00117     return pulsetime.read_us();
00118 }