mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-30 11:59:12 +03:00
SSD1306_128x64
This commit is contained in:
@@ -1,20 +1,15 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
#include "classes/IoTItem.h"
|
#include "classes/IoTItem.h"
|
||||||
|
|
||||||
#include <map>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include <GyverOLED.h>
|
#include <GyverOLED.h>
|
||||||
//GyverOLED<SSD1306_128x32, OLED_BUFFER> oled;
|
|
||||||
//GyverOLED<SSD1306_128x32, OLED_NO_BUFFER> oled;
|
|
||||||
//GyverOLED<SSD1306_128x64, OLED_BUFFER> oled;
|
|
||||||
//GyverOLED<SSD1306_128x64, OLED_NO_BUFFER> oled;
|
|
||||||
//GyverOLED<SSD1306_128x64, OLED_BUFFER, OLED_SPI, 8, 7, 6> oled;
|
|
||||||
GyverOLED<SSH1106_128x64> oled;
|
|
||||||
|
|
||||||
|
GyverOLED<SSD1306_128x64, OLED_BUFFER> oled;
|
||||||
|
|
||||||
|
// GyverOLED<SSD1306_128x32, OLED_BUFFER> oled;
|
||||||
|
// GyverOLED<SSD1306_128x32, OLED_NO_BUFFER> oled;
|
||||||
|
// GyverOLED<SSD1306_128x64, OLED_NO_BUFFER> oled;
|
||||||
|
// GyverOLED<SSD1306_128x64, OLED_BUFFER, OLED_SPI, 8, 7, 6> oled;
|
||||||
|
// GyverOLED<SSH1106_128x64> oled;
|
||||||
|
|
||||||
class Oled128 : public IoTItem {
|
class Oled128 : public IoTItem {
|
||||||
private:
|
private:
|
||||||
@@ -31,25 +26,19 @@ class Oled128 : public IoTItem {
|
|||||||
|
|
||||||
int _prevStrSize;
|
int _prevStrSize;
|
||||||
|
|
||||||
bool _isShow = true; // экран показывает
|
bool _isShow = true; // экран показывает
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Oled128(String parameters) : IoTItem(parameters) {
|
Oled128(String parameters) : IoTItem(parameters) {
|
||||||
|
String addr, size, xy, k;
|
||||||
String addr, size, xy, k ;
|
|
||||||
_prevStrSize = 0;
|
_prevStrSize = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
jsonRead(parameters, "addr", addr);
|
jsonRead(parameters, "addr", addr);
|
||||||
if (addr == "") {
|
if (addr == "") {
|
||||||
//scanI2C();
|
// scanI2C();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
jsonRead(parameters, "coord", xy);
|
jsonRead(parameters, "coord", xy);
|
||||||
_x = selectFromMarkerToMarker(xy, ",", 0).toInt();
|
_x = selectFromMarkerToMarker(xy, ",", 0).toInt();
|
||||||
_y = selectFromMarkerToMarker(xy, ",", 1).toInt();
|
_y = selectFromMarkerToMarker(xy, ",", 1).toInt();
|
||||||
@@ -57,92 +46,80 @@ class Oled128 : public IoTItem {
|
|||||||
jsonRead(parameters, "descr", _descr);
|
jsonRead(parameters, "descr", _descr);
|
||||||
jsonRead(parameters, "id2show", _id2show);
|
jsonRead(parameters, "id2show", _id2show);
|
||||||
jsonRead(parameters, "descr1", _descr1);
|
jsonRead(parameters, "descr1", _descr1);
|
||||||
//jsonRead(parameters, "scale", _k);
|
// jsonRead(parameters, "scale", _k);
|
||||||
jsonRead(parameters, "shrift", _shrift);
|
jsonRead(parameters, "shrift", _shrift);
|
||||||
|
|
||||||
// Wire.begin(2,0); // Инициализация шины I2C для модуля E01
|
// Wire.begin(2,0); // Инициализация шины I2C для модуля E01
|
||||||
|
|
||||||
oled.init(); // инициализация экрана
|
oled.init(); // инициализация экрана
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void doByInterval() {
|
void doByInterval() {
|
||||||
|
printBlankStr(_prevStrSize);
|
||||||
|
|
||||||
|
String tmpStr = "";
|
||||||
|
|
||||||
|
// if (_descr != "none") tmpStr = _descr + " " + getItemValue(_id2show);
|
||||||
|
if (_descr != "none")
|
||||||
|
tmpStr = _descr + " " + getItemValue(_id2show) + " " + _descr1;
|
||||||
|
else
|
||||||
|
tmpStr = getItemValue(_id2show);
|
||||||
|
|
||||||
printBlankStr(_prevStrSize);
|
// oled.setScale(2);
|
||||||
|
|
||||||
|
oled.setScale(_shrift);
|
||||||
|
|
||||||
String tmpStr = "";
|
oled.setCursorXY(_x, _y);
|
||||||
|
|
||||||
//if (_descr != "none") tmpStr = _descr + " " + getItemValue(_id2show);
|
oled.print(tmpStr);
|
||||||
if (_descr != "none") tmpStr = _descr + " " + getItemValue(_id2show) + " " + _descr1;
|
|
||||||
else tmpStr = getItemValue(_id2show);
|
|
||||||
|
|
||||||
//oled.setScale(2);
|
|
||||||
|
|
||||||
oled.setScale(_shrift);
|
|
||||||
|
|
||||||
oled.setCursorXY(_x, _y);
|
|
||||||
|
|
||||||
oled.print(tmpStr);
|
|
||||||
|
|
||||||
oled.update();
|
|
||||||
|
|
||||||
_prevStrSize = tmpStr.length();
|
|
||||||
|
|
||||||
|
oled.update();
|
||||||
|
|
||||||
|
_prevStrSize = tmpStr.length();
|
||||||
}
|
}
|
||||||
|
|
||||||
IoTValue execute(String command, std::vector<IoTValue> ¶m) { // будет возможным использовать, когда сценарии запустятся
|
IoTValue execute(String command, std::vector<IoTValue> ¶m) { // будет возможным использовать, когда сценарии запустятся
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (command == "scroll") {
|
if (command == "scroll") {
|
||||||
String tmpStr = "";
|
String tmpStr = "";
|
||||||
oled.clear();
|
oled.clear();
|
||||||
uint32_t tmr = millis();
|
uint32_t tmr = millis();
|
||||||
oled.autoPrintln(false);
|
oled.autoPrintln(false);
|
||||||
int val = 128;
|
int val = 128;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
//oled.clear(); // ЗАКОММЕНТИРУЙ, ЕСЛИ ВКЛЮЧЕН БУФЕР
|
// oled.clear(); // ЗАКОММЕНТИРУЙ, ЕСЛИ ВКЛЮЧЕН БУФЕР
|
||||||
//oled.setScale(2);
|
// oled.setScale(2);
|
||||||
|
|
||||||
oled.setScale(_shrift);
|
oled.setScale(_shrift);
|
||||||
|
|
||||||
oled.setCursor(val, _y);
|
oled.setCursor(val, _y);
|
||||||
|
|
||||||
|
oled.print(tmpStr);
|
||||||
oled.print(tmpStr);
|
|
||||||
oled.update();
|
oled.update();
|
||||||
val--;
|
val--;
|
||||||
if (millis() - tmr > 5000);// return;
|
if (millis() - tmr > 5000)
|
||||||
|
; // return;
|
||||||
|
|
||||||
|
_isShow = true;
|
||||||
_isShow = true;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (command == "stopscroll") {
|
else if (command == "stopscroll") {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
_isShow = true;
|
_isShow = true;
|
||||||
// display->backlight();
|
// display->backlight();
|
||||||
// else if (command == "noDisplay") {
|
// else if (command == "noDisplay") {
|
||||||
// display->noDisplay();
|
// display->noDisplay();
|
||||||
// _isShow = false;
|
// _isShow = false;
|
||||||
}
|
} else if (command == "display") {
|
||||||
else if (command == "display") {
|
// display.display();
|
||||||
// display.display();
|
|
||||||
_isShow = true;
|
_isShow = true;
|
||||||
} else if (command == "toggle") {
|
} else if (command == "toggle") {
|
||||||
if (_isShow) {
|
if (_isShow) {
|
||||||
// display->noDisplay();
|
// display->noDisplay();
|
||||||
_isShow = false;
|
_isShow = false;
|
||||||
} else {
|
} else {
|
||||||
// display.display();
|
// display.display();
|
||||||
_isShow = true;
|
_isShow = true;
|
||||||
}
|
}
|
||||||
} else if (command == "x") {
|
} else if (command == "x") {
|
||||||
@@ -169,24 +146,22 @@ class Oled128 : public IoTItem {
|
|||||||
|
|
||||||
doByInterval();
|
doByInterval();
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//печать пустой строки нужной длинны для затирания предыдущего значения на экране
|
// печать пустой строки нужной длинны для затирания предыдущего значения на экране
|
||||||
void printBlankStr(int strSize) {
|
void printBlankStr(int strSize) {
|
||||||
String tmpStr = "";
|
String tmpStr = "";
|
||||||
for (int i = 0; i < strSize; i++) tmpStr += " ";
|
for (int i = 0; i < strSize; i++) tmpStr += " ";
|
||||||
|
|
||||||
// oled.setScale(2);
|
// oled.setScale(2);
|
||||||
|
|
||||||
oled.setScale(_shrift);
|
oled.setScale(_shrift);
|
||||||
|
|
||||||
oled.setCursorXY(_x, _y);
|
oled.setCursorXY(_x, _y);
|
||||||
|
|
||||||
oled.print(tmpStr);
|
oled.print(tmpStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
~Oled128(){};
|
~Oled128(){};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user