diff --git a/TC1/http_server/app_httpd.c b/TC1/http_server/app_httpd.c index 249197a..3828924 100644 --- a/TC1/http_server/app_httpd.c +++ b/TC1/http_server/app_httpd.c @@ -149,7 +149,7 @@ static int HttpGetAssets(httpd_request_t *req) { static int HttpGetTc1Status(httpd_request_t *req) { char *sockets = GetSocketStatus(); - char *short_click_config = GetShortClickConfig(); + char *short_click_config = GetButtonClickConfig(); char *tc1_status = malloc(1024); char *socket_names = malloc(512); sprintf(socket_names, "%s,%s,%s,%s,%s,%s", @@ -215,7 +215,7 @@ static int HttpSetSocketName(httpd_request_t *req) { return err; } -static int HttpSetShortClickEvent(httpd_request_t *req) { +static int HttpSetButtonEvent(httpd_request_t *req) { OSStatus err = kNoErr; int buf_size = 10; @@ -225,8 +225,13 @@ static int HttpSetShortClickEvent(httpd_request_t *req) { require_noerr(err, exit); int index; int func; - sscanf(buf, "%d %d", &index, &func); - set_key_map(index + 1,func, get_long_func(index + 1)); + 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); + }else{ + set_key_map(index,func==-1?NO_FUNCTION:func, get_long_func(index)); + } mico_system_context_update(sys_config); send_http("OK", 2, exit, &err); @@ -298,7 +303,7 @@ static int HttpGetPowerInfo(httpd_request_t *req) { char *powers = GetPowerRecord(idx); char *sockets = GetSocketStatus(); - char *short_click_config = GetShortClickConfig(); + char *short_click_config = GetButtonClickConfig(); char *socket_names = malloc(512); sprintf(socket_names, "%s,%s,%s,%s,%s,%s", user_config->socket_names[0], @@ -457,9 +462,9 @@ static int HttpGetTasks(httpd_request_t *req) { return err; } -static int HttpGetShortClickEvents(httpd_request_t *req) { +static int HttpGetButtonEvents(httpd_request_t *req) { OSStatus err = kNoErr; - char *clicks = GetShortClickConfig(); + char *clicks = GetButtonClickConfig(); send_http(clicks, strlen(clicks), exit, &err); exit: @@ -625,7 +630,7 @@ const struct httpd_wsgi_call g_app_handlers[] = { {"/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}, - {"/shortClickEvent", HTTPD_HDR_DEFORT, 0, HttpGetShortClickEvents, HttpSetShortClickEvent, NULL, NULL}, + {"/buttonEvents", HTTPD_HDR_DEFORT, 0, HttpGetButtonEvents, HttpSetButtonEvent, NULL, NULL}, }; static int g_app_handlers_no = sizeof(g_app_handlers) / sizeof(struct httpd_wsgi_call); diff --git a/TC1/http_server/app_httpd.h b/TC1/http_server/app_httpd.h index 9e1dba9..aa4085f 100644 --- a/TC1/http_server/app_httpd.h +++ b/TC1/http_server/app_httpd.h @@ -68,10 +68,10 @@ 'socketNames':'%s',\ 'child_lock_enabled':%d,\ 'deviceName':'%s',\ - 'shortClicks':'%s'\ + 'btnClicks':'%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','shortClicks':'%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','btnClicks':'%s'}" int AppHttpdStart(void); diff --git a/TC1/http_server/web/index.html b/TC1/http_server/web/index.html index 764b5a2..b495846 100644 --- a/TC1/http_server/web/index.html +++ b/TC1/http_server/web/index.html @@ -91,6 +91,14 @@ 定时任务 + + + + + + 按键自定义 + + @@ -98,7 +106,7 @@ 系统状态 - + @@ -106,7 +114,7 @@ 在线升级 - + @@ -309,23 +317,6 @@ -
-
-
-
-

按键自定义

-
- - - - - -
按键类型执行操作
- -
-
-
-
@@ -543,7 +534,86 @@
-
+
+
+

按键自定义

+
+ + + + + + +
按键类型执行操作操作
+
+ +
+ + +
@@ -579,7 +649,7 @@ -
+

在线升级

@@ -600,7 +670,7 @@
-
+

系统日志

@@ -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 += ` + + + + + + `; + } + if(operations[1]!=-1){ + var valueText = (isNaN(operations[1]) || operations[1] < 0 || operations[1] >= BTN_OPERATIONS.length) ? '未设置' : BTN_OPERATIONS[operations[1]]; tb_html += ` - - + + + `; + } + } 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);
  • 版本
    按键类型执行操作执行动作操作
    ${times > 0 ? '连续' : ''}短按${times}次${valueText}删除
    ${i > 0 ? '连续' : ''}短按${i + 1}次 -
    - - -
      -
    • 未设置
    • - ${BTN_OPERATIONS.map((op, idx) => - `
    • ${op}
    • ` - ).join('')} -
    -
    -
    长按${times}秒${valueText}删除