Include first driver: SHT31
Make I2C reads blocking w/ timeout Add SHT31 driver, roughly :) Fix mg_time() to return a double.
This commit is contained in:
@ -12,6 +12,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "mgos.h"
|
||||
#include <stdio.h>
|
||||
#include <linux/i2c.h>
|
||||
#include <linux/i2c-dev.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
/* Each platform defines its own I2C connection parameters. */
|
||||
struct mgos_i2c;
|
||||
@ -113,5 +122,6 @@ void mgos_i2c_close(struct mgos_i2c *conn);
|
||||
struct mgos_i2c *mgos_i2c_get_global(void);
|
||||
|
||||
// User contributed!
|
||||
int get_i2c_register(struct mgos_i2c *i2c, uint8_t addr, uint8_t reg, uint8_t *val);
|
||||
bool mgos_i2c_open(int busnr);
|
||||
|
||||
|
@ -30,6 +30,8 @@ int log_print_prefix(enum cs_log_level l, const char *func, const char *file);
|
||||
} while (0)
|
||||
|
||||
|
||||
float mg_time();
|
||||
double mg_time();
|
||||
|
||||
void mgos_usleep(uint32_t usecs);
|
||||
|
||||
#endif // __MGOS_MOCK_H
|
||||
|
57
include/mgos_sht31.h
Normal file
57
include/mgos_sht31.h
Normal file
@ -0,0 +1,57 @@
|
||||
#pragma once
|
||||
|
||||
#include "mgos.h"
|
||||
#include "mgos_i2c.h"
|
||||
|
||||
#define MGOS_SHT31_READ_DELAY (2)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct mgos_sht31;
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
struct mgos_sht31 *mgos_sht31_create(struct mgos_i2c *i2c, uint8_t i2caddr);
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
void mgos_sht31_destroy(struct mgos_sht31 **sensor);
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
bool mgos_sht31_read(struct mgos_sht31 *sensor);
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
void mgos_sht31_setHeater(struct mgos_sht31 *sensor, bool enabled);
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
float mgos_sht31_getTemperature(struct mgos_sht31 *sensor);
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
float mgos_sht31_getHumidity(struct mgos_sht31 *sensor);
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
uint16_t mgos_sht31_getStatus(struct mgos_sht31 *sensor);
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
bool mgos_sht31_i2c_init(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
Reference in New Issue
Block a user