#include "key_functions_setting.h" //KEY_SETTING uint8_t log_page = 1; //输入/输出记录页面的页码 uint8_t setting_window_cursor = 0, setting_window_cursor_prv = 0; //弹窗内的游标 void key_functions_setting(void) { if( key_pv.status == KEY_STATUS_DISABLE ) return; //临时游标,替代枚举变量进行加减运算 uint8_t cursor_temp = 0; uint8_t cursor_start = 0; uint8_t cursor_end = 0; switch (key_pv.tag) { case KEY_BACK: { key = 0; key_char2struct(); switch (current_operation) { case SET_ITEM_CHOOSE: { //加载主界面 if(!scr_main_set_flag) { scr_main_set_flag = 1; setup_scr_screen_main(&guider_ui); delay_cnt(200); //不加延时有概率卡死 } scr_main_recover(); lv_scr_load(guider_ui.screen_main); lv_obj_clear_flag(guider_ui.screen_main, LV_OBJ_FLAG_HIDDEN); //隐藏设置界面对象 lv_obj_add_flag(guider_ui.screen_setting, LV_OBJ_FLAG_HIDDEN); menu_data.scr_now = SCREEN_MAIN; //当前操作从“选项卡选择” 返回 至“主要功能”,按键配置同步更新 current_operation = MAIN_FUNCTION; key_config_update(current_operation); } break; case SET_CONTENT_CHOOSE: { //熄灭当前选中的内容 setting_contents_check(99, tabdata.content_cursor); //取消内容选中与焦点 tabdata.content_cursor = 0; tabdata.content_cursor_prv = 99; tabdata.item_page = 1; tabdata.item_page_prv = 1; tabdata.content_focus = 0; //当前操作从“内容选择” 返回 至“选项卡选择”,按键配置同步更新 current_operation = SET_ITEM_CHOOSE; key_config_update(current_operation); } break; case SET_CONTENT_MODIFY: { //当存在焦点时,取消焦点,返回内容选择 tabdata.content_focus = 0; setting_contents_check(tabdata.content_cursor, CONTENT_EMPTY); //更新当前游标所在内容的文本(焦点前后不一致) tabdata.current_content = content_cur_char2enum(tabdata.item_cursor ,tabdata.content_cursor); switch (tabdata.item_cursor) { case ITEM_0: { set_item0_text(tabdata.current_content); if(tabdata.current_content == VOL_UNIT_SET) { set_item0_text(VOL_UP_SET); set_item0_text(VOL_LOW_SET); } if(tabdata.current_content == TC_TYPE_SET) { set_item0_text(TC_UP_SET); set_item0_text(TC_LOW_SET); } } break; case ITEM_1: { set_item1_text(tabdata.current_content); } break; case ITEM_2: { set_item2_text(tabdata.current_content); } break; case ITEM_3: { set_item3_text(tabdata.current_content); } break; default: break; } tabdata.current_content = CONTENT_EMPTY; //当前操作从“内容修改” 返回 至“内容选择”,按键配置同步更新 current_operation = SET_CONTENT_CHOOSE; key_config_update(current_operation); } break; case SET_WINDOW_MODIFY: { lv_obj_add_flag(guider_ui.screen_setting_window_set, LV_OBJ_FLAG_HIDDEN); //熄灭游标 setting_window_num_check(99, setting_window_cursor); setting_window_cursor = 3; setting_window_cursor_prv = 99; //取消焦点 tabdata.content_focus = 0; setting_contents_check(tabdata.content_cursor, tabdata.content_cursor_prv); //更新文本 setting_window2val(); set_item0_text(tabdata.current_content); current_operation = SET_CONTENT_CHOOSE; key_config_update(current_operation); } break; case SET_SHOW_LOG: { //恢复至原本页面 setting_items_page(ITEM_2, 1); tabdata.content_focus = 0; setting_contents_check(tabdata.content_cursor, tabdata.content_cursor_prv); //当前操作从“查看记录” 返回 至“内容选择”,按键配置同步更新 current_operation = SET_CONTENT_CHOOSE; key_config_update(current_operation); } break; case SET_COMMUNICATION_SWITCH: { //恢复至原本页面 setting_contents_check(99, com_switch_cursor); setting_items_page(ITEM_2, 1); tabdata.content_focus = 0; setting_contents_check(tabdata.content_cursor, tabdata.content_cursor_prv); //当前操作从“查看记录” 返回 至“内容选择”,按键配置同步更新 current_operation = SET_CONTENT_CHOOSE; key_config_update(current_operation); } break; case SET_COMMUNICATION_MODIFY: { tabdata.content_focus = 0; setting_contents_check(com_switch_cursor, com_switch_cursor_prv); set_communication_text(com_switch_cursor); current_operation = SET_COMMUNICATION_SWITCH; key_config_update(current_operation); } break; default: break; } } break; case KEY_UP: { key = 0; key_char2struct(); switch (current_operation) { case SET_ITEM_CHOOSE: { cursor_start = (uint8_t)ITEM_0; cursor_end = (uint8_t)ITEM_3; cursor_temp = (uint8_t)tabdata.item_cursor; cursor_temp = (cursor_temp <= cursor_start)?(cursor_end):(cursor_temp - 1); tabdata.item_cursor_prv = tabdata.item_cursor; tabdata.item_cursor = (ITEMS)cursor_temp; //更新文本 setting_items_check(tabdata.item_cursor, tabdata.item_cursor_prv); } break; case SET_CONTENT_CHOOSE: { switch (tabdata.item_cursor) { case ITEM_0: { cursor_start = 0; cursor_end = 5; } break; case ITEM_1: { cursor_start = 0; cursor_end = 3; } break; case ITEM_2: { cursor_start = 0; cursor_end = 3; } break; case ITEM_3: { cursor_start = 0; cursor_end = 3; } break; default: break; } cursor_temp = tabdata.content_cursor; cursor_temp = ( cursor_temp <= cursor_start)?(cursor_end):(cursor_temp - 1); tabdata.content_cursor_prv = tabdata.content_cursor; tabdata.content_cursor = cursor_temp; setting_contents_check(tabdata.content_cursor, tabdata.content_cursor_prv); } break; case SET_WINDOW_MODIFY: { //增加弹窗内指定数字的值 if(setting_window_cursor == 4) { setting_window_num[setting_window_cursor] = !setting_window_num[setting_window_cursor]; } else { setting_window_num[setting_window_cursor] += 1; if( setting_window_num[setting_window_cursor] > 9 ) setting_window_num[setting_window_cursor] = 0; } setting_window_set_num(setting_window_cursor); } break; case SET_COMMUNICATION_SWITCH: { cursor_start = 0; cursor_end = 3; cursor_temp = com_switch_cursor; cursor_temp = ( cursor_temp <= cursor_start)?(cursor_end):(cursor_temp - 1); com_switch_cursor_prv = com_switch_cursor; com_switch_cursor = cursor_temp; setting_contents_check(com_switch_cursor, com_switch_cursor_prv); } break; default: break; } } break; case KEY_DOWN: { key = 0; key_char2struct(); switch (current_operation) { case SET_ITEM_CHOOSE: { cursor_start = (uint8_t)ITEM_0; cursor_end = (uint8_t)ITEM_3; cursor_temp = (uint8_t)tabdata.item_cursor; cursor_temp = (cursor_temp >= cursor_end)?(cursor_start):(cursor_temp + 1); tabdata.item_cursor_prv = tabdata.item_cursor; tabdata.item_cursor = (ITEMS)cursor_temp; setting_items_check(tabdata.item_cursor, tabdata.item_cursor_prv); } break; case SET_CONTENT_CHOOSE: { switch (tabdata.item_cursor) { case ITEM_0: { cursor_start = 0; cursor_end = 5; } break; case ITEM_1: { cursor_start = 0; cursor_end = 3; } break; case ITEM_2: { cursor_start = 0; cursor_end = 3; } break; case ITEM_3: { cursor_start = 0; cursor_end = 3; } break; default: break; } cursor_temp = tabdata.content_cursor; cursor_temp = ( cursor_temp >= cursor_end)?(cursor_start):(cursor_temp + 1); tabdata.content_cursor_prv = tabdata.content_cursor; tabdata.content_cursor = cursor_temp; setting_contents_check(tabdata.content_cursor, tabdata.content_cursor_prv); } break; case SET_WINDOW_MODIFY: { //减小弹窗内指定数字的值 if(setting_window_cursor == 4) { setting_window_num[setting_window_cursor] = !setting_window_num[setting_window_cursor]; } else { setting_window_num[setting_window_cursor] -= 1; if( setting_window_num[setting_window_cursor] > 200 ) setting_window_num[setting_window_cursor] = 9; } //更新文本 setting_window_set_num(setting_window_cursor); } break; case SET_COMMUNICATION_SWITCH: { cursor_start = 0; cursor_end = 3; cursor_temp = com_switch_cursor; cursor_temp = ( cursor_temp >= cursor_end)?(cursor_start):(cursor_temp + 1); com_switch_cursor_prv = com_switch_cursor; com_switch_cursor = cursor_temp; setting_contents_check(com_switch_cursor, com_switch_cursor_prv); } break; default: break; } } break; case KEY_OK: { key = 0; key_char2struct(); switch (current_operation) { case SET_ITEM_CHOOSE: { //选中某个选项卡后,点亮该选项卡内的第一个内容 tabdata.content_cursor = 0; tabdata.content_cursor_prv = 99; setting_contents_check(tabdata.content_cursor, tabdata.content_cursor_prv); //当前操作从“选项卡选择” 切换 至“内容选择”,按键配置同步更新 current_operation = SET_CONTENT_CHOOSE; key_config_update(current_operation); } break; case SET_CONTENT_CHOOSE: { //选中选项卡内的某个内容后,焦点当前选中内容 tabdata.content_focus = 1; setting_contents_check(tabdata.content_cursor, tabdata.content_cursor_prv); //焦点后更新所选内容的文本 tabdata.current_content = content_cur_char2enum(tabdata.item_cursor, tabdata.content_cursor); switch (tabdata.item_cursor) { case ITEM_0: { if( setting_window_display() == 0 ) { set_item0_text(tabdata.current_content); //当前操作从“内容选择” 切换 至“内容修改”,按键配置同步更新 current_operation = SET_CONTENT_MODIFY; key_config_update(current_operation); } else { //点亮窗口内游标,游标从第3位开始 setting_window_cursor = 3; setting_window_cursor_prv = 99; setting_window_num_check(setting_window_cursor, setting_window_cursor_prv); //当前操作从“内容选择” 切换 至“弹窗修改”,按键配置同步更新 current_operation = SET_WINDOW_MODIFY; key_config_update(current_operation); } } break; case ITEM_1: { set_item1_text(tabdata.current_content); //当前操作从“内容选择” 切换 至“内容修改”,按键配置同步更新 current_operation = SET_CONTENT_MODIFY; key_config_update(current_operation); } break; case ITEM_2: { switch (tabdata.current_content) { case INPUT_LOG: { lv_obj_set_style_bg_color(guider_ui.screen_setting_label_01, lv_color_hex(COLOR_ITEMS_UNCHECKED), LV_PART_MAIN|LV_STATE_DEFAULT); show_IO_log(IO_INPUT, 1); //当前操作从“内容选择” 切换 至“查看记录”,按键配置同步更新 current_operation = SET_SHOW_LOG; key_config_update(current_operation); } break; case OUTPUT_LOG: { lv_obj_set_style_bg_color(guider_ui.screen_setting_label_11, lv_color_hex(COLOR_ITEMS_UNCHECKED), LV_PART_MAIN|LV_STATE_DEFAULT); show_IO_log(IO_OUTPUT, 1); //当前操作从“内容选择” 切换 至“查看记录”,按键配置同步更新 current_operation = SET_SHOW_LOG; key_config_update(current_operation); } break; case COMMUNICATION: { tabdata.content_focus = 0; lv_obj_set_style_bg_color(guider_ui.screen_setting_label_21, lv_color_hex(COLOR_ITEMS_UNCHECKED), LV_PART_MAIN|LV_STATE_DEFAULT); communication_switch(); current_operation = SET_COMMUNICATION_SWITCH; key_config_update(current_operation); } break; case PROGRAM_OUTPUT: {} break; default: break; } } break; case ITEM_3: { set_item3_text(tabdata.current_content); //当前操作从“内容选择” 切换 至“内容修改”,按键配置同步更新 current_operation = SET_CONTENT_MODIFY; key_config_update(current_operation); } break; default: break; } } break; case SET_COMMUNICATION_SWITCH: { if(com_switch_cursor != TEXT_MODBUS_CONFIG) { tabdata.content_focus = 1; setting_contents_check(com_switch_cursor, com_switch_cursor_prv); set_communication_text(com_switch_cursor); current_operation = SET_COMMUNICATION_MODIFY; key_config_update(current_operation); } else if( tabdata.modbus_type == SIG_MASTER) { //【主界面, 设置界面】共用一块内存空间,两者之间通过隐藏&显示切换 //【Modbus主站配置界面, Modbus主站收发界面】共用一块内存空间,两者之间通过隐藏&显示切换 //设置界面 -> Modbus主站配置界面时,立即删除主界面对象,异步删除设置界面,加载配置界面,切换至收发界面时再加载收发界面对象 //设置界面 <- Modbus主站配置界面时,立即删除收发界面对象,异步删除配置界面,加载设置界面,切换至主界面时再加载主界面对象 tabdata.content_focus = 0; lv_obj_set_style_bg_color(guider_ui.screen_setting_label_31, lv_color_hex(COLOR_ITEMS_UNCHECKED), LV_PART_MAIN|LV_STATE_DEFAULT); //立即删除主界面的相关内容,释放内存 if(scr_main_set_flag) { //加载过的情况下才能删除,否则会进入硬件错误中断。 scr_main_set_flag = 0; lv_obj_del(guider_ui.screen_main); } //设置modbus配置界面的内容 setup_scr_screen_modbus_config(&guider_ui); scr_modbus_config_recover(); delay_cnt(200); //不加延时有概率卡死 lv_scr_load(guider_ui.screen_modbus_config); //加载界面 menu_data.scr_now = SCREEN_MODBUS_MASTER_CONFIG; //异步删除设置界面,更加安全 lv_obj_del_async(guider_ui.screen_setting); //当前操作变更为MODBUS主站配置 current_operation = MODBUS_MASTER_CONFIG; key_config_update(current_operation); } } break; default: break; } } break; case KEY_LEFT: { key = 0; key_char2struct(); switch (current_operation) { case SET_CONTENT_CHOOSE: { //不存在焦点时,执行翻页操作 switch (tabdata.item_cursor) { case ITEM_0: { tabdata.item_page_prv = tabdata.item_page; tabdata.item_page = ( tabdata.item_page <= 1)?(I0_PAGE_MAX):(tabdata.item_page - 1); setting_items_page(ITEM_0, tabdata.item_page); //翻页后熄灭原本的游标 setting_contents_check(99, tabdata.content_cursor); //翻页后点亮新的一页的第一个内容 tabdata.content_cursor = 0; tabdata.content_cursor_prv = 99; setting_contents_check(tabdata.content_cursor, tabdata.content_cursor_prv); } break; case ITEM_1: {} break; case ITEM_2: {} break; case ITEM_3: {} break; default: break; } } break; case SET_CONTENT_MODIFY: { //存在焦点后,修改内容 tabdata.current_content = content_cur_char2enum(tabdata.item_cursor, tabdata.content_cursor); setting_contents_modify(tabdata.item_cursor, tabdata.current_content, -1); } break; case SET_WINDOW_MODIFY: { //向左移动弹窗内游标 setting_window_cursor_prv = setting_window_cursor; setting_window_cursor -= 1; if(setting_window_cursor > 200) setting_window_cursor = 4; setting_window_num_check(setting_window_cursor, setting_window_cursor_prv); } break; case SET_SHOW_LOG: { //查看记录 if( tabdata.current_content == INPUT_LOG ) { log_page--; if(log_page > 10) log_page = 1; if(log_page < 1) log_page = 10; show_IO_log(IO_INPUT, log_page); return; } if (tabdata.current_content == OUTPUT_LOG) { log_page--; if(log_page > 10) log_page = 1; if(log_page < 1) log_page = 10; show_IO_log(IO_OUTPUT, log_page); return; } } break; case SET_COMMUNICATION_MODIFY: { set_communication_modify(com_switch_cursor, -1); set_communication_text(com_switch_cursor); } break; default: break; } } break; case KEY_RIGHT: { key = 0; key_char2struct(); switch (current_operation) { case SET_CONTENT_CHOOSE: { //翻页 switch (tabdata.item_cursor) { case ITEM_0: { tabdata.item_page_prv = tabdata.item_page; tabdata.item_page = ( tabdata.item_page >= I0_PAGE_MAX)?(1):(tabdata.item_page + 1); setting_items_page(ITEM_0, tabdata.item_page); //翻页后熄灭原本的游标 setting_contents_check(99, tabdata.content_cursor); //翻页后点亮新的一页的第一个内容 tabdata.content_cursor = 0; tabdata.content_cursor_prv = 99; setting_contents_check(tabdata.content_cursor, tabdata.content_cursor_prv); } break; case ITEM_1: {} break; case ITEM_2: {} break; case ITEM_3: {} break; default: break; } } break; case SET_CONTENT_MODIFY: { //存在焦点后,修改内容 tabdata.current_content = content_cur_char2enum(tabdata.item_cursor, tabdata.content_cursor); setting_contents_modify(tabdata.item_cursor, tabdata.current_content, 1); } break; case SET_WINDOW_MODIFY: { //向右移动弹窗内游标 setting_window_cursor_prv = setting_window_cursor; setting_window_cursor += 1; if(setting_window_cursor > 4) setting_window_cursor = 0; setting_window_num_check(setting_window_cursor, setting_window_cursor_prv); } break; case SET_SHOW_LOG: { //查看记录 if( tabdata.current_content == INPUT_LOG ) { log_page++; if(log_page > 10) log_page = 1; if(log_page < 1) log_page = 10; show_IO_log(IO_INPUT, log_page); return; } if (tabdata.current_content == OUTPUT_LOG) { log_page++; if(log_page > 10) log_page = 1; if(log_page < 1) log_page = 10; show_IO_log(IO_OUTPUT, log_page); return; } } break; case SET_COMMUNICATION_MODIFY: { set_communication_modify(com_switch_cursor, 1); set_communication_text(com_switch_cursor); } break; default: break; } } break; case KEY_NONE: { } default: { key = 0; key_char2struct(); } break; } }