Skip to content
This repository was archived by the owner on Sep 30, 2019. It is now read-only.

Commit a10b254

Browse files
committed
Moves parsing of sensor type to function, adds dedicated bcm2835_init
function, moves variable definitions into readDHT function to allow multiple reads.
1 parent 501c1ce commit a10b254

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

Adafruit_DHT_Driver/Adafruit_DHT.c

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
#define AM2302 22
3535

3636
int readDHT(int type, int pin);
37+
int parseType(char *input);
38+
int init(void);
3739

3840
int main(int argc, char **argv)
3941
{
@@ -45,10 +47,9 @@ int main(int argc, char **argv)
4547
printf("example: %s 2302 4 - Read from an AM2302 connected to GPIO #4\n", argv[0]);
4648
return 2;
4749
}
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+
5253
if (type == 0) {
5354
printf("Select 11, 22, 2302 as type!\n");
5455
return 3;
@@ -69,10 +70,12 @@ int main(int argc, char **argv)
6970
} // main
7071

7172

72-
int bits[250], data[100];
73-
int bitidx = 0;
73+
7474

7575
int readDHT(int type, int pin) {
76+
int bits[250], data[100];
77+
int bitidx = 0;
78+
7679
int counter = 0;
7780
int laststate = HIGH;
7881
int j=0;
@@ -146,3 +149,16 @@ int readDHT(int type, int pin) {
146149

147150
return 0;
148151
}
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

Comments
 (0)