mirror of
https://github.com/oopuuu/zTC1.git
synced 2026-03-23 12:39:53 +08:00
Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
caffddfb43 | ||
|
|
11d3d50265 | ||
|
|
66d2863fa4 | ||
|
|
d925c7d805 | ||
|
|
981c33e3ad | ||
|
|
840b0eb374 | ||
|
|
78dbc6209b | ||
|
|
9d80970e9e | ||
|
|
5f81f2ca71 | ||
|
|
57dbe17175 | ||
|
|
f41a20f8d0 | ||
|
|
52da5983b5 | ||
|
|
758abf123b | ||
|
|
7f0e5d15c8 | ||
|
|
3aec445e57 | ||
|
|
bfae22ddd6 | ||
|
|
1f92b30ea0 |
@@ -54,6 +54,9 @@ TC1 排插硬件分 A1 A2 两个版本, 本固件仅支持 **A1 版本**. A1 A2
|
||||
- [x] 可以设置mqtt数据上报频率,默认2秒
|
||||
- [x] 可以设置电源 led 是否打开,默认打开(系统自检以及错误指示灯仍会工作)
|
||||
- [x] 后台和ha mqtt增加总开关控制
|
||||
- [x] 后台可以自定义6个插座的名称,名称将会自动同步到ha mqtt
|
||||
- [x] 修复了原代码中电源按钮长按 (现在是5秒)重新配网和(10秒)恢复出厂的逻辑错误
|
||||
- [x] 后台和ha mqtt中增加了童锁开关,开启童锁则上电以后不再响应任何电源按钮的事件,上电时同时按住按钮的话会开启配网热点(防止开了童锁,wifi又嗝屁,导致插座功能暴毙的救命逻辑)
|
||||
|
||||
# 编译固件
|
||||
|
||||
|
||||
@@ -163,7 +163,7 @@ static int HttpGetTc1Status(httpd_request_t *req) {
|
||||
user_config->ap_name, user_config->ap_key, MQTT_SERVER, MQTT_SERVER_PORT,
|
||||
MQTT_SERVER_USR, MQTT_SERVER_PWD,
|
||||
VERSION, ip_status.ip, ip_status.mask, ip_status.gateway, user_config->mqtt_report_freq,
|
||||
user_config->power_led_enabled, 0L,socket_names);
|
||||
user_config->power_led_enabled, 0L,socket_names,childLockEnabled,sys_config->micoSystemConfig.name);
|
||||
|
||||
OSStatus err = kNoErr;
|
||||
send_http(tc1_status, strlen(tc1_status), exit, &err);
|
||||
@@ -195,7 +195,7 @@ static int HttpSetSocketStatus(httpd_request_t *req) {
|
||||
static int HttpSetSocketName(httpd_request_t *req) {
|
||||
OSStatus err = kNoErr;
|
||||
|
||||
int buf_size = 512;
|
||||
int buf_size = 70;
|
||||
char *buf = malloc(buf_size);
|
||||
|
||||
err = httpd_get_data(req, buf, buf_size);
|
||||
@@ -213,6 +213,47 @@ static int HttpSetSocketName(httpd_request_t *req) {
|
||||
return err;
|
||||
}
|
||||
|
||||
static int HttpSetDeviceName(httpd_request_t *req) {
|
||||
OSStatus err = kNoErr;
|
||||
|
||||
int buf_size = 70;
|
||||
char *buf = malloc(buf_size);
|
||||
|
||||
err = httpd_get_data(req, buf, buf_size);
|
||||
require_noerr(err, exit);
|
||||
char name[64];
|
||||
sscanf(buf, "%s",name);
|
||||
strcpy(sys_config->micoSystemConfig.name,name);
|
||||
mico_system_context_update(sys_config);
|
||||
registerMqttEvents();
|
||||
send_http("OK", 2, exit, &err);
|
||||
|
||||
exit:
|
||||
if (buf) free(buf);
|
||||
return err;
|
||||
}
|
||||
|
||||
static int HttpSetChildLock(httpd_request_t *req) {
|
||||
OSStatus err = kNoErr;
|
||||
|
||||
int buf_size = 32;
|
||||
char *buf = malloc(buf_size);
|
||||
|
||||
err = httpd_get_data(req, buf, buf_size);
|
||||
require_noerr(err, exit);
|
||||
int enableLock;
|
||||
sscanf(buf, "%d",&enableLock);
|
||||
user_config->user[0] = enableLock;
|
||||
childLockEnabled = enableLock;
|
||||
mico_system_context_update(sys_config);
|
||||
UserMqttSendChildLockState();
|
||||
send_http("OK", 2, exit, &err);
|
||||
|
||||
exit:
|
||||
if (buf) free(buf);
|
||||
return err;
|
||||
}
|
||||
|
||||
static int HttpGetPowerInfo(httpd_request_t *req) {
|
||||
OSStatus err = kNoErr;
|
||||
char buf[16];
|
||||
@@ -243,7 +284,7 @@ static int HttpGetPowerInfo(httpd_request_t *req) {
|
||||
user_config->socket_names[4],
|
||||
user_config->socket_names[5]);
|
||||
sprintf(power_info_json, POWER_INFO_JSON, sockets, power_record.idx, PW_NUM, p_count, powers,
|
||||
up_time,user_config->power_led_enabled,RelayOut()?1:0,socket_names);
|
||||
up_time,user_config->power_led_enabled,RelayOut()?1:0,socket_names,user_config->p_count_1_day_ago,user_config->p_count_2_days_ago,childLockEnabled,sys_config->micoSystemConfig.name);
|
||||
send_http(power_info_json, strlen(power_info_json), exit, &err);
|
||||
if (socket_names) free(socket_names);
|
||||
exit:
|
||||
@@ -546,6 +587,8 @@ const struct httpd_wsgi_call g_app_handlers[] = {
|
||||
{"/led", HTTPD_HDR_DEFORT, 0, LedStatus, LedSetEnabled, NULL, NULL},
|
||||
{"/socketAll", HTTPD_HDR_DEFORT, 0, NULL, TotalSocketSetEnabled, NULL, NULL},
|
||||
{"/socketNames", HTTPD_HDR_DEFORT, 0, NULL, HttpSetSocketName, NULL, NULL},
|
||||
{"/childLock", HTTPD_HDR_DEFORT, 0, NULL, HttpSetChildLock, NULL, NULL},
|
||||
{"/deviceName", HTTPD_HDR_DEFORT, 0, NULL, HttpSetDeviceName, NULL, NULL},
|
||||
};
|
||||
|
||||
static int g_app_handlers_no = sizeof(g_app_handlers) / sizeof(struct httpd_wsgi_call);
|
||||
|
||||
@@ -65,10 +65,12 @@
|
||||
'reportFreq':'%d',\
|
||||
'ledEnabled':%d,\
|
||||
'up_time':%ld,\
|
||||
'socketNames':'%s'\
|
||||
'socketNames':'%s',\
|
||||
'child_lock_enabled':%d,\
|
||||
'deviceName':'%s'\
|
||||
}"
|
||||
|
||||
#define POWER_INFO_JSON "{'sockets':'%s','idx':%d,'len':%d,'p_count':%ld,'powers':[%s],'up_time':'%s','led_enabled':%d,'total_switch_on':%d,'socketNames':'%s'}"
|
||||
#define POWER_INFO_JSON "{'sockets':'%s','idx':%d,'len':%d,'p_count':%ld,'powers':[%s],'up_time':'%s','led_enabled':%d,'total_switch_on':%d,'socketNames':'%s','p_count_1_day_ago':%d,'p_count_2_days_ago':%d,'child_lock_enabled':%d,'deviceName':'%s'}"
|
||||
|
||||
int AppHttpdStart(void);
|
||||
|
||||
|
||||
@@ -25,22 +25,29 @@
|
||||
<div class="demo-layout mdl-layout mdl-js-layout mdl-layout--fixed-drawer mdl-layout--fixed-header">
|
||||
<header class="demo-header mdl-layout__header">
|
||||
<div class="mdl-layout__header-row">
|
||||
<span class="mdl-layout-title">TC1智能插座</span>
|
||||
<div class="mdl-layout-spacer"></div>
|
||||
<button class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon"
|
||||
id="hdrbtn">
|
||||
<button class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon edit-device-name">
|
||||
<i class="material-icons">
|
||||
<svg>
|
||||
<use xlink:href="#icon-translate"/>
|
||||
<use xlink:href="#icon-edit"/>
|
||||
</svg>
|
||||
</i>
|
||||
</button>
|
||||
<ul class="mdl-menu mdl-js-menu mdl-js-ripple-effect mdl-menu--bottom-right"
|
||||
for="hdrbtn">
|
||||
<li class="mdl-menu__item" onclick="ChangeLanguage('en')">English</li>
|
||||
<li class="mdl-menu__item" onclick="ChangeLanguage('cn')">中文</li>
|
||||
<li class="mdl-menu__item" onclick="ChangeLanguage('jp')">日本語</li>
|
||||
</ul>
|
||||
<span class="mdl-layout-title">TC1智能插座</span>
|
||||
<div class="mdl-layout-spacer"></div>
|
||||
<!-- <button class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon"-->
|
||||
<!-- id="hdrbtn">-->
|
||||
<!-- <i class="material-icons">-->
|
||||
<!-- <svg>-->
|
||||
<!-- <use xlink:href="#icon-translate"/>-->
|
||||
<!-- </svg>-->
|
||||
<!-- </i>-->
|
||||
<!-- </button>-->
|
||||
<!-- <ul class="mdl-menu mdl-js-menu mdl-js-ripple-effect mdl-menu--bottom-right"-->
|
||||
<!-- for="hdrbtn">-->
|
||||
<!-- <li class="mdl-menu__item" onclick="ChangeLanguage('en')">English</li>-->
|
||||
<!-- <li class="mdl-menu__item" onclick="ChangeLanguage('cn')">中文</li>-->
|
||||
<!-- <li class="mdl-menu__item" onclick="ChangeLanguage('jp')">日本語</li>-->
|
||||
<!-- </ul>-->
|
||||
<button onclick="reboot()"
|
||||
class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon"
|
||||
id="rebootbtn">
|
||||
@@ -122,6 +129,18 @@
|
||||
-->
|
||||
<ul id="socket_ul" class="demo-list-control mdl-list">
|
||||
<li class="mdl-list__item">
|
||||
<span class="mdl-list__item-primary-content">
|
||||
<span class="lang" langKey="ChildLock">启用童锁</span>
|
||||
</span>
|
||||
<span class="mdl-list__item-secondary-action">
|
||||
<label class="mdl-switch mdl-js-switch mdl-js-ripple-effect"
|
||||
for="list-switch-child-lock">
|
||||
<input type="checkbox" id="list-switch-child-lock" class="mdl-switch__input"
|
||||
checked/>
|
||||
</label>
|
||||
</span>
|
||||
</li>
|
||||
<li class="mdl-list__item">
|
||||
<span class="mdl-list__item-primary-content">
|
||||
<span class="lang" langKey="Led">电源指示灯</span>
|
||||
</span>
|
||||
@@ -270,8 +289,10 @@
|
||||
style="height:315px;overflow-x:scroll;overflow-y:hidden;">
|
||||
<table class="pw">
|
||||
<tr>
|
||||
<td>P: <span id="p" class="success">0</span> W</td>
|
||||
<td>W: <span id="w" class="error">0</span> kW·h</td>
|
||||
<td>当前功率: <span id="p" class="success">0</span> W</td>
|
||||
<td>今日电量: <span id="w_t" class="error">0</span> kW·h</td>
|
||||
<td>昨日电量: <span id="w_y" class="error">0</span> kW·h</td>
|
||||
<td>总电量: <span id="w" class="error">0</span> kW·h</td>
|
||||
</tr>
|
||||
</table>
|
||||
<div id="ct-chart" class="ct-chart ct-perfect-fourth"
|
||||
@@ -519,7 +540,7 @@
|
||||
</tr>
|
||||
</table>
|
||||
<div class="mdl-card__actions mdl-card--border">
|
||||
<span>提示:长按电源按钮5s可开启热点重新配网,10s恢复出厂设置</span>
|
||||
<span>提示:长按电源按钮5s,指示灯闪烁3次可开启热点重新配网,10s指示灯保持闪烁恢复出厂设置</span>
|
||||
<div class="mdl-layout-spacer"></div>
|
||||
<i class="material-icons">
|
||||
<svg>
|
||||
@@ -694,7 +715,8 @@
|
||||
//主页
|
||||
Socket: {en: "Socket", cn: "插座"},
|
||||
Led:{en: "PowerLed", cn: "电源指示灯"},
|
||||
SocketAll:{en: "Total switch", cn: "总开关"}
|
||||
SocketAll:{en: "Total Switch", cn: "总开关"},
|
||||
ChildLock:{en: "Child Lock", cn: "童锁"}
|
||||
}
|
||||
function ChangeLanguage(lang) {
|
||||
if (lang == "jp") {
|
||||
@@ -780,16 +802,18 @@
|
||||
var status_arr = status.sockets.split(",");
|
||||
var names_arr = status.socketNames.split(",");
|
||||
var switchTexts = document.querySelectorAll('.mdl-list__item-primary-content');
|
||||
$(".mdl-layout-title").text(status.deviceName);
|
||||
document.title=status.deviceName;
|
||||
for (var i = 0; i < status_arr.length; i++) {
|
||||
var langSpan = switchTexts[i+2].querySelector('.lang');
|
||||
var indexSpan = switchTexts[i+2].querySelector('.socket-index');
|
||||
var langSpan = switchTexts[i+3].querySelector('.lang');
|
||||
var indexSpan = switchTexts[i+3].querySelector('.socket-index');
|
||||
if (langSpan) langSpan.textContent = names_arr[i]; // 修改插座名称
|
||||
if (indexSpan) indexSpan.textContent = ""; // 修改序号,可自定义起始数字
|
||||
//checkboxs[i].checked = status_arr[i] == "1";
|
||||
if (status_arr[i] == "1") {
|
||||
switch_lables[i+2].MaterialSwitch.on();
|
||||
switch_lables[i+3].MaterialSwitch.on();
|
||||
} else {
|
||||
switch_lables[i+2].MaterialSwitch.off();
|
||||
switch_lables[i+3].MaterialSwitch.off();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -854,17 +878,17 @@
|
||||
var checkboxs = socket_ul.getElementsByClassName("mdl-switch__input");
|
||||
var switch_lables = socket_ul.getElementsByClassName("mdl-switch");
|
||||
$(".mdl-switch__input").on("click", function() {
|
||||
if("list-switch-all" == this.id){
|
||||
if("list-switch-all" == this.id||"list-switch-child-lock"== this.id){
|
||||
return;
|
||||
}
|
||||
var sockets_st = "";
|
||||
for (var i = 2; i < checkboxs.length; i++) {
|
||||
for (var i = 3; i < checkboxs.length; i++) {
|
||||
sockets_st += (checkboxs[i].checked ? "1," : "0,");
|
||||
}
|
||||
HttpPost("/socket", function (re) {
|
||||
}, sockets_st);
|
||||
HttpPost("/led", function (re) {
|
||||
}, checkboxs[0].checked ? "1" : "0");
|
||||
}, checkboxs[1].checked ? "1" : "0");
|
||||
|
||||
});
|
||||
|
||||
@@ -900,9 +924,35 @@
|
||||
}, index+' '+newName.trim());}
|
||||
});
|
||||
|
||||
$(".edit-device-name").on("click", function () {
|
||||
var title = $(".mdl-layout-title");
|
||||
// 原名称
|
||||
var oldName = title.text().trim();
|
||||
|
||||
// 弹窗编辑
|
||||
var newName = prompt("请输入新的设备名称", oldName);
|
||||
if (newName && newName.trim() !== "") {
|
||||
if(newName.trim().includes(" ")){
|
||||
ShowToast("名称不能包含空格");
|
||||
return;
|
||||
}
|
||||
if(newName.trim().length>16){
|
||||
ShowToast("名称不能超过16个字");
|
||||
return;
|
||||
}
|
||||
title.text(newName.trim());
|
||||
|
||||
HttpPost("/deviceName", function (re) {
|
||||
}, newName.trim());}
|
||||
});
|
||||
|
||||
document.getElementById("list-switch-all").addEventListener("click", function() {
|
||||
HttpPost("/socketAll", function (re) {
|
||||
}, checkboxs[1].checked ? "1" : "0");});
|
||||
}, checkboxs[2].checked ? "1" : "0");});
|
||||
|
||||
document.getElementById("list-switch-child-lock").addEventListener("click", function() {
|
||||
HttpPost("/childLock", function (re) {
|
||||
}, checkboxs[0].checked ? "1" : "0");});
|
||||
|
||||
//Socket-end
|
||||
|
||||
@@ -1028,6 +1078,9 @@
|
||||
var chart_wth = 0;
|
||||
var p = document.getElementById("p");
|
||||
var w = document.getElementById("w");
|
||||
var w_t = document.getElementById("w_t");
|
||||
var w_y = document.getElementById("w_y");
|
||||
|
||||
function GetPowerRecord() {
|
||||
HttpPost("/power", function (re) {
|
||||
re = re.replace(/'/g, '"');
|
||||
@@ -1053,30 +1106,43 @@
|
||||
$("#uptime").html(power.up_time);
|
||||
|
||||
var w_v = (17.1 * power.p_count) / 1000 / 36000;
|
||||
w.innerHTML = w_v.toFixed(2);
|
||||
if (power.led_enabled == 1) {
|
||||
w.innerHTML = w_v.toFixed(3);
|
||||
var w_v_t = (17.1 * (power.p_count - power.p_count_1_day_ago)) / 1000 / 36000;
|
||||
w_v_t = w_v_t < 0 ? 0 : w_v_t;
|
||||
w_t.innerHTML = w_v_t.toFixed(3);
|
||||
var w_v_y = (17.1 * (power.p_count_1_day_ago - power.p_count_2_days_ago)) / 1000 / 36000;
|
||||
w_v_y = w_v_y < 0 ? 0 : w_v_y;
|
||||
w_y.innerHTML = w_v_y.toFixed(3);
|
||||
if (power.child_lock_enabled == 1) {
|
||||
switch_lables[0].MaterialSwitch.on();
|
||||
} else {
|
||||
switch_lables[0].MaterialSwitch.off();
|
||||
}
|
||||
if (power.total_switch_on == 1) {
|
||||
if (power.led_enabled == 1) {
|
||||
switch_lables[1].MaterialSwitch.on();
|
||||
} else {
|
||||
switch_lables[1].MaterialSwitch.off();
|
||||
}
|
||||
if (power.total_switch_on == 1) {
|
||||
switch_lables[2].MaterialSwitch.on();
|
||||
} else {
|
||||
switch_lables[2].MaterialSwitch.off();
|
||||
}
|
||||
var status_arr = power.sockets.split(",");
|
||||
var names_arr = power.socketNames.split(",");
|
||||
var switchTexts = document.querySelectorAll('.mdl-list__item-primary-content');
|
||||
var switchTexts = document.querySelectorAll('.mdl-list__item-primary-content');
|
||||
$(".mdl-layout-title").text(power.deviceName);
|
||||
document.title=power.deviceName;
|
||||
for (var i = 0; i < status_arr.length; i++) {
|
||||
//checkboxs[i].checked = status_arr[i] == "1";
|
||||
var langSpan = switchTexts[i+2].querySelector('.lang');
|
||||
var indexSpan = switchTexts[i+2].querySelector('.socket-index');
|
||||
var langSpan = switchTexts[i+3].querySelector('.lang');
|
||||
var indexSpan = switchTexts[i+3].querySelector('.socket-index');
|
||||
if (langSpan) langSpan.textContent = names_arr[i]; // 修改插座名称
|
||||
if (indexSpan) indexSpan.textContent = ""; // 修改序号,可自定义起始数字
|
||||
if (status_arr[i] == "1") {
|
||||
switch_lables[i+2].MaterialSwitch.on();
|
||||
switch_lables[i+3].MaterialSwitch.on();
|
||||
} else {
|
||||
switch_lables[i+2].MaterialSwitch.off();
|
||||
switch_lables[i+3].MaterialSwitch.off();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
24
TC1/main.c
24
TC1/main.c
@@ -18,6 +18,7 @@ char rtc_init = 0; //sntp校时成功标志位
|
||||
uint32_t total_time = 0;
|
||||
char str_mac[16] = {0};
|
||||
int last_check_day = 0;
|
||||
int childLockEnabled = 0;
|
||||
|
||||
system_config_t *sys_config;
|
||||
user_config_t *user_config;
|
||||
@@ -48,7 +49,7 @@ void appRestoreDefault_callback(void *const user_config_data, uint32_t size) {
|
||||
int i;
|
||||
for (i = 0; i < SOCKET_NUM; i++) {
|
||||
userConfigDefault->socket_status[i] = 1;
|
||||
snprintf(userConfigDefault->socket_names[i], SOCKET_NAME_LENGTH, "插座-%d", i+1);
|
||||
snprintf(userConfigDefault->socket_names[i], SOCKET_NAME_LENGTH, "插座-%d", i + 1);
|
||||
}
|
||||
for (i = 0; i < MAX_TASK_NUM; i++) {
|
||||
userConfigDefault->timed_tasks[i].on_use = false;
|
||||
@@ -58,15 +59,17 @@ void appRestoreDefault_callback(void *const user_config_data, uint32_t size) {
|
||||
|
||||
void recordDailyPCount() {
|
||||
// 获取当前时间
|
||||
mico_utc_time_t utc_time;
|
||||
mico_time_get_utc_time(&utc_time);
|
||||
utc_time += 28800;
|
||||
struct tm * current_time = localtime((const time_t *) &utc_time);
|
||||
mico_utc_time_t utc_time;
|
||||
mico_time_get_utc_time(&utc_time);
|
||||
utc_time += 28800;
|
||||
struct tm *current_time = localtime((const time_t *) &utc_time);
|
||||
// 判断上次检查的时间与当前时间的日期是否不同
|
||||
if (last_check_day != 0) {
|
||||
// 如果日期发生变化(即跨天了),则进行记录
|
||||
if (current_time->tm_mday != last_check_day) {
|
||||
tc1_log("WARNGIN: pcount day changed! now day %d hour %d min %d ,lastCheck day %d",current_time->tm_mday,current_time->tm_hour,current_time->tm_min,last_check_day);
|
||||
if (current_time->tm_mday != last_check_day) { tc1_log(
|
||||
"WARNGIN: pcount day changed! now day %d hour %d min %d ,lastCheck day %d",
|
||||
current_time->tm_mday, current_time->tm_hour, current_time->tm_min,
|
||||
last_check_day);
|
||||
|
||||
// tc1_log("WARNGIN: pcount day changed! ");
|
||||
// 记录数据
|
||||
@@ -83,8 +86,8 @@ void recordDailyPCount() {
|
||||
} else {
|
||||
// tc1_log("WARNGIN: pcount day not changed , waiting for next run! ");
|
||||
}
|
||||
}else{
|
||||
tc1_log("WARNGIN: now day %d hour %d min %d ,lastCheck day %d",current_time->tm_mday,current_time->tm_hour,current_time->tm_min,last_check_day);
|
||||
} else { tc1_log("WARNGIN: now day %d hour %d min %d ,lastCheck day %d", current_time->tm_mday,
|
||||
current_time->tm_hour, current_time->tm_min, last_check_day);
|
||||
}
|
||||
// 更新上次检查时间
|
||||
last_check_day = current_time->tm_mday;
|
||||
@@ -134,7 +137,7 @@ int application_start(void) {
|
||||
MicoGpioInitialize((mico_gpio_t) Button, INPUT_PULL_UP);
|
||||
if (!MicoGpioInputGet(Button)) { //开机时按钮状态
|
||||
tc1_log("press ap_init");
|
||||
ApInit(false);
|
||||
ApInit(true);
|
||||
open_ap = true;
|
||||
}
|
||||
|
||||
@@ -145,6 +148,7 @@ int application_start(void) {
|
||||
}
|
||||
MicoSysLed(0);
|
||||
|
||||
childLockEnabled = (int) user_config->user[0];
|
||||
if (user_config->version != USER_CONFIG_VERSION) { tc1_log("WARNGIN: user params restored!");
|
||||
err = mico_system_context_restore(sys_config);
|
||||
require_noerr(err, exit);
|
||||
|
||||
@@ -19,9 +19,9 @@
|
||||
#define VERSION "v2.1.6"
|
||||
|
||||
#define TYPE 1
|
||||
#define TYPE_NAME "zTC1"
|
||||
#define TYPE_NAME "TC1"
|
||||
|
||||
#define ZTC1_NAME "zTC1-%s"
|
||||
#define ZTC1_NAME "TC1-%s"
|
||||
|
||||
#define USER_CONFIG_VERSION 9
|
||||
#define SETTING_MQTT_STRING_LENGTH_MAX 32 //必须4字节对齐。
|
||||
@@ -75,6 +75,7 @@ extern char str_mac[16];
|
||||
extern system_config_t* sys_config;
|
||||
extern user_config_t* user_config;
|
||||
extern mico_gpio_t Relay[Relay_NUM];
|
||||
extern int childLockEnabled;
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -76,6 +76,7 @@ void UserMqttTimerFunc(void *arg) {
|
||||
case 0:
|
||||
UserMqttHassAutoLed();
|
||||
UserMqttHassAutoTotalSocket();
|
||||
UserMqttHassAutoChildLock();
|
||||
break;
|
||||
case 1:
|
||||
case 2:
|
||||
@@ -263,6 +264,8 @@ void MqttClientThread(mico_thread_arg_t arg) {
|
||||
}
|
||||
|
||||
UserMqttSendLedState();
|
||||
UserMqttSendTotalSocketState();
|
||||
UserMqttSendChildLockState();
|
||||
|
||||
mico_init_timer(&timer_handle, 150, UserMqttTimerFunc, &arg);
|
||||
registerMqttEvents();
|
||||
@@ -410,6 +413,14 @@ void ProcessHaCmd(char *cmd) {
|
||||
UserMqttSendSocketState(i);
|
||||
}
|
||||
UserMqttSendTotalSocketState();
|
||||
}else if (strcmp(cmd, "set childLock") == ' ') {
|
||||
int on;
|
||||
sscanf(cmd, "set childLock %s %d", mac, &on);
|
||||
if (strcmp(mac, str_mac)) return;mqtt_log("set childLock on[%d]", on);
|
||||
user_config->user[0] = on;
|
||||
childLockEnabled = on;
|
||||
UserMqttSendChildLockState();
|
||||
mico_system_context_update(sys_config);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -498,6 +509,21 @@ OSStatus UserMqttSendLedState(void) {
|
||||
return oss_status;
|
||||
}
|
||||
|
||||
OSStatus UserMqttSendChildLockState(void) {
|
||||
char *send_buf = malloc(64);
|
||||
char *topic_buf = malloc(64);
|
||||
OSStatus oss_status = kUnknownErr;
|
||||
if (send_buf != NULL && topic_buf != NULL) {
|
||||
sprintf(topic_buf, "homeassistant/switch/%s/childLock/state", str_mac);
|
||||
sprintf(send_buf, "set childLock %s %d", str_mac, childLockEnabled);
|
||||
oss_status = UserMqttSendTopic(topic_buf, send_buf, 1);
|
||||
}
|
||||
if (send_buf) free(send_buf);
|
||||
if (topic_buf) free(topic_buf);
|
||||
|
||||
return oss_status;
|
||||
}
|
||||
|
||||
//hass mqtt鑷姩鍙戠幇鏁版嵁寮<E5B581>鍏冲彂閫<E5BD82>
|
||||
void UserMqttHassAuto(char socket_id) {
|
||||
socket_id--;
|
||||
@@ -509,19 +535,20 @@ void UserMqttHassAuto(char socket_id) {
|
||||
sprintf(topic_buf, "homeassistant/switch/%s/socket_%d/config", str_mac, socket_id);
|
||||
sprintf(send_buf,
|
||||
"{\"name\":\"%s\","
|
||||
"\"uniq_id\":\"%s_s%d\","
|
||||
"\"uniq_id\":\"tc1_%s_s%d\","
|
||||
"\"object_id\":\"tc1_%s_s%d\","
|
||||
"\"stat_t\":\"homeassistant/switch/%s/socket_%d/state\","
|
||||
"\"cmd_t\":\"device/ztc1/set\","
|
||||
"\"pl_on\":\"set socket %s %d 1\","
|
||||
"\"pl_off\":\"set socket %s %d 0\","
|
||||
"\"device\":{"
|
||||
"\"identifiers\":[\"tc1_%s\"],"
|
||||
"\"name\":\"TC1_%s\","
|
||||
"\"name\":\"%s\","
|
||||
"\"model\":\"TC1\","
|
||||
"\"manufacturer\":\"PHICOMM\"}}",
|
||||
user_config->socket_names[(int)socket_id], str_mac, socket_id, str_mac, socket_id,
|
||||
user_config->socket_names[(int)socket_id], str_mac, socket_id,str_mac, socket_id, str_mac, socket_id,
|
||||
str_mac,
|
||||
socket_id, str_mac, socket_id, str_mac, str_mac);
|
||||
socket_id, str_mac, socket_id, str_mac,sys_config->micoSystemConfig.name);
|
||||
UserMqttSendTopic(topic_buf, send_buf, 1);
|
||||
}
|
||||
if (send_buf)
|
||||
@@ -539,17 +566,47 @@ void UserMqttHassAutoLed(void) {
|
||||
sprintf(topic_buf, "homeassistant/switch/%s/led/config", str_mac);
|
||||
sprintf(send_buf,
|
||||
"{\"name\":\"LED指示灯\","
|
||||
"\"uniq_id\":\"%s_led\","
|
||||
"\"uniq_id\":\"tc1_%s_led\","
|
||||
"\"object_id\":\"tc1_%s_led\","
|
||||
"\"stat_t\":\"homeassistant/switch/%s/led/state\","
|
||||
"\"cmd_t\":\"device/ztc1/set\","
|
||||
"\"pl_on\":\"set led %s 1\","
|
||||
"\"pl_off\":\"set led %s 0\","
|
||||
"\"device\":{"
|
||||
"\"identifiers\":[\"tc1_%s\"],"
|
||||
"\"name\":\"TC1_%s\","
|
||||
"\"name\":\"%s\","
|
||||
"\"model\":\"TC1\","
|
||||
"\"manufacturer\":\"PHICOMM\"}}",
|
||||
str_mac, str_mac, str_mac, str_mac, str_mac, str_mac);
|
||||
str_mac,str_mac,str_mac, str_mac, str_mac, str_mac,sys_config->micoSystemConfig.name);
|
||||
UserMqttSendTopic(topic_buf, send_buf, 1);
|
||||
}
|
||||
if (send_buf)
|
||||
free(send_buf);
|
||||
if (topic_buf)
|
||||
free(topic_buf);
|
||||
}
|
||||
|
||||
void UserMqttHassAutoChildLock(void) {
|
||||
char *send_buf = NULL;
|
||||
char *topic_buf = NULL;
|
||||
send_buf = (char *) malloc(600);
|
||||
topic_buf = (char *) malloc(64);
|
||||
if (send_buf != NULL && topic_buf != NULL) {
|
||||
sprintf(topic_buf, "homeassistant/switch/%s/childLock/config", str_mac);
|
||||
sprintf(send_buf,
|
||||
"{\"name\":\"童锁\","
|
||||
"\"uniq_id\":\"tc1_%s_child_lock\","
|
||||
"\"object_id\":\"tc1_%s_child_lock\","
|
||||
"\"stat_t\":\"homeassistant/switch/%s/childLock/state\","
|
||||
"\"cmd_t\":\"device/ztc1/set\","
|
||||
"\"pl_on\":\"set childLock %s 1\","
|
||||
"\"pl_off\":\"set childLock %s 0\","
|
||||
"\"device\":{"
|
||||
"\"identifiers\":[\"tc1_%s\"],"
|
||||
"\"name\":\"%s\","
|
||||
"\"model\":\"TC1\","
|
||||
"\"manufacturer\":\"PHICOMM\"}}",
|
||||
str_mac,str_mac,str_mac, str_mac, str_mac, str_mac,sys_config->micoSystemConfig.name);
|
||||
UserMqttSendTopic(topic_buf, send_buf, 1);
|
||||
}
|
||||
if (send_buf)
|
||||
@@ -567,17 +624,18 @@ void UserMqttHassAutoTotalSocket(void) {
|
||||
sprintf(topic_buf, "homeassistant/switch/%s/total_socket/config", str_mac);
|
||||
sprintf(send_buf,
|
||||
"{\"name\":\"总开关\","
|
||||
"\"uniq_id\":\"%s_total_socket\","
|
||||
"\"uniq_id\":\"tc1_%s_total_socket\","
|
||||
"\"object_id\":\"tc1_%s_total_socket\","
|
||||
"\"stat_t\":\"homeassistant/switch/%s/total_socket/state\","
|
||||
"\"cmd_t\":\"device/ztc1/set\","
|
||||
"\"pl_on\":\"set total_socket %s 1\","
|
||||
"\"pl_off\":\"set total_socket %s 0\","
|
||||
"\"device\":{"
|
||||
"\"identifiers\":[\"tc1_%s\"],"
|
||||
"\"name\":\"TC1_%s\","
|
||||
"\"name\":\"%s\","
|
||||
"\"model\":\"TC1\","
|
||||
"\"manufacturer\":\"PHICOMM\"}}",
|
||||
str_mac, str_mac, str_mac, str_mac, str_mac, str_mac);
|
||||
str_mac, str_mac, str_mac, str_mac, str_mac, str_mac,sys_config->micoSystemConfig.name);
|
||||
UserMqttSendTopic(topic_buf, send_buf, 1);
|
||||
}
|
||||
if (send_buf)
|
||||
@@ -596,60 +654,64 @@ void UserMqttHassAutoPower(void) {
|
||||
sprintf(topic_buf, "homeassistant/sensor/%s/power/config", str_mac);
|
||||
sprintf(send_buf,
|
||||
"{\"name\":\"功率\","
|
||||
"\"uniq_id\":\"%s_p\","
|
||||
"\"uniq_id\":\"tc1_%s_p\","
|
||||
"\"object_id\":\"tc1_%s_p\","
|
||||
"\"state_topic\":\"homeassistant/sensor/%s/power/state\","
|
||||
"\"unit_of_measurement\":\"W\","
|
||||
"\"icon\":\"mdi:gauge\","
|
||||
"\"value_template\":\"{{ value_json.power }}\",""\"device\":{"
|
||||
"\"identifiers\":[\"tc1_%s\"],"
|
||||
"\"name\":\"TC1_%s\","
|
||||
"\"name\":\"%s\","
|
||||
"\"model\":\"TC1\","
|
||||
"\"manufacturer\":\"PHICOMM\"}}",
|
||||
str_mac, str_mac, str_mac, str_mac);
|
||||
str_mac,str_mac, str_mac, str_mac,sys_config->micoSystemConfig.name);
|
||||
UserMqttSendTopic(topic_buf, send_buf, 1);
|
||||
sprintf(topic_buf, "homeassistant/sensor/%s/powerConsumption/config", str_mac);
|
||||
sprintf(send_buf,
|
||||
"{\"name\":\"总耗电量\","
|
||||
"\"uniq_id\":\"%s_pc\","
|
||||
"\"uniq_id\":\"tc1_%s_pc\","
|
||||
"\"object_id\":\"tc1_%s_pc\","
|
||||
"\"state_topic\":\"homeassistant/sensor/%s/powerConsumption/state\","
|
||||
"\"unit_of_measurement\":\"kWh\","
|
||||
"\"icon\":\"mdi:fence-electric\","
|
||||
"\"value_template\":\"{{ value_json.powerConsumption }}\",""\"device\":{"
|
||||
"\"identifiers\":[\"tc1_%s\"],"
|
||||
"\"name\":\"TC1_%s\","
|
||||
"\"name\":\"%s\","
|
||||
"\"model\":\"TC1\","
|
||||
"\"manufacturer\":\"PHICOMM\"}}",
|
||||
str_mac, str_mac, str_mac, str_mac);
|
||||
str_mac, str_mac, str_mac, str_mac,sys_config->micoSystemConfig.name);
|
||||
UserMqttSendTopic(topic_buf, send_buf, 1);
|
||||
|
||||
sprintf(topic_buf, "homeassistant/sensor/%s/powerConsumptionToday/config", str_mac);
|
||||
sprintf(send_buf,
|
||||
"{\"name\":\"今日耗电量\","
|
||||
"\"uniq_id\":\"%s_pc_today\","
|
||||
"\"uniq_id\":\"tc1_%s_pc_today\","
|
||||
"\"object_id\":\"tc1_%s_pc_today\","
|
||||
"\"state_topic\":\"homeassistant/sensor/%s/powerConsumptionToday/state\","
|
||||
"\"unit_of_measurement\":\"kWh\","
|
||||
"\"icon\":\"mdi:fence-electric\","
|
||||
"\"value_template\":\"{{ value_json.powerConsumptionToday }}\",""\"device\":{"
|
||||
"\"identifiers\":[\"tc1_%s\"],"
|
||||
"\"name\":\"TC1_%s\","
|
||||
"\"name\":\"%s\","
|
||||
"\"model\":\"TC1\","
|
||||
"\"manufacturer\":\"PHICOMM\"}}",
|
||||
str_mac, str_mac, str_mac, str_mac);
|
||||
str_mac,str_mac, str_mac, str_mac,sys_config->micoSystemConfig.name);
|
||||
UserMqttSendTopic(topic_buf, send_buf, 1);
|
||||
|
||||
sprintf(topic_buf, "homeassistant/sensor/%s/powerConsumptionYesterday/config", str_mac);
|
||||
sprintf(send_buf,
|
||||
"{\"name\":\"昨日耗电量\","
|
||||
"\"uniq_id\":\"%s_pc_yesterday\","
|
||||
"\"uniq_id\":\"tc1_%s_pc_yesterday\","
|
||||
"\"object_id\":\"tc1_%s_pc_yesterday\","
|
||||
"\"state_topic\":\"homeassistant/sensor/%s/powerConsumptionYesterday/state\","
|
||||
"\"unit_of_measurement\":\"kWh\","
|
||||
"\"icon\":\"mdi:fence-electric\","
|
||||
"\"value_template\":\"{{ value_json.powerConsumptionYesterday }}\",""\"device\":{"
|
||||
"\"identifiers\":[\"tc1_%s\"],"
|
||||
"\"name\":\"TC1_%s\","
|
||||
"\"name\":\"%s\","
|
||||
"\"model\":\"TC1\","
|
||||
"\"manufacturer\":\"PHICOMM\"}}",
|
||||
str_mac, str_mac, str_mac, str_mac);
|
||||
str_mac,str_mac, str_mac, str_mac,sys_config->micoSystemConfig.name);
|
||||
UserMqttSendTopic(topic_buf, send_buf, 1);
|
||||
}
|
||||
if (send_buf) free(send_buf);
|
||||
|
||||
@@ -31,6 +31,8 @@ extern OSStatus UserMqttSendSocketState(char socket_id);
|
||||
|
||||
extern OSStatus UserMqttSendLedState(void);
|
||||
|
||||
extern OSStatus UserMqttSendChildLockState(void);
|
||||
|
||||
extern OSStatus UserMqttSendTotalSocketState(void);
|
||||
|
||||
extern void UserMqttHassAuto(char socket_id);
|
||||
@@ -41,6 +43,8 @@ extern void UserMqttHassAutoPower(void);
|
||||
|
||||
extern void UserMqttHassAutoLed(void);
|
||||
|
||||
extern void UserMqttHassAutoChildLock(void);
|
||||
|
||||
extern void UserMqttHassAutoTotalSocket(void);
|
||||
|
||||
extern void registerMqttEvents(void);
|
||||
|
||||
165
TC1/user_gpio.c
165
TC1/user_gpio.c
@@ -2,13 +2,13 @@
|
||||
|
||||
#include "main.h"
|
||||
#include "user_gpio.h"
|
||||
#include "user_wifi.h"
|
||||
#include "mqtt_server/user_mqtt_client.h"
|
||||
|
||||
mico_gpio_t relay[Relay_NUM] = { Relay_0, Relay_1, Relay_2, Relay_3, Relay_4, Relay_5 };
|
||||
char socket_status[32] = { 0 };
|
||||
mico_gpio_t relay[Relay_NUM] = {Relay_0, Relay_1, Relay_2, Relay_3, Relay_4, Relay_5};
|
||||
char socket_status[32] = {0};
|
||||
|
||||
void UserLedSet(char x)
|
||||
{
|
||||
void UserLedSet(char x) {
|
||||
if (x == -1)
|
||||
MicoGpioOutputTrigger(Led);
|
||||
else if (x)
|
||||
@@ -17,43 +17,37 @@ void UserLedSet(char x)
|
||||
MicoGpioOutputLow(Led);
|
||||
}
|
||||
|
||||
bool RelayOut(void)
|
||||
{
|
||||
bool RelayOut(void) {
|
||||
int i;
|
||||
for (i = 0; i < SOCKET_NUM; i++)
|
||||
{
|
||||
if (user_config->socket_status[i] != 0)
|
||||
{
|
||||
for (i = 0; i < SOCKET_NUM; i++) {
|
||||
if (user_config->socket_status[i] != 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
char* GetSocketStatus()
|
||||
{
|
||||
char *GetSocketStatus() {
|
||||
sprintf(socket_status, "%d,%d,%d,%d,%d,%d",
|
||||
user_config->socket_status[0],
|
||||
user_config->socket_status[1],
|
||||
user_config->socket_status[2],
|
||||
user_config->socket_status[3],
|
||||
user_config->socket_status[4],
|
||||
user_config->socket_status[5]);
|
||||
user_config->socket_status[0],
|
||||
user_config->socket_status[1],
|
||||
user_config->socket_status[2],
|
||||
user_config->socket_status[3],
|
||||
user_config->socket_status[4],
|
||||
user_config->socket_status[5]);
|
||||
return socket_status;
|
||||
}
|
||||
|
||||
void SetSocketStatus(char* socket_status)
|
||||
{
|
||||
void SetSocketStatus(char *socket_status) {
|
||||
sscanf(socket_status, "%d,%d,%d,%d,%d,%d,",
|
||||
(int*)&user_config->socket_status[0],
|
||||
(int*)&user_config->socket_status[1],
|
||||
(int*)&user_config->socket_status[2],
|
||||
(int*)&user_config->socket_status[3],
|
||||
(int*)&user_config->socket_status[4],
|
||||
(int*)&user_config->socket_status[5]);
|
||||
(int *) &user_config->socket_status[0],
|
||||
(int *) &user_config->socket_status[1],
|
||||
(int *) &user_config->socket_status[2],
|
||||
(int *) &user_config->socket_status[3],
|
||||
(int *) &user_config->socket_status[4],
|
||||
(int *) &user_config->socket_status[5]);
|
||||
int i = 0;
|
||||
for (i = 0; i < SOCKET_NUM; i++)
|
||||
{
|
||||
for (i = 0; i < SOCKET_NUM; i++) {
|
||||
UserRelaySet(i, user_config->socket_status[i]);
|
||||
UserMqttSendSocketState(i);
|
||||
}
|
||||
@@ -66,27 +60,20 @@ void SetSocketStatus(char* socket_status)
|
||||
* i:编号 0-5
|
||||
* on:开关 0:关 1:开
|
||||
*/
|
||||
void UserRelaySet(unsigned char i, unsigned char on)
|
||||
{
|
||||
void UserRelaySet(unsigned char i, unsigned char on) {
|
||||
if (i < 0 || i >= SOCKET_NUM) return;
|
||||
|
||||
if (on == Relay_ON)
|
||||
{
|
||||
if (on == Relay_ON) {
|
||||
MicoGpioOutputHigh(relay[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
MicoGpioOutputLow(relay[i]);
|
||||
}
|
||||
|
||||
user_config->socket_status[i] = on;
|
||||
|
||||
if (RelayOut()&&user_config->power_led_enabled)
|
||||
{
|
||||
if (RelayOut() && user_config->power_led_enabled) {
|
||||
UserLedSet(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
UserLedSet(0);
|
||||
}
|
||||
}
|
||||
@@ -96,110 +83,110 @@ void UserRelaySet(unsigned char i, unsigned char on)
|
||||
* y: 0:全部关 1:全部开
|
||||
*
|
||||
*/
|
||||
void UserRelaySetAll(char y)
|
||||
{
|
||||
void UserRelaySetAll(char y) {
|
||||
int i;
|
||||
for (i = 0; i < SOCKET_NUM; i++)
|
||||
UserRelaySet(i, y);
|
||||
}
|
||||
|
||||
static void KeyLong5sPress(void)
|
||||
{
|
||||
static void KeyLong5sPress(void) {
|
||||
key_log("WARNGIN: wifi ap started!");
|
||||
sys_config->micoSystemConfig.ssid[0] = 0;
|
||||
mico_system_context_update(mico_system_context_get());
|
||||
micoWlanSuspendStation();
|
||||
ApInit(true);
|
||||
}
|
||||
|
||||
static void KeyLong10sPress(void)
|
||||
{
|
||||
static void KeyLong10sPress(void) {
|
||||
key_log("WARNGIN: user params restored!");
|
||||
mico_system_context_restore(sys_config);
|
||||
// appRestoreDefault_callback(user_config, sizeof(user_config_t));
|
||||
// sys_config->micoSystemConfig.ssid[0] = 0;
|
||||
// mico_system_context_update(mico_system_context_get());
|
||||
}
|
||||
static void KeyShortPress(void)
|
||||
{
|
||||
|
||||
static void KeyShortPress(void) {
|
||||
char i;
|
||||
|
||||
if (RelayOut())
|
||||
{
|
||||
if (RelayOut()) {
|
||||
UserRelaySetAll(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
UserRelaySetAll(1);
|
||||
}
|
||||
|
||||
for (i = 0; i < SOCKET_NUM; i++)
|
||||
{
|
||||
for (i = 0; i < SOCKET_NUM; i++) {
|
||||
UserMqttSendSocketState(i);
|
||||
}
|
||||
UserMqttSendTotalSocketState();
|
||||
}
|
||||
|
||||
mico_timer_t user_key_timer;
|
||||
uint16_t key_time = 0;
|
||||
#define BUTTON_LONG_PRESS_TIME 10 //100ms*10=1s
|
||||
|
||||
static void KeyTimeoutHandler(void* arg)
|
||||
{
|
||||
static void KeyTimeoutHandler(void *arg) {
|
||||
if(childLockEnabled)
|
||||
return;
|
||||
static char key_trigger, key_continue;
|
||||
//按键扫描程序
|
||||
char tmp = ~(0xfe | MicoGpioInputGet(Button));
|
||||
key_trigger = tmp & (tmp ^ key_continue);
|
||||
key_continue = tmp;
|
||||
if (key_trigger != 0) key_time = 0; //新按键按下时,重新开始按键计时
|
||||
if (key_continue != 0)
|
||||
{
|
||||
if (key_continue != 0) {
|
||||
//any button pressed
|
||||
key_time++;
|
||||
if (key_time > BUTTON_LONG_PRESS_TIME)
|
||||
{
|
||||
key_log("button long pressed:%d",key_time);
|
||||
if (key_time > BUTTON_LONG_PRESS_TIME) { key_log("button long pressed:%d", key_time);
|
||||
|
||||
if (key_time == 50)
|
||||
{
|
||||
if (key_time == 50) {
|
||||
KeyLong5sPress();
|
||||
}
|
||||
else if (key_time == 100)
|
||||
{
|
||||
} else if (key_time > 50 && key_time < 57) {
|
||||
switch (key_time) {
|
||||
case 51:
|
||||
UserLedSet(1);
|
||||
break;
|
||||
case 52:
|
||||
UserLedSet(0);
|
||||
break;
|
||||
case 53:
|
||||
UserLedSet(1);
|
||||
break;
|
||||
case 54:
|
||||
UserLedSet(0);
|
||||
break;
|
||||
case 55:
|
||||
UserLedSet(1);
|
||||
break;
|
||||
case 56:
|
||||
UserLedSet(0);
|
||||
break;
|
||||
}
|
||||
} else if (key_time == 57) {
|
||||
UserLedSet(RelayOut() && user_config->power_led_enabled);
|
||||
} else if (key_time == 100) {
|
||||
KeyLong10sPress();
|
||||
}
|
||||
else if (key_time == 102)
|
||||
{
|
||||
} else if (key_time == 102) {
|
||||
UserLedSet(1);
|
||||
}
|
||||
else if (key_time == 103)
|
||||
{
|
||||
} else if (key_time == 103) {
|
||||
UserLedSet(0);
|
||||
key_time = 101;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
//button released
|
||||
if (key_time < BUTTON_LONG_PRESS_TIME)
|
||||
{ //100ms*10=1s 大于1s为长按
|
||||
key_time = 0;
|
||||
key_log("button short pressed:%d",key_time);
|
||||
if (key_time < BUTTON_LONG_PRESS_TIME) { //100ms*10=1s 大于1s为长按
|
||||
key_time = 0;key_log("button short pressed:%d", key_time);
|
||||
KeyShortPress();
|
||||
}
|
||||
else if (key_time > 100)
|
||||
{
|
||||
} else if (key_time > 100) {
|
||||
MicoSystemReboot();
|
||||
}
|
||||
mico_rtos_stop_timer(&user_key_timer);
|
||||
}
|
||||
}
|
||||
|
||||
static void KeyFallingIrqHandler(void* arg)
|
||||
{
|
||||
static void KeyFallingIrqHandler(void *arg) {
|
||||
mico_rtos_start_timer(&user_key_timer);
|
||||
}
|
||||
|
||||
void KeyInit(void)
|
||||
{
|
||||
void KeyInit(void) {
|
||||
MicoGpioInitialize(Button, INPUT_PULL_UP);
|
||||
mico_rtos_init_timer(&user_key_timer, 100, KeyTimeoutHandler, NULL);
|
||||
|
||||
|
||||
BIN
doc/IMG_0862.png
BIN
doc/IMG_0862.png
Binary file not shown.
|
Before Width: | Height: | Size: 171 KiB After Width: | Height: | Size: 396 KiB |
BIN
doc/IMG_0863.png
BIN
doc/IMG_0863.png
Binary file not shown.
|
Before Width: | Height: | Size: 215 KiB After Width: | Height: | Size: 286 KiB |
Reference in New Issue
Block a user