DualLedController/components/command/CustomCommand.cpp

54 lines
1.4 KiB
C++
Raw Normal View History

2024-05-17 01:08:15 +08:00
#include "CustomCommand.h"
#include "LedController.h"
2024-05-22 23:07:24 +08:00
#include "MqttClient.h"
2024-05-17 01:08:15 +08:00
#include "esp_console.h"
#include <iostream>
static int custom_command(int argc, char **argv) {
printf("i am amass.\n");
return 0;
}
static int led_command(int argc, char **argv) {
for (int i = 0; i < argc; i++) {
std::cout << i << " " << argv[i] << std::endl;
}
LedController::instance()->setDuty(atoi(argv[1]), atoi(argv[2]));
return 0;
}
2024-05-22 23:07:24 +08:00
static int mqtt_command(int argc, char **argv) {
MqttClient::instance()->initialize(argv[1], argv[2]);
return 0;
}
2024-05-17 01:08:15 +08:00
void register_custom() {
const esp_console_cmd_t heap_cmd = {
.command = "amass",
.help = "test command.",
.hint = NULL,
.func = &custom_command,
2024-05-22 23:07:24 +08:00
.argtable = nullptr,
2024-05-17 01:08:15 +08:00
};
ESP_ERROR_CHECK(esp_console_cmd_register(&heap_cmd));
const esp_console_cmd_t led_cmd = {
.command = "led",
.help = "led pwm duty.",
.hint = NULL,
.func = &led_command,
2024-05-22 23:07:24 +08:00
.argtable = nullptr,
2024-05-17 01:08:15 +08:00
};
ESP_ERROR_CHECK(esp_console_cmd_register(&led_cmd));
2024-05-22 23:07:24 +08:00
const esp_console_cmd_t mqtt_cmd = {
.command = "mqtt",
.help = "mqtt client.",
.hint = NULL,
.func = &mqtt_command,
.argtable = nullptr,
};
ESP_ERROR_CHECK(esp_console_cmd_register(&mqtt_cmd));
2024-05-17 01:08:15 +08:00
}