summaryrefslogtreecommitdiff
path: root/src/app_console/app_console.cpp
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2023-06-16 13:14:45 +1000
committerjacqueline <me@jacqueline.id.au>2023-06-16 13:14:45 +1000
commit5b7b88420b169d1dfdeea6d082762fccefbc7d49 (patch)
treee5bc4a44088a9ac62e1628ffa3265f4819c3c979 /src/app_console/app_console.cpp
parentc6bb42cdd21b63accd20012373a8a0e41d8566f5 (diff)
downloadtangara-fw-5b7b88420b169d1dfdeea6d082762fccefbc7d49.tar.gz
Fix issues with importing my entire library
Diffstat (limited to 'src/app_console/app_console.cpp')
-rw-r--r--src/app_console/app_console.cpp61
1 files changed, 35 insertions, 26 deletions
diff --git a/src/app_console/app_console.cpp b/src/app_console/app_console.cpp
index 457d66f6..81a49e99 100644
--- a/src/app_console/app_console.cpp
+++ b/src/app_console/app_console.cpp
@@ -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 = "";
+ }
+
+ 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;
}
- DIR* dir;
- struct dirent* ent;
- dir = opendir(path.c_str());
- while ((ent = readdir(dir))) {
- std::cout << ent->d_name << std::endl;
+ 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;
+ }
}
- closedir(dir);
+
+ 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();