mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-30 03:49:13 +03:00
add count down timer
This commit is contained in:
@@ -3,8 +3,8 @@
|
|||||||
"chipID": "",
|
"chipID": "",
|
||||||
"apssid": "IoTmanager",
|
"apssid": "IoTmanager",
|
||||||
"appass": "",
|
"appass": "",
|
||||||
"routerssid": "VOLODYA",
|
"routerssid": "rise",
|
||||||
"routerpass": "BELCHENKO",
|
"routerpass": "hostel3333",
|
||||||
"timezone": 1,
|
"timezone": 1,
|
||||||
"ntp": "pool.ntp.org",
|
"ntp": "pool.ntp.org",
|
||||||
"mqttServer": "wqtt.ru",
|
"mqttServer": "wqtt.ru",
|
||||||
|
|||||||
1
data/items/count-down.txt
Normal file
1
data/items/count-down.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
0;count-down;id;na;na;na;order
|
||||||
@@ -91,7 +91,8 @@
|
|||||||
"/set?addItem=bmp280-temp": "18.Датчик температуры bmp280",
|
"/set?addItem=bmp280-temp": "18.Датчик температуры bmp280",
|
||||||
"/set?addItem=bmp280-press": "19.Датчик давления bmp280",
|
"/set?addItem=bmp280-press": "19.Датчик давления bmp280",
|
||||||
"/set?addItem=impuls-out": "20.Создать импульсы через заданный промежуток времени (управление шд)",
|
"/set?addItem=impuls-out": "20.Создать импульсы через заданный промежуток времени (управление шд)",
|
||||||
"/set?addItem=modbus": "21.Прочитать регистр modbus устройства",
|
"/set?addItem=count-down": "21.Таймер обратного отчета",
|
||||||
|
"/set?addItem=modbus": "22.Прочитать регистр modbus устройства",
|
||||||
"/set?addItem=logging": "a.Логгирование и вывод в график любой величины",
|
"/set?addItem=logging": "a.Логгирование и вывод в график любой величины",
|
||||||
"/set?addItem=uptime": "b.Отобразить время работы устройства"
|
"/set?addItem=uptime": "b.Отобразить время работы устройства"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,4 +44,4 @@ extern void bmp280ReadingPress();
|
|||||||
extern void sysUptime();
|
extern void sysUptime();
|
||||||
extern void uptimeReading();
|
extern void uptimeReading();
|
||||||
|
|
||||||
extern void impuls();
|
|
||||||
|
|||||||
@@ -81,6 +81,9 @@ extern int inOutput_EnterCounter;
|
|||||||
extern String pwmOut_KeyList;
|
extern String pwmOut_KeyList;
|
||||||
extern int pwmOut_EnterCounter;
|
extern int pwmOut_EnterCounter;
|
||||||
//=========================================
|
//=========================================
|
||||||
|
extern String countDown_KeyList;
|
||||||
|
extern int countDown_EnterCounter;
|
||||||
|
//=========================================
|
||||||
|
|
||||||
// Sensors
|
// Sensors
|
||||||
extern String sensorReadingMap10sec;
|
extern String sensorReadingMap10sec;
|
||||||
|
|||||||
27
include/items/vCountDown.h
Normal file
27
include/items/vCountDown.h
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include "Global.h"
|
||||||
|
|
||||||
|
class CountDownClass;
|
||||||
|
|
||||||
|
typedef std::vector<CountDownClass> MyCountDownVector;
|
||||||
|
|
||||||
|
class CountDownClass {
|
||||||
|
public:
|
||||||
|
CountDownClass(String key);
|
||||||
|
~CountDownClass();
|
||||||
|
|
||||||
|
void loop();
|
||||||
|
void execute(unsigned int countDownPeriod);
|
||||||
|
|
||||||
|
private:
|
||||||
|
unsigned long _countDownPeriod = 0;
|
||||||
|
String _key;
|
||||||
|
bool _start = false;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
extern MyCountDownVector* myCountDown;
|
||||||
|
|
||||||
|
extern void countDown();
|
||||||
|
extern void countDownExecute();
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
|
|
||||||
class ImpulsOutClass;
|
class ImpulsOutClass;
|
||||||
@@ -28,4 +27,5 @@ class ImpulsOutClass {
|
|||||||
|
|
||||||
extern MyImpulsOutVector* myImpulsOut;
|
extern MyImpulsOutVector* myImpulsOut;
|
||||||
|
|
||||||
|
extern void impuls();
|
||||||
extern void impulsExecute();
|
extern void impulsExecute();
|
||||||
|
|||||||
@@ -6,6 +6,8 @@
|
|||||||
#include "items/vPwmOut.h"
|
#include "items/vPwmOut.h"
|
||||||
#include "items/vInOutput.h"
|
#include "items/vInOutput.h"
|
||||||
#include "items/vLogging.h"
|
#include "items/vLogging.h"
|
||||||
|
#include "items/vImpulsOut.h"
|
||||||
|
#include "items/vCountDown.h"
|
||||||
|
|
||||||
void loopCmdAdd(const String& cmdStr) {
|
void loopCmdAdd(const String& cmdStr) {
|
||||||
orderBuf += cmdStr;
|
orderBuf += cmdStr;
|
||||||
@@ -89,6 +91,9 @@ void csvCmdExecute(String& cmdStr) {
|
|||||||
else if (order == F("impuls-out")) {
|
else if (order == F("impuls-out")) {
|
||||||
sCmd.addCommand(order.c_str(), impuls);
|
sCmd.addCommand(order.c_str(), impuls);
|
||||||
}
|
}
|
||||||
|
else if (order == F("count-down")) {
|
||||||
|
sCmd.addCommand(order.c_str(), countDown);
|
||||||
|
}
|
||||||
|
|
||||||
sCmd.readStr(buf);
|
sCmd.readStr(buf);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,6 +52,9 @@ int inOutput_EnterCounter = -1;
|
|||||||
String pwmOut_KeyList = "";
|
String pwmOut_KeyList = "";
|
||||||
int pwmOut_EnterCounter = -1;
|
int pwmOut_EnterCounter = -1;
|
||||||
//=========================================
|
//=========================================
|
||||||
|
String countDown_KeyList = "";
|
||||||
|
int countDown_EnterCounter = -1;
|
||||||
|
//=========================================
|
||||||
|
|
||||||
// Sensors
|
// Sensors
|
||||||
String sensorReadingMap10sec;
|
String sensorReadingMap10sec;
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#include "items/vSensorDallas.h"
|
#include "items/vSensorDallas.h"
|
||||||
#include "items/vInOutput.h"
|
#include "items/vInOutput.h"
|
||||||
#include "items/vPwmOut.h"
|
#include "items/vPwmOut.h"
|
||||||
|
#include "items/vCountDown.h"
|
||||||
|
|
||||||
void loadConfig() {
|
void loadConfig() {
|
||||||
configSetupJson = readFile("config.json", 4096);
|
configSetupJson = readFile("config.json", 4096);
|
||||||
@@ -73,6 +74,12 @@ void Device_init() {
|
|||||||
pwmOut_KeyList = "";
|
pwmOut_KeyList = "";
|
||||||
pwmOut_EnterCounter = -1;
|
pwmOut_EnterCounter = -1;
|
||||||
//===================================
|
//===================================
|
||||||
|
if (myCountDown != nullptr) {
|
||||||
|
myCountDown->clear();
|
||||||
|
}
|
||||||
|
countDown_KeyList = "";
|
||||||
|
countDown_EnterCounter = -1;
|
||||||
|
//===================================
|
||||||
|
|
||||||
|
|
||||||
#ifdef LAYOUT_IN_RAM
|
#ifdef LAYOUT_IN_RAM
|
||||||
|
|||||||
71
src/items/vCountDown.cpp
Normal file
71
src/items/vCountDown.cpp
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
#include "items/vCountDown.h"
|
||||||
|
#include "BufferExecute.h"
|
||||||
|
#include "Class/LineParsing.h"
|
||||||
|
#include "Global.h"
|
||||||
|
#include "BufferExecute.h"
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
CountDownClass::CountDownClass(String key) {
|
||||||
|
_key = key;
|
||||||
|
}
|
||||||
|
|
||||||
|
CountDownClass::~CountDownClass() {}
|
||||||
|
|
||||||
|
void CountDownClass::execute(unsigned int countDownPeriod) {
|
||||||
|
_countDownPeriod = countDownPeriod * 1000;
|
||||||
|
_start = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CountDownClass::loop() {
|
||||||
|
static unsigned long prevMillis1;
|
||||||
|
static unsigned long prevMillis2;
|
||||||
|
static int sec;
|
||||||
|
if (_countDownPeriod > 0 && _start) {
|
||||||
|
prevMillis1 = millis();
|
||||||
|
_start = false;
|
||||||
|
sec = (_countDownPeriod / 1000) + 1;
|
||||||
|
}
|
||||||
|
unsigned long currentMillis = millis();
|
||||||
|
unsigned long difference1 = currentMillis - prevMillis1;
|
||||||
|
unsigned long difference2 = currentMillis - prevMillis2;
|
||||||
|
if (difference1 > _countDownPeriod && _countDownPeriod > 0) {
|
||||||
|
_countDownPeriod = 0;
|
||||||
|
eventGen2(_key, "0");
|
||||||
|
}
|
||||||
|
if (difference2 > 1000 && _countDownPeriod > 0) {
|
||||||
|
prevMillis2 = millis();
|
||||||
|
Serial.println(sec--);
|
||||||
|
publishStatus(_key, String(sec));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MyCountDownVector* myCountDown = nullptr;
|
||||||
|
|
||||||
|
void countDown() {
|
||||||
|
myLineParsing.update();
|
||||||
|
String key = myLineParsing.gkey();
|
||||||
|
myLineParsing.clear();
|
||||||
|
|
||||||
|
countDown_EnterCounter++;
|
||||||
|
addKey(key, countDown_KeyList, countDown_EnterCounter);
|
||||||
|
|
||||||
|
static bool firstTime = true;
|
||||||
|
if (firstTime) myCountDown = new MyCountDownVector();
|
||||||
|
firstTime = false;
|
||||||
|
myCountDown->push_back(CountDownClass(key));
|
||||||
|
|
||||||
|
sCmd.addCommand(key.c_str(), countDownExecute);
|
||||||
|
}
|
||||||
|
|
||||||
|
void countDownExecute() {
|
||||||
|
String key = sCmd.order();
|
||||||
|
String countDownPeriod = sCmd.next();
|
||||||
|
|
||||||
|
int number = getKeyNum(key, countDown_KeyList);
|
||||||
|
|
||||||
|
if (myCountDown != nullptr) {
|
||||||
|
if (number != -1) {
|
||||||
|
myCountDown->at(number).execute(countDownPeriod.toInt());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,10 +1,9 @@
|
|||||||
#include "items/vImpulsOut.h"
|
#include "items/vImpulsOut.h"
|
||||||
|
|
||||||
#include <Arduino.h>
|
|
||||||
#include "BufferExecute.h"
|
#include "BufferExecute.h"
|
||||||
#include "Class/LineParsing.h"
|
#include "Class/LineParsing.h"
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
#include "BufferExecute.h"
|
#include "BufferExecute.h"
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
ImpulsOutClass::ImpulsOutClass(unsigned int impulsPin) {
|
ImpulsOutClass::ImpulsOutClass(unsigned int impulsPin) {
|
||||||
_impulsPin = impulsPin;
|
_impulsPin = impulsPin;
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
#include "items/vLogging.h"
|
#include "items/vLogging.h"
|
||||||
#include "items/vImpulsOut.h"
|
#include "items/vImpulsOut.h"
|
||||||
#include "items/vSensorDallas.h"
|
#include "items/vSensorDallas.h"
|
||||||
|
#include "items/vCountDown.h"
|
||||||
#include "Telegram.h"
|
#include "Telegram.h"
|
||||||
|
|
||||||
void not_async_actions();
|
void not_async_actions();
|
||||||
@@ -156,16 +157,19 @@ void loop() {
|
|||||||
myLogging->at(i).loop();
|
myLogging->at(i).loop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (myImpulsOut != nullptr) {
|
if (myImpulsOut != nullptr) {
|
||||||
for (unsigned int i = 0; i < myImpulsOut->size(); i++) {
|
for (unsigned int i = 0; i < myImpulsOut->size(); i++) {
|
||||||
myImpulsOut->at(i).loop();
|
myImpulsOut->at(i).loop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mySensorDallas2 != nullptr) {
|
if (mySensorDallas2 != nullptr) {
|
||||||
for (unsigned int i = 0; i < mySensorDallas2->size(); i++) {
|
for (unsigned int i = 0; i < mySensorDallas2->size(); i++) {
|
||||||
mySensorDallas2->at(i).loop();
|
mySensorDallas2->at(i).loop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (myCountDown != nullptr) {
|
||||||
|
for (unsigned int i = 0; i < myCountDown->size(); i++) {
|
||||||
|
myCountDown->at(i).loop();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user