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.cpp56
1 files changed, 46 insertions, 10 deletions
diff --git a/src/main/app_console.cpp b/src/main/app_console.cpp
index 613d5a9a..d032a631 100644
--- a/src/main/app_console.cpp
+++ b/src/main/app_console.cpp
@@ -1,7 +1,9 @@
#include "app_console.hpp"
#include <dirent.h>
+#include <cstdint>
#include <cstdio>
+#include <cstdlib>
#include <iostream>
#include <string>
#include "esp_console.h"
@@ -10,16 +12,22 @@ namespace console {
static AppConsole* sInstance = nullptr;
+std::string toSdPath(std::string filepath) {
+ return std::string(drivers::kStoragePath) + "/" + filepath;
+}
+
int CmdListDir(int argc, char** argv) {
static const std::string usage = "usage: ls [directory]";
if (argc > 2) {
std::cout << usage << std::endl;
return 1;
}
- std::string path = drivers::kStoragePath;
+
+ std::string path;
if (argc == 2) {
- path += "/";
- path += argv[1];
+ path = toSdPath(argv[1]);
+ } else {
+ path = toSdPath("");
}
DIR* dir;
@@ -44,15 +52,15 @@ void RegisterListDir() {
int CmdPlayFile(int argc, char** argv) {
static const std::string usage = "usage: play [file]";
- if (argc != 2) {
+ if (argc < 2 || argc > 3) {
std::cout << usage << std::endl;
return 1;
}
- std::string path = drivers::kStoragePath;
- path += "/";
- path += argv[1];
- sInstance->playback_->Play(path.c_str());
+ sInstance->playback_->Play(toSdPath(argv[1]));
+ if (argc == 3) {
+ sInstance->playback_->SetNextFile(toSdPath(argv[2]));
+ }
return 0;
}
@@ -87,8 +95,35 @@ void RegisterToggle() {
esp_console_cmd_register(&cmd);
}
-AppConsole::AppConsole(std::unique_ptr<drivers::AudioPlayback> playback)
- : playback_(std::move(playback)) {
+int CmdVolume(int argc, char** argv) {
+ static const std::string usage = "usage: volume [0-255]";
+ if (argc != 2) {
+ std::cout << usage << std::endl;
+ return 1;
+ }
+
+ long int raw_vol = strtol(argv[1], NULL, 10);
+ if (raw_vol < 0 || raw_vol > 255) {
+ std::cout << usage << std::endl;
+ return 1;
+ }
+
+ sInstance->playback_->SetVolume((uint8_t)raw_vol);
+
+ return 0;
+}
+
+void RegisterVolume() {
+ esp_console_cmd_t cmd{
+ .command = "vol",
+ .help = "Changes the volume (between 0 and 254. 255 is mute.)",
+ .hint = NULL,
+ .func = &CmdVolume,
+ .argtable = NULL};
+ esp_console_cmd_register(&cmd);
+}
+
+AppConsole::AppConsole(drivers::AudioPlayback* playback) : playback_(playback) {
sInstance = this;
}
AppConsole::~AppConsole() {
@@ -99,6 +134,7 @@ auto AppConsole::RegisterExtraComponents() -> void {
RegisterListDir();
RegisterPlayFile();
RegisterToggle();
+ RegisterVolume();
}
} // namespace console