mirror of
https://github.com/oopuuu/zTC1.git
synced 2025-12-13 05:28:14 +08:00
优化 web_log
This commit is contained in:
@@ -227,7 +227,7 @@ exit:
|
|||||||
static int HttpGetLog(httpd_request_t *req)
|
static int HttpGetLog(httpd_request_t *req)
|
||||||
{
|
{
|
||||||
OSStatus err = kNoErr;
|
OSStatus err = kNoErr;
|
||||||
char* logs = GetLogRecord(0);
|
char* logs = GetLogRecord();
|
||||||
send_http(logs, strlen(logs), exit, &err);
|
send_http(logs, strlen(logs), exit, &err);
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
|
|||||||
@@ -24,11 +24,9 @@ void SetLogRecord(LogRecord* lr, char* log)
|
|||||||
*p_log = log;
|
*p_log = log;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* GetLogRecord(int idx)
|
char* GetLogRecord()
|
||||||
{
|
{
|
||||||
if (idx > log_record.idx) return "";
|
int i = log_record.idx - LOG_NUM + 1;
|
||||||
|
|
||||||
int i = idx > 0 ? idx : (log_record.idx - LOG_NUM + 1);
|
|
||||||
i = i < 0 ? 0 : i;
|
i = i < 0 ? 0 : i;
|
||||||
char* tmp = log_record_str;
|
char* tmp = log_record_str;
|
||||||
for (; i <= log_record.idx; i++)
|
for (; i <= log_record.idx; i++)
|
||||||
@@ -37,6 +35,7 @@ char* GetLogRecord(int idx)
|
|||||||
sprintf(tmp, "%s\n", log_record.logs[i%LOG_NUM]);
|
sprintf(tmp, "%s\n", log_record.logs[i%LOG_NUM]);
|
||||||
tmp += strlen(tmp);
|
tmp += strlen(tmp);
|
||||||
}
|
}
|
||||||
|
sprintf(tmp, "%d", log_record.idx);
|
||||||
return log_record_str;
|
return log_record_str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ extern time_t now;
|
|||||||
extern char time_buf[];
|
extern char time_buf[];
|
||||||
|
|
||||||
void SetLogRecord(LogRecord* lr, char* log);
|
void SetLogRecord(LogRecord* lr, char* log);
|
||||||
char* GetLogRecord(int idx);
|
char* GetLogRecord();
|
||||||
|
|
||||||
#define web_log(format, ...) \
|
#define web_log(format, ...) \
|
||||||
LOG_TMP = (char*)malloc(sizeof(char)*LOG_LEN); \
|
LOG_TMP = (char*)malloc(sizeof(char)*LOG_LEN); \
|
||||||
|
|||||||
@@ -168,8 +168,8 @@ static void KeyTimeoutHandler(void* arg)
|
|||||||
key_time = 101;
|
key_time = 101;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else
|
else
|
||||||
{
|
{
|
||||||
//button released
|
//button released
|
||||||
if (key_time < BUTTON_LONG_PRESS_TIME)
|
if (key_time < BUTTON_LONG_PRESS_TIME)
|
||||||
@@ -177,7 +177,8 @@ static void KeyTimeoutHandler(void* arg)
|
|||||||
key_time = 0;
|
key_time = 0;
|
||||||
os_log("button short pressed:%d",key_time);
|
os_log("button short pressed:%d",key_time);
|
||||||
KeyShortPress();
|
KeyShortPress();
|
||||||
} else if (key_time > 100)
|
}
|
||||||
|
else if (key_time > 100)
|
||||||
{
|
{
|
||||||
MicoSystemReboot();
|
MicoSystemReboot();
|
||||||
}
|
}
|
||||||
@@ -189,6 +190,7 @@ static void KeyFallingIrqHandler(void* arg)
|
|||||||
{
|
{
|
||||||
mico_rtos_start_timer(&user_key_timer);
|
mico_rtos_start_timer(&user_key_timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeyInit(void)
|
void KeyInit(void)
|
||||||
{
|
{
|
||||||
MicoGpioInitialize(Button, INPUT_PULL_UP);
|
MicoGpioInitialize(Button, INPUT_PULL_UP);
|
||||||
|
|||||||
Reference in New Issue
Block a user