Files
loopy_midi_controller/components/hal/switch_stub.cpp
T
ash 458cb5060f Fix Phase 1 skeleton: add build system, fix compilation errors
- Add CMakeLists.txt for project and all components
- Add idf_component.yml with TinyUSB dependency
- Create switch_stub.cpp implementation
- Fix app_task.h to match .cpp implementation (2-param signature)
- Fix led_stub.h/cpp class naming (DefaultLedStub)
- Fix midi_transport.cpp TinyUSB API usage (tud_midi_*)
- Move main.cpp to main/ directory
- Add sdkconfig.defaults for ESP32-S3
2026-06-23 08:59:53 +00:00

42 lines
1.3 KiB
C++

// components/hal/switch_stub.cpp
#include "hal/switch_stub.h"
#include "esp_log.h"
static const char* TAG = "switch_stub";
DefaultSwitchStub::DefaultSwitchStub() : initialized(false) {
for (int i = 0; i < NUM_SWITCHES; i++) {
switch_states[i].id = i;
switch_states[i].gpio_pin = 0;
switch_states[i].current_state = false;
switch_states[i].previous_state = false;
switch_states[i].last_change_time = 0;
switch_states[i].debounce_time = 50;
}
}
void DefaultSwitchStub::begin() {
initialized = true;
ESP_LOGI(TAG, "Switch stub initialized (GPIO pins not configured yet)");
}
bool DefaultSwitchStub::is_pressed(uint8_t switch_id) {
if (!initialized || switch_id >= NUM_SWITCHES) {
return false;
}
return switch_states[switch_id].current_state;
}
void DefaultSwitchStub::configure_switch(uint8_t switch_id, uint8_t gpio_pin) {
if (switch_id >= NUM_SWITCHES) return;
switch_states[switch_id].gpio_pin = gpio_pin;
ESP_LOGI(TAG, "Switch %d configured to GPIO %d", switch_id, gpio_pin);
}
void DefaultSwitchStub::set_debounce_time(uint32_t time_ms) {
for (int i = 0; i < NUM_SWITCHES; i++) {
switch_states[i].debounce_time = time_ms;
}
ESP_LOGI(TAG, "Debounce time set to %lu ms", time_ms);
}