## New
- Read property files with `PropertiesFile`
- Support `boot.properties` so the user can specify the launcher app and an optional app to start after the launcher finishes. (see `BootProperties.cpp`)
- Create registry for CPU affinity and update code to make use of it
- `AppRegistration` and `ServiceRegistration` now also ensure that the `/data` directories always exist for all apps
- `Notes` is now the default app for opening text files. `TextViewer` is removed entirely. Created `tt::app:🎶:start(path)` function.
- WiFi settings moved from NVS to properties file.
- Specify `*.ap.properties` file on the SD card for automatic WiFi settings import on start-up.
- Added `file::getLock(path)` and `file::withLock(path, function)` to do safe file operations on SD cards
## Improvements
- Update TinyUSB to `1.7.6~1`
- Improved `Boot.cpp` code. General code quality fixes and some restructuring to improve readability.
- `tt::string` functionality improvements
- Rename `AppRegistry` to `AppRegistration`
- Rename `ServiceRegistry` to `ServiceRegistration`
- Cleanup in `Notes.cpp`
- `FileTest.cpp` fix for PC
- Created `TestFile` helper class for tests, which automatically deletes files after the test.
- Renamed `Partitions.h` to `MountPoints.h`
- Created `std::string getMountPoints()` function for easy re-use
- Other code quality improvements
- `SdCardDevice`'s `getState()` and `isMounted()` now have a timeout argument
## Fixes
- ELF loading now has a lock so to avoid a bug when 2 ELF apps are loaded in parallel
178 lines
4.8 KiB
C++
178 lines
4.8 KiB
C++
#include "Tactility/TactilityConfig.h"
|
|
|
|
#if TT_FEATURE_SCREENSHOT_ENABLED
|
|
|
|
#include "Tactility/service/screenshot/ScreenshotTask.h"
|
|
|
|
#include "Tactility/service/loader/Loader.h"
|
|
#include "Tactility/lvgl/LvglSync.h"
|
|
|
|
#include <lv_screenshot.h>
|
|
#include <Tactility/TactilityCore.h>
|
|
|
|
#include <format>
|
|
#include <Tactility/CpuAffinity.h>
|
|
|
|
namespace tt::service::screenshot {
|
|
|
|
#define TAG "screenshot_task"
|
|
|
|
ScreenshotTask::~ScreenshotTask() {
|
|
if (thread) {
|
|
stop();
|
|
}
|
|
}
|
|
|
|
bool ScreenshotTask::isInterrupted() {
|
|
auto lock = mutex.asScopedLock();
|
|
if (!lock.lock(50 / portTICK_PERIOD_MS)) {
|
|
TT_LOG_W(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED);
|
|
return true;
|
|
}
|
|
return interrupted;
|
|
}
|
|
|
|
bool ScreenshotTask::isFinished() {
|
|
auto lock = mutex.asScopedLock();
|
|
if (!lock.lock(50 / portTICK_PERIOD_MS)) {
|
|
TT_LOG_W(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED);
|
|
return false;
|
|
}
|
|
return finished;
|
|
}
|
|
|
|
void ScreenshotTask::setFinished() {
|
|
auto lock = mutex.asScopedLock();
|
|
lock.lock();
|
|
finished = true;
|
|
}
|
|
|
|
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.c_str())) {
|
|
TT_LOG_I(TAG, "Screenshot saved to %s", filename.c_str());
|
|
} else {
|
|
TT_LOG_E(TAG, "Screenshot not saved to %s", filename.c_str());
|
|
}
|
|
lvgl::unlock();
|
|
} else {
|
|
TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "LVGL");
|
|
}
|
|
}
|
|
|
|
void ScreenshotTask::taskMain() {
|
|
uint8_t screenshots_taken = 0;
|
|
std::string last_app_id;
|
|
|
|
while (!isInterrupted()) {
|
|
if (work.type == TASK_WORK_TYPE_DELAY) {
|
|
// Splitting up the delays makes it easier to stop the service
|
|
for (int i = 0; i < (work.delay_in_seconds * 10) && !isInterrupted(); ++i){
|
|
kernel::delayMillis(100);
|
|
}
|
|
|
|
if (!isInterrupted()) {
|
|
screenshots_taken++;
|
|
std::string filename = std::format("{}/screenshot-{}.png", work.path, screenshots_taken);
|
|
makeScreenshot(filename);
|
|
|
|
if (work.amount > 0 && screenshots_taken >= work.amount) {
|
|
break; // Interrupted loop
|
|
}
|
|
}
|
|
} else if (work.type == TASK_WORK_TYPE_APPS) {
|
|
auto appContext = app::getCurrentAppContext();
|
|
if (appContext != nullptr) {
|
|
const app::AppManifest& manifest = appContext->getManifest();
|
|
if (manifest.id != last_app_id) {
|
|
kernel::delayMillis(100);
|
|
last_app_id = manifest.id;
|
|
auto filename = std::format("{}/screenshot-{}.png", work.path, manifest.id);
|
|
makeScreenshot(filename);
|
|
}
|
|
}
|
|
// Ensure the LVGL widgets are rendered as the app just started
|
|
kernel::delayMillis(250);
|
|
}
|
|
}
|
|
|
|
setFinished();
|
|
}
|
|
|
|
void ScreenshotTask::taskStart() {
|
|
auto lock = mutex.asScopedLock();
|
|
if (!lock.lock(50 / portTICK_PERIOD_MS)) {
|
|
TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED);
|
|
return;
|
|
}
|
|
|
|
tt_check(thread == nullptr);
|
|
thread = new Thread(
|
|
"screenshot",
|
|
8192,
|
|
[this] {
|
|
this->taskMain();
|
|
return 0;
|
|
},
|
|
getCpuAffinityConfiguration().graphics
|
|
);
|
|
thread->start();
|
|
}
|
|
|
|
void ScreenshotTask::startApps(const std::string& path) {
|
|
auto lock = mutex.asScopedLock();
|
|
if (!lock.lock(50 / portTICK_PERIOD_MS)) {
|
|
TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED);
|
|
return;
|
|
}
|
|
|
|
if (thread == nullptr) {
|
|
interrupted = false;
|
|
work.type = TASK_WORK_TYPE_APPS;
|
|
work.path = path;
|
|
taskStart();
|
|
} else {
|
|
TT_LOG_E(TAG, "Task was already running");
|
|
}
|
|
}
|
|
|
|
void ScreenshotTask::startTimed(const std::string& path, uint8_t delay_in_seconds, uint8_t amount) {
|
|
auto lock = mutex.asScopedLock();
|
|
if (!lock.lock(50 / portTICK_PERIOD_MS)) {
|
|
TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED);
|
|
return;
|
|
}
|
|
|
|
if (thread == nullptr) {
|
|
interrupted = false;
|
|
work.type = TASK_WORK_TYPE_DELAY;
|
|
work.delay_in_seconds = delay_in_seconds;
|
|
work.amount = amount;
|
|
work.path = path;
|
|
taskStart();
|
|
} else {
|
|
TT_LOG_E(TAG, "Task was already running");
|
|
}
|
|
}
|
|
|
|
void ScreenshotTask::stop() {
|
|
if (thread != nullptr) {
|
|
if (mutex.lock(50 / portTICK_PERIOD_MS)) {
|
|
interrupted = true;
|
|
tt_check(mutex.unlock());
|
|
}
|
|
|
|
thread->join();
|
|
|
|
if (mutex.lock(50 / portTICK_PERIOD_MS)) {
|
|
delete thread;
|
|
thread = nullptr;
|
|
tt_check(mutex.unlock());
|
|
}
|
|
}
|
|
}
|
|
|
|
} // namespace
|
|
|
|
#endif
|