basic main menu

main
radex 2024-02-22 16:27:04 +01:00
parent 43c12c65a5
commit fe220120cc
Signed by: radex
SSH Key Fingerprint: SHA256:hvqRXAGG1h89yqnS+cyFTLKQbzjWD4uXIqw7Y+0ws30
8 changed files with 86 additions and 8 deletions

View File

@ -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];

View File

@ -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");

View File

@ -10,3 +10,9 @@ Input getInput() {
return {debugKey, key, switchEvent, encoderEvent, hasInput};
}
Input handleInput() {
auto input = getInput();
debugHandleInput(input);
return input;
}

View File

@ -13,3 +13,4 @@ struct Input {
};
Input getInput();
Input handleInput();

View File

@ -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);
}

View File

@ -25,4 +25,5 @@ void splashScreen() {
delay(300);
lcd.setCursor(0, 1);
lcd.print("by");
delay(1000);
}

71
firmware/src/menu.cpp Normal file
View File

@ -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;
}
}
}

3
firmware/src/menu.h Normal file
View File

@ -0,0 +1,3 @@
#pragma once
void menu();