upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
ds18b20.h
Go to the documentation of this file.
1 /*
2  * Author: Jon Trulson <jtrulson@ics.com>
3  * Copyright (c) 2016-2017 Intel Corporation.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining
6  * a copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sublicense, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 #pragma once
25 
26 #include <stdlib.h>
27 #include <unistd.h>
28 #include <string.h>
29 
30 #include <mraa/uart_ow.h>
31 #include <upm.h>
32 #include "ds18b20_defs.h"
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
46  // forward declaration
47  typedef struct _ds18b20_info_t ds18b20_info_t;
48 
52  typedef struct _ds18b20_context {
53  mraa_uart_ow_context ow;
54 
55  // number of devices found
56  unsigned int numDevices;
57 
58  // list of allocated ds18b20_info_t instances
59  ds18b20_info_t *devices;
60  } *ds18b20_context;
61 
71  ds18b20_context ds18b20_init(unsigned int uart);
72 
77 
85  void ds18b20_update(const ds18b20_context dev, int index);
86 
95  unsigned int index);
96 
105  void ds18b20_set_resolution(const ds18b20_context dev, unsigned int index,
106  DS18B20_RESOLUTIONS_T res);
107 
114  void ds18b20_copy_scratchpad(const ds18b20_context dev, unsigned int index);
115 
124  void ds18b20_recall_eeprom(const ds18b20_context dev, unsigned int index);
125 
132  unsigned int ds18b20_devices_found(const ds18b20_context dev);
133 
143  const uint8_t *ds18b20_get_id(const ds18b20_context dev,
144  unsigned int index);
145 
146 #ifdef __cplusplus
147 }
148 #endif
void ds18b20_recall_eeprom(const ds18b20_context dev, unsigned int index)
Definition: ds18b20.c:359
unsigned int ds18b20_devices_found(const ds18b20_context dev)
Definition: ds18b20.c:378
void ds18b20_close(ds18b20_context dev)
Definition: ds18b20.c:177
void ds18b20_set_resolution(const ds18b20_context dev, unsigned int index, DS18B20_RESOLUTIONS_T res)
Definition: ds18b20.c:309
const uint8_t * ds18b20_get_id(const ds18b20_context dev, unsigned int index)
Definition: ds18b20.c:385
struct _ds18b20_context * ds18b20_context
void ds18b20_copy_scratchpad(const ds18b20_context dev, unsigned int index)
Definition: ds18b20.c:342
float ds18b20_get_temperature(const ds18b20_context dev, unsigned int index)
Definition: ds18b20.c:296
void ds18b20_update(const ds18b20_context dev, int index)
Definition: ds18b20.c:189
Definition: ds18b20.h:52
Definition: ds18b20.c:31
ds18b20_context ds18b20_init(unsigned int uart)
Definition: ds18b20.c:41