add main menu

This commit is contained in:
cheykrym 2026-03-30 05:07:12 +03:00
parent 00dcbe6afe
commit 5a07913067
5 changed files with 70 additions and 3 deletions

View File

@ -4,6 +4,7 @@
#include <Adafruit_SSD1306.h> #include <Adafruit_SSD1306.h>
#include "body.h" #include "body.h"
#include "../../../config.h" #include "../../../config.h"
#include "../../../server/web_server.h"
// ===== OLED CONFIG ===== // ===== OLED CONFIG =====
// ESP32 ESP-WROOM-32D с OLED 0.96" (SSD1306) // ESP32 ESP-WROOM-32D с OLED 0.96" (SSD1306)
@ -24,6 +25,10 @@ static int currentStage = 0;
static int totalStages = 5; static int totalStages = 5;
static bool systemReady = false; static bool systemReady = false;
// Display update tracking
static unsigned long lastDisplayUpdate = 0;
static const unsigned long DISPLAY_UPDATE_INTERVAL = 500; // ms
static void drawHeader() { static void drawHeader() {
// Заголовок (инверсия) // Заголовок (инверсия)
display.fillRect(0, 0, SCREEN_WIDTH, 16, SSD1306_WHITE); display.fillRect(0, 0, SCREEN_WIDTH, 16, SSD1306_WHITE);
@ -231,3 +236,41 @@ void oledShowCalibration() {
display.display(); display.display();
} }
void oledDrawMainMenu(const char* ip, const char* mode) {
display.clearDisplay();
// Заголовок
drawHeader();
// Основной контент
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 20);
display.setTextSize(1);
// Строка 1: IP адрес
display.print("IP: ");
display.println(ip ? ip : "N/A");
// Строка 2: Режим
display.print("Mode: ");
display.println(mode ? mode : "IDLE");
// Подвал
drawFooter();
display.display();
}
void oledUpdateDisplay() {
if (!systemReady) return;
unsigned long now = millis();
if (now - lastDisplayUpdate >= DISPLAY_UPDATE_INTERVAL) {
lastDisplayUpdate = now;
const char* ip = webServerGetIP();
const char* mode = webServerGetMode();
oledDrawMainMenu(ip, mode);
}
}

View File

@ -20,3 +20,7 @@ void oledShowMain(const char* line1, const char* line2, const char* line3, const
// состояние системы // состояние системы
void oledSetSystemReady(bool ready); void oledSetSystemReady(bool ready);
bool oledIsSystemReady(); bool oledIsSystemReady();
// меню
void oledDrawMainMenu(const char* ip, const char* mode);
void oledUpdateDisplay();

View File

@ -78,4 +78,7 @@ void loop() {
joyUpdate(); joyUpdate();
controllerUpdate(); controllerUpdate();
// irPoll(); // irPoll();
// Обновляем дисплей с IP и режимом
oledUpdateDisplay();
} }

View File

@ -10,6 +10,10 @@
static WebServer server(80); static WebServer server(80);
// Static buffers for getters
static char ipStr[16] = "No IP";
static char modeStr[16] = "IDLE";
#define WIFI_RETRY_MAX 5 #define WIFI_RETRY_MAX 5
#define WIFI_RETRY_DELAY_MS 800 #define WIFI_RETRY_DELAY_MS 800
@ -68,7 +72,8 @@ void handleMode() {
return; return;
} }
oledShowMode(modeToStr(robot.mode)); snprintf(modeStr, sizeof(modeStr), "%s", modeToStr(robot.mode));
// oledShowMode(modeStr);
// lcdShowText("SERVICE MODE", "Waiting..."); // lcdShowText("SERVICE MODE", "Waiting...");
server.send(200, "text/plain", server.send(200, "text/plain",
String("OK MODE=") + modeToStr(robot.mode)); String("OK MODE=") + modeToStr(robot.mode));
@ -139,8 +144,8 @@ bool webServerInit() {
if (WiFi.status() == WL_CONNECTED) { if (WiFi.status() == WL_CONNECTED) {
// Показываем успешное подключение // Показываем успешное подключение
String ipStr = "IP: " + WiFi.localIP().toString(); snprintf(ipStr, sizeof(ipStr), "%s", WiFi.localIP().toString().c_str());
oledShowText("WiFi: CONNECTED", ipStr.c_str()); oledShowText("WiFi: CONNECTED", ipStr);
Serial.print("\nConnected. IP: "); Serial.print("\nConnected. IP: ");
Serial.println(WiFi.localIP()); Serial.println(WiFi.localIP());
@ -163,3 +168,11 @@ bool webServerInit() {
void webServerLoop() { void webServerLoop() {
server.handleClient(); server.handleClient();
} }
const char* webServerGetIP() {
return ipStr;
}
const char* webServerGetMode() {
return modeStr;
}

View File

@ -1,3 +1,7 @@
#pragma once #pragma once
bool webServerInit(); bool webServerInit();
void webServerLoop(); void webServerLoop();
// Getters for display
const char* webServerGetIP();
const char* webServerGetMode();