增加了语音抽签控制屏幕显示
增加了校准和财位控制电机旋转
This commit is contained in:
@@ -51,10 +51,44 @@ static const char *find_command_prefix(const char *text)
|
||||
return strstr(cursor, "/*{");
|
||||
}
|
||||
|
||||
static bool text_contains_chouqian_result(const char *text)
|
||||
{
|
||||
return text != NULL &&
|
||||
(strstr(text, "签文:") != NULL || strstr(text, "签文:") != NULL);
|
||||
}
|
||||
|
||||
static bool resolve_chouqian_result_index(const char *value, size_t *out_index)
|
||||
{
|
||||
static const char *const s_chouqian_result_names[] = {
|
||||
"卜运签",
|
||||
"和平签",
|
||||
"上上签",
|
||||
"小吉签",
|
||||
"中上签",
|
||||
};
|
||||
|
||||
if (value == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < sizeof(s_chouqian_result_names) / sizeof(s_chouqian_result_names[0]); ++i) {
|
||||
if (strcmp(value, s_chouqian_result_names[i]) == 0) {
|
||||
if (out_index != NULL) {
|
||||
*out_index = i;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool control_plane_extract_model_command(const char *text,
|
||||
control_plane_model_command_type_t *out_command_type,
|
||||
char *out_value,
|
||||
size_t out_value_capacity)
|
||||
size_t out_value_capacity,
|
||||
size_t *out_value_index,
|
||||
bool *out_value_index_valid)
|
||||
{
|
||||
if (text == NULL || out_command_type == NULL ||
|
||||
out_value == NULL || out_value_capacity == 0U) {
|
||||
@@ -63,9 +97,20 @@ bool control_plane_extract_model_command(const char *text,
|
||||
|
||||
*out_command_type = CONTROL_PLANE_MODEL_COMMAND_UNKNOWN;
|
||||
out_value[0] = '\0';
|
||||
if (out_value_index != NULL) {
|
||||
*out_value_index = 0U;
|
||||
}
|
||||
if (out_value_index_valid != NULL) {
|
||||
*out_value_index_valid = false;
|
||||
}
|
||||
|
||||
const char *command_start = find_command_prefix(text);
|
||||
if (command_start == NULL || command_start[0] != '/' || command_start[1] != '*') {
|
||||
if (text_contains_chouqian_result(text)) {
|
||||
*out_command_type = CONTROL_PLANE_MODEL_COMMAND_CHOUQIAN;
|
||||
strlcpy(out_value, "签文", out_value_capacity);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -101,6 +146,7 @@ bool control_plane_extract_model_command(const char *text,
|
||||
bool found = false;
|
||||
cJSON *direction = cJSON_GetObjectItemCaseSensitive(cmd_json, "转向");
|
||||
cJSON *calibrate = cJSON_GetObjectItemCaseSensitive(cmd_json, "校准");
|
||||
cJSON *chouqian = cJSON_GetObjectItemCaseSensitive(cmd_json, "抽签");
|
||||
|
||||
if (cJSON_IsString(direction) && direction->valuestring != NULL) {
|
||||
if (is_supported_model_direction(direction->valuestring)) {
|
||||
@@ -114,6 +160,19 @@ bool control_plane_extract_model_command(const char *text,
|
||||
strlcpy(out_value, calibrate->valuestring, out_value_capacity);
|
||||
found = true;
|
||||
}
|
||||
} else if (cJSON_IsString(chouqian) && chouqian->valuestring != NULL) {
|
||||
size_t result_index = 0U;
|
||||
if (resolve_chouqian_result_index(chouqian->valuestring, &result_index)) {
|
||||
*out_command_type = CONTROL_PLANE_MODEL_COMMAND_CHOUQIAN;
|
||||
strlcpy(out_value, chouqian->valuestring, out_value_capacity);
|
||||
if (out_value_index != NULL) {
|
||||
*out_value_index = result_index;
|
||||
}
|
||||
if (out_value_index_valid != NULL) {
|
||||
*out_value_index_valid = true;
|
||||
}
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
|
||||
cJSON_Delete(cmd_json);
|
||||
|
||||
@@ -197,7 +197,14 @@ static void control_plane_responding_text_bridge(const char *text,
|
||||
|
||||
control_plane_model_command_type_t command_type = CONTROL_PLANE_MODEL_COMMAND_UNKNOWN;
|
||||
char value[32] = {0};
|
||||
if (!control_plane_extract_model_command(text, &command_type, value, sizeof(value))) {
|
||||
size_t value_index = 0U;
|
||||
bool value_index_valid = false;
|
||||
if (!control_plane_extract_model_command(text,
|
||||
&command_type,
|
||||
value,
|
||||
sizeof(value),
|
||||
&value_index,
|
||||
&value_index_valid)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -213,8 +220,13 @@ static void control_plane_responding_text_bridge(const char *text,
|
||||
return;
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "Device command: type=%d value=%s", (int)command_type, value);
|
||||
cb(command_type, value, cb_user_data);
|
||||
ESP_LOGI(TAG,
|
||||
"Device command: type=%d value=%s index=%u valid=%d",
|
||||
(int)command_type,
|
||||
value,
|
||||
(unsigned int)value_index,
|
||||
value_index_valid ? 1 : 0);
|
||||
cb(command_type, value, value_index, value_index_valid, cb_user_data);
|
||||
}
|
||||
|
||||
static esp_err_t control_plane_prepare_for_multimodal_start(void)
|
||||
|
||||
Reference in New Issue
Block a user