// --- Keypad Setup (Same as before) ---
#include <Keypad.h>
#include "InputHandler.h" // Include the refactored class
InputHandler inp;
const uint8_t ROWS = 4;
const uint8_t COLS = 4;
char keys[ROWS][COLS] = {
{ '1', '2', '3', 'A' },
{ '4', '5', '6', 'B' },
{ '7', '8', '9', 'C' },
{ '*', '0', '#', 'D' }
};
uint8_t colPins[COLS] = { 5, 4, 3, 2 };
uint8_t rowPins[ROWS] = { 9, 8, 7, 6 };
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
// --- Main Program ---
void setup() {
Serial.begin(115200);
inp.attach(&keypad);
// Start the input process in ALL mode
inp.startInput(InputHandler::mode::ALL);
Serial.println("System Ready. Type on keypad, press D when done.");
Serial.println("----------------------------------------------");
}
void loop() {
// 1. Run the non-blocking input handler on every loop iteration
inp.run();
// 2. Check the exit condition externally
if (inp.isDone()) {
String finalData = inp.getResult();
Serial.print("Final Data Received: ");
Serial.println(finalData);
// OPTIONAL: Stop the program or transition to a new State Machine
while(true) {
// We exit the loop to prevent further processing
delay(1000);
}
}
// --- OTHER NON-BLOCKING TASKS GO HERE ---
// The InputHandler no longer blocks, so queues and state machines run freely!
// sensor_producer_task();
// fsm.run();
}