add main menu
This commit is contained in:
parent
00dcbe6afe
commit
5a07913067
@ -4,6 +4,7 @@
|
||||
#include <Adafruit_SSD1306.h>
|
||||
#include "body.h"
|
||||
#include "../../../config.h"
|
||||
#include "../../../server/web_server.h"
|
||||
|
||||
// ===== OLED CONFIG =====
|
||||
// ESP32 ESP-WROOM-32D с OLED 0.96" (SSD1306)
|
||||
@ -24,6 +25,10 @@ static int currentStage = 0;
|
||||
static int totalStages = 5;
|
||||
static bool systemReady = false;
|
||||
|
||||
// Display update tracking
|
||||
static unsigned long lastDisplayUpdate = 0;
|
||||
static const unsigned long DISPLAY_UPDATE_INTERVAL = 500; // ms
|
||||
|
||||
static void drawHeader() {
|
||||
// Заголовок (инверсия)
|
||||
display.fillRect(0, 0, SCREEN_WIDTH, 16, SSD1306_WHITE);
|
||||
@ -231,3 +236,41 @@ void oledShowCalibration() {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -20,3 +20,7 @@ void oledShowMain(const char* line1, const char* line2, const char* line3, const
|
||||
// состояние системы
|
||||
void oledSetSystemReady(bool ready);
|
||||
bool oledIsSystemReady();
|
||||
|
||||
// меню
|
||||
void oledDrawMainMenu(const char* ip, const char* mode);
|
||||
void oledUpdateDisplay();
|
||||
|
||||
@ -78,4 +78,7 @@ void loop() {
|
||||
joyUpdate();
|
||||
controllerUpdate();
|
||||
// irPoll();
|
||||
|
||||
// Обновляем дисплей с IP и режимом
|
||||
oledUpdateDisplay();
|
||||
}
|
||||
|
||||
@ -10,6 +10,10 @@
|
||||
|
||||
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_DELAY_MS 800
|
||||
|
||||
@ -68,7 +72,8 @@ void handleMode() {
|
||||
return;
|
||||
}
|
||||
|
||||
oledShowMode(modeToStr(robot.mode));
|
||||
snprintf(modeStr, sizeof(modeStr), "%s", modeToStr(robot.mode));
|
||||
// oledShowMode(modeStr);
|
||||
// lcdShowText("SERVICE MODE", "Waiting...");
|
||||
server.send(200, "text/plain",
|
||||
String("OK MODE=") + modeToStr(robot.mode));
|
||||
@ -139,8 +144,8 @@ bool webServerInit() {
|
||||
|
||||
if (WiFi.status() == WL_CONNECTED) {
|
||||
// Показываем успешное подключение
|
||||
String ipStr = "IP: " + WiFi.localIP().toString();
|
||||
oledShowText("WiFi: CONNECTED", ipStr.c_str());
|
||||
snprintf(ipStr, sizeof(ipStr), "%s", WiFi.localIP().toString().c_str());
|
||||
oledShowText("WiFi: CONNECTED", ipStr);
|
||||
Serial.print("\nConnected. IP: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
|
||||
@ -163,3 +168,11 @@ bool webServerInit() {
|
||||
void webServerLoop() {
|
||||
server.handleClient();
|
||||
}
|
||||
|
||||
const char* webServerGetIP() {
|
||||
return ipStr;
|
||||
}
|
||||
|
||||
const char* webServerGetMode() {
|
||||
return modeStr;
|
||||
}
|
||||
|
||||
@ -1,3 +1,7 @@
|
||||
#pragma once
|
||||
bool webServerInit();
|
||||
void webServerLoop();
|
||||
|
||||
// Getters for display
|
||||
const char* webServerGetIP();
|
||||
const char* webServerGetMode();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user