From 0a9a1b9387ea9324ab904cc1dee88fd34f01723d Mon Sep 17 00:00:00 2001 From: Mit4el Date: Wed, 15 May 2024 22:22:55 +0300 Subject: [PATCH 1/3] =?UTF-8?q?Impulse=20-=20=D0=B4=D0=B2=D0=B0=20=D1=80?= =?UTF-8?q?=D0=B5=D0=B6=D0=B8=D0=BC=D0=B0=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/sensors/Impulse/Impulse.cpp | 33 ++++++++++++++++++------ src/modules/sensors/Impulse/modinfo.json | 10 ++++--- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/src/modules/sensors/Impulse/Impulse.cpp b/src/modules/sensors/Impulse/Impulse.cpp index e84a1123..b32a2693 100644 --- a/src/modules/sensors/Impulse/Impulse.cpp +++ b/src/modules/sensors/Impulse/Impulse.cpp @@ -12,7 +12,9 @@ private: bool _lastButtonState = LOW; unsigned long _lastDebounceTime = 0; int _debounceDelay = 50; + int _timeORcount = 0; int _count = 0; + int CNT = 0; unsigned long timing; public: @@ -22,6 +24,8 @@ public: jsonRead(parameters, F("pin"), _pin); jsonRead(parameters, F("pinMode"), _pinMode); jsonRead(parameters, F("debounceDelay"), _debounceDelay); + jsonRead(parameters, F("count"), _count); + jsonRead(parameters, F("timeORcount"), _timeORcount); jsonRead(parameters, "int", _int); _round = 0; @@ -53,18 +57,31 @@ public: if (_reading != _buttonState) { _buttonState = _reading; - _count++; + CNT++; } - if (_count == 1) + if (CNT == 1) { timing = millis(); } - if (millis() - timing > _int * 1000 && _count > 1) - { - timing = millis(); - value.valD = _count; - regEvent(value.valD, F("Impulse")); - _count = 0; + if (!_timeORcount) + { // работаем по времени + if (millis() - timing > _int * 1000 && CNT > 1) + { + timing = millis(); + value.valD = CNT; + regEvent(value.valD, F("Impulse")); + CNT = 0; + } + } + else + { // работаем по количеству импульсов + if (_count && CNT == _count) + { + value.valD = 1; + regEvent(value.valD, F("Impulse")); + CNT = 0; + } + } } diff --git a/src/modules/sensors/Impulse/modinfo.json b/src/modules/sensors/Impulse/modinfo.json index 81095235..bc4d8587 100644 --- a/src/modules/sensors/Impulse/modinfo.json +++ b/src/modules/sensors/Impulse/modinfo.json @@ -15,7 +15,9 @@ "pin": 16, "pinMode": "INPUT", "debounceDelay": 3, - "multiply": 1 + "multiply": 1, + "count": 0, + "timeORcount":0 } ], "about": { @@ -24,7 +26,7 @@ "authorGit": "https://github.com/avaksru", "specialThanks": "", "moduleName": "Impulse", - "moduleVersion": "2.0", + "moduleVersion": "3.0", "usedRam": { "esp32_4mb": 15, "esp8266_4mb": 15 @@ -35,7 +37,9 @@ "int": "Период сбора импульсов в секундах", "pin": "Укажите GPIO номер пина для чтения импульсов", "pinMode": "Может быть INPUT_PULLUP INPUT_PULLDOWN INPUT", - "debounceDelay": "Время обработки дребезга (миллисекунд)" + "debounceDelay": "Время обработки дребезга (миллисекунд)", + "count": "количество импульсов для выработки события c 1(единицей в данных). По событию можно прибавлять к другой переменной, так же домножить на multiply. Например 32имп = 0.1кВт => count=32, multiply=0.1", + "timeORcount": "0 - выдает количество импульсов за int секунд; 1 - выдает событие с 1 когда количество импульсов наберется равным count" } }, "defActive": true, From 94bfc4ec61687d635ec20c33490a6ccee9611d44 Mon Sep 17 00:00:00 2001 From: Mit4el Date: Wed, 15 May 2024 22:25:23 +0300 Subject: [PATCH 2/3] =?UTF-8?q?Fix=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BE=D0=BA?= =?UTF-8?q?=20=D0=B8=20=D0=BF=D0=BE=D0=B4=20esp8266?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/ESPNexUpload/src/ESPNexUpload.cpp | 94 +++++++++---------- lib/ESPNexUpload/src/ESPNexUpload.h | 19 +++- src/modules/display/Nextion/Nextion.cpp | 5 +- src/modules/display/Nextion/modinfo.json | 9 +- .../display/NextionUpload/NextionUpload.cpp | 11 ++- src/modules/display/TM16XX/TM16XX.cpp | 2 +- src/modules/exec/Telegram_v2/Telegram_v2.cpp | 13 ++- 7 files changed, 86 insertions(+), 67 deletions(-) diff --git a/lib/ESPNexUpload/src/ESPNexUpload.cpp b/lib/ESPNexUpload/src/ESPNexUpload.cpp index 0856aa5f..1eaf5403 100644 --- a/lib/ESPNexUpload/src/ESPNexUpload.cpp +++ b/lib/ESPNexUpload/src/ESPNexUpload.cpp @@ -26,33 +26,6 @@ #define DEBUG_SERIAL_ENABLE #include "ESPNexUpload.h" -#if defined ESP8266 - -#include - -#ifndef NEXT_RX -#define NEXT_RX 14 // Nextion RX pin | Default 14 / D5 -#define NEXT_TX 12 // Nextion TX pin | Default 12 / D6 -#endif -#ifndef nexSerial -//SoftwareSerial softSerial(NEXT_RX, NEXT_TX); -#define nexSerial softSerial -#define nexSerialBegin(a, b, c) nexSerial.begin(a) -#endif - -#elif defined ESP32 - -#ifndef NEXT_RX -#define NEXT_RX 17 // Nextion RX pin | Default 16 -#define NEXT_TX 16 // Nextion TX pin | Default 17 -#endif -#ifndef nexSerial -#define nexSerial Serial2 -#define nexSerialBegin(a, rx, tx) nexSerial.begin(a, SERIAL_8N1, rx, tx) -#endif - -#endif - #ifdef DEBUG_SERIAL_ENABLE #define dbSerialPrint(a) Serial.print(a) #define dbSerialPrintHex(a) Serial.print(a, HEX) @@ -77,23 +50,40 @@ } while (0) #endif -ESPNexUpload::ESPNexUpload(uint32_t upload_baudrate, uint8_t rx, uint8_t tx) +ESPNexUpload::ESPNexUpload(uint32_t upload_baudrate, int line, int rx, int tx) { _upload_baudrate = upload_baudrate; - if (rx == 0 || tx == 0) - { - _rx = NEXT_RX; - _tx = NEXT_TX; - }else{ - _rx = rx; - _tx = tx; - } + _rx = rx; + _tx = tx; + _line = line; + #if defined ESP8266 - SoftwareSerial softSerial(_rx, _tx); + nexSerial = new SoftwareSerial(_rx, _tx); +#else + if (line >= 0) { + nexSerial = new HardwareSerial(line); + // ((HardwareSerial*)nexSerial)->begin(_upload_baudrate, SERIAL_8N1, _rx, _tx); + } else { + nexSerial = new SoftwareSerial(_rx, _tx); + // ((SoftwareSerial*)nexSerial)->begin(_upload_baudrate); + } #endif } +void ESPNexUpload::nexSerialBegin(uint32_t _speed, int _line, int _rx, int _tx) +{ +#if defined ESP8266 + nexSerial->begin(_speed); +#else + if (_line >= 0) { + ((HardwareSerial*)nexSerial)->begin(_speed, SERIAL_8N1, _rx, _tx); + } else { + ((SoftwareSerial*)nexSerial)->begin(_speed); + } +#endif +} + bool ESPNexUpload::connect() { #if defined ESP8266 @@ -172,7 +162,7 @@ bool ESPNexUpload::_searchBaudrate(uint32_t baudrate) dbSerialPrint(F("init nextion serial interface on baudrate: ")); dbSerialPrintln(baudrate); - nexSerialBegin(baudrate, _rx, _tx); + nexSerialBegin(baudrate, _line, _rx, _tx); _printInfoLine(F("ESP baudrate established, try to connect to display")); const char _nextion_FF_FF[3] = {0xFF, 0xFF, 0x00}; @@ -231,20 +221,20 @@ void ESPNexUpload::sendCommand(const char *cmd, bool tail, bool null_head) if (null_head) { - nexSerial.write(0x00); + ((HardwareSerial*)nexSerial)->write(0x00); } - while (nexSerial.available()) + while (nexSerial->available()) { - nexSerial.read(); + nexSerial->read(); } - nexSerial.print(cmd); + nexSerial->print(cmd); if (tail) { - nexSerial.write(0xFF); - nexSerial.write(0xFF); - nexSerial.write(0xFF); + nexSerial->write(0xFF); + nexSerial->write(0xFF); + nexSerial->write(0xFF); } _printSerialData(true, cmd); } @@ -270,10 +260,10 @@ uint16_t ESPNexUpload::recvRetString(String &response, uint32_t timeout, bool re while (millis() - start <= timeout) { - while (nexSerial.available()) + while (nexSerial->available()) { - c = nexSerial.read(); + c = nexSerial->read(); if (c == 0) { continue; @@ -344,9 +334,9 @@ bool ESPNexUpload::_setPrepareForFirmwareUpdate(uint32_t upload_baudrate) // because switching to another baudrate (nexSerialBegin command) has an higher prio. // The ESP will first jump to the new 'upload_baudrate' and than process the serial 'transmit buffer' // The flush command forced the ESP to wait until the 'transmit buffer' is empty - nexSerial.flush(); + nexSerial->flush(); - nexSerialBegin(upload_baudrate, _rx, _tx); + nexSerialBegin(upload_baudrate, _line, _rx, _tx); _printInfoLine(F("changing upload baudrate...")); _printInfoLine(String(upload_baudrate)); @@ -421,7 +411,7 @@ bool ESPNexUpload::upload(const uint8_t *file_buf, size_t buf_size) c = file_buf[i]; // write byte to nextion over serial - nexSerial.write(c); + nexSerial->write(c); // update sent packets counter _sent_packets++; @@ -438,7 +428,7 @@ bool ESPNexUpload::upload(Stream &myFile) #endif // create buffer for read - uint8_t buff[2048] = {0}; + uint8_t buff[4096] = {0}; // read all data from server while (_undownloadByte > 0 || _undownloadByte == -1) @@ -492,7 +482,7 @@ void ESPNexUpload::end() this->softReset(); // end Serial connection - nexSerial.end(); + ((HardwareSerial*)nexSerial)->end(); // reset sent packets counter _sent_packets = 0; diff --git a/lib/ESPNexUpload/src/ESPNexUpload.h b/lib/ESPNexUpload/src/ESPNexUpload.h index b9cfe746..3a22ac15 100644 --- a/lib/ESPNexUpload/src/ESPNexUpload.h +++ b/lib/ESPNexUpload/src/ESPNexUpload.h @@ -56,6 +56,13 @@ #include #include +#ifdef ESP8266 +#include +#else +#include +#include +#endif + /** * @addtogroup CoreAPI * @{ @@ -79,7 +86,7 @@ public: /* methods */ * * @param uint32_t upload_baudrate - set upload baudrate. */ - ESPNexUpload(uint32_t upload_baudrate, uint8_t rx=0, uint8_t tx=0); + ESPNexUpload(uint32_t upload_baudrate, int line, int rx, int tx); /** * destructor. @@ -256,6 +263,8 @@ private: /* methods */ */ uint32_t calculateTransmissionTimeMs(String message); + void nexSerialBegin(uint32_t upload_baudrate, int line, int rx, int tx); + private: /* data */ uint32_t _baudrate; /* nextion serail baudrate */ uint32_t _undownloadByte; /* undownload byte of tft file */ @@ -263,8 +272,14 @@ private: /* data */ uint16_t _sent_packets = 0; /* upload baudrate */ uint8_t _rx; uint8_t _tx; - + uint8_t _line; THandlerFunction _updateProgressCallback; + +#ifdef ESP8266 + SoftwareSerial* nexSerial; +#else + Stream* nexSerial; +#endif }; /** * @} diff --git a/src/modules/display/Nextion/Nextion.cpp b/src/modules/display/Nextion/Nextion.cpp index 4fe3af4f..a1a25c33 100644 --- a/src/modules/display/Nextion/Nextion.cpp +++ b/src/modules/display/Nextion/Nextion.cpp @@ -211,9 +211,10 @@ public: if (!updated) { SerialPrint("I", F("NextionUpdate"), "connecting to " + (String)_host); - HTTPClient http; + HTTPClient http; #if defined ESP8266 - if (!http.begin(_host, 80, _url)) + WiFiClient client; + if (!http.begin(client, _host, 80, _url)) SerialPrint("I", F("NextionUpdate"), "connection failed "); #elif defined ESP32 if (!http.begin(String("http://") + _host + _url)) diff --git a/src/modules/display/Nextion/modinfo.json b/src/modules/display/Nextion/modinfo.json index d74991c1..7168875d 100644 --- a/src/modules/display/Nextion/modinfo.json +++ b/src/modules/display/Nextion/modinfo.json @@ -87,12 +87,7 @@ }, "defActive": false, "usedLibs": { - "esp32_4mb": [], - "esp32_4mb3f": [], - "esp8266_4mb": [], - "esp8266_1mb": [], - "esp8266_1mb_ota": [], - "esp8285_1mb": [], - "esp8285_1mb_ota": [] + "esp32*": [], + "esp82*": [] } } \ No newline at end of file diff --git a/src/modules/display/NextionUpload/NextionUpload.cpp b/src/modules/display/NextionUpload/NextionUpload.cpp index f2db9474..b8745217 100644 --- a/src/modules/display/NextionUpload/NextionUpload.cpp +++ b/src/modules/display/NextionUpload/NextionUpload.cpp @@ -42,7 +42,8 @@ public: HTTPClient http; #if defined ESP8266 - if (!http.begin(_host, 80, _url)) + WiFiClient client; + if (!http.begin(client, _host, 80, _url)) { // Serial.println("connection failed"); SerialPrint("I", F("NextionUpdate"), "connection failed "); @@ -118,7 +119,13 @@ public: int contentLength = http.getSize(); SerialPrint("I", F("NextionUpdate"), "File received. Update Nextion... "); bool result; - ESPNexUpload nextion(115200, _NEXT_RX, _NEXT_TX); + #ifdef ESP8266 + ESPNexUpload nextion(115200, -1, _NEXT_RX, _NEXT_TX); + #elif defined(esp32c3m_4mb) || defined(esp32s2_4mb) + ESPNexUpload nextion(115200, 1, _NEXT_RX, _NEXT_TX); + #else + ESPNexUpload nextion(115200, 2, _NEXT_RX, _NEXT_TX); + #endif nextion.setUpdateProgressCallback([]() { SerialPrint("I", F("NextionUpdate"), "... "); }); diff --git a/src/modules/display/TM16XX/TM16XX.cpp b/src/modules/display/TM16XX/TM16XX.cpp index 10199d38..8bbafc2d 100644 --- a/src/modules/display/TM16XX/TM16XX.cpp +++ b/src/modules/display/TM16XX/TM16XX.cpp @@ -4,7 +4,7 @@ #include #include #include -#include +#include TM16xxButtons* buttons = nullptr; // указатель на объект управления кнопками для TM1638 иначе nullptr diff --git a/src/modules/exec/Telegram_v2/Telegram_v2.cpp b/src/modules/exec/Telegram_v2/Telegram_v2.cpp index 30092bb6..b872730a 100644 --- a/src/modules/exec/Telegram_v2/Telegram_v2.cpp +++ b/src/modules/exec/Telegram_v2/Telegram_v2.cpp @@ -8,7 +8,9 @@ // #include // #include // #include "esp_camera.h" - +#ifdef ESP8266 +#define FB_DYNAMIC +#endif #include #include @@ -93,6 +95,7 @@ public: if (fl_rollback) { _myBot->tickManual(); // Чтобы отметить сообщение прочитанным +#ifdef ESP32 if (Update.rollBack()) { SerialPrint("I", F("Update"), F("Откат OTA успешно выполнен")); @@ -104,6 +107,7 @@ public: SerialPrint("E", F("Update"), F("Откат OTA не выполнен!")); _myBot->sendMessage("Откат OTA не выполнен!", _chatID); } +#endif } // была попытка OTA обновления. Обновляемся после ответа серверу! if (_OTAstate >= 0) @@ -369,10 +373,16 @@ public: // ------------------------------------------------------------------------- if (msg.text.indexOf("/rollback") != -1 && msg.chatID == _chatID) { +#ifdef ESP32 _myBot->inlineMenu("Вы уверены, что хотите откатить прошивку? " + jsonReadStr(settingsFlashJson, F("name")) + " \n OTA_roll", F("Rollback \t Cancel")); +#elif ESP8266 + SerialPrint("E", F("Update"), F("Откат OTA не поддерживается на esp8266!")); + _myBot->sendMessage("Откат OTA не поддерживается на esp8266!", _chatID); +#endif } else if (msg.text.indexOf("OTA_roll") != -1) { +#ifdef ESP32 // удаляем последнее сообщение от бота _myBot->deleteMessage(_myBot->lastBotMsg()); if (msg.data.indexOf("Rollback") != -1) @@ -387,6 +397,7 @@ public: _myBot->sendMessage("Откат OTA не возможен!", _chatID); } } +#endif } // -------------- Обработка файлов *.bin для прошивки по OTA -------------- // ------------------------------------------------------------------------- From a693f69fddd6bcb7a890cbe5d14666f131201058 Mon Sep 17 00:00:00 2001 From: Mit4el Date: Fri, 7 Jun 2024 19:31:52 +0300 Subject: [PATCH 3/3] Update patch8266_16m.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Абсолютный путь на портале, с ~ почему то перестал работать --- tools/patch8266_16m.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/patch8266_16m.py b/tools/patch8266_16m.py index c0358cec..6b4b139c 100644 --- a/tools/patch8266_16m.py +++ b/tools/patch8266_16m.py @@ -7,7 +7,7 @@ from sys import platform if platform == "linux" or platform == "linux2": # linux - mainPyPath = '~/.platformio/platforms/espressif8266@4.0.1/builder/main.py' + mainPyPath = '/home/rise/.platformio/platforms/espressif8266@4.0.1/builder/main.py' else: # windows mainPyPath = os.environ['USERPROFILE'] + '\\.platformio\\platforms\\espressif8266@4.0.1\\builder\\main.py' @@ -20,4 +20,4 @@ with open(mainPyPath) as fr: shutil.copyfile(mainPyPath, mainPyPath+'.bak') newData = oldData.replace('_value += 0xE00000 # correction', '_value += 0xE00000 # correction\n\n if _value == -0x6000:\n _value = env[k]-0x40200000') with open(mainPyPath, 'w') as fw: - fw.write(newData) \ No newline at end of file + fw.write(newData)