mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-30 11:59:12 +03:00
Добавляем весь основной функционал для TM1637
This commit is contained in:
@@ -5,6 +5,10 @@
|
|||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
#include <TM1637Display.h>
|
#include <TM1637Display.h>
|
||||||
|
|
||||||
|
struct DisplayObj {
|
||||||
|
TM1637Display* disp;
|
||||||
|
int curIndex;
|
||||||
|
};
|
||||||
|
|
||||||
class SensorTM1637;
|
class SensorTM1637;
|
||||||
|
|
||||||
@@ -12,26 +16,26 @@ typedef std::vector<SensorTM1637> MySensorTM1637Vector;
|
|||||||
|
|
||||||
class SensorTM1637 {
|
class SensorTM1637 {
|
||||||
public:
|
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();
|
~SensorTM1637();
|
||||||
|
|
||||||
void loop();
|
void loop();
|
||||||
void writeTM1637();
|
void writeTM1637();
|
||||||
void execute(String command);
|
void execute(String command);
|
||||||
String _key;
|
String _key;
|
||||||
void printBlankStr(int strSize);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
unsigned long currentMillis;
|
unsigned long currentMillis;
|
||||||
unsigned long prevMillis;
|
unsigned long prevMillis;
|
||||||
unsigned long difference;
|
unsigned long difference;
|
||||||
|
|
||||||
unsigned long _interval;
|
|
||||||
unsigned int _x;
|
|
||||||
unsigned int _y;
|
|
||||||
String _val;
|
|
||||||
String _descr;
|
String _descr;
|
||||||
int _prevStrSize;
|
unsigned long _interval;
|
||||||
|
unsigned int _c;
|
||||||
|
unsigned int _k;
|
||||||
|
String _val;
|
||||||
|
|
||||||
|
TM1637Display* _disp;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern MySensorTM1637Vector* mySensorTM1637;
|
extern MySensorTM1637Vector* mySensorTM1637;
|
||||||
|
|||||||
@@ -9,51 +9,58 @@
|
|||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
//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<int, DisplayObj> displayObjects;
|
||||||
|
|
||||||
|
uint8_t char2Segment(char ch) {
|
||||||
|
for (int i=0; i<sizeof(segmentsIndex); i++) {
|
||||||
|
if (ch == segmentsIndex[i]) return segmentsVal[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
SensorTM1637::SensorTM1637(String key, int pin1, int pin2, unsigned long interval, unsigned int c, unsigned int k, String val, String descr) {
|
||||||
_key = key;
|
_key = key;
|
||||||
_interval = interval * 1000;
|
_interval = interval * 1000;
|
||||||
_x = x;
|
_c = c;
|
||||||
_y = y;
|
_k = k;
|
||||||
_val = val;
|
_val = val;
|
||||||
_descr = descr;
|
_descr = descr;
|
||||||
_prevStrSize = 0;
|
|
||||||
|
if (displayObjects.find(pin1) == displayObjects.end()) {
|
||||||
|
_disp = new TM1637Display(pin1, pin2);
|
||||||
|
DisplayObj dispObj;
|
||||||
|
dispObj.curIndex = 0;
|
||||||
|
dispObj.disp = _disp;
|
||||||
|
displayObjects[pin1] = dispObj;
|
||||||
|
|
||||||
|
_disp->setBrightness(0x0f);
|
||||||
|
_disp->clear();
|
||||||
|
} else {
|
||||||
|
_disp = displayObjects[pin1].disp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SensorTM1637::~SensorTM1637() {}
|
SensorTM1637::~SensorTM1637() {}
|
||||||
|
|
||||||
//печать пустой строки нужной длинны для затирания предыдущего значения на экране
|
|
||||||
void SensorTM1637::printBlankStr(int strSize){
|
|
||||||
String tmpStr = "";
|
|
||||||
for(int i=0; i<strSize; i++) tmpStr += " ";
|
|
||||||
//LCDI2C2->setCursor(_x, _y);
|
|
||||||
//LCDI2C2->print(tmpStr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SensorTM1637::execute(String command) {
|
void SensorTM1637::execute(String command) {
|
||||||
//if (command == "noBacklight") LCDI2C2->noBacklight();
|
if (command == "noDisplay") _disp->setBrightness(0x00, false);
|
||||||
//else if (command == "backlight") LCDI2C2->backlight();
|
else if (command == "display") _disp->setBrightness(0x0f, true);
|
||||||
//else if (command == "noDisplay") LCDI2C2->noDisplay();
|
else if (command == "setBrightness") {
|
||||||
//else if (command == "display") LCDI2C2->display();
|
String par = sCmd.next();
|
||||||
//else if (command == "x") {
|
_disp->setBrightness(par.toInt());
|
||||||
// printBlankStr(_prevStrSize);
|
}
|
||||||
// String par = sCmd.next();
|
else if (command == "descr") {
|
||||||
// _x = par.toInt();
|
String par = sCmd.next();
|
||||||
//}
|
_descr = par;
|
||||||
//else if (command == "y") {
|
}
|
||||||
// printBlankStr(_prevStrSize);
|
else { //не команда, значит данные
|
||||||
// String par = sCmd.next();
|
_val = command;
|
||||||
// _y = par.toInt();
|
}
|
||||||
//}
|
|
||||||
//else if (command == "descr") {
|
|
||||||
// printBlankStr(_prevStrSize);
|
|
||||||
// String par = sCmd.next();
|
|
||||||
// _descr = par;
|
|
||||||
//}
|
|
||||||
//else { //не команда, значит данные
|
|
||||||
// _val = command;
|
|
||||||
//}
|
|
||||||
|
|
||||||
writeTM1637();
|
writeTM1637();
|
||||||
}
|
}
|
||||||
@@ -68,17 +75,17 @@ void SensorTM1637::loop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SensorTM1637::writeTM1637() {
|
void SensorTM1637::writeTM1637() {
|
||||||
// if (LCDI2C2 != nullptr) {
|
if (_disp != nullptr) {
|
||||||
// printBlankStr(_prevStrSize);
|
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;
|
||||||
|
|
||||||
// String tmpStr = getValue(_val);
|
_disp->showNumberDec(tmpStr.toInt(), false, _c, _k);
|
||||||
// if (tmpStr == "no value") tmpStr = _val;
|
}
|
||||||
// if (_descr != "none") tmpStr = _descr + " " + tmpStr;
|
|
||||||
// LCDI2C2->setCursor(_x, _y);
|
|
||||||
// LCDI2C2->print(tmpStr);
|
|
||||||
|
|
||||||
// _prevStrSize = tmpStr.length();
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MySensorTM1637Vector* mySensorTM1637 = nullptr;
|
MySensorTM1637Vector* mySensorTM1637 = nullptr;
|
||||||
@@ -95,7 +102,7 @@ void TM1637Execute() {
|
|||||||
void TM1637() {
|
void TM1637() {
|
||||||
myLineParsing.update();
|
myLineParsing.update();
|
||||||
String key = myLineParsing.gkey();
|
String key = myLineParsing.gkey();
|
||||||
String addr = myLineParsing.gaddr();
|
String pins = myLineParsing.gpin();
|
||||||
String interval = myLineParsing.gint();
|
String interval = myLineParsing.gint();
|
||||||
String c = myLineParsing.gc();
|
String c = myLineParsing.gc();
|
||||||
String k = myLineParsing.gk();
|
String k = myLineParsing.gk();
|
||||||
@@ -103,24 +110,13 @@ void TM1637() {
|
|||||||
String descr = myLineParsing.gdescr();
|
String descr = myLineParsing.gdescr();
|
||||||
myLineParsing.clear();
|
myLineParsing.clear();
|
||||||
|
|
||||||
int x = selectFromMarkerToMarker(c, ",", 0).toInt();
|
int pin1 = selectFromMarkerToMarker(pins, ",", 0).toInt();
|
||||||
int y = selectFromMarkerToMarker(c, ",", 1).toInt();
|
int pin2 = selectFromMarkerToMarker(pins, ",", 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();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
static bool firstTime = true;
|
static bool firstTime = true;
|
||||||
if (firstTime) mySensorTM1637 = new MySensorTM1637Vector();
|
if (firstTime) mySensorTM1637 = new MySensorTM1637Vector();
|
||||||
firstTime = false;
|
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);
|
sCmd.addCommand(key.c_str(), TM1637Execute);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user