5#include "mupplet_core.h"
51#if USTD_FEATURE_MEMORY > USTD_FEATURE_MEM_512B
52 static const char *version;
60 bool activeLogic =
false;
65 DigitalOut(String name, uint8_t port,
bool activeLogic =
false,
const char *topic =
"relay")
66 : name(name), port(port), activeLogic(activeLogic), topic(topic) {
80 void begin(Scheduler *_pSched) {
86 pinMode(port, OUTPUT);
89#if USTD_FEATURE_MEMORY > USTD_FEATURE_MEM_512B
90 auto ft = [=]() { this->loop(); };
91 tID = pSched->add(ft, name, 50000);
92 auto fnall = [=](String topic, String msg, String originator) {
93 this->subsMsg(topic, msg, originator);
95 pSched->subscribe(tID, name +
"/" + topic +
"/#", fnall);
96 pSched->subscribe(tID,
"mqtt/state");
106 if (this->state == state)
112#if USTD_FEATURE_MEMORY > USTD_FEATURE_MEM_512B
121 digitalWrite(port,
true);
123 digitalWrite(port,
false);
129 digitalWrite(port,
false);
131 digitalWrite(port,
true);
135#if USTD_FEATURE_MEMORY > USTD_FEATURE_MEM_512B
136 void publishState() {
138 pSched->publish(name +
"/" + topic +
"/state",
"on");
140 pSched->publish(name +
"/" + topic +
"/state",
"off");
145#if USTD_FEATURE_MEMORY > USTD_FEATURE_MEM_512B
150#if USTD_FEATURE_MEMORY > USTD_FEATURE_MEM_512B
151 void subsMsg(String topic, String msg, String originator) {
153 memset(msgbuf, 0, 128);
154 strncpy(msgbuf, msg.c_str(), 127);
156 if (topic == name +
"/" + topic +
"/set") {
157 set((msg ==
"on" || msg ==
"1"));
158 }
else if (topic ==
"mqtt/state") {
166#if USTD_FEATURE_MEMORY > USTD_FEATURE_MEM_512B
167const char *DigitalOut::version =
"0.2.0";
mupplet-core DigitalOut class
Definition: mup_digital_out.h:49
DigitalOut(String name, uint8_t port, bool activeLogic=false, const char *topic="relay")
Definition: mup_digital_out.h:65
void set(bool state)
Definition: mup_digital_out.h:101
void begin(Scheduler *_pSched)
Definition: mup_digital_out.h:80
The muwerk namespace.
Definition: home_assistant.h:10