迫不及待想试一下~

This commit is contained in:
zogodo
2019-10-10 18:09:53 +08:00
parent d011c14baf
commit 470a7af3ee
5 changed files with 34 additions and 24 deletions

View File

@@ -46,7 +46,7 @@
static bool is_http_init; static bool is_http_init;
static bool is_handlers_registered; static bool is_handlers_registered;
struct httpd_wsgi_call g_app_handlers[]; struct httpd_wsgi_call g_app_handlers[];
char power_info_json[1130] = { 0 }; char power_info_json[1140] = { 0 };
static int HttpGetIndexPage(httpd_request_t *req) static int HttpGetIndexPage(httpd_request_t *req)
{ {
@@ -99,9 +99,16 @@ exit:
static int HttpGetPowerInfo(httpd_request_t *req) static int HttpGetPowerInfo(httpd_request_t *req)
{ {
char* powers = GetPowerRecord();
sprintf(power_info_json, POWER_INFO_JSON, power_record.idx, powers);
OSStatus err = kNoErr; OSStatus err = kNoErr;
char buf[4];
err = httpd_get_data(req, buf, 4);
require_noerr(err, exit);
int idx = 0;
sscanf(buf, "%d", &idx);
char* powers = GetPowerRecord(idx);
sprintf(power_info_json, POWER_INFO_JSON, power_record.idx, PW_NUM, powers);
send_http(power_info_json, strlen(power_info_json), exit, &err); send_http(power_info_json, strlen(power_info_json), exit, &err);
exit: exit:
return err; return err;
@@ -172,7 +179,7 @@ struct httpd_wsgi_call g_app_handlers[] = {
{"/", HTTPD_HDR_DEFORT, 0, HttpGetIndexPage, NULL, NULL, NULL}, {"/", HTTPD_HDR_DEFORT, 0, HttpGetIndexPage, NULL, NULL, NULL},
{"/socket", HTTPD_HDR_DEFORT, 0, NULL, HttpSetSocketStatus, NULL, NULL}, {"/socket", HTTPD_HDR_DEFORT, 0, NULL, HttpSetSocketStatus, NULL, NULL},
{"/status", HTTPD_HDR_DEFORT, 0, HttpGetTc1Status, NULL, NULL, NULL}, {"/status", HTTPD_HDR_DEFORT, 0, HttpGetTc1Status, NULL, NULL, NULL},
{"/power", HTTPD_HDR_DEFORT, 0, HttpGetPowerInfo, NULL, NULL, NULL}, {"/power", HTTPD_HDR_DEFORT, 0, NULL, HttpGetPowerInfo, NULL, NULL},
{"/wifi/config", HTTPD_HDR_DEFORT, 0, HttpGetWifiConfig, HttpSetWifiConfig, NULL, NULL}, {"/wifi/config", HTTPD_HDR_DEFORT, 0, HttpGetWifiConfig, HttpSetWifiConfig, NULL, NULL},
{"/wifi/scan", HTTPD_HDR_DEFORT, 0, HttpGetWifiScan, HttpSetWifiScan, NULL, NULL}, {"/wifi/scan", HTTPD_HDR_DEFORT, 0, HttpGetWifiScan, HttpSetWifiScan, NULL, NULL},
}; };

View File

@@ -56,7 +56,7 @@
'gateway':'%s'\ 'gateway':'%s'\
}" }"
#define POWER_INFO_JSON "{'idx':%d, 'powers:[%s]'}" #define POWER_INFO_JSON "{'idx':%d,'len':%d,'powers:[%s]'}"
int AppHttpdStart(void); int AppHttpdStart(void);
int AppHttpdStop(); int AppHttpdStop();

View File

@@ -251,16 +251,21 @@ HttpGet("/status", function (re) {
} }
}); });
var first_load_power = true;
var power_idx = 1;
var position = 10;
function GetPowerRecord() { function GetPowerRecord() {
HttpGet("/power", function (re) { HttpPost("/power", function (re) {
var power = JSON.parse(re); var power = JSON.parse(re);
power_idx = power.idx + 1;
var html = ""; var html = "";
for (var i = 0; i < power.powers.length; i++) { for (var i = 0; i <= power.idx; i++) {
html += "<div class='power_pre' style='height:"+power.powers[i]+"px;left:"+((i+1)*10)+"px;'></div>"; html += "<div class='power_pre' style='height:"+power.powers[i]+"px;left:"+position+"px;'></div>";
power_line.innerHTML = html; position += 10;
//滑动到最后
} }
}); power_line.innerHTML += html;
//滑动到最后
}, idx.toString());
} }
function SetOK(i) { function SetOK(i) {

View File

@@ -10,7 +10,7 @@
mico_timer_t power_timer; mico_timer_t power_timer;
PowerRecord power_record = { 0, { 50,55,60,65,70,75,80,85,90,95,90,85,80,75,70,65,60,65,70,75,80,85,90,95,90,85,80,75,70,65,60,65,70,75,80,85,90,95,90,85,80,75,70,65,60 } }; PowerRecord power_record = { 44, { 50,55,60,65,70,75,80,85,90,95,90,85,80,75,70,65,60,65,70,75,80,85,90,95,90,85,80,75,70,65,60,65,70,75,80,85,90,95,90,85,80,75,70,65,60 } };
static uint32_t clock_count_last = 0; static uint32_t clock_count_last = 0;
static uint32_t clock_count = 0; static uint32_t clock_count = 0;
@@ -21,20 +21,18 @@ char power_record_str[1101] = { 0 };
void SetPowerRecord(PowerRecord* pr, uint32_t pw) void SetPowerRecord(PowerRecord* pr, uint32_t pw)
{ {
if (pr->idx >= PW_NUM) pr->powers[(++pr->idx)% PW_NUM] = pw;
{
pr->idx = 0;
}
pr->powers[pr->idx++] = pw;
} }
char* GetPowerRecord() char* GetPowerRecord(int idx)
{ {
int i = 0; if (idx > power_record.idx) return NULL;
int i = idx > 0 ? idx : (power_record.idx - PW_NUM - 1);
char* tmp = power_record_str; char* tmp = power_record_str;
for (; i < PW_NUM; i++) for (; i <= power_record.idx; i++)
{ {
sprintf(tmp, "%d,", power_record.powers[i]); sprintf(tmp, "%d,", power_record.powers[i%PW_NUM]);
tmp += strlen(tmp); tmp += strlen(tmp);
} }
*(--tmp) = 0; *(--tmp) = 0;

View File

@@ -10,7 +10,7 @@ typedef struct
extern PowerRecord power_record; extern PowerRecord power_record;
char* GetPowerRecord(); char* GetPowerRecord(int idx);
void PowerInit(void); void PowerInit(void);
void SetPowerRecord(PowerRecord* pr, uint32_t pw); void SetPowerRecord(PowerRecord* pr, uint32_t pw);