Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ include(FetchContent)
include(Portduino)
include(LovyanGFX)
include(LVGL)
include(libdeflate)
include(protobuf)
include(nanopb)
include(Doctest)
Expand All @@ -46,7 +47,7 @@ file(GLOB_RECURSE sources source/* generated/* portduino/* locale/* generat
file(GLOB_RECURSE sources_test tests/*.cpp)

add_library(DeviceUI ${sources})
target_link_libraries(DeviceUI PRIVATE lvgl::lvgl LovyanGFX Portduino Protobufs)
target_link_libraries(DeviceUI PRIVATE lvgl::lvgl libdeflate LovyanGFX Portduino Protobufs)
target_compile_options(DeviceUI PUBLIC -Wall -Wno-format -Wfloat-conversion)

target_include_directories(DeviceUI PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
Expand Down
3 changes: 2 additions & 1 deletion cmake/LVGL.cmake
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
message(STATUS "Fetching LVGL ...")
set(LV_CONF_BUILD_DISABLE_DEMOS 1)
set(LV_CONF_BUILD_DISABLE_EXAMPLES 1)
set(LV_BUILD_CONF_DIR "include")
add_compile_definitions(LV_LVGL_H_INCLUDE_SIMPLE)
add_compile_definitions(LV_CONF_INCLUDE_SIMPLE)
add_compile_definitions(LV_COMP_CONF_INCLUDE_SIMPLE)
add_compile_definitions(LV_BUILD_TEST=0)
add_compile_definitions(LV_USE_LIBINPUT=1)
add_compile_definitions(LV_LIBINPUT_XKB=1)
FetchContent_Declare(lvgl
Expand Down
23 changes: 23 additions & 0 deletions cmake/libdeflate.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
message(STATUS "Fetching libdeflate ...")
set(LIBDEFLATE_BUILD_STATIC_LIB "Build the static library" 1)
set(LIBDEFLATE_BUILD_SHARED_LIB "Build the shared library" 0)
set(LIBDEFLATE_COMPRESSION_SUPPORT "Support compression" 0)
set(LIBDEFLATE_DECOMPRESSION_SUPPORT "Support decompression" 1)
set(LIBDEFLATE_ZLIB_SUPPORT "Support the zlib format" 0)
set(LIBDEFLATE_GZIP_SUPPORT "Support the gzip format" 1)
set(LIBDEFLATE_FREESTANDING "Build a freestanding library" 0)
set(LIBDEFLATE_BUILD_GZIP "Build the libdeflate-gzip program" 0)
set(LIBDEFLATE_BUILD_TESTS "Build the test programs" 0)

FetchContent_Declare(
libdeflate
GIT_REPOSITORY "https://github.com/mverch67/libdeflate.git"
GIT_TAG "ce93eca5c1260da59c347bfebfd271343d55be38"
)
FetchContent_MakeAvailable(libdeflate)
include_directories(${libdeflate_SOURCE_DIR}/lib)

file(GLOB_RECURSE libdeflate_SOURCES ${libdeflate_SOURCE_DIR}/lib/*.c)
add_library(libdeflate STATIC ${libdeflate_SOURCES})
target_include_directories(libdeflate PUBLIC ${libdeflate_SOURCE_DIR})
target_include_directories(libdeflate PUBLIC ${libdeflate_SOURCE_DIR}/lib)
2 changes: 1 addition & 1 deletion include/graphics/map/FileSystemService.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class FileSystemService : public ITileService

virtual ~FileSystemService();

bool load(const char *name, void *img) override;
bool load(uint32_t x, uint32_t y, uint32_t z, void *img) override;

protected:
static void *fs_open(lv_fs_drv_t *drv, const char *path, lv_fs_mode_t mode);
Expand Down
2 changes: 1 addition & 1 deletion include/graphics/map/LinuxFileSystemService.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class LinuxFileSystemService : public ITileService

virtual ~LinuxFileSystemService();

bool load(const char *name, void *img) override;
bool load(uint32_t x, uint32_t y, uint32_t z, void *img) override;

protected:
static void *fs_open(lv_fs_drv_t *drv, const char *path, lv_fs_mode_t mode);
Expand Down
8 changes: 1 addition & 7 deletions include/graphics/map/MapTileSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,7 @@ class MapTileSettings
static void setPrefix(const char *p) { strcpy(prefix, p); }

static const char *getTileStyle(void) { return tileStyle; }
static void setTileStyle(const char *p)
{
strcpy(tileStyle, p);
size_t len = strlen(tileStyle);
if (len > 0 && tileStyle[len - 1] != '/')
strcat(tileStyle, "/");
}
static void setTileStyle(const char *p) { strcpy(tileStyle, p); }

static const char *getTileFormat(void) { return tileFormat; }
static void setTileFormat(const char *p) { strcpy(tileFormat, p); }
Expand Down
33 changes: 9 additions & 24 deletions include/graphics/map/OSMTiles.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
#pragma once

Check failure on line 1 in include/graphics/map/OSMTiles.h

View workflow job for this annotation

GitHub Actions / Trunk Check

clang-format

Incorrect formatting, autoformat by running 'trunk fmt'

#include "graphics/map/GeoPoint.h"
#include "graphics/map/MapTileSettings.h"
#include <cstdio>
#include <cstring>
#include <functional>
#include <stdint.h>

#ifndef IMG_PATH_LEN
#define IMG_PATH_LEN 64
#endif

/**
* Generic OSM raster tile loader (singleton class).
* Of course can also load other raster styles than just osm, lol.
Expand All @@ -19,43 +13,34 @@
{
public:
struct Tile : public GeoPoint {
Tile(float lat, float lon, uint8_t zoom) : GeoPoint(lat, lon, zoom) { filename[0] = '\0'; }
Tile(uint32_t xTile, uint32_t yTile, uint8_t zoom) : GeoPoint(xTile, yTile, zoom) { filename[0] = '\0'; }
char filename[IMG_PATH_LEN];
Tile(float lat, float lon, uint8_t zoom) : GeoPoint(lat, lon, zoom) { }
Tile(uint32_t xTile, uint32_t yTile, uint8_t zoom) : GeoPoint(xTile, yTile, zoom) { }
};

// create instance of this class and provide cb function for loading images
static OSMTiles *create(std::function<bool(const char *, IMG *)> cb);
static OSMTiles *create(std::function<bool(uint32_t x, uint32_t y, uint32_t z, IMG *)> cb);

// filename caching for GeoPoint tile
// load tile via callback provider
bool load(OSMTiles::Tile &tile, IMG *img)
{
if (!tile.filename[0]) {
std::snprintf(tile.filename, IMG_PATH_LEN, "%s/%s%d/%d/%d.%s", MapTileSettings::getPrefix(),
MapTileSettings::getTileStyle(), tile.zoomLevel, tile.xTile, tile.yTile,
MapTileSettings::getTileFormat());
}
return loadcb(tile.filename, img);
return loadcb(tile.xTile, tile.yTile, tile.zoomLevel, img);
}

protected:
bool load(const GeoPoint &tile, IMG *img)
{
char name[IMG_PATH_LEN];
std::snprintf(name, IMG_PATH_LEN, "%s/%s%d/%d/%d.%s", MapTileSettings::getPrefix(), MapTileSettings::getTileStyle(),
tile.zoomLevel, tile.xTile, tile.yTile, MapTileSettings::getTileFormat());
return loadcb(name, img);
return loadcb(tile.xTile, tile.yTile, tile.zoomLevel, img);
}

private:
OSMTiles() = default;
static std::function<bool(const char *, IMG *)> loadcb;
static std::function<bool(uint32_t x, uint32_t y, uint32_t z, IMG *)> loadcb;
};

template <class IMG> OSMTiles<IMG> *OSMTiles<IMG>::create(std::function<bool(const char *, IMG *)> cb)
template <class IMG> OSMTiles<IMG> *OSMTiles<IMG>::create(std::function<bool(uint32_t x, uint32_t y, uint32_t z, IMG *)> cb)
{
loadcb = cb;
return new OSMTiles;
}

template <class IMG> std::function<bool(const char *, IMG *)> OSMTiles<IMG>::loadcb;
template <class IMG> std::function<bool(uint32_t x, uint32_t y, uint32_t z, IMG *)> OSMTiles<IMG>::loadcb = nullptr;
37 changes: 37 additions & 0 deletions include/graphics/map/PMTileService.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#pragma once

Check failure on line 1 in include/graphics/map/PMTileService.h

View workflow job for this annotation

GitHub Actions / Trunk Check

clang-format

Incorrect formatting, autoformat by running 'trunk fmt'

#include "graphics/map/TileService.h"
#include "graphics/map/pmtiles.hpp"
#include "graphics/common/SdCard.h"
#include "lvgl.h"
#include <vector>
#include <string>

#if defined(ARCH_PORTDUINO)
#include "PortduinoFS.h"
extern fs::FS &SDFs;
typedef fs::File FsFile;
#endif

class PMTileService : public ITileService
{
public:
PMTileService();

virtual ~PMTileService();

bool load(uint32_t x, uint32_t y, uint32_t z, void *img) override;

protected:
std::string decompress(const std::string &data, uint8_t compression);
bool decodeImg(const void *data, size_t size, lv_img_dsc_t* &img);
void convertRGB888ToRGB565(uint8_t *src, uint16_t *dst, int width, int height);

private:
// pmtiles directory cache
uint64_t cachedDirOffset[3] = { 0, 0, 0 };
std::vector<pmtiles::entryv3> cachedDirEntries[3];
// pmtiles file and header
FsFile pmTiles;
pmtiles::headerv3 pmHeader;
};
2 changes: 1 addition & 1 deletion include/graphics/map/SDCardService.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class SDCardService : public ITileService

virtual ~SDCardService();

bool load(const char *name, void *img) override;
bool load(uint32_t x, uint32_t y, uint32_t z, void *img) override;

protected:
static void *fs_open(lv_fs_drv_t *drv, const char *path, lv_fs_mode_t mode);
Expand Down
4 changes: 1 addition & 3 deletions include/graphics/map/SdFatService.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
#include "SdFat.h"
#include "graphics/map/TileService.h"
#include "lvgl.h"
#include <memory>
#include <unordered_map>

class SdFatService : public ITileService
{
Expand All @@ -13,7 +11,7 @@ class SdFatService : public ITileService

virtual ~SdFatService();

bool load(const char *name, void *img) override;
bool load(uint32_t x, uint32_t y, uint32_t z, void *img) override;

protected:
static void *fs_open(lv_fs_drv_t *drv, const char *path, lv_fs_mode_t mode);
Expand Down
7 changes: 3 additions & 4 deletions include/graphics/map/TileService.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
class ITileService
{
public:
// lvgl lv_fs_drv callbacks
virtual bool load(const char *name, void *img) = 0;
virtual bool load(uint32_t x, uint32_t y, uint32_t z, void *img) = 0;
virtual ~ITileService() {}

protected:
Expand All @@ -29,9 +28,9 @@ class TileService : public ITileService
virtual void setService(ITileService *s);
virtual void setBackupService(ITileService *s);

bool load(const char *name, void *img) override
bool load(uint32_t x, uint32_t y, uint32_t z, void *img) override
{
return service ? service->load(name, img) : backup ? backup->load(name, img) : false;
return service ? service->load(x, y, z, img) : backup ? backup->load(x, y, z, img) : false;
}

virtual ~TileService();
Expand Down
2 changes: 1 addition & 1 deletion include/graphics/map/URLService.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class URLService : public ITileService

virtual ~URLService();

bool load(const char *name, void *img) override;
bool load(uint32_t x, uint32_t y, uint32_t z, void *img) override;

protected:
static void *fs_open(lv_fs_drv_t *drv, const char *path, lv_fs_mode_t mode);
Expand Down
Loading
Loading