Added the coment

This commit is contained in:
gein@sfedu.ru 2025-02-17 20:32:04 +03:00
parent a9a73f23ed
commit d0cf1c5d07

View File

@ -1,30 +1,41 @@
//----------------include libraries----------------//
#include <WiFi.h> #include <WiFi.h>
#include <WebServer.h> #include <WebServer.h>
#include <DMD32.h> #include <DMD32.h>
#include <fonts/Font_BOLD.h> #include <fonts/Font_BOLD.h>
#include <FS.h> #include <FS.h>
//-------------------------------------------------//
#define FONT Font_BOLD //----------------settings panel----------------//
#define DISPLAYS_ACROSS 1 #define FONT Font_BOLD //Default font
#define DISPLAYS_DOWN 1 #define DISPLAYS_ACROSS 1 //number of panels in width
#define DISPLAYS_DOWN 1 //number of panels in height
DMD dmd(DISPLAYS_ACROSS, DISPLAYS_DOWN); DMD dmd(DISPLAYS_ACROSS, DISPLAYS_DOWN);
bool panel = true; //----------------------------------------------//
const char* ssid = "SKBKIT"; //----------------settings local wifi----------------//
const char* password = "skbkit2024"; const char* ssid = "SKBKIT"; //edit for your local wifi
const char* password = "skbkit2024"; //edit for your local wifi
//---------------------------------------------------//
//----------------settings web server----------------//
WebServer server(80); WebServer server(80);
IPAddress staticIP(10, 131, 170, 4); IPAddress staticIP(10, 131, 170, 4); //edit for your local ip
IPAddress gateway(10, 131, 170, 1); IPAddress gateway(10, 131, 170, 1);
IPAddress subnet(255, 255, 255, 0); IPAddress subnet(255, 255, 255, 0);
//---------------------------------------------------//
String displayText = "Привет из СКБ \"КИТ\""; //----------------other variables----------------//
//String displayText = "Пизда с членом разлучились("; String displayText = "Привет из СКБ \"КИТ\""; //change the default label
hw_timer_t* timer = NULL; hw_timer_t* timer = NULL;
bool panel = true;
//-----------------------------------------------//
//---Search SPI panel---//
void IRAM_ATTR triggerScan() { void IRAM_ATTR triggerScan() {
dmd.scanDisplayBySPI(); dmd.scanDisplayBySPI();
} }
//----------------------//
void reader() {} void reader() {}
@ -32,29 +43,33 @@ void setup() {
Serial.begin(115200); Serial.begin(115200);
dmd.selectFont(Font_BOLD); dmd.selectFont(Font_BOLD);
WiFi.begin(ssid, password); WiFi.begin(ssid, password);
//WiFi.config(staticIP, gateway, subnet);
//---Configured WebServer---//
if (!WiFi.config(staticIP, gateway, subnet)) { if (!WiFi.config(staticIP, gateway, subnet)) {
Serial.println("Failed to configure Static IP"); Serial.println("Failed to configure Static IP");
} else { } else {
Serial.println("Static IP configured!"); Serial.println("Static IP configured!");
} }
//--------------------------//
//---Start file system---//
// if(!SPIFFS.begin()){ // if(!SPIFFS.begin()){
// Serial.print("An occurred ERROR"); // Serial.print("An occurred ERROR");
// log_e("OCCURRED ERROR"); // log_e("OCCURRED ERROR");
// return; // return;
// } // }
//-----------------------//
//---Start the WiFi---//
while (WiFi.status() != WL_CONNECTED) { while (WiFi.status() != WL_CONNECTED) {
delay(500); delay(500);
Serial.print("."); Serial.print(".");
} }
Serial.println("\nConnected to WiFi"); Serial.println("\nConnected to WiFi");
Serial.println(WiFi.localIP()); Serial.println(WiFi.localIP());
//--------------------//
// Обрабатываем GET запрос для главной страницы с формой //---Main page for edit text---//
server.on("/", HTTP_GET, []() { server.on("/", HTTP_GET, []() {
panel = true; panel = true;
server.send(200, "text/html", server.send(200, "text/html",
@ -70,7 +85,9 @@ void setup() {
"</body>" "</body>"
"</html>"); "</html>");
}); });
//-----------------------------//
//---Request to check the status of the panel---//
server.on("/api/led", HTTP_GET, [](){ server.on("/api/led", HTTP_GET, [](){
if(panel){ if(panel){
server.send(200, "application/json", "{\"state\": \"true\"}"); server.send(200, "application/json", "{\"state\": \"true\"}");
@ -78,7 +95,9 @@ void setup() {
server.send(200, "application/json", "{\"state\": \"false\"}"); server.send(200, "application/json", "{\"state\": \"false\"}");
}; };
}); });
//----------------------------------------------//
//---Request to change the status of the panel---//
server.on("/api/led", HTTP_POST, [](){ server.on("/api/led", HTTP_POST, [](){
String panelState = server.arg("plain"); String panelState = server.arg("plain");
Serial.println(panelState); Serial.println(panelState);
@ -94,45 +113,50 @@ void setup() {
} }
server.send(200, "text/html", ""); server.send(200, "text/html", "");
}); });
//-----------------------------------------------//
// Обрабатываем POST запрос для изменения текста //---A text modification request---//
server.on("/api/text", HTTP_POST, []() { server.on("/api/text", HTTP_POST, []() {
panel = true; panel = true;
if (server.hasArg("text")) { if (server.hasArg("text")) {
// Получаем текст с формы без преобразования в HTML-сущности
displayText = server.arg("text"); displayText = server.arg("text");
} }
// Отправляем ответ с правильной кодировкой UTF-8
server.send(200, "text/html; charset=UTF-8", server.send(200, "text/html; charset=UTF-8",
"<html><body><h2>Text set to:</h2><p>" + displayText + "</p></body></html>"); "<html><body><h2>Text set to:</h2><p>" + displayText + "</p></body></html>");
}); });
//---------------------------------//
server.begin(); server.begin();
//---Start the timer---//
uint8_t cpuClock = ESP.getCpuFreqMHz(); uint8_t cpuClock = ESP.getCpuFreqMHz();
timer = timerBegin(0, cpuClock, true); timer = timerBegin(0, cpuClock, true);
timerAttachInterrupt(timer, &triggerScan, true); timerAttachInterrupt(timer, &triggerScan, true);
timerAlarmWrite(timer, 300, true); timerAlarmWrite(timer, 300, true);
timerAlarmEnable(timer); timerAlarmEnable(timer);
//--------------------//
dmd.clearScreen(true); dmd.clearScreen(true); //Clearing the screen
} }
void loop() { void loop() {
server.handleClient(); // Обработка запросов от клиента server.handleClient(); //Processing requests from the client
// // Очистка экрана и вывод текста //---Screen cleaning and text output---//
// dmd.clearScreen(true); // dmd.clearScreen(true);
// dmd.drawMarquee(displayText.c_str(), displayText.length(), (32 * DISPLAYS_ACROSS) - 1, 0); // dmd.drawMarquee(displayText.c_str(), displayText.length(), (32 * DISPLAYS_ACROSS) - 1, 0);
//-------------------------------------//
// long start = millis(); // long start = millis();
// long timer = start; // long timer = start;
// boolean ret = false; // boolean ret = false;
//---Scrolling text---//
// while (!ret) { // while (!ret) {
// if ((timer + 30) < millis()) { // if ((timer + 30) < millis()) {
// ret = dmd.stepMarquee(-1, 0); // Прокрутка текста // ret = dmd.stepMarquee(-1, 0); // Прокрутка текста
// timer = millis(); // timer = millis();
// } // }
// } // }
//--------------------//
} }