Cleanup and improvements (#194)

- Lots of changes for migrating C code to C++
- Improved `Lockable` in several ways like adding `withLock()` (+ tests)
- Improved `Semaphore` a bit for improved readability, and also added some tests
- Upgrade Linux machine in GitHub Actions so that we can compile with a newer GCC
- Simplification of WiFi connection
- Updated funding options
- (and more)
This commit is contained in:
Ken Van Hoeylandt
2025-01-28 17:39:58 +01:00
committed by GitHub
parent 1bb1260ea0
commit 6c67845645
54 changed files with 518 additions and 531 deletions
@@ -2,11 +2,10 @@
#if TT_FEATURE_SCREENSHOT_ENABLED
#include <cstring>
#include "ScreenshotTask.h"
#include "lv_screenshot.h"
#include <format>
#include "app/AppContext.h"
#include "TactilityCore.h"
#include "service/loader/Loader.h"
#include "lvgl/LvglSync.h"
@@ -45,12 +44,12 @@ void ScreenshotTask::setFinished() {
finished = true;
}
static void makeScreenshot(const char* filename) {
static void makeScreenshot(const std::string& filename) {
if (lvgl::lock(50 / portTICK_PERIOD_MS)) {
if (lv_screenshot_create(lv_scr_act(), LV_100ASK_SCREENSHOT_SV_PNG, filename)) {
TT_LOG_I(TAG, "Screenshot saved to %s", filename);
if (lv_screenshot_create(lv_scr_act(), LV_100ASK_SCREENSHOT_SV_PNG, filename.c_str())) {
TT_LOG_I(TAG, "Screenshot saved to %s", filename.c_str());
} else {
TT_LOG_E(TAG, "Screenshot not saved to %s", filename);
TT_LOG_E(TAG, "Screenshot not saved to %s", filename.c_str());
}
lvgl::unlock();
} else {
@@ -78,8 +77,7 @@ void ScreenshotTask::taskMain() {
if (!isInterrupted()) {
screenshots_taken++;
char filename[SCREENSHOT_PATH_LIMIT + 32];
sprintf(filename, "%s/screenshot-%d.png", work.path, screenshots_taken);
std::string filename = std::format("{}/screenshot-{}.png", work.path, screenshots_taken);
makeScreenshot(filename);
if (work.amount > 0 && screenshots_taken >= work.amount) {
@@ -93,8 +91,7 @@ void ScreenshotTask::taskMain() {
if (manifest.id != last_app_id) {
kernel::delayMillis(100);
last_app_id = manifest.id;
char filename[SCREENSHOT_PATH_LIMIT + 32];
sprintf(filename, "%s/screenshot-%s.png", work.path, manifest.id.c_str());
auto filename = std::format("{}/screenshot-{}.png", work.path, manifest.id);
makeScreenshot(filename);
}
}
@@ -123,9 +120,7 @@ void ScreenshotTask::taskStart() {
thread->start();
}
void ScreenshotTask::startApps(const char* path) {
tt_check(strlen(path) < (SCREENSHOT_PATH_LIMIT - 1));
void ScreenshotTask::startApps(const std::string& path) {
auto scoped_lockable = mutex.scoped();
if (!scoped_lockable->lock(50 / portTICK_PERIOD_MS)) {
TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED);
@@ -135,15 +130,14 @@ void ScreenshotTask::startApps(const char* path) {
if (thread == nullptr) {
interrupted = false;
work.type = TASK_WORK_TYPE_APPS;
strcpy(work.path, path);
work.path = path;
taskStart();
} else {
TT_LOG_E(TAG, "Task was already running");
}
}
void ScreenshotTask::startTimed(const char* path, uint8_t delay_in_seconds, uint8_t amount) {
tt_check(strlen(path) < (SCREENSHOT_PATH_LIMIT - 1));
void ScreenshotTask::startTimed(const std::string& path, uint8_t delay_in_seconds, uint8_t amount) {
auto scoped_lockable = mutex.scoped();
if (!scoped_lockable->lock(50 / portTICK_PERIOD_MS)) {
TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED);
@@ -155,7 +149,7 @@ void ScreenshotTask::startTimed(const char* path, uint8_t delay_in_seconds, uint
work.type = TASK_WORK_TYPE_DELAY;
work.delay_in_seconds = delay_in_seconds;
work.amount = amount;
strcpy(work.path, path);
work.path = path;
taskStart();
} else {
TT_LOG_E(TAG, "Task was already running");