Browse Source

Added support for SD Card browsing. Added missing CMakeLists.txt.

master
dejvino 4 years ago
parent
commit
af712d9124
20 changed files with 206 additions and 45 deletions
  1. +6
    -0
      CMakeLists.txt
  2. +21
    -0
      components/epaper/CMakeLists.txt
  3. +1
    -1
      components/epaper/EPDspi.c
  4. +1
    -1
      components/epaper/EPDspi.h
  5. +1
    -1
      components/epaper/component.mk
  6. +9
    -0
      components/spidriver/CMakeLists.txt
  7. +17
    -0
      components/spiffs/CMakeLists.txt
  8. +5
    -0
      main/CMakeLists.txt
  9. +1
    -1
      main/Kconfig.projbuild
  10. +2
    -2
      main/core/display.c
  11. +1
    -1
      main/core/storage.c
  12. +26
    -13
      main/modes/AbstractMenuMode.cpp
  13. +2
    -0
      main/modes/AbstractMenuMode.h
  14. +1
    -1
      main/modes/InternalMemoryMenuMode.cpp
  15. +2
    -2
      main/modes/MainMenuMode.cpp
  16. +84
    -10
      main/modes/SdCardMenuMode.cpp
  17. +20
    -6
      main/modes/SdCardMenuMode.h
  18. +3
    -3
      main/modes/SettingsMenuMode.cpp
  19. +1
    -1
      main/modes/reader/PagePrinter.cpp
  20. +2
    -2
      main/modes/reader/PageSettingsProvider.cpp

+ 6
- 0
CMakeLists.txt View File

@@ -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)

+ 21
- 0
components/epaper/CMakeLists.txt View File

@@ -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()



+ 1
- 1
components/epaper/EPDspi.c View File

@@ -9,7 +9,7 @@
*/


#include "spi_master_lobo.h"
#include "spidriver/spi_master_lobo.h"
#include <errno.h>
#include <stdio.h>
#include <time.h>


+ 1
- 1
components/epaper/EPDspi.h View File

@@ -13,7 +13,7 @@
#define _EPDSPI_H_

#include <stdint.h>
#include "spi_master_lobo.h"
#include "spidriver/spi_master_lobo.h"

#ifdef __cplusplus
extern "C" {


+ 1
- 1
components/epaper/component.mk View File

@@ -4,4 +4,4 @@
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)

COMPONENT_SRCDIRS := .
COMPONENT_ADD_INCLUDEDIRS := .
COMPONENT_ADD_INCLUDEDIRS := . ../

+ 9
- 0
components/spidriver/CMakeLists.txt View File

@@ -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()



+ 17
- 0
components/spiffs/CMakeLists.txt View File

@@ -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()



+ 5
- 0
main/CMakeLists.txt View File

@@ -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()

+ 1
- 1
main/Kconfig.projbuild View File

@@ -2,7 +2,7 @@ menu "LilyBook Configuration"

config SPIFFS_BASE_ADDR
hex "SPIFFS Base address"
range 0x100000 0x1FFE000
# range 0x100000 0x1FFE000
default 0x180000
help
Starting address of the SPIFFS area in ESP32 Flash


+ 2
- 2
main/core/display.c View File

@@ -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 "esp_system.h"
#include "driver/gpio.h"


+ 1
- 1
main/core/storage.c View File

@@ -9,7 +9,7 @@
#include "driver/sdmmc_host.h"
#include "driver/sdspi_host.h"
#include "sdmmc_cmd.h"
#include "spiffs_vfs.h"
#include "spiffs/spiffs_vfs.h"
#include "storage.h"

static const char *tag = "storage";


+ 26
- 13
main/modes/AbstractMenuMode.cpp View File

