clean up debug functions
parent
5febbecb99
commit
d006b7a457
|
@ -1,13 +1,13 @@
|
|||
#include <Arduino.h>
|
||||
#if DEBUG_I2C
|
||||
#include <I2CScanner.h>
|
||||
I2CScanner scanner;
|
||||
#endif
|
||||
#include "constants.h"
|
||||
#include "buzzer.h"
|
||||
|
||||
#if DEBUG_I2C
|
||||
I2CScanner scanner;
|
||||
#endif
|
||||
#include "screen.h"
|
||||
#include "keyboard.h"
|
||||
#include "stepper.h"
|
||||
|
||||
void setupDebug() {
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
|
@ -47,3 +47,47 @@ char getDebugKey() {
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void handleDebugFunctions(char key) {
|
||||
if (key == 'h') {
|
||||
Serial.println("Debug functions:");
|
||||
Serial.println(" h - print this help");
|
||||
Serial.println(" s - play sounds");
|
||||
Serial.println(" i - timing test");
|
||||
Serial.println(" l - change stepper direction to left");
|
||||
Serial.println(" r - change stepper direction to right");
|
||||
Serial.println(" - - toggle stepper timer");
|
||||
} else if (key == 's') {
|
||||
happyBuzz();
|
||||
delay(500);
|
||||
sadBuzz();
|
||||
delay(500);
|
||||
beep();
|
||||
delay(500);
|
||||
tick();
|
||||
} else if (key == 'i') {
|
||||
auto micros1 = micros();
|
||||
Serial.println("Hello, world!");
|
||||
auto micros2 = micros();
|
||||
Serial.print("Serial print time (microseconds): ");
|
||||
Serial.println(micros2 - micros1);
|
||||
|
||||
micros1 = micros();
|
||||
lcd.print("Hello, world!");
|
||||
micros2 = micros();
|
||||
Serial.print("LCD print time (microseconds): ");
|
||||
Serial.println(micros2 - micros1);
|
||||
|
||||
micros1 = micros();
|
||||
auto key = handleKeyboard();
|
||||
micros2 = micros();
|
||||
Serial.print("Keyboard scan time (microseconds): ");
|
||||
Serial.println(micros2 - micros1);
|
||||
} else if (key == 'l') {
|
||||
setStepperDirection(LEFT);
|
||||
} else if (key == 'r') {
|
||||
setStepperDirection(RIGHT);
|
||||
} else if (key == '-') {
|
||||
setTimerEnabled(!isTimerEnabled());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,3 +17,5 @@ void fatal();
|
|||
* Encoder switch: Space
|
||||
*/
|
||||
char getDebugKey();
|
||||
|
||||
void handleDebugFunctions(char key);
|
||||
|
|
|
@ -20,7 +20,10 @@ void setup() {
|
|||
Wire.begin();
|
||||
Wire.setClock(800000);
|
||||
|
||||
if (!setupScreen() || !setupKeyboard()) {
|
||||
if (!setupScreen()) {
|
||||
fatal();
|
||||
}
|
||||
if (!setupKeyboard()) {
|
||||
fatal();
|
||||
}
|
||||
|
||||
|
@ -35,20 +38,8 @@ unsigned long lastStepperDemoMillis = 0;
|
|||
void loop() {
|
||||
debugScanI2C();
|
||||
|
||||
char debugKey = getDebugKey();
|
||||
|
||||
if (debugKey == '1') {
|
||||
setStepperEnabled(true);
|
||||
} else if (debugKey == '2') {
|
||||
setStepperEnabled(false);
|
||||
} else if (debugKey == 'l') {
|
||||
setStepperDirection(LEFT);
|
||||
} else if (debugKey == 'r') {
|
||||
setStepperDirection(RIGHT);
|
||||
} else if (debugKey == '-') {
|
||||
setTimerEnabled(!isTimerEnabled());
|
||||
stepperDemo = false;
|
||||
} else if (debugKey == 'k') {
|
||||
/*
|
||||
if (debugKey == 'k') {
|
||||
setStepperEnabled(true);
|
||||
setStepperDirection(RIGHT);
|
||||
setTimerEnabled(true);
|
||||
|
@ -83,8 +74,18 @@ void loop() {
|
|||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
if (auto key = handleDebugKeyboard(debugKey)) {
|
||||
auto debugKey = getDebugKey();
|
||||
auto key = handleDebugKeyboard(debugKey);
|
||||
auto switchEvent = handleDebugSwitch(debugKey);
|
||||
auto encoderEvent = handleDebugEncoder(debugKey);
|
||||
if (debugKey || key || switchEvent || encoderEvent) {
|
||||
tick();
|
||||
}
|
||||
handleDebugFunctions(debugKey);
|
||||
|
||||
if (key) {
|
||||
Serial.print("Key pressed: ");
|
||||
Serial.print(allKeys[key]);
|
||||
|
||||
|
@ -97,36 +98,13 @@ void loop() {
|
|||
}
|
||||
|
||||
Serial.println();
|
||||
|
||||
if (key == KEY_A) {
|
||||
happyBuzz();
|
||||
} else if (key == KEY_B) {
|
||||
sadBuzz();
|
||||
} else if (key == KEY_C) {
|
||||
beep();
|
||||
} else if (digit == 7) {
|
||||
auto micros1 = micros();
|
||||
// 0.1ms
|
||||
// Serial.println("Hello, world!");
|
||||
// 13.2ms
|
||||
// lcd.print("Hello, world!");
|
||||
// 0.5ms
|
||||
// auto key = handleKeyboard();
|
||||
auto micros2 = micros();
|
||||
Serial.println(micros2 - micros1);
|
||||
} else {
|
||||
tick();
|
||||
}
|
||||
}
|
||||
|
||||
if (auto switchEvent = handleDebugSwitch(debugKey)) {
|
||||
tick();
|
||||
if (switchEvent) {
|
||||
Serial.println(switchEvent == SWITCH_PRESSED ? "Pressed" : "Released");
|
||||
}
|
||||
|
||||
if (auto encoderEvent = handleDebugEncoder(debugKey)) {
|
||||
tick();
|
||||
if (encoderEvent) {
|
||||
Serial.println(encoderEvent == ENCODER_CLOCKWISE ? "Clockwise" : "Counter-clockwise");
|
||||
setTimerCadence(getTimerCadence() + (encoderEvent == ENCODER_CLOCKWISE ? -1 : 1));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue