add init joy
This commit is contained in:
parent
7e8c58828d
commit
57c07b07db
@ -4,7 +4,6 @@
|
||||
#include <Adafruit_SSD1306.h>
|
||||
#include "body.h"
|
||||
#include "../../../config.h"
|
||||
#include "../../joystick/joystick.h"
|
||||
|
||||
// ===== OLED CONFIG =====
|
||||
// ESP32 ESP-WROOM-32D с OLED 0.96" (SSD1306)
|
||||
@ -100,22 +99,6 @@ void oledShowMain(const char* line1, const char* line2, const char* line3, const
|
||||
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);
|
||||
|
||||
|
||||
@ -20,6 +20,3 @@ void oledShowMain(const char* line1, const char* line2, const char* line3, const
|
||||
// состояние системы
|
||||
void oledSetSystemReady(bool ready);
|
||||
bool oledIsSystemReady();
|
||||
|
||||
// проверка устройств
|
||||
bool oledCheckJoystick();
|
||||
|
||||
@ -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() {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
void joyInit();
|
||||
bool joyInit();
|
||||
void joyUpdate();
|
||||
|
||||
// возвращает значения 0-4095
|
||||
|
||||
20
src/main.cpp
20
src/main.cpp
@ -14,28 +14,29 @@
|
||||
// #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,7 +52,6 @@ void setup() {
|
||||
|
||||
servoInit();
|
||||
ultrasonicInit();
|
||||
joyInit();
|
||||
// faceInit();
|
||||
actuatorsInit();
|
||||
webServerInit();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user