summaryrefslogtreecommitdiff
path: root/src/main/app_console.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/app_console.cpp')
-rw-r--r--src/main/app_console.cpp54
1 files changed, 53 insertions, 1 deletions
diff --git a/src/main/app_console.cpp b/src/main/app_console.cpp
index 40159f4e..859700f4 100644
--- a/src/main/app_console.cpp
+++ b/src/main/app_console.cpp
@@ -9,7 +9,9 @@
#include <string>
#include "audio_playback.hpp"
+#include "database.hpp"
#include "esp_console.h"
+#include "esp_log.h"
namespace console {
@@ -145,7 +147,55 @@ void RegisterAudioStatus() {
esp_console_cmd_register(&cmd);
}
-AppConsole::AppConsole(audio::AudioPlayback* playback) : playback_(playback) {
+int CmdDbInit(int argc, char** argv) {
+ static const std::string usage = "usage: db_init";
+ if (argc != 1) {
+ std::cout << usage << std::endl;
+ return 1;
+ }
+
+ sInstance->database_->Initialise();
+
+ return 0;
+}
+
+void RegisterDbInit() {
+ esp_console_cmd_t cmd{.command = "db_init",
+ .help = "scans for playable files and adds them to the database",
+ .hint = NULL,
+ .func = &CmdDbInit,
+ .argtable = NULL};
+ esp_console_cmd_register(&cmd);
+}
+
+int CmdDbTitles(int argc, char** argv) {
+ static const std::string usage = "usage: db_titles";
+ if (argc != 1) {
+ std::cout << usage << std::endl;
+ return 1;
+ }
+
+ database::Iterator it = sInstance->database_->ByTitle();
+ while (true) {
+ std::optional<std::string> title = it.Next();
+ if (!title) {
+ break;
+ }
+ std::cout << *title << std::endl;
+ }
+ return 0;
+}
+
+void RegisterDbTitles() {
+ esp_console_cmd_t cmd{.command = "db_titles",
+ .help = "lists titles of ALL songs in the database",
+ .hint = NULL,
+ .func = &CmdDbTitles,
+ .argtable = NULL};
+ esp_console_cmd_register(&cmd);
+}
+
+AppConsole::AppConsole(audio::AudioPlayback* playback, database::Database *database) : playback_(playback), database_(database) {
sInstance = this;
}
AppConsole::~AppConsole() {
@@ -158,6 +208,8 @@ auto AppConsole::RegisterExtraComponents() -> void {
RegisterToggle();
RegisterVolume();
RegisterAudioStatus();
+ RegisterDbInit();
+ RegisterDbTitles();
}
} // namespace console