blackmagic-esp32-s2/main/cli-commands.c

67 lines
1.4 KiB
C
Raw Normal View History

2021-12-01 04:15:45 +00:00
#include <stdlib.h>
#include <stdint.h>
2021-12-01 13:01:52 +00:00
#include <esp_mac.h>
2021-12-01 04:15:45 +00:00
#include "cli.h"
2021-12-01 13:01:52 +00:00
#include "cli-args.h"
2021-12-01 04:15:45 +00:00
#include "cli-commands.h"
#include "helpers.h"
2021-12-01 13:01:52 +00:00
void cli_id(Cli* cli, mstring_t* args);
2021-12-01 04:15:45 +00:00
void cli_help(Cli* cli, mstring_t* args);
2021-12-01 13:01:52 +00:00
void cli_version(Cli* cli, mstring_t* args);
void cli_gpio_set(Cli* cli, mstring_t* args);
2021-12-01 04:15:45 +00:00
const CliItem cli_items[] = {
2021-12-01 04:32:52 +00:00
{
.name = "?",
.callback = cli_help,
},
2021-12-01 13:01:52 +00:00
{
.name = "id",
.callback = cli_id,
},
2021-12-01 04:15:45 +00:00
{
.name = "help",
.callback = cli_help,
},
2021-12-01 13:01:52 +00:00
{
.name = "version",
.callback = cli_version,
},
{
.name = "gpio_set",
.callback = cli_gpio_set,
},
2021-12-01 04:15:45 +00:00
};
size_t cli_items_count = COUNT_OF(cli_items);
void cli_help(Cli* cli, mstring_t* args) {
for(size_t i = 0; i < cli_items_count; i++) {
cli_write_str(cli, cli_items[i].name);
2021-12-01 04:32:52 +00:00
if((i + 1) < cli_items_count) {
cli_write_eol(cli);
}
2021-12-01 04:15:45 +00:00
}
2021-12-01 13:01:52 +00:00
}
void cli_id(Cli* cli, mstring_t* args) {
uint8_t mac_addr[6] = {0};
ESP_ERROR_CHECK(esp_read_mac(mac_addr, ESP_MAC_WIFI_STA));
cli_printf(
cli,
"%02X%02X%02X%02X%02X%02X",
mac_addr[0],
mac_addr[1],
mac_addr[2],
mac_addr[3],
mac_addr[4],
mac_addr[5]);
}
void cli_version(Cli* cli, mstring_t* args) {
cli_printf(cli, "IDF version: %s", IDF_VER);
cli_write_eol(cli);
cli_printf(cli, "FW version: %s", "0.1");
2021-12-01 04:15:45 +00:00
}