Initial checkin of empty MCP9808 driver
This commit is contained in:
19
src/main.c
19
src/main.c
@ -3,10 +3,11 @@
|
||||
#include "mgos_sht31.h"
|
||||
#include "mgos_si7021.h"
|
||||
#include "mgos_htu21df.h"
|
||||
#include "mgos_mcp9808.h"
|
||||
#include <fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#define I2CBUSNR 7
|
||||
#define I2CBUSNR 5
|
||||
|
||||
void i2c_scanner(struct mgos_i2c *i2c) {
|
||||
int i;
|
||||
@ -76,11 +77,23 @@ bool do_htu21df(struct mgos_htu21df *sensor) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool do_mcp9808(struct mgos_mcp9808 *sensor) {
|
||||
float temp;
|
||||
|
||||
if (!sensor) return false;
|
||||
|
||||
temp=mgos_mcp9808_getTemperature(sensor);
|
||||
LOG(LL_INFO, ("temperature=%.2fC", temp));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int main() {
|
||||
struct mgos_i2c *i2c;
|
||||
struct mgos_si7021 *si7021;
|
||||
struct mgos_sht31 *sht31;
|
||||
struct mgos_htu21df *htu21df;
|
||||
struct mgos_mcp9808 *mcp9808;
|
||||
|
||||
if (!mgos_i2c_open(I2CBUSNR)) {
|
||||
LOG(LL_ERROR, ("Cannot open I2C bus %u", I2CBUSNR));
|
||||
@ -102,6 +115,9 @@ int main() {
|
||||
if (!(htu21df = mgos_htu21df_create(i2c, 0x40)))
|
||||
LOG(LL_ERROR, ("Cannot create HTU21DF device"));
|
||||
|
||||
if (!(mcp9808 = mgos_mcp9808_create(i2c, 0x18)))
|
||||
LOG(LL_ERROR, ("Cannot create MCP9808 device"));
|
||||
|
||||
for (;;) {
|
||||
do_sht31(sht31);
|
||||
do_si7021(si7021);
|
||||
@ -112,6 +128,7 @@ int main() {
|
||||
mgos_sht31_destroy(&sht31);
|
||||
mgos_si7021_destroy(&si7021);
|
||||
mgos_htu21df_destroy(&htu21df);
|
||||
mgos_mcp9808_destroy(&mcp9808);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user