Add app.dht_gpio flag to find DHT sensors
Parse this comma separated string to find GPIO pins on which we must enable DHT sensors. Seperators are space and comma. Can be empty, single GPIO pins, or a list: app.dht_gpio="" app.dht_gpio="5" app.dht_gpio="5,4,14" app.dht_gpio="5 4 14" app.dht_gpio="5, 4 14"
This commit is contained in:
1
mos.yml
1
mos.yml
@ -42,6 +42,7 @@ config_schema:
|
|||||||
- ["app.hostname", "sonoff-sv"]
|
- ["app.hostname", "sonoff-sv"]
|
||||||
- ["app.config", "s", {title: "Application specific config file"}]
|
- ["app.config", "s", {title: "Application specific config file"}]
|
||||||
- ["app.config", "sonoff-basic.json"]
|
- ["app.config", "sonoff-basic.json"]
|
||||||
|
- ["app.dht_gpio", "s", "5,4,14", {title: "Comma Separated list of GPIO pins to enable DHT22/AM2302 sensors on"}]
|
||||||
|
|
||||||
|
|
||||||
#build_vars:
|
#build_vars:
|
||||||
|
16
src/dht.c
16
src/dht.c
@ -3,6 +3,7 @@
|
|||||||
#ifdef MGOS_HAVE_DHT
|
#ifdef MGOS_HAVE_DHT
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "mgos_dht.h"
|
#include "mgos_dht.h"
|
||||||
|
#include "mgos_config.h"
|
||||||
#include "mqtt.h"
|
#include "mqtt.h"
|
||||||
|
|
||||||
#define MAX_DHT 8
|
#define MAX_DHT 8
|
||||||
@ -44,12 +45,17 @@ static bool dht_create(int pin, enum dht_type type) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void dht_init() {
|
void dht_init() {
|
||||||
|
char *tok;
|
||||||
|
|
||||||
memset(s_dht, 0, sizeof (struct mgos_dht *) * MAX_DHT);
|
memset(s_dht, 0, sizeof (struct mgos_dht *) * MAX_DHT);
|
||||||
dht_create(5, AM2302);
|
tok = strtok((char *)mgos_sys_config_get_app_dht_gpio(), ", ");
|
||||||
mgos_msleep(250);
|
while (tok) {
|
||||||
dht_create(4, AM2302);
|
int gpio;
|
||||||
mgos_msleep(250);
|
gpio = atoi(tok);
|
||||||
dht_create(14, AM2302);
|
tok=strtok(NULL, ", ");
|
||||||
|
dht_create(gpio, AM2302);
|
||||||
|
mgos_msleep(250);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
Reference in New Issue
Block a user