Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a45b63528e | ||
|
|
3713c859ad | ||
|
|
972eb280d0 | ||
|
|
2ab4e9d8a6 |
@@ -32,6 +32,7 @@
|
||||
namespace audio {
|
||||
|
||||
static constexpr uint16_t kVolumeRange = 60;
|
||||
static constexpr uint16_t kVolumeStep = 5; // CUSTOM - added
|
||||
|
||||
using ConnectionState = drivers::Bluetooth::ConnectionState;
|
||||
|
||||
@@ -101,7 +102,11 @@ auto BluetoothAudioOutput::AdjustVolumeUp() -> bool {
|
||||
if (volume_ == 100) {
|
||||
return false;
|
||||
}
|
||||
volume_++;
|
||||
if (volume_ > 100 - kVolumeStep) {
|
||||
volume_ = 100;
|
||||
} else {
|
||||
volume_ += kVolumeStep;
|
||||
}
|
||||
SetVolume(volume_);
|
||||
return true;
|
||||
}
|
||||
@@ -110,7 +115,11 @@ auto BluetoothAudioOutput::AdjustVolumeDown() -> bool {
|
||||
if (volume_ == 0) {
|
||||
return false;
|
||||
}
|
||||
volume_--;
|
||||
if (volume_ < kVolumeStep) {
|
||||
volume_ = 0;
|
||||
} else {
|
||||
volume_ -= kVolumeStep;
|
||||
}
|
||||
SetVolume(volume_);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ static constexpr uint16_t kMinVolume = 0b0;
|
||||
static constexpr uint16_t kMaxVolumeBeforeClipping = 0x185;
|
||||
static constexpr uint16_t kLineLevelVolume = 0x13d;
|
||||
static constexpr uint16_t kDefaultVolume = 0x100;
|
||||
static constexpr uint16_t kVolumeStep = 5; // CUSTOM - added
|
||||
|
||||
I2SAudioOutput::I2SAudioOutput(drivers::IGpios& expander,
|
||||
drivers::OutputBuffers& buffers)
|
||||
@@ -140,21 +141,29 @@ auto I2SAudioOutput::SetVolumeDb(int_fast16_t val) -> bool {
|
||||
}
|
||||
|
||||
auto I2SAudioOutput::AdjustVolumeUp() -> bool {
|
||||
if (GetVolume() >= max_volume_) {
|
||||
uint16_t vol = GetVolume();
|
||||
if (vol >= max_volume_) {
|
||||
return false;
|
||||
}
|
||||
SetVolume(GetVolume() + 1);
|
||||
|
||||
if (vol > max_volume_ - kVolumeStep) {
|
||||
SetVolume(max_volume_);
|
||||
} else {
|
||||
SetVolume(vol + kVolumeStep);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
auto I2SAudioOutput::AdjustVolumeDown() -> bool {
|
||||
if (GetVolume() == kMinVolume) {
|
||||
uint16_t vol = GetVolume();
|
||||
if (vol == kMinVolume) {
|
||||
return false;
|
||||
}
|
||||
if (GetVolume() <= kMinVolume + 1) {
|
||||
if (vol <= kMinVolume + kVolumeStep) {
|
||||
SetVolume(0);
|
||||
} else {
|
||||
SetVolume(GetVolume() - 1);
|
||||
SetVolume(vol - kVolumeStep);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -13,8 +13,8 @@ namespace input {
|
||||
|
||||
MediaButtons::MediaButtons(drivers::IGpios& gpios, audio::TrackQueue& queue)
|
||||
: gpios_(gpios),
|
||||
up_("upper", actions::nextTrack(queue), {}, {}, actions::volumeUp()),
|
||||
down_("lower", actions::prevTrack(queue), {}, {}, actions::volumeDown()),
|
||||
up_("upper", {}, actions::nextTrack(queue), {}, actions::volumeUp()),
|
||||
down_("lower", {}, actions::prevTrack(queue), {}, actions::volumeDown()),
|
||||
locked_(),
|
||||
both_buttons_pressed_(false) {}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "esp_log.h"
|
||||
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
|
||||
#include "drivers/spi.hpp"
|
||||
#include "ff.h"
|
||||
@@ -91,4 +92,64 @@ auto FileIterator::iterate(bool show_hidden) -> bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
FileIteratorSorted::FileIteratorSorted(std::string filepath, bool showHidden)
|
||||
: offset_(-1) {
|
||||
|
||||
FileIterator iter(filepath, showHidden);
|
||||
|
||||
while (true) {
|
||||
iter.next();
|
||||
std::optional<FileEntry> res = iter.value();
|
||||
if (res) {
|
||||
files_.push_back(*res);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
std::sort(files_.begin(), files_.end(),
|
||||
[](const auto& lhs, const auto& rhs) {
|
||||
if (lhs.isDirectory > rhs.isDirectory) {
|
||||
return true;
|
||||
} else if (lhs.isDirectory < rhs.isDirectory) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return lhs.name < rhs.name;
|
||||
});
|
||||
|
||||
// reindex the files
|
||||
for(size_t i = 0; i != files_.size(); i++) {
|
||||
files_[i].index = i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
FileIteratorSorted::~FileIteratorSorted() {
|
||||
}
|
||||
|
||||
auto FileIteratorSorted::value() const -> const std::optional<FileEntry> {
|
||||
if (offset_ < 0 || offset_ >= files_.size()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
return std::optional(files_[offset_]);
|
||||
}
|
||||
|
||||
auto FileIteratorSorted::next() -> void {
|
||||
if (offset_ < (int) files_.size()) {
|
||||
offset_++;
|
||||
}
|
||||
}
|
||||
|
||||
auto FileIteratorSorted::prev() -> void {
|
||||
if (offset_ <= 0) {
|
||||
offset_ = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
offset_--;
|
||||
}
|
||||
|
||||
|
||||
} // namespace lua
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
#include "ff.h"
|
||||
|
||||
@@ -43,4 +44,18 @@ class FileIterator {
|
||||
auto iterate(bool reverse = false) -> bool;
|
||||
};
|
||||
|
||||
class FileIteratorSorted {
|
||||
public:
|
||||
FileIteratorSorted(std::string filepath, bool showHidden);
|
||||
~FileIteratorSorted();
|
||||
|
||||
auto value() const -> const std::optional<FileEntry>;
|
||||
auto next() -> void;
|
||||
auto prev() -> void;
|
||||
|
||||
private:
|
||||
std::vector<FileEntry> files_;
|
||||
int offset_;
|
||||
};
|
||||
|
||||
} // namespace lua
|
||||
|
||||
@@ -38,22 +38,22 @@ auto check_file_entry(lua_State* L, int stack_pos) -> lua::FileEntry* {
|
||||
return entry;
|
||||
}
|
||||
|
||||
auto check_file_iterator(lua_State* L, int stack_pos) -> lua::FileIterator* {
|
||||
lua::FileIterator* it = *reinterpret_cast<lua::FileIterator**>(
|
||||
auto check_file_iterator(lua_State* L, int stack_pos) -> lua::FileIteratorSorted* {
|
||||
lua::FileIteratorSorted* it = *reinterpret_cast<lua::FileIteratorSorted**>(
|
||||
luaL_checkudata(L, stack_pos, kFileIteratorMetatable));
|
||||
return it;
|
||||
}
|
||||
|
||||
static auto push_iterator(lua_State* state, const lua::FileIterator& it)
|
||||
static auto push_iterator(lua_State* state, const lua::FileIteratorSorted& it)
|
||||
-> void {
|
||||
lua::FileIterator** data = reinterpret_cast<lua::FileIterator**>(
|
||||
lua::FileIteratorSorted** data = reinterpret_cast<lua::FileIteratorSorted**>(
|
||||
lua_newuserdata(state, sizeof(uintptr_t)));
|
||||
*data = new lua::FileIterator(it);
|
||||
*data = new lua::FileIteratorSorted(it);
|
||||
luaL_setmetatable(state, kFileIteratorMetatable);
|
||||
}
|
||||
|
||||
static auto fs_iterate_prev(lua_State* state) -> int {
|
||||
lua::FileIterator* it = check_file_iterator(state, 1);
|
||||
lua::FileIteratorSorted* it = check_file_iterator(state, 1);
|
||||
it->prev();
|
||||
std::optional<lua::FileEntry> res = it->value();
|
||||
|
||||
@@ -67,7 +67,7 @@ static auto fs_iterate_prev(lua_State* state) -> int {
|
||||
}
|
||||
|
||||
static auto fs_iterate(lua_State* state) -> int {
|
||||
lua::FileIterator* it = check_file_iterator(state, 1);
|
||||
lua::FileIteratorSorted* it = check_file_iterator(state, 1);
|
||||
it->next();
|
||||
std::optional<lua::FileEntry> res = it->value();
|
||||
|
||||
@@ -81,13 +81,13 @@ static auto fs_iterate(lua_State* state) -> int {
|
||||
}
|
||||
|
||||
static auto fs_iterator_clone(lua_State* state) -> int {
|
||||
lua::FileIterator* it = check_file_iterator(state, 1);
|
||||
lua::FileIteratorSorted* it = check_file_iterator(state, 1);
|
||||
push_iterator(state, *it);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static auto fs_iterator_value(lua_State* state) -> int {
|
||||
lua::FileIterator* it = check_file_iterator(state, 1);
|
||||
lua::FileIteratorSorted* it = check_file_iterator(state, 1);
|
||||
std::optional<lua::FileEntry> res = it->value();
|
||||
|
||||
if (res) {
|
||||
@@ -100,7 +100,7 @@ static auto fs_iterator_value(lua_State* state) -> int {
|
||||
}
|
||||
|
||||
static auto fs_iterator_gc(lua_State* state) -> int {
|
||||
lua::FileIterator* it = check_file_iterator(state, 1);
|
||||
lua::FileIteratorSorted* it = check_file_iterator(state, 1);
|
||||
delete it;
|
||||
return 0;
|
||||
}
|
||||
@@ -155,7 +155,7 @@ static auto fs_new_iterator(lua_State* state) -> int {
|
||||
// Takes a filepath as a string and returns a new FileIterator
|
||||
// on that directory
|
||||
std::string filepath = luaL_checkstring(state, -1);
|
||||
lua::FileIterator iter(filepath, false);
|
||||
lua::FileIteratorSorted iter(filepath, false);
|
||||
push_iterator(state, iter);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
namespace lua {
|
||||
|
||||
auto check_file_iterator(lua_State*, int stack_pos) -> lua::FileIterator*;
|
||||
auto check_file_iterator(lua_State*, int stack_pos) -> lua::FileIteratorSorted*;
|
||||
|
||||
auto RegisterFileSystemModule(lua_State*) -> void;
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ Screen::Screen()
|
||||
|
||||
// Disable wrapping by default, since it's confusing and generally makes it
|
||||
// harder to navigate quickly.
|
||||
lv_group_set_wrap(group_, false);
|
||||
lv_group_set_wrap(group_, true); // CUSTOMIZE: enabled - https://codeberg.org/cool-tech-zone/tangara-fw/issues/222
|
||||
}
|
||||
|
||||
Screen::~Screen() {
|
||||
|
||||
Reference in New Issue
Block a user