SmartCradle v1
Baby smart cradle
dht.c
1
10#include <string.h>
11#include <stdio.h>
12#include <stdlib.h>
13#include <fcntl.h>
14#include <unistd.h>
15#include "../inc/dht.h"
16
17void initDHT11(void){
18 system("insmod dht11.ko");
19}
20
21void remDHT11(void){
22 system("rmmod dht11");
23}
24
25int readDHT11(dht11_t *data){
26 int fd0 = open("/dev/dht110", O_RDONLY);
27
28 if(fd0 == -1)
29 {
30 printf("Failed to open DHT11 device driver.\n");
31 return 0;
32 }
33
34 if(read(fd0,data, sizeof(*data)) <= 0)
35 {
36 printf("Failed to read from device driver.\n");
37 close(fd0);
38 return 0;
39 }
40
41 close(fd0);
42
43 return 1;
44}
void remDHT11(void)
Removes the sensor device driver.
Definition: dht.c:21
int readDHT11(dht11_t *data)
Sample from the sensor.
Definition: dht.c:25
void initDHT11(void)
Loads the sensor device driver.
Definition: dht.c:17
DHT11 Data structure CompleteSample: receives all the data from the sensor.
Definition: dht.h:31