3#include <Preferences.h>
10#include "ble_keyboard_adapter.h"
19#include "led_controller.h"
35static constexpr const char* NVS_NAMESPACE =
"pedal";
36static constexpr const char* NVS_KEY_PROFILE =
"profile";
38static void saveCurrentProfile(uint8_t index)
41 prefs.begin(NVS_NAMESPACE,
false);
42 prefs.putUChar(NVS_KEY_PROFILE, index);
46static uint8_t loadSavedProfile()
49 prefs.begin(NVS_NAMESPACE,
true);
50 uint8_t index = prefs.getUChar(NVS_KEY_PROFILE, 0);
56static void saveCurrentProfile(uint8_t) {}
57static uint8_t loadSavedProfile() {
return 0; }
81 Serial.println(
"CONFIG ERROR: falling back to factory default");
82 constexpr int BLINK_COUNT = 5;
83 constexpr int BLINK_DURATION = 100;
84 for (
int i = 0; i < BLINK_COUNT; i++)
90 delay(BLINK_DURATION);
95 delay(BLINK_DURATION);
142static const IsrFunc BTN_ISRS[Btn::MAX] = {
183 Serial.printf(
"Button %s pressed (Profile: %s)\n", btnLabel, profileName);
187 if (action->isInProgress())
189 Serial.println(
" -> DelayedAction in progress, ignoring");
194 if (action->hasName())
196 Serial.printf(
" -> Executing %s action [%s]\n", actionType, action->getName().c_str());
200 Serial.printf(
" -> Executing %s action\n", actionType);
206 Serial.println(
" -> no action configured");
227 Serial.printf(
"Switched to Profile %d\n", profile + 1);
228 saveCurrentProfile(profile);
237 Serial.begin(115200);
239 Serial.println(
"started");
254 uint8_t savedProfile = loadSavedProfile();
259 Serial.printf(
"Restored profile %d from NVS\n", savedProfile + 1);
321 Serial.println(
"connected");
331 Serial.println(
"disconnected");
339 uint32_t now = millis();
Adapter that implements IBleKeyboard interface using BleKeyboard.
void begin() override
Initializes the BLE keyboard.
bool isConnected() override
Checks if BLE keyboard is connected.
Manages event callbacks for button presses.
void dispatch(uint8_t button)
Executes the callback for the specified button.
void registerHandler(uint8_t button, EventCallback callback)
Registers a callback function for a button.
ESP32-specific implementation of ILEDController.
bool isBlinking() const override
Returns true if a blink sequence is currently running.
void setup(uint32_t initialState=0) override
void update(uint32_t now) override
Drive timed behaviour — must be called every loop iteration.
void setState(bool state) override
void startBlink(uint32_t intervalMs, int16_t count=-1) override
Start a blink sequence.
void stopBlink() override
Stop any running blink and restore the pre-blink state.
Manages up to MAX_PROFILES profiles with LED feedback.
bool hasActiveDelayedAction() const
Returns true if any DelayedAction across all profiles is currently running.
const std::string & getProfileName(uint8_t profileIndex) const
const Profile * getProfile(uint8_t profileIndex) const
Action * getAction(uint8_t profileIndex, uint8_t button) const
uint8_t getCurrentProfile() const
static const char * getActionTypeString(Action::Type actionType)
static constexpr uint8_t MAX_SELECT_LEDS
void setCurrentProfile(uint8_t profileIndex)
Directly set the current profile without triggering blink feedback.
void update(uint32_t now)
Drive timed LED behaviour — call every loop iteration.
uint8_t switchProfile()
Advance to the next populated profile slot and trigger blink feedback.
const HardwareConfig hardwareConfig
Global hardware configuration instance.
BleKeyboardAdapter * createBleKeyboardAdapter()
Creates the platform-specific BleKeyboardAdapter instance.
void IRAM_ATTR isr_btn16()
void IRAM_ATTR isr_btn6()
void IRAM_ATTR isr_btn7()
void IRAM_ATTR isr_btn13()
void IRAM_ATTR isr_btn10()
void process_events()
Processes button events and dispatches them to handlers.
void IRAM_ATTR isr_btn4()
std::vector< ILEDController * > selectLeds
void IRAM_ATTR isr_btn17()
void signalLoadError()
Signal a configuration load error by blinking all LEDs, then fall back to the hardcoded factory defau...
void IRAM_ATTR isr_btn24()
void IRAM_ATTR isr_buttons(uint8_t index)
void IRAM_ATTR isr_btn1()
void IRAM_ATTR isr_btn11()
void IRAM_ATTR isr_btn25()
void IRAM_ATTR isr_btn3()
void setup()
Arduino setup function - runs once at startup.
void IRAM_ATTR isr_btn9()
LEDController ledPower(hardwareConfig.ledPower)
void detachInterrupts()
Detaches interrupt handlers from all buttons.
Button * actionButtonObjects[Btn::MAX]
BleKeyboardAdapter * bleKeyboardAdapter
void IRAM_ATTR isr_btn23()
void executeActionWithLogging(uint8_t buttonIndex)
Executes an action with proper logging.
Button BUTTON_SELECT(hardwareConfig.buttonSelect)
LEDController ledBluetooth(hardwareConfig.ledBluetooth)
EventDispatcher eventDispatcher
void IRAM_ATTR isr_btn12()
void IRAM_ATTR isr_btn14()
void IRAM_ATTR isr_btn18()
void IRAM_ATTR isr_btn22()
ProfileManager * profileManager
void setup_hardware()
Initializes all hardware components.
void setup_event_handlers()
Configures event handlers for all buttons.
void IRAM_ATTR isr_btn0()
void IRAM_ATTR isr_btn15()
void IRAM_ATTR isr_btn8()
void attachInterrupts()
Attaches interrupt handlers to all buttons.
void IRAM_ATTR isr_btn19()
void IRAM_ATTR isr_btn5()
LEDController * selectLedObjects[ProfileManager::MAX_SELECT_LEDS]
void IRAM_ATTR isr_select()
void IRAM_ATTR isr_btn21()
void IRAM_ATTR isr_btn20()
void loop()
Arduino main loop - runs repeatedly.
void IRAM_ATTR isr_btn2()
void name(uint8_t index, char *buf)
Write the letter name for a button index into buf.
bool configureProfiles(ProfileManager &profileManager, IBleKeyboard *keyboard)
Loads pedal profiles from file, falling back to DEFAULT_CONFIG on failure.
uint8_t numSelectLeds
Profile-select LEDs wired; caps profiles at 2^n − 1.
uint8_t buttonPins[26]
Action button pins: index 0 = A, 1 = B, ..., 25 = Z.
uint8_t ledSelect[6]
Profile-select LED pins (up to 6)
uint8_t ledBluetooth
Bluetooth status LED pin.
uint8_t ledPower
Power indicator LED pin.
uint8_t numButtons
Action buttons wired (1..26, A–Z)
uint8_t buttonSelect
Profile-cycle button pin.