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:
Ken Van Hoeylandt
2024-12-27 22:12:39 +00:00
committed by GitHub
parent 9033daa6dd
commit 50bd6e8bf6
144 changed files with 3244 additions and 2038 deletions
+1 -1
View File
@@ -10,7 +10,7 @@ if (DEFINED ENV{ESP_IDF_VERSION})
SRCS ${SOURCE_FILES}
INCLUDE_DIRS "Source/"
PRIV_INCLUDE_DIRS "Private/"
REQUIRES TactilityCore esp_wifi nvs_flash spiffs driver
REQUIRES TactilityCore esp_wifi nvs_flash driver spiffs vfs fatfs
)
if (NOT DEFINED TACTILITY_SKIP_SPIFFS)
+2 -2
View File
@@ -1,8 +1,8 @@
#pragma once
#include "Power.h"
#include "hal/sdcard/Sdcard.h"
#include "hal/i2c/I2c.h"
#include "SdCard.h"
namespace tt::hal {
@@ -49,7 +49,7 @@ struct Configuration {
/**
* An optional SD card interface.
*/
const sdcard::SdCard* _Nullable sdcard = nullptr;
const std::shared_ptr<SdCard> _Nullable sdcard = nullptr;
/**
* An optional power interface for battery or other power delivery.
+1 -1
View File
@@ -19,7 +19,7 @@ void init(const Configuration& configuration) {
if (configuration.sdcard != nullptr) {
TT_LOG_I(TAG, "Mounting sdcard");
if (!sdcard::mount(configuration.sdcard)) {
if (!configuration.sdcard->mount(TT_SDCARD_MOUNT_POINT )) {
TT_LOG_W(TAG, "SD card mount failed (init can continue)");
}
}
+38
View File
@@ -0,0 +1,38 @@
#pragma once
#include "TactilityCore.h"
namespace tt::hal {
#define TT_SDCARD_MOUNT_POINT "/sdcard"
class SdCard {
public:
enum State {
StateMounted,
StateUnmounted,
StateError,
StateUnknown
};
enum MountBehaviour {
MountBehaviourAtBoot, /** Only mount at boot */
MountBehaviourAnytime /** Mount/dismount any time */
};
private:
MountBehaviour mountBehaviour;
public:
explicit SdCard(MountBehaviour mountBehaviour) : mountBehaviour(mountBehaviour) {}
virtual ~SdCard() = default;
virtual bool mount(const char* mountPath) = 0;
virtual bool unmount() = 0;
virtual State getState() const = 0;
virtual MountBehaviour getMountBehaviour() const { return mountBehaviour; }
bool isMounted() const { return getState() == StateMounted; }
};
} // namespace
+159
View File
@@ -0,0 +1,159 @@
#ifdef ESP_PLATFORM
#include "SpiSdCard.h"
#include "Check.h"
#include "Log.h"
#include <driver/gpio.h>
#include <esp_vfs_fat.h>
#include <sdmmc_cmd.h>
#define TAG "spi_sdcard"
namespace tt::hal {
/**
* Before we can initialize the sdcard's SPI communications, we have to set all
* other SPI pins on the board high.
* See https://github.com/espressif/esp-idf/issues/1597
* See https://github.com/Xinyuan-LilyGO/T-Deck/blob/master/examples/UnitTest/UnitTest.ino
* @return success result
*/
bool SpiSdCard::applyGpioWorkAround() {
TT_LOG_D(TAG, "init");
uint64_t pin_bit_mask = BIT64(config->spiPinCs);
for (auto const& pin: config->csPinWorkAround) {
pin_bit_mask |= BIT64(pin);
}
gpio_config_t sd_gpio_config = {
.pin_bit_mask = pin_bit_mask,
.mode = GPIO_MODE_OUTPUT,
.pull_up_en = GPIO_PULLUP_DISABLE,
.pull_down_en = GPIO_PULLDOWN_DISABLE,
.intr_type = GPIO_INTR_DISABLE,
};
if (gpio_config(&sd_gpio_config) != ESP_OK) {
TT_LOG_E(TAG, "GPIO init failed");
return false;
}
for (auto const& pin: config->csPinWorkAround) {
if (gpio_set_level(pin, 1) != ESP_OK) {
TT_LOG_E(TAG, "Failed to set board CS pin high");
return false;
}
}
return true;
}
bool SpiSdCard::mountInternal(const char* mountPoint) {
TT_LOG_I(TAG, "Mounting %s", mountPoint);
esp_vfs_fat_sdmmc_mount_config_t mount_config = {
.format_if_mount_failed = config->formatOnMountFailed,
.max_files = config->maxOpenFiles,
.allocation_unit_size = config->allocUnitSize,
.disk_status_check_enable = config->statusCheckEnabled,
.use_one_fat = false
};
// Init without card detect (CD) and write protect (WD)
sdspi_device_config_t slot_config = SDSPI_DEVICE_CONFIG_DEFAULT();
slot_config.gpio_cs = config->spiPinCs;
slot_config.gpio_cd = config->spiPinCd;
slot_config.gpio_wp = config->spiPinWp;
slot_config.gpio_int = config->spiPinInt;
sdmmc_host_t host = SDSPI_HOST_DEFAULT();
// The following value is from T-Deck repo's UnitTest.ino project:
// https://github.com/Xinyuan-LilyGO/T-Deck/blob/master/examples/UnitTest/UnitTest.ino
// Observation: Using this automatically sets the bus to 20MHz
host.max_freq_khz = config->spiFrequency;
esp_err_t result = esp_vfs_fat_sdspi_mount(mountPoint, &host, &slot_config, &mount_config, &card);
if (result != ESP_OK) {
if (result == ESP_FAIL) {
TT_LOG_E(TAG, "Mounting failed. Ensure the card is formatted with FAT.");
} else {
TT_LOG_E(TAG, "Mounting failed (%s)", esp_err_to_name(result));
}
return false;
}
this->mountPoint = mountPoint;
return true;
}
bool SpiSdCard::mount(const char* mount_point) {
if (!applyGpioWorkAround()) {
TT_LOG_E(TAG, "Failed to set SPI CS pins high. This is a pre-requisite for mounting.");
return false;
}
if (mountInternal(mount_point)) {
sdmmc_card_print_info(stdout, card);
return true;
} else {
TT_LOG_E(TAG, "Mount failed for %s", mount_point);
return false;
}
}
bool SpiSdCard::unmount() {
if (card == nullptr) {
TT_LOG_E(TAG, "Can't unmount: not mounted");
return false;
}
if (esp_vfs_fat_sdcard_unmount(mountPoint.c_str(), card) == ESP_OK) {
mountPoint = "";
card = nullptr;
return true;
} else {
TT_LOG_E(TAG, "Unmount failed for %s", mountPoint.c_str());
return false;
}
}
// TODO: Refactor to "bool getStatus(Status* status)" method so that it can fail when the lvgl lock fails
tt::hal::SdCard::State SpiSdCard::getState() const {
if (card == nullptr) {
return StateUnmounted;
}
/**
* The SD card and the screen are on the same SPI bus.
* Writing and reading to the bus from 2 devices at the same time causes crashes.
* This work-around ensures that this check is only happening when LVGL isn't rendering.
*/
if (config->lockable) {
bool locked = config->lockable->lock(50); // TODO: Refactor to a more reliable locking mechanism
if (!locked) {
TT_LOG_E(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "LVGL");
return StateUnknown;
}
}
bool result = sdmmc_get_status(card) == ESP_OK;
if (config->lockable) {
config->lockable->unlock();
}
if (result) {
return StateMounted;
} else {
return StateError;
}
}
}
#endif
+80
View File
@@ -0,0 +1,80 @@
#ifdef ESP_PLATFORM
#pragma once
#include "hal/SdCard.h"
#include <sd_protocol_types.h>
#include <utility>
#include <vector>
#include <hal/spi_types.h>
#include <soc/gpio_num.h>
namespace tt::hal {
/**
* SD card interface at the default SPI interface
*/
class SpiSdCard : public tt::hal::SdCard {
public:
struct Config {
Config(
int spiFrequency,
gpio_num_t spiPinCs,
gpio_num_t spiPinCd,
gpio_num_t spiPinWp,
gpio_num_t spiPinInt,
MountBehaviour mountBehaviourAtBoot,
std::shared_ptr<Lockable> lockable = nullptr,
std::vector<gpio_num_t> csPinWorkAround = std::vector<gpio_num_t>(),
spi_host_device_t spiHost = SPI2_HOST
) : spiFrequency(spiFrequency),
spiPinCs(spiPinCs),
spiPinCd(spiPinCd),
spiPinWp(spiPinWp),
spiPinInt(spiPinInt),
mountBehaviourAtBoot(mountBehaviourAtBoot),
lockable(std::move(lockable)),
csPinWorkAround(std::move(csPinWorkAround)),
spiHost(spiHost)
{}
int spiFrequency;
gpio_num_t spiPinCs; // Clock
gpio_num_t spiPinCd; // Card detect
gpio_num_t spiPinWp; // Write-protect
gpio_num_t spiPinInt; // Interrupt
SdCard::MountBehaviour mountBehaviourAtBoot;
std::shared_ptr<Lockable> _Nullable lockable;
std::vector<gpio_num_t> csPinWorkAround;
spi_host_device_t spiHost;
bool formatOnMountFailed = false;
uint16_t maxOpenFiles = 4;
uint16_t allocUnitSize = 16 * 1024;
bool statusCheckEnabled = false;
};
private:
std::string mountPoint;
sdmmc_card_t* card = nullptr;
std::shared_ptr<Config> config;
bool applyGpioWorkAround();
bool mountInternal(const char* mount_point);
public:
explicit SpiSdCard(std::unique_ptr<Config> config) :
SdCard(config->mountBehaviourAtBoot),
config(std::move(config))
{}
bool mount(const char* mountPath) override;
bool unmount() override;
State getState() const override;
};
}
#endif
@@ -1,85 +0,0 @@
#include "Sdcard.h"
#include "Mutex.h"
#include "TactilityCore.h"
namespace tt::hal::sdcard {
#define TAG "sdcard"
static Mutex mutex(Mutex::TypeRecursive);
typedef struct {
const SdCard* sdcard;
void* context;
} MountData;
static MountData data = {
.sdcard = nullptr,
.context = nullptr
};
static bool lock(uint32_t timeout_ticks) {
return mutex.acquire(timeout_ticks) == TtStatusOk;
}
static void unlock() {
mutex.release();
}
bool mount(const SdCard* sdcard) {
TT_LOG_I(TAG, "Mounting");
if (data.sdcard != nullptr) {
TT_LOG_E(TAG, "Failed to mount: already mounted");
return false;
}
if (lock(100)) {
void* context = sdcard->mount(TT_SDCARD_MOUNT_POINT);
data = (MountData) {
.sdcard = sdcard,
.context = context
};
unlock();
return (data.context != nullptr);
} else {
TT_LOG_E(TAG, "Failed to lock");
return false;
}
}
State getState() {
if (data.context == nullptr) {
return StateUnmounted;
} else if (data.sdcard->is_mounted(data.context)) {
return StateMounted;
} else {
return StateError;
}
}
bool unmount(uint32_t timeout_ticks) {
TT_LOG_I(TAG, "Unmounting");
bool result = false;
if (lock(timeout_ticks)) {
if (data.sdcard != nullptr) {
data.sdcard->unmount(data.context);
data = (MountData) {
.sdcard = nullptr,
.context = nullptr
};
result = true;
} else {
TT_LOG_E(TAG, "Can't unmount: nothing mounted");
}
unlock();
} else {
TT_LOG_E(TAG, "Failed to lock in %lu ticks", timeout_ticks);
}
return result;
}
} // namespace
@@ -1,35 +0,0 @@
#pragma once
#include "TactilityCore.h"
namespace tt::hal::sdcard {
#define TT_SDCARD_MOUNT_POINT "/sdcard"
typedef void* (*Mount)(const char* mount_path);
typedef void (*Unmount)(void* context);
typedef bool (*IsMounted)(void* context);
typedef enum {
StateMounted,
StateUnmounted,
StateError,
} State;
typedef enum {
MountBehaviourAtBoot, /** Only mount at boot */
MountBehaviourAnytime /** Mount/dismount any time */
} MountBehaviour;
typedef struct {
Mount mount;
Unmount unmount;
IsMounted is_mounted;
MountBehaviour mount_behaviour;
} SdCard;
bool mount(const SdCard* sdcard);
State getState();
bool unmount(uint32_t timeout_ticks);
} // namespace
@@ -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;
}