From d93fc4b4c71035959afebc69c816924121410349 Mon Sep 17 00:00:00 2001 From: dejvino Date: Sun, 2 Feb 2020 17:14:45 +0100 Subject: [PATCH] Added memory, sd card and settings menus. --- main/modes/AbstractMenuMode.cpp | 62 +++++++++++++++ main/modes/AbstractMenuMode.h | 22 ++++++ main/modes/InternalMemoryMenuMode.cpp | 40 ++++++++++ main/modes/InternalMemoryMenuMode.h | 11 +++ main/modes/MainMenuMode.cpp | 104 +++++++++++--------------- main/modes/MainMenuMode.h | 11 ++- main/modes/SdCardMenuMode.cpp | 44 +++++++++++ main/modes/SdCardMenuMode.h | 17 +++++ main/modes/SettingsMenuMode.cpp | 53 +++++++++++++ main/modes/SettingsMenuMode.h | 17 +++++ 10 files changed, 317 insertions(+), 64 deletions(-) create mode 100644 main/modes/AbstractMenuMode.cpp create mode 100644 main/modes/AbstractMenuMode.h create mode 100644 main/modes/InternalMemoryMenuMode.cpp create mode 100644 main/modes/InternalMemoryMenuMode.h create mode 100644 main/modes/SdCardMenuMode.cpp create mode 100644 main/modes/SdCardMenuMode.h create mode 100644 main/modes/SettingsMenuMode.cpp create mode 100644 main/modes/SettingsMenuMode.h diff --git a/main/modes/AbstractMenuMode.cpp b/main/modes/AbstractMenuMode.cpp new file mode 100644 index 0000000..26a43a3 --- /dev/null +++ b/main/modes/AbstractMenuMode.cpp @@ -0,0 +1,62 @@ +#include "core/common.h" +#include "core/buttons.h" +#include "core/display.h" +#include +#include "ModeRunner.h" +#include "ReaderMode.h" +#include "AbstractMenuMode.h" + +static int baseY = 35; +static int menuSkip = 20; +static int x = 40; +static int menu_options_size = 4; + +void draw_menu_option(char* text, int line, bool selected) +{ + EPD_print(text, CENTER, baseY + line * menuSkip); +} + +void draw_menu_cursor(int cursor) +{ + EPD_drawRect(x, baseY + cursor * menuSkip, + EPD_DISPLAY_WIDTH - 2*x, menuSkip + 1, 0x0F); +} + +void AbstractMenuMode::start() +{} + +void AbstractMenuMode::loop() +{ + display_clear(); + EPD_setFont(COMIC24_FONT, NULL); + EPD_print(this->getTitle(), CENTER, 0); + + int line = 0; + EPD_setFont(DEJAVU18_FONT, NULL); + char** options = this->getOptions(); + int menu_options_size = this->getOptionsSize(); + for (int line = 0; line < menu_options_size; line++) { + draw_menu_option(options[line], line, this->cursor == line); + } + draw_menu_cursor(this->cursor); + display_update(); + + while(1) { + delay(5); + if (buttons_pressed_ok()) { + this->onOptionSelected(this->cursor); + break; + } + if (buttons_pressed_minus()) { + this->cursor = (this->cursor + menu_options_size - 1) % menu_options_size; + break; + } + if (buttons_pressed_plus()) { + this->cursor = (this->cursor + 1) % menu_options_size; + break; + } + } +} + +void AbstractMenuMode::finish() +{} diff --git a/main/modes/AbstractMenuMode.h b/main/modes/AbstractMenuMode.h new file mode 100644 index 0000000..8f215d5 --- /dev/null +++ b/main/modes/AbstractMenuMode.h @@ -0,0 +1,22 @@ +#ifndef _ABSTRACTMENUMODE_H_ +#define _ABSTRACTMENUMODE_H_ +#include "AppMode.h" + +class AbstractMenuMode : public AppMode +{ +public: + virtual void start(); + virtual void loop(); + virtual void finish(); + +protected: + virtual char* getTitle(); + virtual char** getOptions(); + virtual int getOptionsSize(); + virtual void onOptionSelected(int option); + +private: + int cursor = 0; +}; + +#endif diff --git a/main/modes/InternalMemoryMenuMode.cpp b/main/modes/InternalMemoryMenuMode.cpp new file mode 100644 index 0000000..7319de8 --- /dev/null +++ b/main/modes/InternalMemoryMenuMode.cpp @@ -0,0 +1,40 @@ +#include "core/common.h" +#include "core/buttons.h" +#include "core/display.h" +#include +#include "InternalMemoryMenuMode.h" + +void InternalMemoryMenuMode::start() +{ + display_refresh(); +} + +void InternalMemoryMenuMode::loop() +{ + char text[1024]; + + //display_clear(); + EPD_setFont(COMIC24_FONT, NULL); + EPD_print("Internal Memory", CENTER, 00); + + EPD_setFont(DEJAVU18_FONT, NULL); + EPD_print("Current File:", 5, 30); + EPD_print("/spiffs/book.txt", 20, 50); + + EPD_print("Size:", 5, 80); + EPD_print("1234 kB", 100, 80); + + EPD_print("Position:", 5, 100); + EPD_print("45%", 100, 100); + display_update(); + + while (1) { + delay(10); + if (buttons_pressed_ok()) { + this->setFinished(); + break; + } + } +} +void InternalMemoryMenuMode::finish() +{} diff --git a/main/modes/InternalMemoryMenuMode.h b/main/modes/InternalMemoryMenuMode.h new file mode 100644 index 0000000..c7d509e --- /dev/null +++ b/main/modes/InternalMemoryMenuMode.h @@ -0,0 +1,11 @@ +#include "AppMode.h" + +class InternalMemoryMenuMode : public AppMode +{ +public: + virtual void start(); + virtual void loop(); + virtual void finish(); + +private: +}; diff --git a/main/modes/MainMenuMode.cpp b/main/modes/MainMenuMode.cpp index 1558cbe..b3eb00a 100644 --- a/main/modes/MainMenuMode.cpp +++ b/main/modes/MainMenuMode.cpp @@ -4,74 +4,56 @@ #include #include "ModeRunner.h" #include "ReaderMode.h" +#include "InternalMemoryMenuMode.h" +#include "SdCardMenuMode.h" +#include "SettingsMenuMode.h" #include "MainMenuMode.h" -static int baseY = 35; -static int menuSkip = 20; -static int x = 40; -static int menu_options_size = 4; - -void draw_menu_option(char* text, int line, bool selected) -{ - EPD_print(text, CENTER, baseY + line * menuSkip); -} - -void draw_menu_cursor(int cursor) -{ - EPD_drawRect(x, baseY + cursor * menuSkip, - EPD_DISPLAY_WIDTH - 2*x, menuSkip + 1, 0x0F); -} +static char* options[] = { + "Continue Reading", + "Internal Memory", + "SC Card", + "Settings" + }; void MainMenuMode::start() { display_refresh(); } -void MainMenuMode::loop() -{ - display_clear(); - EPD_setFont(COMIC24_FONT, NULL); - EPD_print("Main Menu", CENTER, 0); - - int line = 0; - EPD_setFont(DEJAVU18_FONT, NULL); - draw_menu_option("Continue Reading", line, this->cursor == line); line++; - draw_menu_option("Internal Memory", line, this->cursor == line); line++; - draw_menu_option("SD Card", line, this->cursor == line); line++; - draw_menu_option("Settings", line, this->cursor == line); line++; - draw_menu_cursor(this->cursor); - display_update(); - - while(1) { - delay(5); - if (buttons_pressed_ok()) { - switch (this->cursor) { - case 0: // reading - display_refresh(); - getModeRunner()->startInnerMode(new ReaderMode()); - return; - case 1: // memory - // TODO - break; - case 2: // sd card - // TODO - break; - case 3: // settings - // TODO - break; - } - break; - } - if (buttons_pressed_minus()) { - this->cursor = (this->cursor + menu_options_size - 1) % menu_options_size; - break; - } - if (buttons_pressed_plus()) { - this->cursor = (this->cursor + 1) % menu_options_size; - break; - } - } -} - void MainMenuMode::finish() {} + +char* MainMenuMode::getTitle() +{ + return "Main Menu"; +} + +char** MainMenuMode::getOptions() +{ + return options; +} + +int MainMenuMode::getOptionsSize() +{ + return 4; +} + +void MainMenuMode::onOptionSelected(int option) +{ + switch (option) { + case 0: // reading + display_refresh(); + getModeRunner()->startInnerMode(new ReaderMode()); + return; + case 1: // memory + getModeRunner()->startInnerMode(new InternalMemoryMenuMode()); + break; + case 2: // sd card + getModeRunner()->startInnerMode(new SdCardMenuMode()); + break; + case 3: // settings + getModeRunner()->startInnerMode(new SettingsMenuMode()); + break; + } +} diff --git a/main/modes/MainMenuMode.h b/main/modes/MainMenuMode.h index 7381b19..0e5415a 100644 --- a/main/modes/MainMenuMode.h +++ b/main/modes/MainMenuMode.h @@ -1,12 +1,17 @@ #include "AppMode.h" +#include "AbstractMenuMode.h" -class MainMenuMode : public AppMode +class MainMenuMode : public AbstractMenuMode { public: virtual void start(); - virtual void loop(); virtual void finish(); +protected: + virtual char* getTitle(); + virtual char** getOptions(); + virtual int getOptionsSize(); + virtual void onOptionSelected(int option); + private: - int cursor = 0; }; diff --git a/main/modes/SdCardMenuMode.cpp b/main/modes/SdCardMenuMode.cpp new file mode 100644 index 0000000..cd2e5ab --- /dev/null +++ b/main/modes/SdCardMenuMode.cpp @@ -0,0 +1,44 @@ +#include "core/common.h" +#include "core/buttons.h" +#include "core/display.h" +#include +#include "SdCardMenuMode.h" + +static char* options[] = { + "[Back]", + "/file.txt", + "/book.txt", + "/asdf.gif", + }; + +void SdCardMenuMode::start() +{ + display_refresh(); +} + +void SdCardMenuMode::finish() +{} + +char* SdCardMenuMode::getTitle() +{ + return "SD Card"; +} + +char** SdCardMenuMode::getOptions() +{ + return options; +} + +int SdCardMenuMode::getOptionsSize() +{ + return 4; +} + +void SdCardMenuMode::onOptionSelected(int option) +{ + if (option == 0) { + this->setFinished(); + return; + } + // TODO files +} diff --git a/main/modes/SdCardMenuMode.h b/main/modes/SdCardMenuMode.h new file mode 100644 index 0000000..a014c32 --- /dev/null +++ b/main/modes/SdCardMenuMode.h @@ -0,0 +1,17 @@ +#include "AppMode.h" +#include "AbstractMenuMode.h" + +class SdCardMenuMode : public AbstractMenuMode +{ +public: + virtual void start(); + virtual void finish(); + +protected: + virtual char* getTitle(); + virtual char** getOptions(); + virtual int getOptionsSize(); + virtual void onOptionSelected(int option); + +private: +}; diff --git a/main/modes/SettingsMenuMode.cpp b/main/modes/SettingsMenuMode.cpp new file mode 100644 index 0000000..b441abc --- /dev/null +++ b/main/modes/SettingsMenuMode.cpp @@ -0,0 +1,53 @@ +#include "core/common.h" +#include "core/buttons.h" +#include "core/display.h" +#include +#include "SettingsMenuMode.h" + +static char* options[] = { + "[Back]", + "Reader Option X", + "Reader Option Y", + "Reader Option Z", + }; + +void SettingsMenuMode::start() +{ + display_refresh(); +} + +void SettingsMenuMode::finish() +{} + +char* SettingsMenuMode::getTitle() +{ + return "Settings"; +} + +char** SettingsMenuMode::getOptions() +{ + return options; +} + +int SettingsMenuMode::getOptionsSize() +{ + return 4; +} + +void SettingsMenuMode::onOptionSelected(int option) +{ + switch (option) { + case 0: + // TODO + return; + case 1: + // TODO + break; + case 2: + // TODO + break; + case 3: + this->setFinished(); + break; + } +} diff --git a/main/modes/SettingsMenuMode.h b/main/modes/SettingsMenuMode.h new file mode 100644 index 0000000..39197a3 --- /dev/null +++ b/main/modes/SettingsMenuMode.h @@ -0,0 +1,17 @@ +#include "AppMode.h" +#include "AbstractMenuMode.h" + +class SettingsMenuMode : public AbstractMenuMode +{ +public: + virtual void start(); + virtual void finish(); + +protected: + virtual char* getTitle(); + virtual char** getOptions(); + virtual int getOptionsSize(); + virtual void onOptionSelected(int option); + +private: +};