mirror of
https://github.com/crosspoint-reader/crosspoint-reader.git
synced 2026-04-29 10:26:52 -07:00
Rename Screens to Activities and restructure files (#44)
## Summary
* This PR drastically reshapes the structure of the codebase, moving
from the concept of "Screens" to "Activities", restructing the files and
setting up the concept of subactivities.
* This should help with keep the main file clean and containing all
functional logic in the relevant activity.
* CrossPointState is now also a global singleton which should help with
accessing it from within activities.
## Additional Context
* This is probably going to be a bit disruptive for people with open
PRs, sorry 😞
This commit is contained in:
@@ -3,7 +3,9 @@
|
||||
#include <HardwareSerial.h>
|
||||
#include <Serialization.h>
|
||||
|
||||
namespace {
|
||||
constexpr uint8_t PAGE_FILE_VERSION = 3;
|
||||
}
|
||||
|
||||
void PageLine::render(GfxRenderer& renderer, const int fontId) { block->render(renderer, fontId, xPos, yPos); }
|
||||
|
||||
|
||||
@@ -9,7 +9,9 @@
|
||||
#include "Page.h"
|
||||
#include "parsers/ChapterHtmlSlimParser.h"
|
||||
|
||||
namespace {
|
||||
constexpr uint8_t SECTION_FILE_VERSION = 5;
|
||||
}
|
||||
|
||||
void Section::onPageComplete(std::unique_ptr<Page> page) {
|
||||
const auto filePath = cachePath + "/page_" + std::to_string(pageCount) + ".bin";
|
||||
|
||||
@@ -10,9 +10,11 @@
|
||||
// Initialize the static instance
|
||||
CrossPointSettings CrossPointSettings::instance;
|
||||
|
||||
namespace {
|
||||
constexpr uint8_t SETTINGS_FILE_VERSION = 1;
|
||||
constexpr uint8_t SETTINGS_COUNT = 2;
|
||||
constexpr char SETTINGS_FILE[] = "/sd/.crosspoint/settings.bin";
|
||||
} // namespace
|
||||
|
||||
bool CrossPointSettings::saveToFile() const {
|
||||
// Make sure the directory exists
|
||||
|
||||
@@ -6,8 +6,12 @@
|
||||
|
||||
#include <fstream>
|
||||
|
||||
namespace {
|
||||
constexpr uint8_t STATE_FILE_VERSION = 1;
|
||||
constexpr char STATE_FILE[] = "/sd/.crosspoint/state.bin";
|
||||
} // namespace
|
||||
|
||||
CrossPointState CrossPointState::instance;
|
||||
|
||||
bool CrossPointState::saveToFile() const {
|
||||
std::ofstream outputFile(STATE_FILE);
|
||||
|
||||
@@ -3,11 +3,20 @@
|
||||
#include <string>
|
||||
|
||||
class CrossPointState {
|
||||
// Static instance
|
||||
static CrossPointState instance;
|
||||
|
||||
public:
|
||||
std::string openEpubPath;
|
||||
~CrossPointState() = default;
|
||||
|
||||
// Get singleton instance
|
||||
static CrossPointState& getInstance() { return instance; }
|
||||
|
||||
bool saveToFile() const;
|
||||
|
||||
bool loadFromFile();
|
||||
};
|
||||
|
||||
// Helper macro to access settings
|
||||
#define APP_STATE CrossPointState::getInstance()
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
#include <InputManager.h>
|
||||
|
||||
class GfxRenderer;
|
||||
|
||||
class Activity {
|
||||
protected:
|
||||
GfxRenderer& renderer;
|
||||
InputManager& inputManager;
|
||||
|
||||
public:
|
||||
explicit Activity(GfxRenderer& renderer, InputManager& inputManager)
|
||||
: renderer(renderer), inputManager(inputManager) {}
|
||||
virtual ~Activity() = default;
|
||||
virtual void onEnter() {}
|
||||
virtual void onExit() {}
|
||||
virtual void loop() {}
|
||||
};
|
||||
@@ -0,0 +1,21 @@
|
||||
#include "ActivityWithSubactivity.h"
|
||||
|
||||
void ActivityWithSubactivity::exitActivity() {
|
||||
if (subActivity) {
|
||||
subActivity->onExit();
|
||||
subActivity.reset();
|
||||
}
|
||||
}
|
||||
|
||||
void ActivityWithSubactivity::enterNewActivity(Activity* activity) {
|
||||
subActivity.reset(activity);
|
||||
subActivity->onEnter();
|
||||
}
|
||||
|
||||
void ActivityWithSubactivity::loop() {
|
||||
if (subActivity) {
|
||||
subActivity->loop();
|
||||
}
|
||||
}
|
||||
|
||||
void ActivityWithSubactivity::onExit() { exitActivity(); }
|
||||
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
#include <memory>
|
||||
|
||||
#include "Activity.h"
|
||||
|
||||
class ActivityWithSubactivity : public Activity {
|
||||
protected:
|
||||
std::unique_ptr<Activity> subActivity = nullptr;
|
||||
void exitActivity();
|
||||
void enterNewActivity(Activity* activity);
|
||||
|
||||
public:
|
||||
explicit ActivityWithSubactivity(GfxRenderer& renderer, InputManager& inputManager)
|
||||
: Activity(renderer, inputManager) {}
|
||||
void loop() override;
|
||||
void onExit() override;
|
||||
};
|
||||
@@ -1,11 +1,11 @@
|
||||
#include "BootLogoScreen.h"
|
||||
#include "BootActivity.h"
|
||||
|
||||
#include <GfxRenderer.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "images/CrossLarge.h"
|
||||
|
||||
void BootLogoScreen::onEnter() {
|
||||
void BootActivity::onEnter() {
|
||||
const auto pageWidth = GfxRenderer::getScreenWidth();
|
||||
const auto pageHeight = GfxRenderer::getScreenHeight();
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
#include "../Activity.h"
|
||||
|
||||
class BootActivity final : public Activity {
|
||||
public:
|
||||
explicit BootActivity(GfxRenderer& renderer, InputManager& inputManager) : Activity(renderer, inputManager) {}
|
||||
void onEnter() override;
|
||||
};
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "SleepScreen.h"
|
||||
#include "SleepActivity.h"
|
||||
|
||||
#include <GfxRenderer.h>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include "config.h"
|
||||
#include "images/CrossLarge.h"
|
||||
|
||||
void SleepScreen::onEnter() {
|
||||
void SleepActivity::onEnter() {
|
||||
const auto pageWidth = GfxRenderer::getScreenWidth();
|
||||
const auto pageHeight = GfxRenderer::getScreenHeight();
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
#include "../Activity.h"
|
||||
|
||||
class SleepActivity final : public Activity {
|
||||
public:
|
||||
explicit SleepActivity(GfxRenderer& renderer, InputManager& inputManager) : Activity(renderer, inputManager) {}
|
||||
void onEnter() override;
|
||||
};
|
||||
@@ -1,16 +1,20 @@
|
||||
#include "HomeScreen.h"
|
||||
#include "HomeActivity.h"
|
||||
|
||||
#include <GfxRenderer.h>
|
||||
#include <SD.h>
|
||||
|
||||
#include "config.h"
|
||||
|
||||
void HomeScreen::taskTrampoline(void* param) {
|
||||
auto* self = static_cast<HomeScreen*>(param);
|
||||
namespace {
|
||||
constexpr int menuItemCount = 2;
|
||||
}
|
||||
|
||||
void HomeActivity::taskTrampoline(void* param) {
|
||||
auto* self = static_cast<HomeActivity*>(param);
|
||||
self->displayTaskLoop();
|
||||
}
|
||||
|
||||
void HomeScreen::onEnter() {
|
||||
void HomeActivity::onEnter() {
|
||||
renderingMutex = xSemaphoreCreateMutex();
|
||||
|
||||
selectorIndex = 0;
|
||||
@@ -18,7 +22,7 @@ void HomeScreen::onEnter() {
|
||||
// Trigger first update
|
||||
updateRequired = true;
|
||||
|
||||
xTaskCreate(&HomeScreen::taskTrampoline, "HomeScreenTask",
|
||||
xTaskCreate(&HomeActivity::taskTrampoline, "HomeActivityTask",
|
||||
2048, // Stack size
|
||||
this, // Parameters
|
||||
1, // Priority
|
||||
@@ -26,7 +30,7 @@ void HomeScreen::onEnter() {
|
||||
);
|
||||
}
|
||||
|
||||
void HomeScreen::onExit() {
|
||||
void HomeActivity::onExit() {
|
||||
// Wait until not rendering to delete task to avoid killing mid-instruction to EPD
|
||||
xSemaphoreTake(renderingMutex, portMAX_DELAY);
|
||||
if (displayTaskHandle) {
|
||||
@@ -37,7 +41,7 @@ void HomeScreen::onExit() {
|
||||
renderingMutex = nullptr;
|
||||
}
|
||||
|
||||
void HomeScreen::handleInput() {
|
||||
void HomeActivity::loop() {
|
||||
const bool prevPressed =
|
||||
inputManager.wasPressed(InputManager::BTN_UP) || inputManager.wasPressed(InputManager::BTN_LEFT);
|
||||
const bool nextPressed =
|
||||
@@ -45,7 +49,7 @@ void HomeScreen::handleInput() {
|
||||
|
||||
if (inputManager.wasPressed(InputManager::BTN_CONFIRM)) {
|
||||
if (selectorIndex == 0) {
|
||||
onFileSelectionOpen();
|
||||
onReaderOpen();
|
||||
} else if (selectorIndex == 1) {
|
||||
onSettingsOpen();
|
||||
}
|
||||
@@ -58,7 +62,7 @@ void HomeScreen::handleInput() {
|
||||
}
|
||||
}
|
||||
|
||||
void HomeScreen::displayTaskLoop() {
|
||||
void HomeActivity::displayTaskLoop() {
|
||||
while (true) {
|
||||
if (updateRequired) {
|
||||
updateRequired = false;
|
||||
@@ -70,7 +74,7 @@ void HomeScreen::displayTaskLoop() {
|
||||
}
|
||||
}
|
||||
|
||||
void HomeScreen::render() const {
|
||||
void HomeActivity::render() const {
|
||||
renderer.clearScreen();
|
||||
|
||||
const auto pageWidth = GfxRenderer::getScreenWidth();
|
||||
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/semphr.h>
|
||||
#include <freertos/task.h>
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include "../Activity.h"
|
||||
|
||||
class HomeActivity final : public Activity {
|
||||
TaskHandle_t displayTaskHandle = nullptr;
|
||||
SemaphoreHandle_t renderingMutex = nullptr;
|
||||
int selectorIndex = 0;
|
||||
bool updateRequired = false;
|
||||
const std::function<void()> onReaderOpen;
|
||||
const std::function<void()> onSettingsOpen;
|
||||
|
||||
static void taskTrampoline(void* param);
|
||||
[[noreturn]] void displayTaskLoop();
|
||||
void render() const;
|
||||
|
||||
public:
|
||||
explicit HomeActivity(GfxRenderer& renderer, InputManager& inputManager, const std::function<void()>& onReaderOpen,
|
||||
const std::function<void()>& onSettingsOpen)
|
||||
: Activity(renderer, inputManager), onReaderOpen(onReaderOpen), onSettingsOpen(onSettingsOpen) {}
|
||||
void onEnter() override;
|
||||
void onExit() override;
|
||||
void loop() override;
|
||||
};
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "EpubReaderScreen.h"
|
||||
#include "EpubReaderActivity.h"
|
||||
|
||||
#include <Epub/Page.h>
|
||||
#include <GfxRenderer.h>
|
||||
@@ -6,23 +6,25 @@
|
||||
|
||||
#include "Battery.h"
|
||||
#include "CrossPointSettings.h"
|
||||
#include "EpubReaderChapterSelectionScreen.h"
|
||||
#include "EpubReaderChapterSelectionActivity.h"
|
||||
#include "config.h"
|
||||
|
||||
constexpr int PAGES_PER_REFRESH = 15;
|
||||
constexpr unsigned long SKIP_CHAPTER_MS = 700;
|
||||
namespace {
|
||||
constexpr int pagesPerRefresh = 15;
|
||||
constexpr unsigned long skipChapterMs = 700;
|
||||
constexpr float lineCompression = 0.95f;
|
||||
constexpr int marginTop = 8;
|
||||
constexpr int marginRight = 10;
|
||||
constexpr int marginBottom = 22;
|
||||
constexpr int marginLeft = 10;
|
||||
} // namespace
|
||||
|
||||
void EpubReaderScreen::taskTrampoline(void* param) {
|
||||
auto* self = static_cast<EpubReaderScreen*>(param);
|
||||
void EpubReaderActivity::taskTrampoline(void* param) {
|
||||
auto* self = static_cast<EpubReaderActivity*>(param);
|
||||
self->displayTaskLoop();
|
||||
}
|
||||
|
||||
void EpubReaderScreen::onEnter() {
|
||||
void EpubReaderActivity::onEnter() {
|
||||
if (!epub) {
|
||||
return;
|
||||
}
|
||||
@@ -44,7 +46,7 @@ void EpubReaderScreen::onEnter() {
|
||||
// Trigger first update
|
||||
updateRequired = true;
|
||||
|
||||
xTaskCreate(&EpubReaderScreen::taskTrampoline, "EpubReaderScreenTask",
|
||||
xTaskCreate(&EpubReaderActivity::taskTrampoline, "EpubReaderActivityTask",
|
||||
8192, // Stack size
|
||||
this, // Parameters
|
||||
1, // Priority
|
||||
@@ -52,7 +54,7 @@ void EpubReaderScreen::onEnter() {
|
||||
);
|
||||
}
|
||||
|
||||
void EpubReaderScreen::onExit() {
|
||||
void EpubReaderActivity::onExit() {
|
||||
// Wait until not rendering to delete task to avoid killing mid-instruction to EPD
|
||||
xSemaphoreTake(renderingMutex, portMAX_DELAY);
|
||||
if (displayTaskHandle) {
|
||||
@@ -65,22 +67,22 @@ void EpubReaderScreen::onExit() {
|
||||
epub.reset();
|
||||
}
|
||||
|
||||
void EpubReaderScreen::handleInput() {
|
||||
// Pass input responsibility to sub screen if exists
|
||||
if (subScreen) {
|
||||
subScreen->handleInput();
|
||||
void EpubReaderActivity::loop() {
|
||||
// Pass input responsibility to sub activity if exists
|
||||
if (subAcitivity) {
|
||||
subAcitivity->loop();
|
||||
return;
|
||||
}
|
||||
|
||||
// Enter chapter selection screen
|
||||
// Enter chapter selection activity
|
||||
if (inputManager.wasPressed(InputManager::BTN_CONFIRM)) {
|
||||
// Don't start screen transition while rendering
|
||||
// Don't start activity transition while rendering
|
||||
xSemaphoreTake(renderingMutex, portMAX_DELAY);
|
||||
subScreen.reset(new EpubReaderChapterSelectionScreen(
|
||||
subAcitivity.reset(new EpubReaderChapterSelectionActivity(
|
||||
this->renderer, this->inputManager, epub, currentSpineIndex,
|
||||
[this] {
|
||||
subScreen->onExit();
|
||||
subScreen.reset();
|
||||
subAcitivity->onExit();
|
||||
subAcitivity.reset();
|
||||
updateRequired = true;
|
||||
},
|
||||
[this](const int newSpineIndex) {
|
||||
@@ -89,11 +91,11 @@ void EpubReaderScreen::handleInput() {
|
||||
nextPageNumber = 0;
|
||||
section.reset();
|
||||
}
|
||||
subScreen->onExit();
|
||||
subScreen.reset();
|
||||
subAcitivity->onExit();
|
||||
subAcitivity.reset();
|
||||
updateRequired = true;
|
||||
}));
|
||||
subScreen->onEnter();
|
||||
subAcitivity->onEnter();
|
||||
xSemaphoreGive(renderingMutex);
|
||||
}
|
||||
|
||||
@@ -119,7 +121,7 @@ void EpubReaderScreen::handleInput() {
|
||||
return;
|
||||
}
|
||||
|
||||
const bool skipChapter = inputManager.getHeldTime() > SKIP_CHAPTER_MS;
|
||||
const bool skipChapter = inputManager.getHeldTime() > skipChapterMs;
|
||||
|
||||
if (skipChapter) {
|
||||
// We don't want to delete the section mid-render, so grab the semaphore
|
||||
@@ -165,7 +167,7 @@ void EpubReaderScreen::handleInput() {
|
||||
}
|
||||
}
|
||||
|
||||
void EpubReaderScreen::displayTaskLoop() {
|
||||
void EpubReaderActivity::displayTaskLoop() {
|
||||
while (true) {
|
||||
if (updateRequired) {
|
||||
updateRequired = false;
|
||||
@@ -178,7 +180,7 @@ void EpubReaderScreen::displayTaskLoop() {
|
||||
}
|
||||
|
||||
// TODO: Failure handling
|
||||
void EpubReaderScreen::renderScreen() {
|
||||
void EpubReaderActivity::renderScreen() {
|
||||
if (!epub) {
|
||||
return;
|
||||
}
|
||||
@@ -285,12 +287,12 @@ void EpubReaderScreen::renderScreen() {
|
||||
f.close();
|
||||
}
|
||||
|
||||
void EpubReaderScreen::renderContents(std::unique_ptr<Page> page) {
|
||||
void EpubReaderActivity::renderContents(std::unique_ptr<Page> page) {
|
||||
page->render(renderer, READER_FONT_ID);
|
||||
renderStatusBar();
|
||||
if (pagesUntilFullRefresh <= 1) {
|
||||
renderer.displayBuffer(EInkDisplay::HALF_REFRESH);
|
||||
pagesUntilFullRefresh = PAGES_PER_REFRESH;
|
||||
pagesUntilFullRefresh = pagesPerRefresh;
|
||||
} else {
|
||||
renderer.displayBuffer();
|
||||
pagesUntilFullRefresh--;
|
||||
@@ -322,7 +324,7 @@ void EpubReaderScreen::renderContents(std::unique_ptr<Page> page) {
|
||||
renderer.restoreBwBuffer();
|
||||
}
|
||||
|
||||
void EpubReaderScreen::renderStatusBar() const {
|
||||
void EpubReaderActivity::renderStatusBar() const {
|
||||
constexpr auto textY = 776;
|
||||
|
||||
// Calculate progress in book
|
||||
@@ -5,14 +5,14 @@
|
||||
#include <freertos/semphr.h>
|
||||
#include <freertos/task.h>
|
||||
|
||||
#include "Screen.h"
|
||||
#include "../Activity.h"
|
||||
|
||||
class EpubReaderScreen final : public Screen {
|
||||
class EpubReaderActivity final : public Activity {
|
||||
std::shared_ptr<Epub> epub;
|
||||
std::unique_ptr<Section> section = nullptr;
|
||||
TaskHandle_t displayTaskHandle = nullptr;
|
||||
SemaphoreHandle_t renderingMutex = nullptr;
|
||||
std::unique_ptr<Screen> subScreen = nullptr;
|
||||
std::unique_ptr<Activity> subAcitivity = nullptr;
|
||||
int currentSpineIndex = 0;
|
||||
int nextPageNumber = 0;
|
||||
int pagesUntilFullRefresh = 0;
|
||||
@@ -26,10 +26,10 @@ class EpubReaderScreen final : public Screen {
|
||||
void renderStatusBar() const;
|
||||
|
||||
public:
|
||||
explicit EpubReaderScreen(GfxRenderer& renderer, InputManager& inputManager, std::unique_ptr<Epub> epub,
|
||||
const std::function<void()>& onGoBack)
|
||||
: Screen(renderer, inputManager), epub(std::move(epub)), onGoBack(onGoBack) {}
|
||||
explicit EpubReaderActivity(GfxRenderer& renderer, InputManager& inputManager, std::unique_ptr<Epub> epub,
|
||||
const std::function<void()>& onGoBack)
|
||||
: Activity(renderer, inputManager), epub(std::move(epub)), onGoBack(onGoBack) {}
|
||||
void onEnter() override;
|
||||
void onExit() override;
|
||||
void handleInput() override;
|
||||
void loop() override;
|
||||
};
|
||||
+9
-9
@@ -1,4 +1,4 @@
|
||||
#include "EpubReaderChapterSelectionScreen.h"
|
||||
#include "EpubReaderChapterSelectionActivity.h"
|
||||
|
||||
#include <GfxRenderer.h>
|
||||
#include <SD.h>
|
||||
@@ -8,12 +8,12 @@
|
||||
constexpr int PAGE_ITEMS = 24;
|
||||
constexpr int SKIP_PAGE_MS = 700;
|
||||
|
||||
void EpubReaderChapterSelectionScreen::taskTrampoline(void* param) {
|
||||
auto* self = static_cast<EpubReaderChapterSelectionScreen*>(param);
|
||||
void EpubReaderChapterSelectionActivity::taskTrampoline(void* param) {
|
||||
auto* self = static_cast<EpubReaderChapterSelectionActivity*>(param);
|
||||
self->displayTaskLoop();
|
||||
}
|
||||
|
||||
void EpubReaderChapterSelectionScreen::onEnter() {
|
||||
void EpubReaderChapterSelectionActivity::onEnter() {
|
||||
if (!epub) {
|
||||
return;
|
||||
}
|
||||
@@ -23,7 +23,7 @@ void EpubReaderChapterSelectionScreen::onEnter() {
|
||||
|
||||
// Trigger first update
|
||||
updateRequired = true;
|
||||
xTaskCreate(&EpubReaderChapterSelectionScreen::taskTrampoline, "EpubReaderChapterSelectionScreenTask",
|
||||
xTaskCreate(&EpubReaderChapterSelectionActivity::taskTrampoline, "EpubReaderChapterSelectionActivityTask",
|
||||
2048, // Stack size
|
||||
this, // Parameters
|
||||
1, // Priority
|
||||
@@ -31,7 +31,7 @@ void EpubReaderChapterSelectionScreen::onEnter() {
|
||||
);
|
||||
}
|
||||
|
||||
void EpubReaderChapterSelectionScreen::onExit() {
|
||||
void EpubReaderChapterSelectionActivity::onExit() {
|
||||
// Wait until not rendering to delete task to avoid killing mid-instruction to EPD
|
||||
xSemaphoreTake(renderingMutex, portMAX_DELAY);
|
||||
if (displayTaskHandle) {
|
||||
@@ -42,7 +42,7 @@ void EpubReaderChapterSelectionScreen::onExit() {
|
||||
renderingMutex = nullptr;
|
||||
}
|
||||
|
||||
void EpubReaderChapterSelectionScreen::handleInput() {
|
||||
void EpubReaderChapterSelectionActivity::loop() {
|
||||
const bool prevReleased =
|
||||
inputManager.wasReleased(InputManager::BTN_UP) || inputManager.wasReleased(InputManager::BTN_LEFT);
|
||||
const bool nextReleased =
|
||||
@@ -72,7 +72,7 @@ void EpubReaderChapterSelectionScreen::handleInput() {
|
||||
}
|
||||
}
|
||||
|
||||
void EpubReaderChapterSelectionScreen::displayTaskLoop() {
|
||||
void EpubReaderChapterSelectionActivity::displayTaskLoop() {
|
||||
while (true) {
|
||||
if (updateRequired) {
|
||||
updateRequired = false;
|
||||
@@ -84,7 +84,7 @@ void EpubReaderChapterSelectionScreen::displayTaskLoop() {
|
||||
}
|
||||
}
|
||||
|
||||
void EpubReaderChapterSelectionScreen::renderScreen() {
|
||||
void EpubReaderChapterSelectionActivity::renderScreen() {
|
||||
renderer.clearScreen();
|
||||
|
||||
const auto pageWidth = renderer.getScreenWidth();
|
||||
+8
-8
@@ -6,9 +6,9 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "Screen.h"
|
||||
#include "../Activity.h"
|
||||
|
||||
class EpubReaderChapterSelectionScreen final : public Screen {
|
||||
class EpubReaderChapterSelectionActivity final : public Activity {
|
||||
std::shared_ptr<Epub> epub;
|
||||
TaskHandle_t displayTaskHandle = nullptr;
|
||||
SemaphoreHandle_t renderingMutex = nullptr;
|
||||
@@ -23,16 +23,16 @@ class EpubReaderChapterSelectionScreen final : public Screen {
|
||||
void renderScreen();
|
||||
|
||||
public:
|
||||
explicit EpubReaderChapterSelectionScreen(GfxRenderer& renderer, InputManager& inputManager,
|
||||
const std::shared_ptr<Epub>& epub, const int currentSpineIndex,
|
||||
const std::function<void()>& onGoBack,
|
||||
const std::function<void(int newSpineIndex)>& onSelectSpineIndex)
|
||||
: Screen(renderer, inputManager),
|
||||
explicit EpubReaderChapterSelectionActivity(GfxRenderer& renderer, InputManager& inputManager,
|
||||
const std::shared_ptr<Epub>& epub, const int currentSpineIndex,
|
||||
const std::function<void()>& onGoBack,
|
||||
const std::function<void(int newSpineIndex)>& onSelectSpineIndex)
|
||||
: Activity(renderer, inputManager),
|
||||
epub(epub),
|
||||
currentSpineIndex(currentSpineIndex),
|
||||
onGoBack(onGoBack),
|
||||
onSelectSpineIndex(onSelectSpineIndex) {}
|
||||
void onEnter() override;
|
||||
void onExit() override;
|
||||
void handleInput() override;
|
||||
void loop() override;
|
||||
};
|
||||
+10
-10
@@ -1,4 +1,4 @@
|
||||
#include "FileSelectionScreen.h"
|
||||
#include "FileSelectionActivity.h"
|
||||
|
||||
#include <GfxRenderer.h>
|
||||
#include <SD.h>
|
||||
@@ -15,12 +15,12 @@ void sortFileList(std::vector<std::string>& strs) {
|
||||
});
|
||||
}
|
||||
|
||||
void FileSelectionScreen::taskTrampoline(void* param) {
|
||||
auto* self = static_cast<FileSelectionScreen*>(param);
|
||||
void FileSelectionActivity::taskTrampoline(void* param) {
|
||||
auto* self = static_cast<FileSelectionActivity*>(param);
|
||||
self->displayTaskLoop();
|
||||
}
|
||||
|
||||
void FileSelectionScreen::loadFiles() {
|
||||
void FileSelectionActivity::loadFiles() {
|
||||
files.clear();
|
||||
selectorIndex = 0;
|
||||
auto root = SD.open(basepath.c_str());
|
||||
@@ -42,7 +42,7 @@ void FileSelectionScreen::loadFiles() {
|
||||
sortFileList(files);
|
||||
}
|
||||
|
||||
void FileSelectionScreen::onEnter() {
|
||||
void FileSelectionActivity::onEnter() {
|
||||
renderingMutex = xSemaphoreCreateMutex();
|
||||
|
||||
basepath = "/";
|
||||
@@ -52,7 +52,7 @@ void FileSelectionScreen::onEnter() {
|
||||
// Trigger first update
|
||||
updateRequired = true;
|
||||
|
||||
xTaskCreate(&FileSelectionScreen::taskTrampoline, "FileSelectionScreenTask",
|
||||
xTaskCreate(&FileSelectionActivity::taskTrampoline, "FileSelectionActivityTask",
|
||||
2048, // Stack size
|
||||
this, // Parameters
|
||||
1, // Priority
|
||||
@@ -60,7 +60,7 @@ void FileSelectionScreen::onEnter() {
|
||||
);
|
||||
}
|
||||
|
||||
void FileSelectionScreen::onExit() {
|
||||
void FileSelectionActivity::onExit() {
|
||||
// Wait until not rendering to delete task to avoid killing mid-instruction to EPD
|
||||
xSemaphoreTake(renderingMutex, portMAX_DELAY);
|
||||
if (displayTaskHandle) {
|
||||
@@ -72,7 +72,7 @@ void FileSelectionScreen::onExit() {
|
||||
files.clear();
|
||||
}
|
||||
|
||||
void FileSelectionScreen::handleInput() {
|
||||
void FileSelectionActivity::loop() {
|
||||
const bool prevPressed =
|
||||
inputManager.wasPressed(InputManager::BTN_UP) || inputManager.wasPressed(InputManager::BTN_LEFT);
|
||||
const bool nextPressed =
|
||||
@@ -110,7 +110,7 @@ void FileSelectionScreen::handleInput() {
|
||||
}
|
||||
}
|
||||
|
||||
void FileSelectionScreen::displayTaskLoop() {
|
||||
void FileSelectionActivity::displayTaskLoop() {
|
||||
while (true) {
|
||||
if (updateRequired) {
|
||||
updateRequired = false;
|
||||
@@ -122,7 +122,7 @@ void FileSelectionScreen::displayTaskLoop() {
|
||||
}
|
||||
}
|
||||
|
||||
void FileSelectionScreen::render() const {
|
||||
void FileSelectionActivity::render() const {
|
||||
renderer.clearScreen();
|
||||
|
||||
const auto pageWidth = GfxRenderer::getScreenWidth();
|
||||
@@ -7,9 +7,9 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "Screen.h"
|
||||
#include "../Activity.h"
|
||||
|
||||
class FileSelectionScreen final : public Screen {
|
||||
class FileSelectionActivity final : public Activity {
|
||||
TaskHandle_t displayTaskHandle = nullptr;
|
||||
SemaphoreHandle_t renderingMutex = nullptr;
|
||||
std::string basepath = "/";
|
||||
@@ -25,11 +25,11 @@ class FileSelectionScreen final : public Screen {
|
||||
void loadFiles();
|
||||
|
||||
public:
|
||||
explicit FileSelectionScreen(GfxRenderer& renderer, InputManager& inputManager,
|
||||
const std::function<void(const std::string&)>& onSelect,
|
||||
const std::function<void()>& onGoHome)
|
||||
: Screen(renderer, inputManager), onSelect(onSelect), onGoHome(onGoHome) {}
|
||||
explicit FileSelectionActivity(GfxRenderer& renderer, InputManager& inputManager,
|
||||
const std::function<void(const std::string&)>& onSelect,
|
||||
const std::function<void()>& onGoHome)
|
||||
: Activity(renderer, inputManager), onSelect(onSelect), onGoHome(onGoHome) {}
|
||||
void onEnter() override;
|
||||
void onExit() override;
|
||||
void handleInput() override;
|
||||
void loop() override;
|
||||
};
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user