mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-27 06:32:19 +03:00
add Oled64 module
This commit is contained in:
@@ -28,6 +28,7 @@ void* getAPI_ButtonIn(String subtype, String params);
|
||||
void* getAPI_ButtonOut(String subtype, String params);
|
||||
void* getAPI_Buzzer(String subtype, String params);
|
||||
void* getAPI_Encoder(String subtype, String params);
|
||||
void* getAPI_HttpGet(String subtype, String params);
|
||||
void* getAPI_IoTServo(String subtype, String params);
|
||||
void* getAPI_Mcp23017(String subtype, String params);
|
||||
void* getAPI_Mp3(String subtype, String params);
|
||||
@@ -36,6 +37,7 @@ void* getAPI_Pcf8574(String subtype, String params);
|
||||
void* getAPI_Pwm8266(String subtype, String params);
|
||||
void* getAPI_TelegramLT(String subtype, String params);
|
||||
void* getAPI_Lcd2004(String subtype, String params);
|
||||
void* getAPI_Oled64(String subtype, String params);
|
||||
void* getAPI_TM16XX(String subtype, String params);
|
||||
|
||||
void* getAPI(String subtype, String params) {
|
||||
@@ -68,6 +70,7 @@ if ((tmpAPI = getAPI_ButtonIn(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_ButtonOut(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_Buzzer(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_Encoder(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_HttpGet(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_IoTServo(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_Mcp23017(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_Mp3(subtype, params)) != nullptr) return tmpAPI;
|
||||
@@ -76,6 +79,7 @@ if ((tmpAPI = getAPI_Pcf8574(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_Pwm8266(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_TelegramLT(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_Lcd2004(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_Oled64(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_TM16XX(subtype, params)) != nullptr) return tmpAPI;
|
||||
return nullptr;
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
#include "classes/IoTItem.h"
|
||||
#include <RobotClass_LiquidCrystal_I2C.h>
|
||||
|
||||
RobotClass_LiquidCrystal_I2C *LCDI2C;
|
||||
RobotClass_LiquidCrystal_I2C* LCDI2C;
|
||||
|
||||
class Lcd2004 : public IoTItem {
|
||||
private:
|
||||
@@ -12,7 +12,7 @@ class Lcd2004 : public IoTItem {
|
||||
int _prevStrSize;
|
||||
String _addr;
|
||||
|
||||
bool _isShow = true; // экран показывает
|
||||
bool _isShow = true; // экран показывает
|
||||
|
||||
public:
|
||||
Lcd2004(String parameters) : IoTItem(parameters) {
|
||||
@@ -26,9 +26,9 @@ class Lcd2004 : public IoTItem {
|
||||
}
|
||||
|
||||
jsonRead(parameters, "size", size);
|
||||
int w = selectFromMarkerToMarker(size, ",", 0).toInt(); //количество столбцов
|
||||
int h = selectFromMarkerToMarker(size, ",", 1).toInt(); //количество строк
|
||||
if (LCDI2C == nullptr) { //инициализации экрана еще не было
|
||||
int w = selectFromMarkerToMarker(size, ",", 0).toInt(); // количество столбцов
|
||||
int h = selectFromMarkerToMarker(size, ",", 1).toInt(); // количество строк
|
||||
if (LCDI2C == nullptr) { // инициализации экрана еще не было
|
||||
LCDI2C = new RobotClass_LiquidCrystal_I2C(hexStringToUint8(_addr), w, h, CP_UTF8);
|
||||
if (LCDI2C != nullptr) {
|
||||
LCDI2C->init();
|
||||
@@ -46,7 +46,7 @@ class Lcd2004 : public IoTItem {
|
||||
jsonRead(parameters, "postfix", _postfix);
|
||||
}
|
||||
|
||||
void drawItem(IoTItem* item) {
|
||||
void drawItem(IoTItem* item) {
|
||||
String tmpStr = _prefix;
|
||||
tmpStr += item->getValue();
|
||||
tmpStr += _postfix;
|
||||
@@ -66,15 +66,18 @@ class Lcd2004 : public IoTItem {
|
||||
}
|
||||
|
||||
void onRegEvent(IoTItem* eventItem) {
|
||||
if (LCDI2C == nullptr) { scanI2C(); return;}
|
||||
if (!eventItem || _id2show == "") return;
|
||||
if (LCDI2C == nullptr) {
|
||||
scanI2C();
|
||||
return;
|
||||
}
|
||||
if (!eventItem || _id2show == "") return;
|
||||
|
||||
if (_id2show == eventItem->getID()) {
|
||||
setValue(eventItem->value, false);
|
||||
}
|
||||
}
|
||||
|
||||
IoTValue execute(String command, std::vector<IoTValue> ¶m) {
|
||||
IoTValue execute(String command, std::vector<IoTValue>& param) {
|
||||
if (command == "noBacklight")
|
||||
LCDI2C->noBacklight();
|
||||
else if (command == "backlight")
|
||||
@@ -89,7 +92,7 @@ class Lcd2004 : public IoTItem {
|
||||
if (_isShow) {
|
||||
LCDI2C->noDisplay();
|
||||
_isShow = false;
|
||||
} else {
|
||||
} else {
|
||||
LCDI2C->display();
|
||||
_isShow = true;
|
||||
}
|
||||
@@ -119,7 +122,7 @@ class Lcd2004 : public IoTItem {
|
||||
return {};
|
||||
}
|
||||
|
||||
//печать пустой строки нужной длинны для затирания предыдущего значения на экране
|
||||
// печать пустой строки нужной длинны для затирания предыдущего значения на экране
|
||||
void printBlankStr(int strSize) {
|
||||
String tmpStr = "";
|
||||
for (int i = 0; i < strSize; i++) tmpStr += " ";
|
||||
@@ -127,13 +130,13 @@ class Lcd2004 : public IoTItem {
|
||||
LCDI2C->print(tmpStr);
|
||||
}
|
||||
|
||||
~Lcd2004(){
|
||||
~Lcd2004() {
|
||||
if (LCDI2C) delete LCDI2C;
|
||||
LCDI2C = nullptr;
|
||||
};
|
||||
};
|
||||
|
||||
void *getAPI_Lcd2004(String subtype, String param) {
|
||||
void* getAPI_Lcd2004(String subtype, String param) {
|
||||
if (subtype == F("Lcd2004")) {
|
||||
return new Lcd2004(param);
|
||||
} else {
|
||||
|
||||
137
src/modules/display/Oled64/Oled64.cpp
Normal file
137
src/modules/display/Oled64/Oled64.cpp
Normal file
@@ -0,0 +1,137 @@
|
||||
|
||||
|
||||
#include "Global.h"
|
||||
#include "classes/IoTItem.h"
|
||||
|
||||
#include <map>
|
||||
|
||||
#include <SPI.h>
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_GFX.h>
|
||||
#include <Adafruit_SSD1306.h>
|
||||
|
||||
#define OLED_RESET 0
|
||||
Adafruit_SSD1306 display(OLED_RESET);
|
||||
|
||||
class Oled64 : public IoTItem {
|
||||
private:
|
||||
unsigned int _x;
|
||||
unsigned int _y;
|
||||
String _id2show, _prefix = "", _postfix = "";
|
||||
String _size = "1";
|
||||
String _addr;
|
||||
|
||||
int _prevStrSize;
|
||||
|
||||
bool _isShow = true;
|
||||
|
||||
public:
|
||||
Oled64(String parameters) : IoTItem(parameters) {
|
||||
String size, xy;
|
||||
_prevStrSize = 0;
|
||||
|
||||
jsonRead(parameters, "addr", _addr);
|
||||
if (_addr == "") {
|
||||
scanI2C();
|
||||
return;
|
||||
}
|
||||
|
||||
display.begin(SSD1306_SWITCHCAPVCC, hexStringToUint8(_addr));
|
||||
|
||||
display.display();
|
||||
|
||||
display.clearDisplay();
|
||||
|
||||
jsonRead(parameters, "coord", xy);
|
||||
_x = selectFromMarkerToMarker(xy, ",", 0).toInt();
|
||||
_y = selectFromMarkerToMarker(xy, ",", 1).toInt();
|
||||
jsonRead(parameters, "id2show", _id2show);
|
||||
jsonRead(parameters, "prefix", _prefix);
|
||||
jsonRead(parameters, "postfix", _postfix);
|
||||
jsonRead(parameters, "size", _size);
|
||||
}
|
||||
|
||||
void drawItem(IoTItem *item) {
|
||||
Serial.println("drawItem");
|
||||
String tmpStr = _prefix;
|
||||
tmpStr += item->getValue();
|
||||
tmpStr += _postfix;
|
||||
|
||||
display.setRotation(0);
|
||||
display.setCursor(_x, _y);
|
||||
display.setTextColor(WHITE, BLACK);
|
||||
display.setTextSize(_size.toInt());
|
||||
|
||||
printBlankStr(_prevStrSize);
|
||||
|
||||
display.setCursor(_x, _y);
|
||||
|
||||
display.print(tmpStr);
|
||||
_prevStrSize = tmpStr.length();
|
||||
display.display();
|
||||
_prevStrSize = tmpStr.length();
|
||||
}
|
||||
|
||||
void setValue(const IoTValue &Value, bool genEvent = true) {
|
||||
value = Value;
|
||||
drawItem(this);
|
||||
IoTItem::setValue(Value, genEvent);
|
||||
}
|
||||
|
||||
void onRegEvent(IoTItem *eventItem) {
|
||||
if (!eventItem || _id2show == "") return;
|
||||
|
||||
if (_id2show == eventItem->getID()) {
|
||||
setValue(eventItem->value, false);
|
||||
}
|
||||
}
|
||||
|
||||
IoTValue execute(String command, std::vector<IoTValue> ¶m) {
|
||||
if (command == "display") {
|
||||
_isShow = true;
|
||||
} else if (command == "noDisplay") {
|
||||
_isShow = false;
|
||||
} else if (command == "x") {
|
||||
if (param.size()) {
|
||||
_x = param[0].valD;
|
||||
}
|
||||
} else if (command == "y") {
|
||||
if (param.size()) {
|
||||
_y = param[0].valD;
|
||||
}
|
||||
} else if (command == "prefix") {
|
||||
if (param.size()) {
|
||||
_prefix = param[0].valS;
|
||||
}
|
||||
} else if (command == "postfix") {
|
||||
if (param.size()) {
|
||||
_postfix = param[0].valS;
|
||||
}
|
||||
} else if (command == "id2show") {
|
||||
if (param.size()) {
|
||||
_id2show = param[0].valS;
|
||||
}
|
||||
}
|
||||
|
||||
doByInterval();
|
||||
return {};
|
||||
}
|
||||
|
||||
// печать пустой строки нужной длинны для затирания предыдущего значения на экране
|
||||
void printBlankStr(int strSize) {
|
||||
String tmpStr = "";
|
||||
for (int i = 0; i < strSize; i++) tmpStr += " ";
|
||||
display.setCursor(_x, _y);
|
||||
display.print(tmpStr);
|
||||
}
|
||||
|
||||
~Oled64(){};
|
||||
};
|
||||
|
||||
void *getAPI_Oled64(String subtype, String param) {
|
||||
if (subtype == F("Oled64")) {
|
||||
return new Oled64(param);
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
99
src/modules/display/Oled64/modinfo.json
Normal file
99
src/modules/display/Oled64/modinfo.json
Normal file
@@ -0,0 +1,99 @@
|
||||
{
|
||||
"menuSection": "screens",
|
||||
"configItem": [
|
||||
{
|
||||
"global": 0,
|
||||
"name": "OLED экран 64 8266",
|
||||
"type": "Reading",
|
||||
"subtype": "Oled64",
|
||||
"id": "Oled",
|
||||
"widget": "inputTxt",
|
||||
"page": "screens",
|
||||
"descr": "OLED Экран",
|
||||
"addr": "0x3C",
|
||||
"coord": "0,0",
|
||||
"size": "1",
|
||||
"id2show": "",
|
||||
"prefix": "",
|
||||
"postfix": ""
|
||||
}
|
||||
],
|
||||
"about": {
|
||||
"authorName": "Serghei Crasnicov",
|
||||
"authorContact": "https://t.me/Serghei63",
|
||||
"authorGit": "https://github.com/Serghei63",
|
||||
"specialThanks": "Valentin Khandriga @Valiuhaaa",
|
||||
"moduleName": "Oled64",
|
||||
"moduleVersion": "1.0",
|
||||
"usedRam": {
|
||||
"esp32_4mb": 15,
|
||||
"esp8266_4mb": 15
|
||||
},
|
||||
"title": "Модуль отображения на экранах OLED 64*48",
|
||||
"moduleDesc": "Позволяет выводить на OLED экраны по указанным позициям значения других элементов конфигурации.",
|
||||
"propInfo": {
|
||||
"int": "Период времени в секундах обновления информации на экране по конкретному элементу.",
|
||||
"addr": "Адрес устройства на шине, обычно 0x3C.",
|
||||
"size": "Размерность шрифта экрана.",
|
||||
"coord": "Координата позиции для вывода данных элемента конфигурации.",
|
||||
"id2show": "id элемента конфигурации.",
|
||||
"size": "Размер шрифта. Допускается 1 , 2, 3, 4"
|
||||
},
|
||||
"funcInfo": [
|
||||
{
|
||||
"name": "x",
|
||||
"descr": "Устанавливает первую координату",
|
||||
"params": [
|
||||
"Номер строки первого символа"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "y",
|
||||
"descr": "Устанавливает вторую координату",
|
||||
"params": [
|
||||
"Номер столбца первого символа"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "descr",
|
||||
"descr": "Задает приставку слева от значения",
|
||||
"params": [
|
||||
"Строка"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "descr1",
|
||||
"descr1": "Задает приставку справа от значения",
|
||||
"params": [
|
||||
"Строка"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "id2show",
|
||||
"descr": "Задает ИД элемента, значение которого хотим отображать на экране",
|
||||
"params": [
|
||||
"Имя элемента конфигурации"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"defActive": true,
|
||||
"usedLibs": {
|
||||
"esp32_4mb": [
|
||||
"https://github.com/stblassitude/Adafruit_SSD1306_Wemos_OLED",
|
||||
"https://github.com/adafruit/Adafruit-GFX-Library"
|
||||
],
|
||||
"esp8266_4mb": [
|
||||
"https://github.com/stblassitude/Adafruit_SSD1306_Wemos_OLED",
|
||||
"https://github.com/adafruit/Adafruit-GFX-Library"
|
||||
],
|
||||
"esp8266_1mb": [
|
||||
"https://github.com/stblassitude/Adafruit_SSD1306_Wemos_OLED",
|
||||
"https://github.com/adafruit/Adafruit-GFX-Library"
|
||||
],
|
||||
"esp8266_1mb_ota": [
|
||||
"https://github.com/stblassitude/Adafruit_SSD1306_Wemos_OLED",
|
||||
"https://github.com/adafruit/Adafruit-GFX-Library"
|
||||
]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user