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

custom
ailurux 4 months ago
commit f219886753
  1. 8
      BUILDING.md
  2. 6
      lua/settings.lua
  3. 9
      luals-stubs/nvs.lua
  4. 4
      src/drivers/display.cpp
  5. 3
      src/tangara/audio/audio_fsm.cpp
  6. 19
      src/tangara/database/tag_parser.cpp
  7. 13
      src/tangara/database/tag_parser.hpp
  8. 3
      src/tangara/dev_console/console.cpp
  9. 2
      src/tangara/lua/bridge.cpp
  10. 39
      src/tangara/lua/lua_nvs.cpp
  11. 15
      src/tangara/lua/lua_nvs.hpp

@ -1,5 +1,13 @@
# Building and flashing # Building and flashing
NOTE: The development environment for Linux requires running external pre-compiled binaries linked against GLIBC. This means they will not run on Linux distros that use alternative libc (e.g. musl).
0. For Linux, the following packages are needed to run the development env. Note that package names are from Debian, and may vary on other distros.
- cmake
- libusb-1.0
- python3-venv
1. Make sure you've got all of the submodules in this repo correctly initialised: 1. Make sure you've got all of the submodules in this repo correctly initialised:
``` ```

@ -13,6 +13,7 @@ local usb = require("usb")
local font = require("font") local font = require("font")
local main_menu = require("main_menu") local main_menu = require("main_menu")
local img = require("images") local img = require("images")
local nvs = require("nvs")
local settings = {} local settings = {}
@ -33,6 +34,9 @@ local SettingsScreen = widgets.MenuScreen:new {
pad_left = 4, pad_left = 4,
pad_right = 4, pad_right = 4,
} }
end,
on_hide = function(self)
nvs.write();
end end
} }
@ -290,7 +294,7 @@ settings.DisplaySettings = SettingsScreen:new {
local brightness = self.content:Slider { local brightness = self.content:Slider {
w = lvgl.PCT(100), w = lvgl.PCT(100),
range = { min = 0, max = 100 }, range = { min = 20, max = 100 },
value = display.brightness:get(), value = display.brightness:get(),
} }
brightness:onevent(lvgl.EVENT.VALUE_CHANGED, function() brightness:onevent(lvgl.EVENT.VALUE_CHANGED, function()

@ -0,0 +1,9 @@
--- @meta
--- @class nvs
local nvs = {}
--- Saves current nvs
function nvs.write() end
return nvs

@ -194,6 +194,10 @@ auto Display::SetDisplayOn(bool enabled) -> void {
} }
auto Display::SetBrightness(uint_fast8_t percent) -> void { auto Display::SetBrightness(uint_fast8_t percent) -> void {
// Set a lower limit of 7%, below this the backlight turns off.
// See https://codeberg.org/cool-tech-zone/tangara-fw/issues/158
if (percent < 7)
percent = 7;
brightness_ = brightness_ =
std::pow(static_cast<double>(percent) / 100.0, 2.8) * 1024.0 + 0.5; std::pow(static_cast<double>(percent) / 100.0, 2.8) * 1024.0 + 0.5;
if (first_flush_finished_ && display_on_) { if (first_flush_finished_ && display_on_) {

@ -270,6 +270,9 @@ void AudioState::react(const system_fsm::HasPhonesChanged& ev) {
if (sServices->bluetooth().enabled()) { if (sServices->bluetooth().enabled()) {
events::Audio().Dispatch(audio::OutputModeChanged{ events::Audio().Dispatch(audio::OutputModeChanged{
.set_to = drivers::NvsStorage::Output::kBluetooth}); .set_to = drivers::NvsStorage::Output::kBluetooth});
} else {
// Nothing connected
transit<states::Standby>();
} }
} }
} }

@ -171,9 +171,11 @@ OggTagParser::OggTagParser() {
nameToTag_["ALBUM"] = Tag::kAlbum; nameToTag_["ALBUM"] = Tag::kAlbum;
nameToTag_["ARTIST"] = Tag::kArtist; nameToTag_["ARTIST"] = Tag::kArtist;
nameToTag_["ALBUMARTIST"] = Tag::kAlbumArtist; nameToTag_["ALBUMARTIST"] = Tag::kAlbumArtist;
nameToTag_["TRACK"] = Tag::kTrack;
nameToTag_["TRACKNUMBER"] = Tag::kTrack; nameToTag_["TRACKNUMBER"] = Tag::kTrack;
nameToTag_["GENRE"] = Tag::kGenres; nameToTag_["GENRE"] = Tag::kGenres;
nameToTag_["DISC"] = Tag::kDisc; nameToTag_["DISC"] = Tag::kDisc;
nameToTag_["DISCNUMBER"] = Tag::kDisc;
} }
auto OggTagParser::ReadAndParseTags(std::string_view p) auto OggTagParser::ReadAndParseTags(std::string_view p)
@ -310,6 +312,23 @@ auto GenericTagParser::ReadAndParseTags(std::string_view p)
-> std::shared_ptr<TrackTags> { -> std::shared_ptr<TrackTags> {
std::string path{p}; std::string path{p};
libtags::Aux aux; 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(); auto out = TrackTags::create();
aux.tags = out.get(); aux.tags = out.get();

@ -55,6 +55,19 @@ class GenericTagParser : public ITagParser {
public: public:
auto ReadAndParseTags(std::string_view path) auto ReadAndParseTags(std::string_view path)
-> std::shared_ptr<TrackTags> override; -> 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 } // namespace database

@ -73,7 +73,8 @@ void RegisterLogLevel() {
.command = "loglevel", .command = "loglevel",
.help = .help =
"Sets the log level to one of \"VERBOSE\", \"DEBUG\", \"INFO\", " "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", .hint = "level",
.func = &CmdLogLevel, .func = &CmdLogLevel,
.argtable = NULL}; .argtable = NULL};

@ -25,6 +25,7 @@
#include "lua/lua_database.hpp" #include "lua/lua_database.hpp"
#include "lua/lua_filesystem.hpp" #include "lua/lua_filesystem.hpp"
#include "lua/lua_font.hpp" #include "lua/lua_font.hpp"
#include "lua/lua_nvs.hpp"
#include "lua/lua_queue.hpp" #include "lua/lua_queue.hpp"
#include "lua/lua_screen.hpp" #include "lua/lua_screen.hpp"
#include "lua/lua_testing.hpp" #include "lua/lua_testing.hpp"
@ -84,6 +85,7 @@ auto Bridge::installBaseModules(lua_State* L) -> void {
RegisterVersionModule(L); RegisterVersionModule(L);
RegisterThemeModule(L); RegisterThemeModule(L);
RegisterScreenModule(L); RegisterScreenModule(L);
RegisterNvsModule(L);
} }
auto Bridge::installLvgl(lua_State* L) -> void { auto Bridge::installLvgl(lua_State* L) -> void {

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

@ -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
Loading…
Cancel
Save