Use Bundle consistently (#70)

This commit is contained in:
Ken Van Hoeylandt 2024-11-04 21:19:24 +01:00 committed by GitHub
parent c11d63ef2d
commit 68aa34ad14
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 34 additions and 14 deletions

20
sdkconfig.md Normal file
View File

@ -0,0 +1,20 @@
# Get Started
Copy the relevant `sdkconfig.board.*` file into `sdkconfig`.
This will apply the relevant settings to build the project for your hardware.
# Useful Parameters
## Enable FPS
```
CONFIG_LV_USE_OBSERVER=y
CONFIG_LV_USE_PERF_MONITOR=y
```
## Halt on error
```
CONFIG_ESP_SYSTEM_PANIC_PRINT_HALT=y
# CONFIG_ESP_SYSTEM_PANIC_PRINT_REBOOT is not set
```

View File

@ -5,9 +5,9 @@
#include <string.h> #include <string.h>
#include <tactility_core.h> #include <tactility_core.h>
static Bundle* preferences_bundle; static Bundle preferences_bundle;
static Bundle* get_preferences_bundle() { static Bundle get_preferences_bundle() {
if (preferences_bundle == NULL) { if (preferences_bundle == NULL) {
preferences_bundle = tt_bundle_alloc(); preferences_bundle = tt_bundle_alloc();
} }

View File

@ -13,7 +13,7 @@ static const AppFlags DEFAULT_FLAGS = {
// region Alloc/free // region Alloc/free
App tt_app_alloc(const AppManifest* manifest, Bundle* _Nullable parameters) { App tt_app_alloc(const AppManifest* manifest, Bundle _Nullable parameters) {
#ifdef ESP_PLATFORM #ifdef ESP_PLATFORM
size_t memory_before = heap_caps_get_free_size(MALLOC_CAP_INTERNAL); size_t memory_before = heap_caps_get_free_size(MALLOC_CAP_INTERNAL);
#else #else
@ -132,10 +132,10 @@ void tt_app_set_data(App app, void* value) {
* Consider creating MutableBundle vs Bundle. * Consider creating MutableBundle vs Bundle.
* Consider not exposing bundle, but expose `app_get_bundle_int(key)` methods with locking in it. * Consider not exposing bundle, but expose `app_get_bundle_int(key)` methods with locking in it.
*/ */
Bundle* _Nullable tt_app_get_parameters(App app) { Bundle _Nullable tt_app_get_parameters(App app) {
AppData* data = (AppData*)app; AppData* data = (AppData*)app;
tt_app_lock(data); tt_app_lock(data);
Bundle* bundle = data->parameters; Bundle bundle = data->parameters;
tt_app_unlock(data); tt_app_unlock(data);
return bundle; return bundle;
} }

View File

@ -29,7 +29,7 @@ typedef void* App;
* @param parameters optional bundle. memory ownership is transferred to App * @param parameters optional bundle. memory ownership is transferred to App
* @return * @return
*/ */
App tt_app_alloc(const AppManifest* manifest, Bundle* _Nullable parameters); App tt_app_alloc(const AppManifest* manifest, Bundle _Nullable parameters);
void tt_app_free(App app); void tt_app_free(App app);
void tt_app_set_state(App app, AppState state); void tt_app_set_state(App app, AppState state);
@ -43,7 +43,7 @@ void tt_app_set_flags(App app, AppFlags flags);
void* _Nullable tt_app_get_data(App app); void* _Nullable tt_app_get_data(App app);
void tt_app_set_data(App app, void* data); void tt_app_set_data(App app, void* data);
Bundle* _Nullable tt_app_get_parameters(App app); Bundle _Nullable tt_app_get_parameters(App app);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -21,7 +21,7 @@ typedef struct {
* When these are stored in the app struct, the struct takes ownership. * When these are stored in the app struct, the struct takes ownership.
* Do not mutate after app creation. * Do not mutate after app creation.
*/ */
Bundle* _Nullable parameters; Bundle _Nullable parameters;
/** @brief @brief Contextual data related to the running app's instance /** @brief @brief Contextual data related to the running app's instance
* The app can attach its data to this. * The app can attach its data to this.
* The lifecycle is determined by the on_start and on_stop methods in the AppManifest. * The lifecycle is determined by the on_start and on_stop methods in the AppManifest.

View File

@ -98,7 +98,7 @@ void wifi_connect_view_create(App app, void* wifi, lv_obj_t* parent) {
gui_keyboard_add_textarea(view->password_textarea); gui_keyboard_add_textarea(view->password_textarea);
// Init from app parameters // Init from app parameters
Bundle* _Nullable bundle = tt_app_get_parameters(app); Bundle _Nullable bundle = tt_app_get_parameters(app);
if (bundle) { if (bundle) {
char* ssid; char* ssid;
if (tt_bundle_opt_string(bundle, WIFI_CONNECT_PARAM_SSID, &ssid)) { if (tt_bundle_opt_string(bundle, WIFI_CONNECT_PARAM_SSID, &ssid)) {

View File

@ -66,7 +66,7 @@ void loader_unlock() {
tt_check(tt_mutex_release(loader_singleton->mutex) == TtStatusOk); tt_check(tt_mutex_release(loader_singleton->mutex) == TtStatusOk);
} }
LoaderStatus loader_start_app(const char* id, bool blocking, Bundle* _Nullable bundle) { LoaderStatus loader_start_app(const char* id, bool blocking, Bundle _Nullable bundle) {
tt_check(loader_singleton); tt_check(loader_singleton);
LoaderMessageLoaderStatusResult result = { LoaderMessageLoaderStatusResult result = {
.value = LoaderStatusOk .value = LoaderStatusOk
@ -184,7 +184,7 @@ static void app_transition_to_state(App app, AppState state) {
LoaderStatus loader_do_start_app_with_manifest( LoaderStatus loader_do_start_app_with_manifest(
const AppManifest* manifest, const AppManifest* manifest,
Bundle* _Nullable bundle Bundle _Nullable bundle
) { ) {
TT_LOG_I(TAG, "start with manifest %s", manifest->id); TT_LOG_I(TAG, "start with manifest %s", manifest->id);
@ -230,7 +230,7 @@ LoaderStatus loader_do_start_app_with_manifest(
static LoaderStatus loader_do_start_by_id( static LoaderStatus loader_do_start_by_id(
const char* id, const char* id,
Bundle* _Nullable bundle Bundle _Nullable bundle
) { ) {
TT_LOG_I(TAG, "Start by id %s", id); TT_LOG_I(TAG, "Start by id %s", id);

View File

@ -59,7 +59,7 @@ typedef struct {
* @param[in] bundle optional bundle. Ownership is transferred to Loader. * @param[in] bundle optional bundle. Ownership is transferred to Loader.
* @return LoaderStatus * @return LoaderStatus
*/ */
LoaderStatus loader_start_app(const char* id, bool blocking, Bundle* _Nullable bundle); LoaderStatus loader_start_app(const char* id, bool blocking, Bundle _Nullable bundle);
/** /**
* @brief Stop the currently showing app. Show the previous app if any app was still running. * @brief Stop the currently showing app. Show the previous app if any app was still running.

View File

@ -36,7 +36,7 @@ typedef enum {
typedef struct { typedef struct {
const char* id; const char* id;
Bundle* _Nullable bundle; Bundle _Nullable bundle;
} LoaderMessageAppStart; } LoaderMessageAppStart;
typedef struct { typedef struct {