add Oled64 module

This commit is contained in:
IoT Manager
2023-10-09 20:38:48 +02:00
parent 0d3e6ee829
commit 928b5a7d5c
9 changed files with 329 additions and 35 deletions

View File

@@ -414,6 +414,10 @@
"path": "src/modules/display/Oled128",
"active": false
},
{
"path": "src/modules/display/Oled64",
"active": true
},
{
"path": "src/modules/display/Smi2_m",
"active": true

View File

@@ -232,7 +232,7 @@
},
{
"path": "src/modules/exec/HttpGet",
"active": false
"active": true
},
{
"path": "src/modules/exec/IoTServo",
@@ -316,6 +316,10 @@
"path": "src/modules/display/Oled128",
"active": false
},
{
"path": "src/modules/display/Oled64",
"active": true
},
{
"path": "src/modules/display/Smi2_m",
"active": true

View File

@@ -730,7 +730,20 @@
},
{
"global": 0,
"name": "48. Сервопривод",
"name": "48. HttpGet",
"type": "Writing",
"subtype": "HttpGet",
"id": "http",
"widget": "",
"page": "",
"descr": "",
"token": "",
"chatID": "",
"num": 48
},
{
"global": 0,
"name": "49. Сервопривод",
"type": "Writing",
"subtype": "IoTServo",
"id": "servo",
@@ -741,11 +754,11 @@
"pin": 12,
"apin": -1,
"amap": "0, 4096, 0, 180",
"num": 48
"num": 49
},
{
"global": 0,
"name": "49. Расширитель портов Mcp23017",
"name": "50. Расширитель портов Mcp23017",
"type": "Reading",
"subtype": "Mcp23017",
"id": "Mcp",
@@ -755,11 +768,11 @@
"int": "0",
"addr": "0x20",
"index": 1,
"num": 49
"num": 50
},
{
"global": 0,
"name": "50. MP3 плеер",
"name": "51. MP3 плеер",
"type": "Reading",
"subtype": "Mp3",
"id": "mp3",
@@ -769,11 +782,11 @@
"int": 1,
"pins": "14,12",
"volume": 20,
"num": 50
"num": 51
},
{
"global": 0,
"name": "51. Сенсорная кнопка",
"name": "52. Сенсорная кнопка",
"type": "Writing",
"subtype": "Multitouch",
"id": "impulse",
@@ -787,11 +800,11 @@
"pinMode": "INPUT",
"debounceDelay": 50,
"PWMDelay": 500,
"num": 51
"num": 52
},
{
"global": 0,
"name": "52. Расширитель портов Pcf8574",
"name": "53. Расширитель портов Pcf8574",
"type": "Reading",
"subtype": "Pcf8574",
"id": "Pcf",
@@ -801,11 +814,11 @@
"int": "0",
"addr": "0x20",
"index": 1,
"num": 52
"num": 53
},
{
"global": 0,
"name": "53. PWM ESP8266",
"name": "54. PWM ESP8266",
"type": "Writing",
"subtype": "Pwm8266",
"id": "pwm",
@@ -817,11 +830,11 @@
"freq": 5000,
"val": 0,
"apin": -1,
"num": 53
"num": 54
},
{
"global": 0,
"name": "54. Телеграм-Лайт",
"name": "55. Телеграм-Лайт",
"type": "Writing",
"subtype": "TelegramLT",
"id": "tg",
@@ -830,14 +843,14 @@
"descr": "",
"token": "",
"chatID": "",
"num": 54
"num": 55
},
{
"header": "screens"
},
{
"global": 0,
"name": "55. LCD экран 2004",
"name": "56. LCD экран 2004",
"type": "Reading",
"subtype": "Lcd2004",
"id": "Lcd",
@@ -850,10 +863,10 @@
"id2show": "",
"prefix": "",
"postfix": "",
"num": 55
"num": 56
},
{
"name": "56. LCD экран 1602",
"name": "57. LCD экран 1602",
"type": "Reading",
"subtype": "Lcd2004",
"id": "Lcd",
@@ -866,11 +879,28 @@
"id2show": "",
"prefix": "",
"postfix": "",
"num": 56
"num": 57
},
{
"global": 0,
"name": "57. 7 сегментный дисплей TM16XX",
"name": "58. 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": "",
"num": 58
},
{
"global": 0,
"name": "59. 7 сегментный дисплей TM16XX",
"type": "Writing",
"subtype": "TM16XX",
"id": "tm",
@@ -886,6 +916,6 @@
"intensity": "5",
"on": "1",
"id2show": "",
"num": 57
"num": 59
}
]

View File

@@ -330,7 +330,7 @@
},
{
"path": "src/modules/exec/HttpGet",
"active": false
"active": true
},
{
"path": "src/modules/exec/IoTServo",
@@ -414,6 +414,10 @@
"path": "src/modules/display/Oled128",
"active": false
},
{
"path": "src/modules/display/Oled64",
"active": true
},
{
"path": "src/modules/display/Smi2_m",
"active": true

View File

@@ -480,6 +480,8 @@ lib_deps =
adafruit/Adafruit BusIO @ ^1.13.2
https://github.com/robotclass/RobotClass_LiquidCrystal_I2C
marcoschwartz/LiquidCrystal_I2C@^1.1.4
https://github.com/stblassitude/Adafruit_SSD1306_Wemos_OLED
https://github.com/adafruit/Adafruit-GFX-Library
https://github.com/maxint-rd/TM16xx
adafruit/Adafruit GFX Library @ ^1.11.5
adafruit/Adafruit BusIO @ ^1.13.2
@@ -512,6 +514,7 @@ build_src_filter =
+<modules/exec/ButtonOut>
+<modules/exec/Buzzer>
+<modules/exec/Enconder>
+<modules/exec/HttpGet>
+<modules/exec/IoTServo>
+<modules/exec/Mcp23017>
+<modules/exec/Mp3>
@@ -520,6 +523,7 @@ build_src_filter =
+<modules/exec/Pwm8266>
+<modules/exec/TelegramLT>
+<modules/display/Lcd2004>
+<modules/display/Oled64>
+<modules/display/TM16XX>
[env:esp32_4mb_fromitems]
@@ -541,12 +545,16 @@ lib_deps =
adafruit/Adafruit BusIO @ ^1.13.2
https://github.com/robotclass/RobotClass_LiquidCrystal_I2C
marcoschwartz/LiquidCrystal_I2C@^1.1.4
https://github.com/stblassitude/Adafruit_SSD1306_Wemos_OLED
https://github.com/adafruit/Adafruit-GFX-Library
https://github.com/maxint-rd/TM16xx
adafruit/Adafruit GFX Library @ ^1.11.5
adafruit/Adafruit BusIO @ ^1.13.2
build_src_filter =
+<modules/virtual/Cron>
+<modules/virtual/Loging>
+<modules/virtual/LogingDaily>
+<modules/virtual/owmWeather>
+<modules/virtual/Timer>
+<modules/virtual/Variable>
+<modules/virtual/VariableColor>
@@ -578,6 +586,7 @@ build_src_filter =
+<modules/exec/Pwm32>
+<modules/exec/TelegramLT>
+<modules/display/Lcd2004>
+<modules/display/Oled648266/Oled648266>
+<modules/display/Smi2_m>
+<modules/display/TM16XX>

View File

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

View File

@@ -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> &param) {
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 {

View 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> &param) {
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;
}
}

View 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"
]
}
}