Browse Source

Core mode trainsitions work. Boot > Menu > Reading > repeat

master
dejvino 4 years ago
parent
commit
8917b91a03
10 changed files with 97 additions and 21 deletions
  1. +1
    -1
      main/component.mk
  2. +2
    -0
      main/main.cpp
  3. +11
    -0
      main/modes/AppMode.h
  4. +1
    -1
      main/modes/BootMode.cpp
  5. +53
    -1
      main/modes/MainMenuMode.cpp
  6. +3
    -0
      main/modes/MainMenuMode.h
  7. +6
    -1
      main/modes/ModeRunner.cpp
  8. +6
    -15
      main/modes/ReaderMode.cpp
  9. +13
    -1
      main/modes/ReaderMode.h
  10. +1
    -1
      main/modes/reader/PagePrinter.cpp

+ 1
- 1
main/component.mk View File

@@ -3,5 +3,5 @@
# #
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.) # (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)


COMPONENT_SRCDIRS := . core modes
COMPONENT_SRCDIRS := . core modes modes/reader
COMPONENT_ADD_INCLUDEDIRS := . COMPONENT_ADD_INCLUDEDIRS := .

+ 2
- 0
main/main.cpp View File

@@ -20,6 +20,7 @@ static const char *TAG = "main";


#include "modes/ModeRunner.h" #include "modes/ModeRunner.h"
#include "modes/BootMode.h" #include "modes/BootMode.h"
#include "modes/MainMenuMode.h"




static struct tm* tm_info; static struct tm* tm_info;
@@ -46,6 +47,7 @@ extern "C" void app_main()


getModeRunner()->init(); getModeRunner()->init();
getModeRunner()->startMainMode(new BootMode()); getModeRunner()->startMainMode(new BootMode());

while (1) { while (1) {
getModeRunner()->loop(); getModeRunner()->loop();
} }


+ 11
- 0
main/modes/AppMode.h View File

@@ -7,6 +7,17 @@ public:
virtual void start(); virtual void start();
virtual void loop(); virtual void loop();
virtual void finish(); virtual void finish();
bool isFinished() {
return this->finished;
}

protected:
void setFinished() {
this->finished = true;
}

private:
bool finished = false;
}; };


#endif #endif

+ 1
- 1
main/modes/BootMode.cpp View File

@@ -10,7 +10,7 @@ void BootMode::start()
void BootMode::loop() void BootMode::loop()
{ {
display_splash_screen(); display_splash_screen();
delay(500);
delay(200);


getModeRunner()->startMainMode(new MainMenuMode()); getModeRunner()->startMainMode(new MainMenuMode());
} }


+ 53
- 1
main/modes/MainMenuMode.cpp View File

@@ -2,20 +2,72 @@
#include "core/buttons.h" #include "core/buttons.h"
#include "core/display.h" #include "core/display.h"
#include <EPD.h> #include <EPD.h>
#include "ModeRunner.h"
#include "ReaderMode.h"
#include "MainMenuMode.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);
}

void MainMenuMode::start() void MainMenuMode::start()
{}
{
display_refresh();
}


void MainMenuMode::loop() void MainMenuMode::loop()
{ {
display_clear(); display_clear();
EPD_setFont(COMIC24_FONT, NULL);
EPD_print("Main Menu", CENTER, 0); 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(); display_update();


while(1) { while(1) {
delay(5); delay(5);
if (buttons_pressed_ok()) { 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; break;
} }
} }


+ 3
- 0
main/modes/MainMenuMode.h View File

@@ -6,4 +6,7 @@ public:
virtual void start(); virtual void start();
virtual void loop(); virtual void loop();
virtual void finish(); virtual void finish();

private:
int cursor = 0;
}; };

+ 6
- 1
main/modes/ModeRunner.cpp View File

@@ -14,7 +14,12 @@ void ModeRunner::loop()
ESP_LOGE(TAG, "Cannot run app mode. None activated (depth %d).", this->modeStackDepth); ESP_LOGE(TAG, "Cannot run app mode. None activated (depth %d).", this->modeStackDepth);
return; return;
} }
this->modeStack[this->modeStackDepth]->loop();
AppMode* appMode = this->modeStack[this->modeStackDepth];
if (appMode->isFinished()) {
this->finishMode(appMode);
} else {
appMode->loop();
}
} }


void ModeRunner::startMainMode(AppMode* mode) void ModeRunner::startMainMode(AppMode* mode)


+ 6
- 15
main/modes/ReaderMode.cpp View File

@@ -2,27 +2,16 @@
#include "string.h" #include "string.h"
#include "core/buttons.h" #include "core/buttons.h"
#include "core/display.h" #include "core/display.h"
#include "reader/Typesetter.h"
#include "reader/TextStorage.h"
#include "reader/PagePrinter.h"
#include "ReaderMode.h" #include "ReaderMode.h"


#include "esp_log.h" #include "esp_log.h"
static const char *TAG = "ReaderMode"; static const char *TAG = "ReaderMode";


// TODO: class members
Typesetter typesetter;
PagePrinter pagePrinter;
TextStorage textStorage;
TextReader* textReader = textStorage.open("/sdcard/book.txt");
Page* pageLast = NULL;
Page* pageCurrent = NULL;

long bookmark = 0;
//bool displaySleeping = false; //bool displaySleeping = false;


void ReaderMode::start() void ReaderMode::start()
{ {
this->textReader = textStorage.open("/sdcard/book.txt");
} }


void ReaderMode::loop() void ReaderMode::loop()
@@ -60,8 +49,8 @@ void ReaderMode::loop()
while (1) { while (1) {
delay(10); delay(10);
if (buttons_pressed_ok()) { if (buttons_pressed_ok()) {
ESP_LOGI(TAG, "Clear page.");
display_refresh();
ESP_LOGI(TAG, "Exiting reader.");
this->setFinished();
break; break;
} }
if (buttons_pressed_plus()) { if (buttons_pressed_plus()) {
@@ -103,4 +92,6 @@ void ReaderMode::loop()
} }


void ReaderMode::finish() void ReaderMode::finish()
{}
{
textStorage.close(this->textReader);
}

+ 13
- 1
main/modes/ReaderMode.h View File

@@ -1,9 +1,21 @@
#include "AppMode.h" #include "AppMode.h"
#include "reader/Typesetter.h"
#include "reader/TextStorage.h"
#include "reader/PagePrinter.h"


class ReaderMode : AppMode
class ReaderMode : public AppMode
{ {
public: public:
virtual void start(); virtual void start();
virtual void loop(); virtual void loop();
virtual void finish(); virtual void finish();

private:
long bookmark = 0;
Typesetter typesetter;
PagePrinter pagePrinter;
TextStorage textStorage;
TextReader* textReader = NULL;
Page* pageLast = NULL;
Page* pageCurrent = NULL;
}; };

+ 1
- 1
main/modes/reader/PagePrinter.cpp View File

@@ -1,4 +1,4 @@
#include "display.h"
#include "core/display.h"
#include "EPD.h" #include "EPD.h"
#include "PagePrinter.h" #include "PagePrinter.h"




Loading…
Cancel
Save