chore: initial commit
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024-2026 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "control_plane_internal.h"
|
||||
esp_err_t control_plane_direction_calibrate_internal(
|
||||
const domain_direction_calibration_t *config,
|
||||
int timeout_ms)
|
||||
{
|
||||
return domain_calibrate_with_timeout(config, timeout_ms);
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "control_plane_internal.h"
|
||||
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
|
||||
static void trimmed_span(const char *input, const char **start_out, size_t *len_out)
|
||||
{
|
||||
const char *start = input;
|
||||
const char *end = NULL;
|
||||
|
||||
if (input == NULL) {
|
||||
*start_out = NULL;
|
||||
*len_out = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
while (*start != '\0' && isspace((unsigned char)*start)) {
|
||||
start++;
|
||||
}
|
||||
|
||||
end = start + strlen(start);
|
||||
while (end > start && isspace((unsigned char)*(end - 1))) {
|
||||
end--;
|
||||
}
|
||||
|
||||
*start_out = start;
|
||||
*len_out = (size_t)(end - start);
|
||||
}
|
||||
|
||||
static bool equals_trimmed(const char *input, const char *token, bool case_insensitive)
|
||||
{
|
||||
const char *start = NULL;
|
||||
size_t len = 0;
|
||||
size_t token_len = 0;
|
||||
|
||||
if (input == NULL || token == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
trimmed_span(input, &start, &len);
|
||||
token_len = strlen(token);
|
||||
if (len == 0 || len != token_len) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
char left = start[i];
|
||||
char right = token[i];
|
||||
|
||||
if (case_insensitive) {
|
||||
left = (char)tolower((unsigned char)left);
|
||||
right = (char)tolower((unsigned char)right);
|
||||
}
|
||||
|
||||
if (left != right) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
control_plane_direction_command_t control_plane_direction_parse_command_internal(
|
||||
const char *input,
|
||||
size_t *out_direction_index)
|
||||
{
|
||||
if (out_direction_index != NULL) {
|
||||
*out_direction_index = 0;
|
||||
}
|
||||
|
||||
if (equals_trimmed(input, "help", true) || equals_trimmed(input, "?", false)) {
|
||||
return CONTROL_PLANE_DIRECTION_CMD_HELP;
|
||||
}
|
||||
|
||||
if (equals_trimmed(input, "pos", true)) {
|
||||
return CONTROL_PLANE_DIRECTION_CMD_POSITION;
|
||||
}
|
||||
|
||||
if (equals_trimmed(input, "cal", true) ||
|
||||
equals_trimmed(input, "calibrate", true) ||
|
||||
equals_trimmed(input, "校准", false)) {
|
||||
return CONTROL_PLANE_DIRECTION_CMD_CALIBRATE;
|
||||
}
|
||||
|
||||
if (domain_find_direction_by_name(input, out_direction_index)) {
|
||||
return CONTROL_PLANE_DIRECTION_CMD_DIRECTION;
|
||||
}
|
||||
|
||||
return CONTROL_PLANE_DIRECTION_CMD_UNKNOWN;
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "control_plane.h"
|
||||
|
||||
#include "control_plane_internal.h"
|
||||
#define CONTROL_PLANE_ROTATE_TIMEOUT_MS 8000
|
||||
|
||||
static bool control_plane_is_initialized(void)
|
||||
{
|
||||
return domain_is_initialized();
|
||||
}
|
||||
|
||||
esp_err_t control_plane_init(void)
|
||||
{
|
||||
if (control_plane_is_initialized()) {
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
const domain_direction_axis_config_t *axis_config =
|
||||
domain_direction_default_axis_config();
|
||||
const domain_direction_calibration_t *calibration =
|
||||
domain_direction_default_calibration();
|
||||
|
||||
esp_err_t err = domain_init(axis_config, calibration);
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
control_plane_direction_command_t control_plane_parse_direction_command(const char *input,
|
||||
size_t *out_direction_index)
|
||||
{
|
||||
if (!control_plane_is_initialized()) {
|
||||
if (out_direction_index != NULL) {
|
||||
*out_direction_index = 0;
|
||||
}
|
||||
return CONTROL_PLANE_DIRECTION_CMD_UNKNOWN;
|
||||
}
|
||||
return control_plane_direction_parse_command_internal(input, out_direction_index);
|
||||
}
|
||||
|
||||
esp_err_t control_plane_rotate_to_angle(float target_angle)
|
||||
{
|
||||
if (!control_plane_is_initialized()) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
return domain_rotate_to_angle_with_timeout(target_angle, CONTROL_PLANE_ROTATE_TIMEOUT_MS);
|
||||
}
|
||||
|
||||
esp_err_t control_plane_rotate_to_direction(size_t direction_index)
|
||||
{
|
||||
float angle = 0.0f;
|
||||
|
||||
if (!control_plane_is_initialized()) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
if (!domain_get_direction_view(direction_index, NULL, NULL, &angle)) {
|
||||
return ESP_ERR_NOT_FOUND;
|
||||
}
|
||||
|
||||
return control_plane_rotate_to_angle(angle);
|
||||
}
|
||||
|
||||
esp_err_t control_plane_execute_direction_command(const char *input,
|
||||
control_plane_direction_command_t *out_command,
|
||||
size_t *out_direction_index)
|
||||
{
|
||||
size_t direction_index = 0;
|
||||
control_plane_direction_command_t command = control_plane_parse_direction_command(input, &direction_index);
|
||||
if (out_command != NULL) {
|
||||
*out_command = command;
|
||||
}
|
||||
if (out_direction_index != NULL) {
|
||||
*out_direction_index = direction_index;
|
||||
}
|
||||
|
||||
if (command == CONTROL_PLANE_DIRECTION_CMD_DIRECTION) {
|
||||
return control_plane_rotate_to_direction(direction_index);
|
||||
}
|
||||
if (command == CONTROL_PLANE_DIRECTION_CMD_CALIBRATE) {
|
||||
return control_plane_calibrate();
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t control_plane_calibrate(void)
|
||||
{
|
||||
return control_plane_calibrate_with_timeout(0);
|
||||
}
|
||||
|
||||
esp_err_t control_plane_calibrate_with_timeout(int timeout_ms)
|
||||
{
|
||||
if (!control_plane_is_initialized()) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
return control_plane_direction_calibrate_internal(NULL, timeout_ms);
|
||||
}
|
||||
Reference in New Issue
Block a user