#include "devcontrol_common.h"

const device_abnormal_close_t devcontrol_config_t[]= {
        {
        .device_id = DEVICE_CAR0101,
        .device_abnormal_stop = car0101_middle_pwm
    },
        {
        .device_id = DEVICE_CAR0102,
        .device_abnormal_stop = car0102_speed_stop
    },
        {
        .device_id = DEVICE_CAR0103,
        .device_abnormal_stop = car0103_middle
    },
        {
        .device_id = DEVICE_CAR0104,
        .device_abnormal_stop = car0104_stop
    },
        {
        .device_id = DEVICE_TANK0202,
        .device_abnormal_stop = tank0202_middle,
        .device_close=tank0202_thread_close
    },
        {
        .device_id = DEVICE_PAO_PTZ0401,
        .device_abnormal_stop = PTZ_pwm_init
    },
    // 结束标记
    { .device_id = -1 }
};

void device_stop(int device_id) {
    const device_abnormal_close_t *config = NULL;
    
    // 查找设备配置
    for(int i = 0; devcontrol_config_t[i].device_id != -1; i++) {
        if(devcontrol_config_t[i].device_id == device_id) {
            config = &devcontrol_config_t[i];
            break;
        }
    }
    
    if(!config) {
        my_zlog_error("Error: Device ID %d not found!\n", device_id);
        return;
    }
    
    config->device_abnormal_stop();          // 速度控制初始化

    
    my_zlog_debug("device stop successfully!,:%d",device_id);
}

void device_end_close(int device_id) {
    const device_abnormal_close_t *config = NULL;
    
    // 查找设备配置
    for(int i = 0; devcontrol_config_t[i].device_id != -1; i++) {
        if(devcontrol_config_t[i].device_id == device_id) {
            config = &devcontrol_config_t[i];
            break;
        }
    }
    
    if(!config) {
        my_zlog_error("device close and end successfully!,:%d",device_id);
        return;
    }
    
    config->device_close();          // 速度控制初始化

}

