mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-31 04:19:15 +03:00
@@ -10,21 +10,18 @@ static const char FILE_NOT_FOUND[] PROGMEM = "FileNotFound";
|
||||
// static bool fsOK;
|
||||
// const char* fsName = "LittleFS";
|
||||
|
||||
void standWebServerInit()
|
||||
{
|
||||
void standWebServerInit() {
|
||||
// Кэшировать файлы для быстрой работы
|
||||
HTTP.serveStatic("/bundle.js", FileFS, "/", "max-age=31536000"); // кеширование на 1 год
|
||||
HTTP.serveStatic("/bundle.css", FileFS, "/", "max-age=31536000"); // кеширование на 1 год
|
||||
HTTP.serveStatic("/bundle.js.gz", FileFS, "/", "max-age=31536000"); // кеширование на 1 год
|
||||
HTTP.serveStatic("/bundle.css.gz", FileFS, "/", "max-age=31536000"); // кеширование на 1 год
|
||||
HTTP.serveStatic("/favicon.png", FileFS, "/", "max-age=31536000"); // кеширование на 1 год
|
||||
HTTP.serveStatic("/build/bundle.js", FileFS, "/build/bundle.js.gz", "max-age=31536000"); // кеширование на 1 год
|
||||
HTTP.serveStatic("/build/bundle.css", FileFS, "/build/bundle.css.gz", "max-age=31536000"); // кеширование на 1 год
|
||||
HTTP.serveStatic("/favicon.ico", FileFS, "/favicon.ico", "max-age=31536000"); // кеширование на 1 год
|
||||
|
||||
// HTTP.on("/devicelist.json", HTTP_GET, []() {
|
||||
// HTTP.send(200, "application/json", devListHeapJson);
|
||||
// });
|
||||
HTTP.on("/settings.h.json", HTTP_GET, []() {
|
||||
HTTP.send(200, "application/json", settingsFlashJson);
|
||||
});
|
||||
// HTTP.on("/settings.h.json", HTTP_GET, []() {
|
||||
// HTTP.send(200, "application/json", settingsFlashJson);
|
||||
//});
|
||||
// HTTP.on("/settings.f.json", HTTP_GET, []() {
|
||||
// HTTP.send(200, "application/json", readFile(F("settings.json"), 20000));
|
||||
// });
|
||||
@@ -46,7 +43,6 @@ void standWebServerInit()
|
||||
// HTTP.send(200, "text/plain", "ok");
|
||||
// });
|
||||
|
||||
|
||||
HTTP.on("/set", HTTP_GET, []() {
|
||||
if (HTTP.hasArg(F("routerssid")) && WiFi.getMode() == WIFI_AP) {
|
||||
jsonWriteStr(settingsFlashJson, F("routerssid"), HTTP.arg(F("routerssid")));
|
||||
@@ -59,7 +55,6 @@ void standWebServerInit()
|
||||
syncSettingsFlashJson();
|
||||
HTTP.send(200, "text/plain", "ok");
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// Добавляем функцию Update для перезаписи прошивки по WiFi при 1М(256K FileFS) и выше
|
||||
@@ -101,29 +96,24 @@ void standWebServerInit()
|
||||
////////////////////////////////
|
||||
// Utils to return HTTP codes, and determine content-type
|
||||
|
||||
void replyOK()
|
||||
{
|
||||
void replyOK() {
|
||||
HTTP.send(200, FPSTR(TEXT_PLAIN), "");
|
||||
}
|
||||
|
||||
void replyOKWithMsg(String msg)
|
||||
{
|
||||
void replyOKWithMsg(String msg) {
|
||||
HTTP.send(200, FPSTR(TEXT_PLAIN), msg);
|
||||
}
|
||||
|
||||
void replyNotFound(String msg)
|
||||
{
|
||||
void replyNotFound(String msg) {
|
||||
HTTP.send(404, FPSTR(TEXT_PLAIN), msg);
|
||||
}
|
||||
|
||||
void replyBadRequest(String msg)
|
||||
{
|
||||
void replyBadRequest(String msg) {
|
||||
// DBG_OUTPUT_PORT.println(msg);
|
||||
HTTP.send(400, FPSTR(TEXT_PLAIN), msg + "\r\n");
|
||||
}
|
||||
|
||||
void replyServerError(String msg)
|
||||
{
|
||||
void replyServerError(String msg) {
|
||||
// DBG_OUTPUT_PORT.println(msg);
|
||||
HTTP.send(500, FPSTR(TEXT_PLAIN), msg + "\r\n");
|
||||
}
|
||||
@@ -131,8 +121,7 @@ void replyServerError(String msg)
|
||||
/*
|
||||
Return the FS type, status and size info
|
||||
*/
|
||||
void handleStatus()
|
||||
{
|
||||
void handleStatus() {
|
||||
// DBG_OUTPUT_PORT.println("handleStatus");
|
||||
String json;
|
||||
json.reserve(128);
|
||||
@@ -202,21 +191,16 @@ String getContentType(String filename) {
|
||||
/*
|
||||
Read the given file from the filesystem and stream it back to the client
|
||||
*/
|
||||
bool handleFileRead(String path)
|
||||
{
|
||||
bool handleFileRead(String path) {
|
||||
// DBG_OUTPUT_PORT.println(String("handleFileRead: ") + path);
|
||||
if (path.endsWith("/"))
|
||||
{
|
||||
if (path.endsWith("/")) {
|
||||
path += "index.html";
|
||||
}
|
||||
|
||||
String contentType;
|
||||
if (HTTP.hasArg("download"))
|
||||
{
|
||||
if (HTTP.hasArg("download")) {
|
||||
contentType = F("application/octet-stream");
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
#ifdef ESP32
|
||||
contentType = getContentType(path);
|
||||
#endif
|
||||
@@ -225,16 +209,13 @@ bool handleFileRead(String path)
|
||||
#endif
|
||||
}
|
||||
|
||||
if (!FileFS.exists(path))
|
||||
{
|
||||
if (!FileFS.exists(path)) {
|
||||
// File not found, try gzip version
|
||||
path = path + ".gz";
|
||||
}
|
||||
if (FileFS.exists(path))
|
||||
{
|
||||
if (FileFS.exists(path)) {
|
||||
File file = FileFS.open(path, "r");
|
||||
if (HTTP.streamFile(file, contentType) != file.size())
|
||||
{
|
||||
if (HTTP.streamFile(file, contentType) != file.size()) {
|
||||
// DBG_OUTPUT_PORT.println("Sent less data than expected!");
|
||||
}
|
||||
file.close();
|
||||
@@ -248,16 +229,11 @@ bool handleFileRead(String path)
|
||||
As some FS (e.g. LittleFS) delete the parent folder when the last child has been removed,
|
||||
return the path of the closest parent still existing
|
||||
*/
|
||||
String lastExistingParent(String path)
|
||||
{
|
||||
while (!path.isEmpty() && !FileFS.exists(path))
|
||||
{
|
||||
if (path.lastIndexOf('/') > 0)
|
||||
{
|
||||
String lastExistingParent(String path) {
|
||||
while (!path.isEmpty() && !FileFS.exists(path)) {
|
||||
if (path.lastIndexOf('/') > 0) {
|
||||
path = path.substring(0, path.lastIndexOf('/'));
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
path = String(); // No slash => the top folder does not exist
|
||||
}
|
||||
}
|
||||
@@ -268,68 +244,52 @@ String lastExistingParent(String path)
|
||||
/*
|
||||
Handle a file upload request
|
||||
*/
|
||||
void handleFileUpload()
|
||||
{
|
||||
if (HTTP.uri() != "/edit")
|
||||
{
|
||||
void handleFileUpload() {
|
||||
if (HTTP.uri() != "/edit") {
|
||||
return;
|
||||
}
|
||||
HTTPUpload &upload = HTTP.upload();
|
||||
if (upload.status == UPLOAD_FILE_START)
|
||||
{
|
||||
if (upload.status == UPLOAD_FILE_START) {
|
||||
String filename = upload.filename;
|
||||
// Make sure paths always start with "/"
|
||||
if (!filename.startsWith("/"))
|
||||
{
|
||||
if (!filename.startsWith("/")) {
|
||||
filename = "/" + filename;
|
||||
}
|
||||
// DBG_OUTPUT_PORT.println(String("handleFileUpload Name: ") + filename);
|
||||
uploadFile = FileFS.open(filename, "w");
|
||||
if (!uploadFile)
|
||||
{
|
||||
if (!uploadFile) {
|
||||
return replyServerError(F("CREATE FAILED"));
|
||||
}
|
||||
// DBG_OUTPUT_PORT.println(String("Upload: START, filename: ") + filename);
|
||||
}
|
||||
else if (upload.status == UPLOAD_FILE_WRITE)
|
||||
{
|
||||
if (uploadFile)
|
||||
{
|
||||
} else if (upload.status == UPLOAD_FILE_WRITE) {
|
||||
if (uploadFile) {
|
||||
size_t bytesWritten = uploadFile.write(upload.buf, upload.currentSize);
|
||||
if (bytesWritten != upload.currentSize)
|
||||
{
|
||||
if (bytesWritten != upload.currentSize) {
|
||||
return replyServerError(F("WRITE FAILED"));
|
||||
}
|
||||
}
|
||||
// DBG_OUTPUT_PORT.println(String("Upload: WRITE, Bytes: ") + upload.currentSize);
|
||||
}
|
||||
else if (upload.status == UPLOAD_FILE_END)
|
||||
{
|
||||
if (uploadFile)
|
||||
{
|
||||
} else if (upload.status == UPLOAD_FILE_END) {
|
||||
if (uploadFile) {
|
||||
uploadFile.close();
|
||||
}
|
||||
// DBG_OUTPUT_PORT.println(String("Upload: END, Size: ") + upload.totalSize);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifdef ESP8266
|
||||
void deleteRecursive(String path)
|
||||
{
|
||||
void deleteRecursive(String path) {
|
||||
File file = FileFS.open(path, "r");
|
||||
bool isDir = file.isDirectory();
|
||||
file.close();
|
||||
|
||||
// If it's a plain file, delete it
|
||||
if (!isDir)
|
||||
{
|
||||
if (!isDir) {
|
||||
FileFS.remove(path);
|
||||
return;
|
||||
}
|
||||
Dir dir = FileFS.openDir(path);
|
||||
while (dir.next())
|
||||
{
|
||||
while (dir.next()) {
|
||||
deleteRecursive(path + '/' + dir.fileName());
|
||||
}
|
||||
|
||||
@@ -344,7 +304,6 @@ struct treename{
|
||||
char *name;
|
||||
};
|
||||
|
||||
|
||||
void deleteRecursive(String path) {
|
||||
fs::File dir = FileFS.open(path);
|
||||
|
||||
@@ -360,7 +319,6 @@ void deleteRecursive( String path ){
|
||||
fs::File entry, nextentry;
|
||||
|
||||
while (entry = dir.openNextFile()) {
|
||||
|
||||
if (entry.isDirectory()) {
|
||||
deleteRecursive(entry.path());
|
||||
} else {
|
||||
@@ -368,12 +326,10 @@ if ( entry.isDirectory() ){
|
||||
entry.close();
|
||||
Serial.printf("result of removing file %s: %d\n", tmpname, FileFS.remove(tmpname));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
dir.close();
|
||||
Serial.printf("result of removing directory %s: %d\n", path, FileFS.rmdir(path));
|
||||
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
@@ -383,23 +339,18 @@ if ( entry.isDirectory() ){
|
||||
Delete file | parent of deleted file, or remaining ancestor
|
||||
Delete folder | parent of deleted folder, or remaining ancestor
|
||||
*/
|
||||
void handleFileDelete()
|
||||
{
|
||||
void handleFileDelete() {
|
||||
String path = HTTP.arg(0);
|
||||
if (path.isEmpty() || path == "/")
|
||||
{
|
||||
if (path.isEmpty() || path == "/") {
|
||||
return replyBadRequest("BAD PATH");
|
||||
}
|
||||
|
||||
// DBG_OUTPUT_PORT.println(String("handleFileDelete: ") + path);
|
||||
if (!FileFS.exists(path))
|
||||
{
|
||||
if (!FileFS.exists(path)) {
|
||||
return replyNotFound(FPSTR(FILE_NOT_FOUND));
|
||||
}
|
||||
deleteRecursive(path);
|
||||
|
||||
|
||||
|
||||
replyOKWithMsg(lastExistingParent(path));
|
||||
}
|
||||
|
||||
@@ -414,50 +365,39 @@ void handleFileDelete()
|
||||
Rename folder | parent of source folder
|
||||
Move folder | parent of source folder, or remaining ancestor
|
||||
*/
|
||||
void handleFileCreate()
|
||||
{
|
||||
void handleFileCreate() {
|
||||
String path = HTTP.arg("path");
|
||||
if (path.isEmpty())
|
||||
{
|
||||
if (path.isEmpty()) {
|
||||
return replyBadRequest(F("PATH ARG MISSING"));
|
||||
}
|
||||
|
||||
#ifdef USE_SPIFFS
|
||||
if (checkForUnsupportedPath(path).length() > 0)
|
||||
{
|
||||
if (checkForUnsupportedPath(path).length() > 0) {
|
||||
return replyServerError(F("INVALID FILENAME"));
|
||||
}
|
||||
#endif
|
||||
|
||||
if (path == "/")
|
||||
{
|
||||
if (path == "/") {
|
||||
return replyBadRequest("BAD PATH");
|
||||
}
|
||||
if (FileFS.exists(path))
|
||||
{
|
||||
if (FileFS.exists(path)) {
|
||||
return replyBadRequest(F("PATH FILE EXISTS"));
|
||||
}
|
||||
|
||||
String src = HTTP.arg("src");
|
||||
if (src.isEmpty())
|
||||
{
|
||||
if (src.isEmpty()) {
|
||||
// No source specified: creation
|
||||
// DBG_OUTPUT_PORT.println(String("handleFileCreate: ") + path);
|
||||
if (path.endsWith("/"))
|
||||
{
|
||||
if (path.endsWith("/")) {
|
||||
// Create a folder
|
||||
path.remove(path.length() - 1);
|
||||
if (!FileFS.mkdir(path))
|
||||
{
|
||||
if (!FileFS.mkdir(path)) {
|
||||
return replyServerError(F("MKDIR FAILED"));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// Create a file
|
||||
File file = FileFS.open(path, "w");
|
||||
if (file)
|
||||
{
|
||||
if (file) {
|
||||
#ifdef ESP8266
|
||||
file.write((const char *)0);
|
||||
#endif
|
||||
@@ -465,42 +405,32 @@ void handleFileCreate()
|
||||
file.write(0);
|
||||
#endif
|
||||
file.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return replyServerError(F("CREATE FAILED"));
|
||||
}
|
||||
}
|
||||
if (path.lastIndexOf('/') > -1)
|
||||
{
|
||||
if (path.lastIndexOf('/') > -1) {
|
||||
path = path.substring(0, path.lastIndexOf('/'));
|
||||
}
|
||||
replyOKWithMsg(path);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// Source specified: rename
|
||||
if (src == "/")
|
||||
{
|
||||
if (src == "/") {
|
||||
return replyBadRequest("BAD SRC");
|
||||
}
|
||||
if (!FileFS.exists(src))
|
||||
{
|
||||
if (!FileFS.exists(src)) {
|
||||
return replyBadRequest(F("SRC FILE NOT FOUND"));
|
||||
}
|
||||
|
||||
// DBG_OUTPUT_PORT.println(String("handleFileCreate: ") + path + " from " + src);
|
||||
|
||||
if (path.endsWith("/"))
|
||||
{
|
||||
if (path.endsWith("/")) {
|
||||
path.remove(path.length() - 1);
|
||||
}
|
||||
if (src.endsWith("/"))
|
||||
{
|
||||
if (src.endsWith("/")) {
|
||||
src.remove(src.length() - 1);
|
||||
}
|
||||
if (!FileFS.rename(src, path))
|
||||
{
|
||||
if (!FileFS.rename(src, path)) {
|
||||
return replyServerError(F("RENAME FAILED"));
|
||||
}
|
||||
replyOKWithMsg(lastExistingParent(src));
|
||||
@@ -512,16 +442,13 @@ void handleFileCreate()
|
||||
Also demonstrates the use of chunked responses.
|
||||
*/
|
||||
#ifdef ESP8266
|
||||
void handleFileList()
|
||||
{
|
||||
if (!HTTP.hasArg("dir"))
|
||||
{
|
||||
void handleFileList() {
|
||||
if (!HTTP.hasArg("dir")) {
|
||||
return replyBadRequest(F("DIR ARG MISSING"));
|
||||
}
|
||||
|
||||
String path = HTTP.arg("dir");
|
||||
if (path != "/" && !FileFS.exists(path))
|
||||
{
|
||||
if (path != "/" && !FileFS.exists(path)) {
|
||||
return replyBadRequest("BAD PATH");
|
||||
}
|
||||
|
||||
@@ -530,8 +457,7 @@ void handleFileList()
|
||||
path.clear();
|
||||
|
||||
// use HTTP/1.1 Chunked response to avoid building a huge temporary string
|
||||
if (!HTTP.chunkedResponseModeStart(200, "text/json"))
|
||||
{
|
||||
if (!HTTP.chunkedResponseModeStart(200, "text/json")) {
|
||||
HTTP.send(505, F("text/html"), F("HTTP1.1 required"));
|
||||
return;
|
||||
}
|
||||
@@ -539,47 +465,36 @@ void handleFileList()
|
||||
// use the same string for every line
|
||||
String output;
|
||||
output.reserve(64);
|
||||
while (dir.next())
|
||||
{
|
||||
while (dir.next()) {
|
||||
#ifdef USE_SPIFFS
|
||||
String error = checkForUnsupportedPath(dir.fileName());
|
||||
if (error.length() > 0)
|
||||
{
|
||||
if (error.length() > 0) {
|
||||
// DBG_OUTPUT_PORT.println(String("Ignoring ") + error + dir.fileName());
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
if (output.length())
|
||||
{
|
||||
if (output.length()) {
|
||||
// send string from previous iteration
|
||||
// as an HTTP chunk
|
||||
HTTP.sendContent(output);
|
||||
output = ',';
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
output = '[';
|
||||
}
|
||||
|
||||
output += "{\"type\":\"";
|
||||
if (dir.isDirectory())
|
||||
{
|
||||
if (dir.isDirectory()) {
|
||||
output += "dir";
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
output += F("file\",\"size\":\"");
|
||||
output += dir.fileSize();
|
||||
}
|
||||
|
||||
output += F("\",\"name\":\"");
|
||||
// Always return names without leading "/"
|
||||
if (dir.fileName()[0] == '/')
|
||||
{
|
||||
if (dir.fileName()[0] == '/') {
|
||||
output += &(dir.fileName()[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
output += dir.fileName();
|
||||
}
|
||||
|
||||
@@ -603,7 +518,6 @@ void handleFileList() {
|
||||
String path = HTTP.arg("dir");
|
||||
// DBG_OUTPUT_PORT.println("handleFileList: " + path);
|
||||
|
||||
|
||||
File root = FileFS.open(path);
|
||||
path = String();
|
||||
|
||||
@@ -616,12 +530,9 @@ void handleFileList() {
|
||||
}
|
||||
output += "{\"type\":\"";
|
||||
// output += (file.isDirectory()) ? "dir" : "file";
|
||||
if (file.isDirectory())
|
||||
{
|
||||
if (file.isDirectory()) {
|
||||
output += "dir";
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
output += F("file\",\"size\":\"");
|
||||
output += file.size();
|
||||
}
|
||||
@@ -634,26 +545,22 @@ void handleFileList() {
|
||||
}
|
||||
output += "]";
|
||||
HTTP.send(200, "text/json", output);
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
The "Not Found" handler catches all URI not explicitly declared in code
|
||||
First try to find and return the requested file from the filesystem,
|
||||
and if it fails, return a 404 page with debug information
|
||||
*/
|
||||
void handleNotFound()
|
||||
{
|
||||
void handleNotFound() {
|
||||
#ifdef ESP8266
|
||||
String uri = ESP8266WebServer::urlDecode(HTTP.uri()); // required to read paths with blanks
|
||||
#endif
|
||||
#ifdef ESP32
|
||||
String uri = WebServer::urlDecode(HTTP.uri()); // required to read paths with blanks
|
||||
#endif
|
||||
if (handleFileRead(uri))
|
||||
{
|
||||
if (handleFileRead(uri)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -667,8 +574,7 @@ void handleNotFound()
|
||||
message += F("\nArguments: ");
|
||||
message += HTTP.args();
|
||||
message += '\n';
|
||||
for (uint8_t i = 0; i < HTTP.args(); i++)
|
||||
{
|
||||
for (uint8_t i = 0; i < HTTP.args(); i++) {
|
||||
message += F(" NAME:");
|
||||
message += HTTP.argName(i);
|
||||
message += F("\n VALUE:");
|
||||
@@ -689,10 +595,8 @@ void handleNotFound()
|
||||
embedded in the program code.
|
||||
Otherwise, fails with a 404 page with debug information
|
||||
*/
|
||||
void handleGetEdit()
|
||||
{
|
||||
if (handleFileRead(F("/edit.htm")))
|
||||
{
|
||||
void handleGetEdit() {
|
||||
if (handleFileRead(F("/edit.htm"))) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,20 +1,15 @@
|
||||
|
||||
|
||||
#include "Global.h"
|
||||
#include "classes/IoTItem.h"
|
||||
|
||||
#include <map>
|
||||
|
||||
|
||||
|
||||
#include <GyverOLED.h>
|
||||
|
||||
GyverOLED<SSD1306_128x64, OLED_BUFFER> oled;
|
||||
|
||||
// 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<SSH1106_128x64> oled;
|
||||
|
||||
class Oled128 : public IoTItem {
|
||||
private:
|
||||
@@ -33,23 +28,17 @@ class Oled128 : public IoTItem {
|
||||
|
||||
bool _isShow = true; // экран показывает
|
||||
|
||||
|
||||
|
||||
public:
|
||||
Oled128(String parameters) : IoTItem(parameters) {
|
||||
|
||||
String addr, size, xy, k;
|
||||
_prevStrSize = 0;
|
||||
|
||||
|
||||
|
||||
jsonRead(parameters, "addr", addr);
|
||||
if (addr == "") {
|
||||
// scanI2C();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
jsonRead(parameters, "coord", xy);
|
||||
_x = selectFromMarkerToMarker(xy, ",", 0).toInt();
|
||||
_y = selectFromMarkerToMarker(xy, ",", 1).toInt();
|
||||
@@ -63,21 +52,18 @@ class Oled128 : public IoTItem {
|
||||
// Wire.begin(2,0); // Инициализация шины I2C для модуля E01
|
||||
|
||||
oled.init(); // инициализация экрана
|
||||
|
||||
}
|
||||
|
||||
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);
|
||||
if (_descr != "none")
|
||||
tmpStr = _descr + " " + getItemValue(_id2show) + " " + _descr1;
|
||||
else
|
||||
tmpStr = getItemValue(_id2show);
|
||||
|
||||
// oled.setScale(2);
|
||||
|
||||
@@ -90,14 +76,10 @@ class Oled128 : public IoTItem {
|
||||
oled.update();
|
||||
|
||||
_prevStrSize = tmpStr.length();
|
||||
|
||||
|
||||
}
|
||||
|
||||
IoTValue execute(String command, std::vector<IoTValue> ¶m) { // будет возможным использовать, когда сценарии запустятся
|
||||
|
||||
|
||||
|
||||
if (command == "scroll") {
|
||||
String tmpStr = "";
|
||||
oled.clear();
|
||||
@@ -112,12 +94,11 @@ class Oled128 : public IoTItem {
|
||||
|
||||
oled.setCursor(val, _y);
|
||||
|
||||
|
||||
oled.print(tmpStr);
|
||||
oled.update();
|
||||
val--;
|
||||
if (millis() - tmr > 5000);// return;
|
||||
|
||||
if (millis() - tmr > 5000)
|
||||
; // return;
|
||||
|
||||
_isShow = true;
|
||||
}
|
||||
@@ -125,16 +106,12 @@ class Oled128 : public IoTItem {
|
||||
}
|
||||
|
||||
else if (command == "stopscroll") {
|
||||
|
||||
|
||||
|
||||
_isShow = true;
|
||||
// display->backlight();
|
||||
// else if (command == "noDisplay") {
|
||||
// display->noDisplay();
|
||||
// _isShow = false;
|
||||
}
|
||||
else if (command == "display") {
|
||||
} else if (command == "display") {
|
||||
// display.display();
|
||||
_isShow = true;
|
||||
} else if (command == "toggle") {
|
||||
@@ -169,7 +146,6 @@ class Oled128 : public IoTItem {
|
||||
|
||||
doByInterval();
|
||||
return {};
|
||||
|
||||
}
|
||||
|
||||
// печать пустой строки нужной длинны для затирания предыдущего значения на экране
|
||||
@@ -186,7 +162,6 @@ class Oled128 : public IoTItem {
|
||||
oled.print(tmpStr);
|
||||
}
|
||||
|
||||
|
||||
~Oled128(){};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user