mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2025-12-18 15:17:42 +03:00
Compare commits
15 Commits
05da79f6ad
...
71fc35845b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
71fc35845b | ||
|
|
abb3dc3d43 | ||
|
|
b87a8c5dd5 | ||
|
|
b46f872e37 | ||
|
|
f3810f3c69 | ||
|
|
ba96a26b71 | ||
|
|
21cb8a6731 | ||
|
|
421c5cd30b | ||
|
|
5d935e6719 | ||
|
|
08227a07fa | ||
|
|
063a1df851 | ||
|
|
d429966dd4 | ||
|
|
c78f2a9840 | ||
|
|
11f01d3a41 | ||
|
|
973d372521 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,3 +3,4 @@
|
||||
.DS_Store
|
||||
.vscode
|
||||
lib/EpdFont/fontsrc
|
||||
*.generated.h
|
||||
|
||||
@ -73,10 +73,8 @@ bool Epub::parseContentOpf(const std::string& contentOpfFilePath) {
|
||||
coverImageItem = opfParser.items.at(opfParser.coverItemId);
|
||||
}
|
||||
|
||||
if (opfParser.items.count("ncx")) {
|
||||
tocNcxItem = opfParser.items.at("ncx");
|
||||
} else if (opfParser.items.count("ncxtoc")) {
|
||||
tocNcxItem = opfParser.items.at("ncxtoc");
|
||||
if (!opfParser.tocNcxPath.empty()) {
|
||||
tocNcxItem = opfParser.tocNcxPath;
|
||||
}
|
||||
|
||||
for (auto& spineRef : opfParser.spineRefs) {
|
||||
@ -150,6 +148,18 @@ bool Epub::load() {
|
||||
return false;
|
||||
}
|
||||
|
||||
// determine size of spine items
|
||||
size_t spineItemsCount = getSpineItemsCount();
|
||||
size_t spineItemsSize = 0;
|
||||
for (size_t i = 0; i < spineItemsCount; i++) {
|
||||
std::string spineItem = getSpineItem(i);
|
||||
size_t s = 0;
|
||||
getItemSize(spineItem, &s);
|
||||
spineItemsSize += s;
|
||||
cumulativeSpineItemSize.emplace_back(spineItemsSize);
|
||||
}
|
||||
Serial.printf("[%lu] [EBP] Book size: %u\n", millis(), spineItemsSize);
|
||||
|
||||
Serial.printf("[%lu] [EBP] Loaded ePub: %s\n", millis(), filepath.c_str());
|
||||
|
||||
return true;
|
||||
@ -257,6 +267,8 @@ bool Epub::getItemSize(const std::string& itemHref, size_t* size) const {
|
||||
|
||||
int Epub::getSpineItemsCount() const { return spine.size(); }
|
||||
|
||||
size_t Epub::getCumulativeSpineItemSize(const int spineIndex) const { return cumulativeSpineItemSize.at(spineIndex); }
|
||||
|
||||
std::string& Epub::getSpineItem(const int spineIndex) {
|
||||
if (spineIndex < 0 || spineIndex >= spine.size()) {
|
||||
Serial.printf("[%lu] [EBP] getSpineItem index:%d is out of range\n", millis(), spineIndex);
|
||||
@ -304,3 +316,14 @@ int Epub::getTocIndexForSpineIndex(const int spineIndex) const {
|
||||
Serial.printf("[%lu] [EBP] TOC item not found\n", millis());
|
||||
return -1;
|
||||
}
|
||||
|
||||
size_t Epub::getBookSize() const { return getCumulativeSpineItemSize(getSpineItemsCount() - 1); }
|
||||
|
||||
// Calculate progress in book
|
||||
uint8_t Epub::calculateProgress(const int currentSpineIndex, const float currentSpineRead) {
|
||||
size_t prevChapterSize = (currentSpineIndex >= 1) ? getCumulativeSpineItemSize(currentSpineIndex - 1) : 0;
|
||||
size_t curChapterSize = getCumulativeSpineItemSize(currentSpineIndex) - prevChapterSize;
|
||||
size_t bookSize = getBookSize();
|
||||
size_t sectionProgSize = currentSpineRead * curChapterSize;
|
||||
return round(static_cast<float>(prevChapterSize + sectionProgSize) / bookSize * 100.0);
|
||||
}
|
||||
|
||||
@ -20,6 +20,8 @@ class Epub {
|
||||
std::string filepath;
|
||||
// the spine of the EPUB file
|
||||
std::vector<std::pair<std::string, std::string>> spine;
|
||||
// the file size of the spine items (proxy to book progress)
|
||||
std::vector<size_t> cumulativeSpineItemSize;
|
||||
// the toc of the EPUB file
|
||||
std::vector<EpubTocEntry> toc;
|
||||
// the base path for items in the EPUB file
|
||||
@ -51,8 +53,12 @@ class Epub {
|
||||
bool getItemSize(const std::string& itemHref, size_t* size) const;
|
||||
std::string& getSpineItem(int spineIndex);
|
||||
int getSpineItemsCount() const;
|
||||
EpubTocEntry& getTocItem(int tocTndex);
|
||||
size_t getCumulativeSpineItemSize(const int spineIndex) const;
|
||||
EpubTocEntry& getTocItem(int tocIndex);
|
||||
int getTocItemsCount() const;
|
||||
int getSpineIndexForTocIndex(int tocIndex) const;
|
||||
int getTocIndexForSpineIndex(int spineIndex) const;
|
||||
|
||||
size_t getBookSize() const;
|
||||
uint8_t calculateProgress(const int currentSpineIndex, const float currentSpineRead);
|
||||
};
|
||||
|
||||
@ -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";
|
||||
|
||||
@ -3,6 +3,10 @@
|
||||
#include <HardwareSerial.h>
|
||||
#include <ZipFile.h>
|
||||
|
||||
namespace {
|
||||
constexpr const char MEDIA_TYPE_NCX[] = "application/x-dtbncx+xml";
|
||||
}
|
||||
|
||||
bool ContentOpfParser::setup() {
|
||||
parser = XML_ParserCreate(nullptr);
|
||||
if (!parser) {
|
||||
@ -111,16 +115,28 @@ void XMLCALL ContentOpfParser::startElement(void* userData, const XML_Char* name
|
||||
if (self->state == IN_MANIFEST && (strcmp(name, "item") == 0 || strcmp(name, "opf:item") == 0)) {
|
||||
std::string itemId;
|
||||
std::string href;
|
||||
std::string mediaType;
|
||||
|
||||
for (int i = 0; atts[i]; i += 2) {
|
||||
if (strcmp(atts[i], "id") == 0) {
|
||||
itemId = atts[i + 1];
|
||||
} else if (strcmp(atts[i], "href") == 0) {
|
||||
href = self->baseContentPath + atts[i + 1];
|
||||
} else if (strcmp(atts[i], "media-type") == 0) {
|
||||
mediaType = atts[i + 1];
|
||||
}
|
||||
}
|
||||
|
||||
self->items[itemId] = href;
|
||||
|
||||
if (mediaType == MEDIA_TYPE_NCX) {
|
||||
if (self->tocNcxPath.empty()) {
|
||||
self->tocNcxPath = href;
|
||||
} else {
|
||||
Serial.printf("[%lu] [COF] Warning: Multiple NCX files found in manifest. Ignoring duplicate: %s\n", millis(),
|
||||
href.c_str());
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@ -31,6 +31,9 @@ board_build.flash_mode = dio
|
||||
board_build.flash_size = 16MB
|
||||
board_build.partitions = partitions.csv
|
||||
|
||||
extra_scripts =
|
||||
pre:scripts/build_html.py
|
||||
|
||||
; Libraries
|
||||
lib_deps =
|
||||
BatteryMonitor=symlink://open-x4-sdk/libs/hardware/BatteryMonitor
|
||||
|
||||
51
scripts/build_html.py
Normal file
51
scripts/build_html.py
Normal file
@ -0,0 +1,51 @@
|
||||
import os
|
||||
import re
|
||||
|
||||
SRC_DIR = "src"
|
||||
|
||||
def minify_html(html: str) -> str:
|
||||
# Tags where whitespace should be preserved
|
||||
preserve_tags = ['pre', 'code', 'textarea', 'script', 'style']
|
||||
preserve_regex = '|'.join(preserve_tags)
|
||||
|
||||
# Protect preserve blocks with placeholders
|
||||
preserve_blocks = []
|
||||
def preserve(match):
|
||||
preserve_blocks.append(match.group(0))
|
||||
return f"__PRESERVE_BLOCK_{len(preserve_blocks)-1}__"
|
||||
|
||||
html = re.sub(rf'<({preserve_regex})[\s\S]*?</\1>', preserve, html, flags=re.IGNORECASE)
|
||||
|
||||
# Remove HTML comments
|
||||
html = re.sub(r'<!--.*?-->', '', html, flags=re.DOTALL)
|
||||
|
||||
# Collapse all whitespace between tags
|
||||
html = re.sub(r'>\s+<', '><', html)
|
||||
|
||||
# Collapse multiple spaces inside tags
|
||||
html = re.sub(r'\s+', ' ', html)
|
||||
|
||||
# Restore preserved blocks
|
||||
for i, block in enumerate(preserve_blocks):
|
||||
html = html.replace(f"__PRESERVE_BLOCK_{i}__", block)
|
||||
|
||||
return html.strip()
|
||||
|
||||
for root, _, files in os.walk(SRC_DIR):
|
||||
for file in files:
|
||||
if file.endswith(".html"):
|
||||
html_path = os.path.join(root, file)
|
||||
with open(html_path, "r", encoding="utf-8") as f:
|
||||
html_content = f.read()
|
||||
|
||||
# minified = regex.sub("\g<1>", html_content)
|
||||
minified = minify_html(html_content)
|
||||
base_name = f"{os.path.splitext(file)[0]}Html"
|
||||
header_path = os.path.join(root, f"{base_name}.generated.h")
|
||||
|
||||
with open(header_path, "w", encoding="utf-8") as h:
|
||||
h.write(f"// THIS FILE IS AUTOGENERATED, DO NOT EDIT MANUALLY\n\n")
|
||||
h.write(f"#pragma once\n")
|
||||
h.write(f'constexpr char {base_name}[] PROGMEM = R"rawliteral({minified})rawliteral";\n')
|
||||
|
||||
print(f"Generated: {header_path}")
|
||||
@ -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()
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
18
src/activities/Activity.h
Normal file
18
src/activities/Activity.h
Normal file
@ -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() {}
|
||||
};
|
||||
21
src/activities/ActivityWithSubactivity.cpp
Normal file
21
src/activities/ActivityWithSubactivity.cpp
Normal file
@ -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(); }
|
||||
17
src/activities/ActivityWithSubactivity.h
Normal file
17
src/activities/ActivityWithSubactivity.h
Normal file
@ -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();
|
||||
|
||||
8
src/activities/boot_sleep/BootActivity.h
Normal file
8
src/activities/boot_sleep/BootActivity.h
Normal file
@ -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();
|
||||
|
||||
8
src/activities/boot_sleep/SleepActivity.h
Normal file
8
src/activities/boot_sleep/SleepActivity.h
Normal file
@ -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;
|
||||
};
|
||||
103
src/activities/home/HomeActivity.cpp
Normal file
103
src/activities/home/HomeActivity.cpp
Normal file
@ -0,0 +1,103 @@
|
||||
#include "HomeActivity.h"
|
||||
|
||||
#include <GfxRenderer.h>
|
||||
#include <SD.h>
|
||||
|
||||
#include "config.h"
|
||||
|
||||
namespace {
|
||||
constexpr int menuItemCount = 2;
|
||||
}
|
||||
|
||||
void HomeActivity::taskTrampoline(void* param) {
|
||||
auto* self = static_cast<HomeActivity*>(param);
|
||||
self->displayTaskLoop();
|
||||
}
|
||||
|
||||
void HomeActivity::onEnter() {
|
||||
renderingMutex = xSemaphoreCreateMutex();
|
||||
|
||||
selectorIndex = 0;
|
||||
|
||||
// Trigger first update
|
||||
updateRequired = true;
|
||||
|
||||
xTaskCreate(&HomeActivity::taskTrampoline, "HomeActivityTask",
|
||||
2048, // Stack size
|
||||
this, // Parameters
|
||||
1, // Priority
|
||||
&displayTaskHandle // Task handle
|
||||
);
|
||||
}
|
||||
|
||||
void HomeActivity::onExit() {
|
||||
// Wait until not rendering to delete task to avoid killing mid-instruction to EPD
|
||||
xSemaphoreTake(renderingMutex, portMAX_DELAY);
|
||||
if (displayTaskHandle) {
|
||||
vTaskDelete(displayTaskHandle);
|
||||
displayTaskHandle = nullptr;
|
||||
}
|
||||
vSemaphoreDelete(renderingMutex);
|
||||
renderingMutex = nullptr;
|
||||
}
|
||||
|
||||
void HomeActivity::loop() {
|
||||
const bool prevPressed =
|
||||
inputManager.wasPressed(InputManager::BTN_UP) || inputManager.wasPressed(InputManager::BTN_LEFT);
|
||||
const bool nextPressed =
|
||||
inputManager.wasPressed(InputManager::BTN_DOWN) || inputManager.wasPressed(InputManager::BTN_RIGHT);
|
||||
|
||||
if (inputManager.wasPressed(InputManager::BTN_CONFIRM)) {
|
||||
if (selectorIndex == 0) {
|
||||
onReaderOpen();
|
||||
} else if (selectorIndex == 1) {
|
||||
onSettingsOpen();
|
||||
}
|
||||
} else if (prevPressed) {
|
||||
selectorIndex = (selectorIndex + menuItemCount - 1) % menuItemCount;
|
||||
updateRequired = true;
|
||||
} else if (nextPressed) {
|
||||
selectorIndex = (selectorIndex + 1) % menuItemCount;
|
||||
updateRequired = true;
|
||||
}
|
||||
}
|
||||
|
||||
void HomeActivity::displayTaskLoop() {
|
||||
while (true) {
|
||||
if (updateRequired) {
|
||||
updateRequired = false;
|
||||
xSemaphoreTake(renderingMutex, portMAX_DELAY);
|
||||
render();
|
||||
xSemaphoreGive(renderingMutex);
|
||||
}
|
||||
vTaskDelay(10 / portTICK_PERIOD_MS);
|
||||
}
|
||||
}
|
||||
|
||||
void HomeActivity::render() const {
|
||||
renderer.clearScreen();
|
||||
|
||||
const auto pageWidth = GfxRenderer::getScreenWidth();
|
||||
const auto pageHeight = GfxRenderer::getScreenHeight();
|
||||
renderer.drawCenteredText(READER_FONT_ID, 10, "CrossPoint Reader", true, BOLD);
|
||||
|
||||
// Draw selection
|
||||
renderer.fillRect(0, 60 + selectorIndex * 30 + 2, pageWidth - 1, 30);
|
||||
renderer.drawText(UI_FONT_ID, 20, 60, "Read", selectorIndex != 0);
|
||||
renderer.drawText(UI_FONT_ID, 20, 90, "Settings", selectorIndex != 1);
|
||||
|
||||
renderer.drawRect(25, pageHeight - 40, 106, 40);
|
||||
renderer.drawText(UI_FONT_ID, 25 + (105 - renderer.getTextWidth(UI_FONT_ID, "Back")) / 2, pageHeight - 35, "Back");
|
||||
|
||||
renderer.drawRect(130, pageHeight - 40, 106, 40);
|
||||
renderer.drawText(UI_FONT_ID, 130 + (105 - renderer.getTextWidth(UI_FONT_ID, "Confirm")) / 2, pageHeight - 35,
|
||||
"Confirm");
|
||||
|
||||
renderer.drawRect(245, pageHeight - 40, 106, 40);
|
||||
renderer.drawText(UI_FONT_ID, 245 + (105 - renderer.getTextWidth(UI_FONT_ID, "Left")) / 2, pageHeight - 35, "Left");
|
||||
|
||||
renderer.drawRect(350, pageHeight - 40, 106, 40);
|
||||
renderer.drawText(UI_FONT_ID, 350 + (105 - renderer.getTextWidth(UI_FONT_ID, "Right")) / 2, pageHeight - 35, "Right");
|
||||
|
||||
renderer.displayBuffer();
|
||||
}
|
||||
29
src/activities/home/HomeActivity.h
Normal file
29
src/activities/home/HomeActivity.h
Normal file
@ -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;
|
||||
};
|
||||
@ -3,6 +3,8 @@
|
||||
#include <GfxRenderer.h>
|
||||
#include <WiFi.h>
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "CrossPointWebServer.h"
|
||||
#include "WifiCredentialStore.h"
|
||||
#include "config.h"
|
||||
@ -46,24 +48,37 @@ void WifiScreen::onEnter() {
|
||||
}
|
||||
|
||||
void WifiScreen::onExit() {
|
||||
Serial.printf("[%lu] [WIFI] [MEM] Free heap at onExit start: %d bytes\n", millis(), ESP.getFreeHeap());
|
||||
|
||||
// Stop any ongoing WiFi scan
|
||||
WiFi.scanDelete();
|
||||
Serial.printf("[%lu] [WIFI] [MEM] Free heap after scanDelete: %d bytes\n", millis(), ESP.getFreeHeap());
|
||||
|
||||
// Stop the web server to free memory
|
||||
crossPointWebServer.stop();
|
||||
Serial.printf("[%lu] [WIFI] [MEM] Free heap after webserver stop: %d bytes\n", millis(), ESP.getFreeHeap());
|
||||
|
||||
// Disconnect WiFi to free memory
|
||||
WiFi.disconnect(true);
|
||||
WiFi.mode(WIFI_OFF);
|
||||
Serial.printf("[%lu] [WIFI] [MEM] Free heap after WiFi disconnect: %d bytes\n", millis(), ESP.getFreeHeap());
|
||||
|
||||
// Wait until not rendering to delete task to avoid killing mid-instruction to EPD
|
||||
xSemaphoreTake(renderingMutex, portMAX_DELAY);
|
||||
// Delete the display task
|
||||
if (displayTaskHandle) {
|
||||
vTaskDelete(displayTaskHandle);
|
||||
displayTaskHandle = nullptr;
|
||||
}
|
||||
vSemaphoreDelete(renderingMutex);
|
||||
renderingMutex = nullptr;
|
||||
|
||||
// Small delay to ensure task is fully deleted before cleaning up mutex
|
||||
vTaskDelay(10 / portTICK_PERIOD_MS);
|
||||
|
||||
// Now safe to delete the mutex
|
||||
if (renderingMutex) {
|
||||
vSemaphoreDelete(renderingMutex);
|
||||
renderingMutex = nullptr;
|
||||
}
|
||||
|
||||
Serial.printf("[%lu] [WIFI] [MEM] Free heap at onExit end: %d bytes\n", millis(), ESP.getFreeHeap());
|
||||
}
|
||||
|
||||
void WifiScreen::startWifiScan() {
|
||||
@ -95,18 +110,35 @@ void WifiScreen::processWifiScanResults() {
|
||||
}
|
||||
|
||||
// Scan complete, process results
|
||||
networks.clear();
|
||||
// Use a map to deduplicate networks by SSID, keeping the strongest signal
|
||||
std::map<std::string, WifiNetworkInfo> uniqueNetworks;
|
||||
|
||||
for (int i = 0; i < scanResult; i++) {
|
||||
WifiNetworkInfo network;
|
||||
network.ssid = WiFi.SSID(i).c_str();
|
||||
network.rssi = WiFi.RSSI(i);
|
||||
network.isEncrypted = (WiFi.encryptionType(i) != WIFI_AUTH_OPEN);
|
||||
network.hasSavedPassword = WIFI_STORE.hasSavedCredential(network.ssid);
|
||||
std::string ssid = WiFi.SSID(i).c_str();
|
||||
int32_t rssi = WiFi.RSSI(i);
|
||||
|
||||
// Skip hidden networks (empty SSID)
|
||||
if (!network.ssid.empty()) {
|
||||
networks.push_back(network);
|
||||
if (ssid.empty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check if we've already seen this SSID
|
||||
auto it = uniqueNetworks.find(ssid);
|
||||
if (it == uniqueNetworks.end() || rssi > it->second.rssi) {
|
||||
// New network or stronger signal than existing entry
|
||||
WifiNetworkInfo network;
|
||||
network.ssid = ssid;
|
||||
network.rssi = rssi;
|
||||
network.isEncrypted = (WiFi.encryptionType(i) != WIFI_AUTH_OPEN);
|
||||
network.hasSavedPassword = WIFI_STORE.hasSavedCredential(network.ssid);
|
||||
uniqueNetworks[ssid] = network;
|
||||
}
|
||||
}
|
||||
|
||||
// Convert map to vector
|
||||
networks.clear();
|
||||
for (const auto& pair : uniqueNetworks) {
|
||||
networks.push_back(pair.second);
|
||||
}
|
||||
|
||||
// Sort by signal strength (strongest first)
|
||||
@ -227,7 +259,7 @@ void WifiScreen::checkConnectionStatus() {
|
||||
}
|
||||
}
|
||||
|
||||
void WifiScreen::handleInput() {
|
||||
void WifiScreen::loop() {
|
||||
// Check scan progress
|
||||
if (state == WifiScreenState::SCANNING) {
|
||||
processWifiScanResults();
|
||||
@ -9,8 +9,8 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "../Activity.h"
|
||||
#include "OnScreenKeyboard.h"
|
||||
#include "Screen.h"
|
||||
|
||||
// Structure to hold WiFi network information
|
||||
struct WifiNetworkInfo {
|
||||
@ -32,7 +32,7 @@ enum class WifiScreenState {
|
||||
FORGET_PROMPT // Asking user if they want to forget the network
|
||||
};
|
||||
|
||||
class WifiScreen final : public Screen {
|
||||
class WifiScreen final : public Activity {
|
||||
TaskHandle_t displayTaskHandle = nullptr;
|
||||
SemaphoreHandle_t renderingMutex = nullptr;
|
||||
bool updateRequired = false;
|
||||
@ -86,8 +86,8 @@ class WifiScreen final : public Screen {
|
||||
|
||||
public:
|
||||
explicit WifiScreen(GfxRenderer& renderer, InputManager& inputManager, const std::function<void()>& onGoBack)
|
||||
: Screen(renderer, inputManager), onGoBack(onGoBack) {}
|
||||
: Activity(renderer, inputManager), onGoBack(onGoBack) {}
|
||||
void onEnter() override;
|
||||
void onExit() override;
|
||||
void handleInput() 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,16 +91,16 @@ void EpubReaderScreen::handleInput() {
|
||||
nextPageNumber = 0;
|
||||
section.reset();
|
||||
}
|
||||
subScreen->onExit();
|
||||
subScreen.reset();
|
||||
subAcitivity->onExit();
|
||||
subAcitivity.reset();
|
||||
updateRequired = true;
|
||||
}));
|
||||
subScreen->onEnter();
|
||||
subAcitivity->onEnter();
|
||||
xSemaphoreGive(renderingMutex);
|
||||
}
|
||||
|
||||
if (inputManager.wasPressed(InputManager::BTN_BACK)) {
|
||||
onGoHome();
|
||||
onGoBack();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -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,10 +324,16 @@ 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
|
||||
float sectionChapterProg = static_cast<float>(section->currentPage) / section->pageCount;
|
||||
uint8_t bookProgress = epub->calculateProgress(currentSpineIndex, sectionChapterProg);
|
||||
|
||||
// Right aligned text for progress counter
|
||||
const std::string progress = std::to_string(section->currentPage + 1) + " / " + std::to_string(section->pageCount);
|
||||
const std::string progress = std::to_string(section->currentPage + 1) + "/" + std::to_string(section->pageCount) +
|
||||
" " + std::to_string(bookProgress) + "%";
|
||||
const auto progressTextWidth = renderer.getTextWidth(SMALL_FONT_ID, progress.c_str());
|
||||
renderer.drawText(SMALL_FONT_ID, GfxRenderer::getScreenWidth() - marginRight - progressTextWidth, textY,
|
||||
progress.c_str());
|
||||
@ -5,19 +5,19 @@
|
||||
#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;
|
||||
bool updateRequired = false;
|
||||
const std::function<void()> onGoHome;
|
||||
const std::function<void()> onGoBack;
|
||||
|
||||
static void taskTrampoline(void* param);
|
||||
[[noreturn]] void displayTaskLoop();
|
||||
@ -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()>& onGoHome)
|
||||
: Screen(renderer, inputManager), epub(std::move(epub)), onGoHome(onGoHome) {}
|
||||
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;
|
||||
};
|
||||
@ -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();
|
||||
@ -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;
|
||||
};
|
||||
@ -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 =
|
||||
@ -98,8 +98,8 @@ void FileSelectionScreen::handleInput() {
|
||||
loadFiles();
|
||||
updateRequired = true;
|
||||
} else {
|
||||
// At root level, go to settings
|
||||
onSettingsOpen();
|
||||
// At root level, go back home
|
||||
onGoHome();
|
||||
}
|
||||
} else if (prevPressed) {
|
||||
selectorIndex = (selectorIndex + files.size() - 1) % files.size();
|
||||
@ -110,7 +110,7 @@ void FileSelectionScreen::handleInput() {
|
||||
}
|
||||
}
|
||||
|
||||
void FileSelectionScreen::displayTaskLoop() {
|
||||
void FileSelectionActivity::displayTaskLoop() {
|
||||
while (true) {
|
||||
if (updateRequired) {
|
||||
updateRequired = false;
|
||||
@ -122,14 +122,14 @@ void FileSelectionScreen::displayTaskLoop() {
|
||||
}
|
||||
}
|
||||
|
||||
void FileSelectionScreen::render() const {
|
||||
void FileSelectionActivity::render() const {
|
||||
renderer.clearScreen();
|
||||
|
||||
const auto pageWidth = GfxRenderer::getScreenWidth();
|
||||
renderer.drawCenteredText(READER_FONT_ID, 10, "CrossPoint Reader", true, BOLD);
|
||||
|
||||
// Help text
|
||||
renderer.drawText(SMALL_FONT_ID, 20, GfxRenderer::getScreenHeight() - 30, "Press BACK for Settings");
|
||||
renderer.drawText(SMALL_FONT_ID, 20, GfxRenderer::getScreenHeight() - 30, "Press BACK for Home");
|
||||
|
||||
if (files.empty()) {
|
||||
renderer.drawText(UI_FONT_ID, 20, 60, "No EPUBs found");
|
||||
@ -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 = "/";
|
||||
@ -17,7 +17,7 @@ class FileSelectionScreen final : public Screen {
|
||||
int selectorIndex = 0;
|
||||
bool updateRequired = false;
|
||||
const std::function<void(const std::string&)> onSelect;
|
||||
const std::function<void()> onSettingsOpen;
|
||||
const std::function<void()> onGoHome;
|
||||
|
||||
static void taskTrampoline(void* param);
|
||||
[[noreturn]] void displayTaskLoop();
|
||||
@ -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()>& onSettingsOpen)
|
||||
: Screen(renderer, inputManager), onSelect(onSelect), onSettingsOpen(onSettingsOpen) {}
|
||||
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;
|
||||
};
|
||||
68
src/activities/reader/ReaderActivity.cpp
Normal file
68
src/activities/reader/ReaderActivity.cpp
Normal file
@ -0,0 +1,68 @@
|
||||
#include "ReaderActivity.h"
|
||||
|
||||
#include <SD.h>
|
||||
|
||||
#include "CrossPointState.h"
|
||||
#include "Epub.h"
|
||||
#include "EpubReaderActivity.h"
|
||||
#include "FileSelectionActivity.h"
|
||||
#include "activities/util/FullScreenMessageActivity.h"
|
||||
|
||||
std::unique_ptr<Epub> ReaderActivity::loadEpub(const std::string& path) {
|
||||
if (!SD.exists(path.c_str())) {
|
||||
Serial.printf("[%lu] [ ] File does not exist: %s\n", millis(), path.c_str());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto epub = std::unique_ptr<Epub>(new Epub(path, "/.crosspoint"));
|
||||
if (epub->load()) {
|
||||
return epub;
|
||||
}
|
||||
|
||||
Serial.printf("[%lu] [ ] Failed to load epub\n", millis());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void ReaderActivity::onSelectEpubFile(const std::string& path) {
|
||||
exitActivity();
|
||||
enterNewActivity(new FullScreenMessageActivity(renderer, inputManager, "Loading..."));
|
||||
|
||||
auto epub = loadEpub(path);
|
||||
if (epub) {
|
||||
APP_STATE.openEpubPath = path;
|
||||
APP_STATE.saveToFile();
|
||||
onGoToEpubReader(std::move(epub));
|
||||
} else {
|
||||
exitActivity();
|
||||
enterNewActivity(new FullScreenMessageActivity(renderer, inputManager, "Failed to load epub", REGULAR,
|
||||
EInkDisplay::HALF_REFRESH));
|
||||
delay(2000);
|
||||
onGoToFileSelection();
|
||||
}
|
||||
}
|
||||
|
||||
void ReaderActivity::onGoToFileSelection() {
|
||||
exitActivity();
|
||||
enterNewActivity(new FileSelectionActivity(
|
||||
renderer, inputManager, [this](const std::string& path) { onSelectEpubFile(path); }, onGoBack));
|
||||
}
|
||||
|
||||
void ReaderActivity::onGoToEpubReader(std::unique_ptr<Epub> epub) {
|
||||
exitActivity();
|
||||
enterNewActivity(new EpubReaderActivity(renderer, inputManager, std::move(epub), [this] { onGoToFileSelection(); }));
|
||||
}
|
||||
|
||||
void ReaderActivity::onEnter() {
|
||||
if (initialEpubPath.empty()) {
|
||||
onGoToFileSelection();
|
||||
return;
|
||||
}
|
||||
|
||||
auto epub = loadEpub(initialEpubPath);
|
||||
if (!epub) {
|
||||
onGoBack();
|
||||
return;
|
||||
}
|
||||
|
||||
onGoToEpubReader(std::move(epub));
|
||||
}
|
||||
24
src/activities/reader/ReaderActivity.h
Normal file
24
src/activities/reader/ReaderActivity.h
Normal file
@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
#include <memory>
|
||||
|
||||
#include "../ActivityWithSubactivity.h"
|
||||
|
||||
class Epub;
|
||||
|
||||
class ReaderActivity final : public ActivityWithSubactivity {
|
||||
std::string initialEpubPath;
|
||||
const std::function<void()> onGoBack;
|
||||
static std::unique_ptr<Epub> loadEpub(const std::string& path);
|
||||
|
||||
void onSelectEpubFile(const std::string& path);
|
||||
void onGoToFileSelection();
|
||||
void onGoToEpubReader(std::unique_ptr<Epub> epub);
|
||||
|
||||
public:
|
||||
explicit ReaderActivity(GfxRenderer& renderer, InputManager& inputManager, std::string initialEpubPath,
|
||||
const std::function<void()>& onGoBack)
|
||||
: ActivityWithSubactivity(renderer, inputManager),
|
||||
initialEpubPath(std::move(initialEpubPath)),
|
||||
onGoBack(onGoBack) {}
|
||||
void onEnter() override;
|
||||
};
|
||||
@ -1,4 +1,4 @@
|
||||
#include "SettingsScreen.h"
|
||||
#include "SettingsActivity.h"
|
||||
|
||||
#include <GfxRenderer.h>
|
||||
|
||||
@ -7,17 +7,17 @@
|
||||
|
||||
// Define the static settings list
|
||||
|
||||
const SettingInfo SettingsScreen::settingsList[SettingsScreen::settingsCount] = {
|
||||
const SettingInfo SettingsActivity::settingsList[settingsCount] = {
|
||||
{"White Sleep Screen", SettingType::TOGGLE, &CrossPointSettings::whiteSleepScreen},
|
||||
{"Extra Paragraph Spacing", SettingType::TOGGLE, &CrossPointSettings::extraParagraphSpacing},
|
||||
{"WiFi", SettingType::ACTION, nullptr}};
|
||||
|
||||
void SettingsScreen::taskTrampoline(void* param) {
|
||||
auto* self = static_cast<SettingsScreen*>(param);
|
||||
void SettingsActivity::taskTrampoline(void* param) {
|
||||
auto* self = static_cast<SettingsActivity*>(param);
|
||||
self->displayTaskLoop();
|
||||
}
|
||||
|
||||
void SettingsScreen::onEnter() {
|
||||
void SettingsActivity::onEnter() {
|
||||
renderingMutex = xSemaphoreCreateMutex();
|
||||
|
||||
// Reset selection to first item
|
||||
@ -26,7 +26,7 @@ void SettingsScreen::onEnter() {
|
||||
// Trigger first update
|
||||
updateRequired = true;
|
||||
|
||||
xTaskCreate(&SettingsScreen::taskTrampoline, "SettingsScreenTask",
|
||||
xTaskCreate(&SettingsActivity::taskTrampoline, "SettingsActivityTask",
|
||||
2048, // Stack size
|
||||
this, // Parameters
|
||||
1, // Priority
|
||||
@ -34,7 +34,7 @@ void SettingsScreen::onEnter() {
|
||||
);
|
||||
}
|
||||
|
||||
void SettingsScreen::onExit() {
|
||||
void SettingsActivity::onExit() {
|
||||
// Wait until not rendering to delete task to avoid killing mid-instruction to EPD
|
||||
xSemaphoreTake(renderingMutex, portMAX_DELAY);
|
||||
if (displayTaskHandle) {
|
||||
@ -45,7 +45,7 @@ void SettingsScreen::onExit() {
|
||||
renderingMutex = nullptr;
|
||||
}
|
||||
|
||||
void SettingsScreen::handleInput() {
|
||||
void SettingsActivity::loop() {
|
||||
// Handle actions with early return
|
||||
if (inputManager.wasPressed(InputManager::BTN_CONFIRM)) {
|
||||
activateCurrentSetting();
|
||||
@ -73,7 +73,7 @@ void SettingsScreen::handleInput() {
|
||||
}
|
||||
}
|
||||
|
||||
void SettingsScreen::activateCurrentSetting() {
|
||||
void SettingsActivity::activateCurrentSetting() {
|
||||
// Validate index
|
||||
if (selectedSettingIndex < 0 || selectedSettingIndex >= settingsCount) {
|
||||
return;
|
||||
@ -93,7 +93,7 @@ void SettingsScreen::activateCurrentSetting() {
|
||||
}
|
||||
}
|
||||
|
||||
void SettingsScreen::toggleCurrentSetting() {
|
||||
void SettingsActivity::toggleCurrentSetting() {
|
||||
// Validate index
|
||||
if (selectedSettingIndex < 0 || selectedSettingIndex >= settingsCount) {
|
||||
return;
|
||||
@ -114,7 +114,7 @@ void SettingsScreen::toggleCurrentSetting() {
|
||||
SETTINGS.saveToFile();
|
||||
}
|
||||
|
||||
void SettingsScreen::displayTaskLoop() {
|
||||
void SettingsActivity::displayTaskLoop() {
|
||||
while (true) {
|
||||
if (updateRequired) {
|
||||
updateRequired = false;
|
||||
@ -126,7 +126,7 @@ void SettingsScreen::displayTaskLoop() {
|
||||
}
|
||||
}
|
||||
|
||||
void SettingsScreen::render() const {
|
||||
void SettingsActivity::render() const {
|
||||
renderer.clearScreen();
|
||||
|
||||
const auto pageWidth = GfxRenderer::getScreenWidth();
|
||||
@ -8,11 +8,10 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "Screen.h"
|
||||
#include "../Activity.h"
|
||||
|
||||
class CrossPointSettings;
|
||||
|
||||
// Enum to distinguish setting types
|
||||
enum class SettingType { TOGGLE, ACTION };
|
||||
|
||||
// Structure to hold setting information
|
||||
@ -22,7 +21,7 @@ struct SettingInfo {
|
||||
uint8_t CrossPointSettings::* valuePtr; // Pointer to member in CrossPointSettings (for TOGGLE)
|
||||
};
|
||||
|
||||
class SettingsScreen final : public Screen {
|
||||
class SettingsActivity final : public Activity {
|
||||
TaskHandle_t displayTaskHandle = nullptr;
|
||||
SemaphoreHandle_t renderingMutex = nullptr;
|
||||
bool updateRequired = false;
|
||||
@ -41,10 +40,10 @@ class SettingsScreen final : public Screen {
|
||||
void activateCurrentSetting();
|
||||
|
||||
public:
|
||||
explicit SettingsScreen(GfxRenderer& renderer, InputManager& inputManager, const std::function<void()>& onGoHome,
|
||||
const std::function<void()>& onGoWifi)
|
||||
: Screen(renderer, inputManager), onGoHome(onGoHome), onGoWifi(onGoWifi) {}
|
||||
explicit SettingsActivity(GfxRenderer& renderer, InputManager& inputManager, const std::function<void()>& onGoHome,
|
||||
const std::function<void()>& onGoWifi)
|
||||
: Activity(renderer, inputManager), onGoHome(onGoHome), onGoWifi(onGoWifi) {}
|
||||
void onEnter() override;
|
||||
void onExit() override;
|
||||
void handleInput() override;
|
||||
void loop() override;
|
||||
};
|
||||
@ -1,10 +1,10 @@
|
||||
#include "FullScreenMessageScreen.h"
|
||||
#include "FullScreenMessageActivity.h"
|
||||
|
||||
#include <GfxRenderer.h>
|
||||
|
||||
#include "config.h"
|
||||
|
||||
void FullScreenMessageScreen::onEnter() {
|
||||
void FullScreenMessageActivity::onEnter() {
|
||||
const auto height = renderer.getLineHeight(UI_FONT_ID);
|
||||
const auto top = (GfxRenderer::getScreenHeight() - height) / 2;
|
||||
|
||||
21
src/activities/util/FullScreenMessageActivity.h
Normal file
21
src/activities/util/FullScreenMessageActivity.h
Normal file
@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
#include <EInkDisplay.h>
|
||||
#include <EpdFontFamily.h>
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "../Activity.h"
|
||||
|
||||
class FullScreenMessageActivity final : public Activity {
|
||||
std::string text;
|
||||
EpdFontStyle style;
|
||||
EInkDisplay::RefreshMode refreshMode;
|
||||
|
||||
public:
|
||||
explicit FullScreenMessageActivity(GfxRenderer& renderer, InputManager& inputManager, std::string text,
|
||||
const EpdFontStyle style = REGULAR,
|
||||
const EInkDisplay::RefreshMode refreshMode = EInkDisplay::FAST_REFRESH)
|
||||
: Activity(renderer, inputManager), text(std::move(text)), style(style), refreshMode(refreshMode) {}
|
||||
void onEnter() override;
|
||||
};
|
||||
251
src/html/FilesPageFooter.html
Normal file
251
src/html/FilesPageFooter.html
Normal file
@ -0,0 +1,251 @@
|
||||
<div class="card">
|
||||
<p style="text-align: center; color: #95a5a6; margin: 0;">
|
||||
CrossPoint E-Reader • Open Source
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<!-- Upload Modal -->
|
||||
<div class="modal-overlay" id="uploadModal">
|
||||
<div class="modal">
|
||||
<button class="modal-close" onclick="closeUploadModal()">×</button>
|
||||
<h3>📤 Upload eBook</h3>
|
||||
<div class="upload-form">
|
||||
<p class="file-info">Select an .epub file to upload to <strong id="uploadPathDisplay"></strong></p>
|
||||
<input type="file" id="fileInput" accept=".epub" onchange="validateFile()">
|
||||
<button id="uploadBtn" class="upload-btn" onclick="uploadFile()" disabled>Upload</button>
|
||||
<div id="progress-container">
|
||||
<div id="progress-bar"><div id="progress-fill"></div></div>
|
||||
<div id="progress-text"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- New Folder Modal -->
|
||||
<div class="modal-overlay" id="folderModal">
|
||||
<div class="modal">
|
||||
<button class="modal-close" onclick="closeFolderModal()">×</button>
|
||||
<h3>📁 New Folder</h3>
|
||||
<div class="folder-form">
|
||||
<p class="file-info">Create a new folder in <strong id="folderPathDisplay"></strong></p>
|
||||
<input type="text" id="folderName" class="folder-input" placeholder="Folder name...">
|
||||
<button class="folder-btn" onclick="createFolder()">Create Folder</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Delete Confirmation Modal -->
|
||||
<div class="modal-overlay" id="deleteModal">
|
||||
<div class="modal">
|
||||
<button class="modal-close" onclick="closeDeleteModal()">×</button>
|
||||
<h3>🗑️ Delete Item</h3>
|
||||
<div class="folder-form">
|
||||
<p class="delete-warning">⚠️ This action cannot be undone!</p>
|
||||
<p class="file-info">Are you sure you want to delete:</p>
|
||||
<p class="delete-item-name" id="deleteItemName"></p>
|
||||
<input type="hidden" id="deleteItemPath">
|
||||
<input type="hidden" id="deleteItemType">
|
||||
<button class="delete-btn-confirm" onclick="confirmDelete()">Delete</button>
|
||||
<button class="delete-btn-cancel" onclick="closeDeleteModal()">Cancel</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Modal functions
|
||||
function openUploadModal() {
|
||||
const currentPath = document.getElementById('currentPath').value;
|
||||
document.getElementById('uploadPathDisplay').textContent = currentPath === '/' ? '/ 🏠' : currentPath;
|
||||
document.getElementById('uploadModal').classList.add('open');
|
||||
}
|
||||
|
||||
function closeUploadModal() {
|
||||
document.getElementById('uploadModal').classList.remove('open');
|
||||
document.getElementById('fileInput').value = '';
|
||||
document.getElementById('uploadBtn').disabled = true;
|
||||
document.getElementById('progress-container').style.display = 'none';
|
||||
document.getElementById('progress-fill').style.width = '0%';
|
||||
document.getElementById('progress-fill').style.backgroundColor = '#27ae60';
|
||||
}
|
||||
|
||||
function openFolderModal() {
|
||||
const currentPath = document.getElementById('currentPath').value;
|
||||
document.getElementById('folderPathDisplay').textContent = currentPath === '/' ? '/ 🏠' : currentPath;
|
||||
document.getElementById('folderModal').classList.add('open');
|
||||
document.getElementById('folderName').value = '';
|
||||
}
|
||||
|
||||
function closeFolderModal() {
|
||||
document.getElementById('folderModal').classList.remove('open');
|
||||
}
|
||||
|
||||
// Close modals when clicking overlay
|
||||
document.querySelectorAll('.modal-overlay').forEach(function(overlay) {
|
||||
overlay.addEventListener('click', function(e) {
|
||||
if (e.target === overlay) {
|
||||
overlay.classList.remove('open');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function validateFile() {
|
||||
const fileInput = document.getElementById('fileInput');
|
||||
const uploadBtn = document.getElementById('uploadBtn');
|
||||
const file = fileInput.files[0];
|
||||
|
||||
if (file) {
|
||||
const fileName = file.name.toLowerCase();
|
||||
if (!fileName.endsWith('.epub')) {
|
||||
alert('Only .epub files are allowed!');
|
||||
fileInput.value = '';
|
||||
uploadBtn.disabled = true;
|
||||
return;
|
||||
}
|
||||
uploadBtn.disabled = false;
|
||||
} else {
|
||||
uploadBtn.disabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
function uploadFile() {
|
||||
const fileInput = document.getElementById('fileInput');
|
||||
const file = fileInput.files[0];
|
||||
const currentPath = document.getElementById('currentPath').value;
|
||||
|
||||
if (!file) {
|
||||
alert('Please select a file first!');
|
||||
return;
|
||||
}
|
||||
|
||||
const fileName = file.name.toLowerCase();
|
||||
if (!fileName.endsWith('.epub')) {
|
||||
alert('Only .epub files are allowed!');
|
||||
return;
|
||||
}
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
|
||||
const progressContainer = document.getElementById('progress-container');
|
||||
const progressFill = document.getElementById('progress-fill');
|
||||
const progressText = document.getElementById('progress-text');
|
||||
const uploadBtn = document.getElementById('uploadBtn');
|
||||
|
||||
progressContainer.style.display = 'block';
|
||||
uploadBtn.disabled = true;
|
||||
|
||||
const xhr = new XMLHttpRequest();
|
||||
// Include path as query parameter since multipart form data doesn't make
|
||||
// form fields available until after file upload completes
|
||||
xhr.open('POST', '/upload?path=' + encodeURIComponent(currentPath), true);
|
||||
|
||||
xhr.upload.onprogress = function(e) {
|
||||
if (e.lengthComputable) {
|
||||
const percent = Math.round((e.loaded / e.total) * 100);
|
||||
progressFill.style.width = percent + '%';
|
||||
progressText.textContent = 'Uploading: ' + percent + '%';
|
||||
}
|
||||
};
|
||||
|
||||
xhr.onload = function() {
|
||||
if (xhr.status === 200) {
|
||||
progressText.textContent = 'Upload complete!';
|
||||
setTimeout(function() {
|
||||
window.location.reload();
|
||||
}, 1000);
|
||||
} else {
|
||||
progressText.textContent = 'Upload failed: ' + xhr.responseText;
|
||||
progressFill.style.backgroundColor = '#e74c3c';
|
||||
uploadBtn.disabled = false;
|
||||
}
|
||||
};
|
||||
|
||||
xhr.onerror = function() {
|
||||
progressText.textContent = 'Upload failed - network error';
|
||||
progressFill.style.backgroundColor = '#e74c3c';
|
||||
uploadBtn.disabled = false;
|
||||
};
|
||||
|
||||
xhr.send(formData);
|
||||
}
|
||||
|
||||
function createFolder() {
|
||||
const folderName = document.getElementById('folderName').value.trim();
|
||||
const currentPath = document.getElementById('currentPath').value;
|
||||
|
||||
if (!folderName) {
|
||||
alert('Please enter a folder name!');
|
||||
return;
|
||||
}
|
||||
|
||||
// Validate folder name (no special characters except underscore and hyphen)
|
||||
const validName = /^[a-zA-Z0-9_\-]+$/.test(folderName);
|
||||
if (!validName) {
|
||||
alert('Folder name can only contain letters, numbers, underscores, and hyphens.');
|
||||
return;
|
||||
}
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append('name', folderName);
|
||||
formData.append('path', currentPath);
|
||||
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open('POST', '/mkdir', true);
|
||||
|
||||
xhr.onload = function() {
|
||||
if (xhr.status === 200) {
|
||||
window.location.reload();
|
||||
} else {
|
||||
alert('Failed to create folder: ' + xhr.responseText);
|
||||
}
|
||||
};
|
||||
|
||||
xhr.onerror = function() {
|
||||
alert('Failed to create folder - network error');
|
||||
};
|
||||
|
||||
xhr.send(formData);
|
||||
}
|
||||
|
||||
// Delete functions
|
||||
function openDeleteModal(name, path, isFolder) {
|
||||
document.getElementById('deleteItemName').textContent = (isFolder ? '📁 ' : '📄 ') + name;
|
||||
document.getElementById('deleteItemPath').value = path;
|
||||
document.getElementById('deleteItemType').value = isFolder ? 'folder' : 'file';
|
||||
document.getElementById('deleteModal').classList.add('open');
|
||||
}
|
||||
|
||||
function closeDeleteModal() {
|
||||
document.getElementById('deleteModal').classList.remove('open');
|
||||
}
|
||||
|
||||
function confirmDelete() {
|
||||
const path = document.getElementById('deleteItemPath').value;
|
||||
const itemType = document.getElementById('deleteItemType').value;
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append('path', path);
|
||||
formData.append('type', itemType);
|
||||
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open('POST', '/delete', true);
|
||||
|
||||
xhr.onload = function() {
|
||||
if (xhr.status === 200) {
|
||||
window.location.reload();
|
||||
} else {
|
||||
alert('Failed to delete: ' + xhr.responseText);
|
||||
closeDeleteModal();
|
||||
}
|
||||
};
|
||||
|
||||
xhr.onerror = function() {
|
||||
alert('Failed to delete - network error');
|
||||
closeDeleteModal();
|
||||
};
|
||||
|
||||
xhr.send(formData);
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
472
src/html/FilesPageHeader.html
Normal file
472
src/html/FilesPageHeader.html
Normal file
@ -0,0 +1,472 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>CrossPoint Reader - Files</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
|
||||
Oxygen, Ubuntu, sans-serif;
|
||||
max-width: 800px;
|
||||
margin: 0 auto;
|
||||
padding: 20px;
|
||||
background-color: #f5f5f5;
|
||||
color: #333;
|
||||
}
|
||||
h1 {
|
||||
color: #2c3e50;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
h2 {
|
||||
color: #34495e;
|
||||
margin-top: 0;
|
||||
}
|
||||
.card {
|
||||
background: white;
|
||||
border-radius: 8px;
|
||||
padding: 20px;
|
||||
margin: 15px 0;
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
.page-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: 15px;
|
||||
margin-bottom: 20px;
|
||||
padding-bottom: 15px;
|
||||
border-bottom: 2px solid #3498db;
|
||||
}
|
||||
.page-header-left {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 12px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.breadcrumb-inline {
|
||||
color: #7f8c8d;
|
||||
font-size: 1.1em;
|
||||
}
|
||||
.breadcrumb-inline a {
|
||||
color: #3498db;
|
||||
text-decoration: none;
|
||||
}
|
||||
.breadcrumb-inline a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
.breadcrumb-inline .sep {
|
||||
margin: 0 6px;
|
||||
color: #bdc3c7;
|
||||
}
|
||||
.breadcrumb-inline .current {
|
||||
color: #2c3e50;
|
||||
font-weight: 500;
|
||||
}
|
||||
.nav-links {
|
||||
margin: 20px 0;
|
||||
}
|
||||
.nav-links a {
|
||||
display: inline-block;
|
||||
padding: 10px 20px;
|
||||
background-color: #3498db;
|
||||
color: white;
|
||||
text-decoration: none;
|
||||
border-radius: 4px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
.nav-links a:hover {
|
||||
background-color: #2980b9;
|
||||
}
|
||||
/* Action buttons */
|
||||
.action-buttons {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
}
|
||||
.action-btn {
|
||||
color: white;
|
||||
padding: 10px 16px;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
font-size: 0.95em;
|
||||
font-weight: 600;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
.upload-action-btn {
|
||||
background-color: #27ae60;
|
||||
}
|
||||
.upload-action-btn:hover {
|
||||
background-color: #219a52;
|
||||
}
|
||||
.folder-action-btn {
|
||||
background-color: #f39c12;
|
||||
}
|
||||
.folder-action-btn:hover {
|
||||
background-color: #d68910;
|
||||
}
|
||||
/* Upload modal */
|
||||
.modal-overlay {
|
||||
display: none;
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
z-index: 200;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
.modal-overlay.open {
|
||||
display: flex;
|
||||
}
|
||||
.modal {
|
||||
background: white;
|
||||
border-radius: 8px;
|
||||
padding: 25px;
|
||||
max-width: 450px;
|
||||
width: 90%;
|
||||
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
.modal h3 {
|
||||
margin: 0 0 15px 0;
|
||||
color: #2c3e50;
|
||||
}
|
||||
.modal-close {
|
||||
float: right;
|
||||
background: none;
|
||||
border: none;
|
||||
font-size: 1.5em;
|
||||
cursor: pointer;
|
||||
color: #7f8c8d;
|
||||
line-height: 1;
|
||||
}
|
||||
.modal-close:hover {
|
||||
color: #2c3e50;
|
||||
}
|
||||
.file-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
.file-table th,
|
||||
.file-table td {
|
||||
padding: 12px;
|
||||
text-align: left;
|
||||
border-bottom: 1px solid #eee;
|
||||
}
|
||||
.file-table th {
|
||||
background-color: #f8f9fa;
|
||||
font-weight: 600;
|
||||
color: #7f8c8d;
|
||||
}
|
||||
.file-table tr:hover {
|
||||
background-color: #f8f9fa;
|
||||
}
|
||||
.epub-file {
|
||||
background-color: #e8f6e9 !important;
|
||||
}
|
||||
.epub-file:hover {
|
||||
background-color: #d4edda !important;
|
||||
}
|
||||
.folder-row {
|
||||
background-color: #fff9e6 !important;
|
||||
}
|
||||
.folder-row:hover {
|
||||
background-color: #fff3cd !important;
|
||||
}
|
||||
.epub-badge {
|
||||
display: inline-block;
|
||||
padding: 2px 8px;
|
||||
background-color: #27ae60;
|
||||
color: white;
|
||||
border-radius: 10px;
|
||||
font-size: 0.75em;
|
||||
margin-left: 8px;
|
||||
}
|
||||
.folder-badge {
|
||||
display: inline-block;
|
||||
padding: 2px 8px;
|
||||
background-color: #f39c12;
|
||||
color: white;
|
||||
border-radius: 10px;
|
||||
font-size: 0.75em;
|
||||
margin-left: 8px;
|
||||
}
|
||||
.file-icon {
|
||||
margin-right: 8px;
|
||||
}
|
||||
.folder-link {
|
||||
color: #2c3e50;
|
||||
text-decoration: none;
|
||||
cursor: pointer;
|
||||
}
|
||||
.folder-link:hover {
|
||||
color: #3498db;
|
||||
text-decoration: underline;
|
||||
}
|
||||
.upload-form {
|
||||
margin-top: 10px;
|
||||
}
|
||||
.upload-form input[type="file"] {
|
||||
margin: 10px 0;
|
||||
width: 100%;
|
||||
}
|
||||
.upload-btn {
|
||||
background-color: #27ae60;
|
||||
color: white;
|
||||
padding: 10px 20px;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
font-size: 1em;
|
||||
width: 100%;
|
||||
}
|
||||
.upload-btn:hover {
|
||||
background-color: #219a52;
|
||||
}
|
||||
.upload-btn:disabled {
|
||||
background-color: #95a5a6;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
.file-info {
|
||||
color: #7f8c8d;
|
||||
font-size: 0.85em;
|
||||
margin: 8px 0;
|
||||
}
|
||||
.no-files {
|
||||
text-align: center;
|
||||
color: #95a5a6;
|
||||
padding: 40px;
|
||||
font-style: italic;
|
||||
}
|
||||
.message {
|
||||
padding: 15px;
|
||||
border-radius: 4px;
|
||||
margin: 15px 0;
|
||||
}
|
||||
.message.success {
|
||||
background-color: #d4edda;
|
||||
color: #155724;
|
||||
border: 1px solid #c3e6cb;
|
||||
}
|
||||
.message.error {
|
||||
background-color: #f8d7da;
|
||||
color: #721c24;
|
||||
border: 1px solid #f5c6cb;
|
||||
}
|
||||
.contents-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.contents-title {
|
||||
font-size: 1.1em;
|
||||
font-weight: 600;
|
||||
color: #34495e;
|
||||
margin: 0;
|
||||
}
|
||||
.summary-inline {
|
||||
color: #7f8c8d;
|
||||
font-size: 0.9em;
|
||||
}
|
||||
#progress-container {
|
||||
display: none;
|
||||
margin-top: 10px;
|
||||
}
|
||||
#progress-bar {
|
||||
width: 100%;
|
||||
height: 20px;
|
||||
background-color: #e0e0e0;
|
||||
border-radius: 10px;
|
||||
overflow: hidden;
|
||||
}
|
||||
#progress-fill {
|
||||
height: 100%;
|
||||
background-color: #27ae60;
|
||||
width: 0%;
|
||||
transition: width 0.3s;
|
||||
}
|
||||
#progress-text {
|
||||
text-align: center;
|
||||
margin-top: 5px;
|
||||
font-size: 0.9em;
|
||||
color: #7f8c8d;
|
||||
}
|
||||
.folder-form {
|
||||
margin-top: 10px;
|
||||
}
|
||||
.folder-input {
|
||||
width: 100%;
|
||||
padding: 10px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 4px;
|
||||
font-size: 1em;
|
||||
margin-bottom: 10px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.folder-btn {
|
||||
background-color: #f39c12;
|
||||
color: white;
|
||||
padding: 10px 20px;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
font-size: 1em;
|
||||
width: 100%;
|
||||
}
|
||||
.folder-btn:hover {
|
||||
background-color: #d68910;
|
||||
}
|
||||
/* Delete button styles */
|
||||
.delete-btn {
|
||||
background: none;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
font-size: 1.1em;
|
||||
padding: 4px 8px;
|
||||
border-radius: 4px;
|
||||
color: #95a5a6;
|
||||
transition: all 0.15s;
|
||||
}
|
||||
.delete-btn:hover {
|
||||
background-color: #fee;
|
||||
color: #e74c3c;
|
||||
}
|
||||
.actions-col {
|
||||
width: 60px;
|
||||
text-align: center;
|
||||
}
|
||||
/* Delete modal */
|
||||
.delete-warning {
|
||||
color: #e74c3c;
|
||||
font-weight: 600;
|
||||
margin: 10px 0;
|
||||
}
|
||||
.delete-item-name {
|
||||
font-weight: 600;
|
||||
color: #2c3e50;
|
||||
word-break: break-all;
|
||||
}
|
||||
.delete-btn-confirm {
|
||||
background-color: #e74c3c;
|
||||
color: white;
|
||||
padding: 10px 20px;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
font-size: 1em;
|
||||
width: 100%;
|
||||
}
|
||||
.delete-btn-confirm:hover {
|
||||
background-color: #c0392b;
|
||||
}
|
||||
.delete-btn-cancel {
|
||||
background-color: #95a5a6;
|
||||
color: white;
|
||||
padding: 10px 20px;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
font-size: 1em;
|
||||
width: 100%;
|
||||
margin-top: 10px;
|
||||
}
|
||||
.delete-btn-cancel:hover {
|
||||
background-color: #7f8c8d;
|
||||
}
|
||||
/* Mobile responsive styles */
|
||||
@media (max-width: 600px) {
|
||||
body {
|
||||
padding: 10px;
|
||||
font-size: 14px;
|
||||
}
|
||||
.card {
|
||||
padding: 12px;
|
||||
margin: 10px 0;
|
||||
}
|
||||
.page-header {
|
||||
gap: 10px;
|
||||
margin-bottom: 12px;
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
.page-header-left {
|
||||
gap: 8px;
|
||||
}
|
||||
h1 {
|
||||
font-size: 1.3em;
|
||||
}
|
||||
.breadcrumb-inline {
|
||||
font-size: 0.95em;
|
||||
}
|
||||
.nav-links a {
|
||||
padding: 8px 12px;
|
||||
margin-right: 6px;
|
||||
font-size: 0.9em;
|
||||
}
|
||||
.action-buttons {
|
||||
gap: 6px;
|
||||
}
|
||||
.action-btn {
|
||||
padding: 8px 10px;
|
||||
font-size: 0.85em;
|
||||
}
|
||||
.file-table th,
|
||||
.file-table td {
|
||||
padding: 8px 6px;
|
||||
font-size: 0.9em;
|
||||
}
|
||||
.file-table th {
|
||||
font-size: 0.85em;
|
||||
}
|
||||
.file-icon {
|
||||
margin-right: 4px;
|
||||
}
|
||||
.epub-badge,
|
||||
.folder-badge {
|
||||
padding: 2px 5px;
|
||||
font-size: 0.65em;
|
||||
margin-left: 4px;
|
||||
}
|
||||
.contents-header {
|
||||
margin-bottom: 8px;
|
||||
flex-wrap: wrap;
|
||||
gap: 4px;
|
||||
}
|
||||
.contents-title {
|
||||
font-size: 1em;
|
||||
}
|
||||
.summary-inline {
|
||||
font-size: 0.8em;
|
||||
}
|
||||
.modal {
|
||||
padding: 15px;
|
||||
}
|
||||
.modal h3 {
|
||||
font-size: 1.1em;
|
||||
}
|
||||
.actions-col {
|
||||
width: 40px;
|
||||
}
|
||||
.delete-btn {
|
||||
font-size: 1em;
|
||||
padding: 2px 4px;
|
||||
}
|
||||
.no-files {
|
||||
padding: 20px;
|
||||
font-size: 0.9em;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="nav-links">
|
||||
<a href="/">Home</a>
|
||||
<a href="/files">File Manager</a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
108
src/html/HomePage.html
Normal file
108
src/html/HomePage.html
Normal file
@ -0,0 +1,108 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>CrossPoint Reader</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
|
||||
Oxygen, Ubuntu, sans-serif;
|
||||
max-width: 800px;
|
||||
margin: 0 auto;
|
||||
padding: 20px;
|
||||
background-color: #f5f5f5;
|
||||
color: #333;
|
||||
}
|
||||
h1 {
|
||||
color: #2c3e50;
|
||||
border-bottom: 2px solid #3498db;
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
h2 {
|
||||
color: #34495e;
|
||||
margin-top: 0;
|
||||
}
|
||||
.card {
|
||||
background: white;
|
||||
border-radius: 8px;
|
||||
padding: 20px;
|
||||
margin: 15px 0;
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
.info-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
padding: 8px 0;
|
||||
border-bottom: 1px solid #eee;
|
||||
}
|
||||
.info-row:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
.label {
|
||||
font-weight: 600;
|
||||
color: #7f8c8d;
|
||||
}
|
||||
.value {
|
||||
color: #2c3e50;
|
||||
}
|
||||
.status {
|
||||
display: inline-block;
|
||||
padding: 4px 12px;
|
||||
border-radius: 12px;
|
||||
background-color: #27ae60;
|
||||
color: white;
|
||||
font-size: 0.9em;
|
||||
}
|
||||
.nav-links {
|
||||
margin: 20px 0;
|
||||
}
|
||||
.nav-links a {
|
||||
display: inline-block;
|
||||
padding: 10px 20px;
|
||||
background-color: #3498db;
|
||||
color: white;
|
||||
text-decoration: none;
|
||||
border-radius: 4px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
.nav-links a:hover {
|
||||
background-color: #2980b9;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>📚 CrossPoint Reader</h1>
|
||||
|
||||
<div class="nav-links">
|
||||
<a href="/">Home</a>
|
||||
<a href="/files">File Manager</a>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<h2>Device Status</h2>
|
||||
<div class="info-row">
|
||||
<span class="label">Version</span>
|
||||
<span class="value">%VERSION%</span>
|
||||
</div>
|
||||
<div class="info-row">
|
||||
<span class="label">WiFi Status</span>
|
||||
<span class="status">Connected</span>
|
||||
</div>
|
||||
<div class="info-row">
|
||||
<span class="label">IP Address</span>
|
||||
<span class="value">%IP_ADDRESS%</span>
|
||||
</div>
|
||||
<div class="info-row">
|
||||
<span class="label">Free Memory</span>
|
||||
<span class="value">%FREE_HEAP% bytes</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<p style="text-align: center; color: #95a5a6; margin: 0">
|
||||
CrossPoint E-Reader • Open Source
|
||||
</p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
156
src/main.cpp
156
src/main.cpp
@ -18,14 +18,14 @@
|
||||
#include "CrossPointSettings.h"
|
||||
#include "CrossPointState.h"
|
||||
#include "CrossPointWebServer.h"
|
||||
#include "activities/boot_sleep/BootActivity.h"
|
||||
#include "activities/boot_sleep/SleepActivity.h"
|
||||
#include "activities/home/HomeActivity.h"
|
||||
#include "activities/network/WifiScreen.h"
|
||||
#include "activities/reader/ReaderActivity.h"
|
||||
#include "activities/settings/SettingsActivity.h"
|
||||
#include "activities/util/FullScreenMessageActivity.h"
|
||||
#include "config.h"
|
||||
#include "screens/BootLogoScreen.h"
|
||||
#include "screens/EpubReaderScreen.h"
|
||||
#include "screens/FileSelectionScreen.h"
|
||||
#include "screens/FullScreenMessageScreen.h"
|
||||
#include "screens/SettingsScreen.h"
|
||||
#include "screens/SleepScreen.h"
|
||||
#include "screens/WifiScreen.h"
|
||||
|
||||
#define SPI_FQ 40000000
|
||||
// Display SPI pins (custom pins for XteinkX4, not hardware SPI defaults)
|
||||
@ -44,8 +44,7 @@
|
||||
EInkDisplay einkDisplay(EPD_SCLK, EPD_MOSI, EPD_CS, EPD_DC, EPD_RST, EPD_BUSY);
|
||||
InputManager inputManager;
|
||||
GfxRenderer renderer(einkDisplay);
|
||||
Screen* currentScreen;
|
||||
CrossPointState appState;
|
||||
Activity* currentActivity;
|
||||
|
||||
// Fonts
|
||||
EpdFont bookerlyFont(&bookerly_2b);
|
||||
@ -69,31 +68,16 @@ constexpr unsigned long POWER_BUTTON_SLEEP_MS = 500;
|
||||
// Auto-sleep timeout (10 minutes of inactivity)
|
||||
constexpr unsigned long AUTO_SLEEP_TIMEOUT_MS = 10 * 60 * 1000;
|
||||
|
||||
std::unique_ptr<Epub> loadEpub(const std::string& path) {
|
||||
if (!SD.exists(path.c_str())) {
|
||||
Serial.printf("[%lu] [ ] File does not exist: %s\n", millis(), path.c_str());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto epub = std::unique_ptr<Epub>(new Epub(path, "/.crosspoint"));
|
||||
if (epub->load()) {
|
||||
return epub;
|
||||
}
|
||||
|
||||
Serial.printf("[%lu] [ ] Failed to load epub\n", millis());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void exitScreen() {
|
||||
if (currentScreen) {
|
||||
currentScreen->onExit();
|
||||
delete currentScreen;
|
||||
void exitActivity() {
|
||||
if (currentActivity) {
|
||||
currentActivity->onExit();
|
||||
delete currentActivity;
|
||||
}
|
||||
}
|
||||
|
||||
void enterNewScreen(Screen* screen) {
|
||||
currentScreen = screen;
|
||||
currentScreen->onEnter();
|
||||
void enterNewActivity(Activity* activity) {
|
||||
currentActivity = activity;
|
||||
currentActivity->onEnter();
|
||||
}
|
||||
|
||||
// Verify long press on wake-up from deep sleep
|
||||
@ -137,8 +121,8 @@ void waitForPowerRelease() {
|
||||
|
||||
// Enter deep sleep mode
|
||||
void enterDeepSleep() {
|
||||
exitScreen();
|
||||
enterNewScreen(new SleepScreen(renderer, inputManager));
|
||||
exitActivity();
|
||||
enterNewActivity(new SleepActivity(renderer, inputManager));
|
||||
|
||||
Serial.printf("[%lu] [ ] Power button released after a long press. Entering deep sleep.\n", millis());
|
||||
delay(1000); // Allow Serial buffer to empty and display to update
|
||||
@ -153,40 +137,27 @@ void enterDeepSleep() {
|
||||
}
|
||||
|
||||
void onGoHome();
|
||||
void onSelectEpubFile(const std::string& path) {
|
||||
exitScreen();
|
||||
enterNewScreen(new FullScreenMessageScreen(renderer, inputManager, "Loading..."));
|
||||
|
||||
auto epub = loadEpub(path);
|
||||
if (epub) {
|
||||
appState.openEpubPath = path;
|
||||
appState.saveToFile();
|
||||
exitScreen();
|
||||
enterNewScreen(new EpubReaderScreen(renderer, inputManager, std::move(epub), onGoHome));
|
||||
} else {
|
||||
exitScreen();
|
||||
enterNewScreen(
|
||||
new FullScreenMessageScreen(renderer, inputManager, "Failed to load epub", REGULAR, EInkDisplay::HALF_REFRESH));
|
||||
delay(2000);
|
||||
onGoHome();
|
||||
}
|
||||
void onGoToReader(const std::string& initialEpubPath) {
|
||||
exitActivity();
|
||||
enterNewActivity(new ReaderActivity(renderer, inputManager, initialEpubPath, onGoHome));
|
||||
}
|
||||
void onGoToReaderHome() { onGoToReader(std::string()); }
|
||||
|
||||
void onGoToSettings();
|
||||
|
||||
void onGoToWifi() {
|
||||
exitScreen();
|
||||
enterNewScreen(new WifiScreen(renderer, inputManager, onGoToSettings));
|
||||
exitActivity();
|
||||
enterNewActivity(new WifiScreen(renderer, inputManager, onGoToSettings));
|
||||
}
|
||||
|
||||
void onGoToSettings() {
|
||||
exitScreen();
|
||||
enterNewScreen(new SettingsScreen(renderer, inputManager, onGoHome, onGoToWifi));
|
||||
exitActivity();
|
||||
enterNewActivity(new SettingsActivity(renderer, inputManager, onGoHome, onGoToWifi));
|
||||
}
|
||||
|
||||
void onGoHome() {
|
||||
exitScreen();
|
||||
enterNewScreen(new FileSelectionScreen(renderer, inputManager, onSelectEpubFile, onGoToSettings));
|
||||
exitActivity();
|
||||
enterNewActivity(new HomeActivity(renderer, inputManager, onGoToReaderHome, onGoToSettings));
|
||||
}
|
||||
|
||||
void setup() {
|
||||
@ -212,34 +183,39 @@ void setup() {
|
||||
renderer.insertFont(SMALL_FONT_ID, smallFontFamily);
|
||||
Serial.printf("[%lu] [ ] Fonts setup\n", millis());
|
||||
|
||||
exitScreen();
|
||||
enterNewScreen(new BootLogoScreen(renderer, inputManager));
|
||||
exitActivity();
|
||||
enterNewActivity(new BootActivity(renderer, inputManager));
|
||||
|
||||
// SD Card Initialization
|
||||
SD.begin(SD_SPI_CS, SPI, SPI_FQ);
|
||||
|
||||
SETTINGS.loadFromFile();
|
||||
appState.loadFromFile();
|
||||
if (!appState.openEpubPath.empty()) {
|
||||
auto epub = loadEpub(appState.openEpubPath);
|
||||
if (epub) {
|
||||
exitScreen();
|
||||
enterNewScreen(new EpubReaderScreen(renderer, inputManager, std::move(epub), onGoHome));
|
||||
// Ensure we're not still holding the power button before leaving setup
|
||||
waitForPowerRelease();
|
||||
return;
|
||||
}
|
||||
APP_STATE.loadFromFile();
|
||||
if (APP_STATE.openEpubPath.empty()) {
|
||||
onGoHome();
|
||||
} else {
|
||||
onGoToReader(APP_STATE.openEpubPath);
|
||||
}
|
||||
|
||||
exitScreen();
|
||||
enterNewScreen(new FileSelectionScreen(renderer, inputManager, onSelectEpubFile, onGoToSettings));
|
||||
|
||||
// Ensure we're not still holding the power button before leaving setup
|
||||
waitForPowerRelease();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
delay(10);
|
||||
static unsigned long lastLoopTime = 0;
|
||||
static unsigned long maxLoopDuration = 0;
|
||||
static unsigned long lastHandleClientTime = 0;
|
||||
|
||||
unsigned long loopStartTime = millis();
|
||||
unsigned long timeSinceLastLoop = loopStartTime - lastLoopTime;
|
||||
|
||||
// Reduce delay when webserver is running to allow faster handleClient() calls
|
||||
// This is critical for upload performance and preventing TCP timeouts
|
||||
if (crossPointWebServer.isRunning()) {
|
||||
delay(1); // Minimal delay to prevent tight loop
|
||||
} else {
|
||||
delay(10); // Normal delay when webserver not active
|
||||
}
|
||||
|
||||
static unsigned long lastMemPrint = 0;
|
||||
if (Serial && millis() - lastMemPrint >= 10000) {
|
||||
@ -248,11 +224,6 @@ void loop() {
|
||||
lastMemPrint = millis();
|
||||
}
|
||||
|
||||
// Handle web server clients if WiFi is connected
|
||||
if (WiFi.status() == WL_CONNECTED) {
|
||||
crossPointWebServer.handleClient();
|
||||
}
|
||||
|
||||
inputManager.update();
|
||||
|
||||
// Check for any user activity (button press or release)
|
||||
@ -274,7 +245,34 @@ void loop() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentScreen) {
|
||||
currentScreen->handleInput();
|
||||
unsigned long activityStartTime = millis();
|
||||
if (currentActivity) {
|
||||
currentActivity->loop();
|
||||
}
|
||||
unsigned long activityDuration = millis() - activityStartTime;
|
||||
|
||||
// Handle web server requests if running
|
||||
if (crossPointWebServer.isRunning()) {
|
||||
unsigned long timeSinceLastHandleClient = millis() - lastHandleClientTime;
|
||||
|
||||
// Log if there's a significant gap between handleClient calls (>100ms)
|
||||
if (lastHandleClientTime > 0 && timeSinceLastHandleClient > 100) {
|
||||
Serial.printf("[%lu] [LOOP] WARNING: %lu ms gap since last handleClient (activity took %lu ms)\n", millis(),
|
||||
timeSinceLastHandleClient, activityDuration);
|
||||
}
|
||||
|
||||
crossPointWebServer.handleClient();
|
||||
lastHandleClientTime = millis();
|
||||
}
|
||||
|
||||
unsigned long loopDuration = millis() - loopStartTime;
|
||||
if (loopDuration > maxLoopDuration) {
|
||||
maxLoopDuration = loopDuration;
|
||||
if (maxLoopDuration > 50) {
|
||||
Serial.printf("[%lu] [LOOP] New max loop duration: %lu ms (activity: %lu ms)\n", millis(), maxLoopDuration,
|
||||
activityDuration);
|
||||
}
|
||||
}
|
||||
|
||||
lastLoopTime = loopStartTime;
|
||||
}
|
||||
|
||||
@ -1,8 +0,0 @@
|
||||
#pragma once
|
||||
#include "Screen.h"
|
||||
|
||||
class BootLogoScreen final : public Screen {
|
||||
public:
|
||||
explicit BootLogoScreen(GfxRenderer& renderer, InputManager& inputManager) : Screen(renderer, inputManager) {}
|
||||
void onEnter() override;
|
||||
};
|
||||
@ -1,21 +0,0 @@
|
||||
#pragma once
|
||||
#include <EInkDisplay.h>
|
||||
#include <EpdFontFamily.h>
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "Screen.h"
|
||||
|
||||
class FullScreenMessageScreen final : public Screen {
|
||||
std::string text;
|
||||
EpdFontStyle style;
|
||||
EInkDisplay::RefreshMode refreshMode;
|
||||
|
||||
public:
|
||||
explicit FullScreenMessageScreen(GfxRenderer& renderer, InputManager& inputManager, std::string text,
|
||||
const EpdFontStyle style = REGULAR,
|
||||
const EInkDisplay::RefreshMode refreshMode = EInkDisplay::FAST_REFRESH)
|
||||
: Screen(renderer, inputManager), text(std::move(text)), style(style), refreshMode(refreshMode) {}
|
||||
void onEnter() override;
|
||||
};
|
||||
@ -1,17 +0,0 @@
|
||||
#pragma once
|
||||
#include <InputManager.h>
|
||||
|
||||
class GfxRenderer;
|
||||
|
||||
class Screen {
|
||||
protected:
|
||||
GfxRenderer& renderer;
|
||||
InputManager& inputManager;
|
||||
|
||||
public:
|
||||
explicit Screen(GfxRenderer& renderer, InputManager& inputManager) : renderer(renderer), inputManager(inputManager) {}
|
||||
virtual ~Screen() = default;
|
||||
virtual void onEnter() {}
|
||||
virtual void onExit() {}
|
||||
virtual void handleInput() {}
|
||||
};
|
||||
@ -1,8 +0,0 @@
|
||||
#pragma once
|
||||
#include "Screen.h"
|
||||
|
||||
class SleepScreen final : public Screen {
|
||||
public:
|
||||
explicit SleepScreen(GfxRenderer& renderer, InputManager& inputManager) : Screen(renderer, inputManager) {}
|
||||
void onEnter() override;
|
||||
};
|
||||
Loading…
Reference in New Issue
Block a user