1
0
mirror of https://github.com/Dejvino/lilybook.git synced 2024-11-14 20:33:28 +00:00
lilybook/main/main.cpp

99 lines
2.2 KiB
C++
Raw Normal View History

#include <time.h>
#include <errno.h>
#include <sys/fcntl.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "driver/gpio.h"
#include "esp_system.h"
#include "esp_heap_alloc_caps.h"
2020-01-31 19:54:19 +00:00
#include "esp_log.h"
static const char *TAG = "main";
2020-01-31 19:54:19 +00:00
extern "C" {
#include "config.h"
#include "buttons.h"
#include "storage.h"
#include "display.h"
}
2020-01-29 22:50:03 +00:00
2020-01-31 19:54:19 +00:00
#include "Typesetter.h"
#include "TextStorage.h"
#include "PagePrinter.h"
static struct tm* tm_info;
static char tmp_buff[128];
static time_t time_now, time_last = 0;
static const char *file_fonts[3] = {"/spiffs/fonts/DotMatrix_M.fon", "/spiffs/fonts/Ubuntu.fon", "/spiffs/fonts/Grotesk24x48.fon"};
static const char tag[] = "[LilyBook]";
esp_err_t ret;
2020-01-31 19:54:19 +00:00
void sleep(unsigned int ms)
{
2020-01-31 19:54:19 +00:00
vTaskDelay(ms / portTICK_RATE_MS);
}
extern "C" void app_main()
{
2020-01-31 19:54:19 +00:00
printf("\n LilyBook v%s\n\n", APP_VERSION);
2020-01-29 22:50:03 +00:00
2020-01-31 19:54:19 +00:00
storage_init();
buttons_init();
display_init();
spi_init();
2020-01-31 19:54:19 +00:00
sleep(500);
display_connect();
2020-01-31 19:54:19 +00:00
display_splash_screen();
2020-01-31 19:54:19 +00:00
sleep(500);
printf("==== START ====\r\n\n");
2020-01-31 19:54:19 +00:00
Typesetter typesetter;
PagePrinter pagePrinter;
TextStorage textStorage;
TextReader* textReader = textStorage.open("/sdcard/book.txt");
Page page;
2020-01-29 22:50:03 +00:00
2020-01-31 19:54:19 +00:00
long bookmark = 0;
while (1) {
2020-01-31 19:54:19 +00:00
char text[1024];
if (textReader != NULL) {
size_t read = textReader->read(bookmark, text, sizeof(text));
} else {
2020-01-31 19:54:19 +00:00
strcpy(text, "File could not be opened.");
}
2020-01-31 19:54:19 +00:00
typesetter.preparePage(&page, text, sizeof(text));
display_clear();
pagePrinter.print(&page);
display_update();
2020-01-29 22:50:03 +00:00
while (1) {
2020-01-31 19:54:19 +00:00
sleep(10);
if (buttons_pressed_ok()) {
2020-01-29 22:50:03 +00:00
ESP_LOGI(TAG, "Clear page.");
2020-01-31 19:54:19 +00:00
display_refresh();
break;
2020-01-29 22:50:03 +00:00
}
2020-01-31 19:54:19 +00:00
if (buttons_pressed_plus()) {
2020-01-29 22:50:03 +00:00
ESP_LOGI(TAG, "Turn page PLUS.");
2020-01-31 19:54:19 +00:00
bookmark += sizeof(text);
2020-01-29 22:50:03 +00:00
break;
}
2020-01-31 19:54:19 +00:00
if (buttons_pressed_minus()) {
2020-01-29 22:50:03 +00:00
ESP_LOGI(TAG, "Turn page MINUS.");
2020-01-31 19:54:19 +00:00
bookmark -= sizeof(text);
2020-01-29 22:50:03 +00:00
break;
}
}
}
}