SingleCompensation.c
2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <stdio.h>
#include "JZsdkLib.h"
#include "./SingleCompensation.h"
#define SINGLE_COMPENSATION_INFO_PATH "/root/SingleCompensationInfo.txt"
static T_JZsdkReturnCode SingleCompensation_ReadValues(T_JZ_SingleCompensationInfo *p_SingleCompensationInfo)
{
FILE *file = fopen(SINGLE_COMPENSATION_INFO_PATH, "r");
// 如果文件不存在,创建默认文件
if (!file)
{
// 设置默认值
p_SingleCompensationInfo->Left_SingleCompensationValue = 0;
p_SingleCompensationInfo->Right_SingleCompensationValue = 0;
// 创建文件并写入默认值
FILE *new_file = fopen(SINGLE_COMPENSATION_INFO_PATH, "w");
if (!new_file)
{
JZSDK_LOG_ERROR("Failed to create default config file");
return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE;
}
fprintf(new_file, "%d\n%d\n", p_SingleCompensationInfo->Left_SingleCompensationValue, p_SingleCompensationInfo->Right_SingleCompensationValue);
fclose(new_file);
JZSDK_LOG_INFO("Created default config file with values: Left=0, Right=0");
return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
// 读取两个整数值
if (fscanf(file, "%d %d", &(p_SingleCompensationInfo->Left_SingleCompensationValue) , &(p_SingleCompensationInfo->Right_SingleCompensationValue)) != 2)
{
// 如果读取失败,使用默认值
p_SingleCompensationInfo->Left_SingleCompensationValue = 0;
p_SingleCompensationInfo->Right_SingleCompensationValue = 0;
}
fclose(file);
return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_JZsdkReturnCode SingleCompensation_SaveValues(T_JZ_SingleCompensationInfo *p_SingleCompensationInfo)
{
FILE *file = fopen(SINGLE_COMPENSATION_INFO_PATH, "w");
if (!file) {
JZSDK_LOG_ERROR("Failed to open config file for writing");
return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE;
}
// 直接写入两个值
fprintf(file, "%d\n%d\n", p_SingleCompensationInfo->Left_SingleCompensationValue, p_SingleCompensationInfo->Right_SingleCompensationValue);
fclose(file);
return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_JZsdkReturnCode JZsdk_SingleCompensation_Init(T_JZ_SingleCompensationInfo *p_SingleCompensationInfo)
{
//读取本地的补偿值
SingleCompensation_ReadValues(p_SingleCompensationInfo);
return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}