Merge develop into main branch (#137)
* 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
This commit is contained in:
committed by
GitHub
parent
9033daa6dd
commit
50bd6e8bf6
@@ -17,7 +17,7 @@ extern const ServiceManifest manifest;
|
||||
struct ServiceData {
|
||||
Mutex mutex;
|
||||
std::unique_ptr<Timer> updateTimer;
|
||||
hal::sdcard::State lastState = hal::sdcard::StateUnmounted;
|
||||
hal::SdCard::State lastState = hal::SdCard::StateUnmounted;
|
||||
|
||||
bool lock(TickType_t timeout) const {
|
||||
return mutex.acquire(timeout) == TtStatusOk;
|
||||
@@ -30,18 +30,23 @@ struct ServiceData {
|
||||
|
||||
|
||||
static void onUpdate(std::shared_ptr<void> context) {
|
||||
auto data = std::static_pointer_cast<ServiceData>(context);
|
||||
|
||||
if (!data->lock(50)) {
|
||||
TT_LOG_W(TAG, "Failed to acquire lock");
|
||||
auto sdcard = tt::hal::getConfiguration().sdcard;
|
||||
if (sdcard == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
hal::sdcard::State new_state = hal::sdcard::getState();
|
||||
auto data = std::static_pointer_cast<ServiceData>(context);
|
||||
|
||||
if (new_state == hal::sdcard::StateError) {
|
||||
if (!data->lock(50)) {
|
||||
TT_LOG_W(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED);
|
||||
return;
|
||||
}
|
||||
|
||||
auto new_state = sdcard->getState();
|
||||
|
||||
if (new_state == hal::SdCard::StateError) {
|
||||
TT_LOG_W(TAG, "Sdcard error - unmounting. Did you eject the card in an unsafe manner?");
|
||||
hal::sdcard::unmount(kernel::millisToTicks(1000));
|
||||
sdcard->unmount();
|
||||
}
|
||||
|
||||
if (new_state != data->lastState) {
|
||||
|
||||
@@ -72,50 +72,54 @@ public:
|
||||
bool connection_target_remember = false; // Whether to store the connection_target on successful connection or not
|
||||
|
||||
WifiRadioState getRadioState() const {
|
||||
auto lock = dataMutex.scoped();
|
||||
lock->acquire(TtWaitForever);
|
||||
auto lockable = dataMutex.scoped();
|
||||
lockable->lock(TtWaitForever);
|
||||
// TODO: Handle lock failure
|
||||
return radio_state;
|
||||
}
|
||||
|
||||
void setRadioState(WifiRadioState newState) {
|
||||
auto lock = dataMutex.scoped();
|
||||
lock->acquire(TtWaitForever);
|
||||
auto lockable = dataMutex.scoped();
|
||||
lockable->lock(TtWaitForever);
|
||||
// TODO: Handle lock failure
|
||||
radio_state = newState;
|
||||
}
|
||||
|
||||
bool isScanning() const {
|
||||
auto lock = dataMutex.scoped();
|
||||
lock->acquire(TtWaitForever);
|
||||
auto lockable = dataMutex.scoped();
|
||||
lockable->lock(TtWaitForever);
|
||||
// TODO: Handle lock failure
|
||||
return radio_state;
|
||||
}
|
||||
|
||||
void setScanning(bool newState) {
|
||||
auto lock = dataMutex.scoped();
|
||||
lock->acquire(TtWaitForever);
|
||||
auto lockable = dataMutex.scoped();
|
||||
lockable->lock(TtWaitForever);
|
||||
// TODO: Handle lock failure
|
||||
scan_active = newState;
|
||||
}
|
||||
|
||||
bool isScanActive() const {
|
||||
auto lock = dataMutex.scoped();
|
||||
lock->acquire(TtWaitForever);
|
||||
auto lcokable = dataMutex.scoped();
|
||||
lcokable->lock(TtWaitForever);
|
||||
return scan_active;
|
||||
}
|
||||
|
||||
void setScanActive(bool newState) {
|
||||
auto lock = dataMutex.scoped();
|
||||
lock->acquire(TtWaitForever);
|
||||
auto lockable = dataMutex.scoped();
|
||||
lockable->lock(TtWaitForever);
|
||||
scan_active = newState;
|
||||
}
|
||||
|
||||
bool isSecureConnection() const {
|
||||
auto lock = dataMutex.scoped();
|
||||
lock->acquire(TtWaitForever);
|
||||
auto lockable = dataMutex.scoped();
|
||||
lockable->lock(TtWaitForever);
|
||||
return secure_connection;
|
||||
}
|
||||
|
||||
void setSecureConnection(bool newState) {
|
||||
auto lock = dataMutex.scoped();
|
||||
lock->acquire(TtWaitForever);
|
||||
auto lockable = dataMutex.scoped();
|
||||
lockable->lock(TtWaitForever);
|
||||
secure_connection = newState;
|
||||
}
|
||||
};
|
||||
@@ -186,8 +190,8 @@ void connect(const settings::WifiApSettings* ap, bool remember) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto lock = wifi->dataMutex.scoped();
|
||||
if (!lock->acquire(10 / portTICK_PERIOD_MS)) {
|
||||
auto lockable = wifi->dataMutex.scoped();
|
||||
if (!lockable->lock(10 / portTICK_PERIOD_MS)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -205,8 +209,8 @@ void disconnect() {
|
||||
return;
|
||||
}
|
||||
|
||||
auto lock = wifi->dataMutex.scoped();
|
||||
if (!lock->acquire(10 / portTICK_PERIOD_MS)) {
|
||||
auto lockable = wifi->dataMutex.scoped();
|
||||
if (!lockable->lock(10 / portTICK_PERIOD_MS)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -227,8 +231,8 @@ void setScanRecords(uint16_t records) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto lock = wifi->dataMutex.scoped();
|
||||
if (!lock->acquire(10 / portTICK_PERIOD_MS)) {
|
||||
auto lockable = wifi->dataMutex.scoped();
|
||||
if (!lockable->lock(10 / portTICK_PERIOD_MS)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -248,8 +252,8 @@ std::vector<WifiApRecord> getScanResults() {
|
||||
return records;
|
||||
}
|
||||
|
||||
auto lock = wifi->dataMutex.scoped();
|
||||
if (!lock->acquire(10 / portTICK_PERIOD_MS)) {
|
||||
auto lockable = wifi->dataMutex.scoped();
|
||||
if (!lockable->lock(10 / portTICK_PERIOD_MS)) {
|
||||
return records;
|
||||
}
|
||||
|
||||
@@ -274,8 +278,8 @@ void setEnabled(bool enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto lock = wifi->dataMutex.scoped();
|
||||
if (!lock->acquire(10 / portTICK_PERIOD_MS)) {
|
||||
auto lockable = wifi->dataMutex.scoped();
|
||||
if (!lockable->lock(10 / portTICK_PERIOD_MS)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -294,8 +298,8 @@ bool isConnectionSecure() {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto lock = wifi->dataMutex.scoped();
|
||||
if (!lock->acquire(10 / portTICK_PERIOD_MS)) {
|
||||
auto lockable = wifi->dataMutex.scoped();
|
||||
if (!lockable->lock(10 / portTICK_PERIOD_MS)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -315,8 +319,8 @@ int getRssi() {
|
||||
// endregion Public functions
|
||||
|
||||
static void scan_list_alloc(std::shared_ptr<Wifi> wifi) {
|
||||
auto lock = wifi->dataMutex.scoped();
|
||||
if (lock->acquire(TtWaitForever)) {
|
||||
auto lockable = wifi->dataMutex.scoped();
|
||||
if (lockable->lock(TtWaitForever)) {
|
||||
tt_assert(wifi->scan_list == nullptr);
|
||||
wifi->scan_list = static_cast<wifi_ap_record_t*>(malloc(sizeof(wifi_ap_record_t) * wifi->scan_list_limit));
|
||||
wifi->scan_list_count = 0;
|
||||
@@ -324,8 +328,8 @@ static void scan_list_alloc(std::shared_ptr<Wifi> wifi) {
|
||||
}
|
||||
|
||||
static void scan_list_alloc_safely(std::shared_ptr<Wifi> wifi) {
|
||||
auto lock = wifi->dataMutex.scoped();
|
||||
if (lock->acquire(TtWaitForever)) {
|
||||
auto lockable = wifi->dataMutex.scoped();
|
||||
if (lockable->lock(TtWaitForever)) {
|
||||
if (wifi->scan_list == nullptr) {
|
||||
scan_list_alloc(wifi);
|
||||
}
|
||||
@@ -333,8 +337,8 @@ static void scan_list_alloc_safely(std::shared_ptr<Wifi> wifi) {
|
||||
}
|
||||
|
||||
static void scan_list_free(std::shared_ptr<Wifi> wifi) {
|
||||
auto lock = wifi->dataMutex.scoped();
|
||||
if (lock->acquire(TtWaitForever)) {
|
||||
auto lockable = wifi->dataMutex.scoped();
|
||||
if (lockable->lock(TtWaitForever)) {
|
||||
tt_assert(wifi->scan_list != nullptr);
|
||||
free(wifi->scan_list);
|
||||
wifi->scan_list = nullptr;
|
||||
@@ -343,8 +347,8 @@ static void scan_list_free(std::shared_ptr<Wifi> wifi) {
|
||||
}
|
||||
|
||||
static void scan_list_free_safely(std::shared_ptr<Wifi> wifi) {
|
||||
auto lock = wifi->dataMutex.scoped();
|
||||
if (lock->acquire(TtWaitForever)) {
|
||||
auto lockable = wifi->dataMutex.scoped();
|
||||
if (lockable->lock(TtWaitForever)) {
|
||||
if (wifi->scan_list != nullptr) {
|
||||
scan_list_free(wifi);
|
||||
}
|
||||
@@ -352,8 +356,8 @@ static void scan_list_free_safely(std::shared_ptr<Wifi> wifi) {
|
||||
}
|
||||
|
||||
static void publish_event_simple(std::shared_ptr<Wifi> wifi, WifiEventType type) {
|
||||
auto lock = wifi->dataMutex.scoped();
|
||||
if (lock->acquire(TtWaitForever)) {
|
||||
auto lockable = wifi->dataMutex.scoped();
|
||||
if (lockable->lock(TtWaitForever)) {
|
||||
WifiEvent turning_on_event = {.type = type};
|
||||
tt_pubsub_publish(wifi->pubsub, &turning_on_event);
|
||||
}
|
||||
@@ -369,8 +373,8 @@ static bool copy_scan_list(std::shared_ptr<Wifi> wifi) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto lock = wifi->dataMutex.scoped();
|
||||
if (!lock->acquire(TtWaitForever)) {
|
||||
auto lockable = wifi->dataMutex.scoped();
|
||||
if (!lockable->lock(TtWaitForever)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -396,9 +400,9 @@ static bool copy_scan_list(std::shared_ptr<Wifi> wifi) {
|
||||
|
||||
static bool find_auto_connect_ap(std::shared_ptr<void> context, settings::WifiApSettings& settings) {
|
||||
auto wifi = std::static_pointer_cast<Wifi>(context);
|
||||
auto lock = wifi->dataMutex.scoped();
|
||||
auto lockable = wifi->dataMutex.scoped();
|
||||
|
||||
if (lock->acquire(10 / portTICK_PERIOD_MS)) {
|
||||
if (lockable->lock(10 / portTICK_PERIOD_MS)) {
|
||||
TT_LOG_I(TAG, "auto_connect()");
|
||||
for (int i = 0; i < wifi->scan_list_count; ++i) {
|
||||
auto ssid = reinterpret_cast<const char*>(wifi->scan_list[i].ssid);
|
||||
@@ -495,9 +499,9 @@ static void dispatchEnable(std::shared_ptr<void> context) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto lock = std::make_unique<ScopedMutexUsage>(wifi->radioMutex);
|
||||
auto lockable = wifi->radioMutex.scoped();
|
||||
|
||||
if (lock->acquire(50 / portTICK_PERIOD_MS)) {
|
||||
if (lockable->lock(50 / portTICK_PERIOD_MS)) {
|
||||
TT_LOG_I(TAG, "Enabling");
|
||||
wifi->setRadioState(WIFI_RADIO_ON_PENDING);
|
||||
publish_event_simple(wifi, WifiEventTypeRadioStateOnPending);
|
||||
@@ -566,17 +570,17 @@ static void dispatchEnable(std::shared_ptr<void> context) {
|
||||
publish_event_simple(wifi, WifiEventTypeRadioStateOn);
|
||||
TT_LOG_I(TAG, "Enabled");
|
||||
} else {
|
||||
TT_LOG_E(TAG, "enable() mutex timeout");
|
||||
TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED);
|
||||
}
|
||||
}
|
||||
|
||||
static void dispatchDisable(std::shared_ptr<void> context) {
|
||||
TT_LOG_I(TAG, "dispatchDisable()");
|
||||
auto wifi = std::static_pointer_cast<Wifi>(context);
|
||||
auto lock = wifi->radioMutex.scoped();
|
||||
auto lockable = wifi->radioMutex.scoped();
|
||||
|
||||
if (!lock->acquire(50 / portTICK_PERIOD_MS)) {
|
||||
TT_LOG_E(TAG, "disable() mutex timeout");
|
||||
if (!lockable->lock(50 / portTICK_PERIOD_MS)) {
|
||||
TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "disable()");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -640,10 +644,10 @@ static void dispatchDisable(std::shared_ptr<void> context) {
|
||||
static void dispatchScan(std::shared_ptr<void> context) {
|
||||
TT_LOG_I(TAG, "dispatchScan()");
|
||||
auto wifi = std::static_pointer_cast<Wifi>(context);
|
||||
auto lock = wifi->radioMutex.scoped();
|
||||
auto lockable = wifi->radioMutex.scoped();
|
||||
|
||||
if (!lock->acquire(10 / portTICK_PERIOD_MS)) {
|
||||
TT_LOG_E(TAG, "dispatchScan() mutex timeout");
|
||||
if (!lockable->lock(10 / portTICK_PERIOD_MS)) {
|
||||
TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -674,10 +678,10 @@ static void dispatchScan(std::shared_ptr<void> context) {
|
||||
static void dispatchConnect(std::shared_ptr<void> context) {
|
||||
TT_LOG_I(TAG, "dispatchConnect()");
|
||||
auto wifi = std::static_pointer_cast<Wifi>(context);
|
||||
auto lock = wifi->radioMutex.scoped();
|
||||
auto lockable = wifi->radioMutex.scoped();
|
||||
|
||||
if (!lock->acquire(50 / portTICK_PERIOD_MS)) {
|
||||
TT_LOG_E(TAG, "dispatchConnect() mutex timeout");
|
||||
if (!lockable->lock(50 / portTICK_PERIOD_MS)) {
|
||||
TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "dispatchConnect()");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -803,10 +807,10 @@ static void dispatchConnect(std::shared_ptr<void> context) {
|
||||
static void dispatchDisconnectButKeepActive(std::shared_ptr<void> context) {
|
||||
TT_LOG_I(TAG, "dispatchDisconnectButKeepActive()");
|
||||
auto wifi = std::static_pointer_cast<Wifi>(context);
|
||||
auto lock = wifi->radioMutex.scoped();
|
||||
auto lockable = wifi->radioMutex.scoped();
|
||||
|
||||
if (!lock->acquire(50 / portTICK_PERIOD_MS)) {
|
||||
TT_LOG_E(TAG, "disconnect_internal_but_keep_active() mutex timeout");
|
||||
if (!lockable->lock(50 / portTICK_PERIOD_MS)) {
|
||||
TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -881,9 +885,9 @@ static void dispatchDisconnectButKeepActive(std::shared_ptr<void> context) {
|
||||
}
|
||||
|
||||
static bool shouldScanForAutoConnect(std::shared_ptr<Wifi> wifi) {
|
||||
auto lock = wifi->dataMutex.scoped();
|
||||
auto lockable = wifi->dataMutex.scoped();
|
||||
|
||||
if (!lock->acquire(100)) {
|
||||
if (!lockable->lock(100)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user