clean up input
parent
d006b7a457
commit
1914c026d2
|
@ -19,4 +19,4 @@ lib_deps =
|
||||||
robtillaart/PCF8574@^0.4.1
|
robtillaart/PCF8574@^0.4.1
|
||||||
robtillaart/AS5600@^0.6.0
|
robtillaart/AS5600@^0.6.0
|
||||||
|
|
||||||
monitor_speed = 2000000
|
monitor_speed = 1500000
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
// --- debug config
|
// --- debug config
|
||||||
|
|
||||||
#define DEBUG_I2C 0
|
#define DEBUG_I2C 0
|
||||||
|
#define DEBUG_PRINT_EVENTS 1
|
||||||
|
|
||||||
// --- pinout
|
// --- pinout
|
||||||
|
|
||||||
|
|
|
@ -8,11 +8,12 @@ I2CScanner scanner;
|
||||||
#include "screen.h"
|
#include "screen.h"
|
||||||
#include "keyboard.h"
|
#include "keyboard.h"
|
||||||
#include "stepper.h"
|
#include "stepper.h"
|
||||||
|
#include "input.h"
|
||||||
|
|
||||||
void setupDebug() {
|
void setupDebug() {
|
||||||
pinMode(LED_BUILTIN, OUTPUT);
|
pinMode(LED_BUILTIN, OUTPUT);
|
||||||
|
|
||||||
Serial.begin(2000000);
|
Serial.begin(1500000);
|
||||||
Serial.println("it's cewk-o-mator, hello!");
|
Serial.println("it's cewk-o-mator, hello!");
|
||||||
#if DEBUG_I2C
|
#if DEBUG_I2C
|
||||||
scanner.Init();
|
scanner.Init();
|
||||||
|
@ -79,7 +80,7 @@ void handleDebugFunctions(char key) {
|
||||||
Serial.println(micros2 - micros1);
|
Serial.println(micros2 - micros1);
|
||||||
|
|
||||||
micros1 = micros();
|
micros1 = micros();
|
||||||
auto key = handleKeyboard();
|
handleKeyboard();
|
||||||
micros2 = micros();
|
micros2 = micros();
|
||||||
Serial.print("Keyboard scan time (microseconds): ");
|
Serial.print("Keyboard scan time (microseconds): ");
|
||||||
Serial.println(micros2 - micros1);
|
Serial.println(micros2 - micros1);
|
||||||
|
@ -91,3 +92,32 @@ void handleDebugFunctions(char key) {
|
||||||
setTimerEnabled(!isTimerEnabled());
|
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
|
||||||
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
struct Input;
|
||||||
|
|
||||||
void setupDebug();
|
void setupDebug();
|
||||||
void debugScanI2C();
|
void debugScanI2C();
|
||||||
|
@ -18,4 +19,4 @@ void fatal();
|
||||||
*/
|
*/
|
||||||
char getDebugKey();
|
char getDebugKey();
|
||||||
|
|
||||||
void handleDebugFunctions(char key);
|
void debugHandleInput(Input input);
|
||||||
|
|
|
@ -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};
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
#pragma once
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
#include "keyboard.h"
|
||||||
|
#include "encoder.h"
|
||||||
|
|
||||||
|
struct Input {
|
||||||
|
char debugKey;
|
||||||
|
Key key;
|
||||||
|
SwitchEvent switchEvent;
|
||||||
|
EncoderEvent encoderEvent;
|
||||||
|
bool hasInput;
|
||||||
|
};
|
||||||
|
|
||||||
|
Input getInput();
|
|
@ -9,6 +9,7 @@
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "stepper.h"
|
#include "stepper.h"
|
||||||
#include "memes.h"
|
#include "memes.h"
|
||||||
|
#include "input.h"
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
setupDebug();
|
setupDebug();
|
||||||
|
@ -30,10 +31,12 @@ void setup() {
|
||||||
splashScreen();
|
splashScreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
bool stepperDemo = false;
|
bool stepperDemo = false;
|
||||||
bool stepperDemoSlowing = false;
|
bool stepperDemoSlowing = false;
|
||||||
bool stepperDemoLongStretch = false;
|
bool stepperDemoLongStretch = false;
|
||||||
unsigned long lastStepperDemoMillis = 0;
|
unsigned long lastStepperDemoMillis = 0;
|
||||||
|
*/
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
debugScanI2C();
|
debugScanI2C();
|
||||||
|
@ -76,35 +79,10 @@ void loop() {
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
auto debugKey = getDebugKey();
|
auto input = getInput();
|
||||||
auto key = handleDebugKeyboard(debugKey);
|
if (input.hasInput) {
|
||||||
auto switchEvent = handleDebugSwitch(debugKey);
|
|
||||||
auto encoderEvent = handleDebugEncoder(debugKey);
|
|
||||||
if (debugKey || key || switchEvent || encoderEvent) {
|
|
||||||
tick();
|
tick();
|
||||||
}
|
}
|
||||||
handleDebugFunctions(debugKey);
|
debugHandleInput(input);
|
||||||
|
|
||||||
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");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue