|
|
|
@ -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; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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 << '/'; |
|
|
|
|
} |
|
|
|
|
closedir(dir); |
|
|
|
|
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(); |
|
|
|
|