@@ -0,0 +1,6 @@ | |||||
# The following lines of boilerplate have to be in your project's CMakeLists | |||||
# in this exact order for cmake to work correctly | |||||
cmake_minimum_required(VERSION 3.5) | |||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake) | |||||
project(lilybook) |
@@ -0,0 +1,21 @@ | |||||
set(COMPONENT_PRIV_INCLUDEDIRS "." "../") | |||||
set(COMPONENT_SRCS | |||||
"comic24.c" | |||||
"DefaultFont.c" | |||||
"DejaVuSans18.c" | |||||
"DejaVuSans24.c" | |||||
"dejavuX.c" | |||||
"EPD.c" | |||||
"EPDspi.c" | |||||
"minya24.c" | |||||
"SmallFont.c" | |||||
"tooney32.c" | |||||
"Ubuntu16.c" | |||||
) | |||||
set(COMPONENT_REQUIRES spi_flash) | |||||
set(COMPONENT_PRIV_REQUIRES bootloader_support) | |||||
register_component() | |||||
@@ -9,7 +9,7 @@ | |||||
*/ | */ | ||||
#include "spi_master_lobo.h" | |||||
#include "spidriver/spi_master_lobo.h" | |||||
#include <errno.h> | #include <errno.h> | ||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <time.h> | #include <time.h> | ||||
@@ -13,7 +13,7 @@ | |||||
#define _EPDSPI_H_ | #define _EPDSPI_H_ | ||||
#include <stdint.h> | #include <stdint.h> | ||||
#include "spi_master_lobo.h" | |||||
#include "spidriver/spi_master_lobo.h" | |||||
#ifdef __cplusplus | #ifdef __cplusplus | ||||
extern "C" { | extern "C" { | ||||
@@ -4,4 +4,4 @@ | |||||
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.) | # (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.) | ||||
COMPONENT_SRCDIRS := . | COMPONENT_SRCDIRS := . | ||||
COMPONENT_ADD_INCLUDEDIRS := . | |||||
COMPONENT_ADD_INCLUDEDIRS := . ../ |
@@ -0,0 +1,9 @@ | |||||
set(COMPONENT_PRIV_INCLUDEDIRS ".") | |||||
set(COMPONENT_SRCS "spi_master_lobo.c") | |||||
set(COMPONENT_REQUIRES spi_flash) | |||||
set(COMPONENT_PRIV_REQUIRES bootloader_support) | |||||
register_component() | |||||
@@ -0,0 +1,17 @@ | |||||
set(COMPONENT_PRIV_INCLUDEDIRS ".") | |||||
set(COMPONENT_SRCS "esp_spiffs.c" | |||||
"list.c" | |||||
"mutex.c" | |||||
"spiffs_cache.c" | |||||
"spiffs_check.c" | |||||
"spiffs_gc.c" | |||||
"spiffs_hydrogen.c" | |||||
"spiffs_nucleus.c" | |||||
"spiffs_vfs.c") | |||||
set(COMPONENT_REQUIRES spi_flash) | |||||
set(COMPONENT_PRIV_REQUIRES bootloader_support) | |||||
register_component() | |||||
@@ -0,0 +1,5 @@ | |||||
FILE(GLOB_RECURSE app_sources *.cpp *.c) | |||||
set(COMPONENT_SRCS "${app_sources} main.cpp") | |||||
set(COMPONENT_ADD_INCLUDEDIRS "." "../components/") | |||||
register_component() |
@@ -2,7 +2,7 @@ menu "LilyBook Configuration" | |||||
config SPIFFS_BASE_ADDR | config SPIFFS_BASE_ADDR | ||||
hex "SPIFFS Base address" | hex "SPIFFS Base address" | ||||
range 0x100000 0x1FFE000 | |||||
# range 0x100000 0x1FFE000 | |||||
default 0x180000 | default 0x180000 | ||||
help | help | ||||
Starting address of the SPIFFS area in ESP32 Flash | Starting address of the SPIFFS area in ESP32 Flash | ||||
@@ -1,6 +1,6 @@ | |||||
#include "spi_master_lobo.h" | |||||
#include "EPD.h" | |||||
#include "spidriver/spi_master_lobo.h" | |||||
#include "epaper/EPD.h" | |||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include "esp_system.h" | #include "esp_system.h" | ||||
#include "driver/gpio.h" | #include "driver/gpio.h" | ||||
@@ -9,7 +9,7 @@ | |||||
#include "driver/sdmmc_host.h" | #include "driver/sdmmc_host.h" | ||||
#include "driver/sdspi_host.h" | #include "driver/sdspi_host.h" | ||||
#include "sdmmc_cmd.h" | #include "sdmmc_cmd.h" | ||||
#include "spiffs_vfs.h" | |||||
#include "spiffs/spiffs_vfs.h" | |||||
#include "storage.h" | #include "storage.h" | ||||
static const char *tag = "storage"; | static const char *tag = "storage"; | ||||
@@ -1,25 +1,23 @@ | |||||
#include "core/common.h" | #include "core/common.h" | ||||
#include "core/buttons.h" | #include "core/buttons.h" | ||||
#include "core/display.h" | #include "core/display.h" | ||||
#include <EPD.h> | |||||
#include <epaper/EPD.h> | |||||
#include "ModeRunner.h" | #include "ModeRunner.h" | ||||
#include "ReaderMode.h" | #include "ReaderMode.h" | ||||
#include "AbstractMenuMode.h" | #include "AbstractMenuMode.h" | ||||
static int baseY = 35; | static int baseY = 35; | ||||
static int menuSkip = 20; | |||||
static int x = 40; | |||||
static int menu_options_size = 4; | |||||
static int x = 20; | |||||
void draw_menu_option(char* text, int line, bool selected) | |||||
void draw_menu_option(char* text, int textX, int textHeight, int line, bool selected) | |||||
{ | { | ||||
EPD_print(text, CENTER, baseY + line * menuSkip); | |||||
EPD_print(text, textX, baseY + line * textHeight); | |||||
} | } | ||||
void draw_menu_cursor(int cursor) | |||||
void draw_menu_cursor(int cursor, int textHeight) | |||||
{ | { | ||||
EPD_drawRect(x, baseY + cursor * menuSkip, | |||||
EPD_DISPLAY_WIDTH - 2*x, menuSkip + 1, 0x0F); | |||||
EPD_drawRect(x, baseY + cursor * textHeight, | |||||
EPD_DISPLAY_WIDTH - 2*x, textHeight + 1, 0x0F); | |||||
} | } | ||||
void AbstractMenuMode::start() | void AbstractMenuMode::start() | ||||
@@ -32,13 +30,18 @@ void AbstractMenuMode::loop() | |||||
EPD_print(this->getTitle(), CENTER, 0); | EPD_print(this->getTitle(), CENTER, 0); | ||||
int line = 0; | int line = 0; | ||||
EPD_setFont(DEJAVU18_FONT, NULL); | |||||
EPD_setFont(this->getOptionsFont(), NULL); | |||||
int menu_option_height = EPD_getfontheight() + 1; | |||||
int menu_options_limit = (EPD_DISPLAY_HEIGHT - baseY) / (EPD_getfontheight() + 1); | |||||
char** options = this->getOptions(); | char** options = this->getOptions(); | ||||
int menu_options_size = this->getOptionsSize(); | int menu_options_size = this->getOptionsSize(); | ||||
for (int line = 0; line < menu_options_size; line++) { | |||||
draw_menu_option(options[line], line, this->cursor == line); | |||||
int start = (this->cursor / menu_options_limit) * menu_options_limit; | |||||
int stop = ((this->cursor / menu_options_limit) + 1) * menu_options_limit; | |||||
for (int line = start; line < menu_options_size && line < stop; line++) { | |||||
draw_menu_option(options[line], this->getOptionsX(), menu_option_height, | |||||
line % menu_options_limit, this->cursor == line); | |||||
} | } | ||||
draw_menu_cursor(this->cursor); | |||||
draw_menu_cursor(this->cursor % menu_options_limit, menu_option_height); | |||||
display_update(); | display_update(); | ||||
while(1) { | while(1) { | ||||
@@ -60,3 +63,13 @@ void AbstractMenuMode::loop() | |||||
void AbstractMenuMode::finish() | void AbstractMenuMode::finish() | ||||
{} | {} | ||||
int AbstractMenuMode::getOptionsX() | |||||
{ | |||||
return CENTER; | |||||
} | |||||
int AbstractMenuMode::getOptionsFont() | |||||
{ | |||||
return DEJAVU18_FONT; | |||||
} |
@@ -14,6 +14,8 @@ protected: | |||||
virtual char** getOptions(); | virtual char** getOptions(); | ||||
virtual int getOptionsSize(); | virtual int getOptionsSize(); | ||||
virtual void onOptionSelected(int option); | virtual void onOptionSelected(int option); | ||||
virtual int getOptionsX(); | |||||
virtual int getOptionsFont(); | |||||
private: | private: | ||||
int cursor = 0; | int cursor = 0; | ||||
@@ -1,7 +1,7 @@ | |||||
#include "core/common.h" | #include "core/common.h" | ||||
#include "core/buttons.h" | #include "core/buttons.h" | ||||
#include "core/display.h" | #include "core/display.h" | ||||
#include <EPD.h> | |||||
#include <epaper/EPD.h> | |||||
#include "InternalMemoryMenuMode.h" | #include "InternalMemoryMenuMode.h" | ||||
void InternalMemoryMenuMode::start() | void InternalMemoryMenuMode::start() | ||||
@@ -1,7 +1,7 @@ | |||||
#include "core/common.h" | #include "core/common.h" | ||||
#include "core/buttons.h" | #include "core/buttons.h" | ||||
#include "core/display.h" | #include "core/display.h" | ||||
#include <EPD.h> | |||||
#include <epaper/EPD.h> | |||||
#include "ModeRunner.h" | #include "ModeRunner.h" | ||||
#include "ReaderMode.h" | #include "ReaderMode.h" | ||||
#include "InternalMemoryMenuMode.h" | #include "InternalMemoryMenuMode.h" | ||||
@@ -12,7 +12,7 @@ | |||||
static char* options[] = { | static char* options[] = { | ||||
"Continue Reading", | "Continue Reading", | ||||
"Internal Memory", | "Internal Memory", | ||||
"SC Card", | |||||
"SD Card", | |||||
"Settings" | "Settings" | ||||
}; | }; | ||||
@@ -1,23 +1,87 @@ | |||||
#include <string.h> | |||||
#include "core/common.h" | #include "core/common.h" | ||||
#include "core/buttons.h" | #include "core/buttons.h" | ||||
#include "core/display.h" | #include "core/display.h" | ||||
#include <EPD.h> | |||||
#include <epaper/EPD.h> | |||||
#include <stdio.h> | |||||
#include <unistd.h> | |||||
#include <sys/stat.h> | |||||
#include <sys/types.h> | |||||
#include <dirent.h> | |||||
#include "SdCardMenuMode.h" | #include "SdCardMenuMode.h" | ||||
static char* options[] = { | |||||
"[Back]", | |||||
"/file.txt", | |||||
"/book.txt", | |||||
"/asdf.gif", | |||||
}; | |||||
#include "esp_log.h" | |||||
static char* TAG = "SdCardMenuMode"; | |||||
// TODO: make use of bytes | |||||
void SdCardMenuMode::start() | void SdCardMenuMode::start() | ||||
{ | { | ||||
display_refresh(); | display_refresh(); | ||||
dir_entry_t* dir_chain_start = new dir_entry_t; | |||||
strcpy(dir_chain_start->name, "[Back]"); | |||||
dir_entry_t* last_entry = dir_chain_start; | |||||
int entries = 1; | |||||
struct stat stats; | |||||
struct dirent *dir; | |||||
DIR* d = opendir(this->basedir); | |||||
if (d) | |||||
{ | |||||
while ((dir = readdir(d)) != NULL) | |||||
{ | |||||
ESP_LOGI(TAG, "* %s", dir->d_name); | |||||
dir_entry_t* new_entry = new dir_entry_t; | |||||
strcpy(new_entry->name, dir->d_name); | |||||
char path[64]; | |||||
strcpy(path, this->basedir); | |||||
strcat(path, dir->d_name); | |||||
if (stat(path, &stats) == 0) { | |||||
last_entry->bytes = stats.st_size; | |||||
} | |||||
new_entry->next = NULL; | |||||
if (dir_chain_start == NULL) { | |||||
dir_chain_start = new_entry; | |||||
} | |||||
if (last_entry == NULL) { | |||||
last_entry = new_entry; | |||||
} else { | |||||
last_entry->next = new_entry; | |||||
last_entry = new_entry; | |||||
} | |||||
entries++; | |||||
} | |||||
closedir(d); | |||||
} else { | |||||
ESP_LOGE(TAG, "Could not open dir."); | |||||
} | |||||
this->optionsNames = new char[entries*DIR_ENTRY_NAME_SIZE]; | |||||
this->options = new char*[entries]; | |||||
this->optionsBytes = new unsigned long[entries]; | |||||
this->optionsSize = entries; | |||||
last_entry = dir_chain_start; | |||||
int i = 0; | |||||
while (last_entry != NULL) { | |||||
this->options[i] = &this->optionsNames[i * DIR_ENTRY_NAME_SIZE]; | |||||
memcpy(this->options[i], last_entry->name, DIR_ENTRY_NAME_SIZE); | |||||
this->optionsBytes[i] = last_entry->bytes; | |||||
dir_entry_t* next = (dir_entry_t*)last_entry->next; | |||||
delete last_entry; | |||||
last_entry = next; | |||||
i++; | |||||
} | |||||
} | } | ||||
void SdCardMenuMode::finish() | void SdCardMenuMode::finish() | ||||
{} | |||||
{ | |||||
delete this->options; | |||||
delete this->optionsNames; | |||||
delete this->optionsBytes; | |||||
} | |||||
char* SdCardMenuMode::getTitle() | char* SdCardMenuMode::getTitle() | ||||
{ | { | ||||
@@ -26,12 +90,12 @@ char* SdCardMenuMode::getTitle() | |||||
char** SdCardMenuMode::getOptions() | char** SdCardMenuMode::getOptions() | ||||
{ | { | ||||
return options; | |||||
return this->options; | |||||
} | } | ||||
int SdCardMenuMode::getOptionsSize() | int SdCardMenuMode::getOptionsSize() | ||||
{ | { | ||||
return 4; | |||||
return this->optionsSize; | |||||
} | } | ||||
void SdCardMenuMode::onOptionSelected(int option) | void SdCardMenuMode::onOptionSelected(int option) | ||||
@@ -42,3 +106,13 @@ void SdCardMenuMode::onOptionSelected(int option) | |||||
} | } | ||||
// TODO files | // TODO files | ||||
} | } | ||||
int SdCardMenuMode::getOptionsX() | |||||
{ | |||||
return 35; | |||||
} | |||||
int SdCardMenuMode::getOptionsFont() | |||||
{ | |||||
return SMALL_FONT; | |||||
} |
@@ -1,17 +1,31 @@ | |||||
#include "AppMode.h" | #include "AppMode.h" | ||||
#include "AbstractMenuMode.h" | #include "AbstractMenuMode.h" | ||||
#define DIR_ENTRY_NAME_SIZE 16 | |||||
typedef struct { | |||||
char name[DIR_ENTRY_NAME_SIZE]; | |||||
unsigned long bytes; | |||||
void* next; | |||||
} dir_entry_t; | |||||
class SdCardMenuMode : public AbstractMenuMode | class SdCardMenuMode : public AbstractMenuMode | ||||
{ | { | ||||
public: | public: | ||||
virtual void start(); | |||||
virtual void finish(); | |||||
void start(); | |||||
void finish(); | |||||
protected: | protected: | ||||
virtual char* getTitle(); | |||||
virtual char** getOptions(); | |||||
virtual int getOptionsSize(); | |||||
virtual void onOptionSelected(int option); | |||||
char* getTitle(); | |||||
char** getOptions(); | |||||
int getOptionsSize(); | |||||
void onOptionSelected(int option); | |||||
int getOptionsX(); | |||||
int getOptionsFont(); | |||||
private: | private: | ||||
char* basedir = "/sdcard/"; | |||||
char** options; | |||||
char* optionsNames; | |||||
unsigned long* optionsBytes; | |||||
int optionsSize; | |||||
}; | }; |
@@ -1,7 +1,7 @@ | |||||
#include "core/common.h" | #include "core/common.h" | ||||
#include "core/buttons.h" | #include "core/buttons.h" | ||||
#include "core/display.h" | #include "core/display.h" | ||||
#include <EPD.h> | |||||
#include <epaper/EPD.h> | |||||
#include "SettingsMenuMode.h" | #include "SettingsMenuMode.h" | ||||
static char* options[] = { | static char* options[] = { | ||||
@@ -38,7 +38,7 @@ void SettingsMenuMode::onOptionSelected(int option) | |||||
{ | { | ||||
switch (option) { | switch (option) { | ||||
case 0: | case 0: | ||||
// TODO | |||||
this->setFinished(); | |||||
return; | return; | ||||
case 1: | case 1: | ||||
// TODO | // TODO | ||||
@@ -47,7 +47,7 @@ void SettingsMenuMode::onOptionSelected(int option) | |||||
// TODO | // TODO | ||||
break; | break; | ||||
case 3: | case 3: | ||||
this->setFinished(); | |||||
// TODO | |||||
break; | break; | ||||
} | } | ||||
} | } |
@@ -1,5 +1,5 @@ | |||||
#include "core/display.h" | #include "core/display.h" | ||||
#include "EPD.h" | |||||
#include "epaper/EPD.h" | |||||
#include "PagePrinter.h" | #include "PagePrinter.h" | ||||
#include "esp_log.h" | #include "esp_log.h" | ||||
@@ -1,6 +1,6 @@ | |||||
#include "PageSettingsProvider.h" | #include "PageSettingsProvider.h" | ||||
#include "EPD.h" | |||||
#include "EPDspi.h" // TODO: remove after display config is extracted | |||||
#include "epaper/EPD.h" | |||||
#include "epaper/EPDspi.h" // TODO: remove after display config is extracted | |||||
int PageSettingsProvider::getWidth() | int PageSettingsProvider::getWidth() | ||||
{ | { | ||||