dht11/dht11.c

changeset 146
11f431ac253d
parent 51
a03b6dac5398
equal deleted inserted replaced
145:1396350141cf 146:11f431ac253d
18 * You should have received a copy of the GNU General Public License 18 * You should have received a copy of the GNU General Public License
19 * along with EC-65K; see the file COPYING. If not, write to the Free 19 * along with EC-65K; see the file COPYING. If not, write to the Free
20 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. 20 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 *****************************************************************************/ 21 *****************************************************************************/
22 22
23 #include "../config.h"
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <stdint.h>
27 #include <stdarg.h>
28 #include <syslog.h>
29 #include <unistd.h>
30
23 #include "dht11.h" 31 #include "dht11.h"
24 32
25 #ifdef HAVE_WIRINGPI_H 33 #ifdef HAVE_WIRINGPI_H
34 #include <wiringPi.h>
26 35
27 #define MAXTIMINGS 100 36 #define MAXTIMINGS 100
28 37
29 int dht11_pin = -1; 38 int dht11_pin = -1;
30 int dht11_temperature = -1; 39 int dht11_temperature = -1;
31 int dht11_humidity = -1; 40 int dht11_humidity = -1;
32 int dht11_valid = false; 41 int dht11_valid = FALSE;
33 int dht11_t_offset = 0; 42 int dht11_t_offset = 0;
34 int dht11_h_offset = 0; 43 int dht11_h_offset = 0;
35 44
36 45
37 46
120 } else { 129 } else {
121 syslog(LOG_NOTICE, "dht11 sensor not present"); 130 syslog(LOG_NOTICE, "dht11 sensor not present");
122 } 131 }
123 dht11_temperature = -1; 132 dht11_temperature = -1;
124 dht11_humidity = -1; 133 dht11_humidity = -1;
125 dht11_valid = false; 134 dht11_valid = FALSE;
126 return; 135 return;
127 } 136 }
128 137
129 /* 138 /*
130 * check we read 40 bits (8bit x 5 ) + verify checksum in the last byte 139 * check we read 40 bits (8bit x 5 ) + verify checksum in the last byte
141 if ((dht11_dat[2] & 0x80) != 0) 150 if ((dht11_dat[2] & 0x80) != 0)
142 t *= -1; 151 t *= -1;
143 152
144 dht11_temperature = t; 153 dht11_temperature = t;
145 dht11_humidity = h; 154 dht11_humidity = h;
146 dht11_valid = true; 155 dht11_valid = TRUE;
147 } else { 156 } else {
148 tries--; 157 tries--;
149 if (tries == 0) 158 if (tries == 0)
150 syslog(LOG_INFO, "dht11 data checksum was wrong 5 times"); 159 syslog(LOG_INFO, "dht11 data checksum was wrong 5 times");
151 usleep(100000); 160 usleep(100000);

mercurial