diff options
| author | ailurux <ailuruxx@gmail.com> | 2024-12-30 11:04:33 +1100 |
|---|---|---|
| committer | ailurux <ailuruxx@gmail.com> | 2024-12-30 11:04:33 +1100 |
| commit | f2198867538bec387bd54db8dc0ddca8b4a20e60 (patch) | |
| tree | a2ad6645d6866b281c93c09531423a6107d93297 /src/tangara | |
| parent | dac29bf98632bb4450932b06e12328af48f1bb9e (diff) | |
| parent | ff87c9217577783b60ee4cf466a3c59777a2fc40 (diff) | |
| download | tangara-fw-f2198867538bec387bd54db8dc0ddca8b4a20e60.tar.gz | |
Merge branch 'main' of codeberg.org:cool-tech-zone/tangara-fw
Diffstat (limited to 'src/tangara')
| -rw-r--r-- | src/tangara/audio/audio_fsm.cpp | 3 | ||||
| -rw-r--r-- | src/tangara/database/tag_parser.cpp | 19 | ||||
| -rw-r--r-- | src/tangara/database/tag_parser.hpp | 13 | ||||
| -rw-r--r-- | src/tangara/dev_console/console.cpp | 3 | ||||
| -rw-r--r-- | src/tangara/lua/bridge.cpp | 2 | ||||
| -rw-r--r-- | src/tangara/lua/lua_nvs.cpp | 39 | ||||
| -rw-r--r-- | src/tangara/lua/lua_nvs.hpp | 15 |
7 files changed, 93 insertions, 1 deletions
diff --git a/src/tangara/audio/audio_fsm.cpp b/src/tangara/audio/audio_fsm.cpp index 63b960e4..603584b7 100644 --- a/src/tangara/audio/audio_fsm.cpp +++ b/src/tangara/audio/audio_fsm.cpp @@ -270,6 +270,9 @@ void AudioState::react(const system_fsm::HasPhonesChanged& ev) { if (sServices->bluetooth().enabled()) { events::Audio().Dispatch(audio::OutputModeChanged{ .set_to = drivers::NvsStorage::Output::kBluetooth}); + } else { + // Nothing connected + transit<states::Standby>(); } } } diff --git a/src/tangara/database/tag_parser.cpp b/src/tangara/database/tag_parser.cpp index a6a25555..15323a7c 100644 --- a/src/tangara/database/tag_parser.cpp +++ b/src/tangara/database/tag_parser.cpp @@ -171,9 +171,11 @@ OggTagParser::OggTagParser() { nameToTag_["ALBUM"] = Tag::kAlbum; nameToTag_["ARTIST"] = Tag::kArtist; nameToTag_["ALBUMARTIST"] = Tag::kAlbumArtist; + nameToTag_["TRACK"] = Tag::kTrack; nameToTag_["TRACKNUMBER"] = Tag::kTrack; nameToTag_["GENRE"] = Tag::kGenres; nameToTag_["DISC"] = Tag::kDisc; + nameToTag_["DISCNUMBER"] = Tag::kDisc; } auto OggTagParser::ReadAndParseTags(std::string_view p) @@ -310,6 +312,23 @@ auto GenericTagParser::ReadAndParseTags(std::string_view p) -> std::shared_ptr<TrackTags> { std::string path{p}; libtags::Aux aux; + + // Fail fast if trying to parse a file that doesn't appear to be a supported audio format + // For context, see: https://codeberg.org/cool-tech-zone/tangara-fw/issues/149 + bool found = false; + for (const auto& ext : supported_exts) { + // Case-insensitive file extension check + if (std::equal(ext.rbegin(), ext.rend(), path.rbegin(), + [](char a, char b) { return std::tolower(a) == std::tolower(b); })) { + found=true; + break; + } + } + if (!found) { + ESP_LOGD(kTag, "skipping unsupported file: %s", path.c_str()); + return {}; + } + auto out = TrackTags::create(); aux.tags = out.get(); diff --git a/src/tangara/database/tag_parser.hpp b/src/tangara/database/tag_parser.hpp index 642c4876..9130b306 100644 --- a/src/tangara/database/tag_parser.hpp +++ b/src/tangara/database/tag_parser.hpp @@ -55,6 +55,19 @@ class GenericTagParser : public ITagParser { public: auto ReadAndParseTags(std::string_view path) -> std::shared_ptr<TrackTags> override; + + private: + // Supported file extensions for parsing tags, derived from the list of + // supported audio formats here: + // https://cooltech.zone/tangara/docs/music-library/ + static constexpr std::string supported_exts[] = { + "flac", + "mp3", + "ogg", + "ogx", + "opus", + "wav" + }; }; } // namespace database diff --git a/src/tangara/dev_console/console.cpp b/src/tangara/dev_console/console.cpp index bc3a7aca..d902c176 100644 --- a/src/tangara/dev_console/console.cpp +++ b/src/tangara/dev_console/console.cpp @@ -73,7 +73,8 @@ void RegisterLogLevel() { .command = "loglevel", .help = "Sets the log level to one of \"VERBOSE\", \"DEBUG\", \"INFO\", " - "\"WARN\", \"ERROR\", \"NONE\"", + "\"WARN\", \"ERROR\", \"NONE\". NOTE: Some log levels aren't available " + "on release builds.", .hint = "level", .func = &CmdLogLevel, .argtable = NULL}; diff --git a/src/tangara/lua/bridge.cpp b/src/tangara/lua/bridge.cpp index 1c757a22..9521f265 100644 --- a/src/tangara/lua/bridge.cpp +++ b/src/tangara/lua/bridge.cpp @@ -25,6 +25,7 @@ #include "lua/lua_database.hpp" #include "lua/lua_filesystem.hpp" #include "lua/lua_font.hpp" +#include "lua/lua_nvs.hpp" #include "lua/lua_queue.hpp" #include "lua/lua_screen.hpp" #include "lua/lua_testing.hpp" @@ -84,6 +85,7 @@ auto Bridge::installBaseModules(lua_State* L) -> void { RegisterVersionModule(L); RegisterThemeModule(L); RegisterScreenModule(L); + RegisterNvsModule(L); } auto Bridge::installLvgl(lua_State* L) -> void { diff --git a/src/tangara/lua/lua_nvs.cpp b/src/tangara/lua/lua_nvs.cpp new file mode 100644 index 00000000..e38e58d9 --- /dev/null +++ b/src/tangara/lua/lua_nvs.cpp @@ -0,0 +1,39 @@ +/* + * Copyright 2024 Clayton Craft <clayton@craftyguy.net> + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +#include "lua/lua_version.hpp" + +#include "lua.hpp" +#include "lua/bridge.hpp" + +#include "lua.h" +#include "lua/lua_thread.hpp" + +namespace lua { + +[[maybe_unused]] static constexpr char kTag[] = "lua_nvs"; + +static auto write(lua_State* L) -> int { + Bridge* instance = Bridge::Get(L); + instance->services().nvs().Write(); + + return 1; +} + +static const struct luaL_Reg kNvsFuncs[] = {{"write", write}, + {NULL, NULL}}; + +static auto lua_nvs(lua_State* L) -> int { + luaL_newlib(L, kNvsFuncs); + return 1; +} + +auto RegisterNvsModule(lua_State* L) -> void { + luaL_requiref(L, "nvs", lua_nvs, true); + lua_pop(L, 1); +} + +} // namespace lua diff --git a/src/tangara/lua/lua_nvs.hpp b/src/tangara/lua/lua_nvs.hpp new file mode 100644 index 00000000..1275fcc7 --- /dev/null +++ b/src/tangara/lua/lua_nvs.hpp @@ -0,0 +1,15 @@ +/* + * Copyright 2024 Clayton Craft <clayton@craftyguy.net> + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +#pragma once + +#include "lua.hpp" + +namespace lua { + +auto RegisterNvsModule(lua_State*) -> void; + +} // namespace lua |
