Hardware Reference
In-Depth Information
37 /
38
Wait until the GPIO line goes low:
39
/
40 static inline unsigned
41 wait_until_low(void) {
42 const unsigned maxcount = 12000;
43 unsigned count = 0;
44
45 while ( gread() )
46 if ( ++count >= maxcount || is_signaled )
47 longjmp(timeout_exit,1);
48 return count;
49 }
50
51 /
52
Wait until the GPIO line goes high:
53
/
54 static inline unsigned
55 wait_until_high(void) {
56 unsigned count = 0;
57
58 while ( !gread() )
59 ++count;
60 return count;
61 }
62
63 /
64
Read 1 bit from the DHT11 sensor:
65
/
66 static unsigned
67 rbit(void) {
68 unsigned bias;
69 unsigned lo_count, hi_count;
70
71 wait_until_low();
72 lo_count = wait_until_high();
73 hi_count = wait_until_low();
74
75 bias = lo_count / 3;
76
77 return hi_count + bias > lo_count ? 1 : 0 ;
78 }
79
80 /
81
Read 1 byte from the DHT11 sensor :
82
/
Search WWH ::




Custom Search