feat: add calibration switch support

This commit is contained in:
2026-01-30 17:08:40 +08:00
parent 512c64ecff
commit a709cdb56a
3 changed files with 228 additions and 7 deletions

View File

@@ -48,6 +48,7 @@ static void print_help(void)
printf("命令 (Commands):\n");
printf(" help - 显示帮助信息\n");
printf(" pos - 显示当前位置\n");
printf(" cal - 校准正北位置\n");
printf("========================================\n\n");
}
@@ -119,6 +120,21 @@ static void direction_control_task(void *arg)
case DIRECTION_CONTROLLER_CMD_POSITION:
print_current_position();
break;
case DIRECTION_CONTROLLER_CMD_CALIBRATE: {
printf("开始校准...\n");
esp_err_t err = direction_controller_calibrate(NULL);
if (err == ESP_OK) {
printf("校准完成\n");
print_current_position();
} else if (err == ESP_ERR_TIMEOUT) {
printf("校准失败: 未检测到微动开关\n");
} else if (err == ESP_ERR_INVALID_STATE) {
printf("校准失败: 未配置校准开关\n");
} else {
printf("校准失败: 错误码 %d\n", err);
}
break;
}
case DIRECTION_CONTROLLER_CMD_DIRECTION:
if (dir != NULL) {
printf("目标方向: %s (%s, %.1f°)\n",
@@ -181,7 +197,27 @@ void app_main(void)
ESP_LOGI(TAG, "========================================");
/* Initialize peripherals */
direction_controller_init(NULL);
direction_controller_calibration_t calibration = {
.enabled = true,
.gpio_num = GPIO_NUM_39,
.active_level = 0,
.pullup_en = false,
.pulldown_en = false,
.calibration_angle = 180.0f,
.step_angle_deg = 5.0f,
.max_sweep_deg = 360.0f,
.search_cw = true,
.settle_delay_ms = 10
};
direction_controller_config_t config = {
.directions = NULL,
.direction_count = 0,
.initial_angle = 0.0f,
.rotate_speed_us = 0,
.init_stepper_gpio = true,
.calibration = &calibration
};
direction_controller_init(&config);
uart_init();
ESP_LOGI(TAG, "Initial position: South (0°)");