Интегрируем дисплэй TM1637 в ядро

This commit is contained in:
2022-01-12 19:01:15 +03:00
parent 0a2c86ccbf
commit c87854b2ce
5 changed files with 68 additions and 51 deletions

View File

@@ -3,7 +3,7 @@
#include <Arduino.h> #include <Arduino.h>
#include <OneWire.h> #include <OneWire.h>
#include "Global.h" #include "Global.h"
#include "LiquidCrystal_I2C.h" #include <TM1637Display.h>
class SensorTM1637; class SensorTM1637;
@@ -34,7 +34,7 @@ class SensorTM1637 {
int _prevStrSize; int _prevStrSize;
}; };
extern MySensorTM1637Vector* mySensorTM16372; extern MySensorTM1637Vector* mySensorTM1637;
extern void TM1637(); extern void TM1637();
#endif #endif

View File

@@ -17,6 +17,7 @@
#include "items/vSensorCcs811.h" #include "items/vSensorCcs811.h"
#include "items/vSensorDallas.h" #include "items/vSensorDallas.h"
#include "items/vSensorLCD2004.h" #include "items/vSensorLCD2004.h"
#include "items/vSensorTM1637.h"
#include "items/vSensorDht.h" #include "items/vSensorDht.h"
#include "items/vSensorNode.h" #include "items/vSensorNode.h"
#include "items/vSensorPzem.h" #include "items/vSensorPzem.h"
@@ -110,6 +111,10 @@ void csvCmdExecute(String& cmdStr) {
} else if (order == F("LCD2004")) { } else if (order == F("LCD2004")) {
#ifdef EnableSensorLCD2004 #ifdef EnableSensorLCD2004
sCmd.addCommand(order.c_str(), lcd2004); sCmd.addCommand(order.c_str(), lcd2004);
#endif
} else if (order == F("TM1637")) {
#ifdef EnableSensorTM1637
sCmd.addCommand(order.c_str(), TM1637);
#endif #endif
} else if (order == F("dht")) { } else if (order == F("dht")) {
#ifdef EnableSensorDht #ifdef EnableSensorDht

View File

@@ -17,6 +17,7 @@
#include "items/vSensorCcs811.h" #include "items/vSensorCcs811.h"
#include "items/vSensorDallas.h" #include "items/vSensorDallas.h"
#include "items/vSensorLCD2004.h" #include "items/vSensorLCD2004.h"
#include "items/vSensorTM1637.h"
#include "items/vSensorDht.h" #include "items/vSensorDht.h"
#include "items/vSensorNode.h" #include "items/vSensorNode.h"
#include "items/vSensorPzem.h" #include "items/vSensorPzem.h"
@@ -178,7 +179,11 @@ void clearVectors() {
if (mySensorLCD20042 != nullptr) { if (mySensorLCD20042 != nullptr) {
if(LCDI2C != nullptr) LCDI2C->clear(); if(LCDI2C != nullptr) LCDI2C->clear();
mySensorLCD20042->clear(); mySensorLCD20042->clear();
}
#endif
#ifdef EnableSensorTM1637
if (mySensorTM1637 != nullptr) {
mySensorTM1637->clear();
} }
#endif #endif
#ifdef EnableSensorUltrasonic #ifdef EnableSensorUltrasonic

View File

@@ -9,7 +9,7 @@
#include <Arduino.h> #include <Arduino.h>
LiquidCrystal_I2C *LCDI2C2; //LiquidCrystal_I2C *LCDI2C2;
SensorTM1637::SensorTM1637(String key, unsigned long interval, unsigned int x, unsigned int y, String val, String descr) { SensorTM1637::SensorTM1637(String key, unsigned long interval, unsigned int x, unsigned int y, String val, String descr) {
_key = key; _key = key;
@@ -27,33 +27,33 @@ SensorTM1637::~SensorTM1637() {}
void SensorTM1637::printBlankStr(int strSize){ void SensorTM1637::printBlankStr(int strSize){
String tmpStr = ""; String tmpStr = "";
for(int i=0; i<strSize; i++) tmpStr += " "; for(int i=0; i<strSize; i++) tmpStr += " ";
LCDI2C2->setCursor(_x, _y); //LCDI2C2->setCursor(_x, _y);
LCDI2C2->print(tmpStr); //LCDI2C2->print(tmpStr);
} }
void SensorTM1637::execute(String command) { void SensorTM1637::execute(String command) {
if (command == "noBacklight") LCDI2C2->noBacklight(); //if (command == "noBacklight") LCDI2C2->noBacklight();
else if (command == "backlight") LCDI2C2->backlight(); //else if (command == "backlight") LCDI2C2->backlight();
else if (command == "noDisplay") LCDI2C2->noDisplay(); //else if (command == "noDisplay") LCDI2C2->noDisplay();
else if (command == "display") LCDI2C2->display(); //else if (command == "display") LCDI2C2->display();
else if (command == "x") { //else if (command == "x") {
printBlankStr(_prevStrSize); // printBlankStr(_prevStrSize);
String par = sCmd.next(); // String par = sCmd.next();
_x = par.toInt(); // _x = par.toInt();
} //}
else if (command == "y") { //else if (command == "y") {
printBlankStr(_prevStrSize); // printBlankStr(_prevStrSize);
String par = sCmd.next(); // String par = sCmd.next();
_y = par.toInt(); // _y = par.toInt();
} //}
else if (command == "descr") { //else if (command == "descr") {
printBlankStr(_prevStrSize); // printBlankStr(_prevStrSize);
String par = sCmd.next(); // String par = sCmd.next();
_descr = par; // _descr = par;
} //}
else { //не команда, значит данные //else { //не команда, значит данные
_val = command; // _val = command;
} //}
writeTM1637(); writeTM1637();
} }
@@ -68,27 +68,27 @@ void SensorTM1637::loop() {
} }
void SensorTM1637::writeTM1637() { void SensorTM1637::writeTM1637() {
if (LCDI2C2 != nullptr) { // if (LCDI2C2 != nullptr) {
printBlankStr(_prevStrSize); // printBlankStr(_prevStrSize);
String tmpStr = getValue(_val); // String tmpStr = getValue(_val);
if (tmpStr == "no value") tmpStr = _val; // if (tmpStr == "no value") tmpStr = _val;
if (_descr != "none") tmpStr = _descr + " " + tmpStr; // if (_descr != "none") tmpStr = _descr + " " + tmpStr;
LCDI2C2->setCursor(_x, _y); // LCDI2C2->setCursor(_x, _y);
LCDI2C2->print(tmpStr); // LCDI2C2->print(tmpStr);
_prevStrSize = tmpStr.length(); // _prevStrSize = tmpStr.length();
} // }
} }
MySensorTM1637Vector* mySensorTM16372 = nullptr; MySensorTM1637Vector* mySensorTM1637 = nullptr;
void TM1637Execute() { void TM1637Execute() {
String key = sCmd.order(); String key = sCmd.order();
String command = sCmd.next(); String command = sCmd.next();
for (unsigned int i = 0; i < mySensorTM16372->size(); i++) { for (unsigned int i = 0; i < mySensorTM1637->size(); i++) {
if (mySensorTM16372->at(i)._key == key) mySensorTM16372->at(i).execute(command); if (mySensorTM1637->at(i)._key == key) mySensorTM1637->at(i).execute(command);
} }
} }
@@ -108,19 +108,19 @@ void TM1637() {
int w = selectFromMarkerToMarker(k, ",", 0).toInt(); //количество столбцов int w = selectFromMarkerToMarker(k, ",", 0).toInt(); //количество столбцов
int h = selectFromMarkerToMarker(k, ",", 1).toInt(); //количество строк int h = selectFromMarkerToMarker(k, ",", 1).toInt(); //количество строк
if (LCDI2C2 == nullptr) { //инициализации экрана еще не было // if (LCDI2C2 == nullptr) { //инициализации экрана еще не было
LCDI2C2 = new LiquidCrystal_I2C(hexStringToUint8(addr), w, h);//hexStringToUint8(addr), w, h); // //LCDI2C2 = new LiquidCrystal_I2C(hexStringToUint8(addr), w, h);//hexStringToUint8(addr), w, h);
if(LCDI2C2 != nullptr) { // if(LCDI2C2 != nullptr) {
LCDI2C2->init(); // LCDI2C2->init();
LCDI2C2->backlight(); // LCDI2C2->backlight();
} // }
} // }
static bool firstTime = true; static bool firstTime = true;
if (firstTime) mySensorTM16372 = new MySensorTM1637Vector(); if (firstTime) mySensorTM1637 = new MySensorTM1637Vector();
firstTime = false; 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); sCmd.addCommand(key.c_str(), TM1637Execute);
} }

View File

@@ -1,4 +1,3 @@
#include <SSDP.h> #include <SSDP.h>
#include "BufferExecute.h" #include "BufferExecute.h"
@@ -30,6 +29,7 @@
#include "items/vSensorCcs811.h" #include "items/vSensorCcs811.h"
#include "items/vSensorDallas.h" #include "items/vSensorDallas.h"
#include "items/vSensorLCD2004.h" #include "items/vSensorLCD2004.h"
#include "items/vSensorTM1637.h"
#include "items/vSensorDht.h" #include "items/vSensorDht.h"
#include "items/vSensorNode.h" #include "items/vSensorNode.h"
#include "items/vSensorPzem.h" #include "items/vSensorPzem.h"
@@ -161,6 +161,13 @@ void loop() {
} }
} }
#endif #endif
#ifdef EnableSensorTM1637
if (mySensorTM1637 != nullptr) {
for (unsigned int i = 0; i < mySensorTM1637->size(); i++) {
mySensorTM1637->at(i).loop();
}
}
#endif
#ifdef EnableSensorUltrasonic #ifdef EnableSensorUltrasonic
if (mySensorUltrasonic != nullptr) { if (mySensorUltrasonic != nullptr) {
for (unsigned int i = 0; i < mySensorUltrasonic->size(); i++) { for (unsigned int i = 0; i < mySensorUltrasonic->size(); i++) {