Files
velometer/gui.h
T

92 lines
2.0 KiB
C

#ifndef VELOMETER_GUI_H
#define VELOMETER_GUI_H
#include "config.h"
#include <pico/stdlib.h>
enum ButtonInputType {
BUTTON_SHORT_PRESS,
BUTTON_LONG_PRESS,
};
enum GUIScreen {
MAIN_SCREEN,
MENU_SCREEN,
};
enum DisplayMode {
DISPLAY_MODE_SPEED,
DISPLAY_MODE_DISTANCE_FROM_POWER_ON,
DISPLAY_MODE_TOTAL_DISTANCE,
};
enum MenuOptionType {
MENU_OPTION_NUMBER,
MENU_OPTION_ONOFF,
MENU_OPTION_TEXT,
MENU_OPTION_LINK,
};
#define TEXT_EDIT_STATIC_BUFFER_SIZE 18
struct TextEditState {
uint textLength; // number of characters in input
uint textByteLength; // number of bytes occupied by characters
// fixed-size buffers for most cases
char staticTextBuffer[TEXT_EDIT_STATIC_BUFFER_SIZE];
uint8_t staticCharWidthBuffer[TEXT_EDIT_STATIC_BUFFER_SIZE];
// the same thing but in heap for longer input
bool heapBufferInUse;
char *heapTextBuffer;
uint8_t *heapCharWidthBuffer;
uint heapTextBufferCapacity;
uint heapCharWidthBufferCapacity;
// visual edit field properties
uint cursorPos; // in characters
uint cursorPosCharOffset; // for quicker character addressing inside a UTF-8 string
uint scrollOffset; // in pixels
};
struct MenuScreenState {
enum {
MENU_SCREEN_STATE_CHOOSING_OPTION,
MENU_SCREEN_STATE_EDITING_OPTION,
} subState;
union {
struct {
uint chosenOptionIndex;
short scrollAnimationProgress;
} choosingOption;
struct {
uint optionIndex;
enum MenuOptionType optionType;
union {
uint numberValue;
bool onOffValue;
struct TextEditState textEditState;
};
} editingOption;
};
};
struct GUIState {
uint screen;
union {
struct {
uint displayMode;
bool displayModeChanged;
} mainScreen;
struct MenuScreenState menuScreen;
} screenState;
uint8_t drawnTimeHours;
uint8_t drawnTimeMinutes;
uint16_t drawnTimeTextWidth;
};
void gui_init();
void on_button_input(short button, enum ButtonInputType type, uint heldButtons);
void update_lcd();
#endif