diff --git a/include/Consts.h b/include/Consts.h index 0fbb2765..fe42560a 100644 --- a/include/Consts.h +++ b/include/Consts.h @@ -1,8 +1,6 @@ #pragma once -// -// Firmware -// +//===========Firmware============================================================================================================================================= #ifdef ESP8266 #define FIRMWARE_NAME "esp8266-iotm" #define FIRMWARE_VERSION 262 @@ -11,35 +9,24 @@ #define FIRMWARE_NAME "esp32-iotm" #define FIRMWARE_VERSION 259 #endif - #define FLASH_4MB true -// -// System -// +//===========FSystem============================================================================================================================================== #define NUM_BUTTONS 6 #define LED_PIN 2 -// -// MQTT -// +//===========MQTT================================================================================================================================================= #define MQTT_RECONNECT_INTERVAL 20000 -// -// Telemetry -// +//==========Telemetry============================================================================================================================================= #define TELEMETRY_UPDATE_INTERVAL_MIN 60 - -// -// Configuration -// +//=========Configuration========================================================================================================================================== #define DEVICE_CONFIG_FILE "s.conf.csv" #define DEVICE_SCENARIO_FILE "s.scen.txt" -// -// System parts -// + +//=========System parts=========================================================================================================================================== //#define OTA_UPDATES_ENABLED //#define MDNS_ENABLED //#define WEBSOCKET_ENABLED @@ -47,9 +34,7 @@ //#define UDP_ENABLED //#define SSDP_ENABLED -// -// Sensors enable/disable -// +//=========Sensors enable/disable================================================================================================================================= #define TANK_LEVEL_SAMPLES 10 #define LEVEL_ENABLED #define ANALOG_ENABLED @@ -58,15 +43,13 @@ #define BMP_ENABLED #define BME_ENABLED -// -// Gears enable/disable -// + +//=========Gears enable/disable=================================================================================================================================== #define STEPPER_ENABLED #define SERVO_ENABLED -// -// Other enable/disable -// + +//========Other enable/disable==================================================================================================================================== #define LOGGING_ENABLED #define SERIAL_ENABLED #define PUSH_ENABLED @@ -84,6 +67,7 @@ struct Time_t { unsigned long valid; }; +//================================================================================================================================================================ enum TimerTask_t { WIFI_SCAN, WIFI_MQTT_CONNECTION_CHECK, SENSORS10SEC, diff --git a/include/items/ImpulsOutClass.h b/include/items/ImpulsOutClass.h new file mode 100644 index 00000000..2f6b8651 --- /dev/null +++ b/include/items/ImpulsOutClass.h @@ -0,0 +1,29 @@ +#pragma once +#include + +#include "Global.h" + +class ImpulsOutClass; + +typedef std::vector MyImpulsOutVector; + +class ImpulsOutClass { + public: + ImpulsOutClass(unsigned long impulsPeriod, unsigned int impulsCount, unsigned int impulsPin); + ~ImpulsOutClass(); + + void loop(); + void activate(); + + private: + unsigned long currentMillis; + unsigned long prevMillis; + + unsigned long _impulsPeriod; + unsigned int _impulsCount; + unsigned int _impulsCountBuf; + unsigned int _impulsPin; + +}; + +extern MyImpulsOutVector* myImpulsOut; diff --git a/src/Web.cpp b/src/Web.cpp index e1485f23..bb033be1 100644 --- a/src/Web.cpp +++ b/src/Web.cpp @@ -1,9 +1,10 @@ #include "Web.h" -#include "items/LoggingClass.h" + #include "Class/NotAsync.h" #include "Global.h" #include "Init.h" #include "ItemsList.h" +#include "items/LoggingClass.h" bool parseRequestForPreset(AsyncWebServerRequest* request, uint8_t& preset) { if (request->hasArg("preset")) { @@ -239,6 +240,8 @@ void web_init() { msg = F("Cервер не найден. Попробуйте повторить позже..."); } else if (lastVersion == -2) { msg = F("Устройство не подключено к роутеру!"); + } else if (lastVersion < FIRMWARE_VERSION) { + msg = F("Ошибка версии. Попробуйте повторить позже..."); } // else if (lastVersion == "") { diff --git a/src/items/ImpulsOutClass.cpp b/src/items/ImpulsOutClass.cpp new file mode 100644 index 00000000..6a0df539 --- /dev/null +++ b/src/items/ImpulsOutClass.cpp @@ -0,0 +1,55 @@ +#include "items/ImpulsOutClass.h" + +#include + +#include "Class/LineParsing.h" +#include "Global.h" +#include "ItemsCmd.h" + +ImpulsOutClass::ImpulsOutClass(unsigned long impulsPeriod, unsigned int impulsCount, unsigned int impulsPin) { + _impulsPeriod = impulsPeriod; + _impulsCount = impulsCount * 2; + _impulsPin = impulsPin; + pinMode(impulsPin, OUTPUT); +} + +ImpulsOutClass::~ImpulsOutClass() {} + +void ImpulsOutClass::activate() { + _impulsCountBuf = _impulsCount; +} + +void ImpulsOutClass::loop() { + currentMillis = millis(); + unsigned long difference = currentMillis - prevMillis; + if (_impulsCountBuf > 0) { + if (difference > _impulsPeriod) { + _impulsCountBuf--; + prevMillis = millis(); + yield(); + digitalWrite(_impulsPin, !digitalRead(_impulsPin)); + yield(); + } + } + if (_impulsCountBuf <= 0) { + digitalWrite(_impulsPin, LOW); + } +} + +MyImpulsOutVector* myImpulsOut = nullptr; + +//void impuls() { +// myLineParsing.update(); +// String loggingValueKey = myLineParsing.gvalue(); +// String key = myLineParsing.gkey(); +// String interv = myLineParsing.gint(); +// String maxcnt = myLineParsing.gmaxcnt(); +// myLineParsing.clear(); +// +// logging_value_names_list += key + ","; +// +// static bool firstTime = true; +// if (firstTime) myImpulsOut = new MyImpulsOutVector(); +// firstTime = false; +// myImpulsOut->push_back(ImpulsOutClass(interv.toInt(), maxcnt.toInt(), loggingValueKey, key)); +//} diff --git a/src/main.cpp b/src/main.cpp index e94d744f..14293ccc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -17,6 +17,8 @@ #include "items/ButtonInClass.h" #include "items/LoggingClass.h" +#include "items/ImpulsOutClass.h" + void not_async_actions(); Timings metric; @@ -99,11 +101,13 @@ void setup() { just_load = false; initialized = true; //this second POST makes the data to be processed (you don't need to connect as "keep-alive" for that to work) - + static bool firstTime = true; + if (firstTime) myImpulsOut = new MyImpulsOutVector(); + firstTime = false; + myImpulsOut->push_back(ImpulsOutClass(500, 10, 13)); + myImpulsOut->at(0).activate(); } - - void loop() { if (!initialized) { return; @@ -129,4 +133,10 @@ void loop() { myLogging->at(i).loop(); } } + + if (myImpulsOut != nullptr) { + for (unsigned int i = 0; i < myImpulsOut->size(); i++) { + myImpulsOut->at(i).loop(); + } + } } \ No newline at end of file