Compiler warning cleanup (#113)
Cleanup + expose more methods for external ELFs
This commit is contained in:
committed by
GitHub
parent
415442e410
commit
e4206e8637
@@ -16,12 +16,12 @@ extern const AppManifest manifest;
|
||||
static void on_timer(TT_UNUSED std::shared_ptr<void> context);
|
||||
|
||||
struct Data {
|
||||
std::unique_ptr<Timer> update_timer = std::unique_ptr<Timer>(new Timer(Timer::TypePeriodic, &on_timer, nullptr));
|
||||
const hal::Power* power;
|
||||
lv_obj_t* enable_switch;
|
||||
lv_obj_t* charge_state;
|
||||
lv_obj_t* charge_level;
|
||||
lv_obj_t* current;
|
||||
Timer update_timer = Timer(Timer::TypePeriodic, &on_timer, nullptr);
|
||||
const hal::Power* power = getConfiguration()->hardware->power;
|
||||
lv_obj_t* enable_switch = nullptr;
|
||||
lv_obj_t* charge_state = nullptr;
|
||||
lv_obj_t* charge_level = nullptr;
|
||||
lv_obj_t* current = nullptr;
|
||||
};
|
||||
|
||||
/** Returns the app data if the app is active. Note that this could clash if the same app is started twice and a background thread is slow. */
|
||||
@@ -53,7 +53,7 @@ static void updateUi(std::shared_ptr<Data> data) {
|
||||
lvgl::unlock();
|
||||
}
|
||||
|
||||
static void on_timer(TT_UNUSED void* context) {
|
||||
static void on_timer(TT_UNUSED std::shared_ptr<void> context) {
|
||||
auto data = optData();
|
||||
if (data != nullptr) {
|
||||
updateUi(data);
|
||||
@@ -110,18 +110,17 @@ static void onShow(AppContext& app, lv_obj_t* parent) {
|
||||
data->current = lv_label_create(wrapper);
|
||||
|
||||
updateUi(data);
|
||||
data->update_timer->start(kernel::millisToTicks(1000));
|
||||
data->update_timer.start(kernel::millisToTicks(1000));
|
||||
}
|
||||
|
||||
static void onHide(TT_UNUSED AppContext& app) {
|
||||
auto data = std::static_pointer_cast<Data>(app.getData());
|
||||
data->update_timer->stop();
|
||||
data->update_timer.stop();
|
||||
}
|
||||
|
||||
static void onStart(AppContext& app) {
|
||||
auto data = std::shared_ptr<Data>();
|
||||
app.setData(data);
|
||||
data->power = getConfiguration()->hardware->power;
|
||||
assert(data->power != nullptr); // The Power app only shows up on supported devices
|
||||
}
|
||||
|
||||
|
||||
@@ -14,23 +14,20 @@ namespace tt::lvgl {
|
||||
|
||||
#define TAG "statusbar"
|
||||
|
||||
typedef struct {
|
||||
const char* image;
|
||||
bool visible;
|
||||
bool claimed;
|
||||
} StatusbarIcon;
|
||||
|
||||
typedef struct {
|
||||
Mutex* mutex;
|
||||
std::shared_ptr<PubSub> pubsub;
|
||||
StatusbarIcon icons[STATUSBAR_ICON_LIMIT];
|
||||
} StatusbarData;
|
||||
|
||||
static StatusbarData statusbar_data = {
|
||||
.mutex = nullptr,
|
||||
.icons = {}
|
||||
struct StatusbarIcon {
|
||||
const char* image = nullptr;
|
||||
bool visible = false;
|
||||
bool claimed = false;
|
||||
};
|
||||
|
||||
struct StatusbarData {
|
||||
Mutex mutex = Mutex(Mutex::TypeRecursive);
|
||||
std::shared_ptr<PubSub> pubsub = std::make_shared<PubSub>();
|
||||
StatusbarIcon icons[STATUSBAR_ICON_LIMIT] = {};
|
||||
};
|
||||
|
||||
static StatusbarData statusbar_data;
|
||||
|
||||
typedef struct {
|
||||
lv_obj_t obj;
|
||||
lv_obj_t* icons[STATUSBAR_ICON_LIMIT];
|
||||
@@ -38,29 +35,12 @@ typedef struct {
|
||||
PubSubSubscription* pubsub_subscription;
|
||||
} Statusbar;
|
||||
|
||||
static void statusbar_init() {
|
||||
statusbar_data.mutex = tt_mutex_alloc(Mutex::TypeRecursive);
|
||||
statusbar_data.pubsub = std::make_shared<PubSub>();
|
||||
for (int i = 0; i < STATUSBAR_ICON_LIMIT; i++) {
|
||||
statusbar_data.icons[i].image = nullptr;
|
||||
statusbar_data.icons[i].visible = false;
|
||||
statusbar_data.icons[i].claimed = false;
|
||||
}
|
||||
}
|
||||
|
||||
static void statusbar_ensure_initialized() {
|
||||
if (statusbar_data.mutex == nullptr) {
|
||||
statusbar_init();
|
||||
}
|
||||
}
|
||||
|
||||
static void statusbar_lock() {
|
||||
statusbar_ensure_initialized();
|
||||
tt_mutex_acquire(statusbar_data.mutex, TtWaitForever);
|
||||
statusbar_data.mutex.acquire(TtWaitForever);
|
||||
}
|
||||
|
||||
static void statusbar_unlock() {
|
||||
tt_mutex_release(statusbar_data.mutex);
|
||||
statusbar_data.mutex.release();
|
||||
}
|
||||
|
||||
static void statusbar_constructor(const lv_obj_class_t* class_p, lv_obj_t* obj);
|
||||
@@ -74,10 +54,14 @@ static const lv_obj_class_t statusbar_class = {
|
||||
.constructor_cb = &statusbar_constructor,
|
||||
.destructor_cb = &statusbar_destructor,
|
||||
.event_cb = &statusbar_event,
|
||||
.user_data = nullptr,
|
||||
.name = nullptr,
|
||||
.width_def = LV_PCT(100),
|
||||
.height_def = STATUSBAR_HEIGHT,
|
||||
.editable = false,
|
||||
.group_def = LV_OBJ_CLASS_GROUP_DEF_TRUE,
|
||||
.instance_size = sizeof(Statusbar)
|
||||
.instance_size = sizeof(Statusbar),
|
||||
.theme_inheritable = false
|
||||
};
|
||||
|
||||
static void statusbar_pubsub_event(TT_UNUSED const void* message, void* obj) {
|
||||
@@ -96,7 +80,6 @@ static void statusbar_constructor(const lv_obj_class_t* class_p, lv_obj_t* obj)
|
||||
lv_obj_remove_flag(obj, LV_OBJ_FLAG_SCROLLABLE);
|
||||
LV_TRACE_OBJ_CREATE("finished");
|
||||
auto* statusbar = (Statusbar*)obj;
|
||||
statusbar_ensure_initialized();
|
||||
statusbar->pubsub_subscription = tt_pubsub_subscribe(statusbar_data.pubsub, &statusbar_pubsub_event, statusbar);
|
||||
}
|
||||
|
||||
@@ -168,6 +151,7 @@ static void statusbar_event(TT_UNUSED const lv_obj_class_t* class_p, lv_event_t*
|
||||
if (code == LV_EVENT_VALUE_CHANGED) {
|
||||
lv_obj_invalidate(obj);
|
||||
} else if (code == LV_EVENT_DRAW_MAIN) {
|
||||
// NO-OP
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,10 +26,15 @@ static const lv_obj_class_t toolbar_class = {
|
||||
.base_class = &lv_obj_class,
|
||||
.constructor_cb = &toolbar_constructor,
|
||||
.destructor_cb = nullptr,
|
||||
.event_cb = nullptr,
|
||||
.user_data = nullptr,
|
||||
.name = nullptr,
|
||||
.width_def = LV_PCT(100),
|
||||
.height_def = TOOLBAR_HEIGHT,
|
||||
.editable = false,
|
||||
.group_def = LV_OBJ_CLASS_GROUP_DEF_TRUE,
|
||||
.instance_size = sizeof(Toolbar),
|
||||
.theme_inheritable = false
|
||||
};
|
||||
|
||||
static void stop_app(TT_UNUSED lv_event_t* event) {
|
||||
|
||||
@@ -27,8 +27,7 @@ void loader_callback(const void* message, TT_UNUSED void* context) {
|
||||
}
|
||||
|
||||
Gui* gui_alloc() {
|
||||
auto* instance = static_cast<Gui*>(malloc(sizeof(Gui)));
|
||||
memset(instance, 0, sizeof(Gui));
|
||||
auto* instance = new Gui();
|
||||
tt_check(instance != nullptr);
|
||||
instance->thread = new Thread(
|
||||
"gui",
|
||||
@@ -36,8 +35,6 @@ Gui* gui_alloc() {
|
||||
&gui_main,
|
||||
nullptr
|
||||
);
|
||||
instance->mutex = tt_mutex_alloc(Mutex::TypeRecursive);
|
||||
instance->keyboard = nullptr;
|
||||
instance->loader_pubsub_subscription = tt_pubsub_subscribe(loader::getPubsub(), &loader_callback, instance);
|
||||
tt_check(lvgl::lock(1000 / portTICK_PERIOD_MS));
|
||||
instance->keyboard_group = lv_group_create();
|
||||
@@ -50,25 +47,23 @@ Gui* gui_alloc() {
|
||||
void gui_free(Gui* instance) {
|
||||
tt_assert(instance != nullptr);
|
||||
delete instance->thread;
|
||||
tt_mutex_free(instance->mutex);
|
||||
|
||||
lv_group_delete(instance->keyboard_group);
|
||||
tt_check(lvgl::lock(1000 / portTICK_PERIOD_MS));
|
||||
lv_group_del(instance->keyboard_group);
|
||||
lvgl::unlock();
|
||||
|
||||
free(instance);
|
||||
delete instance;
|
||||
}
|
||||
|
||||
void lock() {
|
||||
tt_assert(gui);
|
||||
tt_assert(gui->mutex);
|
||||
tt_check(tt_mutex_acquire(gui->mutex, configTICK_RATE_HZ) == TtStatusOk);
|
||||
tt_check(gui->mutex.acquire(configTICK_RATE_HZ) == TtStatusOk);
|
||||
}
|
||||
|
||||
void unlock() {
|
||||
tt_assert(gui);
|
||||
tt_assert(gui->mutex);
|
||||
tt_check(tt_mutex_release(gui->mutex) == TtStatusOk);
|
||||
tt_check(gui->mutex.release() == TtStatusOk);
|
||||
}
|
||||
|
||||
void requestDraw() {
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
#include "ScreenshotTask.h"
|
||||
#include "service/ServiceContext.h"
|
||||
#include "service/ServiceRegistry.h"
|
||||
#include "TactilityCore.h"
|
||||
|
||||
namespace tt::service::screenshot {
|
||||
|
||||
|
||||
@@ -17,36 +17,31 @@ namespace tt::service::screenshot::task {
|
||||
|
||||
#define SCREENSHOT_PATH_LIMIT 128
|
||||
|
||||
typedef struct {
|
||||
int type;
|
||||
uint8_t delay_in_seconds;
|
||||
uint8_t amount;
|
||||
char path[SCREENSHOT_PATH_LIMIT];
|
||||
} ScreenshotTaskWork;
|
||||
|
||||
typedef struct {
|
||||
Thread* thread;
|
||||
Mutex* mutex;
|
||||
bool interrupted;
|
||||
struct ScreenshotTaskWork {
|
||||
int type = TASK_WORK_TYPE_DELAY ;
|
||||
uint8_t delay_in_seconds = 0;
|
||||
uint8_t amount = 0;
|
||||
char path[SCREENSHOT_PATH_LIMIT] = { 0 };
|
||||
};
|
||||
|
||||
struct ScreenshotTaskData {
|
||||
Thread* thread = nullptr;
|
||||
Mutex mutex = Mutex(Mutex::TypeRecursive);
|
||||
bool interrupted = false;
|
||||
ScreenshotTaskWork work;
|
||||
} ScreenshotTaskData;
|
||||
};
|
||||
|
||||
static void task_lock(ScreenshotTaskData* data) {
|
||||
tt_check(tt_mutex_acquire(data->mutex, TtWaitForever) == TtStatusOk);
|
||||
tt_check(data->mutex.acquire(TtWaitForever) == TtStatusOk);
|
||||
}
|
||||
|
||||
static void task_unlock(ScreenshotTaskData* data) {
|
||||
tt_check(tt_mutex_release(data->mutex) == TtStatusOk);
|
||||
tt_check(data->mutex.release() == TtStatusOk);
|
||||
}
|
||||
|
||||
ScreenshotTask* alloc() {
|
||||
auto* data = static_cast<ScreenshotTaskData*>(malloc(sizeof(ScreenshotTaskData)));
|
||||
*data = (ScreenshotTaskData) {
|
||||
.thread = nullptr,
|
||||
.mutex = tt_mutex_alloc(Mutex::TypeRecursive),
|
||||
.interrupted = false
|
||||
};
|
||||
return data;
|
||||
return new ScreenshotTaskData();
|
||||
}
|
||||
|
||||
void free(ScreenshotTask* task) {
|
||||
@@ -54,6 +49,7 @@ void free(ScreenshotTask* task) {
|
||||
if (data->thread) {
|
||||
stop(data);
|
||||
}
|
||||
delete data;
|
||||
}
|
||||
|
||||
static bool is_interrupted(ScreenshotTaskData* data) {
|
||||
|
||||
Reference in New Issue
Block a user