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 Pulse1 by
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 Temp1.start(); 00061 while (io == 0 ) { 00062 } 00063 00064 while (io == 1) { 00065 } 00066 00067 pulsetime.start(); 00068 while (io == 0) { 00069 } 00070 pulsetime.stop(); 00071 return pulsetime.read_us(); 00072 } 00073 00074 int PulseInOut::read_low_us(int timeout) { 00075 runtime.reset(); 00076 runtime.start(); 00077 pulsetime.reset(); 00078 io.input(); 00079 while (io == 0) { 00080 if (runtime.read_us() > timeout) return -1; 00081 } 00082 while (io == 1) { 00083 if (runtime.read_us() > timeout) return -1; 00084 } 00085 pulsetime.start(); 00086 while (io == 0) { 00087 if (runtime.read_us() > timeout) return -1; 00088 } 00089 pulsetime.stop(); 00090 return pulsetime.read_us(); 00091 } 00092 00093 int PulseInOut::read_us() { 00094 pulsetime.reset(); 00095 io.input(); 00096 startval = io; 00097 while (io == startval) { 00098 } 00099 pulsetime.start(); 00100 while (io != startval) { 00101 } 00102 pulsetime.stop(); 00103 return pulsetime.read_us(); 00104 } 00105 00106 int PulseInOut::read_us(int timeout) { 00107 runtime.reset(); 00108 runtime.start(); 00109 pulsetime.reset(); 00110 io.input(); 00111 startval = io; 00112 while (io == startval) { 00113 if (runtime.read_us() > timeout) return -1; 00114 } 00115 pulsetime.start(); 00116 while (io != startval) { 00117 if (runtime.read_us() > timeout) return -1; 00118 } 00119 pulsetime.stop(); 00120 return pulsetime.read_us(); 00121 }
Generated on Tue Jul 19 2022 06:41:15 by
