diff --git a/include/mgos_arduino_dallas_temp.h b/include/mgos_arduino_dallas_temp.h index d4f6171..05ed6e1 100644 --- a/include/mgos_arduino_dallas_temp.h +++ b/include/mgos_arduino_dallas_temp.h @@ -29,6 +29,9 @@ typedef struct DallasTemperatureTag DallasTemperature; extern "C" { #endif +// Auto-created, config-controlled singleton. NULL if disabled. +DallasTemperature *mgos_ds18x_get_global(); + // Initialize DallasTemperature driver. // Return value: handle opaque pointer. DallasTemperature *mgos_arduino_dt_create(OneWire *ow); diff --git a/mos.yml b/mos.yml index 26f0ab0..626ba49 100644 --- a/mos.yml +++ b/mos.yml @@ -20,6 +20,10 @@ libs: - origin: https://github.com/mongoose-os-libs/arduino-compat - origin: https://github.com/mongoose-os-libs/arduino-onewire +config_schema: + - ["ds18x", "o", {"title":"DTCL (Dallas Temperature Control Library) settings"}] + - ["ds18x.pin", "i", -1, {"title": "GPIO for 1-wire link; -1 disables DTCL singleton"}] + tags: - arduino - c diff --git a/src/mgos_arduino_dallas_temp_c.c b/src/mgos_arduino_dallas_temp_c.c index bfd7202..55398e2 100644 --- a/src/mgos_arduino_dallas_temp_c.c +++ b/src/mgos_arduino_dallas_temp_c.c @@ -1,5 +1,18 @@ #include +#include + +#include + +static DallasTemperature *s_global_mgos_ds18x = NULL; +DallasTemperature *mgos_ds18x_get_global() { + return s_global_mgos_ds18x; +} + bool mgos_arduino_dallas_temperature_init(void) { + int pin = mgos_sys_config_get_ds18x_pin(); + if (pin < 0) return true; + s_global_mgos_ds18x = mgos_arduino_dt_create(mgos_arduino_onewire_create(pin)); + mgos_arduino_dt_begin(s_global_mgos_ds18x); return true; }