MotorFineTuning.c 2.4 KB
#include <stdio.h>
#include "JZsdkLib.h"

#include "./MotorFineTuning.h"

#define MOTOR_FILE_PATH         "/root/motor"

/************************
 * 
 *  云台微调初始化
 * 
 * 
 * *************************/
T_JZsdkReturnCode MotorFineTuning_Init(int *pitch, int *yaw, int *roll)
{
    Read_MotorFineTuning_Pitch(pitch);

    return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}


/************************************************************************************************************
 * 
 *    pitch轴
 * 
 * 
*/

/*******
 * 
 *  pitch轴微调值的读取
 * 
 * 
 * ************/
T_JZsdkReturnCode Read_MotorFineTuning_Pitch(int *value)
{
    FILE *motor_file = NULL;
    
	int MotorFineTuningPitch = 0;
	motor_file = fopen(MOTOR_FILE_PATH, "rb+");
    if (motor_file == NULL) 
    {
        motor_file = fopen(MOTOR_FILE_PATH, "wb+");
        if (motor_file == NULL) 
        {
            *value = 0;
            return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
        }
    } 
    else 
    {
        int ret = fseek(motor_file, 0, SEEK_SET);
        if (ret != 0) 
        {
            printf("Seek log count file error, ret: %d.\r\n", ret);
        }

        ret = fread((int *) &MotorFineTuningPitch, 1, sizeof(int), motor_file);
        if (ret != sizeof(int)) 
        {
            printf("Read motor weitiao error.\r\n");
            *value = 0;
            return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE;
        }
		else
        {
			printf("Read motor weitiao=%d\n",MotorFineTuningPitch);
            *value = 0;
            return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE;
		}
    }

    if (motor_file != NULL)
    {
        fclose(motor_file);
    }
    
    *value = MotorFineTuningPitch;
	
	return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}


/*******
 * 
 *  pitch轴微调值的写入
 * 
 * 
 * ************/
T_JZsdkReturnCode MotorFineTuning_WritePitch(int Pitch)
{
    //写入文件	
	FILE *motor_file;
	motor_file = fopen(MOTOR_FILE_PATH, "wb+");
    if (motor_file == NULL)
    {
        return JZ_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
    }
    
	int ret = fwrite((int *) &Pitch, 1, sizeof(unsigned int),motor_file);
    if (ret != sizeof(unsigned int)) 
    {
        JZSDK_LOG_ERROR("MotorFineTuning_WritePitch error.");
    }
	else
    {
		JZSDK_LOG_DEBUG("MotorFineTuning_WritePitch=%d\n",Pitch);
	}

    fclose(motor_file);

    return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}