* SdCard HAL refactored (#135) - Refactor SdCard HAL - introduce Lockable * Screenshot and FatFS improvements (#136) - Fix screenshots on ESP32 - Improve Screenshot service - Convert Screenshot app to class-based instead of structs - Screenshot app now automatically updates when task is finished - Enable FatFS long filename support * Re-use common log messages (#138) For consistency and binary size reduction * Toolbar spinner should get margin to the right * More TactilityC features (#139) * Rewrote Loader - Simplified Loader by removing custom threa - Created DispatcherThread - Move auto-starting apps to Boot app - Fixed Dispatcher bug where it could get stuck not processing new messages * Hide AP settings if the AP is not saved * Missing from previous commit * Replace LV_EVENT_CLICKED with LV_EVENT_SHORT_CLICKED * Refactored files app and created InputDialog (#140) - Changed Files app so that it has a View and State - Files app now allows for long-pressing on files to perform actions - Files app now has rename and delete actions - Created InputDialog app - Improved AlertDialog app layout
104 lines
2.7 KiB
C++
104 lines
2.7 KiB
C++
#include "TactilityConfig.h"
|
|
|
|
#if TT_FEATURE_SCREENSHOT_ENABLED
|
|
|
|
#include "Screenshot.h"
|
|
#include <memory>
|
|
|
|
#include "service/ServiceContext.h"
|
|
#include "service/ServiceRegistry.h"
|
|
|
|
namespace tt::service::screenshot {
|
|
|
|
#define TAG "screenshot_service"
|
|
|
|
extern const ServiceManifest manifest;
|
|
|
|
std::shared_ptr<ScreenshotService> _Nullable optScreenshotService() {
|
|
ServiceContext* context = service::findServiceById(manifest.id);
|
|
if (context != nullptr) {
|
|
return std::static_pointer_cast<ScreenshotService>(context->getData());
|
|
} else {
|
|
return nullptr;
|
|
}
|
|
}
|
|
|
|
void ScreenshotService::startApps(const char* path) {
|
|
auto scoped_lockable = mutex.scoped();
|
|
if (!scoped_lockable->lock(50 / portTICK_PERIOD_MS)) {
|
|
TT_LOG_W(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED);
|
|
return;
|
|
}
|
|
|
|
if (task == nullptr || task->isFinished()) {
|
|
task = std::make_unique<ScreenshotTask>();
|
|
mode = ScreenshotModeApps;
|
|
task->startApps(path);
|
|
} else {
|
|
TT_LOG_W(TAG, "Screenshot task already running");
|
|
}
|
|
}
|
|
|
|
void ScreenshotService::startTimed(const char* path, uint8_t delay_in_seconds, uint8_t amount) {
|
|
auto scoped_lockable = mutex.scoped();
|
|
if (!scoped_lockable->lock(50 / portTICK_PERIOD_MS)) {
|
|
TT_LOG_W(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED);
|
|
return;
|
|
}
|
|
|
|
if (task == nullptr || task->isFinished()) {
|
|
task = std::make_unique<ScreenshotTask>();
|
|
mode = ScreenshotModeTimed;
|
|
task->startTimed(path, delay_in_seconds, amount);
|
|
} else {
|
|
TT_LOG_W(TAG, "Screenshot task already running");
|
|
}
|
|
}
|
|
|
|
void ScreenshotService::stop() {
|
|
auto scoped_lockable = mutex.scoped();
|
|
if (!scoped_lockable->lock(50 / portTICK_PERIOD_MS)) {
|
|
TT_LOG_W(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED);
|
|
return;
|
|
}
|
|
|
|
if (task != nullptr) {
|
|
task = nullptr;
|
|
mode = ScreenshotModeNone;
|
|
} else {
|
|
TT_LOG_W(TAG, "Screenshot task not running");
|
|
}
|
|
}
|
|
|
|
Mode ScreenshotService::getMode() {
|
|
auto scoped_lockable = mutex.scoped();
|
|
if (!scoped_lockable->lock(50 / portTICK_PERIOD_MS)) {
|
|
TT_LOG_W(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED);
|
|
return ScreenshotModeNone;
|
|
}
|
|
|
|
return mode;
|
|
}
|
|
|
|
bool ScreenshotService::isTaskStarted() {
|
|
auto* current_task = task.get();
|
|
if (current_task == nullptr) {
|
|
return false;
|
|
} else {
|
|
return !current_task->isFinished();
|
|
}
|
|
}
|
|
|
|
static void onStart(ServiceContext& serviceContext) {
|
|
auto service = std::make_shared<ScreenshotService>();
|
|
serviceContext.setData(service);
|
|
}
|
|
|
|
extern const ServiceManifest manifest = {
|
|
.id = "Screenshot",
|
|
.onStart = onStart
|
|
};
|
|
|
|
} // namespace
|
|
|
|
#endif |