@@ -23,6 +23,10 @@ | |||
#define EPD_DEBUG 1 | |||
#define EPD_BORDER_WHITE 0x61 | |||
#define EPD_BORDER_BLACK 0x51 | |||
#define EPD_BORDER EPD_BORDER_BLACK | |||
#define EPD2X9 1 | |||
#define xDot 128 | |||
@@ -54,7 +58,7 @@ static uint8_t VCOMVol[2] = {0x2c, 0xa8}; // VCOM 7c | |||
static uint8_t DummyLine[2] = {0x3a, 0x1a}; // 4 dummy line per gate | |||
static uint8_t Gatetime[2] = {0x3b, 0x08}; // 2us per line | |||
static uint8_t RamDataEntryMode[2] = {0x11, 0x01}; // Ram data entry mode | |||
static uint8_t Border[2] = {0x3c, 0x61}; // Border control ( 0x61: white border; 0x51: black border | |||
static uint8_t Border[2] = {0x3c, EPD_BORDER}; // Border control ( 0x61: white border; 0x51: black border | |||
/* | |||
There are totally 20 phases for programmable Source waveform of different phase length. | |||
@@ -528,6 +532,13 @@ static void EPD_init_Part(void) | |||
EPD_Write((uint8_t *)LUT_part, 31); | |||
EPD_PowerOn(); | |||
} | |||
void EPD_wake() | |||
{ | |||
EPD_Init(); | |||
EPD_PowerOn(); | |||
} | |||
/******************************************************************************** | |||
parameter: | |||
Label : | |||
@@ -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."); | |||
@@ -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; | |||
} |
@@ -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 |
@@ -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(); | |||
} |
@@ -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(); |
@@ -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(); | |||
}*/ | |||
} | |||
} |