diff --git a/include/items/vSensorTM1637.h b/include/items/vSensorTM1637.h index a60ca2d5..70552be2 100644 --- a/include/items/vSensorTM1637.h +++ b/include/items/vSensorTM1637.h @@ -3,7 +3,7 @@ #include #include #include "Global.h" -#include "LiquidCrystal_I2C.h" +#include class SensorTM1637; @@ -34,7 +34,7 @@ class SensorTM1637 { int _prevStrSize; }; -extern MySensorTM1637Vector* mySensorTM16372; +extern MySensorTM1637Vector* mySensorTM1637; extern void TM1637(); #endif diff --git a/src/BufferExecute.cpp b/src/BufferExecute.cpp index 4c2b483f..74817482 100644 --- a/src/BufferExecute.cpp +++ b/src/BufferExecute.cpp @@ -17,6 +17,7 @@ #include "items/vSensorCcs811.h" #include "items/vSensorDallas.h" #include "items/vSensorLCD2004.h" +#include "items/vSensorTM1637.h" #include "items/vSensorDht.h" #include "items/vSensorNode.h" #include "items/vSensorPzem.h" @@ -110,6 +111,10 @@ void csvCmdExecute(String& cmdStr) { } else if (order == F("LCD2004")) { #ifdef EnableSensorLCD2004 sCmd.addCommand(order.c_str(), lcd2004); +#endif + } else if (order == F("TM1637")) { +#ifdef EnableSensorTM1637 + sCmd.addCommand(order.c_str(), TM1637); #endif } else if (order == F("dht")) { #ifdef EnableSensorDht diff --git a/src/Init.cpp b/src/Init.cpp index 19781682..d55dd099 100644 --- a/src/Init.cpp +++ b/src/Init.cpp @@ -17,6 +17,7 @@ #include "items/vSensorCcs811.h" #include "items/vSensorDallas.h" #include "items/vSensorLCD2004.h" +#include "items/vSensorTM1637.h" #include "items/vSensorDht.h" #include "items/vSensorNode.h" #include "items/vSensorPzem.h" @@ -177,8 +178,12 @@ void clearVectors() { #ifdef EnableSensorLCD2004 if (mySensorLCD20042 != nullptr) { if(LCDI2C != nullptr) LCDI2C->clear(); - mySensorLCD20042->clear(); - + mySensorLCD20042->clear(); + } +#endif +#ifdef EnableSensorTM1637 + if (mySensorTM1637 != nullptr) { + mySensorTM1637->clear(); } #endif #ifdef EnableSensorUltrasonic diff --git a/src/items/vSensorTM1637.cpp b/src/items/vSensorTM1637.cpp index 33c13215..7290836b 100644 --- a/src/items/vSensorTM1637.cpp +++ b/src/items/vSensorTM1637.cpp @@ -9,7 +9,7 @@ #include -LiquidCrystal_I2C *LCDI2C2; +//LiquidCrystal_I2C *LCDI2C2; SensorTM1637::SensorTM1637(String key, unsigned long interval, unsigned int x, unsigned int y, String val, String descr) { _key = key; @@ -27,33 +27,33 @@ SensorTM1637::~SensorTM1637() {} void SensorTM1637::printBlankStr(int strSize){ String tmpStr = ""; for(int i=0; isetCursor(_x, _y); - LCDI2C2->print(tmpStr); + //LCDI2C2->setCursor(_x, _y); + //LCDI2C2->print(tmpStr); } void SensorTM1637::execute(String command) { - if (command == "noBacklight") LCDI2C2->noBacklight(); - else if (command == "backlight") LCDI2C2->backlight(); - else if (command == "noDisplay") LCDI2C2->noDisplay(); - else if (command == "display") LCDI2C2->display(); - else if (command == "x") { - printBlankStr(_prevStrSize); - String par = sCmd.next(); - _x = par.toInt(); - } - else if (command == "y") { - printBlankStr(_prevStrSize); - String par = sCmd.next(); - _y = par.toInt(); - } - else if (command == "descr") { - printBlankStr(_prevStrSize); - String par = sCmd.next(); - _descr = par; - } - else { //не команда, значит данные - _val = command; - } + //if (command == "noBacklight") LCDI2C2->noBacklight(); + //else if (command == "backlight") LCDI2C2->backlight(); + //else if (command == "noDisplay") LCDI2C2->noDisplay(); + //else if (command == "display") LCDI2C2->display(); + //else if (command == "x") { + // printBlankStr(_prevStrSize); + // String par = sCmd.next(); + // _x = par.toInt(); + //} + //else if (command == "y") { + // printBlankStr(_prevStrSize); + // String par = sCmd.next(); + // _y = par.toInt(); + //} + //else if (command == "descr") { + // printBlankStr(_prevStrSize); + // String par = sCmd.next(); + // _descr = par; + //} + //else { //не команда, значит данные + // _val = command; + //} writeTM1637(); } @@ -68,27 +68,27 @@ void SensorTM1637::loop() { } void SensorTM1637::writeTM1637() { - if (LCDI2C2 != nullptr) { - printBlankStr(_prevStrSize); + // if (LCDI2C2 != nullptr) { + // printBlankStr(_prevStrSize); - String tmpStr = getValue(_val); - if (tmpStr == "no value") tmpStr = _val; - if (_descr != "none") tmpStr = _descr + " " + tmpStr; - LCDI2C2->setCursor(_x, _y); - LCDI2C2->print(tmpStr); + // String tmpStr = getValue(_val); + // if (tmpStr == "no value") tmpStr = _val; + // if (_descr != "none") tmpStr = _descr + " " + tmpStr; + // LCDI2C2->setCursor(_x, _y); + // LCDI2C2->print(tmpStr); - _prevStrSize = tmpStr.length(); - } + // _prevStrSize = tmpStr.length(); + // } } -MySensorTM1637Vector* mySensorTM16372 = nullptr; +MySensorTM1637Vector* mySensorTM1637 = nullptr; void TM1637Execute() { String key = sCmd.order(); String command = sCmd.next(); - for (unsigned int i = 0; i < mySensorTM16372->size(); i++) { - if (mySensorTM16372->at(i)._key == key) mySensorTM16372->at(i).execute(command); + for (unsigned int i = 0; i < mySensorTM1637->size(); i++) { + if (mySensorTM1637->at(i)._key == key) mySensorTM1637->at(i).execute(command); } } @@ -108,19 +108,19 @@ void TM1637() { int w = selectFromMarkerToMarker(k, ",", 0).toInt(); //количество столбцов int h = selectFromMarkerToMarker(k, ",", 1).toInt(); //количество строк - if (LCDI2C2 == nullptr) { //инициализации экрана еще не было - LCDI2C2 = new LiquidCrystal_I2C(hexStringToUint8(addr), w, h);//hexStringToUint8(addr), w, h); - if(LCDI2C2 != nullptr) { - LCDI2C2->init(); - LCDI2C2->backlight(); - } - } + // if (LCDI2C2 == nullptr) { //инициализации экрана еще не было + // //LCDI2C2 = new LiquidCrystal_I2C(hexStringToUint8(addr), w, h);//hexStringToUint8(addr), w, h); + // if(LCDI2C2 != nullptr) { + // LCDI2C2->init(); + // LCDI2C2->backlight(); + // } + // } static bool firstTime = true; - if (firstTime) mySensorTM16372 = new MySensorTM1637Vector(); + if (firstTime) mySensorTM1637 = new MySensorTM1637Vector(); firstTime = false; - mySensorTM16372->push_back(SensorTM1637(key, interval.toInt(), x, y, val, descr)); + mySensorTM1637->push_back(SensorTM1637(key, interval.toInt(), x, y, val, descr)); sCmd.addCommand(key.c_str(), TM1637Execute); } diff --git a/src/main.cpp b/src/main.cpp index 274d5e23..c2385e92 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,4 +1,3 @@ - #include #include "BufferExecute.h" @@ -30,6 +29,7 @@ #include "items/vSensorCcs811.h" #include "items/vSensorDallas.h" #include "items/vSensorLCD2004.h" +#include "items/vSensorTM1637.h" #include "items/vSensorDht.h" #include "items/vSensorNode.h" #include "items/vSensorPzem.h" @@ -161,6 +161,13 @@ void loop() { } } #endif +#ifdef EnableSensorTM1637 + if (mySensorTM1637 != nullptr) { + for (unsigned int i = 0; i < mySensorTM1637->size(); i++) { + mySensorTM1637->at(i).loop(); + } + } +#endif #ifdef EnableSensorUltrasonic if (mySensorUltrasonic != nullptr) { for (unsigned int i = 0; i < mySensorUltrasonic->size(); i++) {