File tree Expand file tree Collapse file tree 2 files changed +35
-2
lines changed Expand file tree Collapse file tree 2 files changed +35
-2
lines changed Original file line number Diff line number Diff line change @@ -136,6 +136,9 @@ void detachInterrupt(uint8_t pin);
136136void interrupts (void );
137137void noInterrupts (void );
138138
139+ unsigned long pulseInLong (uint8_t pin, uint8_t state,
140+ unsigned long timeout = 1000000L );
141+
139142void setup (void );
140143void loop (void );
141144
@@ -175,8 +178,6 @@ uint16_t makeWord(byte h, byte l);
175178
176179unsigned long pulseIn (uint8_t pin, uint8_t state,
177180 unsigned long timeout = 1000000L );
178- unsigned long pulseInLong (uint8_t pin, uint8_t state,
179- unsigned long timeout = 1000000L );
180181
181182void tone (uint8_t _pin, unsigned int frequency, unsigned long duration = 0 );
182183void noTone (uint8_t _pin);
Original file line number Diff line number Diff line change 2121#define IRAM
2222#endif
2323
24+ static inline uint64_t uptime () {
25+ return (uint64_t )(1000000 * mgos_uptime ());
26+ }
27+
28+ unsigned long pulseInLong (uint8_t pin, uint8_t state, unsigned long timeout) {
29+ uint64_t startMicros = uptime ();
30+
31+ // wait for any previous pulse to end
32+ while (state == mgos_gpio_read (pin)) {
33+ if ((uptime () - startMicros) > timeout) {
34+ return 0 ;
35+ }
36+ }
37+
38+ // wait for the pulse to start
39+ while (state != mgos_gpio_read (pin)) {
40+ if ((uptime () - startMicros) > timeout) {
41+ return 0 ;
42+ }
43+ }
44+
45+ uint64_t start = uptime ();
46+
47+ // wait for the pulse to stop
48+ while (state == mgos_gpio_read (pin)) {
49+ if ((uptime () - startMicros) > timeout) {
50+ return 0 ;
51+ }
52+ }
53+ return (uint32_t )(uptime () - start);
54+ }
55+
2456IRAM void pinMode (uint8_t pin, uint8_t mode) {
2557 switch (mode) {
2658 case INPUT:
You can’t perform that action at this time.
0 commit comments