34
34
#define AM2302 22
35
35
36
36
int readDHT (int type , int pin );
37
+ int parseType (char * input );
38
+ int init (void );
37
39
38
40
int main (int argc , char * * argv )
39
41
{
@@ -45,10 +47,9 @@ int main(int argc, char **argv)
45
47
printf ("example: %s 2302 4 - Read from an AM2302 connected to GPIO #4\n" , argv [0 ]);
46
48
return 2 ;
47
49
}
48
- int type = 0 ;
49
- if (strcmp (argv [1 ], "11" ) == 0 ) type = DHT11 ;
50
- if (strcmp (argv [1 ], "22" ) == 0 ) type = DHT22 ;
51
- if (strcmp (argv [1 ], "2302" ) == 0 ) type = AM2302 ;
50
+
51
+ int type = parseType (argv [1 ]);
52
+
52
53
if (type == 0 ) {
53
54
printf ("Select 11, 22, 2302 as type!\n" );
54
55
return 3 ;
@@ -69,10 +70,12 @@ int main(int argc, char **argv)
69
70
} // main
70
71
71
72
72
- int bits [250 ], data [100 ];
73
- int bitidx = 0 ;
73
+
74
74
75
75
int readDHT (int type , int pin ) {
76
+ int bits [250 ], data [100 ];
77
+ int bitidx = 0 ;
78
+
76
79
int counter = 0 ;
77
80
int laststate = HIGH ;
78
81
int j = 0 ;
@@ -146,3 +149,16 @@ int readDHT(int type, int pin) {
146
149
147
150
return 0 ;
148
151
}
152
+
153
+ int parseType (char * input ){
154
+ int type = 0 ;
155
+ if (strcmp (input , "11" ) == 0 ) type = DHT11 ;
156
+ if (strcmp (input , "22" ) == 0 ) type = DHT22 ;
157
+ if (strcmp (input , "2302" ) == 0 ) type = AM2302 ;
158
+ return type ;
159
+ }
160
+
161
+ int init (void ){
162
+ if (bcm2835_init ()) return 1 ;
163
+ return 0 ;
164
+ }
0 commit comments