mirror of
https://github.com/oopuuu/zTC1.git
synced 2025-12-12 21:18:13 +08:00
迫不及待想试一下~
This commit is contained in:
@@ -46,7 +46,7 @@
|
||||
static bool is_http_init;
|
||||
static bool is_handlers_registered;
|
||||
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)
|
||||
{
|
||||
@@ -99,9 +99,16 @@ exit:
|
||||
|
||||
static int HttpGetPowerInfo(httpd_request_t *req)
|
||||
{
|
||||
char* powers = GetPowerRecord();
|
||||
sprintf(power_info_json, POWER_INFO_JSON, power_record.idx, powers);
|
||||
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);
|
||||
exit:
|
||||
return err;
|
||||
@@ -172,7 +179,7 @@ struct httpd_wsgi_call g_app_handlers[] = {
|
||||
{"/", HTTPD_HDR_DEFORT, 0, HttpGetIndexPage, NULL, NULL, NULL},
|
||||
{"/socket", HTTPD_HDR_DEFORT, 0, NULL, HttpSetSocketStatus, 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/scan", HTTPD_HDR_DEFORT, 0, HttpGetWifiScan, HttpSetWifiScan, NULL, NULL},
|
||||
};
|
||||
|
||||
@@ -56,7 +56,7 @@
|
||||
'gateway':'%s'\
|
||||
}"
|
||||
|
||||
#define POWER_INFO_JSON "{'idx':%d, 'powers:[%s]'}"
|
||||
#define POWER_INFO_JSON "{'idx':%d,'len':%d,'powers:[%s]'}"
|
||||
|
||||
int AppHttpdStart(void);
|
||||
int AppHttpdStop();
|
||||
|
||||
@@ -251,16 +251,21 @@ HttpGet("/status", function (re) {
|
||||
}
|
||||
});
|
||||
|
||||
var first_load_power = true;
|
||||
var power_idx = 1;
|
||||
var position = 10;
|
||||
function GetPowerRecord() {
|
||||
HttpGet("/power", function (re) {
|
||||
var power = JSON.parse(re);
|
||||
var html = "";
|
||||
for (var i = 0; i < power.powers.length; i++) {
|
||||
html += "<div class='power_pre' style='height:"+power.powers[i]+"px;left:"+((i+1)*10)+"px;'></div>";
|
||||
power_line.innerHTML = html;
|
||||
HttpPost("/power", function (re) {
|
||||
var power = JSON.parse(re);
|
||||
power_idx = power.idx + 1;
|
||||
var html = "";
|
||||
for (var i = 0; i <= power.idx; i++) {
|
||||
html += "<div class='power_pre' style='height:"+power.powers[i]+"px;left:"+position+"px;'></div>";
|
||||
position += 10;
|
||||
}
|
||||
power_line.innerHTML += html;
|
||||
//滑动到最后
|
||||
}
|
||||
});
|
||||
}, idx.toString());
|
||||
}
|
||||
|
||||
function SetOK(i) {
|
||||
|
||||
Reference in New Issue
Block a user