mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-27 14:42:18 +03:00
Интегрируем дисплэй TM1637 в ядро
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
|
||||
#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) {
|
||||
_key = key;
|
||||
@@ -27,33 +27,33 @@ SensorTM1637::~SensorTM1637() {}
|
||||
void SensorTM1637::printBlankStr(int strSize){
|
||||
String tmpStr = "";
|
||||
for(int i=0; i<strSize; i++) tmpStr += " ";
|
||||
LCDI2C2->setCursor(_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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user