C++ conversion (#80)

Converted project to C++
This commit is contained in:
Ken Van Hoeylandt
2024-11-22 20:26:08 +01:00
committed by GitHub
parent 6d80144e12
commit 85e26636a3
488 changed files with 6017 additions and 39466 deletions
+33
View File
@@ -0,0 +1,33 @@
#pragma once
#include "App.h"
#include "AppManifest.h"
#include "Mutex.h"
namespace tt {
class AppData {
public:
Mutex* mutex;
const AppManifest* manifest;
AppState state = AppStateInitial;
/** @brief Memory marker at start of app, to detect memory leaks */
size_t memory = 0;
AppFlags flags = {
.flags = 0
};
/** @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.
*/
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;
};
} // namespace
+9
View File
@@ -0,0 +1,9 @@
#pragma once
#include "Hal/Configuration.h"
namespace tt {
void lvgl_init(const hal::Configuration* config);
} // namespace
+44
View File
@@ -0,0 +1,44 @@
#pragma once
#include "MessageQueue.h"
#include "Mutex.h"
#include "Pubsub.h"
#include "Services/Gui/Gui.h"
#include "Services/Gui/ViewPort.h"
#include "Services/Gui/ViewPort_i.h"
#include <cstdio>
namespace tt::service::gui {
#define GUI_THREAD_FLAG_DRAW (1 << 0)
#define GUI_THREAD_FLAG_INPUT (1 << 1)
#define GUI_THREAD_FLAG_EXIT (1 << 2)
#define GUI_THREAD_FLAG_ALL (GUI_THREAD_FLAG_DRAW | GUI_THREAD_FLAG_INPUT | GUI_THREAD_FLAG_EXIT)
/** Gui structure */
struct Gui {
// Thread and lock
Thread* thread;
Mutex* mutex;
PubSubSubscription* loader_pubsub_subscription;
// Layers and Canvas
lv_obj_t* lvgl_parent;
// App-specific
ViewPort* app_view_port;
lv_obj_t* _Nullable keyboard;
lv_group_t* keyboard_group;
};
/** Update GUI, request redraw */
void request_draw();
/** Lock GUI */
void lock();
/** Unlock GUI */
void unlock();
} // namespace
@@ -0,0 +1,23 @@
#pragma once
#include "Services/Gui/ViewPort.h"
namespace tt::service::gui {
/** Process draw call. Calls on_show callback.
* To be used by GUI, called on redraw.
*
* @param view_port ViewPort instance
* @param canvas canvas to draw at
*/
void view_port_show(ViewPort* view_port, lv_obj_t* parent);
/**
* Process draw clearing call. Calls on_hdie callback.
* To be used by GUI, called on redraw.
*
* @param view_port
*/
void view_port_hide(ViewPort* view_port);
} // namespace
@@ -0,0 +1,117 @@
#pragma once
#include "ApiLock.h"
#include "AppManifest.h"
#include "MessageQueue.h"
#include "Pubsub.h"
#include "Thread.h"
#include "Services/Gui/ViewPort.h"
#include "Services/Loader/Loader.h"
#ifdef ESP_PLATFORM
#include "freertos/FreeRTOS.h"
#include "freertos/semphr.h"
#else
#include "FreeRTOS.h"
#include "semphr.h"
#endif
namespace tt::service::loader {
#define APP_STACK_SIZE 32
typedef enum {
LoaderMessageTypeNone,
LoaderMessageTypeAppStart,
LoaderMessageTypeAppStop,
LoaderMessageTypeServiceStop,
} LoaderMessageType;
class LoaderMessageAppStart {
public:
std::string id;
Bundle bundle;
LoaderMessageAppStart() = default;
LoaderMessageAppStart(const std::string& id, const Bundle& bundle) {
this->id = id;
this->bundle = bundle;
}
};
typedef struct {
LoaderStatus value;
} LoaderMessageLoaderStatusResult;
typedef struct {
bool value;
} LoaderMessageBoolResult;
class LoaderMessage {
public:
// This lock blocks anyone from starting an app as long
// as an app is already running via loader_start()
// This lock's lifecycle is not owned by this class.
// TODO: Convert to smart pointer
ApiLock api_lock;
LoaderMessageType type;
struct {
union {
// TODO: Convert to smart pointer
const LoaderMessageAppStart* start;
};
} payload;
struct {
union {
LoaderMessageLoaderStatusResult status_value;
LoaderMessageBoolResult bool_value;
void* raw_value;
};
} result;
LoaderMessage() {
api_lock = nullptr;
type = LoaderMessageTypeNone;
payload = { .start = nullptr };
result = { .raw_value = nullptr };
}
LoaderMessage(const LoaderMessageAppStart* start, const LoaderMessageLoaderStatusResult& statusResult) {
api_lock = nullptr;
type = LoaderMessageTypeAppStart;
payload.start = start;
result.status_value = statusResult;
}
LoaderMessage(LoaderMessageType messageType) {
api_lock = nullptr;
type = messageType;
payload = { .start = nullptr };
result = { .raw_value = nullptr };
}
void setLock(ApiLock lock) {
api_lock = lock;
}
void cleanup() {
if (type == LoaderMessageTypeAppStart) {
delete payload.start;
}
}
};
struct Loader {
Thread* thread;
PubSub* pubsub_internal;
PubSub* pubsub_external;
MessageQueue queue = MessageQueue(1, sizeof(LoaderMessage));
Mutex* mutex;
int8_t app_stack_index;
App app_stack[APP_STACK_SIZE];
};
} // namespace