Fix issues with importing my entire library
This commit is contained in:
@@ -20,14 +20,11 @@
|
||||
#include "esp_console.h"
|
||||
#include "esp_log.h"
|
||||
#include "event_queue.hpp"
|
||||
#include "ff.h"
|
||||
|
||||
namespace console {
|
||||
|
||||
static AppConsole* sInstance = nullptr;
|
||||
|
||||
std::string toSdPath(const std::string& filepath) {
|
||||
return std::string("/") + filepath;
|
||||
}
|
||||
std::weak_ptr<database::Database> AppConsole::sDatabase;
|
||||
|
||||
int CmdListDir(int argc, char** argv) {
|
||||
static const std::string usage = "usage: ls [directory]";
|
||||
@@ -36,7 +33,7 @@ int CmdListDir(int argc, char** argv) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
auto lock = sInstance->database_.lock();
|
||||
auto lock = AppConsole::sDatabase.lock();
|
||||
if (lock == nullptr) {
|
||||
std::cout << "storage is not available" << std::endl;
|
||||
return 1;
|
||||
@@ -44,18 +41,38 @@ int CmdListDir(int argc, char** argv) {
|
||||
|
||||
std::string path;
|
||||
if (argc == 2) {
|
||||
path = toSdPath(argv[1]);
|
||||
path = argv[1];
|
||||
} else {
|
||||
path = toSdPath("");
|
||||
path = "";
|
||||
}
|
||||
|
||||
DIR* dir;
|
||||
struct dirent* ent;
|
||||
dir = opendir(path.c_str());
|
||||
while ((ent = readdir(dir))) {
|
||||
std::cout << ent->d_name << std::endl;
|
||||
FF_DIR dir;
|
||||
FRESULT res = f_opendir(&dir, path.c_str());
|
||||
if (res != FR_OK) {
|
||||
std::cout << "failed to open directory. does it exist?" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
closedir(dir);
|
||||
|
||||
for (;;) {
|
||||
FILINFO info;
|
||||
res = f_readdir(&dir, &info);
|
||||
if (res != FR_OK || info.fname[0] == 0) {
|
||||
// No more files in the directory.
|
||||
break;
|
||||
} else {
|
||||
std::cout << path;
|
||||
if (!path.ends_with('/') && !path.empty()) {
|
||||
std::cout << '/';
|
||||
}
|
||||
std::cout << info.fname;
|
||||
if (info.fattrib & AM_DIR) {
|
||||
std::cout << '/';
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
f_closedir(&dir);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -101,7 +118,7 @@ int CmdDbInit(int argc, char** argv) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
auto db = sInstance->database_.lock();
|
||||
auto db = AppConsole::sDatabase.lock();
|
||||
if (!db) {
|
||||
std::cout << "no database open" << std::endl;
|
||||
return 1;
|
||||
@@ -128,13 +145,13 @@ int CmdDbTracks(int argc, char** argv) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
auto db = sInstance->database_.lock();
|
||||
auto db = AppConsole::sDatabase.lock();
|
||||
if (!db) {
|
||||
std::cout << "no database open" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
std::unique_ptr<database::Result<database::Track>> res(
|
||||
db->GetTracks(5).get());
|
||||
db->GetTracks(20).get());
|
||||
while (true) {
|
||||
for (database::Track s : res->values()) {
|
||||
std::cout << s.tags().title.value_or("[BLANK]") << std::endl;
|
||||
@@ -166,7 +183,7 @@ int CmdDbDump(int argc, char** argv) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
auto db = sInstance->database_.lock();
|
||||
auto db = AppConsole::sDatabase.lock();
|
||||
if (!db) {
|
||||
std::cout << "no database open" << std::endl;
|
||||
return 1;
|
||||
@@ -201,14 +218,6 @@ void RegisterDbDump() {
|
||||
esp_console_cmd_register(&cmd);
|
||||
}
|
||||
|
||||
AppConsole::AppConsole(const std::weak_ptr<database::Database>& database)
|
||||
: database_(database) {
|
||||
sInstance = this;
|
||||
}
|
||||
AppConsole::~AppConsole() {
|
||||
sInstance = nullptr;
|
||||
}
|
||||
|
||||
auto AppConsole::RegisterExtraComponents() -> void {
|
||||
RegisterListDir();
|
||||
RegisterPlayFile();
|
||||
|
||||
@@ -15,10 +15,7 @@ namespace console {
|
||||
|
||||
class AppConsole : public Console {
|
||||
public:
|
||||
explicit AppConsole(const std::weak_ptr<database::Database>& database);
|
||||
virtual ~AppConsole();
|
||||
|
||||
const std::weak_ptr<database::Database>& database_;
|
||||
static std::weak_ptr<database::Database> sDatabase;
|
||||
|
||||
protected:
|
||||
virtual auto RegisterExtraComponents() -> void;
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
#include "esp_log.h"
|
||||
#include "ff.h"
|
||||
#include "freertos/projdefs.h"
|
||||
#include "leveldb/cache.h"
|
||||
#include "leveldb/db.h"
|
||||
#include "leveldb/iterator.h"
|
||||
@@ -68,12 +69,13 @@ auto Database::Open(IFileGatherer* gatherer, ITagParser* parser)
|
||||
return cpp::fail(DatabaseError::ALREADY_OPEN);
|
||||
}
|
||||
|
||||
leveldb::sBackgroundThread.reset(
|
||||
tasks::Worker::Start<tasks::Type::kDatabaseBackground>());
|
||||
std::shared_ptr<tasks::Worker> worker(
|
||||
tasks::Worker::Start<tasks::Type::kDatabase>());
|
||||
leveldb::sBackgroundThread = std::weak_ptr<tasks::Worker>(worker);
|
||||
return worker
|
||||
->Dispatch<cpp::result<Database*, DatabaseError>>(
|
||||
[&]() -> cpp::result<Database*, DatabaseError> {
|
||||
[=]() -> cpp::result<Database*, DatabaseError> {
|
||||
leveldb::DB* db;
|
||||
leveldb::Cache* cache = leveldb::NewLRUCache(24 * 1024);
|
||||
leveldb::Options options;
|
||||
@@ -121,7 +123,7 @@ Database::~Database() {
|
||||
delete db_;
|
||||
delete cache_;
|
||||
|
||||
leveldb::sBackgroundThread = std::weak_ptr<tasks::Worker>();
|
||||
leveldb::sBackgroundThread.reset();
|
||||
|
||||
sIsDbOpen.store(false);
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include <cstring>
|
||||
#include <functional>
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <queue>
|
||||
#include <set>
|
||||
@@ -39,7 +40,7 @@
|
||||
|
||||
namespace leveldb {
|
||||
|
||||
std::weak_ptr<tasks::Worker> sBackgroundThread;
|
||||
std::shared_ptr<tasks::Worker> sBackgroundThread;
|
||||
|
||||
std::string ErrToStr(FRESULT err) {
|
||||
switch (err) {
|
||||
@@ -463,7 +464,7 @@ EspEnv::EspEnv() {}
|
||||
void EspEnv::Schedule(
|
||||
void (*background_work_function)(void* background_work_arg),
|
||||
void* background_work_arg) {
|
||||
auto worker = sBackgroundThread.lock();
|
||||
auto worker = sBackgroundThread;
|
||||
if (worker) {
|
||||
worker->Dispatch<void>(
|
||||
[=]() { std::invoke(background_work_function, background_work_arg); });
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
namespace leveldb {
|
||||
|
||||
extern std::weak_ptr<tasks::Worker> sBackgroundThread;
|
||||
extern std::shared_ptr<tasks::Worker> sBackgroundThread;
|
||||
|
||||
// Tracks the files locked by EspEnv::LockFile().
|
||||
//
|
||||
|
||||
@@ -73,6 +73,12 @@ static const char* kTag = "TAGS";
|
||||
|
||||
auto TagParserImpl::ReadAndParseTags(const std::string& path, TrackTags* out)
|
||||
-> bool {
|
||||
if (path.ends_with(".m4a")) {
|
||||
// TODO(jacqueline): Re-enabled once libtags is fixed.
|
||||
ESP_LOGW(kTag, "skipping m4a %s", path.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
libtags::Aux aux;
|
||||
aux.tags = out;
|
||||
if (f_stat(path.c_str(), &aux.info) != FR_OK ||
|
||||
|
||||
@@ -38,7 +38,7 @@ Samd::Samd() {
|
||||
.read(&raw_res, I2C_MASTER_NACK)
|
||||
.stop();
|
||||
ESP_LOGI(kTag, "checking samd firmware rev");
|
||||
ESP_ERROR_CHECK(transaction.Execute());
|
||||
transaction.Execute();
|
||||
ESP_LOGI(kTag, "samd firmware: %u", raw_res);
|
||||
}
|
||||
Samd::~Samd() {}
|
||||
@@ -53,7 +53,7 @@ auto Samd::ReadChargeStatus() -> std::optional<ChargeStatus> {
|
||||
.read(&raw_res, I2C_MASTER_NACK)
|
||||
.stop();
|
||||
ESP_LOGI(kTag, "checking charge status");
|
||||
ESP_ERROR_CHECK(transaction.Execute());
|
||||
transaction.Execute();
|
||||
ESP_LOGI(kTag, "raw charge status: %x", raw_res);
|
||||
|
||||
uint8_t usb_state = raw_res & 0b11;
|
||||
@@ -83,7 +83,7 @@ auto Samd::WriteAllowUsbMsc(bool is_allowed) -> void {
|
||||
.write_addr(kAddress, I2C_MASTER_WRITE)
|
||||
.write_ack(kRegisterUsbMsc, is_allowed)
|
||||
.stop();
|
||||
ESP_ERROR_CHECK(transaction.Execute());
|
||||
transaction.Execute();
|
||||
}
|
||||
|
||||
auto Samd::ReadUsbMscStatus() -> UsbMscStatus {
|
||||
|
||||
@@ -65,7 +65,7 @@ void TouchWheel::WriteRegister(uint8_t reg, uint8_t val) {
|
||||
.write_addr(kTouchWheelAddress, I2C_MASTER_WRITE)
|
||||
.write_ack(reg, val)
|
||||
.stop();
|
||||
ESP_ERROR_CHECK(transaction.Execute());
|
||||
transaction.Execute();
|
||||
}
|
||||
|
||||
uint8_t TouchWheel::ReadRegister(uint8_t reg) {
|
||||
@@ -78,7 +78,7 @@ uint8_t TouchWheel::ReadRegister(uint8_t reg) {
|
||||
.write_addr(kTouchWheelAddress, I2C_MASTER_READ)
|
||||
.read(&res, I2C_MASTER_NACK)
|
||||
.stop();
|
||||
ESP_ERROR_CHECK(transaction.Execute());
|
||||
transaction.Execute();
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,8 +27,6 @@ namespace states {
|
||||
|
||||
static const char kTag[] = "BOOT";
|
||||
|
||||
console::AppConsole* Booting::sAppConsole;
|
||||
|
||||
auto Booting::entry() -> void {
|
||||
ESP_LOGI(kTag, "beginning tangara boot");
|
||||
ESP_LOGI(kTag, "installing early drivers");
|
||||
@@ -78,7 +76,7 @@ auto Booting::entry() -> void {
|
||||
|
||||
auto Booting::exit() -> void {
|
||||
// TODO(jacqueline): Gate this on something. Debug flag? Flashing mode?
|
||||
sAppConsole = new console::AppConsole(sDatabase);
|
||||
sAppConsole = new console::AppConsole();
|
||||
sAppConsole->Launch();
|
||||
}
|
||||
|
||||
|
||||
@@ -56,6 +56,8 @@ class SystemState : public tinyfsm::Fsm<SystemState> {
|
||||
static std::shared_ptr<drivers::SdStorage> sStorage;
|
||||
static std::shared_ptr<drivers::Display> sDisplay;
|
||||
static std::shared_ptr<database::Database> sDatabase;
|
||||
|
||||
static console::AppConsole* sAppConsole;
|
||||
};
|
||||
|
||||
namespace states {
|
||||
@@ -65,9 +67,6 @@ namespace states {
|
||||
* looks good.
|
||||
*/
|
||||
class Booting : public SystemState {
|
||||
private:
|
||||
static console::AppConsole* sAppConsole;
|
||||
|
||||
public:
|
||||
void entry() override;
|
||||
void exit() override;
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: GPL-3.0-only
|
||||
*/
|
||||
|
||||
#include "app_console.hpp"
|
||||
#include "freertos/projdefs.h"
|
||||
#include "result.hpp"
|
||||
|
||||
@@ -28,6 +29,7 @@ void Running::entry() {
|
||||
vTaskDelay(pdMS_TO_TICKS(250));
|
||||
auto storage_res = drivers::SdStorage::Create(sGpioExpander.get());
|
||||
if (storage_res.has_error()) {
|
||||
ESP_LOGW(kTag, "failed to mount!");
|
||||
events::Dispatch<StorageError, SystemState, audio::AudioState, ui::UiState>(
|
||||
StorageError());
|
||||
return;
|
||||
@@ -38,11 +40,13 @@ void Running::entry() {
|
||||
ESP_LOGI(kTag, "opening database");
|
||||
auto database_res = database::Database::Open();
|
||||
if (database_res.has_error()) {
|
||||
ESP_LOGW(kTag, "failed to open!");
|
||||
events::Dispatch<StorageError, SystemState, audio::AudioState, ui::UiState>(
|
||||
StorageError());
|
||||
return;
|
||||
}
|
||||
sDatabase.reset(database_res.value());
|
||||
console::AppConsole::sDatabase = sDatabase;
|
||||
|
||||
ESP_LOGI(kTag, "storage loaded okay");
|
||||
events::Dispatch<StorageMounted, SystemState, audio::AudioState, ui::UiState>(
|
||||
|
||||
@@ -20,6 +20,8 @@ std::shared_ptr<drivers::SdStorage> SystemState::sStorage;
|
||||
std::shared_ptr<drivers::Display> SystemState::sDisplay;
|
||||
std::shared_ptr<database::Database> SystemState::sDatabase;
|
||||
|
||||
console::AppConsole* SystemState::sAppConsole;
|
||||
|
||||
void SystemState::react(const FatalError& err) {
|
||||
if (!is_in_state<states::Error>()) {
|
||||
transit<states::Error>();
|
||||
|
||||
+21
-1
@@ -5,7 +5,9 @@
|
||||
*/
|
||||
|
||||
#include "tasks.hpp"
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include "esp_heap_caps.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/portmacro.h"
|
||||
@@ -31,6 +33,10 @@ template <>
|
||||
auto Name<Type::kDatabase>() -> std::string {
|
||||
return "DB";
|
||||
}
|
||||
template <>
|
||||
auto Name<Type::kDatabaseBackground>() -> std::string {
|
||||
return "DB_BG";
|
||||
}
|
||||
|
||||
template <Type t>
|
||||
auto AllocateStack() -> cpp::span<StackType_t>;
|
||||
@@ -39,7 +45,7 @@ auto AllocateStack() -> cpp::span<StackType_t>;
|
||||
// amount of stack space.
|
||||
template <>
|
||||
auto AllocateStack<Type::kAudio>() -> cpp::span<StackType_t> {
|
||||
std::size_t size = 48 * 1024;
|
||||
std::size_t size = 32 * 1024;
|
||||
return {static_cast<StackType_t*>(heap_caps_malloc(size, MALLOC_CAP_DEFAULT)),
|
||||
size};
|
||||
}
|
||||
@@ -67,6 +73,12 @@ auto AllocateStack<Type::kDatabase>() -> cpp::span<StackType_t> {
|
||||
return {static_cast<StackType_t*>(heap_caps_malloc(size, MALLOC_CAP_SPIRAM)),
|
||||
size};
|
||||
}
|
||||
template <>
|
||||
auto AllocateStack<Type::kDatabaseBackground>() -> cpp::span<StackType_t> {
|
||||
std::size_t size = 256 * 1024;
|
||||
return {static_cast<StackType_t*>(heap_caps_malloc(size, MALLOC_CAP_SPIRAM)),
|
||||
size};
|
||||
}
|
||||
|
||||
// 2048 bytes in internal ram
|
||||
// 302 KiB in external ram.
|
||||
@@ -106,6 +118,10 @@ template <>
|
||||
auto Priority<Type::kDatabase>() -> UBaseType_t {
|
||||
return 8;
|
||||
}
|
||||
template <>
|
||||
auto Priority<Type::kDatabaseBackground>() -> UBaseType_t {
|
||||
return 7;
|
||||
}
|
||||
|
||||
template <Type t>
|
||||
auto WorkerQueueSize() -> std::size_t;
|
||||
@@ -114,6 +130,10 @@ template <>
|
||||
auto WorkerQueueSize<Type::kDatabase>() -> std::size_t {
|
||||
return 8;
|
||||
}
|
||||
template <>
|
||||
auto WorkerQueueSize<Type::kDatabaseBackground>() -> std::size_t {
|
||||
return 8;
|
||||
}
|
||||
|
||||
template <>
|
||||
auto WorkerQueueSize<Type::kUiFlush>() -> std::size_t {
|
||||
|
||||
@@ -36,6 +36,8 @@ enum class Type {
|
||||
kAudio,
|
||||
// Task for running database queries.
|
||||
kDatabase,
|
||||
// Task for internal database operations
|
||||
kDatabaseBackground,
|
||||
};
|
||||
|
||||
template <Type t>
|
||||
@@ -102,6 +104,9 @@ class Worker {
|
||||
}
|
||||
|
||||
~Worker();
|
||||
|
||||
Worker(const Worker&) = delete;
|
||||
Worker& operator=(const Worker&) = delete;
|
||||
};
|
||||
|
||||
/* Specialisation of Evaluate for functions that return nothing. */
|
||||
|
||||
Reference in New Issue
Block a user