mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-30 11:59:12 +03:00
class
This commit is contained in:
@@ -5,7 +5,8 @@
|
|||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
|
|
||||||
class Item {
|
class Item {
|
||||||
private:
|
|
||||||
|
protected:
|
||||||
String type;
|
String type;
|
||||||
String key;
|
String key;
|
||||||
String file;
|
String file;
|
||||||
|
|||||||
34
include/Class/button.h
Normal file
34
include/Class/button.h
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
#include "Class/Item.h"
|
||||||
|
#include "Global.h"
|
||||||
|
|
||||||
|
class Button : public Item {
|
||||||
|
public:
|
||||||
|
|
||||||
|
void pinModeSet(int pinf) {
|
||||||
|
if (pin != "") {
|
||||||
|
pinMode(pinf, OUTPUT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void pinStateSet(int pinf, int statef) {
|
||||||
|
if (state != "") {
|
||||||
|
digitalWrite(pinf, statef);
|
||||||
|
jsonWriteInt(configLiveJson, key, statef);
|
||||||
|
MqttClient::publishStatus(key, String(statef));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void pinStateSetInv(int pinf, int statef) {
|
||||||
|
if (inv != "" && state != "") {
|
||||||
|
digitalWrite(pinf, !statef);
|
||||||
|
jsonWriteInt(configLiveJson, key, !statef);
|
||||||
|
MqttClient::publishStatus(key, String(!statef));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
extern Button* myButton;
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
#include "Cmd.h"
|
#include "Cmd.h"
|
||||||
|
|
||||||
#include "Class/Item.h"
|
#include "Class/Item.h"
|
||||||
|
#include "Class/Button.h"
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
#include "Module/Terminal.h"
|
#include "Module/Terminal.h"
|
||||||
#include "Servo/Servos.h"
|
#include "Servo/Servos.h"
|
||||||
@@ -112,10 +113,13 @@ void button() {
|
|||||||
String pin = myItem->gpin();
|
String pin = myItem->gpin();
|
||||||
String inv = myItem->ginv();
|
String inv = myItem->ginv();
|
||||||
String state = myItem->gstate();
|
String state = myItem->gstate();
|
||||||
myItem->clear();
|
|
||||||
|
|
||||||
sCmd.addCommand(key.c_str(), buttonSet);
|
sCmd.addCommand(key.c_str(), buttonSet);
|
||||||
|
|
||||||
|
|
||||||
|
myItem->pinModeSet(pin.toInt);
|
||||||
|
|
||||||
if (pin != "") {
|
if (pin != "") {
|
||||||
pinMode(pin.toInt(), OUTPUT);
|
pinMode(pin.toInt(), OUTPUT);
|
||||||
jsonWriteInt(configOptionJson, key + "_pin", pin.toInt());
|
jsonWriteInt(configOptionJson, key + "_pin", pin.toInt());
|
||||||
@@ -132,6 +136,7 @@ void button() {
|
|||||||
jsonWriteStr(configLiveJson, key, state);
|
jsonWriteStr(configLiveJson, key, state);
|
||||||
MqttClient::publishStatus(key, state);
|
MqttClient::publishStatus(key, state);
|
||||||
}
|
}
|
||||||
|
myItem->clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void buttonSet() {
|
void buttonSet() {
|
||||||
|
|||||||
Reference in New Issue
Block a user