系统日志
@@ -907,43 +977,67 @@
$("#uptime").html(status.up_time);
- var actions=status.shortClicks.split(",");
+ var actions=status.btnClicks;
//按键操作功能定义
var BTN_OPERATIONS=["切换总开关"];
for (var i = 0; i < names_arr.length; i++) {
BTN_OPERATIONS.push(`切换${names_arr[i]}`);
}
BTN_OPERATIONS.push("切换电源指示灯启用");
+ BTN_OPERATIONS.push("重启系统");
+ BTN_OPERATIONS.push("重新配网");
+ BTN_OPERATIONS.push("重置系统");
+$('#btn_action_selector').append(
+ $('
')
+ .addClass('mdl-menu__item')
+ .attr('data-val', -1)
+ .text("未设置")
+ );
+ for (let i = 0; i <= BTN_OPERATIONS.length; i++) {
+ $('#btn_action_selector').append(
+ $('')
+ .addClass('mdl-menu__item')
+ .attr('data-val', i)
+ .text(BTN_OPERATIONS[i])
+ );
+ }
+
+
var tb_html = `
| 按键类型 |
- 执行操作 |
+ 执行动作 |
+ 操作 |
`;
for (var i = 0; i < actions.length; i++) {
var rowId = `select-${i}`;
- var index = parseInt(actions[i]);
- var valueText = (isNaN(index) || index < 0 || index >= BTN_OPERATIONS.length) ? '未设置' : BTN_OPERATIONS[index];
+ var times = Object.keys(actions[i])[0];
+ var operations = Object.values(actions[i])[0];
+ if(operations[0]!=-1){
+ var valueText = (isNaN(operations[0]) || operations[0] < 0 || operations[0] >= BTN_OPERATIONS.length) ? '未设置' : BTN_OPERATIONS[operations[0]];
+ tb_html += `
+
+ | ${times > 0 ? '连续' : ''}短按${times}次 |
+ ${valueText} |
+ 删除 |
+
+ `;
+ }
+ if(operations[1]!=-1){
+ var valueText = (isNaN(operations[1]) || operations[1] < 0 || operations[1] >= BTN_OPERATIONS.length) ? '未设置' : BTN_OPERATIONS[operations[1]];
tb_html += `
- | ${i > 0 ? '连续' : ''}短按${i + 1}次 |
-
-
-
-
-
-
- |
+ 长按${times}秒 |
+ ${valueText} |
+ 删除 |
`;
+ }
+
}
document.getElementById("short_click_events_tb").innerHTML = tb_html;
componentHandler.upgradeDom();
@@ -952,7 +1046,7 @@ componentHandler.upgradeDom();
});
$(".mdl-switch__input").on("click", function() {
- if("list-switch-all" == this.id||"list-switch-child-lock"== this.id){
+ if("list-switch-all" == this.id||"list-switch-child-lock"== this.id||"task_on"== this.id){
return;
}
var sockets_st = "";
@@ -1295,6 +1389,33 @@ componentHandler.upgradeDom();
GetTimedTask();
}, cmd);
}
+
+ $('#button_type').on('input', function() {
+ var value = $(this).val();
+ $('#click_times_press_time_label').text(value == '0'?'连击次数':'长按秒数');
+});
+ $(function() {
+ for (let i = 1; i <= 30; i++) {
+ $('#click_times_press_time_selector').append(
+ $('')
+ .addClass('mdl-menu__item')
+ .attr('data-val', i)
+ .text(i)
+ );
+ }
+});
+ function addButtonEvent() {
+
+ var longPress = document.getElementById("button_type").value;
+ var event = document.getElementById("action_type").checked;
+ var times_or_seconds = document.getElementById("click_times_press_time").checked;
+
+ HttpPost("/buttonEvents", function (re) {
+ if (re == "OK") {
+ ShowToast("已添加按钮事件");
+ }
+ }, `${times_or_seconds} ${event} ${longPress}`);
+ }
function selectOperation(rowId, index, operationText) {
var witch = parseInt(rowId.split('-')[1]);
if (index === -1) {
diff --git a/TC1/user_gpio.c b/TC1/user_gpio.c
index 2df2ed8..d529368 100644
--- a/TC1/user_gpio.c
+++ b/TC1/user_gpio.c
@@ -7,8 +7,7 @@
mico_gpio_t relay[Relay_NUM] = {Relay_0, Relay_1, Relay_2, Relay_3, Relay_4, Relay_5};
char socket_status[32] = {0};
-char short_click_config[32] = {0};
-char long_click_config[32] = {0};
+char btn_click_config[500] = {0};
void UserLedSet(char x) {
if (x == -1)
@@ -89,19 +88,24 @@ char *GetSocketStatus() {
return socket_status;
}
-char *GetShortClickConfig() {
- sprintf(short_click_config, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",
- get_short_func(user_config->user[1]),
- get_short_func(user_config->user[2]),
- get_short_func(user_config->user[3]),
- get_short_func(user_config->user[4]),
- get_short_func(user_config->user[5]),
- get_short_func(user_config->user[6]),
- get_short_func(user_config->user[7]),
- get_short_func(user_config->user[8]),
- get_short_func(user_config->user[9]),
- get_short_func(user_config->user[10]));
- return short_click_config;
+char *GetButtonClickConfig() {
+ char temp[32];
+ int len = 0;
+ int max_len =sizeof(btn_click_config);
+ len += snprintf(btn_click_config + len, max_len - len, "[");
+
+ for (int i = 1; i <= 30; i++) {
+ char short_func = get_short_func(user_config->user[i]);
+ char long_func = get_long_func(user_config->user[i]);
+
+ snprintf(temp, sizeof(temp), "{\"%d\":[%d,%d]}%s", i, short_func, long_func, (i != 30) ? "," : "");
+ len += snprintf(btn_click_config + len, max_len - len, "%s", temp);
+
+ if (len >= max_len - 1) break;
+ }
+ snprintf(btn_click_config + len, max_len - len, "]");
+
+ return btn_click_config;
}
void SetSocketStatus(char *socket_status) {
diff --git a/TC1/user_gpio.h b/TC1/user_gpio.h
index bc51a14..9926fe7 100644
--- a/TC1/user_gpio.h
+++ b/TC1/user_gpio.h
@@ -25,7 +25,7 @@ void UserRelaySet(unsigned char x, char y);
void UserRelaySetAll(char y);
bool RelayOut(void);
char* GetSocketStatus();
-char* GetShortClickConfig();
+char* GetButtonClickConfig();
void SetSocketStatus(char* socket_status);
void set_key_map(int index, char short_func, char long_func);
char get_short_func(char val);