refactor app code (#93)
This commit is contained in:
committed by
GitHub
parent
a312bd5527
commit
d7b151ab88
@@ -1,102 +0,0 @@
|
||||
#include "app/App.h"
|
||||
|
||||
namespace tt::app {
|
||||
|
||||
#define TAG "app"
|
||||
|
||||
void AppInstance::setState(State newState) {
|
||||
mutex.acquire(TtWaitForever);
|
||||
state = newState;
|
||||
mutex.release();
|
||||
}
|
||||
|
||||
State AppInstance::getState() {
|
||||
mutex.acquire(TtWaitForever);
|
||||
auto result = state;
|
||||
mutex.release();
|
||||
return result;
|
||||
}
|
||||
|
||||
/** TODO: Make this thread-safe.
|
||||
* In practice, the bundle is writeable, so someone could be writing to it
|
||||
* while it is being accessed from another thread.
|
||||
* Consider creating MutableBundle vs Bundle.
|
||||
* Consider not exposing bundle, but expose `app_get_bundle_int(key)` methods with locking in it.
|
||||
*/
|
||||
const Manifest& AppInstance::getManifest() {
|
||||
return manifest;
|
||||
}
|
||||
|
||||
Flags AppInstance::getFlags() {
|
||||
mutex.acquire(TtWaitForever);
|
||||
auto result = flags;
|
||||
mutex.release();
|
||||
return result;
|
||||
}
|
||||
|
||||
void AppInstance::setFlags(Flags newFlags) {
|
||||
mutex.acquire(TtWaitForever);
|
||||
flags = newFlags;
|
||||
mutex.release();
|
||||
}
|
||||
|
||||
_Nullable void* AppInstance::getData() {
|
||||
mutex.acquire(TtWaitForever);
|
||||
auto result = data;
|
||||
mutex.release();
|
||||
return result;
|
||||
}
|
||||
|
||||
void AppInstance::setData(void* newData) {
|
||||
mutex.acquire(TtWaitForever);
|
||||
data = newData;
|
||||
mutex.release();
|
||||
}
|
||||
|
||||
const Bundle& AppInstance::getParameters() {
|
||||
return parameters;
|
||||
}
|
||||
|
||||
App tt_app_alloc(const Manifest& manifest, const Bundle& parameters) {
|
||||
auto* instance = new AppInstance(manifest, parameters);
|
||||
return static_cast<App>(instance);
|
||||
}
|
||||
|
||||
void tt_app_free(App app) {
|
||||
auto* instance = static_cast<AppInstance*>(app);
|
||||
delete instance;
|
||||
}
|
||||
|
||||
void tt_app_set_state(App app, State state) {
|
||||
static_cast<AppInstance*>(app)->setState(state);
|
||||
}
|
||||
|
||||
State tt_app_get_state(App app) {
|
||||
return static_cast<AppInstance*>(app)->getState();
|
||||
}
|
||||
|
||||
const Manifest& tt_app_get_manifest(App app) {
|
||||
return static_cast<AppInstance*>(app)->getManifest();
|
||||
}
|
||||
|
||||
Flags tt_app_get_flags(App app) {
|
||||
return static_cast<AppInstance*>(app)->getFlags();
|
||||
}
|
||||
|
||||
void tt_app_set_flags(App app, Flags flags) {
|
||||
return static_cast<AppInstance*>(app)->setFlags(flags);
|
||||
}
|
||||
|
||||
void* tt_app_get_data(App app) {
|
||||
return static_cast<AppInstance*>(app)->getData();
|
||||
}
|
||||
|
||||
void tt_app_set_data(App app, void* data) {
|
||||
return static_cast<AppInstance*>(app)->setData(data);
|
||||
}
|
||||
|
||||
const Bundle& tt_app_get_parameters(App app) {
|
||||
return static_cast<AppInstance*>(app)->getParameters();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
+13
-83
@@ -2,98 +2,28 @@
|
||||
|
||||
#include "Manifest.h"
|
||||
#include "Bundle.h"
|
||||
#include "Mutex.h"
|
||||
|
||||
namespace tt::app {
|
||||
|
||||
typedef enum {
|
||||
StateInitial, // App is being activated in loader
|
||||
StateStarted, // App is in memory
|
||||
StateShowing, // App view is created
|
||||
StateHiding, // App view is destroyed
|
||||
StateStopped // App is not in memory
|
||||
} State;
|
||||
|
||||
typedef union {
|
||||
struct {
|
||||
bool show_statusbar : 1;
|
||||
bool showStatusbar : 1;
|
||||
};
|
||||
unsigned char flags;
|
||||
} Flags;
|
||||
|
||||
|
||||
class AppInstance {
|
||||
|
||||
private:
|
||||
|
||||
Mutex mutex = Mutex(MutexTypeNormal);
|
||||
const Manifest& manifest;
|
||||
State state = StateInitial;
|
||||
Flags flags = { .show_statusbar = true };
|
||||
/** @brief Optional parameters to start the app with
|
||||
* When these are stored in the app struct, the struct takes ownership.
|
||||
* Do not mutate after app creation.
|
||||
*/
|
||||
tt::Bundle parameters;
|
||||
/** @brief @brief Contextual data related to the running app's instance
|
||||
* The app can attach its data to this.
|
||||
* The lifecycle is determined by the on_start and on_stop methods in the AppManifest.
|
||||
* These manifest methods can optionally allocate/free data that is attached here.
|
||||
*/
|
||||
void* _Nullable data = nullptr;
|
||||
|
||||
/**
|
||||
* A limited representation of the application instance.
|
||||
* Do not store references or pointers to these!
|
||||
*/
|
||||
class App {
|
||||
public:
|
||||
|
||||
AppInstance(const Manifest& manifest) :
|
||||
manifest(manifest) {}
|
||||
|
||||
AppInstance(const Manifest& manifest, const Bundle& parameters) :
|
||||
manifest(manifest),
|
||||
parameters(parameters) {}
|
||||
|
||||
void setState(State state);
|
||||
State getState();
|
||||
|
||||
const Manifest& getManifest();
|
||||
|
||||
Flags getFlags();
|
||||
void setFlags(Flags flags);
|
||||
|
||||
_Nullable void* getData();
|
||||
void setData(void* data);
|
||||
|
||||
const Bundle& getParameters();
|
||||
virtual ~App() {};
|
||||
virtual const Manifest& getManifest() const = 0;
|
||||
virtual _Nullable void* getData() const = 0;
|
||||
virtual void setData(void* data) = 0;
|
||||
virtual const Bundle& getParameters() const = 0;
|
||||
virtual Flags getFlags() const = 0;
|
||||
};
|
||||
|
||||
/** @brief Create an app
|
||||
* @param manifest
|
||||
* @param parameters optional bundle. memory ownership is transferred to App
|
||||
* @return
|
||||
*/
|
||||
[[deprecated("use class")]]
|
||||
App tt_app_alloc(const Manifest& manifest, const Bundle& parameters);
|
||||
[[deprecated("use class")]]
|
||||
void tt_app_free(App app);
|
||||
|
||||
[[deprecated("use class")]]
|
||||
void tt_app_set_state(App app, State state);
|
||||
[[deprecated("use class")]]
|
||||
State tt_app_get_state(App app);
|
||||
|
||||
[[deprecated("use class")]]
|
||||
const Manifest& tt_app_get_manifest(App app);
|
||||
|
||||
[[deprecated("use class")]]
|
||||
Flags tt_app_get_flags(App app);
|
||||
[[deprecated("use class")]]
|
||||
void tt_app_set_flags(App app, Flags flags);
|
||||
|
||||
[[deprecated("use class")]]
|
||||
void* _Nullable tt_app_get_data(App app);
|
||||
[[deprecated("use class")]]
|
||||
void tt_app_set_data(App app, void* data);
|
||||
|
||||
[[deprecated("use class")]]
|
||||
const Bundle& tt_app_get_parameters(App app);
|
||||
|
||||
} // namespace
|
||||
}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
#include "app/AppInstance.h"
|
||||
|
||||
namespace tt::app {
|
||||
|
||||
#define TAG "app"
|
||||
|
||||
void AppInstance::setState(State newState) {
|
||||
mutex.acquire(TtWaitForever);
|
||||
state = newState;
|
||||
mutex.release();
|
||||
}
|
||||
|
||||
State AppInstance::getState() const {
|
||||
mutex.acquire(TtWaitForever);
|
||||
auto result = state;
|
||||
mutex.release();
|
||||
return result;
|
||||
}
|
||||
|
||||
/** TODO: Make this thread-safe.
|
||||
* In practice, the bundle is writeable, so someone could be writing to it
|
||||
* while it is being accessed from another thread.
|
||||
* Consider creating MutableBundle vs Bundle.
|
||||
* Consider not exposing bundle, but expose `app_get_bundle_int(key)` methods with locking in it.
|
||||
*/
|
||||
const Manifest& AppInstance::getManifest() const {
|
||||
return manifest;
|
||||
}
|
||||
|
||||
Flags AppInstance::getFlags() const {
|
||||
mutex.acquire(TtWaitForever);
|
||||
auto result = flags;
|
||||
mutex.release();
|
||||
return result;
|
||||
}
|
||||
|
||||
void AppInstance::setFlags(Flags newFlags) {
|
||||
mutex.acquire(TtWaitForever);
|
||||
flags = newFlags;
|
||||
mutex.release();
|
||||
}
|
||||
|
||||
_Nullable void* AppInstance::getData() const {
|
||||
mutex.acquire(TtWaitForever);
|
||||
auto result = data;
|
||||
mutex.release();
|
||||
return result;
|
||||
}
|
||||
|
||||
void AppInstance::setData(void* newData) {
|
||||
mutex.acquire(TtWaitForever);
|
||||
data = newData;
|
||||
mutex.release();
|
||||
}
|
||||
|
||||
const Bundle& AppInstance::getParameters() const {
|
||||
return parameters;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@@ -8,7 +8,7 @@ typedef struct _lv_obj_t lv_obj_t;
|
||||
|
||||
namespace tt::app {
|
||||
|
||||
typedef void* App;
|
||||
class App;
|
||||
|
||||
typedef enum {
|
||||
/** A desktop app sits at the root of the app stack managed by the Loader service */
|
||||
@@ -23,10 +23,11 @@ typedef enum {
|
||||
TypeUser
|
||||
} Type;
|
||||
|
||||
typedef void (*AppOnStart)(App app);
|
||||
typedef void (*AppOnStop)(App app);
|
||||
typedef void (*AppOnShow)(App app, lv_obj_t* parent);
|
||||
typedef void (*AppOnHide)(App app);
|
||||
|
||||
typedef void (*AppOnStart)(App& app);
|
||||
typedef void (*AppOnStop)(App& app);
|
||||
typedef void (*AppOnShow)(App& app, lv_obj_t* parent);
|
||||
typedef void (*AppOnHide)(App& app);
|
||||
|
||||
typedef struct Manifest {
|
||||
/**
|
||||
@@ -52,26 +53,26 @@ typedef struct Manifest {
|
||||
/**
|
||||
* Non-blocking method to call when app is started.
|
||||
*/
|
||||
const AppOnStart on_start = nullptr;
|
||||
const AppOnStart onStart = nullptr;
|
||||
|
||||
/**
|
||||
* Non-blocking method to call when app is stopped.
|
||||
*/
|
||||
const AppOnStop _Nullable on_stop = nullptr;
|
||||
const AppOnStop _Nullable onStop = nullptr;
|
||||
|
||||
/**
|
||||
* Non-blocking method to create the GUI
|
||||
*/
|
||||
const AppOnShow _Nullable on_show = nullptr;
|
||||
const AppOnShow _Nullable onShow = nullptr;
|
||||
|
||||
/**
|
||||
* Non-blocking method, called before gui is destroyed
|
||||
*/
|
||||
const AppOnHide _Nullable on_hide = nullptr;
|
||||
const AppOnHide _Nullable onHide = nullptr;
|
||||
} AppManifest;
|
||||
|
||||
struct {
|
||||
bool operator()(const Manifest* a, const Manifest* b) const { return a->name < b->name; }
|
||||
bool operator()(const Manifest* left, const Manifest* right) const { return left->name < right->name; }
|
||||
} SortAppManifestByName;
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -3,52 +3,38 @@
|
||||
#include "TactilityCore.h"
|
||||
#include <unordered_map>
|
||||
|
||||
#define TAG "app_registry"
|
||||
#define TAG "app"
|
||||
|
||||
namespace tt::app {
|
||||
|
||||
typedef std::unordered_map<std::string, const Manifest*> AppManifestMap;
|
||||
|
||||
static AppManifestMap app_manifest_map;
|
||||
static Mutex* hash_mutex = nullptr;
|
||||
static Mutex hash_mutex(MutexTypeNormal);
|
||||
|
||||
static void app_registry_lock() {
|
||||
tt_assert(hash_mutex != nullptr);
|
||||
tt_mutex_acquire(hash_mutex, TtWaitForever);
|
||||
}
|
||||
void addApp(const Manifest* manifest) {
|
||||
TT_LOG_I(TAG, "Registering manifest %s", manifest->id.c_str());
|
||||
|
||||
static void app_registry_unlock() {
|
||||
tt_assert(hash_mutex != nullptr);
|
||||
tt_mutex_release(hash_mutex);
|
||||
}
|
||||
|
||||
void app_manifest_registry_init() {
|
||||
tt_assert(hash_mutex == nullptr);
|
||||
hash_mutex = tt_mutex_alloc(MutexTypeNormal);
|
||||
}
|
||||
void app_manifest_registry_add(const Manifest* manifest) {
|
||||
TT_LOG_I(TAG, "adding %s", manifest->id.c_str());
|
||||
|
||||
app_registry_lock();
|
||||
hash_mutex.acquire(TtWaitForever);
|
||||
app_manifest_map[manifest->id] = manifest;
|
||||
app_registry_unlock();
|
||||
hash_mutex.release();
|
||||
}
|
||||
|
||||
_Nullable const Manifest * app_manifest_registry_find_by_id(const std::string& id) {
|
||||
app_registry_lock();
|
||||
_Nullable const Manifest * findAppById(const std::string& id) {
|
||||
hash_mutex.acquire(TtWaitForever);
|
||||
auto iterator = app_manifest_map.find(id);
|
||||
_Nullable const Manifest* result = iterator != app_manifest_map.end() ? iterator->second : nullptr;
|
||||
app_registry_unlock();
|
||||
hash_mutex.release();
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<const Manifest*> app_manifest_registry_get() {
|
||||
std::vector<const Manifest*> getApps() {
|
||||
std::vector<const Manifest*> manifests;
|
||||
app_registry_lock();
|
||||
hash_mutex.acquire(TtWaitForever);
|
||||
for (const auto& item: app_manifest_map) {
|
||||
manifests.push_back(item.second);
|
||||
}
|
||||
app_registry_unlock();
|
||||
hash_mutex.release();
|
||||
return manifests;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,10 +6,8 @@
|
||||
|
||||
namespace tt::app {
|
||||
|
||||
void app_manifest_registry_init();
|
||||
void app_manifest_registry_add(const Manifest* manifest);
|
||||
void app_manifest_registry_remove(const Manifest* manifest);
|
||||
const Manifest _Nullable* app_manifest_registry_find_by_id(const std::string& id);
|
||||
std::vector<const Manifest*> app_manifest_registry_get();
|
||||
void addApp(const Manifest* manifest);
|
||||
const Manifest _Nullable* findAppById(const std::string& id);
|
||||
std::vector<const Manifest*> getApps();
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -23,12 +23,12 @@ static void create_app_widget(const Manifest* manifest, void* parent) {
|
||||
lv_obj_add_event_cb(btn, &on_app_pressed, LV_EVENT_CLICKED, (void*)manifest);
|
||||
}
|
||||
|
||||
static void desktop_show(TT_UNUSED App app, lv_obj_t* parent) {
|
||||
static void desktop_show(TT_UNUSED App& app, lv_obj_t* parent) {
|
||||
lv_obj_t* list = lv_list_create(parent);
|
||||
lv_obj_set_size(list, LV_PCT(100), LV_PCT(100));
|
||||
lv_obj_center(list);
|
||||
|
||||
auto manifests = app_manifest_registry_get();
|
||||
auto manifests = getApps();
|
||||
std::sort(manifests.begin(), manifests.end(), SortAppManifestByName);
|
||||
|
||||
lv_list_add_text(list, "User");
|
||||
@@ -50,7 +50,7 @@ extern const Manifest manifest = {
|
||||
.id = "Desktop",
|
||||
.name = "Desktop",
|
||||
.type = TypeDesktop,
|
||||
.on_show = &desktop_show,
|
||||
.onShow = &desktop_show,
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -67,7 +67,7 @@ static void on_orientation_set(lv_event_t* event) {
|
||||
}
|
||||
}
|
||||
|
||||
static void app_show(App app, lv_obj_t* parent) {
|
||||
static void app_show(App& app, lv_obj_t* parent) {
|
||||
lv_obj_set_flex_flow(parent, LV_FLEX_FLOW_COLUMN);
|
||||
|
||||
lvgl::toolbar_create(parent, app);
|
||||
@@ -89,7 +89,7 @@ static void app_show(App app, lv_obj_t* parent) {
|
||||
lv_obj_set_width(brightness_slider, LV_PCT(50));
|
||||
lv_obj_align(brightness_slider, LV_ALIGN_TOP_RIGHT, -8, 0);
|
||||
lv_slider_set_range(brightness_slider, 0, 255);
|
||||
lv_obj_add_event_cb(brightness_slider, slider_event_cb, LV_EVENT_VALUE_CHANGED, NULL);
|
||||
lv_obj_add_event_cb(brightness_slider, slider_event_cb, LV_EVENT_VALUE_CHANGED, nullptr);
|
||||
|
||||
const Configuration* config = getConfiguration();
|
||||
hal::SetBacklightDuty set_backlight_duty = config->hardware->display.setBacklightDuty;
|
||||
@@ -115,7 +115,7 @@ static void app_show(App app, lv_obj_t* parent) {
|
||||
lv_dropdown_set_selected(orientation_dropdown, orientation_selected);
|
||||
}
|
||||
|
||||
static void app_hide(TT_UNUSED App app) {
|
||||
static void app_hide(TT_UNUSED App& app) {
|
||||
if (backlight_duty_set) {
|
||||
preferences_set_backlight_duty(backlight_duty);
|
||||
}
|
||||
@@ -126,10 +126,10 @@ extern const Manifest manifest = {
|
||||
.name = "Display",
|
||||
.icon = TT_ASSETS_APP_ICON_DISPLAY_SETTINGS,
|
||||
.type = TypeSettings,
|
||||
.on_start = nullptr,
|
||||
.on_stop = nullptr,
|
||||
.on_show = &app_show,
|
||||
.on_hide = &app_hide
|
||||
.onStart = nullptr,
|
||||
.onStop = nullptr,
|
||||
.onShow = &app_show,
|
||||
.onHide = &app_hide
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -180,8 +180,8 @@ static void update_views(Data* data) {
|
||||
|
||||
// region Lifecycle
|
||||
|
||||
static void on_show(App app, lv_obj_t* parent) {
|
||||
auto* data = static_cast<Data*>(tt_app_get_data(app));
|
||||
static void on_show(App& app, lv_obj_t* parent) {
|
||||
auto* data = static_cast<Data*>(app.getData());
|
||||
|
||||
lv_obj_set_flex_flow(parent, LV_FLEX_FLOW_COLUMN);
|
||||
|
||||
@@ -196,7 +196,7 @@ static void on_show(App app, lv_obj_t* parent) {
|
||||
update_views(data);
|
||||
}
|
||||
|
||||
static void on_start(App app) {
|
||||
static void on_start(App& app) {
|
||||
auto* data = data_alloc();
|
||||
// PC platform is bound to current work directory because of the LVGL file system mapping
|
||||
if (get_platform() == PlatformPc) {
|
||||
@@ -211,11 +211,11 @@ static void on_start(App app) {
|
||||
data_set_entries_for_path(data, "/");
|
||||
}
|
||||
|
||||
tt_app_set_data(app, data);
|
||||
app.setData(data);
|
||||
}
|
||||
|
||||
static void on_stop(App app) {
|
||||
auto* data = static_cast<Data*>(tt_app_get_data(app));
|
||||
static void on_stop(App& app) {
|
||||
auto* data = static_cast<Data*>(app.getData());
|
||||
data_free(data);
|
||||
}
|
||||
|
||||
@@ -226,9 +226,9 @@ extern const Manifest manifest = {
|
||||
.name = "Files",
|
||||
.icon = TT_ASSETS_APP_ICON_FILES,
|
||||
.type = TypeSystem,
|
||||
.on_start = &on_start,
|
||||
.on_stop = &on_stop,
|
||||
.on_show = &on_show,
|
||||
.onStart = &on_start,
|
||||
.onStop = &on_stop,
|
||||
.onShow = &on_show,
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -120,8 +120,8 @@ static void task_stop(Gpio* gpio) {
|
||||
|
||||
// region App lifecycle
|
||||
|
||||
static void app_show(App app, lv_obj_t* parent) {
|
||||
auto* gpio = static_cast<Gpio*>(tt_app_get_data(app));
|
||||
static void app_show(App& app, lv_obj_t* parent) {
|
||||
auto* gpio = (Gpio*)app.getData();
|
||||
|
||||
lv_obj_set_flex_flow(parent, LV_FLEX_FLOW_COLUMN);
|
||||
lv_obj_t* toolbar = lvgl::toolbar_create(parent, app);
|
||||
@@ -176,27 +176,26 @@ static void app_show(App app, lv_obj_t* parent) {
|
||||
task_start(gpio);
|
||||
}
|
||||
|
||||
static void on_hide(App app) {
|
||||
auto* gpio = static_cast<Gpio*>(tt_app_get_data(app));
|
||||
static void on_hide(App& app) {
|
||||
auto* gpio = (Gpio*)app.getData();
|
||||
task_stop(gpio);
|
||||
}
|
||||
|
||||
static void on_start(App app) {
|
||||
auto* gpio = static_cast<Gpio*>(malloc(sizeof(Gpio)));
|
||||
*gpio = (Gpio) {
|
||||
static void on_start(App& app) {
|
||||
auto* gpio = new Gpio {
|
||||
.lv_pins = { nullptr },
|
||||
.pin_states = { 0 },
|
||||
.thread = nullptr,
|
||||
.mutex = tt_mutex_alloc(MutexTypeNormal),
|
||||
.thread_interrupted = true,
|
||||
};
|
||||
tt_app_set_data(app, gpio);
|
||||
app.setData(gpio);
|
||||
}
|
||||
|
||||
static void on_stop(App app) {
|
||||
auto* gpio = static_cast<Gpio*>(tt_app_get_data(app));
|
||||
static void on_stop(App& app) {
|
||||
auto* gpio = (Gpio*)app.getData();
|
||||
tt_mutex_free(gpio->mutex);
|
||||
free(gpio);
|
||||
delete gpio;
|
||||
}
|
||||
|
||||
// endregion App lifecycle
|
||||
@@ -205,10 +204,10 @@ extern const Manifest manifest = {
|
||||
.id = "Gpio",
|
||||
.name = "GPIO",
|
||||
.type = TypeSystem,
|
||||
.on_start = &on_start,
|
||||
.on_stop = &on_stop,
|
||||
.on_show = &app_show,
|
||||
.on_hide = &on_hide
|
||||
.onStart = &on_start,
|
||||
.onStop = &on_stop,
|
||||
.onShow = &app_show,
|
||||
.onHide = &on_hide
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -69,7 +69,7 @@ static void show(lv_obj_t* parent, const hal::i2c::Configuration& configuration)
|
||||
}
|
||||
}
|
||||
|
||||
static void on_show(App app, lv_obj_t* parent) {
|
||||
static void on_show(App& app, lv_obj_t* parent) {
|
||||
lv_obj_set_flex_flow(parent, LV_FLEX_FLOW_COLUMN);
|
||||
lvgl::toolbar_create(parent, app);
|
||||
|
||||
@@ -90,7 +90,7 @@ extern const Manifest manifest = {
|
||||
.name = "I2C",
|
||||
.icon = TT_ASSETS_APP_ICON_I2C_SETTINGS,
|
||||
.type = TypeSettings,
|
||||
.on_show = &on_show
|
||||
.onShow = &on_show
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace tt::app::imageviewer {
|
||||
|
||||
#define TAG "image_viewer"
|
||||
|
||||
static void on_show(App app, lv_obj_t* parent) {
|
||||
static void on_show(App& app, lv_obj_t* parent) {
|
||||
lv_obj_set_flex_flow(parent, LV_FLEX_FLOW_COLUMN);
|
||||
lvgl::toolbar_create(parent, app);
|
||||
|
||||
@@ -22,7 +22,7 @@ static void on_show(App app, lv_obj_t* parent) {
|
||||
lv_obj_t* image = lv_img_create(wrapper);
|
||||
lv_obj_align(image, LV_ALIGN_CENTER, 0, 0);
|
||||
|
||||
const Bundle& bundle = tt_app_get_parameters(app);
|
||||
const Bundle& bundle = app.getParameters();
|
||||
std::string file_argument;
|
||||
if (bundle.optString(IMAGE_VIEWER_FILE_ARGUMENT, file_argument)) {
|
||||
std::string prefixed_path = "A:" + file_argument;
|
||||
@@ -35,7 +35,7 @@ extern const Manifest manifest = {
|
||||
.id = "ImageViewer",
|
||||
.name = "Image Viewer",
|
||||
.type = TypeHidden,
|
||||
.on_show = &on_show
|
||||
.onShow = &on_show
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -53,7 +53,7 @@ static void on_power_enabled_change(lv_event_t* event) {
|
||||
}
|
||||
}
|
||||
|
||||
static void app_show(App app, lv_obj_t* parent) {
|
||||
static void app_show(App& app, lv_obj_t* parent) {
|
||||
lv_obj_set_flex_flow(parent, LV_FLEX_FLOW_COLUMN);
|
||||
|
||||
lvgl::toolbar_create(parent, app);
|
||||
@@ -64,7 +64,7 @@ static void app_show(App app, lv_obj_t* parent) {
|
||||
lv_obj_set_flex_grow(wrapper, 1);
|
||||
lv_obj_set_flex_flow(wrapper, LV_FLEX_FLOW_COLUMN);
|
||||
|
||||
auto* data = static_cast<AppData*>(tt_app_get_data(app));
|
||||
auto* data = static_cast<AppData*>(app.getData());
|
||||
|
||||
// Top row: enable/disable
|
||||
lv_obj_t* switch_container = lv_obj_create(wrapper);
|
||||
@@ -90,21 +90,21 @@ static void app_show(App app, lv_obj_t* parent) {
|
||||
data->update_timer->start(ms_to_ticks(1000));
|
||||
}
|
||||
|
||||
static void app_hide(TT_UNUSED App app) {
|
||||
auto* data = static_cast<AppData*>(tt_app_get_data(app));
|
||||
static void app_hide(TT_UNUSED App& app) {
|
||||
auto* data = static_cast<AppData*>(app.getData());
|
||||
data->update_timer->stop();
|
||||
}
|
||||
|
||||
static void app_start(App app) {
|
||||
static void app_start(App& app) {
|
||||
auto* data = new AppData();
|
||||
data->update_timer = new Timer(Timer::TypePeriodic, &app_update_ui, data);
|
||||
data->power = getConfiguration()->hardware->power;
|
||||
assert(data->power != nullptr); // The Power app only shows up on supported devices
|
||||
tt_app_set_data(app, data);
|
||||
app.setData(data);
|
||||
}
|
||||
|
||||
static void app_stop(App app) {
|
||||
auto* data = static_cast<AppData*>(tt_app_get_data(app));
|
||||
static void app_stop(App& app) {
|
||||
auto* data = static_cast<AppData*>(app.getData());
|
||||
delete data->update_timer;
|
||||
delete data;
|
||||
}
|
||||
@@ -114,10 +114,10 @@ extern const Manifest manifest = {
|
||||
.name = "Power",
|
||||
.icon = TT_ASSETS_APP_ICON_POWER_SETTINGS,
|
||||
.type = TypeSettings,
|
||||
.on_start = &app_start,
|
||||
.on_stop = &app_stop,
|
||||
.on_show = &app_show,
|
||||
.on_hide = &app_hide
|
||||
.onStart = &app_start,
|
||||
.onStop = &app_stop,
|
||||
.onShow = &app_show,
|
||||
.onHide = &app_hide
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -2,18 +2,18 @@
|
||||
|
||||
namespace tt::app::screenshot {
|
||||
|
||||
static void on_show(App app, lv_obj_t* parent) {
|
||||
auto* ui = static_cast<ScreenshotUi*>(tt_app_get_data(app));
|
||||
static void on_show(App& app, lv_obj_t* parent) {
|
||||
auto* ui = static_cast<ScreenshotUi*>(app.getData());
|
||||
create_ui(app, ui, parent);
|
||||
}
|
||||
|
||||
static void on_start(App app) {
|
||||
static void on_start(App& app) {
|
||||
auto* ui = static_cast<ScreenshotUi*>(malloc(sizeof(ScreenshotUi)));
|
||||
tt_app_set_data(app, ui);
|
||||
app.setData(ui);
|
||||
}
|
||||
|
||||
static void on_stop(App app) {
|
||||
auto* ui = static_cast<ScreenshotUi*>(tt_app_get_data(app));
|
||||
static void on_stop(App& app) {
|
||||
auto* ui = static_cast<ScreenshotUi*>(app.getData());
|
||||
free(ui);
|
||||
}
|
||||
|
||||
@@ -22,9 +22,9 @@ extern const Manifest manifest = {
|
||||
.name = "_Screenshot", // So it gets put at the bottom of the desktop and becomes less visible on small screen devices
|
||||
.icon = LV_SYMBOL_IMAGE,
|
||||
.type = TypeSystem,
|
||||
.on_start = &on_start,
|
||||
.on_stop = &on_stop,
|
||||
.on_show = &on_show,
|
||||
.onStart = &on_start,
|
||||
.onStop = &on_stop,
|
||||
.onShow = &on_show,
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -153,7 +153,7 @@ static void create_timer_settings_ui(ScreenshotUi* ui, lv_obj_t* parent) {
|
||||
lv_label_set_text(delay_unit_label, "seconds");
|
||||
}
|
||||
|
||||
void create_ui(App app, ScreenshotUi* ui, lv_obj_t* parent) {
|
||||
void create_ui(const App& app, ScreenshotUi* ui, lv_obj_t* parent) {
|
||||
lv_obj_set_flex_flow(parent, LV_FLEX_FLOW_COLUMN);
|
||||
lv_obj_t* toolbar = lvgl::toolbar_create(parent, app);
|
||||
lv_obj_align(toolbar, LV_ALIGN_TOP_MID, 0, 0);
|
||||
|
||||
@@ -13,6 +13,6 @@ typedef struct {
|
||||
lv_obj_t* delay_textarea;
|
||||
} ScreenshotUi;
|
||||
|
||||
void create_ui(App app, ScreenshotUi* ui, lv_obj_t* parent);
|
||||
void create_ui(const App& app, ScreenshotUi* ui, lv_obj_t* parent);
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -24,7 +24,7 @@ static void create_app_widget(const Manifest* manifest, void* parent) {
|
||||
lv_obj_add_event_cb(btn, &on_app_pressed, LV_EVENT_CLICKED, (void*)manifest);
|
||||
}
|
||||
|
||||
static void on_show(App app, lv_obj_t* parent) {
|
||||
static void on_show(App& app, lv_obj_t* parent) {
|
||||
lv_obj_set_flex_flow(parent, LV_FLEX_FLOW_COLUMN);
|
||||
|
||||
lvgl::toolbar_create(parent, app);
|
||||
@@ -33,7 +33,7 @@ static void on_show(App app, lv_obj_t* parent) {
|
||||
lv_obj_set_width(list, LV_PCT(100));
|
||||
lv_obj_set_flex_grow(list, 1);
|
||||
|
||||
auto manifests = app_manifest_registry_get();
|
||||
auto manifests = getApps();
|
||||
std::sort(manifests.begin(), manifests.end(), SortAppManifestByName);
|
||||
for (const auto& manifest: manifests) {
|
||||
if (manifest->type == TypeSettings) {
|
||||
@@ -47,10 +47,10 @@ extern const Manifest manifest = {
|
||||
.name = "Settings",
|
||||
.icon = TT_ASSETS_APP_ICON_SETTINGS,
|
||||
.type = TypeSystem,
|
||||
.on_start = nullptr,
|
||||
.on_stop = nullptr,
|
||||
.on_show = &on_show,
|
||||
.on_hide = nullptr
|
||||
.onStart = nullptr,
|
||||
.onStop = nullptr,
|
||||
.onShow = &on_show,
|
||||
.onHide = nullptr
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -65,7 +65,7 @@ static void add_memory_bar(lv_obj_t* parent, const char* label, size_t used, siz
|
||||
lv_obj_set_style_text_align(bottom_label, LV_TEXT_ALIGN_RIGHT, 0);
|
||||
}
|
||||
|
||||
static void on_show(App app, lv_obj_t* parent) {
|
||||
static void on_show(App& app, lv_obj_t* parent) {
|
||||
lv_obj_set_flex_flow(parent, LV_FLEX_FLOW_COLUMN);
|
||||
lvgl::toolbar_create(parent, app);
|
||||
|
||||
@@ -106,9 +106,9 @@ extern const Manifest manifest = {
|
||||
.name = "System Info",
|
||||
.icon = TT_ASSETS_APP_ICON_SYSTEM_INFO,
|
||||
.type = TypeSystem,
|
||||
.on_start = nullptr,
|
||||
.on_stop = nullptr,
|
||||
.on_show = &on_show
|
||||
.onStart = nullptr,
|
||||
.onStop = nullptr,
|
||||
.onShow = &on_show
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
namespace tt::app::textviewer {
|
||||
|
||||
static void on_show(App app, lv_obj_t* parent) {
|
||||
static void on_show(App& app, lv_obj_t* parent) {
|
||||
lv_obj_set_flex_flow(parent, LV_FLEX_FLOW_COLUMN);
|
||||
lvgl::toolbar_create(parent, app);
|
||||
|
||||
@@ -22,7 +22,7 @@ static void on_show(App app, lv_obj_t* parent) {
|
||||
|
||||
lv_obj_t* label = lv_label_create(wrapper);
|
||||
lv_obj_align(label, LV_ALIGN_CENTER, 0, 0);
|
||||
const Bundle& bundle = tt_app_get_parameters(app);
|
||||
const Bundle& bundle = app.getParameters();
|
||||
std::string file_argument;
|
||||
if (bundle.optString(TEXT_VIEWER_FILE_ARGUMENT, file_argument)) {
|
||||
std::string prefixed_path = "A:" + file_argument;
|
||||
@@ -35,7 +35,7 @@ extern const Manifest manifest = {
|
||||
.id = "TextViewer",
|
||||
.name = "Text Viewer",
|
||||
.type = TypeHidden,
|
||||
.on_show = &on_show
|
||||
.onShow = &on_show
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -101,8 +101,8 @@ static void event_callback(const void* message, void* context) {
|
||||
request_view_update(wifi);
|
||||
}
|
||||
|
||||
static void app_show(App app, lv_obj_t* parent) {
|
||||
auto* wifi = static_cast<WifiConnect*>(tt_app_get_data(app));
|
||||
static void app_show(App& app, lv_obj_t* parent) {
|
||||
auto* wifi = static_cast<WifiConnect*>(app.getData());
|
||||
|
||||
lock(wifi);
|
||||
wifi->view_enabled = true;
|
||||
@@ -111,8 +111,8 @@ static void app_show(App app, lv_obj_t* parent) {
|
||||
unlock(wifi);
|
||||
}
|
||||
|
||||
static void app_hide(App app) {
|
||||
auto* wifi = static_cast<WifiConnect*>(tt_app_get_data(app));
|
||||
static void app_hide(App& app) {
|
||||
auto* wifi = static_cast<WifiConnect*>(app.getData());
|
||||
// No need to lock view, as this is called from within Gui's LVGL context
|
||||
view_destroy(&wifi->view);
|
||||
lock(wifi);
|
||||
@@ -120,16 +120,15 @@ static void app_hide(App app) {
|
||||
unlock(wifi);
|
||||
}
|
||||
|
||||
static void app_start(App app) {
|
||||
static void app_start(App& app) {
|
||||
auto* wifi_connect = wifi_connect_alloc();
|
||||
tt_app_set_data(app, wifi_connect);
|
||||
app.setData(wifi_connect);
|
||||
}
|
||||
|
||||
static void app_stop(App app) {
|
||||
auto* wifi = static_cast<WifiConnect*>(tt_app_get_data(app));
|
||||
static void app_stop(App& app) {
|
||||
auto* wifi = static_cast<WifiConnect*>(app.getData());
|
||||
tt_assert(wifi != nullptr);
|
||||
wifi_connect_free(wifi);
|
||||
tt_app_set_data(app, nullptr);
|
||||
}
|
||||
|
||||
extern const Manifest manifest = {
|
||||
@@ -137,10 +136,10 @@ extern const Manifest manifest = {
|
||||
.name = "Wi-Fi Connect",
|
||||
.icon = LV_SYMBOL_WIFI,
|
||||
.type = TypeSettings,
|
||||
.on_start = &app_start,
|
||||
.on_stop = &app_stop,
|
||||
.on_show = &app_show,
|
||||
.on_hide = &app_hide
|
||||
.onStart = &app_start,
|
||||
.onStop = &app_stop,
|
||||
.onShow = &app_show,
|
||||
.onHide = &app_hide
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -113,7 +113,7 @@ void view_create_bottom_buttons(WifiConnect* wifi, lv_obj_t* parent) {
|
||||
}
|
||||
|
||||
// TODO: Standardize dialogs
|
||||
void view_create(App app, void* wifi, lv_obj_t* parent) {
|
||||
void view_create(const App& app, void* wifi, lv_obj_t* parent) {
|
||||
WifiConnect* wifi_connect = (WifiConnect*)wifi;
|
||||
WifiConnectView* view = &wifi_connect->view;
|
||||
|
||||
@@ -195,7 +195,7 @@ void view_create(App app, void* wifi, lv_obj_t* parent) {
|
||||
service::gui::keyboard_add_textarea(view->password_textarea);
|
||||
|
||||
// Init from app parameters
|
||||
const Bundle& bundle = tt_app_get_parameters(app);
|
||||
const Bundle& bundle = app.getParameters();
|
||||
std::string ssid;
|
||||
if (bundle.optString(WIFI_CONNECT_PARAM_SSID, ssid)) {
|
||||
lv_textarea_set_text(view->ssid_textarea, ssid.c_str());
|
||||
|
||||
@@ -20,7 +20,7 @@ typedef struct {
|
||||
lv_group_t* group;
|
||||
} WifiConnectView;
|
||||
|
||||
void view_create(App app, void* wifi, lv_obj_t* parent);
|
||||
void view_create(const App& app, void* wifi, lv_obj_t* parent);
|
||||
void view_update(WifiConnectView* view, WifiConnectBindings* bindings, WifiConnectState* state);
|
||||
void view_destroy(WifiConnectView* view);
|
||||
|
||||
|
||||
@@ -116,8 +116,8 @@ static void wifi_manage_event_callback(const void* message, void* context) {
|
||||
request_view_update(wifi);
|
||||
}
|
||||
|
||||
static void app_show(App app, lv_obj_t* parent) {
|
||||
auto* wifi = (WifiManage*)tt_app_get_data(app);
|
||||
static void app_show(App& app, lv_obj_t* parent) {
|
||||
auto* wifi = (WifiManage*)app.getData();
|
||||
|
||||
PubSub* wifi_pubsub = service::wifi::get_pubsub();
|
||||
wifi->wifi_subscription = tt_pubsub_subscribe(wifi_pubsub, &wifi_manage_event_callback, wifi);
|
||||
@@ -144,8 +144,8 @@ static void app_show(App app, lv_obj_t* parent) {
|
||||
}
|
||||
}
|
||||
|
||||
static void app_hide(App app) {
|
||||
auto* wifi = (WifiManage*)tt_app_get_data(app);
|
||||
static void app_hide(App& app) {
|
||||
auto* wifi = (WifiManage*)app.getData();
|
||||
lock(wifi);
|
||||
PubSub* wifi_pubsub = service::wifi::get_pubsub();
|
||||
tt_pubsub_unsubscribe(wifi_pubsub, wifi->wifi_subscription);
|
||||
@@ -154,16 +154,15 @@ static void app_hide(App app) {
|
||||
unlock(wifi);
|
||||
}
|
||||
|
||||
static void app_start(App app) {
|
||||
static void app_start(App& app) {
|
||||
WifiManage* wifi = wifi_manage_alloc();
|
||||
tt_app_set_data(app, wifi);
|
||||
app.setData(wifi);
|
||||
}
|
||||
|
||||
static void app_stop(App app) {
|
||||
auto* wifi = (WifiManage*)tt_app_get_data(app);
|
||||
static void app_stop(App& app) {
|
||||
auto* wifi = (WifiManage*)app.getData();
|
||||
tt_assert(wifi != nullptr);
|
||||
wifi_manage_free(wifi);
|
||||
tt_app_set_data(app, nullptr);
|
||||
}
|
||||
|
||||
extern const Manifest manifest = {
|
||||
@@ -171,10 +170,10 @@ extern const Manifest manifest = {
|
||||
.name = "Wi-Fi",
|
||||
.icon = LV_SYMBOL_WIFI,
|
||||
.type = TypeSettings,
|
||||
.on_start = &app_start,
|
||||
.on_stop = &app_stop,
|
||||
.on_show = &app_show,
|
||||
.on_hide = &app_hide
|
||||
.onStart = &app_start,
|
||||
.onStop = &app_stop,
|
||||
.onShow = &app_show,
|
||||
.onHide = &app_hide
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -129,7 +129,7 @@ static void update_connected_ap(WifiManageView* view, WifiManageState* state, TT
|
||||
|
||||
// region Main
|
||||
|
||||
void view_create(App app, WifiManageView* view, WifiManageBindings* bindings, lv_obj_t* parent) {
|
||||
void view_create(const App& app, WifiManageView* view, WifiManageBindings* bindings, lv_obj_t* parent) {
|
||||
view->root = parent;
|
||||
|
||||
lv_obj_set_flex_flow(parent, LV_FLEX_FLOW_COLUMN);
|
||||
|
||||
@@ -17,7 +17,7 @@ typedef struct {
|
||||
lv_obj_t* connected_ap_label;
|
||||
} WifiManageView;
|
||||
|
||||
void view_create(App app, WifiManageView* view, WifiManageBindings* bindings, lv_obj_t* parent);
|
||||
void view_create(const App& app, WifiManageView* view, WifiManageBindings* bindings, lv_obj_t* parent);
|
||||
void view_update(WifiManageView* view, WifiManageBindings* bindings, WifiManageState* state);
|
||||
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user