支持配置多击,长按功能

This commit is contained in:
Your Name
2025-03-21 23:53:17 +08:00
parent 76e8612007
commit b470b0f8a0
4 changed files with 852 additions and 901 deletions

View File

@@ -227,11 +227,12 @@ static int HttpSetButtonEvent(httpd_request_t *req) {
int func;
int longPress;
sscanf(buf, "%d %d %d", &index, &func, &longPress);
if (longPress) {
set_key_map(index, get_short_func(index), func == -1 ? NO_FUNCTION : func);
if (longPress == 1) {
set_key_map(index, get_short_func(user_config->user[index]), func == -1 ? NO_FUNCTION : func);
} else {
set_key_map(index, func == -1 ? NO_FUNCTION : func, get_long_func(index));
set_key_map(index, func == -1 ? NO_FUNCTION : func, get_long_func(user_config->user[index]));
}
key_log("WARNGIN:set KEY func %d %d %d", index,get_short_func(user_config->user[index]),get_long_func(user_config->user[index]));
mico_system_context_update(sys_config);
send_http("OK", 2, exit, &err);
@@ -468,7 +469,6 @@ static int HttpGetButtonEvents(httpd_request_t *req) {
send_http(clicks, strlen(clicks), exit, &err);
exit:
if (clicks) free(clicks);
return err;
}

View File

@@ -88,7 +88,7 @@
<a class="mdl-navigation__link" href="javascript:ShowPage(4);">
<i class="mdl-color-text--blue-grey-400 material-icons" role="presentation">
<svg>
<use xlink:href="#icon-access_alarm"/>
<use xlink:href="#icon-settings"/>
</svg>
</i>
<span class="lang" langKey="TimedTask">按键自定义</span>
@@ -760,32 +760,6 @@
<path d="M0,0h24v24H0V0z" fill="none"/>
<path d="M19.14,12.94c0.04-0.3,0.06-0.61,0.06-0.94c0-0.32-0.02-0.64-0.07-0.94l2.03-1.58c0.18-0.14,0.23-0.41,0.12-0.61 l-1.92-3.32c-0.12-0.22-0.37-0.29-0.59-0.22l-2.39,0.96c-0.5-0.38-1.03-0.7-1.62-0.94L14.4,2.81c-0.04-0.24-0.24-0.41-0.48-0.41 h-3.84c-0.24,0-0.43,0.17-0.47,0.41L9.25,5.35C8.66,5.59,8.12,5.92,7.63,6.29L5.24,5.33c-0.22-0.08-0.47,0-0.59,0.22L2.74,8.87 C2.62,9.08,2.66,9.34,2.86,9.48l2.03,1.58C4.84,11.36,4.8,11.69,4.8,12s0.02,0.64,0.07,0.94l-2.03,1.58 c-0.18,0.14-0.23,0.41-0.12,0.61l1.92,3.32c0.12,0.22,0.37,0.29,0.59,0.22l2.39-0.96c0.5,0.38,1.03,0.7,1.62,0.94l0.36,2.54 c0.05,0.24,0.24,0.41,0.48,0.41h3.84c0.24,0,0.44-0.17,0.47-0.41l0.36-2.54c0.59-0.24,1.13-0.56,1.62-0.94l2.39,0.96 c0.22,0.08,0.47,0,0.59-0.22l1.92-3.32c0.12-0.22,0.07-0.47-0.12-0.61L19.14,12.94z M12,15.6c-1.98,0-3.6-1.62-3.6-3.6 s1.62-3.6,3.6-3.6s3.6,1.62,3.6,3.6S13.98,15.6,12,15.6z"/>
</g>
<g id="img-user">
<g id="#45d0e3ff">
<path fill="#45d0e3" opacity="1.00"
d=" M 53.37 0.00 L 58.72 0.00 C 75.08 0.90 90.91 9.14 100.69 22.33 C 107.50 31.24 111.31 42.21 112.00 53.37 L 112.00 58.70 C 111.04 78.61 98.79 97.47 80.82 106.17 C 79.54 103.27 78.19 100.38 77.13 97.38 C 75.96 93.10 74.50 88.08 76.95 83.97 C 78.90 80.30 84.37 81.15 86.26 77.47 C 87.78 74.72 88.75 71.72 89.88 68.80 C 86.87 67.57 83.95 65.94 82.84 62.67 C 85.41 62.55 87.97 62.56 90.54 62.54 C 90.73 60.46 90.80 58.37 90.97 56.28 C 92.50 56.26 94.04 56.25 95.57 56.24 C 94.14 51.38 93.20 46.39 92.61 41.36 C 91.85 37.14 91.80 32.46 89.06 28.93 C 85.66 24.42 80.36 21.79 75.00 20.42 C 66.49 18.22 57.44 19.54 49.32 22.59 C 48.22 21.70 47.13 20.79 46.00 19.93 C 45.67 19.83 45.02 19.63 44.70 19.53 C 38.54 17.36 31.82 18.95 26.65 22.71 C 21.75 25.72 19.50 31.39 18.56 36.82 C 16.07 51.25 18.52 66.10 15.49 80.46 C 14.80 83.83 13.17 86.89 11.40 89.80 C 4.55 80.87 0.71 69.87 0.00 58.67 L 0.00 53.27 C 0.72 42.15 4.52 31.22 11.31 22.34 C 21.10 9.12 36.98 0.86 53.37 0.00 Z"/>
<path fill="#45d0e3" opacity="1.00"
d=" M 46.81 58.85 C 48.67 60.66 50.63 62.36 52.52 64.14 C 53.51 65.97 54.72 67.81 54.84 69.95 C 55.32 75.99 54.64 82.26 51.85 87.72 C 47.89 95.43 41.52 101.46 36.56 108.49 C 29.02 105.67 22.14 101.21 16.39 95.59 C 21.92 95.26 27.23 93.08 31.33 89.33 C 40.12 81.50 43.93 69.90 46.81 58.85 Z"/>
</g>
<g id="#3e3e3eff">
<path fill="#3e3e3e" opacity="1.00"
d=" M 26.65 22.71 C 31.82 18.95 38.54 17.36 44.70 19.53 C 41.86 22.16 39.20 24.96 36.55 27.77 C 37.72 29.05 38.91 30.31 40.10 31.58 C 42.67 28.12 45.54 24.77 49.32 22.59 C 57.44 19.54 66.49 18.22 75.00 20.42 C 80.36 21.79 85.66 24.42 89.06 28.93 C 91.80 32.46 91.85 37.14 92.61 41.36 C 82.53 41.64 72.25 40.50 62.86 36.65 C 62.81 40.15 63.08 43.92 61.22 47.05 C 60.19 49.27 58.12 50.64 56.32 52.18 C 54.94 50.22 54.14 47.28 51.44 46.79 C 48.33 45.98 45.15 49.54 46.48 52.54 C 48.16 56.57 50.50 60.28 52.52 64.14 C 50.63 62.36 48.67 60.66 46.81 58.85 C 43.93 69.90 40.12 81.50 31.33 89.33 C 27.23 93.08 21.92 95.26 16.39 95.59 C 14.64 93.73 12.95 91.82 11.40 89.80 C 13.17 86.89 14.80 83.83 15.49 80.46 C 18.52 66.10 16.07 51.25 18.56 36.82 C 19.50 31.39 21.75 25.72 26.65 22.71 Z"/>
<path fill="#3e3e3e" opacity="1.00"
d=" M 83.41 50.49 C 84.92 48.75 86.28 50.47 85.90 52.21 C 84.56 52.87 82.99 52.19 83.41 50.49 Z"/>
</g>
<g id="#049d56ff">
<path fill="#049d56" opacity="1.00"
d=" M 44.70 19.53 C 45.02 19.63 45.67 19.83 46.00 19.93 C 47.13 20.79 48.22 21.70 49.32 22.59 C 45.54 24.77 42.67 28.12 40.10 31.58 C 38.91 30.31 37.72 29.05 36.55 27.77 C 39.20 24.96 41.86 22.16 44.70 19.53 Z"/>
</g>
<g id="#ffe1afff">
<path fill="#ffe1af" opacity="1.00"
d=" M 62.86 36.65 C 72.25 40.50 82.53 41.64 92.61 41.36 C 93.20 46.39 94.14 51.38 95.57 56.24 C 94.04 56.25 92.50 56.26 90.97 56.28 C 90.80 58.37 90.73 60.46 90.54 62.54 C 87.97 62.56 85.41 62.55 82.84 62.67 C 83.95 65.94 86.87 67.57 89.88 68.80 C 88.75 71.72 87.78 74.72 86.26 77.47 C 84.37 81.15 78.90 80.30 76.95 83.97 C 74.50 88.08 75.96 93.10 77.13 97.38 C 67.78 97.97 58.22 94.74 51.85 87.72 C 54.64 82.26 55.32 75.99 54.84 69.95 C 54.72 67.81 53.51 65.97 52.52 64.14 C 50.50 60.28 48.16 56.57 46.48 52.54 C 45.15 49.54 48.33 45.98 51.44 46.79 C 54.14 47.28 54.94 50.22 56.32 52.18 C 58.12 50.64 60.19 49.27 61.22 47.05 C 63.08 43.92 62.81 40.15 62.86 36.65 M 83.41 50.49 C 82.99 52.19 84.56 52.87 85.90 52.21 C 86.28 50.47 84.92 48.75 83.41 50.49 Z"/>
</g>
<g id="#fe5606ff">
<path fill="#fe5606" opacity="1.00"
d=" M 36.56 108.49 C 41.52 101.46 47.89 95.43 51.85 87.72 C 58.22 94.74 67.78 97.97 77.13 97.38 C 78.19 100.38 79.54 103.27 80.82 106.17 C 73.65 109.79 65.69 111.59 57.70 112.00 L 54.26 112.00 C 48.24 111.64 42.22 110.63 36.56 108.49 Z"/>
</g>
</g>
</defs>
</svg>
@@ -821,6 +795,7 @@
$(this).html(val);
});
}
var BTN_OPERATIONS=["切换总开关"];
//弹框-start
var snackbarContainer = document.querySelector('#demo-toast-example');
function ShowToast(mess) {
@@ -971,18 +946,15 @@
$("#info_gateway").html(status.gateway);
$("#uptime").html(status.up_time);
var actions=status.btnClicks;
//按键操作功能定义
var BTN_OPERATIONS=["切换总开关"];
for (var i = 0; i < names_arr.length; i++) {
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(
$('#btn_action_selector').append(
$('<li>')
.addClass('mdl-menu__item')
.attr('data-val', -1)
@@ -998,6 +970,11 @@ $('#btn_action_selector').append(
}
getmdlSelect.init(".getmdl-select");
refreshButtonEvents(status.btnClicks);
});
function refreshButtonEvents(actions){
var tb_html = `
<tr>
<th>按键类型</th>
@@ -1006,12 +983,13 @@ var tb_html = `
</tr>
`;
var cnt=0;
for (var i = 0; i < actions.length; i++) {
var rowId = `select-${i}`;
var times = Object.keys(actions[i])[0];
var operations = Object.values(actions[i])[0];
if(operations[0]!=-1){
cnt++;
var valueText = (isNaN(operations[0]) || operations[0] < 0 || operations[0] >= BTN_OPERATIONS.length) ? '未设置' : BTN_OPERATIONS[operations[0]];
tb_html += `
<tr>
@@ -1022,6 +1000,7 @@ for (var i = 0; i < actions.length; i++) {
`;
}
if(operations[1]!=-1){
cnt++;
var valueText = (isNaN(operations[1]) || operations[1] < 0 || operations[1] >= BTN_OPERATIONS.length) ? '未设置' : BTN_OPERATIONS[operations[1]];
tb_html += `
@@ -1034,14 +1013,12 @@ for (var i = 0; i < actions.length; i++) {
}
}
if (actions.length == 0) {
if (cnt == 0) {
tb_html += "<tr><td colspan='5'>没有自定义按键动作</td></tr>";
}
document.getElementById("short_click_events_tb").innerHTML = tb_html;
componentHandler.upgradeDom();
});
}
$(".mdl-switch__input").on("click", function() {
if("list-switch-all" == this.id||"list-switch-child-lock"== this.id||"task_on"== this.id){
@@ -1388,7 +1365,12 @@ componentHandler.upgradeDom();
}, cmd);
}
$('#button_type').on('input', function() {
$(document).ready(function(){
$('ul[for="button_type"] .mdl-menu__item').on('click',function(){
$('#button_type').trigger('change');
});
});
$('#button_type').on('change', function() {
var value = $(this).val();
$('#click_times_press_time_label').text(value == '0'?'连击次数':'长按秒数');
});
@@ -1403,22 +1385,37 @@ componentHandler.upgradeDom();
}
getmdlSelect.init(".getmdl-select");
});
function getButtonEvents(){
HttpGet("/buttonEvents", function (re) {
refreshButtonEvents(JSON.parse(re));
});
}
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;
var event = document.getElementById("action_type").value;
var times_or_seconds = document.getElementById("click_times_press_time").value;
if(!event||!times_or_seconds){
ShowToast("请完成选项");
return;
}
HttpPost("/buttonEvents", function (re) {
if (re == "OK") {
ShowToast("已添加按事件");
ShowToast("已添加按事件");
getButtonEvents();
}
}, `${times_or_seconds} ${event} ${longPress}`);
}
function deleteButtonEvent(times_or_seconds ,longPress){
HttpPost("/buttonEvents", function (re) {
if (re == "OK") {
ShowToast("已删除按事件");
ShowToast("已删除按事件");
getButtonEvents();
}
}, `${times_or_seconds} -1 ${longPress}`);
}

File diff suppressed because it is too large Load Diff

View File

@@ -97,6 +97,7 @@ char *GetButtonClickConfig() {
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]);
// key_log("WARNGIN:KEY func %d %d %d", i,short_func,long_func);
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);
@@ -189,8 +190,8 @@ static void KeyEventHandler(int num, boolean longPress) {
case SWITCH_SOCKET_4:
case SWITCH_SOCKET_5:
case SWITCH_SOCKET_6:
UserRelaySet(user_config->user[num] - 1, Relay_TOGGLE);
UserMqttSendSocketState(user_config->user[num] - 1);
UserRelaySet(function - 1, Relay_TOGGLE);
UserMqttSendSocketState(function - 1);
UserMqttSendTotalSocketState();
mico_system_context_update(sys_config);
break;