upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
Data Structures | Functions | Typedefs
Include dependency graph for ds18b20.h:

API Description

/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <unistd.h>
#include <stdio.h>
#include <signal.h>
#include "ds18b20.h"
#include "upm_utilities.h"
bool shouldRun = true;
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
}
int main(int argc, char **argv)
{
signal(SIGINT, sig_handler);
printf("Initializing...\n");
// Instantiate an DS18B20 instance using the uart 0
if (!sensor)
{
printf("ds18b20_init() failed.\n");
return(1);
}
printf("Found %d device(s)\n\n", ds18b20_devices_found(sensor));
// update and print available values every 2 seconds
while (shouldRun)
{
// update our values for all sensors
ds18b20_update(sensor, -1);
for (unsigned int i=0; i<ds18b20_devices_found(sensor); i++)
{
printf("Device %02d: Temperature: %f C\n",
i, ds18b20_get_temperature(sensor, i));
}
printf("\n");
upm_delay(2);
}
printf("Exiting...\n");
ds18b20_close(sensor);
return 0;
}

Go to the source code of this file.

Data Structures

struct  _ds18b20_context
 

Functions

ds18b20_context ds18b20_init (unsigned int uart)
 
void ds18b20_close (ds18b20_context dev)
 
void ds18b20_update (const ds18b20_context dev, int index)
 
float ds18b20_get_temperature (const ds18b20_context dev, unsigned int index)
 
void ds18b20_set_resolution (const ds18b20_context dev, unsigned int index, DS18B20_RESOLUTIONS_T res)
 
void ds18b20_copy_scratchpad (const ds18b20_context dev, unsigned int index)
 
void ds18b20_recall_eeprom (const ds18b20_context dev, unsigned int index)
 
unsigned int ds18b20_devices_found (const ds18b20_context dev)
 
const uint8_t * ds18b20_get_id (const ds18b20_context dev, unsigned int index)
 

Typedefs

typedef struct _ds18b20_info_t ds18b20_info_t
 
typedef struct _ds18b20_contextds18b20_context
 

Function Documentation

ds18b20_context ds18b20_init ( unsigned int  uart)

This function will initilaize and search the 1-wire bus and store information on each DS18B20 device detected on the bus. If no devices are found, NULL is returned. Once this function completes successfully, you can use ds18b20_devices_found() to determine how many devices were detected.

Returns
device context, or NULL on error.

Here is the call graph for this function:

Here is the caller graph for this function:

void ds18b20_close ( ds18b20_context  dev)

Close the device and deallocate all resources.

Here is the caller graph for this function:

void ds18b20_update ( const ds18b20_context  dev,
int  index 
)

Update our stored temperature for a device. This method must be called prior to ds18b20_get_temperature().

Parameters
indexThe device index to access (starts at 0). Specify -1 to query all detected devices. Default: -1

Here is the caller graph for this function:

float ds18b20_get_temperature ( const ds18b20_context  dev,
unsigned int  index 
)

Get the current temperature. ds18b20_update() must have been called prior to calling this method.

Parameters
indexThe device index to access (starts at 0).
Returns
The last temperature reading in Celsius.

Here is the caller graph for this function:

void ds18b20_set_resolution ( const ds18b20_context  dev,
unsigned int  index,
DS18B20_RESOLUTIONS_T  res 
)

Set the device resolution for a device. These devices support 9, 10, 11, and 12 bits of resolution, with the default from the factory at 12 bits.

Parameters
indexThe device index to access (starts at 0).
resOne of the DS18B20_RESOLUTIONS_T values

Here is the caller graph for this function:

void ds18b20_copy_scratchpad ( const ds18b20_context  dev,
unsigned int  index 
)

Copy the device's scratchpad memory to the EEPROM. This includes the configuration byte (resolution).

Parameters
indexThe device index to access (starts at 0).

Here is the caller graph for this function:

void ds18b20_recall_eeprom ( const ds18b20_context  dev,
unsigned int  index 
)

Copy the device's EEPROM memory to the scratchpad. This method will return when the copy completes. This operation is performed by the device automatically on power up, so it is rarely needed.

Parameters
indexThe device index to access (starts at 0).

Here is the caller graph for this function:

unsigned int ds18b20_devices_found ( const ds18b20_context  dev)

This method will return the number of DS18B20 devices that were found on the bus by ds18b20_init().

Returns
number of DS18B20's that were found on the bus

Here is the caller graph for this function:

const uint8_t* ds18b20_get_id ( const ds18b20_context  dev,
unsigned int  index 
)

Return an 8 byte string representing the unique device ID (1-wire romcode) for a given device index. The pointer returned is statically allocated and will be overwritten on each call.

Parameters
indexThe device index to access (starts at 0).
Returns
pointer to 8 byte DS18B20_ROMCODE_T representing the 1-wire device's unique romcode, or NULL on error.

Here is the caller graph for this function:

Typedef Documentation

Device context