diff --git a/firmware/platformio.ini b/firmware/platformio.ini index e6e3e23..4e6862c 100644 --- a/firmware/platformio.ini +++ b/firmware/platformio.ini @@ -19,4 +19,4 @@ lib_deps = robtillaart/PCF8574@^0.4.1 robtillaart/AS5600@^0.6.0 -monitor_speed = 2000000 +monitor_speed = 1500000 diff --git a/firmware/src/constants.h b/firmware/src/constants.h index fe3e5ec..15e4128 100644 --- a/firmware/src/constants.h +++ b/firmware/src/constants.h @@ -3,6 +3,7 @@ // --- debug config #define DEBUG_I2C 0 +#define DEBUG_PRINT_EVENTS 1 // --- pinout diff --git a/firmware/src/debug.cpp b/firmware/src/debug.cpp index 5971ff0..583a31b 100644 --- a/firmware/src/debug.cpp +++ b/firmware/src/debug.cpp @@ -8,11 +8,12 @@ I2CScanner scanner; #include "screen.h" #include "keyboard.h" #include "stepper.h" +#include "input.h" void setupDebug() { pinMode(LED_BUILTIN, OUTPUT); - Serial.begin(2000000); + Serial.begin(1500000); Serial.println("it's cewk-o-mator, hello!"); #if DEBUG_I2C scanner.Init(); @@ -79,7 +80,7 @@ void handleDebugFunctions(char key) { Serial.println(micros2 - micros1); micros1 = micros(); - auto key = handleKeyboard(); + handleKeyboard(); micros2 = micros(); Serial.print("Keyboard scan time (microseconds): "); Serial.println(micros2 - micros1); @@ -91,3 +92,32 @@ void handleDebugFunctions(char key) { setTimerEnabled(!isTimerEnabled()); } } + +void debugHandleInput(Input input) { + handleDebugFunctions(input.debugKey); + +#if DEBUG_PRINT_EVENTS + if (input.key) { + Serial.print("Key pressed: "); + Serial.print(allKeys[input.key]); + + auto digit = getPressedDigit(input.key); + if (digit != KEY_NONE) { + Serial.print(", digit: "); + Serial.print(digit); + } else { + Serial.print(" (Not a digit)"); + } + + Serial.println(); + } + + if (input.switchEvent) { + Serial.println(input.switchEvent == SWITCH_PRESSED ? "Pressed" : "Released"); + } + + if (input.encoderEvent) { + Serial.println(input.encoderEvent == ENCODER_CLOCKWISE ? "Clockwise" : "Counter-clockwise"); + } +#endif +} diff --git a/firmware/src/debug.h b/firmware/src/debug.h index 0c84993..acacb55 100644 --- a/firmware/src/debug.h +++ b/firmware/src/debug.h @@ -1,4 +1,5 @@ #pragma once +struct Input; void setupDebug(); void debugScanI2C(); @@ -18,4 +19,4 @@ void fatal(); */ char getDebugKey(); -void handleDebugFunctions(char key); +void debugHandleInput(Input input); diff --git a/firmware/src/input.cpp b/firmware/src/input.cpp new file mode 100644 index 0000000..0a53755 --- /dev/null +++ b/firmware/src/input.cpp @@ -0,0 +1,12 @@ +#include "debug.h" +#include "input.h" + +Input getInput() { + auto debugKey = getDebugKey(); + auto key = handleDebugKeyboard(debugKey); + auto switchEvent = handleDebugSwitch(debugKey); + auto encoderEvent = handleDebugEncoder(debugKey); + bool hasInput = debugKey || key || switchEvent || encoderEvent; + + return {debugKey, key, switchEvent, encoderEvent, hasInput}; +} diff --git a/firmware/src/input.h b/firmware/src/input.h new file mode 100644 index 0000000..5ef2124 --- /dev/null +++ b/firmware/src/input.h @@ -0,0 +1,15 @@ +#pragma once +#include + +#include "keyboard.h" +#include "encoder.h" + +struct Input { + char debugKey; + Key key; + SwitchEvent switchEvent; + EncoderEvent encoderEvent; + bool hasInput; +}; + +Input getInput(); diff --git a/firmware/src/main.cpp b/firmware/src/main.cpp index db2771e..7aba963 100644 --- a/firmware/src/main.cpp +++ b/firmware/src/main.cpp @@ -9,6 +9,7 @@ #include "debug.h" #include "stepper.h" #include "memes.h" +#include "input.h" void setup() { setupDebug(); @@ -30,10 +31,12 @@ void setup() { splashScreen(); } +/* bool stepperDemo = false; bool stepperDemoSlowing = false; bool stepperDemoLongStretch = false; unsigned long lastStepperDemoMillis = 0; +*/ void loop() { debugScanI2C(); @@ -76,35 +79,10 @@ void loop() { } */ - auto debugKey = getDebugKey(); - auto key = handleDebugKeyboard(debugKey); - auto switchEvent = handleDebugSwitch(debugKey); - auto encoderEvent = handleDebugEncoder(debugKey); - if (debugKey || key || switchEvent || encoderEvent) { + auto input = getInput(); + if (input.hasInput) { tick(); } - handleDebugFunctions(debugKey); - - if (key) { - Serial.print("Key pressed: "); - Serial.print(allKeys[key]); - - auto digit = getPressedDigit(key); - if (digit != KEY_NONE) { - Serial.print(", digit: "); - Serial.print(digit); - } else { - Serial.print(" (Not a digit)"); - } - - Serial.println(); - } - - if (switchEvent) { - Serial.println(switchEvent == SWITCH_PRESSED ? "Pressed" : "Released"); - } - - if (encoderEvent) { - Serial.println(encoderEvent == ENCODER_CLOCKWISE ? "Clockwise" : "Counter-clockwise"); - } + debugHandleInput(input); } +