## Launcher - Launcher now has optional power button to show - Launcher layout improvements - Removed text from Launcher (translations with larger amounts of text did not fit small device formats) ## T-Lora Pager - Implement power off (created `BQ25896` driver) - Implemented haptics (created `DRV2605` driver project) and buzz on startup - Reversed scroll wheel - Created `TloraEncoder` device and relocated its logic from `TloraKeyboard` - Disabled SPIRAM test to save 0.5 seconds of boot time (current boot time is very slow) - Update `ST7796` esp_lcd driver to v1.3.4 - Fixed keyboard bug: delete queue in destructor - Fixed driver dependencies: Avoiding usage of global static shared_ptr. Properly constructor-inject everywhere, or use `tt::hal::findDevices()` - I2C configuration is now immutable (you cannot disable it anymore from the I2C Settings app, as it would break crucial drivers) - Renamed I2C and UART subsystems to "Internal" ## Drivers - On/off interface added to `PowerDevice` - Created `tt::hal::Configuration.createDevices`, which is intended to replace all custom create calls for display, keyboard, etc. - Created `EncoderDevice` as a `Device` subtype ## Other Improvements - Changed `findDevices(type, function)` into a templatized function. - Improved SD card mounting ## Fixes - Show Screenshot app again - Fixed Statusbar: some updates were allowed to time out and fail silently: When the Statusbar service would do a state update, the LVGL statusbar would never get updated due to this timeout. - Fixed memory leaks in all `createSdCard()` functions (in most board implementations)
96 lines
2.9 KiB
C++
96 lines
2.9 KiB
C++
#include "Tactility/hal/Device.h"
|
|
|
|
#include <Tactility/Mutex.h>
|
|
|
|
namespace tt::hal {
|
|
|
|
std::vector<std::shared_ptr<Device>> devices;
|
|
Mutex mutex = Mutex(Mutex::Type::Recursive);
|
|
static Device::Id nextId = 0;
|
|
|
|
#define TAG "devices"
|
|
|
|
Device::Device() : id(nextId++) {}
|
|
|
|
template <std::ranges::range RangeType>
|
|
auto toVector(RangeType&& range) {
|
|
auto view = range | std::views::common;
|
|
return std::vector(view.begin(), view.end());
|
|
}
|
|
|
|
void registerDevice(const std::shared_ptr<Device>& device) {
|
|
auto scoped_mutex = mutex.asScopedLock();
|
|
scoped_mutex.lock();
|
|
|
|
if (findDevice(device->getId()) == nullptr) {
|
|
devices.push_back(device);
|
|
TT_LOG_I(TAG, "Registered %s with id %lu", device->getName().c_str(), device->getId());
|
|
} else {
|
|
TT_LOG_W(TAG, "Device %s with id %lu was already registered", device->getName().c_str(), device->getId());
|
|
}
|
|
}
|
|
|
|
void deregisterDevice(const std::shared_ptr<Device>& device) {
|
|
auto scoped_mutex = mutex.asScopedLock();
|
|
scoped_mutex.lock();
|
|
|
|
auto id_to_remove = device->getId();
|
|
auto remove_iterator = std::remove_if(devices.begin(), devices.end(), [id_to_remove](const auto& device) {
|
|
return device->getId() == id_to_remove;
|
|
});
|
|
if (remove_iterator != devices.end()) {
|
|
TT_LOG_I(TAG, "Deregistering %s with id %lu", device->getName().c_str(), device->getId());
|
|
devices.erase(remove_iterator);
|
|
} else {
|
|
TT_LOG_W(TAG, "Deregistering %s with id %lu failed: not found", device->getName().c_str(), device->getId());
|
|
}
|
|
}
|
|
|
|
std::vector<std::shared_ptr<Device>> findDevices(const std::function<bool(const std::shared_ptr<Device>&)>& filterFunction) {
|
|
auto scoped_mutex = mutex.asScopedLock();
|
|
scoped_mutex.lock();
|
|
|
|
auto devices_view = devices | std::views::filter([&filterFunction](auto& device) {
|
|
return filterFunction(device);
|
|
});
|
|
return toVector(devices_view);
|
|
}
|
|
|
|
std::shared_ptr<Device> _Nullable findDevice(const std::function<bool(const std::shared_ptr<Device>&)>& filterFunction) {
|
|
auto scoped_mutex = mutex.asScopedLock();
|
|
scoped_mutex.lock();
|
|
|
|
auto result_set = devices | std::views::filter([&filterFunction](auto& device) {
|
|
return filterFunction(device);
|
|
});
|
|
if (!result_set.empty()) {
|
|
return result_set.front();
|
|
} else {
|
|
return nullptr;
|
|
}
|
|
}
|
|
|
|
std::shared_ptr<Device> _Nullable findDevice(std::string name) {
|
|
return findDevice([&name](auto& device){
|
|
return device->getName() == name;
|
|
});
|
|
}
|
|
|
|
std::shared_ptr<Device> _Nullable findDevice(Device::Id id) {
|
|
return findDevice([id](auto& device){
|
|
return device->getId() == id;
|
|
});
|
|
}
|
|
|
|
std::vector<std::shared_ptr<Device>> findDevices(Device::Type type) {
|
|
return findDevices([type](auto& device) {
|
|
return device->getType() == type;
|
|
});
|
|
}
|
|
|
|
std::vector<std::shared_ptr<Device>> getDevices() {
|
|
return devices;
|
|
}
|
|
|
|
}
|