From 1effc988e95a7c39ed673bbcc840ff20cec4bb75 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sun, 13 Mar 2016 11:10:51 +0100 Subject: o Initial import of Diller Arduino library. --- src/diller_core.h | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 src/diller_core.h (limited to 'src/diller_core.h') diff --git a/src/diller_core.h b/src/diller_core.h new file mode 100644 index 0000000..a38779c --- /dev/null +++ b/src/diller_core.h @@ -0,0 +1,71 @@ +#pragma once + +#include "diller_utils.h" +#include +#include + +namespace diller { +namespace core { + +using diller::utils::property; + +template +using props = diller::utils::properties; + +enum class diller_error : uint8_t { + OK, INVAL, NOMEM +}; + +static +const char * to_string(diller_error err) { + switch (err) { + case diller_error::OK: + return "ok"; + case diller_error::INVAL: + return "inval"; + case diller_error::NOMEM: + return "nomem"; + default: + return "unknown"; + } +} + +enum class property_action : uint8_t { + VALUE, + NAME, + DESCRIPTION, +}; + +class property_action_listener { + public: + virtual void on_property_action(const property *, property_action) = 0; +}; + +template +class core { + public: + core(const String &mqtt_host, int mqtt_port); + void set_property_action_listener(property_action_listener *); + + void setup(); + void loop(); + + bool connected() const; + + diller_error cmd_property(const char *id, const char *value, const char *name); + props properties; + + const String mqtt_host; + const int mqtt_port = 1883; + String mac; + String client_id; + + private: + void callback(char* topic_, byte* payload, unsigned int length); + property_action_listener *property_action_listener_; +}; + +} // namespace core +} // namespace diller + +#include "impl/diller_core_impl.h" -- cgit v1.2.3