diff --git a/include/items/vSensorTM1637.h b/include/items/vSensorTM1637.h index 70552be2..866dbb14 100644 --- a/include/items/vSensorTM1637.h +++ b/include/items/vSensorTM1637.h @@ -5,6 +5,10 @@ #include "Global.h" #include +struct DisplayObj { + TM1637Display* disp; + int curIndex; +}; class SensorTM1637; @@ -12,26 +16,26 @@ typedef std::vector MySensorTM1637Vector; class SensorTM1637 { public: - SensorTM1637(String key, unsigned long interval, unsigned int x, unsigned int y, String val, String descr); + SensorTM1637(String key, int pin1, int pin2, unsigned long interval, unsigned int c, unsigned int k, String val, String descr); ~SensorTM1637(); void loop(); void writeTM1637(); void execute(String command); String _key; - void printBlankStr(int strSize); private: unsigned long currentMillis; unsigned long prevMillis; unsigned long difference; - - unsigned long _interval; - unsigned int _x; - unsigned int _y; - String _val; + String _descr; - int _prevStrSize; + unsigned long _interval; + unsigned int _c; + unsigned int _k; + String _val; + + TM1637Display* _disp; }; extern MySensorTM1637Vector* mySensorTM1637; diff --git a/src/items/vSensorTM1637.cpp b/src/items/vSensorTM1637.cpp index 7290836b..c59153bd 100644 --- a/src/items/vSensorTM1637.cpp +++ b/src/items/vSensorTM1637.cpp @@ -9,51 +9,58 @@ #include -//LiquidCrystal_I2C *LCDI2C2; +const uint8_t segmentsVal[] = {0x77, 0x7f, 0x39, 0x3f, 0x79, 0x71, 0x3d, 0x76, 0x1e, 0x38, 0x37, 0x3f, 0x73, 0x6d, 0x3e, 0x6e, 0x5f, 0x7c, 0x58, 0x5e, 0x7b, 0x71, 0x74, 0x10, 0x0e, 0x06, 0x54, 0x5c, 0x67, 0x50, 0x78, 0x1c, 0x6e, 0x40, 0x08, 0x48, 0x00, 0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f}; +char segmentsIndex[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'L', 'N', 'O', 'P', 'S', 'U', 'Y', 'a', 'b', 'c', 'd', 'e', 'f', 'h', 'i', 'j', 'l', 'n', 'o', 'q', 'r', 't', 'u', 'y', '-', '_', '=', ' ', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}; -SensorTM1637::SensorTM1637(String key, unsigned long interval, unsigned int x, unsigned int y, String val, String descr) { + +std::map displayObjects; + +uint8_t char2Segment(char ch) { + for (int i=0; isetBrightness(0x0f); + _disp->clear(); + } else { + _disp = displayObjects[pin1].disp; + } } SensorTM1637::~SensorTM1637() {} -//печать пустой строки нужной длинны для затирания предыдущего значения на экране -void SensorTM1637::printBlankStr(int strSize){ - String tmpStr = ""; - for(int i=0; isetCursor(_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 == "noDisplay") _disp->setBrightness(0x00, false); + else if (command == "display") _disp->setBrightness(0x0f, true); + else if (command == "setBrightness") { + String par = sCmd.next(); + _disp->setBrightness(par.toInt()); + } + else if (command == "descr") { + String par = sCmd.next(); + _descr = par; + } + else { //не команда, значит данные + _val = command; + } writeTM1637(); } @@ -68,17 +75,17 @@ void SensorTM1637::loop() { } void SensorTM1637::writeTM1637() { - // 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); - - // _prevStrSize = tmpStr.length(); - // } + if (_disp != nullptr) { + if (_descr != "none") { + uint8_t segments[] = {0}; + segments[0] = char2Segment(_descr.c_str()[0]); + _disp->setSegments(segments, 1, 0); //выводим поле описания в самом первой секции экрана, один символ + } + String tmpStr = getValue(_val); + if (tmpStr == "no value") tmpStr = _val; + + _disp->showNumberDec(tmpStr.toInt(), false, _c, _k); + } } MySensorTM1637Vector* mySensorTM1637 = nullptr; @@ -95,7 +102,7 @@ void TM1637Execute() { void TM1637() { myLineParsing.update(); String key = myLineParsing.gkey(); - String addr = myLineParsing.gaddr(); + String pins = myLineParsing.gpin(); String interval = myLineParsing.gint(); String c = myLineParsing.gc(); String k = myLineParsing.gk(); @@ -103,24 +110,13 @@ void TM1637() { String descr = myLineParsing.gdescr(); myLineParsing.clear(); - int x = selectFromMarkerToMarker(c, ",", 0).toInt(); - int y = selectFromMarkerToMarker(c, ",", 1).toInt(); - 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(); - // } - // } - + int pin1 = selectFromMarkerToMarker(pins, ",", 0).toInt(); + int pin2 = selectFromMarkerToMarker(pins, ",", 1).toInt(); static bool firstTime = true; if (firstTime) mySensorTM1637 = new MySensorTM1637Vector(); firstTime = false; - mySensorTM1637->push_back(SensorTM1637(key, interval.toInt(), x, y, val, descr)); + mySensorTM1637->push_back(SensorTM1637(key, pin1, pin2, interval.toInt(), c.toInt(), k.toInt(), val, descr)); sCmd.addCommand(key.c_str(), TM1637Execute); }