add init joy
This commit is contained in:
parent
7e8c58828d
commit
57c07b07db
@ -4,7 +4,6 @@
|
|||||||
#include <Adafruit_SSD1306.h>
|
#include <Adafruit_SSD1306.h>
|
||||||
#include "body.h"
|
#include "body.h"
|
||||||
#include "../../../config.h"
|
#include "../../../config.h"
|
||||||
#include "../../joystick/joystick.h"
|
|
||||||
|
|
||||||
// ===== OLED CONFIG =====
|
// ===== OLED CONFIG =====
|
||||||
// ESP32 ESP-WROOM-32D с OLED 0.96" (SSD1306)
|
// 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();
|
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() {
|
void oledInit() {
|
||||||
Wire.begin(SDA_PIN, SCL_PIN);
|
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);
|
void oledSetSystemReady(bool ready);
|
||||||
bool oledIsSystemReady();
|
bool oledIsSystemReady();
|
||||||
|
|
||||||
// проверка устройств
|
|
||||||
bool oledCheckJoystick();
|
|
||||||
|
|||||||
@ -26,19 +26,29 @@ static int lastLoggedXNorm = 0;
|
|||||||
static int lastLoggedYNorm = 0;
|
static int lastLoggedYNorm = 0;
|
||||||
static bool lastLoggedSw = false;
|
static bool lastLoggedSw = false;
|
||||||
|
|
||||||
void joyInit() {
|
bool joyInit() {
|
||||||
pinMode(JOY_SW_PIN, INPUT_PULLUP);
|
pinMode(JOY_SW_PIN, INPUT_PULLUP);
|
||||||
|
|
||||||
// ADC1 каналы (пины 34, 35)
|
// ADC1 каналы (пины 34, 35)
|
||||||
analogReadResolution(12); // 12 бит (0-4095)
|
analogReadResolution(12); // 12 бит (0-4095)
|
||||||
analogSetAttenuation(ADC_11db); // 0-3.3V
|
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.println("Joystick initialized");
|
||||||
Serial.printf(" VRX → GPIO%d (ADC1_CH6)\n", JOY_X_PIN);
|
Serial.printf(" VRX → GPIO%d (ADC1_CH6)\n", JOY_X_PIN);
|
||||||
Serial.printf(" VRY → GPIO%d (ADC1_CH7)\n", JOY_Y_PIN);
|
Serial.printf(" VRY → GPIO%d (ADC1_CH7)\n", JOY_Y_PIN);
|
||||||
Serial.printf(" SW → GPIO%d\n", JOY_SW_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.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() {
|
void joyUpdate() {
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
void joyInit();
|
bool joyInit();
|
||||||
void joyUpdate();
|
void joyUpdate();
|
||||||
|
|
||||||
// возвращает значения 0-4095
|
// возвращает значения 0-4095
|
||||||
|
|||||||
20
src/main.cpp
20
src/main.cpp
@ -14,28 +14,29 @@
|
|||||||
// #include "core/deprecate/ir_input/ir_input.h"
|
// #include "core/deprecate/ir_input/ir_input.h"
|
||||||
|
|
||||||
#define TOTAL_STAGES 5
|
#define TOTAL_STAGES 5
|
||||||
|
#define DELAY_FOR_STARTUP_CHECKS 1000
|
||||||
|
|
||||||
void runStartupChecks() {
|
void runStartupChecks() {
|
||||||
|
delay(DELAY_FOR_STARTUP_CHECKS);
|
||||||
|
|
||||||
// Этап 1: Проверка джойстика
|
// Этап 1: Проверка джойстика
|
||||||
oledSetStage(1, TOTAL_STAGES);
|
oledSetStage(1, TOTAL_STAGES);
|
||||||
bool joyOk = oledCheckJoystick();
|
bool joyOk = joyInit();
|
||||||
oledShowMain(joyOk ? "Joystick: OK" : "Joystick: NOT FOUND", "IR: NOT FOUND",
|
oledShowMain(joyOk ? "Joystick: OK" : "Joystick: NOT FOUND", "IR: NOT FOUND", "", "");
|
||||||
"",
|
delay(DELAY_FOR_STARTUP_CHECKS);
|
||||||
"");
|
|
||||||
delay(500);
|
|
||||||
|
|
||||||
// TODO: Этап 2-5 (другие проверки)
|
// TODO: Этап 2-5 (другие проверки)
|
||||||
oledSetStage(2, TOTAL_STAGES);
|
oledSetStage(2, TOTAL_STAGES);
|
||||||
delay(500);
|
delay(DELAY_FOR_STARTUP_CHECKS);
|
||||||
|
|
||||||
oledSetStage(3, TOTAL_STAGES);
|
oledSetStage(3, TOTAL_STAGES);
|
||||||
delay(500);
|
delay(DELAY_FOR_STARTUP_CHECKS);
|
||||||
|
|
||||||
oledSetStage(4, TOTAL_STAGES);
|
oledSetStage(4, TOTAL_STAGES);
|
||||||
delay(500);
|
delay(DELAY_FOR_STARTUP_CHECKS);
|
||||||
|
|
||||||
oledSetStage(5, TOTAL_STAGES);
|
oledSetStage(5, TOTAL_STAGES);
|
||||||
delay(500);
|
delay(DELAY_FOR_STARTUP_CHECKS);
|
||||||
|
|
||||||
// Все проверки пройдены
|
// Все проверки пройдены
|
||||||
oledSetSystemReady(joyOk); // пока только джойстик влияет
|
oledSetSystemReady(joyOk); // пока только джойстик влияет
|
||||||
@ -51,7 +52,6 @@ void setup() {
|
|||||||
|
|
||||||
servoInit();
|
servoInit();
|
||||||
ultrasonicInit();
|
ultrasonicInit();
|
||||||
joyInit();
|
|
||||||
// faceInit();
|
// faceInit();
|
||||||
actuatorsInit();
|
actuatorsInit();
|
||||||
webServerInit();
|
webServerInit();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user