Ken Van Hoeylandt 3ea02d912f
Merge develop into main (#167)
- WiFi Connect app is now hidden by default, but accessible at the bottom of the WiFi Manage app when WiFi is turned on.
- WiFi service now turns on WiFi when calling connect() and WiFi is not on.
- Removed `blocking` option for `service::loader::startApp()`. This feature was unused and complex.
- Various apps: Moved private headers into Private/ folder.
- Various apps: created start() function for easy starting.
- Added documentation to all TactilityC APIs
- Refactored various `enum` into `class enum`
- Refactor M5Stack `initBoot()` (but VBus is still 0V for some reason)
2025-01-17 19:37:42 +01:00

104 lines
2.6 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 = Mode::Apps;
task->startApps(path);
} else {
TT_LOG_W(TAG, "Screenshot task already running");
}
}
void ScreenshotService::startTimed(const char* path, uint8_t delayInSeconds, 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 = Mode::Timed;
task->startTimed(path, delayInSeconds, 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 = Mode::None;
} else {
TT_LOG_W(TAG, "Screenshot task not running");
}
}
Mode ScreenshotService::getMode() const {
auto scoped_lockable = mutex.scoped();
if (!scoped_lockable->lock(50 / portTICK_PERIOD_MS)) {
TT_LOG_W(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED);
return Mode::None;
}
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