basic main menu
parent
43c12c65a5
commit
fe220120cc
|
@ -7,6 +7,7 @@
|
|||
#define CHAR_INVERTED_D 3
|
||||
#define CHAR_ENCODER 4
|
||||
#define CHAR_ENCODER_SWITCH 5
|
||||
#define CHAR_SELECTION 0b01111110
|
||||
|
||||
extern uint8_t invertedA[8];
|
||||
extern uint8_t invertedB[8];
|
||||
|
|
|
@ -51,7 +51,6 @@ char getDebugKey() {
|
|||
}
|
||||
|
||||
void handleDebugFunctions(char key) {
|
||||
if (key){lcd.write(key);}
|
||||
if (key == 'h') {
|
||||
Serial.println("Debug functions:");
|
||||
Serial.println(" h - print this help");
|
||||
|
|
|
@ -10,3 +10,9 @@ Input getInput() {
|
|||
|
||||
return {debugKey, key, switchEvent, encoderEvent, hasInput};
|
||||
}
|
||||
|
||||
Input handleInput() {
|
||||
auto input = getInput();
|
||||
debugHandleInput(input);
|
||||
return input;
|
||||
}
|
||||
|
|
|
@ -13,3 +13,4 @@ struct Input {
|
|||
};
|
||||
|
||||
Input getInput();
|
||||
Input handleInput();
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "memes.h"
|
||||
#include "input.h"
|
||||
#include "spindle.h"
|
||||
#include "menu.h"
|
||||
|
||||
void setup() {
|
||||
setupDebug();
|
||||
|
@ -21,6 +22,7 @@ void setup() {
|
|||
|
||||
Wire.begin();
|
||||
Wire.setClock(800000);
|
||||
debugScanI2C();
|
||||
|
||||
if (!setupScreen()) {
|
||||
fatal();
|
||||
|
@ -33,15 +35,9 @@ void setup() {
|
|||
}
|
||||
|
||||
splashScreen();
|
||||
menu();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
debugScanI2C();
|
||||
|
||||
auto input = getInput();
|
||||
if (input.hasInput) {
|
||||
tick();
|
||||
}
|
||||
debugHandleInput(input);
|
||||
}
|
||||
|
||||
|
|
|
@ -25,4 +25,5 @@ void splashScreen() {
|
|||
delay(300);
|
||||
lcd.setCursor(0, 1);
|
||||
lcd.print("by");
|
||||
delay(1000);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
#include "input.h"
|
||||
#include "buzzer.h"
|
||||
#include "screen.h"
|
||||
#include "characters.h"
|
||||
|
||||
uint8_t menuPos = 0;
|
||||
#define MENU_ITEMS 2
|
||||
|
||||
void menu_setup();
|
||||
void menu_update();
|
||||
void help();
|
||||
|
||||
void menu() {
|
||||
menu_setup();
|
||||
while (true) {
|
||||
auto input = handleInput();
|
||||
if (input.encoderEvent) {
|
||||
tick();
|
||||
menuPos = (menuPos + input.encoderEvent) % MENU_ITEMS;
|
||||
if (menuPos == 255) {
|
||||
menuPos = MENU_ITEMS - 1;
|
||||
}
|
||||
menu_update();
|
||||
} else if (input.switchEvent == SWITCH_RELEASED) {
|
||||
switch (menuPos) {
|
||||
case 0:
|
||||
Serial.println("Unimplemented");
|
||||
sadBuzz();
|
||||
break;
|
||||
case 1:
|
||||
help();
|
||||
break;
|
||||
}
|
||||
menu_setup();
|
||||
} else if (input.hasInput && input.switchEvent != SWITCH_PRESSED) {
|
||||
beep();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void menu_setup() {
|
||||
menuPos = 0;
|
||||
lcd.clear();
|
||||
lcd.print(" Wind coils");
|
||||
lcd.setCursor(0, 1);
|
||||
lcd.print(" Help");
|
||||
menu_update();
|
||||
}
|
||||
|
||||
void menu_update() {
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.write(menuPos == 0 ? CHAR_SELECTION : ' ');
|
||||
lcd.setCursor(0, 1);
|
||||
lcd.write(menuPos == 1 ? CHAR_SELECTION : ' ');
|
||||
}
|
||||
|
||||
void help() {
|
||||
lcd.clear();
|
||||
lcd.print("Read the source");
|
||||
lcd.setCursor(0, 1);
|
||||
lcd.print("code, Luke ;^)");
|
||||
beep();
|
||||
|
||||
while (true) {
|
||||
auto input = handleInput();
|
||||
if (input.hasInput && input.switchEvent != SWITCH_PRESSED) {
|
||||
tick();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
#pragma once
|
||||
|
||||
void menu();
|
Loading…
Reference in New Issue