Initial checkin of empty MCP9808 driver

This commit is contained in:
Pim van Pelt
2018-04-03 13:46:08 +02:00
parent 9f0cdbb821
commit 62da8aa283
4 changed files with 190 additions and 1 deletions

54
include/mgos_mcp9808.h Normal file
View File

@ -0,0 +1,54 @@
#pragma once
#include "mgos.h"
#include "mgos_i2c.h"
#define MGOS_MCP9808_READ_DELAY (2)
#ifdef __cplusplus
extern "C" {
#endif
struct mgos_mcp9808;
/*
* Initialize a MCP9808 on the I2C bus `i2c` at address specified in `i2caddr`
* parameter (default MCP9808 is on address 0x18). The sensor will be polled for
* validity, upon success a new `struct mgos_mcp9808` is allocated and
* returned. If the device could not be found, NULL is returned.
*/
struct mgos_mcp9808 *mgos_mcp9808_create(struct mgos_i2c *i2c, uint8_t i2caddr);
/*
* Destroy the data structure associated with a MCP9808 device. The reference
* to the pointer of the `struct mgos_mcp9808` has to be provided, and upon
* successful destruction, its associated memory will be freed and the pointer
* set to NULL.
*/
void mgos_mcp9808_destroy(struct mgos_mcp9808 **sensor);
/*
* The sensor will be polled for its temperature and humidity data. If the poll
* has occured in the last `MGOS_MCP9808_READ_DELAY` seconds, the cached data is
* used (so as not to repeatedly poll the bus upon subsequent calls).
*/
bool mgos_mcp9808_read(struct mgos_mcp9808 *sensor);
/*
* The sensor will be polled for its temperature and humidity data. If the poll
* has occured in the last `MGOS_MCP9808_READ_DELAY` seconds, the cached data is
* used (so as not to repeatedly poll the bus upon subsequent calls).
*
* The return value is the temperature of the sensor in Celsius, or NAN if no
* data was found.
*/
float mgos_mcp9808_getTemperature(struct mgos_mcp9808 *sensor);
/*
* Initialization function for MGOS -- currently a noop.
*/
bool mgos_mcp9808_i2c_init(void);
#ifdef __cplusplus
}
#endif