summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2024-04-02 20:41:36 +1100
committerjacqueline <me@jacqueline.id.au>2024-04-02 20:41:36 +1100
commit654fde5f6819cb52a198a524ab78d97e51ab97c7 (patch)
treebad528f15ebfa35f4c1d9a0a027d01453495fb67 /src
parent1e278d55c4dc0a9ae7b5b4511904202824e5c5df (diff)
downloadtangara-fw-654fde5f6819cb52a198a524ab78d97e51ab97c7.tar.gz
Support disabling automatic database updates
Diffstat (limited to 'src')
-rw-r--r--src/drivers/include/nvs.hpp4
-rw-r--r--src/drivers/nvs.cpp14
-rw-r--r--src/system_fsm/running.cpp16
-rw-r--r--src/ui/include/ui_fsm.hpp1
-rw-r--r--src/ui/ui_fsm.cpp18
5 files changed, 43 insertions, 10 deletions
diff --git a/src/drivers/include/nvs.hpp b/src/drivers/include/nvs.hpp
index f288f8e2..25396622 100644
--- a/src/drivers/include/nvs.hpp
+++ b/src/drivers/include/nvs.hpp
@@ -114,6 +114,9 @@ class NvsStorage {
auto PrimaryInput() -> InputModes;
auto PrimaryInput(InputModes) -> void;
+ auto DbAutoIndex() -> bool;
+ auto DbAutoIndex(bool) -> void;
+
explicit NvsStorage(nvs_handle_t);
~NvsStorage();
@@ -136,6 +139,7 @@ class NvsStorage {
Setting<uint8_t> input_mode_;
Setting<uint8_t> output_mode_;
Setting<bluetooth::MacAndName> bt_preferred_;
+ Setting<uint8_t> db_auto_index_;
util::LruCache<10, bluetooth::mac_addr_t, uint8_t> bt_volumes_;
bool bt_volumes_dirty_;
diff --git a/src/drivers/nvs.cpp b/src/drivers/nvs.cpp
index 28cb542c..33d92a9f 100644
--- a/src/drivers/nvs.cpp
+++ b/src/drivers/nvs.cpp
@@ -39,6 +39,7 @@ static constexpr char kKeyScrollSensitivity[] = "scroll";
static constexpr char kKeyLockPolarity[] = "lockpol";
static constexpr char kKeyDisplayCols[] = "dispcols";
static constexpr char kKeyDisplayRows[] = "disprows";
+static constexpr char kKeyDbAutoIndex[] = "dbautoindex";
static auto nvs_get_string(nvs_handle_t nvs, const char* key)
-> std::optional<std::string> {
@@ -173,6 +174,7 @@ NvsStorage::NvsStorage(nvs_handle_t handle)
input_mode_(kKeyPrimaryInput),
output_mode_(kKeyOutput),
bt_preferred_(kKeyBluetoothPreferred),
+ db_auto_index_(kKeyDbAutoIndex),
bt_volumes_(),
bt_volumes_dirty_(false) {}
@@ -194,6 +196,7 @@ auto NvsStorage::Read() -> void {
input_mode_.read(handle_);
output_mode_.read(handle_);
bt_preferred_.read(handle_);
+ db_auto_index_.read(handle_);
readBtVolumes();
}
@@ -210,6 +213,7 @@ auto NvsStorage::Write() -> bool {
input_mode_.write(handle_);
output_mode_.write(handle_);
bt_preferred_.write(handle_);
+ db_auto_index_.write(handle_);
writeBtVolumes();
return nvs_commit(handle_) == ESP_OK;
}
@@ -370,6 +374,16 @@ auto NvsStorage::PrimaryInput(InputModes mode) -> void {
input_mode_.set(static_cast<uint8_t>(mode));
}
+auto NvsStorage::DbAutoIndex() -> bool {
+ std::lock_guard<std::mutex> lock{mutex_};
+ return db_auto_index_.get().value_or(true);
+}
+
+auto NvsStorage::DbAutoIndex(bool en) -> void {
+ std::lock_guard<std::mutex> lock{mutex_};
+ db_auto_index_.set(static_cast<uint8_t>(en));
+}
+
class VolumesParseClient : public cppbor::ParseClient {
public:
VolumesParseClient(util::LruCache<10, bluetooth::mac_addr_t, uint8_t>& out)
diff --git a/src/system_fsm/running.cpp b/src/system_fsm/running.cpp
index a6ab5d47..8625ac66 100644
--- a/src/system_fsm/running.cpp
+++ b/src/system_fsm/running.cpp
@@ -166,13 +166,15 @@ auto Running::mountStorage() -> bool {
// Tell the database to refresh so that we pick up any changes from the newly
// mounted card.
- sServices->bg_worker().Dispatch<void>([&]() {
- auto db = sServices->database().lock();
- if (!db) {
- return;
- }
- db->updateIndexes();
- });
+ if (sServices->nvs().DbAutoIndex()) {
+ sServices->bg_worker().Dispatch<void>([&]() {
+ auto db = sServices->database().lock();
+ if (!db) {
+ return;
+ }
+ db->updateIndexes();
+ });
+ }
return true;
}
diff --git a/src/ui/include/ui_fsm.hpp b/src/ui/include/ui_fsm.hpp
index 5e1cc487..9f9aa9b9 100644
--- a/src/ui/include/ui_fsm.hpp
+++ b/src/ui/include/ui_fsm.hpp
@@ -130,6 +130,7 @@ class UiState : public tinyfsm::Fsm<UiState> {
static lua::Property sLockSwitch;
static lua::Property sDatabaseUpdating;
+ static lua::Property sDatabaseAutoUpdate;
static lua::Property sUsbMassStorageEnabled;
};
diff --git a/src/ui/ui_fsm.cpp b/src/ui/ui_fsm.cpp
index 835da19e..bb1503b2 100644
--- a/src/ui/ui_fsm.cpp
+++ b/src/ui/ui_fsm.cpp
@@ -282,6 +282,14 @@ lua::Property UiState::sScrollSensitivity{
lua::Property UiState::sLockSwitch{false};
lua::Property UiState::sDatabaseUpdating{false};
+lua::Property UiState::sDatabaseAutoUpdate{
+ false, [](const lua::LuaValue& val) {
+ if (!std::holds_alternative<bool>(val)) {
+ return false;
+ }
+ sServices->nvs().DbAutoIndex(std::get<bool>(val));
+ return true;
+ }};
lua::Property UiState::sUsbMassStorageEnabled{
false, [](const lua::LuaValue& val) {
@@ -557,14 +565,18 @@ void Lua::entry() {
"time", {
{"ticks", [&](lua_State* s) { return Ticks(s); }},
});
- registry.AddPropertyModule("database", {
- {"updating", &sDatabaseUpdating},
- });
+ registry.AddPropertyModule("database",
+ {
+ {"updating", &sDatabaseUpdating},
+ {"auto_update", &sDatabaseAutoUpdate},
+ });
registry.AddPropertyModule("usb",
{
{"msc_enabled", &sUsbMassStorageEnabled},
});
+ sDatabaseAutoUpdate.Update(sServices->nvs().DbAutoIndex());
+
auto bt = sServices->bluetooth();
sBluetoothEnabled.Update(bt.IsEnabled());
sBluetoothConnected.Update(bt.IsConnected());