mirror of
https://github.com/ByteWelder/Tactility.git
synced 2026-02-18 10:53:17 +00:00
TactilityC improvements for tt_app_ functions (#192)
- Renamed `tt_app_context_*` to tt_app_*` - Renamed `AppContextHandle` to `AppHandle` - Created `tt_app_start()` and `tt_app_start_with_bundle()`
This commit is contained in:
parent
f9e1f737fd
commit
fa54eaa58a
@ -5,8 +5,8 @@
|
||||
* Note: LVGL and Tactility methods need to be exposed manually from TactilityC/Source/tt_init.cpp
|
||||
* Only C is supported for now (C++ symbols fail to link)
|
||||
*/
|
||||
static void onShow(AppContextHandle context, void* data, lv_obj_t* parent) {
|
||||
lv_obj_t* toolbar = tt_lvgl_toolbar_create(parent, context);
|
||||
static void onShow(AppHandle app, void* data, lv_obj_t* parent) {
|
||||
lv_obj_t* toolbar = tt_lvgl_toolbar_create(parent, app);
|
||||
lv_obj_align(toolbar, LV_ALIGN_TOP_MID, 0, 0);
|
||||
|
||||
lv_obj_t* label = lv_label_create(parent);
|
||||
|
||||
@ -1,26 +1,30 @@
|
||||
#include "tt_app_context.h"
|
||||
#include "tt_app.h"
|
||||
#include <app/App.h>
|
||||
#include <app/AppContext.h>
|
||||
|
||||
struct AppContextDataWrapper {
|
||||
void* _Nullable data;
|
||||
};
|
||||
|
||||
extern "C" {
|
||||
|
||||
#define HANDLE_AS_APP_CONTEXT(handle) ((tt::app::AppContext*)(handle))
|
||||
|
||||
BundleHandle _Nullable tt_app_context_get_parameters(AppContextHandle handle) {
|
||||
BundleHandle _Nullable tt_app_get_parameters(AppHandle handle) {
|
||||
return (BundleHandle)HANDLE_AS_APP_CONTEXT(handle)->getParameters().get();
|
||||
}
|
||||
|
||||
void tt_app_context_set_result(AppContextHandle handle, Result result, BundleHandle _Nullable bundle) {
|
||||
void tt_app_set_result(AppHandle handle, Result result, BundleHandle _Nullable bundle) {
|
||||
auto shared_bundle = std::unique_ptr<tt::Bundle>((tt::Bundle*)bundle);
|
||||
HANDLE_AS_APP_CONTEXT(handle)->getApp()->setResult((tt::app::Result)result, std::move(shared_bundle));
|
||||
}
|
||||
|
||||
bool tt_app_context_has_result(AppContextHandle handle) {
|
||||
bool tt_app_has_result(AppHandle handle) {
|
||||
return HANDLE_AS_APP_CONTEXT(handle)->getApp()->hasResult();
|
||||
}
|
||||
|
||||
void tt_app_start(const char* appId) {
|
||||
tt::app::start(appId);
|
||||
}
|
||||
|
||||
void tt_app_start_with_bundle(const char* appId, BundleHandle parameters) {
|
||||
tt::app::start(appId, std::shared_ptr<tt::Bundle>((tt::Bundle*)parameters));
|
||||
}
|
||||
|
||||
}
|
||||
41
TactilityC/Source/tt_app.h
Normal file
41
TactilityC/Source/tt_app.h
Normal file
@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
|
||||
#include "tt_app_manifest.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef void* AppHandle;
|
||||
|
||||
/** @return the bundle that belongs to this application, or null if it wasn't started with parameters. */
|
||||
BundleHandle _Nullable tt_app_get_parameters(AppHandle handle);
|
||||
|
||||
/**
|
||||
* Set the result before closing an app.
|
||||
* The result and bundle are passed along to the app that launched this app, when this app is closed.
|
||||
* @param[in] handle the app context handle to set the result for
|
||||
* @param[in] result the result state to set
|
||||
* @param[in] bundle the result bundle to set
|
||||
*/
|
||||
void tt_app_set_result(AppHandle handle, Result result, BundleHandle _Nullable bundle);
|
||||
|
||||
/** @return true if a result was set for this app context */
|
||||
bool tt_app_has_result(AppHandle handle);
|
||||
|
||||
/**
|
||||
* Start an app by id.
|
||||
* @param[in] appId the app manifest id
|
||||
*/
|
||||
void tt_app_start(const char* appId);
|
||||
|
||||
/**
|
||||
* Start an app by id and bundle.
|
||||
* @param[in] appId the app manifest id
|
||||
* @param[in] parameters the parameters to pass onto the starting app
|
||||
*/
|
||||
void tt_app_start_with_bundle(const char* appId, BundleHandle parameters);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@ -1,31 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "tt_app_manifest.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef void* AppContextHandle;
|
||||
|
||||
/** @return the data that was attached to this app context */
|
||||
void* _Nullable tt_app_context_get_data(AppContextHandle handle);
|
||||
|
||||
/** @return the bundle that belongs to this application, or null */
|
||||
BundleHandle _Nullable tt_app_context_get_parameters(AppContextHandle handle);
|
||||
|
||||
/**
|
||||
* Set the result before closing an app.
|
||||
* The result and bundle are passed along to the app that launched this app, when this app is closed.
|
||||
* @param[in] handle the app context handle to set the result for
|
||||
* @param[in] result the result state to set
|
||||
* @param[in] bundle the result bundle to set
|
||||
*/
|
||||
void tt_app_context_set_result(AppContextHandle handle, Result result, BundleHandle _Nullable bundle);
|
||||
|
||||
/** @return true if a result was set for this app context */
|
||||
bool tt_app_context_has_result(AppContextHandle handle);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@ -14,16 +14,16 @@ typedef enum {
|
||||
AppResultError = 2
|
||||
} Result;
|
||||
|
||||
typedef void* AppContextHandle;
|
||||
typedef void* AppHandle;
|
||||
|
||||
/** Important: These function types must map to t::app types exactly */
|
||||
typedef void* (*AppCreateData)();
|
||||
typedef void (*AppDestroyData)(void* data);
|
||||
typedef void (*AppOnStart)(AppContextHandle app, void* _Nullable data);
|
||||
typedef void (*AppOnStop)(AppContextHandle app, void* _Nullable data);
|
||||
typedef void (*AppOnShow)(AppContextHandle app, void* _Nullable data, lv_obj_t* parent);
|
||||
typedef void (*AppOnHide)(AppContextHandle app, void* _Nullable data);
|
||||
typedef void (*AppOnResult)(AppContextHandle app, void* _Nullable data, Result result, BundleHandle resultData);
|
||||
typedef void (*AppOnStart)(AppHandle app, void* _Nullable data);
|
||||
typedef void (*AppOnStop)(AppHandle app, void* _Nullable data);
|
||||
typedef void (*AppOnShow)(AppHandle app, void* _Nullable data, lv_obj_t* parent);
|
||||
typedef void (*AppOnHide)(AppHandle app, void* _Nullable data);
|
||||
typedef void (*AppOnResult)(AppHandle app, void* _Nullable data, Result result, BundleHandle resultData);
|
||||
|
||||
typedef struct {
|
||||
/** The application's human-readable name */
|
||||
|
||||
@ -2,9 +2,9 @@
|
||||
|
||||
#include "elf_symbol.h"
|
||||
|
||||
#include "tt_app_context.h"
|
||||
#include "tt_app_manifest.h"
|
||||
#include "tt_app.h"
|
||||
#include "tt_app_alertdialog.h"
|
||||
#include "tt_app_manifest.h"
|
||||
#include "tt_app_selectiondialog.h"
|
||||
#include "tt_bundle.h"
|
||||
#include "tt_hal_i2c.h"
|
||||
@ -23,9 +23,9 @@ extern "C" {
|
||||
const struct esp_elfsym elf_symbols[] {
|
||||
// Tactility
|
||||
ESP_ELFSYM_EXPORT(tt_app_register),
|
||||
ESP_ELFSYM_EXPORT(tt_app_context_get_parameters),
|
||||
ESP_ELFSYM_EXPORT(tt_app_context_set_result),
|
||||
ESP_ELFSYM_EXPORT(tt_app_context_has_result),
|
||||
ESP_ELFSYM_EXPORT(tt_app_get_parameters),
|
||||
ESP_ELFSYM_EXPORT(tt_app_set_result),
|
||||
ESP_ELFSYM_EXPORT(tt_app_has_result),
|
||||
ESP_ELFSYM_EXPORT(tt_app_selectiondialog_start),
|
||||
ESP_ELFSYM_EXPORT(tt_app_selectiondialog_get_result_index),
|
||||
ESP_ELFSYM_EXPORT(tt_app_alertdialog_start),
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
|
||||
extern "C" {
|
||||
|
||||
lv_obj_t* tt_lvgl_toolbar_create(lv_obj_t* parent, AppContextHandle context) {
|
||||
lv_obj_t* tt_lvgl_toolbar_create(lv_obj_t* parent, AppHandle context) {
|
||||
return tt::lvgl::toolbar_create(parent, *(tt::app::AppContext*)context);
|
||||
}
|
||||
|
||||
|
||||
@ -1,14 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "tt_app.h"
|
||||
#include <lvgl.h>
|
||||
#include "tt_app_context.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** Create a toolbar widget that shows the app name as title */
|
||||
lv_obj_t* tt_lvgl_toolbar_create(lv_obj_t* parent, AppContextHandle context);
|
||||
lv_obj_t* tt_lvgl_toolbar_create(lv_obj_t* parent, AppHandle context);
|
||||
|
||||
/** Create a toolbar widget with the provided title*/
|
||||
lv_obj_t* tt_lvgl_toolbar_create_simple(lv_obj_t* parent, const char* title);
|
||||
|
||||
@ -13,7 +13,7 @@ void tt_service_loader_stop_app() {
|
||||
tt::service::loader::stopApp();
|
||||
}
|
||||
|
||||
AppContextHandle tt_service_loader_get_current_app() {
|
||||
AppHandle tt_service_loader_get_current_app() {
|
||||
return tt::service::loader::getCurrentAppContext().get();
|
||||
}
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "tt_app.h"
|
||||
#include "tt_bundle.h"
|
||||
#include "tt_app_context.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -26,7 +26,7 @@ void tt_service_loader_stop_app();
|
||||
/**
|
||||
* Get the context handle of the app that is currently shown on the screen.
|
||||
*/
|
||||
AppContextHandle tt_service_loader_get_current_app();
|
||||
AppHandle tt_service_loader_get_current_app();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user