upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
Data Structures | Functions | Typedefs
Include dependency graph for lm35.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 "lm35.h"
#include "upm_utilities.h"
bool shouldRun = true;
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
}
int main()
{
signal(SIGINT, sig_handler);
// Instantiate a LM35 on analog pin A0, with a default analog
// reference voltage of 5.0
lm35_context sensor = lm35_init(0, 5.0);
// Every half second, sample the sensor and output the temperature
while (shouldRun)
{
float temp;
if (lm35_get_temperature(sensor, &temp) != UPM_SUCCESS)
{
printf("lm35_get_temperature failed\n");
return 1;
}
printf("Temperature: %3.2f C\n", temp);
upm_delay_ms(500);
}
printf("Exiting\n");
lm35_close(sensor);
return 0;
}

Go to the source code of this file.

Data Structures

struct  _lm35_context
 

Functions

lm35_context lm35_init (int pin, float aref)
 
void lm35_close (lm35_context dev)
 
upm_result_t lm35_get_temperature (const lm35_context dev, float *temperature)
 
void lm35_set_offset (const lm35_context dev, float offset)
 
void lm35_set_scale (const lm35_context dev, float scale)
 

Typedefs

typedef struct _lm35_contextlm35_context
 

Function Documentation

lm35_context lm35_init ( int  pin,
float  aref 
)

LM35 initialization.

Parameters
pinAnalog pin to use
arefAnalog reference voltage

Here is the call graph for this function:

void lm35_close ( lm35_context  dev)

LM35 close.

Here is the caller graph for this function:

upm_result_t lm35_get_temperature ( const lm35_context  dev,
float *  temperature 
)

Returns the temperature in degrees Celsius

Parameters
temperatureA pointer to a float that will contain the measured temperature.
Returns
UPM status

Here is the caller graph for this function:

void lm35_set_offset ( const lm35_context  dev,
float  offset 
)

Set sensor offset. This offset is applied to the return values before scaling. Default is 0.0.

Parameters
devsensor context pointer
offsetOffset to apply.

Here is the caller graph for this function:

void lm35_set_scale ( const lm35_context  dev,
float  scale 
)

Set sensor scale. This scale is applied to the return values before the offset is applied. Default is 1.0.

Parameters
devsensor context pointer
scaleScale to apply.

Here is the caller graph for this function:

Typedef Documentation

typedef struct _lm35_context * lm35_context

device context