From 57c07b07db54dcaf6a78ff66393926ba1cda7940 Mon Sep 17 00:00:00 2001 From: cheykrym Date: Mon, 30 Mar 2026 03:30:06 +0300 Subject: [PATCH] add init joy --- src/core/display/body/body.cpp | 19 +------------------ src/core/display/body/body.h | 3 --- src/core/joystick/joystick.cpp | 14 ++++++++++++-- src/core/joystick/joystick.h | 2 +- src/main.cpp | 32 ++++++++++++++++---------------- 5 files changed, 30 insertions(+), 40 deletions(-) diff --git a/src/core/display/body/body.cpp b/src/core/display/body/body.cpp index 2915dd8..adbd90d 100644 --- a/src/core/display/body/body.cpp +++ b/src/core/display/body/body.cpp @@ -4,7 +4,6 @@ #include #include "body.h" #include "../../../config.h" -#include "../../joystick/joystick.h" // ===== OLED CONFIG ===== // ESP32 ESP-WROOM-32D с OLED 0.96" (SSD1306) @@ -96,26 +95,10 @@ void oledShowMain(const char* line1, const char* line2, const char* line3, const // Подвал drawFooter(); - + display.display(); } -// ===== Device Checks ===== - -bool oledCheckJoystick() { - // Проверяем наличие джойстика по значениям ADC - int x = analogRead(JOY_X_PIN); - int y = analogRead(JOY_Y_PIN); - - // Если значения в разумных пределах (не 0 и не 4095) - джойстик подключен - bool connected = (x > 100 && x < 4000) && (y > 100 && y < 4000); - - Serial.printf("[CHECK] Joystick: %s (X=%d, Y=%d)\n", - connected ? "OK" : "NOT FOUND", x, y); - - return connected; -} - void oledInit() { Wire.begin(SDA_PIN, SCL_PIN); diff --git a/src/core/display/body/body.h b/src/core/display/body/body.h index 124c2f0..fc08320 100644 --- a/src/core/display/body/body.h +++ b/src/core/display/body/body.h @@ -20,6 +20,3 @@ void oledShowMain(const char* line1, const char* line2, const char* line3, const // состояние системы void oledSetSystemReady(bool ready); bool oledIsSystemReady(); - -// проверка устройств -bool oledCheckJoystick(); diff --git a/src/core/joystick/joystick.cpp b/src/core/joystick/joystick.cpp index b85f626..e300abd 100644 --- a/src/core/joystick/joystick.cpp +++ b/src/core/joystick/joystick.cpp @@ -26,19 +26,29 @@ static int lastLoggedXNorm = 0; static int lastLoggedYNorm = 0; static bool lastLoggedSw = false; -void joyInit() { +bool joyInit() { pinMode(JOY_SW_PIN, INPUT_PULLUP); // ADC1 каналы (пины 34, 35) analogReadResolution(12); // 12 бит (0-4095) analogSetAttenuation(ADC_11db); // 0-3.3V + // Проверяем наличие джойстика + int x = analogRead(JOY_X_PIN); + int y = analogRead(JOY_Y_PIN); + + // Если значения в разумных пределах - джойстик подключен + bool connected = (x > 100 && x < 4000) && (y > 100 && y < 4000); + Serial.println("Joystick initialized"); Serial.printf(" VRX → GPIO%d (ADC1_CH6)\n", JOY_X_PIN); Serial.printf(" VRY → GPIO%d (ADC1_CH7)\n", JOY_Y_PIN); Serial.printf(" SW → GPIO%d\n", JOY_SW_PIN); Serial.printf(" Center: X=%d, Y=%d\n", ADC_CENTER_X, ADC_CENTER_Y); - Serial.println(" Move stick to calibrate if needed"); + Serial.printf(" Status: %s (X=%d, Y=%d)\n", + connected ? "OK" : "NOT FOUND", x, y); + + return connected; } void joyUpdate() { diff --git a/src/core/joystick/joystick.h b/src/core/joystick/joystick.h index 5cb1795..df325f1 100644 --- a/src/core/joystick/joystick.h +++ b/src/core/joystick/joystick.h @@ -1,6 +1,6 @@ #pragma once -void joyInit(); +bool joyInit(); void joyUpdate(); // возвращает значения 0-4095 diff --git a/src/main.cpp b/src/main.cpp index bda3a67..0a3b451 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -14,29 +14,30 @@ // #include "core/deprecate/ir_input/ir_input.h" #define TOTAL_STAGES 5 +#define DELAY_FOR_STARTUP_CHECKS 1000 void runStartupChecks() { + delay(DELAY_FOR_STARTUP_CHECKS); + // Этап 1: Проверка джойстика oledSetStage(1, TOTAL_STAGES); - bool joyOk = oledCheckJoystick(); - oledShowMain(joyOk ? "Joystick: OK" : "Joystick: NOT FOUND", "IR: NOT FOUND", - "", - ""); - delay(500); - + bool joyOk = joyInit(); + oledShowMain(joyOk ? "Joystick: OK" : "Joystick: NOT FOUND", "IR: NOT FOUND", "", ""); + delay(DELAY_FOR_STARTUP_CHECKS); + // TODO: Этап 2-5 (другие проверки) oledSetStage(2, TOTAL_STAGES); - delay(500); - + delay(DELAY_FOR_STARTUP_CHECKS); + oledSetStage(3, TOTAL_STAGES); - delay(500); - + delay(DELAY_FOR_STARTUP_CHECKS); + oledSetStage(4, TOTAL_STAGES); - delay(500); - + delay(DELAY_FOR_STARTUP_CHECKS); + oledSetStage(5, TOTAL_STAGES); - delay(500); - + delay(DELAY_FOR_STARTUP_CHECKS); + // Все проверки пройдены oledSetSystemReady(joyOk); // пока только джойстик влияет } @@ -51,13 +52,12 @@ void setup() { servoInit(); ultrasonicInit(); - joyInit(); // faceInit(); actuatorsInit(); webServerInit(); wsInit(); // irInit(); - + robot.lastCmdMs = millis(); }