修改ini功能添加默认返回
This commit is contained in:
1 parent
4e5d32a3f4
commit
a27c950c42
6 files changed
+15
-34
No files matched your search
Binary file not shown.
@@ -34,8 +34,8 @@ int read_write_sample(void)
|
||||
return -1;
|
||||
}
|
||||
// 读取各种类型的值
|
||||
strncpy(machine_ID, ini_get_value(ini, "CONFIG", "ID"),sizeof(machine_ID));
|
||||
machine_name = ini_get_value(ini, "CONFIG", "NAME");
|
||||
strncpy(machine_ID, ini_get_value(ini, "CONFIG", "ID","99"),sizeof(machine_ID));
|
||||
machine_name = ini_get_value(ini, "CONFIG", "NAME","828");
|
||||
|
||||
//// ini_set_value(ini,"database", "host","192.168.9.1");
|
||||
|
||||
|
||||
@@ -233,7 +233,7 @@ int ini_delete_key(INI_File *ini, const char *section, const char *key) {
|
||||
return -1; // 未找到
|
||||
}
|
||||
// 获取键值
|
||||
char* ini_get_value(INI_File *ini, const char *section, const char *key) {
|
||||
char* ini_get_value(INI_File *ini, const char *section, const char *key,char *def) {
|
||||
for (int i = 0; i < ini->section_count; i++) {
|
||||
if (strcmp(ini->sections[i].section, section) == 0) {
|
||||
for (int j = 0; j < ini->sections[i].entry_count; j++) {
|
||||
@@ -244,26 +244,26 @@ char* ini_get_value(INI_File *ini, const char *section, const char *key) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return NULL; // 未找到
|
||||
return def; // 未找到
|
||||
}
|
||||
|
||||
// 获取整数值
|
||||
int ini_get_int(INI_File *ini, const char *section, const char *key, int default_value) {
|
||||
const char *value = ini_get_value(ini, section, key);
|
||||
const char *value = ini_get_value(ini, section, key,"0");
|
||||
if (!value) return default_value;
|
||||
return atoi(value);
|
||||
}
|
||||
|
||||
// 获取浮点数值
|
||||
double ini_get_double(INI_File *ini, const char *section, const char *key, double default_value) {
|
||||
const char *value = ini_get_value(ini, section, key);
|
||||
const char *value = ini_get_value(ini, section, key,"0");
|
||||
if (!value) return default_value;
|
||||
return atof(value);
|
||||
}
|
||||
|
||||
// 获取布尔值
|
||||
int ini_get_bool(INI_File *ini, const char *section, const char *key, int default_value) {
|
||||
const char *value = ini_get_value(ini, section, key);
|
||||
const char *value = ini_get_value(ini, section, key,"0");
|
||||
if (!value) return default_value;
|
||||
|
||||
if (strcasecmp(value, "true") == 0 || strcasecmp(value, "yes") == 0 ||
|
||||
|
||||
@@ -44,7 +44,7 @@ extern int ini_parse(INI_File *ini, const char *filename);
|
||||
extern int ini_set_value(INI_File *ini, const char *section, const char *key, const char *value);
|
||||
extern int ini_save(INI_File *ini, const char *filename);
|
||||
extern int ini_delete_key(INI_File *ini, const char *section, const char *key);
|
||||
extern char* ini_get_value(INI_File *ini, const char *section, const char *key);
|
||||
extern char* ini_get_value(INI_File *ini, const char *section, const char *key,char *def);
|
||||
extern int ini_get_int(INI_File *ini, const char *section, const char *key, int default_value);
|
||||
extern double ini_get_double(INI_File *ini, const char *section, const char *key, double default_value);
|
||||
extern int ini_get_bool(INI_File *ini, const char *section, const char *key, int default_value);
|
||||
|
||||
+1
-3
@@ -9,10 +9,9 @@
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <dfs_posix.h>
|
||||
#include <light/RUN_LED.h>
|
||||
#include "DB_SQLite.h"
|
||||
#include "lcd.h"
|
||||
|
||||
#define DBG_TAG "main"
|
||||
#define DBG_LVL DBG_LOG
|
||||
#include <rtdbg.h>
|
||||
@@ -25,6 +24,5 @@ int main(void)
|
||||
thread_DB_SQLite();
|
||||
thread_RUN_LED();//运行指示灯线程
|
||||
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
+6
-23
@@ -131,14 +131,13 @@ static void ds1307_read_time(void)
|
||||
ds1307.datetime.tm_min,
|
||||
ds1307.datetime.tm_sec);
|
||||
|
||||
if(ds1307.datetime.tm_year<199)//
|
||||
{
|
||||
/* 设置日期为年月号 */
|
||||
set_date(ds1307.datetime.tm_year + 1900, ds1307.datetime.tm_mon + 1, ds1307.datetime.tm_mday);
|
||||
/* 设置时间为点分秒 */
|
||||
set_time(ds1307.datetime.tm_hour, ds1307.datetime.tm_min, ds1307.datetime.tm_sec);
|
||||
/* 获取时间 */
|
||||
time_t now = time(RT_NULL);
|
||||
/* 打印输出时间信息 */
|
||||
rt_kprintf("DATE: %s", ctime(&now));
|
||||
}
|
||||
}
|
||||
|
||||
/* Software thread to maintain local time estimation */
|
||||
@@ -148,25 +147,9 @@ static void auto_update_current_datatime(void *parameter)
|
||||
while (1)
|
||||
{
|
||||
rt_thread_delay(RT_TICK_PER_SECOND);
|
||||
ds1307.datetime.tm_sec++;
|
||||
if (ds1307.datetime.tm_sec >= 60)
|
||||
{
|
||||
ds1307.datetime.tm_sec = 0;
|
||||
ds1307.datetime.tm_min++;
|
||||
if (ds1307.datetime.tm_min >= 60)
|
||||
{
|
||||
ds1307.datetime.tm_min = 0;
|
||||
ds1307.datetime.tm_hour++;
|
||||
if (ds1307.datetime.tm_hour >= 24)
|
||||
{
|
||||
ds1307.datetime.tm_hour = 0;
|
||||
// Note: day/month/year rollover not handled in soft update
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Sync with hardware every 10 minutes
|
||||
if (++count >= 600) // 600 seconds
|
||||
if (++count >= 3600) // 600 seconds
|
||||
{
|
||||
ds1307_read_time();
|
||||
count = 0;
|
||||
@@ -227,7 +210,7 @@ static int rt_hw_ds1307_rtc_init(void)
|
||||
|
||||
ds1307_read_time();
|
||||
|
||||
ds1307.thd_soft_update_sec = rt_thread_create("ds1307",auto_update_current_datatime,RT_NULL,512, 10, 5);
|
||||
ds1307.thd_soft_update_sec = rt_thread_create("ds1307",auto_update_current_datatime,RT_NULL,512, 20, 5);
|
||||
if (ds1307.thd_soft_update_sec)
|
||||
{
|
||||
rt_thread_startup(ds1307.thd_soft_update_sec);
|
||||
@@ -236,7 +219,7 @@ static int rt_hw_ds1307_rtc_init(void)
|
||||
LOG_I("DS1307 RTC initialized successfully on %s", ds1307.iic_name);
|
||||
return RT_EOK;
|
||||
}
|
||||
INIT_COMPONENT_EXPORT(rt_hw_ds1307_rtc_init);
|
||||
INIT_APP_EXPORT(rt_hw_ds1307_rtc_init);
|
||||
|
||||
/* MSH Commands */
|
||||
#include <stdlib.h>
|
||||
|
||||
Reference in new issue
Block a user