Merge pull request #115 from biveraxe/ver3

Добавление TM1637
This commit is contained in:
IoT Manager
2022-01-14 15:27:55 +01:00
committed by GitHub
9 changed files with 196 additions and 4 deletions

View File

@@ -38,5 +38,6 @@
0;sensor;anyid;anydata;Сенсоры;Параметр;1;c[1];int[10];type[HDC1080_hum];addr[0x76]*
0;sensor;anyid;anydata;Сенсоры;Параметр;1;c[1];int[10];type[AHTX0_temp];addr[0x76]
0;sensor;anyid;anydata;Сенсоры;Параметр;1;c[1];int[10];type[AHTX0_hum];addr[0x76]*
0;LCD2004;lcdid;anydata;Вывод;IP;1;addr[0x27];k[16,2];int[10];c[0,0];val[ip]*
0;LCD2004;lcdid;na;na;IP;1;addr[0x27];k[16,2];int[10];c[0,0];val[ip]*
0;TM1637;dispid;na;na;f;1;pin[12,13];int[10];c[4];k[0];val[1234]*
0;sensor;anyid;anydata;Сенсоры;Параметр;1;c[1];int[10];type[type1];addr[0x76]*

Binary file not shown.

View File

@@ -88,6 +88,7 @@
#define EnableTelegram
#define EnableUart
#define EnableSensorLCD2004
#define EnableSensorTM1637
#endif
#ifdef GATE_MODE

View File

@@ -0,0 +1,44 @@
#ifdef EnableSensorTM1637
#pragma once
#include <Arduino.h>
#include <OneWire.h>
#include "Global.h"
#include <TM1637Display.h>
struct DisplayObj {
TM1637Display* disp;
int curIndex;
};
class SensorTM1637;
typedef std::vector<SensorTM1637> MySensorTM1637Vector;
class SensorTM1637 {
public:
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;
private:
unsigned long currentMillis;
unsigned long prevMillis;
unsigned long difference;
String _descr;
unsigned long _interval;
unsigned int _c;
unsigned int _k;
String _val;
TM1637Display* _disp;
};
extern MySensorTM1637Vector* mySensorTM1637;
extern void TM1637();
#endif

View File

@@ -45,6 +45,7 @@ lib_deps =
Adafruit AHTX0
BH1750
marcoschwartz/LiquidCrystal_I2C@^1.1.4
smougenot/TM1637@0.0.0-alpha+sha.9486982048
monitor_filters = esp8266_exception_decoder
upload_speed = 921600
monitor_speed = 115200
@@ -73,6 +74,7 @@ lib_deps =
Adafruit AHTX0
BH1750
marcoschwartz/LiquidCrystal_I2C@^1.1.4
smougenot/TM1637@0.0.0-alpha+sha.9486982048
monitor_filters = esp8266_exception_decoder
upload_speed = 921600
monitor_speed = 115200
@@ -91,6 +93,7 @@ lib_deps =
CTBot @2.1.6
MySensors @2.3.2
marcoschwartz/LiquidCrystal_I2C@^1.1.4
smougenot/TM1637@0.0.0-alpha+sha.9486982048
monitor_filters = esp8266_exception_decoder
upload_speed = 921600
monitor_speed = 115200
@@ -120,6 +123,7 @@ lib_deps =
Adafruit AHTX0
BH1750
marcoschwartz/LiquidCrystal_I2C@^1.1.4
smougenot/TM1637@0.0.0-alpha+sha.9486982048
monitor_filters = esp32_exception_decoder
upload_speed = 921600
monitor_speed = 115200
@@ -141,6 +145,7 @@ lib_deps =
MySensors @2.3.2
fmalpartida/LiquidCrystal@^1.5.0
marcoschwartz/LiquidCrystal_I2C@^1.1.4
smougenot/TM1637@0.0.0-alpha+sha.9486982048
monitor_filters = esp32_exception_decoder
upload_speed = 921600
monitor_speed = 115200

View File

@@ -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

View File

@@ -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

124
src/items/vSensorTM1637.cpp Normal file
View File

@@ -0,0 +1,124 @@
#include "Consts.h"
#ifdef EnableSensorTM1637
#include "items/vSensorTM1637.h"
#include "BufferExecute.h"
#include "Class/LineParsing.h"
#include "Global.h"
#include "Utils/StringUtils.h"
#include <map>
#include <Arduino.h>
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'};
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;
_interval = interval * 1000;
_c = c;
_k = k;
_val = val;
_descr = descr;
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() {}
void SensorTM1637::execute(String 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();
}
void SensorTM1637::loop() {
currentMillis = millis();
difference = currentMillis - prevMillis;
if (difference >= _interval) {
prevMillis = millis();
writeTM1637();
}
}
void SensorTM1637::writeTM1637() {
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;
void TM1637Execute() {
String key = sCmd.order();
String command = sCmd.next();
for (unsigned int i = 0; i < mySensorTM1637->size(); i++) {
if (mySensorTM1637->at(i)._key == key) mySensorTM1637->at(i).execute(command);
}
}
void TM1637() {
myLineParsing.update();
String key = myLineParsing.gkey();
String pins = myLineParsing.gpin();
String interval = myLineParsing.gint();
String c = myLineParsing.gc();
String k = myLineParsing.gk();
String val = myLineParsing.gval();
String descr = myLineParsing.gdescr();
myLineParsing.clear();
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, pin1, pin2, interval.toInt(), c.toInt(), k.toInt(), val, descr));
sCmd.addCommand(key.c_str(), TM1637Execute);
}
#endif

View File

@@ -1,4 +1,3 @@
#include <SSDP.h>
#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++) {