mirror of
https://github.com/Dejvino/lilybook.git
synced 2024-12-04 19:58:50 +00:00
Added memory, sd card and settings menus.
This commit is contained in:
parent
8917b91a03
commit
d93fc4b4c7
62
main/modes/AbstractMenuMode.cpp
Normal file
62
main/modes/AbstractMenuMode.cpp
Normal 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()
|
||||
{}
|
22
main/modes/AbstractMenuMode.h
Normal file
22
main/modes/AbstractMenuMode.h
Normal 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
|
40
main/modes/InternalMemoryMenuMode.cpp
Normal file
40
main/modes/InternalMemoryMenuMode.cpp
Normal 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()
|
||||
{}
|
11
main/modes/InternalMemoryMenuMode.h
Normal file
11
main/modes/InternalMemoryMenuMode.h
Normal file
@ -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;
|
||||
|
||||
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()
|
||||
void MainMenuMode::finish()
|
||||
{}
|
||||
|
||||
char* MainMenuMode::getTitle()
|
||||
{
|
||||
display_clear();
|
||||
EPD_setFont(COMIC24_FONT, NULL);
|
||||
EPD_print("Main Menu", CENTER, 0);
|
||||
return "Main Menu";
|
||||
}
|
||||
|
||||
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();
|
||||
char** MainMenuMode::getOptions()
|
||||
{
|
||||
return options;
|
||||
}
|
||||
|
||||
while(1) {
|
||||
delay(5);
|
||||
if (buttons_pressed_ok()) {
|
||||
switch (this->cursor) {
|
||||
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
|
||||
// TODO
|
||||
getModeRunner()->startInnerMode(new InternalMemoryMenuMode());
|
||||
break;
|
||||
case 2: // sd card
|
||||
// TODO
|
||||
getModeRunner()->startInnerMode(new SdCardMenuMode());
|
||||
break;
|
||||
case 3: // settings
|
||||
// TODO
|
||||
getModeRunner()->startInnerMode(new SettingsMenuMode());
|
||||
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()
|
||||
{}
|
||||
|
@ -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;
|
||||
};
|
||||
|
44
main/modes/SdCardMenuMode.cpp
Normal file
44
main/modes/SdCardMenuMode.cpp
Normal 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
|
||||
}
|
17
main/modes/SdCardMenuMode.h
Normal file
17
main/modes/SdCardMenuMode.h
Normal 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:
|
||||
};
|
53
main/modes/SettingsMenuMode.cpp
Normal file
53
main/modes/SettingsMenuMode.cpp
Normal 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;
|
||||
}
|
||||
}
|
17
main/modes/SettingsMenuMode.h
Normal file
17
main/modes/SettingsMenuMode.h
Normal 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:
|
||||
};
|
Loading…
Reference in New Issue
Block a user