/
DriveVision
/
Smart-Column-S3
Обзор
Документация
Войти
/
DriveVision
/
Smart-Column-S3
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/interface/buttons.cpp
51 строка
1 KB
Claude
Import Smart-Column S3 implementation from rectification-controller
06 дек 2025, 10:00
06 дек 2025, 10:00
54e4312
Код
Авторство
О чём код?
/** * Smart-Column S3 - Обработка кнопок * * Чтение и обработка физических кнопок с debounce */ #include "buttons.h" static uint32_t lastPress[4] = {0}; static bool lastState[4] = {false}; namespace Buttons { void init() { LOG_I("Buttons: Initializing..."); pinMode(PIN_BTN_1, INPUT_PULLUP); pinMode(PIN_BTN_2, INPUT_PULLUP); pinMode(PIN_BTN_3, INPUT_PULLUP); pinMode(PIN_BTN_4, INPUT_PULLUP); LOG_I("Buttons: Ready"); } void update() { uint32_t now = millis(); uint8_t pins[] = {PIN_BTN_1, PIN_BTN_2, PIN_BTN_3, PIN_BTN_4}; for (uint8_t i = 0; i < 4; i++) { bool current = !digitalRead(pins[i]); // Инвертируем (pullup) // Debounce if (current != lastState[i] && now - lastPress[i] > BTN_DEBOUNCE_MS) { lastState[i] = current; lastPress[i] = now; if (current) { LOG_D("Buttons: Button %d pressed", i + 1); // TODO: Отправить событие } } } } bool isPressed(uint8_t button) { if (button > 4) return false; uint8_t pins[] = {PIN_BTN_1, PIN_BTN_2, PIN_BTN_3, PIN_BTN_4}; return !digitalRead(pins[button - 1]); } } // namespace Buttons