@@ -1,25 +1,23 @@
#include "core/common.h"
#include "core/buttons.h"
#include "core/display.h"
#include <EPD.h>
#include <epaper/EPD.h>
#include "ModeRunner.h"
#include "ReaderMode.h"
#include "AbstractMenuMode.h"

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()
@@ -32,13 +30,18 @@ void AbstractMenuMode::loop()
EPD_print(this->getTitle(), CENTER, 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();
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();

while(1) {
@@ -60,3 +63,13 @@ void AbstractMenuMode::loop()

void AbstractMenuMode::finish()
{}

int AbstractMenuMode::getOptionsX()
{
return CENTER;
}

int AbstractMenuMode::getOptionsFont()
{
return DEJAVU18_FONT;
}

+ 2
- 0
main/modes/AbstractMenuMode.h View File

@@ -14,6 +14,8 @@ protected:
virtual char** getOptions();
virtual int getOptionsSize();
virtual void onOptionSelected(int option);
virtual int getOptionsX();
virtual int getOptionsFont();

private:
int cursor = 0;


+ 1
- 1
main/modes/InternalMemoryMenuMode.cpp View File

@@ -1,7 +1,7 @@
#include "core/common.h"
#include "core/buttons.h"
#include "core/display.h"
#include <EPD.h>
#include <epaper/EPD.h>
#include "InternalMemoryMenuMode.h"

void InternalMemoryMenuMode::start()


+ 2
- 2
main/modes/MainMenuMode.cpp View File

@@ -1,7 +1,7 @@
#include "core/common.h"
#include "core/buttons.h"
#include "core/display.h"
#include <EPD.h>
#include <epaper/EPD.h>
#include "ModeRunner.h"
#include "ReaderMode.h"
#include "InternalMemoryMenuMode.h"
@@ -12,7 +12,7 @@
static char* options[] = {
"Continue Reading",
"Internal Memory",
"SC Card",
"SD Card",
"Settings"
};



+ 84
- 10
main/modes/SdCardMenuMode.cpp View File

@@ -1,23 +1,87 @@
#include <string.h>
#include "core/common.h"
#include "core/buttons.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"

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()
{
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()
{}
{
delete this->options;
delete this->optionsNames;
delete this->optionsBytes;
}

char* SdCardMenuMode::getTitle()
{
@@ -26,12 +90,12 @@ char* SdCardMenuMode::getTitle()

char** SdCardMenuMode::getOptions()
{
return options;
return this->options;
}
int SdCardMenuMode::getOptionsSize()
{
return 4;
return this->optionsSize;
}

void SdCardMenuMode::onOptionSelected(int option)
@@ -42,3 +106,13 @@ void SdCardMenuMode::onOptionSelected(int option)
}
// TODO files
}

int SdCardMenuMode::getOptionsX()
{
return 35;
}

int SdCardMenuMode::getOptionsFont()
{
return SMALL_FONT;
}

+ 20
- 6
main/modes/SdCardMenuMode.h View File

@@ -1,17 +1,31 @@
#include "AppMode.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
{
public:
virtual void start();
virtual void finish();
void start();
void finish();

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:
char* basedir = "/sdcard/";
char** options;
char* optionsNames;
unsigned long* optionsBytes;
int optionsSize;
};

+ 3
- 3
main/modes/SettingsMenuMode.cpp View File

@@ -1,7 +1,7 @@
#include "core/common.h"
#include "core/buttons.h"
#include "core/display.h"
#include <EPD.h>
#include <epaper/EPD.h>
#include "SettingsMenuMode.h"

static char* options[] = {
@@ -38,7 +38,7 @@ void SettingsMenuMode::onOptionSelected(int option)
{
switch (option) {
case 0:
// TODO
this->setFinished();
return;
case 1:
// TODO
@@ -47,7 +47,7 @@ void SettingsMenuMode::onOptionSelected(int option)
// TODO
break;
case 3:
this->setFinished();
// TODO
break;
}
}

+ 1
- 1
main/modes/reader/PagePrinter.cpp View File

@@ -1,5 +1,5 @@
#include "core/display.h"
#include "EPD.h"
#include "epaper/EPD.h"
#include "PagePrinter.h"

#include "esp_log.h"


+ 2
- 2
main/modes/reader/PageSettingsProvider.cpp View File

@@ -1,6 +1,6 @@
#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()
{


Loading…
Cancel
Save