Skip to content

Commit

Permalink
Merge pull request #3 from QRPp/config-singleton-obj
Browse files Browse the repository at this point in the history
System-wide auto-created configurable singleton
  • Loading branch information
rojer committed Jan 19, 2021
2 parents fe5f0c7 + e39d54a commit e5122f9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions include/mgos_arduino_dallas_temp.h
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions mos.yml
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions src/mgos_arduino_dallas_temp_c.c
@@ -1,5 +1,18 @@
#include <stdbool.h>

#include <mgos_config.h>

#include <mgos_arduino_dallas_temp.h>

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;
}

0 comments on commit e5122f9

Please sign in to comment.