-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdht22.h
81 lines (71 loc) · 1.88 KB
/
dht22.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/* struct dht22 AVR Lirary
*
* Copyright (C) 2015 Sergey Denisov.
* Written by Sergey Denisov aka LittleBuster ([email protected])
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public Licence
* as published by the Free Software Foundation; either version 3
* of the Licence, or (at your option) any later version.
*
* Original library written by Adafruit Industries. MIT license.
*/
#ifndef __DHT22_H__
#define __DHT22_H__
#include <stdint.h>
#include "myriota_user_api.h"
#include "myriota_hardware_api.h"
/*
* Sensor's port
*/
#define DDR_DHT DDRB
#define PORT_DHT PORTB
#define PIN_DHT PINB
/**
* For MicroSleep
*/
#define CLOCK_RATE 48000000 // Clock rate 48MHz
#define CYCLE_PER_US (CLOCK_RATE / 1000000)
#define CYCLES_PER_LOOP 3
struct dht22
{
uint8_t data[6]; /* data from sensor store here */
uint8_t pin; /* DDR & PORT pin */
};
/**
* Init dht sensor
* @dht: sensor struct
* @pin: PORT & DDR pin
*/
void dht_init(struct dht22 *dht, uint8_t pin);
/**
* Reading temperature from sensor
* @dht: sensor struct
* @temp: out temperature pointer
*
* Returns 1 if succeful reading
* Returns 0 if fail reading
*/
uint8_t dht_read_temp(struct dht22 *dht, float *temp);
/**
* Reading humidity from sensor
* @dht: sensor struct
* @hum: out humidity pointer
*
* Returns 1 if succeful reading
* Returns 0 if fail reading
*/
uint8_t dht_read_hum(struct dht22 *dht, float *hum);
/**
* Reading temperature and humidity from sensor
* @dht: sensor struct
* @temp: out temperature pointer
* @hum: out humidity pointer
*
* Returns 1 if succeful reading
* Returns 0 if fail reading
*
* The fastest function for getting temperature + humidity.
*/
uint8_t dht_read_data(struct dht22 *dht, float *temp, float *hum);
#endif