1
0
mirror of https://github.com/Dejvino/lilybook.git synced 2024-12-22 19:48:50 +00:00

Added memory, sd card and settings menus.

This commit is contained in:
dejvino 2020-02-02 17:14:45 +01:00
parent 8917b91a03
commit d93fc4b4c7
10 changed files with 317 additions and 64 deletions

View File

@ -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()
{}

View File

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

View File

@ -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()
{}

View File

@ -0,0 +1,11 @@
#include "AppMode.h"
class InternalMemoryMenuMode : public AppMode
{
public:
virtual void start();
virtual void loop();
virtual void finish();
private:
};

View File

@ -4,74 +4,56 @@
#include <EPD.h> #include <EPD.h>
#include "ModeRunner.h" #include "ModeRunner.h"
#include "ReaderMode.h" #include "ReaderMode.h"
#include "InternalMemoryMenuMode.h"
#include "SdCardMenuMode.h"
#include "SettingsMenuMode.h"
#include "MainMenuMode.h" #include "MainMenuMode.h"
static int baseY = 35; static char* options[] = {
static int menuSkip = 20; "Continue Reading",
static int x = 40; "Internal Memory",
static int menu_options_size = 4; "SC Card",
"Settings"
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 MainMenuMode::start() void MainMenuMode::start()
{ {
display_refresh(); display_refresh();
} }
void MainMenuMode::loop() void MainMenuMode::finish()
{}
char* MainMenuMode::getTitle()
{ {
display_clear(); return "Main Menu";
EPD_setFont(COMIC24_FONT, NULL); }
EPD_print("Main Menu", CENTER, 0);
int line = 0; char** MainMenuMode::getOptions()
EPD_setFont(DEJAVU18_FONT, NULL); {
draw_menu_option("Continue Reading", line, this->cursor == line); line++; return options;
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) { int MainMenuMode::getOptionsSize()
delay(5); {
if (buttons_pressed_ok()) { return 4;
switch (this->cursor) { }
void MainMenuMode::onOptionSelected(int option)
{
switch (option) {
case 0: // reading case 0: // reading
display_refresh(); display_refresh();
getModeRunner()->startInnerMode(new ReaderMode()); getModeRunner()->startInnerMode(new ReaderMode());
return; return;
case 1: // memory case 1: // memory
// TODO getModeRunner()->startInnerMode(new InternalMemoryMenuMode());
break; break;
case 2: // sd card case 2: // sd card
// TODO getModeRunner()->startInnerMode(new SdCardMenuMode());
break; break;
case 3: // settings case 3: // settings
// TODO getModeRunner()->startInnerMode(new SettingsMenuMode());
break; 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()
{}

View File

@ -1,12 +1,17 @@
#include "AppMode.h" #include "AppMode.h"
#include "AbstractMenuMode.h"
class MainMenuMode : public AppMode class MainMenuMode : public AbstractMenuMode
{ {
public: public:
virtual void start(); virtual void start();
virtual void loop();
virtual void finish(); virtual void finish();
protected:
virtual char* getTitle();
virtual char** getOptions();
virtual int getOptionsSize();
virtual void onOptionSelected(int option);
private: private:
int cursor = 0;
}; };

View File

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

View File

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

View File

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

View File

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