Merge branch 'main' of codeberg.org:cool-tech-zone/tangara-fw

custom
ailurux 1 year ago
commit f20ca9583a
  1. 21
      lib/leveldb/util/cache.cc
  2. 163
      lua/settings.lua
  3. 19
      src/audio/audio_fsm.cpp
  4. 24
      src/audio/bt_audio_output.cpp
  5. 33
      src/audio/i2s_audio_output.cpp
  6. 3
      src/audio/include/audio_sink.hpp
  7. 2
      src/audio/include/bt_audio_output.hpp
  8. 2
      src/audio/include/i2s_audio_output.hpp
  9. 8
      src/database/database.cpp
  10. 4
      src/drivers/include/nvs.hpp
  11. 4
      src/drivers/include/samd.hpp
  12. 14
      src/drivers/nvs.cpp
  13. 2
      src/drivers/samd.cpp
  14. 12
      src/lua/property.cpp
  15. 4
      src/system_fsm/include/system_events.hpp
  16. 16
      src/system_fsm/running.cpp
  17. 2
      src/system_fsm/system_fsm.cpp
  18. 3
      src/ui/include/ui_fsm.hpp
  19. 27
      src/ui/ui_fsm.cpp
  20. 2
      tools/cmake/common.cmake

@ -8,6 +8,7 @@
#include <cstdio>
#include <cstdlib>
#include "esp_heap_caps.h"
#include "port/port.h"
#include "port/thread_annotations.h"
#include "util/hash.h"
@ -157,7 +158,9 @@ class LRUCache {
void SetCapacity(size_t capacity) { capacity_ = capacity; }
// Like Cache methods, but with an extra "hash" parameter.
Cache::Handle* Insert(const Slice& key, uint32_t hash, void* value,
Cache::Handle* Insert(const Slice& key,
uint32_t hash,
void* value,
size_t charge,
void (*deleter)(const Slice& key, void* value));
Cache::Handle* Lookup(const Slice& key, uint32_t hash);
@ -264,14 +267,16 @@ void LRUCache::Release(Cache::Handle* handle) {
Unref(reinterpret_cast<LRUHandle*>(handle));
}
Cache::Handle* LRUCache::Insert(const Slice& key, uint32_t hash, void* value,
Cache::Handle* LRUCache::Insert(const Slice& key,
uint32_t hash,
void* value,
size_t charge,
void (*deleter)(const Slice& key,
void* value)) {
MutexLock l(&mutex_);
LRUHandle* e =
reinterpret_cast<LRUHandle*>(malloc(sizeof(LRUHandle) - 1 + key.size()));
LRUHandle* e = reinterpret_cast<LRUHandle*>(
heap_caps_malloc(sizeof(LRUHandle) - 1 + key.size(), MALLOC_CAP_SPIRAM));
e->value = value;
e->deleter = deleter;
e->charge = charge;
@ -356,7 +361,9 @@ class ShardedLRUCache : public Cache {
}
}
~ShardedLRUCache() override {}
Handle* Insert(const Slice& key, void* value, size_t charge,
Handle* Insert(const Slice& key,
void* value,
size_t charge,
void (*deleter)(const Slice& key, void* value)) override {
const uint32_t hash = HashSlice(key);
return shard_[Shard(hash)].Insert(key, hash, value, charge, deleter);
@ -396,6 +403,8 @@ class ShardedLRUCache : public Cache {
} // end anonymous namespace
Cache* NewLRUCache(size_t capacity) { return new ShardedLRUCache(capacity); }
Cache* NewLRUCache(size_t capacity) {
return new ShardedLRUCache(capacity);
}
} // namespace leveldb

@ -24,7 +24,7 @@ local function SettingsScreen(title)
align_items = "flex-start",
align_content = "flex-start",
},
w = lvgl.PCT(90),
w = lvgl.PCT(100),
flex_grow = 1,
pad_left = 4,
pad_right = 4,
@ -40,7 +40,7 @@ local BluetoothSettings = screen:new {
flex = {
flex_direction = "row",
justify_content = "flex-start",
align_items = "content",
align_items = "center",
align_content = "flex-start",
},
w = lvgl.PCT(100),
@ -54,10 +54,10 @@ local BluetoothSettings = screen:new {
bluetooth.enabled:set(enabled)
end)
theme.set_style(self.menu.content:Label {
text = "Paired Device",
pad_bottom = 1,
}, "settings_title")
theme.set_style(self.menu.content:Label {
text = "Paired Device",
pad_bottom = 1,
}, "settings_title")
local paired_container = self.menu.content:Object {
flex = {
@ -80,10 +80,10 @@ local BluetoothSettings = screen:new {
bluetooth.paired_device:set()
end)
theme.set_style(self.menu.content:Label {
text = "Nearby Devices",
pad_bottom = 1,
}, "settings_title")
theme.set_style(self.menu.content:Label {
text = "Nearby Devices",
pad_bottom = 1,
}, "settings_title")
local devices = self.menu.content:List {
w = lvgl.PCT(100),
@ -123,9 +123,9 @@ local HeadphonesSettings = screen:new {
createUi = function(self)
self.menu = SettingsScreen("Headphones")
theme.set_style(self.menu.content:Label {
text = "Maxiumum volume limit",
}, "settings_title")
theme.set_style(self.menu.content:Label {
text = "Maxiumum volume limit",
}, "settings_title")
local volume_chooser = self.menu.content:Dropdown {
options = "Line Level (-10 dB)\nCD Level (+6 dB)\nMaximum (+10dB)",
@ -138,9 +138,9 @@ local HeadphonesSettings = screen:new {
volume.limit_db:set(limits[selection])
end)
theme.set_style(self.menu.content:Label {
text = "Left/Right balance",
}, "settings_title")
theme.set_style(self.menu.content:Label {
text = "Left/Right balance",
}, "settings_title")
local balance = self.menu.content:Slider {
w = lvgl.PCT(100),
@ -186,20 +186,20 @@ local DisplaySettings = screen:new {
createUi = function(self)
self.menu = SettingsScreen("Display")
local brightness_title = self.menu.content:Object {
flex = {
flex_direction = "row",
justify_content = "flex-start",
align_items = "flex-start",
align_content = "flex-start",
},
w = lvgl.PCT(100),
h = lvgl.SIZE_CONTENT,
local brightness_title = self.menu.content:Object {
flex = {
flex_direction = "row",
justify_content = "flex-start",
align_items = "flex-start",
align_content = "flex-start",
},
w = lvgl.PCT(100),
h = lvgl.SIZE_CONTENT,
}
brightness_title:Label { text = "Brightness", flex_grow = 1 }
local brightness_pct = brightness_title:Label {}
theme.set_style(brightness_pct, "settings_title")
}
brightness_title:Label { text = "Brightness", flex_grow = 1 }
local brightness_pct = brightness_title:Label {}
theme.set_style(brightness_pct, "settings_title")
local brightness = self.menu.content:Slider {
w = lvgl.PCT(100),
@ -223,9 +223,9 @@ local InputSettings = screen:new {
createUi = function(self)
self.menu = SettingsScreen("Input Method")
theme.set_style(self.menu.content:Label {
text = "Control scheme",
}, "settings_title")
theme.set_style(self.menu.content:Label {
text = "Control scheme",
}, "settings_title")
local schemes = controls.schemes()
local option_to_scheme = {}
@ -261,9 +261,9 @@ local InputSettings = screen:new {
controls.scheme:set(scheme)
end)
theme.set_style(self.menu.content:Label {
text = "Scroll Sensitivity",
}, "settings_title")
theme.set_style(self.menu.content:Label {
text = "Scroll Sensitivity",
}, "settings_title")
local slider_scale = 4; -- Power steering
local sensitivity = self.menu.content:Slider {
@ -282,10 +282,10 @@ local MassStorageSettings = screen:new {
createUi = function(self)
self.menu = SettingsScreen("USB Storage")
local version = require("version").samd()
if tonumber(version) < 2 then
if tonumber(version) < 3 then
self.menu.content:Label {
w = lvgl.PCT(100),
text = "Usb Mass Storage requires a SAMD21 firmware version >=2."
text = "Usb Mass Storage requires a SAMD21 firmware version >=3."
}
return
end
@ -294,7 +294,7 @@ local MassStorageSettings = screen:new {
flex = {
flex_direction = "row",
justify_content = "flex-start",
align_items = "content",
align_items = "center",
align_content = "flex-start",
},
w = lvgl.PCT(100),
@ -304,6 +304,12 @@ local MassStorageSettings = screen:new {
enable_container:Label { text = "Enable", flex_grow = 1 }
local enable_sw = enable_container:Switch {}
local busy_text = self.menu.content:Label {
w = lvgl.PCT(100),
text = "USB is currently busy. Do not unplug or remove the SD card.",
long_mode = lvgl.LABEL.LONG_WRAP,
}
local bind_switch = function()
if usb.msc_enabled:get() then
enable_sw:add_state(lvgl.STATE.CHECKED)
@ -313,12 +319,21 @@ local MassStorageSettings = screen:new {
end
enable_sw:onevent(lvgl.EVENT.VALUE_CHANGED, function()
usb.msc_enabled:set(enable_sw:enabled())
if not usb.msc_busy:get() then
usb.msc_enabled:set(enable_sw:enabled())
end
bind_switch()
end)
self.bindings = {
usb.msc_enabled:bind(bind_switch),
usb.msc_busy:bind(function(busy)
if busy then
busy_text:clear_flag(lvgl.FLAG.HIDDEN)
else
busy_text:add_flag(lvgl.FLAG.HIDDEN)
end
end)
}
end,
canPop = function()
@ -333,25 +348,53 @@ local DatabaseSettings = screen:new {
widgets.Row(self.menu.content, "Schema version", db.version())
widgets.Row(self.menu.content, "Size on disk", string.format("%.1f KiB", db.size() / 1024))
local actions_container = self.menu.content:Object {
w = lvgl.PCT(100),
h = lvgl.SIZE_CONTENT,
flex = {
flex_direction = "row",
justify_content = "center",
align_items = "space-evenly",
align_content = "center",
},
pad_top = 4,
pad_column = 4,
}
actions_container:add_style(styles.list_item)
local auto_update_container = self.menu.content:Object {
flex = {
flex_direction = "row",
justify_content = "flex-start",
align_items = "flex-start",
align_content = "flex-start",
},
w = lvgl.PCT(100),
h = lvgl.SIZE_CONTENT,
}
auto_update_container:add_style(styles.list_item)
auto_update_container:Label { text = "Auto update", flex_grow = 1 }
local auto_update_sw = auto_update_container:Switch {}
auto_update_sw:onevent(lvgl.EVENT.VALUE_CHANGED, function()
database.auto_update:set(auto_update_sw:enabled())
end)
local actions_container = self.menu.content:Object {
w = lvgl.PCT(100),
h = lvgl.SIZE_CONTENT,
flex = {
flex_direction = "row",
justify_content = "center",
align_items = "space-evenly",
align_content = "center",
},
pad_top = 4,
pad_column = 4,
}
actions_container:add_style(styles.list_item)
local update = actions_container:Button {}
update:Label { text = "Update" }
update:Label { text = "Update now" }
update:onClicked(function()
database.update()
end)
self.bindings = {
database.auto_update:bind(function(en)
if en then
auto_update_sw:add_state(lvgl.STATE.CHECKED)
else
auto_update_sw:clear_state(lvgl.STATE.CHECKED)
end
end),
}
end
}
@ -383,13 +426,13 @@ return screen:new {
flex_grow = 1,
}
local function section(name)
local elem = self.list:Label {
text = name,
pad_left = 4,
}
theme.set_style(elem, "settings_title")
end
local function section(name)
local elem = self.list:Label {
text = name,
pad_left = 4,
}
theme.set_style(elem, "settings_title")
end
local function submenu(name, class)
local item = self.list:add_btn(nil, name)

@ -276,7 +276,24 @@ void AudioState::react(const system_fsm::HasPhonesChanged& ev) {
}
void AudioState::react(const SetVolume& ev) {
// TODO.
if (ev.db.has_value()) {
if (sOutput->SetVolumeDb(ev.db.value())) {
commitVolume();
events::Ui().Dispatch(VolumeChanged{
.percent = sOutput->GetVolumePct(),
.db = sOutput->GetVolumeDb(),
});
}
} else if (ev.percent.has_value()) {
if (sOutput->SetVolumePct(ev.percent.value())) {
commitVolume();
events::Ui().Dispatch(VolumeChanged{
.percent = sOutput->GetVolumePct(),
.db = sOutput->GetVolumeDb(),
});
}
}
}
void AudioState::react(const SetVolumeLimit& ev) {

@ -9,6 +9,7 @@
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <cmath>
#include <memory>
#include <variant>
@ -54,11 +55,30 @@ auto BluetoothAudioOutput::GetVolume() -> uint16_t {
}
auto BluetoothAudioOutput::GetVolumePct() -> uint_fast8_t {
return static_cast<uint_fast8_t>(static_cast<int>(volume_) * 100 / 0x7f);
return static_cast<uint_fast8_t>(round(static_cast<int>(volume_) * 100.0 / 0x7f));
}
auto BluetoothAudioOutput::SetVolumePct(uint_fast8_t val) -> bool {
if (val > 100) {
return false;
}
uint16_t vol = (val * (0x7f))/100;
SetVolume(vol);
return true;
}
auto BluetoothAudioOutput::GetVolumeDb() -> int_fast16_t {
return 0;
double pct = GetVolumePct()/100.0;
if (pct <= 0) {
pct = 0.01;
}
int_fast16_t db = log(pct) * 20;
return db;
}
auto BluetoothAudioOutput::SetVolumeDb(int_fast16_t val) -> bool {
double pct = exp(val / 20.0) * 100;
return SetVolumePct(pct);
}
auto BluetoothAudioOutput::AdjustVolumeUp() -> bool {

@ -63,16 +63,21 @@ auto I2SAudioOutput::changeMode(Modes mode) -> void {
return;
}
if (mode == Modes::kOff) {
dac_->Stop();
dac_.reset();
if (dac_) {
dac_->Stop();
dac_.reset();
}
return;
} else if (current_mode_ == Modes::kOff) {
auto instance = drivers::I2SDac::create(expander_);
if (!instance) {
return;
}
if (current_mode_ == Modes::kOff) {
if (!dac_) {
auto instance = drivers::I2SDac::create(expander_);
if (!instance) {
return;
}
dac_.reset(*instance);
}
SetVolume(GetVolume());
dac_.reset(*instance);
dac_->SetSource(stream());
dac_->Start();
}
@ -111,6 +116,15 @@ auto I2SAudioOutput::GetVolumePct() -> uint_fast8_t {
return (current_volume_ - kMinVolume) * 100 / (max_volume_ - kMinVolume);
}
auto I2SAudioOutput::SetVolumePct(uint_fast8_t val) -> bool {
if (val > 100) {
return false;
}
uint16_t vol = (val * (max_volume_ - kMinVolume))/100 + kMinVolume;
SetVolume(vol);
return true;
}
auto I2SAudioOutput::GetVolumeDb() -> int_fast16_t {
// Add two before dividing in order to round correctly.
return (static_cast<int>(current_volume_) -
@ -118,6 +132,11 @@ auto I2SAudioOutput::GetVolumeDb() -> int_fast16_t {
4;
}
auto I2SAudioOutput::SetVolumeDb(int_fast16_t val) -> bool {
SetVolume(val * 4 + static_cast<int>(drivers::wm8523::kLineLevelReferenceVolume) - 2);
return true;
}
auto I2SAudioOutput::AdjustVolumeUp() -> bool {
if (GetVolume() >= max_volume_) {
return false;

@ -59,6 +59,9 @@ class IAudioOutput {
virtual auto GetVolumePct() -> uint_fast8_t = 0;
virtual auto GetVolumeDb() -> int_fast16_t = 0;
virtual auto SetVolumePct(uint_fast8_t) -> bool = 0;
virtual auto SetVolumeDb(int_fast16_t) -> bool = 0;
virtual auto AdjustVolumeUp() -> bool = 0;
virtual auto AdjustVolumeDown() -> bool = 0;

@ -35,7 +35,9 @@ class BluetoothAudioOutput : public IAudioOutput {
auto GetVolume() -> uint16_t override;
auto GetVolumePct() -> uint_fast8_t override;
auto SetVolumePct(uint_fast8_t val) -> bool override;
auto GetVolumeDb() -> int_fast16_t override;
auto SetVolumeDb(int_fast16_t) -> bool override;
auto AdjustVolumeUp() -> bool override;
auto AdjustVolumeDown() -> bool override;

@ -33,7 +33,9 @@ class I2SAudioOutput : public IAudioOutput {
auto GetVolume() -> uint16_t override;
auto GetVolumePct() -> uint_fast8_t override;
auto SetVolumePct(uint_fast8_t val) -> bool override;
auto GetVolumeDb() -> int_fast16_t override;
auto SetVolumeDb(int_fast16_t) -> bool override;
auto AdjustVolumeUp() -> bool override;
auto AdjustVolumeDown() -> bool override;

@ -139,14 +139,14 @@ auto Database::Open(IFileGatherer& gatherer,
[&]() -> cpp::result<Database*, DatabaseError> {
leveldb::DB* db;
std::unique_ptr<leveldb::Cache> cache{
leveldb::NewLRUCache(4 * 1024)};
leveldb::NewLRUCache(256 * 1024)};
leveldb::Options options;
options.env = sEnv.env();
options.write_buffer_size = 4 * 1024;
options.max_file_size = 32;
options.max_file_size = 16 * 1024;
options.block_cache = cache.get();
options.block_size = 512;
options.block_size = 2048;
auto status = leveldb::DB::Open(options, kDbPath, &db);
if (!status.ok()) {
@ -299,7 +299,7 @@ auto Database::updateIndexes() -> void {
UpdateNotifier notifier{is_updating_};
leveldb::ReadOptions read_options;
read_options.fill_cache = false;
read_options.fill_cache = true;
// Stage 1: verify all existing tracks are still valid.
ESP_LOGI(kTag, "verifying existing tracks");

@ -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_;

@ -48,8 +48,8 @@ class Samd {
// There is a compatible usb host attached, but USB MSC is not currently
// in use by the SAMD.
kAttachedIdle,
// The SAMD is currently exposing the SD card via USB MSC.
kAttachedMounted,
// The SAMD is currently writing to the SD card via USB MSC.
kAttachedBusy,
};
auto GetUsbStatus() -> UsbStatus;

@ -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)

@ -113,7 +113,7 @@ auto Samd::UpdateUsbStatus() -> void {
usb_status_ = UsbStatus::kDetached;
}
usb_status_ =
(raw_res & 0b10) ? UsbStatus::kAttachedMounted : UsbStatus::kAttachedIdle;
(raw_res & 0b10) ? UsbStatus::kAttachedBusy : UsbStatus::kAttachedIdle;
}
auto Samd::ResetToFlashSamd() -> void {

@ -379,22 +379,22 @@ auto Property::Update(const LuaValue& v) -> void {
for (int i = bindings_.size() - 1; i >= 0; i--) {
auto& b = bindings_[i];
int top = lua_gettop(b.first);
lua_pushstring(b.first, kBindingsTable);
lua_gettable(b.first, LUA_REGISTRYINDEX); // REGISTRY[kBindingsTable]
int type = lua_rawgeti(b.first, -1, b.second); // push bindings[i]
// Has closure has been GCed?
if (type == LUA_TNIL) {
// Clean up after ourselves.
lua_pop(b.first, 1);
// Remove the binding.
bindings_.erase(bindings_.begin() + i);
continue;
} else {
PushValue(*b.first); // push the argument
CallProtected(b.first, 1, 0); // invoke the closure
}
PushValue(*b.first); // push the argument
CallProtected(b.first, 1, 0); // invoke the closure
lua_pop(b.first, 1); // pop the bindings table
lua_settop(b.first, top); // clean up after ourselves
}
}

@ -12,6 +12,7 @@
#include "bluetooth_types.hpp"
#include "database.hpp"
#include "haptics.hpp"
#include "samd.hpp"
#include "service_locator.hpp"
#include "tinyfsm.hpp"
@ -56,6 +57,9 @@ struct SdDetectChanged : tinyfsm::Event {
struct SamdUsbMscChanged : tinyfsm::Event {
bool en;
};
struct SamdUsbStatusChanged : tinyfsm::Event {
drivers::Samd::UsbStatus new_status;
};
struct BatteryStateChanged : tinyfsm::Event {
battery::Battery::BatteryState new_state;

@ -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;
}

@ -88,7 +88,7 @@ void SystemState::react(const internal::SamdInterrupt&) {
sServices->battery().Update();
}
if (usb_status != prev_usb_status) {
ESP_LOGI(kTag, "usb status changed");
events::Ui().Dispatch(SamdUsbStatusChanged{.new_status = usb_status});
}
}

@ -65,6 +65,7 @@ class UiState : public tinyfsm::Fsm<UiState> {
void react(const audio::VolumeLimitChanged&);
void react(const system_fsm::KeyLockChanged&);
void react(const system_fsm::SamdUsbStatusChanged&);
void react(const internal::DismissAlerts&);
void react(const internal::ControlSchemeChanged&);
@ -130,8 +131,10 @@ class UiState : public tinyfsm::Fsm<UiState> {
static lua::Property sLockSwitch;
static lua::Property sDatabaseUpdating;
static lua::Property sDatabaseAutoUpdate;
static lua::Property sUsbMassStorageEnabled;
static lua::Property sUsbMassStorageBusy;
};
namespace states {

@ -43,6 +43,7 @@
#include "nvs.hpp"
#include "property.hpp"
#include "relative_wheel.hpp"
#include "samd.hpp"
#include "screen.hpp"
#include "screen_lua.hpp"
#include "screen_splash.hpp"
@ -282,6 +283,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) {
@ -294,6 +303,8 @@ lua::Property UiState::sUsbMassStorageEnabled{
return true;
}};
lua::Property UiState::sUsbMassStorageBusy{false};
auto UiState::InitBootSplash(drivers::IGpios& gpios, drivers::NvsStorage& nvs)
-> bool {
// Init LVGL first, since the display driver registers itself with LVGL.
@ -352,6 +363,11 @@ void UiState::react(const system_fsm::KeyLockChanged& ev) {
sLockSwitch.Update(ev.locking);
}
void UiState::react(const system_fsm::SamdUsbStatusChanged& ev) {
sUsbMassStorageBusy.Update(ev.new_status ==
drivers::Samd::UsbStatus::kAttachedBusy);
}
void UiState::react(const internal::ControlSchemeChanged&) {
if (!sInput) {
return;
@ -557,14 +573,19 @@ 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},
{"msc_busy", &sUsbMassStorageBusy},
});
sDatabaseAutoUpdate.Update(sServices->nvs().DbAutoIndex());
auto bt = sServices->bluetooth();
sBluetoothEnabled.Update(bt.IsEnabled());
sBluetoothConnected.Update(bt.IsConnected());

@ -5,7 +5,7 @@
# For more information about build system see
# https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html
set(PROJECT_VER "0.8.0")
set(PROJECT_VER "0.8.1")
# esp-idf sets the C++ standard weird. Set cmake vars to match.
set(CMAKE_CXX_STANDARD 23)

Loading…
Cancel
Save