mirror of
https://github.com/oopuuu/zTC1.git
synced 2025-12-13 13:38:14 +08:00
获取功率
This commit is contained in:
@@ -39,12 +39,14 @@
|
||||
#include "app_httpd.h"
|
||||
#include "user_gpio.h"
|
||||
#include "user_wifi.h"
|
||||
#include "user_power.h"
|
||||
#include "main.h"
|
||||
#include "web_data.c"
|
||||
|
||||
static bool is_http_init;
|
||||
static bool is_handlers_registered;
|
||||
struct httpd_wsgi_call g_app_handlers[];
|
||||
char power_info_json[1130] = { 0 };
|
||||
|
||||
static int HttpGetIndexPage(httpd_request_t *req)
|
||||
{
|
||||
@@ -95,6 +97,16 @@ exit:
|
||||
return err;
|
||||
}
|
||||
|
||||
static int HttpGetPowerInfo(httpd_request_t *req)
|
||||
{
|
||||
char* powers = GetPowerRecord();
|
||||
sprintf(power_info_json, POWER_INFO_JSON, power_record.idx, powers);
|
||||
OSStatus err = kNoErr;
|
||||
send_http(power_info_json, strlen(power_info_json), exit, &err);
|
||||
exit:
|
||||
return err;
|
||||
}
|
||||
|
||||
static int HttpGetWifiConfig(httpd_request_t *req)
|
||||
{
|
||||
OSStatus err = kNoErr;
|
||||
@@ -160,6 +172,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},
|
||||
{"/wifi/config", HTTPD_HDR_DEFORT, 0, HttpGetWifiConfig, HttpSetWifiConfig, NULL, NULL},
|
||||
{"/wifi/scan", HTTPD_HDR_DEFORT, 0, HttpGetWifiScan, HttpSetWifiScan, NULL, NULL},
|
||||
};
|
||||
|
||||
@@ -56,6 +56,8 @@
|
||||
'gateway':'%s'\
|
||||
}"
|
||||
|
||||
#define POWER_INFO_JSON "{'idx':%d, 'powers:[%s]'}"
|
||||
|
||||
int AppHttpdStart(void);
|
||||
int AppHttpdStop();
|
||||
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
#power_div{margin-top:10px;border-left:1px solid #000;border-bottom:1px solid #000;}
|
||||
#power_line{height:100px;position:relative;overflow:scroll;margin-top:-100px;}
|
||||
.power_pre{position:absolute;bottom:0;float:left;height:76px;width:0;border-left:1px solid #000;border-right:1px solid #000;}
|
||||
.power_by{text-align:center;}
|
||||
.power_by a{text-decoration:none;}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
@@ -175,6 +177,8 @@
|
||||
</table>
|
||||
</fieldset>
|
||||
|
||||
<p class="power_by">power by <a href="https://github.com/zogodo/zTC1" target="_blank">github/zTC1</a></p>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
function Ajax(url, onsuccess, type, data) {
|
||||
@@ -210,6 +214,8 @@ var info_spans = document.getElementsByClassName("status_sp");
|
||||
var socket_tb = document.getElementById("socket_tb");
|
||||
var checkboxs = socket_tb.getElementsByTagName("input");
|
||||
|
||||
var power_line = document.getElementById("power_line");
|
||||
|
||||
var rescan_btn = document.getElementById("rescan");
|
||||
var ssid_slt = document.getElementById("wifi");
|
||||
var ssid_ipt = document.getElementById("ssid");
|
||||
@@ -245,6 +251,18 @@ HttpGet("/status", function (re) {
|
||||
}
|
||||
});
|
||||
|
||||
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:70px;left:20px;'></div>";
|
||||
power_line.innerHTML = html;
|
||||
//滑动到最后
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function SetOK(i) {
|
||||
submit_bts[i].disabled = false;
|
||||
info_spans[i].className = "status_sp success";
|
||||
|
||||
Reference in New Issue
Block a user