summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRobin Howard <robin@rhoward.id.au>2023-11-07 15:47:48 +1100
committerRobin Howard <robin@rhoward.id.au>2023-11-07 16:31:55 +1100
commit606e4d89ec74740f955b5926b7596c28e514901e (patch)
tree44fa4dcbc8bc91bcf5bcee03d68cf2a3da50ac2f /src
parent7318f53fd8949d8625f498ccb2dd07e501e658b2 (diff)
downloadtangara-fw-606e4d89ec74740f955b5926b7596c28e514901e.tar.gz
haptics: adds a "haptic_effect" console command
... which can take multiple optional arguments for ranges of effects and/or a motor library.
Diffstat (limited to 'src')
-rw-r--r--src/app_console/app_console.cpp71
1 files changed, 71 insertions, 0 deletions
diff --git a/src/app_console/app_console.cpp b/src/app_console/app_console.cpp
index 7af484aa..28fac182 100644
--- a/src/app_console/app_console.cpp
+++ b/src/app_console/app_console.cpp
@@ -35,9 +35,11 @@
#include "ff.h"
#include "freertos/FreeRTOSConfig_arch.h"
#include "freertos/projdefs.h"
+#include "haptics.hpp"
#include "index.hpp"
#include "memory_resource.hpp"
#include "service_locator.hpp"
+#include "system_events.hpp"
#include "track.hpp"
namespace console {
@@ -646,6 +648,73 @@ void RegisterCoreDump() {
esp_console_cmd_register(&cmd);
}
+int CmdHaptics(int argc, char** argv) {
+ static const std::pmr::string usage =
+ "There are 123 waveform effects, and 5 'libraries' (motor types);\n"
+ "see the DRV2624 datasheet for more details.\n\n"
+ "Usages:\n"
+ " haptic_effect\n"
+ " haptic_effect library\n"
+ " haptic_effect from-effect to-effect\n"
+ " haptic_effect from-effect to-effect library\n"
+ "eg.\n"
+ " haptic_effect (plays from 1 to 123 with the default library)\n"
+ " haptic_effect 3 (plays from 1 to 123 with library 3\n"
+ " haptic_effect 1 100 (plays from 1 to 100 with the default library)\n"
+ " haptic_effect 1 10 4 (plays from 1 to 10 with library 4)";
+
+ auto& haptics = AppConsole::sServices->haptics();
+
+ if (argc == 1) {
+ haptics.TourEffects();
+
+ } else if (argc == 2 && argv[1] != std::string{"help"}) {
+ std::istringstream raw_library_id{argv[1]};
+ int library_id = 0;
+ raw_library_id >> library_id;
+
+ haptics.TourEffects(static_cast<drivers::Haptics::Library>(library_id));
+
+ } else if (argc == 3) {
+ std::istringstream raw_effect_from_id{argv[1]};
+ std::istringstream raw_effect_to_id{argv[2]};
+ int effect_from_id, effect_to_id = 0;
+ raw_effect_from_id >> effect_from_id;
+ raw_effect_to_id >> effect_to_id;
+
+ haptics.TourEffects(static_cast<drivers::Haptics::Effect>(effect_from_id),
+ static_cast<drivers::Haptics::Effect>(effect_to_id));
+
+ } else if (argc == 4) {
+ std::istringstream raw_effect_from_id{argv[1]};
+ std::istringstream raw_effect_to_id{argv[2]};
+ std::istringstream raw_library_id{argv[3]};
+ int effect_from_id, effect_to_id, library_id = 0;
+ raw_effect_from_id >> effect_from_id;
+ raw_effect_to_id >> effect_to_id;
+ raw_library_id >> library_id;
+
+ haptics.TourEffects(static_cast<drivers::Haptics::Effect>(effect_from_id),
+ static_cast<drivers::Haptics::Effect>(effect_to_id),
+ static_cast<drivers::Haptics::Library>(library_id));
+ } else {
+ std::cout << usage << std::endl;
+ return 1;
+ }
+ return 0;
+}
+
+void RegisterHapticEffect() {
+ esp_console_cmd_t cmd{
+ .command = "haptic_effect",
+ .help =
+ "Plays one, a range of, or all effects from a DRV2624 effect library; run 'haptic_effect help' for more.",
+ .hint = NULL,
+ .func = &CmdHaptics,
+ .argtable = NULL};
+ esp_console_cmd_register(&cmd);
+}
+
auto AppConsole::RegisterExtraComponents() -> void {
RegisterListDir();
RegisterPlayFile();
@@ -669,6 +738,8 @@ auto AppConsole::RegisterExtraComponents() -> void {
RegisterBtList();
RegisterSamd();
RegisterCoreDump();
+
+ RegisterHapticEffect();
}
} // namespace console