@@ -0,0 +1,62 @@ | |||
#include "core/common.h" | |||
#include "core/buttons.h" | |||
#include "core/display.h" | |||
#include <EPD.h> | |||
#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() | |||
{} |
@@ -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 |
@@ -0,0 +1,40 @@ | |||
#include "core/common.h" | |||
#include "core/buttons.h" | |||
#include "core/display.h" | |||
#include <EPD.h> | |||
#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() | |||
{} |
@@ -0,0 +1,11 @@ | |||
#include "AppMode.h" | |||
class InternalMemoryMenuMode : public AppMode | |||
{ | |||
public: | |||
virtual void start(); | |||
virtual void loop(); | |||
virtual void finish(); | |||
private: | |||
}; |
@@ -4,74 +4,56 @@ | |||
#include <EPD.h> | |||
#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; | |||
static char* options[] = { | |||
"Continue Reading", | |||
"Internal Memory", | |||
"SC Card", | |||
"Settings" | |||
}; | |||
void draw_menu_option(char* text, int line, bool selected) | |||
void MainMenuMode::start() | |||
{ | |||
EPD_print(text, CENTER, baseY + line * menuSkip); | |||
display_refresh(); | |||
} | |||
void draw_menu_cursor(int cursor) | |||
void MainMenuMode::finish() | |||
{} | |||
char* MainMenuMode::getTitle() | |||
{ | |||
EPD_drawRect(x, baseY + cursor * menuSkip, | |||
EPD_DISPLAY_WIDTH - 2*x, menuSkip + 1, 0x0F); | |||
return "Main Menu"; | |||
} | |||
void MainMenuMode::start() | |||
char** MainMenuMode::getOptions() | |||
{ | |||
display_refresh(); | |||
return options; | |||
} | |||
void MainMenuMode::loop() | |||
int MainMenuMode::getOptionsSize() | |||
{ | |||
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(); | |||
return 4; | |||
} | |||
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; | |||
} | |||
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; | |||
} | |||
if (buttons_pressed_minus()) { | |||
this->cursor = (this->cursor + menu_options_size - 1) % menu_options_size; | |||
case 2: // sd card | |||
getModeRunner()->startInnerMode(new SdCardMenuMode()); | |||
break; | |||
} | |||
if (buttons_pressed_plus()) { | |||
this->cursor = (this->cursor + 1) % menu_options_size; | |||
case 3: // settings | |||
getModeRunner()->startInnerMode(new SettingsMenuMode()); | |||
break; | |||
} | |||
} | |||
} | |||
void MainMenuMode::finish() | |||
{} |
@@ -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; | |||
}; |
@@ -0,0 +1,44 @@ | |||
#include "core/common.h" | |||
#include "core/buttons.h" | |||
#include "core/display.h" | |||
#include <EPD.h> | |||
#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 | |||
} |
@@ -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: | |||
}; |
@@ -0,0 +1,53 @@ | |||
#include "core/common.h" | |||
#include "core/buttons.h" | |||
#include "core/display.h" | |||
#include <EPD.h> | |||
#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; | |||
} | |||
} |
@@ -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: | |||
}; |