Prepared page handling. Added EPD frame selection.
This commit is contained in:
@@ -22,6 +22,6 @@ void PagePrinter::print(Page* page)
|
||||
EPD_setFont(font, NULL);
|
||||
text_wrap = 1;
|
||||
EPD_print(page->text, 0, 0);
|
||||
EPD_UpdateScreen();
|
||||
//EPD_UpdateScreen();
|
||||
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
#include <string.h>
|
||||
#include "TextReader.h"
|
||||
|
||||
#include "esp_log.h"
|
||||
@@ -15,6 +16,14 @@ void TextReader::close()
|
||||
|
||||
size_t TextReader::read(long pos, char* text, size_t len)
|
||||
{
|
||||
memset(text, 0, len);
|
||||
if (pos < 0) {
|
||||
len += pos;
|
||||
pos = 0;
|
||||
}
|
||||
if (len <= 0) {
|
||||
return 0;
|
||||
}
|
||||
if (this->f == NULL) {
|
||||
ESP_LOGE(TAG, "File not opened.");
|
||||
sprintf(text, "File could not be opened.");
|
||||
|
||||
+26
-2
@@ -1,10 +1,34 @@
|
||||
#include <string.h>
|
||||
#include "Typesetter.h"
|
||||
|
||||
Typesetter::Typesetter()
|
||||
{}
|
||||
|
||||
void Typesetter::preparePage(Page* page, char* text, size_t len)
|
||||
Page* Typesetter::preparePage(char* text, size_t len)
|
||||
{
|
||||
page->text = text;
|
||||
Page* page = new Page;
|
||||
page->text = new char[len+1];
|
||||
memcpy(page->text, text, len);
|
||||
page->text[len] = 0;
|
||||
page->len = len;
|
||||
return page;
|
||||
}
|
||||
|
||||
Page* Typesetter::preparePreviousPage(char* text, size_t len)
|
||||
{
|
||||
Page* page = new Page;
|
||||
page->text = new char[len+1];
|
||||
memcpy(page->text, text, len);
|
||||
page->text[len] = 0;
|
||||
page->len = len;
|
||||
return page;
|
||||
}
|
||||
|
||||
void Typesetter::destroyPage(Page* page)
|
||||
{
|
||||
if (page == NULL) {
|
||||
return;
|
||||
}
|
||||
delete page->text;
|
||||
delete page;
|
||||
}
|
||||
|
||||
+3
-4
@@ -6,8 +6,7 @@ class Typesetter
|
||||
public:
|
||||
Typesetter();
|
||||
|
||||
void preparePage(Page* page, char* text, size_t len);
|
||||
|
||||
//private:
|
||||
|
||||
Page* preparePage(char* text, size_t len);
|
||||
Page* preparePreviousPage(char* text, size_t len);
|
||||
void destroyPage(Page* page);
|
||||
};
|
||||
|
||||
@@ -1,2 +1,4 @@
|
||||
|
||||
#define APP_VERSION "0.1"
|
||||
|
||||
#define DISPLAY_SLEEP_TIMEOUT 1000
|
||||
|
||||
+13
-2
@@ -12,10 +12,12 @@
|
||||
|
||||
void display_init()
|
||||
{
|
||||
// drawing buffer
|
||||
disp_buffer = (uint8_t*)pvPortMallocCaps(EPD_DISPLAY_WIDTH * (EPD_DISPLAY_HEIGHT/8), MALLOC_CAP_DMA);
|
||||
assert(disp_buffer);
|
||||
drawBuff = disp_buffer;
|
||||
|
||||
// gray-scale drawing buffer
|
||||
gs_disp_buffer = (uint8_t*)pvPortMallocCaps(EPD_DISPLAY_WIDTH * EPD_DISPLAY_HEIGHT, MALLOC_CAP_DMA);
|
||||
assert(gs_disp_buffer);
|
||||
gs_drawBuff = gs_disp_buffer;
|
||||
@@ -67,8 +69,6 @@ void display_connect()
|
||||
|
||||
printf("SPI: attached display device, speed=%u\r\n", spi_lobo_get_speed(disp_spi));
|
||||
printf("SPI: bus uses native pins: %s\r\n", spi_lobo_uses_native_pins(disp_spi) ? "true" : "false");
|
||||
|
||||
//EPD_PowerOn();
|
||||
}
|
||||
|
||||
void display_splash_screen()
|
||||
@@ -100,3 +100,14 @@ void display_update()
|
||||
{
|
||||
EPD_UpdateScreen();
|
||||
}
|
||||
|
||||
extern void EPD_wake();
|
||||
void display_wake()
|
||||
{
|
||||
EPD_wake();
|
||||
}
|
||||
|
||||
void display_sleep()
|
||||
{
|
||||
EPD_PowerOff();
|
||||
}
|
||||
|
||||
+4
-1
@@ -5,4 +5,7 @@ void display_splash_screen();
|
||||
|
||||
void display_clear();
|
||||
void display_refresh();
|
||||
void display_update();
|
||||
void display_update();
|
||||
|
||||
void display_wake();
|
||||
void display_sleep();
|
||||
+42
-6
@@ -59,22 +59,34 @@ extern "C" void app_main()
|
||||
PagePrinter pagePrinter;
|
||||
TextStorage textStorage;
|
||||
TextReader* textReader = textStorage.open("/sdcard/book.txt");
|
||||
Page page;
|
||||
Page* pageLast = NULL;
|
||||
Page* pageCurrent = NULL;
|
||||
|
||||
long bookmark = 0;
|
||||
//bool displaySleeping = false;
|
||||
|
||||
while (1) {
|
||||
char text[1024];
|
||||
if (textReader != NULL) {
|
||||
size_t read = textReader->read(bookmark, text, sizeof(text));
|
||||
if (pageCurrent == NULL) {
|
||||
size_t read = textReader->read(bookmark, text, sizeof(text));
|
||||
pageCurrent = typesetter.preparePage(text, sizeof(text));
|
||||
}
|
||||
if (pageLast == NULL) {
|
||||
size_t read = textReader->read(bookmark - sizeof(text), text, sizeof(text));
|
||||
pageLast = typesetter.preparePreviousPage(text, sizeof(text));
|
||||
}
|
||||
} else {
|
||||
typesetter.destroyPage(pageCurrent);
|
||||
strcpy(text, "File could not be opened.");
|
||||
pageCurrent = typesetter.preparePage(text, sizeof(text));
|
||||
}
|
||||
typesetter.preparePage(&page, text, sizeof(text));
|
||||
|
||||
display_clear();
|
||||
pagePrinter.print(&page);
|
||||
pagePrinter.print(pageCurrent);
|
||||
display_update();
|
||||
|
||||
//time_t idleStart = clock();
|
||||
while (1) {
|
||||
sleep(10);
|
||||
if (buttons_pressed_ok()) {
|
||||
@@ -84,15 +96,39 @@ extern "C" void app_main()
|
||||
}
|
||||
if (buttons_pressed_plus()) {
|
||||
ESP_LOGI(TAG, "Turn page PLUS.");
|
||||
bookmark += sizeof(text);
|
||||
if (pageCurrent != NULL) {
|
||||
bookmark += pageCurrent->len;
|
||||
typesetter.destroyPage(pageLast);
|
||||
pageLast = pageCurrent;
|
||||
pageCurrent = NULL;
|
||||
} else {
|
||||
ESP_LOGW(TAG, "No current page.");
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (buttons_pressed_minus()) {
|
||||
ESP_LOGI(TAG, "Turn page MINUS.");
|
||||
bookmark -= sizeof(text);
|
||||
if (pageLast != NULL) {
|
||||
bookmark -= pageLast->len;
|
||||
typesetter.destroyPage(pageCurrent);
|
||||
pageCurrent = pageLast;
|
||||
pageLast = NULL;
|
||||
} else {
|
||||
ESP_LOGW(TAG, "No last page.");
|
||||
}
|
||||
break;
|
||||
}
|
||||
/*if (!displaySleeping && (clock() - idleStart > DISPLAY_SLEEP_TIMEOUT)) {
|
||||
displaySleeping = true;
|
||||
ESP_LOGI(TAG, "Display going to sleep after %d ms.", DISPLAY_SLEEP_TIMEOUT);
|
||||
display_sleep();
|
||||
}*/
|
||||
}
|
||||
/*if (displaySleeping) {
|
||||
displaySleeping = false;
|
||||
ESP_LOGI(TAG, "Display waking up.");
|
||||
display_wake();
|
||||
}*/
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user