Support for building and running external apps (#112)

This commit is contained in:
Ken Van Hoeylandt
2024-12-08 16:46:19 +01:00
committed by GitHub
parent 42e843b463
commit 415442e410
74 changed files with 2901 additions and 126 deletions
+40
View File
@@ -0,0 +1,40 @@
cmake_minimum_required(VERSION 3.16)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if (DEFINED ENV{ESP_IDF_VERSION})
file(GLOB_RECURSE SOURCE_FILES Source/*.c*)
idf_component_register(
SRCS ${SOURCE_FILES}
INCLUDE_DIRS "Source/"
REQUIRES Tactility TactilityCore TactilityHeadless lvgl elf_loader
)
add_definitions(-DESP_PLATFORM)
else()
file(GLOB_RECURSE SOURCES "Source/*.c**")
file(GLOB_RECURSE HEADERS "Source/*.h**")
add_library(TactilityC OBJECT)
target_sources(TactilityC
PRIVATE ${SOURCES}
PUBLIC ${HEADERS}
)
target_include_directories(TactilityC
PUBLIC Source/
)
add_definitions(-D_Nullable=)
add_definitions(-D_Nonnull=)
target_link_libraries(TactilityC
PRIVATE Tactility
PRIVATE TactilityCore
PRIVATE TactilityHeadless
PRIVATE lvgl
)
endif()
@@ -0,0 +1,50 @@
#ifdef ESP_PLATFORM
#include "elf_symbol.h"
#include "app/App.h"
#include "app/SelectionDialog.h"
#include "lvgl/Toolbar.h"
#include "lvgl.h"
extern "C" {
const struct esp_elfsym elf_symbols[] {
// Tactility
ESP_ELFSYM_EXPORT(tt_app_selectiondialog_start),
ESP_ELFSYM_EXPORT(tt_set_app_manifest),
ESP_ELFSYM_EXPORT(tt_lvgl_toolbar_create),
ESP_ELFSYM_EXPORT(tt_lvgl_toolbar_create_simple),
// lv_obj
ESP_ELFSYM_EXPORT(lv_obj_add_event_cb),
ESP_ELFSYM_EXPORT(lv_obj_align),
ESP_ELFSYM_EXPORT(lv_obj_align_to),
ESP_ELFSYM_EXPORT(lv_obj_get_user_data),
ESP_ELFSYM_EXPORT(lv_obj_set_user_data),
ESP_ELFSYM_EXPORT(lv_obj_set_style_margin_all),
ESP_ELFSYM_EXPORT(lv_obj_set_style_pad_all),
ESP_ELFSYM_EXPORT(lv_obj_set_style_border_width),
ESP_ELFSYM_EXPORT(lv_obj_set_style_border_color),
// lv_button
ESP_ELFSYM_EXPORT(lv_button_create),
// lv_label
ESP_ELFSYM_EXPORT(lv_label_create),
ESP_ELFSYM_EXPORT(lv_label_set_text),
ESP_ELFSYM_EXPORT(lv_label_set_text_fmt),
ESP_ELFSYM_END
};
void tt_init_tactility_c() {
elf_set_custom_symbols(elf_symbols);
}
#else // PC
void tt_init_tactility_c() {
}
#endif // ESP_PLATFORM
}
+11
View File
@@ -0,0 +1,11 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
void tt_init_tactility_c();
#ifdef __cplusplus
}
#endif
+102
View File
@@ -0,0 +1,102 @@
#include "App.h"
#include "Log.h"
#include "app/ElfApp.h"
#define TAG "tactilityc_app"
AppOnStart elfOnStart = nullptr;
AppOnStop elfOnStop = nullptr;
AppOnShow elfOnShow = nullptr;
AppOnHide elfOnHide = nullptr;
AppOnResult elfOnResult = nullptr;
static void onStartWrapper(tt::app::AppContext& context) {
if (elfOnStart != nullptr) {
TT_LOG_I(TAG, "onStartWrapper");
elfOnStart(&context);
} else {
TT_LOG_W(TAG, "onStartWrapper not set");
}
}
static void onStopWrapper(tt::app::AppContext& context) {
if (elfOnStop != nullptr) {
TT_LOG_I(TAG, "onStopWrapper");
elfOnStop(&context);
} else {
TT_LOG_W(TAG, "onStopWrapper not set");
}
}
static void onShowWrapper(tt::app::AppContext& context, lv_obj_t* parent) {
if (elfOnShow != nullptr) {
TT_LOG_I(TAG, "onShowWrapper");
elfOnShow(&context, parent);
} else {
TT_LOG_W(TAG, "onShowWrapper not set");
}
}
static void onHideWrapper(tt::app::AppContext& context) {
if (elfOnHide != nullptr) {
TT_LOG_I(TAG, "onHideWrapper");
elfOnHide(&context);
} else {
TT_LOG_W(TAG, "onHideWrapper not set");
}
}
static void onResultWrapper(tt::app::AppContext& context, tt::app::Result result, const tt::Bundle& resultData) {
if (elfOnResult != nullptr) {
TT_LOG_I(TAG, "onResultWrapper");
// Result convertedResult = AppResultError;
// switch (result) {
// case tt::app::ResultOk:
// convertedResult = AppResultOk;
// break;
// case tt::app::ResultCancelled:
// convertedResult = AppResultCancelled;
// break;
// case tt::app::ResultError:
// convertedResult = AppResultError;
// break;
// }
// elfOnResult(&context, convertedResult, (BundleHandle)&resultData);
} else {
TT_LOG_W(TAG, "onResultWrapper not set");
}
}
tt::app::AppManifest manifest = {
.id = "ElfWrapperInTactilityC",
.name = "",
.icon = "",
.onStart = onStartWrapper,
.onStop = onStopWrapper,
.onShow = onShowWrapper,
.onHide = onHideWrapper,
.onResult = onResultWrapper
};
extern "C" {
void tt_set_app_manifest(
const char* name,
const char* _Nullable icon,
AppOnStart onStart,
AppOnStop _Nullable onStop,
AppOnShow _Nullable onShow,
AppOnHide _Nullable onHide,
AppOnResult _Nullable onResult
) {
manifest.name = name;
manifest.icon = icon ? icon : "";
elfOnStart = onStart;
elfOnStop = onStop;
elfOnShow = onShow;
elfOnHide = onHide;
elfOnResult = onResult;
tt::app::setElfAppManifest(manifest);
}
}
+36
View File
@@ -0,0 +1,36 @@
#pragma once
#include "lvgl.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef void* AppContextHandle;
typedef void* BundleHandle;
typedef enum {
AppResultOk,
AppResultCancelled,
AppResultError
} Result;
typedef void (*AppOnStart)(AppContextHandle app);
typedef void (*AppOnStop)(AppContextHandle app);
typedef void (*AppOnShow)(AppContextHandle app, lv_obj_t* parent);
typedef void (*AppOnHide)(AppContextHandle app);
typedef void (*AppOnResult)(AppContextHandle app, Result result, BundleHandle resultData);
void tt_set_app_manifest(
const char* name,
const char* _Nullable icon,
AppOnStart onStart,
AppOnStop _Nullable onStop,
AppOnShow _Nullable onShow,
AppOnHide _Nullable onHide,
AppOnResult _Nullable onResult
);
#ifdef __cplusplus
}
#endif
@@ -0,0 +1,14 @@
#include "app/selectiondialog/SelectionDialog.h"
extern "C" {
void tt_app_selectiondialog_start(const char* title, int argc, const char* argv[]) {
std::vector<std::string> list;
for (int i = 0; i < argc; i++) {
const char* item = argv[i];
list.push_back(item);
}
tt::app::selectiondialog::start(title, list);
}
}
@@ -0,0 +1,11 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
void tt_app_selectiondialog_start(const char* title, int argc, const char* argv[]);
#ifdef __cplusplus
}
#endif
@@ -0,0 +1,14 @@
#include "Toolbar.h"
#include "lvgl/Toolbar.h"
extern "C" {
lv_obj_t* tt_lvgl_toolbar_create(lv_obj_t* parent, AppContextHandle context) {
return tt::lvgl::toolbar_create(parent, *(tt::app::AppContext*)context);
}
lv_obj_t* tt_lvgl_toolbar_create_simple(lv_obj_t* parent, const char* title) {
return tt::lvgl::toolbar_create(parent, title);
}
}
@@ -0,0 +1,15 @@
#pragma once
#include "lvgl.h"
#include "TactilityC/app/App.h"
#ifdef __cplusplus
extern "C" {
#endif
lv_obj_t* tt_lvgl_toolbar_create(lv_obj_t* parent, AppContextHandle context);
lv_obj_t* tt_lvgl_toolbar_create_simple(lv_obj_t* parent, const char* title);
#ifdef __cplusplus
}
#endif