mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-30 11:59:12 +03:00
pwm add
This commit is contained in:
33
include/Class/Pwm.h
Normal file
33
include/Class/Pwm.h
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
#include "Class/LineParsing.h"
|
||||||
|
#include "Global.h"
|
||||||
|
|
||||||
|
class Pwm : public LineParsing {
|
||||||
|
public:
|
||||||
|
Pwm() : LineParsing(){};
|
||||||
|
|
||||||
|
void pwmModeSet() {
|
||||||
|
if (_pin != "") {
|
||||||
|
pinMode(_pin.toInt(), INPUT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void pwmStateSetDefault() {
|
||||||
|
if (_state != "") {
|
||||||
|
pwmChange(_key, _pin, _state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void pwmChange(String key, String pin, String state) {
|
||||||
|
int pinInt = pin.toInt();
|
||||||
|
analogWrite(pinInt, state.toInt());
|
||||||
|
eventGen(key, "");
|
||||||
|
jsonWriteInt(configLiveJson, key, state.toInt());
|
||||||
|
MqttClient::publishStatus(key, state);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
extern Pwm* myPwm;
|
||||||
@@ -10,7 +10,6 @@ class Button : public LineParsing {
|
|||||||
|
|
||||||
void pinModeSet() {
|
void pinModeSet() {
|
||||||
if (_pin != "") {
|
if (_pin != "") {
|
||||||
Serial.println(_pin);
|
|
||||||
pinMode(_pin.toInt(), OUTPUT);
|
pinMode(_pin.toInt(), OUTPUT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,2 @@
|
|||||||
#include "Class/Button.h"
|
#include "Class/Button.h"
|
||||||
|
|
||||||
Button* myButton;
|
Button* myButton;
|
||||||
2
src/Class/Pwm.cpp
Normal file
2
src/Class/Pwm.cpp
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
#include "Class/Pwm.h"
|
||||||
|
Pwm* myPwm;
|
||||||
36
src/Cmd.cpp
36
src/Cmd.cpp
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include "Class/Button.h"
|
#include "Class/Button.h"
|
||||||
#include "Class/LineParsing.h"
|
#include "Class/LineParsing.h"
|
||||||
|
#include "Class/Pwm.h"
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
#include "Module/Terminal.h"
|
#include "Module/Terminal.h"
|
||||||
#include "Servo/Servos.h"
|
#include "Servo/Servos.h"
|
||||||
@@ -100,14 +101,13 @@ void cmd_init() {
|
|||||||
sCmd.addCommand("firmwareVersion", firmwareVersion);
|
sCmd.addCommand("firmwareVersion", firmwareVersion);
|
||||||
|
|
||||||
handle_time_init();
|
handle_time_init();
|
||||||
|
|
||||||
myButton = new Button();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//==========================================Модуль кнопок===================================================
|
//==========================================Модуль кнопок===================================================
|
||||||
//button out light toggle Кнопки Свет 1 pin[12] inv[1] st[1]
|
//button out light toggle Кнопки Свет 1 pin[12] inv[1] st[1]
|
||||||
//==========================================================================================================
|
//==========================================================================================================
|
||||||
void button() {
|
void button() {
|
||||||
|
myButton = new Button();
|
||||||
myButton->update();
|
myButton->update();
|
||||||
String key = myButton->gkey();
|
String key = myButton->gkey();
|
||||||
String pin = myButton->gpin();
|
String pin = myButton->gpin();
|
||||||
@@ -137,31 +137,23 @@ void buttonSet() {
|
|||||||
//pwm out volume range Кнопки Свет 1 pin[12] st[500]
|
//pwm out volume range Кнопки Свет 1 pin[12] st[500]
|
||||||
//==================================================================================================================
|
//==================================================================================================================
|
||||||
void pwm() {
|
void pwm() {
|
||||||
//line->update();
|
myPwm = new Pwm();
|
||||||
//String key = line->gkey();
|
myPwm->update();
|
||||||
//String pin = line->gpin();
|
String key = myPwm->gkey();
|
||||||
//String state = line->gstate();
|
String pin = myPwm->gpin();
|
||||||
//line->clear();
|
String inv = myPwm->ginv();
|
||||||
|
sCmd.addCommand(key.c_str(), pwmSet);
|
||||||
//sCmd.addCommand(key.c_str(), pwmSet);
|
jsonWriteStr(configOptionJson, key + "_pin", pin);
|
||||||
//
|
myPwm->pwmModeSet();
|
||||||
//if (pin != "") {
|
myPwm->pwmStateSetDefault();
|
||||||
// jsonWriteInt(configOptionJson, key + "_pin", pin.toInt());
|
myPwm->clear();
|
||||||
// analogWrite(pin.toInt(), state.toInt());
|
|
||||||
// jsonWriteInt(configLiveJson, key, state.toInt());
|
|
||||||
// MqttClient::publishStatus(key, String(state));
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void pwmSet() {
|
void pwmSet() {
|
||||||
String key = sCmd.order();
|
String key = sCmd.order();
|
||||||
String state = sCmd.next();
|
String state = sCmd.next();
|
||||||
int pin = jsonReadInt(configOptionJson, key + "_pin");
|
String pin = jsonReadStr(configOptionJson, key + "_pin");
|
||||||
|
myPwm->pwmChange(key, pin, state);
|
||||||
analogWrite(pin, state.toInt());
|
|
||||||
eventGen(key, "");
|
|
||||||
jsonWriteStr(configLiveJson, key, state);
|
|
||||||
MqttClient::publishStatus(key, state);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//==================================================================================================================
|
//==================================================================================================================
|
||||||
|
|||||||
Reference in New Issue
Block a user