aboutsummaryrefslogtreecommitdiff
path: root/lib/sensor_ds18b20.h
blob: 046b7aabdf3cc2e97087db655ffdac1a1f692e9c (plain)
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
/* This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
/** library for Maxim DS18B20 digital temperature sensor (using 1-Wire protocol) (API)
 *  @file sensor_ds18b20.h
 *  @author King Kévin <kingkevin@cuvoodoo.info>
 *  @date 2017
 *  @note peripherals used: 1-Wire (timer @ref onewire_master_timer, GPIO @ref onewire_master_gpio)
 *  @warning this library does not support parasite power mode and alarms
 */
#pragma once

/** setup 1-Wire peripheral to communicate with sensors on bus */
void sensor_ds18b20_setup(void);
/** get number of DS18B20 sensors on bus
 *  @return number of DS18B20 sensors on bus
 */
uint64_t sensor_ds18b20_number(void);
/** verify if only DS18B20 sensors are on the bus
 *  @return if only DS18B20 sensors are on the bus
 */
bool sensor_ds18b20_only(void);
/** send all DS18B20 slaves on the bus
 *  @param[out] code ROM code for sensor (0 if error occurred)
 *  @return if an additional sensors have been detected
 */
bool sensor_ds18b20_list(uint64_t* code);
/** start converting (e.g. measuring) temperature
 *  @warning conversion time to wait before reading temperature depends on the resolution set (9 bits: 93.75ms, 10 bits: 187.5ms, 11 bits: 375ms, 12 bits: 950ms)
 *  @param[in] code ROM code of sensor to start conversion on (0 for all, if only DS18B20 sensors are on the bus)
 *  @return if conversion started
 */
bool sensor_ds18b20_convert(uint64_t code);
/** get converted temperature
 *  @note 85.0 C is the default temperature when no conversion has been performed
 *  @param[in] code ROM code of sensor
 *  @return temperature (NaN if error)
 */
float sensor_ds18b20_temperature(uint64_t code);
/** set conversion precision
 *  @param[in] code ROM code of sensor to start conversion on (0 for all, if only DS18B20 sensors are on the bus)
 *  @param[in] precision precision in bits (9-12)
 *  @return if operation succeeded
 */
bool sensor_ds18b20_precision(uint64_t code, uint8_t precision);