Ken Van Hoeylandt ee5a5a7181
Merge develop into main (#304)
## 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
2025-08-23 17:10:18 +02:00

80 lines
2.1 KiB
C++

#include "Tactility/service/ServiceContext.h"
#include "Tactility/TactilityHeadless.h"
#include "Tactility/service/ServiceRegistration.h"
#include <Tactility/Mutex.h>
#include <Tactility/Timer.h>
#define TAG "sdcard_service"
namespace tt::service::sdcard {
extern const ServiceManifest manifest;
class SdCardService final : public Service {
Mutex mutex;
std::unique_ptr<Timer> updateTimer;
hal::sdcard::SdCardDevice::State lastState = hal::sdcard::SdCardDevice::State::Unmounted;
bool lock(TickType_t timeout) const {
return mutex.lock(timeout);
}
void unlock() const {
mutex.unlock();
}
void update() {
auto sdcard = hal::getConfiguration()->sdcard;
assert(sdcard);
if (lock(50)) {
auto new_state = sdcard->getState();
if (new_state == hal::sdcard::SdCardDevice::State::Error) {
TT_LOG_E(TAG, "Sdcard error - unmounting. Did you eject the card in an unsafe manner?");
sdcard->unmount();
}
if (new_state != lastState) {
lastState = new_state;
}
unlock();
} else {
TT_LOG_W(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED);
}
}
public:
void onStart(ServiceContext& serviceContext) override {
if (hal::getConfiguration()->sdcard != nullptr) {
auto service = findServiceById<SdCardService>(manifest.id);
updateTimer = std::make_unique<Timer>(Timer::Type::Periodic, [service]() {
service->update();
});
// We want to try and scan more often in case of startup or scan lock failure
updateTimer->start(1000);
} else {
TT_LOG_I(TAG, "Timer not started: no SD card config");
}
}
void onStop(ServiceContext& serviceContext) override {
if (updateTimer != nullptr) {
// Stop thread
updateTimer->stop();
updateTimer = nullptr;
}
}
};
extern const ServiceManifest manifest = {
.id = "sdcard",
.createService = create<SdCardService>
};
} // namespace