Code Formatting (uncrustify)

This commit is contained in:
Pim van Pelt
2018-04-09 19:44:04 +02:00
parent 9067ab01dd
commit 096192138c
9 changed files with 194 additions and 203 deletions

View File

@ -6,4 +6,5 @@
float mgos_prometheus_sensors_dht_get_temp(uint8_t idx);
float mgos_prometheus_sensors_dht_get_humidity(uint8_t idx);
#endif // __MGOS_PROMETHEUS_SENSORS_H

View File

@ -13,7 +13,9 @@ static void bme280_prometheus_metrics(struct mg_connection *nc, void *user_data)
bool bme280;
struct mgos_bme280_stats stats;
if (!s_bme280) return;
if (!s_bme280) {
return;
}
bme280 = mgos_bme280_is_bme280(s_bme280);
mgos_prometheus_metrics_printf(nc, GAUGE,
@ -52,7 +54,6 @@ static void bme280_prometheus_metrics(struct mg_connection *nc, void *user_data)
(void)user_data;
}
static void bme280_timer_cb(void *user_data) {
struct mgos_bme280_stats stats_before, stats_after;
uint32_t usecs = 0;
@ -65,29 +66,26 @@ static void bme280_timer_cb(void *user_data) {
if (mgos_bme280_is_bme280(s_bme280)) {
LOG(LL_INFO, ("BME280 sensor=0 humidity=%.2f%% temperature=%.2fC pressure=%.1fHPa usecs=%u", s_bme280_data.humid, s_bme280_data.temp, s_bme280_data.press, usecs));
}
else {
}else {
LOG(LL_INFO, ("BMP280 sensor=0 temperature=%.2fC pressure=%.1fHPa usecs=%u", s_bme280_data.temp, s_bme280_data.press, usecs));
}
(void)user_data;
}
void bme280_drv_init() {
s_bme280 = mgos_bme280_i2c_create(mgos_sys_config_get_sensors_bme280_i2caddr());
if (s_bme280) {
mgos_set_timer(mgos_sys_config_get_sensors_bme280_period() * 1000, true, bme280_timer_cb, NULL);
mgos_prometheus_metrics_add_handler(bme280_prometheus_metrics, NULL);
}
else {
}else {
LOG(LL_ERROR, ("Could not create BME280 sensor on I2C address 0x%02x", mgos_sys_config_get_sensors_bme280_i2caddr()));
}
}
#else
void bme280_drv_init() {
LOG(LL_ERROR, ("BME280 disabled, include library in mos.yml to enable"));
}
#endif

View File

@ -8,8 +8,7 @@
#define MAX_DHT 8
struct dht_sensor
{
struct dht_sensor {
struct mgos_dht *dht;
float temp;
float humidity;
@ -55,13 +54,14 @@ static void dht_prometheus_metrics(struct mg_connection *nc, void *user_data) {
(void)user_data;
}
static void dht_timer_cb(void *user_data) {
struct dht_sensor * dht_sensor = (struct dht_sensor *)user_data;
struct mgos_dht_stats stats_before, stats_after;
uint32_t usecs = 0;
if (!dht_sensor) return;
if (!dht_sensor) {
return;
}
mgos_dht_getStats(dht_sensor->dht, &stats_before);
dht_sensor->temp = mgos_dht_get_temp(dht_sensor->dht);
@ -72,9 +72,9 @@ static void dht_timer_cb(void *user_data) {
LOG(LL_INFO, ("DHT sensor=%u gpio=%u temperature=%.2fC humidity=%.1f%% usecs=%u", dht_sensor->idx, dht_sensor->gpio, dht_sensor->temp, dht_sensor->humidity, usecs));
}
static bool dht_sensor_create(int pin, enum dht_type type) {
struct dht_sensor *dht_sensor = calloc(1, sizeof(struct dht_sensor));
if (s_num_dht == MAX_DHT) {
LOG(LL_ERROR, ("No more sensor slots available (%d added)", MAX_DHT));
free(dht_sensor);
@ -95,25 +95,26 @@ static bool dht_sensor_create(int pin, enum dht_type type) {
return true;
}
float mgos_prometheus_sensors_dht_get_temp(uint8_t idx) {
if (idx>=s_num_dht)
if (idx >= s_num_dht) {
return NAN;
if (!s_dht_sensor[idx])
}
if (!s_dht_sensor[idx]) {
return NAN;
}
return s_dht_sensor[idx]->temp;
}
float mgos_prometheus_sensors_dht_get_humidity(uint8_t idx) {
if (idx>=s_num_dht)
if (idx >= s_num_dht) {
return NAN;
if (!s_dht_sensor[idx])
}
if (!s_dht_sensor[idx]) {
return NAN;
}
return s_dht_sensor[idx]->humidity;
}
void dht_drv_init() {
char *tok;
@ -127,13 +128,14 @@ void dht_drv_init() {
mgos_msleep(250);
}
if (s_num_dht>0)
if (s_num_dht > 0) {
mgos_prometheus_metrics_add_handler(dht_prometheus_metrics, NULL);
}
}
#else
void dht_drv_init() {
LOG(LL_ERROR, ("DHT disabled, include library in mos.yml to enable"));
}
#endif

View File

@ -40,7 +40,6 @@ static void htu21df_prometheus_metrics(struct mg_connection *nc, void *user_data
(void)user_data;
}
static void htu21df_timer_cb(void *user_data) {
float temperature, humidity;
struct mgos_htu21df_stats stats_before, stats_after;
@ -57,7 +56,6 @@ static void htu21df_timer_cb(void *user_data) {
(void)user_data;
}
void htu21df_drv_init() {
#ifdef MGOS_HAVE_SI7021_I2C
LOG(LL_WARN, ("HTU21DF and SI7021 are both on I2C address 0x40 -- do not enable both!"));
@ -69,9 +67,9 @@ void htu21df_drv_init() {
}
}
#else
void htu21df_drv_init() {
LOG(LL_ERROR, ("HTU21DF disabled, include library in mos.yml to enable"));
}
#endif

View File

@ -37,7 +37,6 @@ static void mcp9808_prometheus_metrics(struct mg_connection *nc, void *user_data
(void)user_data;
}
static void mcp9808_timer_cb(void *user_data) {
float temperature;
struct mgos_mcp9808_stats stats_before, stats_after;
@ -53,7 +52,6 @@ static void mcp9808_timer_cb(void *user_data) {
(void)user_data;
}
void mcp9808_drv_init() {
s_mcp9808 = mgos_mcp9808_create(mgos_i2c_get_global(), mgos_sys_config_get_sensors_mcp9808_i2caddr());
if (s_mcp9808) {
@ -62,9 +60,9 @@ void mcp9808_drv_init() {
}
}
#else
void mcp9808_drv_init() {
LOG(LL_ERROR, ("MCP9808 disabled, include library in mos.yml to enable"));
}
#endif

View File

@ -15,7 +15,6 @@ static void pushgateway_timer(void *user_data) {
(void)user_data;
}
bool mgos_prometheus_sensors_init(void) {
dht_drv_init();
veml6075_drv_init();
@ -25,7 +24,8 @@ bool mgos_prometheus_sensors_init(void) {
htu21df_drv_init();
mcp9808_drv_init();
if (mgos_sys_config_get_sensors_pushgateway_period()>0)
if (mgos_sys_config_get_sensors_pushgateway_period() > 0) {
mgos_set_timer(mgos_sys_config_get_sensors_pushgateway_period() * 1000, true, pushgateway_timer, NULL);
}
return true;
}

View File

@ -40,7 +40,6 @@ static void sht31_prometheus_metrics(struct mg_connection *nc, void *user_data)
(void)user_data;
}
static void sht31_timer_cb(void *user_data) {
float temperature, humidity;
struct mgos_sht31_stats stats_before, stats_after;
@ -57,7 +56,6 @@ static void sht31_timer_cb(void *user_data) {
(void)user_data;
}
void sht31_drv_init() {
#ifdef MGOS_HAVE_SI7021_I2C
#endif
@ -68,9 +66,9 @@ void sht31_drv_init() {
}
}
#else
void sht31_drv_init() {
LOG(LL_ERROR, ("SHT31 disabled, include library in mos.yml to enable"));
}
#endif

View File

@ -40,7 +40,6 @@ static void si7021_prometheus_metrics(struct mg_connection *nc, void *user_data)
(void)user_data;
}
static void si7021_timer_cb(void *user_data) {
float temperature, humidity;
struct mgos_si7021_stats stats_before, stats_after;
@ -57,7 +56,6 @@ static void si7021_timer_cb(void *user_data) {
(void)user_data;
}
void si7021_drv_init() {
#ifdef MGOS_HAVE_HTU21DF_I2C
LOG(LL_WARN, ("HTU21DF and SI7021 are both on I2C address 0x40 -- do not enable both!"));
@ -69,9 +67,9 @@ void si7021_drv_init() {
}
}
#else
void si7021_drv_init() {
LOG(LL_ERROR, ("SI7021 disabled, include library in mos.yml to enable"));
}
#endif

View File

@ -43,7 +43,6 @@ static void veml6075_prometheus_metrics(struct mg_connection *nc, void *user_dat
(void)user_data;
}
static void veml6075_timer_cb(void *user_data) {
double start;
uint32_t usecs = 0;
@ -59,7 +58,6 @@ static void veml6075_timer_cb(void *user_data) {
(void)user_data;
}
void veml6075_drv_init() {
s_veml6075 = mgos_veml6075_create(mgos_i2c_get_global(), mgos_sys_config_get_sensors_veml6075_i2caddr());
if (s_veml6075) {
@ -68,9 +66,9 @@ void veml6075_drv_init() {
}
}
#else
void veml6075_drv_init() {
LOG(LL_ERROR, ("VEML6075 disabled, include library in mos.yml to enable"));
}
#endif