Reformat with bcpp

Used commandline: bcpp -i 2 -yq -ya -s -bcl -tbcl $i
This commit is contained in:
Pim van Pelt
2018-04-09 18:30:46 +02:00
parent 0337487a0c
commit d2e64c0f45
16 changed files with 310 additions and 243 deletions

View File

@ -39,8 +39,8 @@ static bool mgos_sht31_cmd(struct mgos_sht31 *sensor, uint16_t cmd) {
return true;
}
static uint8_t crc8(const uint8_t *data, int len)
{
static uint8_t crc8(const uint8_t *data, int len) {
const uint8_t poly=0x31;
uint8_t crc=0xFF;
@ -52,6 +52,7 @@ static uint8_t crc8(const uint8_t *data, int len)
return crc;
}
static uint16_t mgos_sht31_status(struct mgos_sht31 *sensor) {
uint8_t data[3];
uint16_t value;
@ -67,6 +68,8 @@ static uint16_t mgos_sht31_status(struct mgos_sht31 *sensor) {
return value;
}
// Private functions end
// Public functions follow
@ -85,11 +88,14 @@ struct mgos_sht31 *mgos_sht31_create(struct mgos_i2c *i2c, uint8_t i2caddr) {
mgos_sht31_cmd(sensor, MGOS_SHT31_SOFTRESET);
// Toggle heater on and off, which shows up in status register bit 13 (0=Off, 1=On)
status0=mgos_sht31_status(sensor); // heater is off, bit13 is 0
// heater is off, bit13 is 0
status0=mgos_sht31_status(sensor);
mgos_sht31_cmd(sensor, MGOS_SHT31_HEATEREN);
status1=mgos_sht31_status(sensor); // heater is on, bit13 is 1
// heater is on, bit13 is 1
status1=mgos_sht31_status(sensor);
mgos_sht31_cmd(sensor, MGOS_SHT31_HEATERDIS);
status2=mgos_sht31_status(sensor); // heater is off, bit13 is 0
// heater is off, bit13 is 0
status2=mgos_sht31_status(sensor);
if (((status0 & 0x2000) == 0) && ((status1 & 0x2000) != 0) && ((status2 & 0x2000) == 0)) {
LOG(LL_INFO, ("SHT31 created at I2C 0x%02x", i2caddr));
@ -101,6 +107,7 @@ struct mgos_sht31 *mgos_sht31_create(struct mgos_i2c *i2c, uint8_t i2caddr) {
return NULL;
}
void mgos_sht31_destroy(struct mgos_sht31 **sensor) {
if (!*sensor) return;
free (*sensor);
@ -108,6 +115,7 @@ void mgos_sht31_destroy(struct mgos_sht31 **sensor) {
return;
}
bool mgos_sht31_read(struct mgos_sht31 *sensor) {
double now = mg_time();
@ -117,7 +125,7 @@ bool mgos_sht31_read(struct mgos_sht31 *sensor) {
if (now - sensor->last_read_time < MGOS_SHT31_READ_DELAY) {
return true;
}
// Read out sensor data here
// Read out sensor data here
//
uint8_t data[6];
float humidity, temperature;
@ -149,19 +157,24 @@ bool mgos_sht31_read(struct mgos_sht31 *sensor) {
return true;
}
float mgos_sht31_getTemperature(struct mgos_sht31 *sensor) {
if (!mgos_sht31_read(sensor)) return NAN;
return sensor->temperature;
}
float mgos_sht31_getHumidity(struct mgos_sht31 *sensor) {
if (!mgos_sht31_read(sensor)) return NAN;
return sensor->humidity;
}
bool mgos_sht31_i2c_init(void) {
return true;
}
// Public functions end