#include "app_screen_setting_trans.h" //设置界面中,通讯选择的游标 uint8_t com_switch_cursor = 0; uint8_t com_switch_cursor_prv = 99; //modbus配置项的游标 MOD_CONF_ITEMS mod_mas_conf_cursor = MOD_CONF_SLAVE_ID; MOD_CONF_ITEMS mod_mas_conf_cursor_prv = MOD_CONF_NONE; uint8_t config_focus = 0; //modbus收发界面的选项游标 MOD_TRX_ITEMS mod_mas_trx_cursor = MOD_TRX_PREVIOUS; MOD_TRX_ITEMS mod_mas_trx_cursor_prv = MOD_TRX_NONE; uint8_t trx_focus = 0; void set_communication_text(uint8_t con) { char str_temp[32] = {0}; switch (con) { case TEXT_HART: { if(tabdata.content_focus == 0) { if(tabdata.hart_enable) { lv_label_set_text(guider_ui.screen_setting_label_01, text_pack.item_2_com_val[0]); } else { lv_label_set_text(guider_ui.screen_setting_label_01, text_pack.item_2_com_val[1]); } } else { if(tabdata.hart_enable) { sprintf(str_temp,"< %s >",text_pack.item_2_com_val[0]); } else { sprintf(str_temp,"< %s >",text_pack.item_2_com_val[1]); } lv_label_set_text(guider_ui.screen_setting_label_01, str_temp); } } break; case TEXT_BLE: { if(tabdata.content_focus == 0) { if(tabdata.bluetooth_enable) { lv_label_set_text(guider_ui.screen_setting_label_11, text_pack.item_2_com_val[0]); } else { lv_label_set_text(guider_ui.screen_setting_label_11, text_pack.item_2_com_val[1]); } } else { if(tabdata.bluetooth_enable) { sprintf(str_temp,"< %s >",text_pack.item_2_com_val[0]); } else { sprintf(str_temp,"< %s >",text_pack.item_2_com_val[1]); } lv_label_set_text(guider_ui.screen_setting_label_11, str_temp); } } break; case TEXT_MODBUS: { if(tabdata.content_focus == 0) { if(tabdata.modbus_enable) { if(tabdata.modbus_type == SIG_SLAVE) { lv_label_set_text(guider_ui.screen_setting_label_21, text_pack.item_2_com_val[3]); lv_label_set_text(guider_ui.screen_setting_label_31, "---"); } else { lv_label_set_text(guider_ui.screen_setting_label_21, text_pack.item_2_com_val[2]); lv_label_set_text(guider_ui.screen_setting_label_31, ">"); } } else { lv_label_set_text(guider_ui.screen_setting_label_21, text_pack.item_2_com_val[1]); lv_label_set_text(guider_ui.screen_setting_label_31, "---"); } } else { if(tabdata.modbus_enable) { if(tabdata.modbus_type == SIG_SLAVE) { sprintf(str_temp,"< %s >", text_pack.item_2_com_val[3]); lv_label_set_text(guider_ui.screen_setting_label_31, "---"); } else { sprintf(str_temp,"< %s >", text_pack.item_2_com_val[2]); lv_label_set_text(guider_ui.screen_setting_label_31, ">"); } } else { sprintf(str_temp,"< %s >", text_pack.item_2_com_val[1]); lv_label_set_text(guider_ui.screen_setting_label_31, "---"); } lv_label_set_text(guider_ui.screen_setting_label_21, str_temp); } } break; default: break; } } void communication_switch(void) { //启用所需组件 if( lv_obj_has_flag(guider_ui.screen_setting_label_00, LV_OBJ_FLAG_HIDDEN) ) { lv_obj_clear_flag(guider_ui.screen_setting_label_00, LV_OBJ_FLAG_HIDDEN); }; if( lv_obj_has_flag(guider_ui.screen_setting_label_01, LV_OBJ_FLAG_HIDDEN) ) { lv_obj_clear_flag(guider_ui.screen_setting_label_01, LV_OBJ_FLAG_HIDDEN); }; if( lv_obj_has_flag(guider_ui.screen_setting_label_10, LV_OBJ_FLAG_HIDDEN) ) { lv_obj_clear_flag(guider_ui.screen_setting_label_10, LV_OBJ_FLAG_HIDDEN); }; if( lv_obj_has_flag(guider_ui.screen_setting_label_11, LV_OBJ_FLAG_HIDDEN) ) { lv_obj_clear_flag(guider_ui.screen_setting_label_11, LV_OBJ_FLAG_HIDDEN); }; if( lv_obj_has_flag(guider_ui.screen_setting_label_20, LV_OBJ_FLAG_HIDDEN) ) { lv_obj_clear_flag(guider_ui.screen_setting_label_20, LV_OBJ_FLAG_HIDDEN); }; if( lv_obj_has_flag(guider_ui.screen_setting_label_21, LV_OBJ_FLAG_HIDDEN) ) { lv_obj_clear_flag(guider_ui.screen_setting_label_21, LV_OBJ_FLAG_HIDDEN); }; if( lv_obj_has_flag(guider_ui.screen_setting_label_30, LV_OBJ_FLAG_HIDDEN) ) { lv_obj_clear_flag(guider_ui.screen_setting_label_30, LV_OBJ_FLAG_HIDDEN); }; if( lv_obj_has_flag(guider_ui.screen_setting_label_31, LV_OBJ_FLAG_HIDDEN) ) { lv_obj_clear_flag(guider_ui.screen_setting_label_31, LV_OBJ_FLAG_HIDDEN); }; //隐藏多余组件 lv_obj_add_flag(guider_ui.screen_setting_label_40, LV_OBJ_FLAG_HIDDEN); lv_obj_add_flag(guider_ui.screen_setting_label_41, LV_OBJ_FLAG_HIDDEN); lv_obj_add_flag(guider_ui.screen_setting_label_50, LV_OBJ_FLAG_HIDDEN); lv_obj_add_flag(guider_ui.screen_setting_label_51, LV_OBJ_FLAG_HIDDEN); //显示左列文本 lv_label_set_text(guider_ui.screen_setting_label_00, text_pack.item_2_com[0]); lv_label_set_text(guider_ui.screen_setting_label_10, text_pack.item_2_com[1]); lv_label_set_text(guider_ui.screen_setting_label_20, text_pack.item_2_com[2]); lv_label_set_text(guider_ui.screen_setting_label_30, text_pack.item_2_com[3]); //根据当前使能状态显示右列文本 set_communication_text(TEXT_HART); set_communication_text(TEXT_BLE); set_communication_text(TEXT_MODBUS); com_switch_cursor = 0; com_switch_cursor_prv = 99; setting_contents_check(com_switch_cursor, com_switch_cursor_prv); } void config_items_set_color(MOD_CONF_ITEMS cur, uint32_t color) { switch (cur) { case MOD_CONF_SLAVE_ID: { lv_obj_set_style_bg_color(guider_ui.screen_modbus_config_value_device_addr, lv_color_hex(color), LV_PART_MAIN|LV_STATE_DEFAULT); } break; case MOD_CONF_START_ADDRESS: { lv_obj_set_style_bg_color(guider_ui.screen_modbus_config_value_start_addr, lv_color_hex(color), LV_PART_MAIN|LV_STATE_DEFAULT); } break; case MOD_CONF_BYTES: { lv_obj_set_style_bg_color(guider_ui.screen_modbus_config_value_bytes, lv_color_hex(color), LV_PART_MAIN|LV_STATE_DEFAULT); } break; case MOD_CONF_TIMEOUT: { lv_obj_set_style_bg_color(guider_ui.screen_modbus_config_value_timeout, lv_color_hex(color), LV_PART_MAIN|LV_STATE_DEFAULT); } break; case MOD_CONF_COMMAND: { lv_obj_set_style_bg_color(guider_ui.screen_modbus_config_value_cmd, lv_color_hex(color), LV_PART_MAIN|LV_STATE_DEFAULT); } break; case MOD_CONF_REGISTER_NUM: { lv_obj_set_style_bg_color(guider_ui.screen_modbus_config_value_register_num, lv_color_hex(color), LV_PART_MAIN|LV_STATE_DEFAULT); } break; case MOD_CONF_CALIBRATION: { lv_obj_set_style_bg_color(guider_ui.screen_modbus_config_value_calibration, lv_color_hex(color), LV_PART_MAIN|LV_STATE_DEFAULT); } break; case MOD_CONF_NEXT: { lv_obj_set_style_bg_color(guider_ui.screen_modbus_config_value_next, lv_color_hex(color), LV_PART_MAIN|LV_STATE_DEFAULT); } break; default: break; } } void config_items_check(MOD_CONF_ITEMS cur, MOD_CONF_ITEMS cur_prv) { uint32_t color = 0; if(config_focus == 1) { color = COLOR_CONTENTS_FOCUSED; } else { color = COLOR_CONTENTS_CHECKED; } //点亮cur config_items_set_color(cur, color); //熄灭cur——prv config_items_set_color(cur_prv, COLOR_ITEMS_UNCHECKED); } void trx_items_set_color(MOD_TRX_ITEMS cur, uint32_t color) { switch (cur) { case MOD_TRX_DATA: { lv_obj_set_style_bg_color(guider_ui.screen_modbus_display_value_Data, lv_color_hex(color), LV_PART_MAIN|LV_STATE_DEFAULT); } break; case MOD_TRX_PREVIOUS: { lv_obj_set_style_bg_color(guider_ui.screen_modbus_display_label_previous, lv_color_hex(color), LV_PART_MAIN|LV_STATE_DEFAULT); } break; case MOD_TRX_SET: { lv_obj_set_style_bg_color(guider_ui.screen_modbus_display_label_set, lv_color_hex(color), LV_PART_MAIN|LV_STATE_DEFAULT); } break; case MOD_TRX_SEND: { lv_obj_set_style_bg_color(guider_ui.screen_modbus_display_label_send, lv_color_hex(color), LV_PART_MAIN|LV_STATE_DEFAULT); } break; default: break; } } void trx_items_check(MOD_TRX_ITEMS cur, MOD_TRX_ITEMS cur_prv) { uint32_t color = 0; if(trx_focus == 1) { color = COLOR_CONTENTS_FOCUSED; } else { color = COLOR_CONTENTS_CHECKED; } //点亮cur trx_items_set_color(cur, color); //熄灭cur——prv trx_items_set_color(cur_prv, COLOR_ITEMS_UNCHECKED); } void set_communication_modify(uint8_t con, int8_t step) { switch (con) { case TEXT_HART: { tabdata.hart_enable = !tabdata.hart_enable; //通讯方式互斥 if(tabdata.hart_enable) { tabdata.bluetooth_enable = 0; tabdata.modbus_enable = 0; tabdata.content_focus = 0; set_communication_text(TEXT_BLE); set_communication_text(TEXT_MODBUS); tabdata.content_focus = 1; } } break; case TEXT_BLE: { tabdata.bluetooth_enable = !tabdata.bluetooth_enable; //通讯方式互斥 if(tabdata.bluetooth_enable) { tabdata.hart_enable = 0; tabdata.modbus_enable = 0; tabdata.content_focus = 0; set_communication_text(TEXT_HART); set_communication_text(TEXT_MODBUS); tabdata.content_focus = 1; } } break; case TEXT_MODBUS: { tabdata.modbus_enable += step; if( ( 2 < tabdata.modbus_enable )&&(tabdata.modbus_enable < 200) ) tabdata.modbus_enable = 0; if(tabdata.modbus_enable > 200) tabdata.modbus_enable = 2; if(tabdata.modbus_enable == 2) { tabdata.modbus_type = SIG_MASTER; } else { tabdata.modbus_type = SIG_SLAVE; } //通讯方式互斥 if(tabdata.modbus_enable) { tabdata.hart_enable = 0; tabdata.bluetooth_enable = 0; tabdata.content_focus = 0; set_communication_text(TEXT_HART); set_communication_text(TEXT_BLE); tabdata.content_focus = 1; } } break; default: break; } } void scr_modbus_config_recover(void) { lv_label_set_text(guider_ui.screen_modbus_config_label_title, text_pack.modbus_master_title); lv_label_set_text(guider_ui.screen_modbus_config_label_device_addr, text_pack.modbus_master_item[0]); lv_label_set_text(guider_ui.screen_modbus_config_label_start_addr, text_pack.modbus_master_item[1]); lv_label_set_text(guider_ui.screen_modbus_config_label_bytes, text_pack.modbus_master_item[2]); lv_label_set_text(guider_ui.screen_modbus_config_label_timeout, text_pack.modbus_master_item[3]); lv_label_set_text(guider_ui.screen_modbus_config_label_cmd, text_pack.modbus_master_item[4]); lv_label_set_text(guider_ui.screen_modbus_config_label_register_num, text_pack.modbus_master_item[5]); lv_label_set_text(guider_ui.screen_modbus_config_label_calibration, text_pack.modbus_master_item[6]); lv_label_set_text(guider_ui.screen_modbus_config_label_next, text_pack.modbus_master_item[7]); mod_mas_conf_cursor = MOD_CONF_SLAVE_ID; //配置项的游标 mod_mas_conf_cursor_prv = MOD_CONF_NONE; config_items_check(mod_mas_conf_cursor, mod_mas_conf_cursor_prv); } void scr_modbus_trx_recover(void) { //清空数据、发送、接收框 lv_label_set_text(guider_ui.screen_modbus_display_value_Data,""); lv_label_set_text(guider_ui.screen_modbus_display_value_Tx,""); lv_label_set_text(guider_ui.screen_modbus_display_value_Rx,""); mod_mas_trx_cursor = MOD_TRX_PREVIOUS; mod_mas_trx_cursor_prv = MOD_TRX_NONE; trx_items_check(mod_mas_trx_cursor, mod_mas_trx_cursor_prv); } uint8_t trx_focus_cnt = 0; void screen_modbus_trx_run(void) { //mobus收发界面,ok按下焦点后,亮一段时间后恢复原色 if(trx_focus) { trx_focus_cnt++; if(trx_focus_cnt >= 2) { trx_focus_cnt = 0; trx_focus = 0; trx_items_check(mod_mas_trx_cursor, MOD_TRX_NONE); } } } uint8_t mod_trx_set_flag = 0; //trx的屏幕是否加载过 void key_functions_modbus(void) { if( key_pv.status == KEY_STATUS_DISABLE ) return; uint8_t calculate_temp = 0; //临时变量,替代枚举变量进行计算 switch (key_pv.tag) { case KEY_UP: { key = 0; key_char2struct(); switch (current_operation) { case MODBUS_MASTER_CONFIG: { mod_mas_conf_cursor_prv = mod_mas_conf_cursor; calculate_temp = (uint8_t)mod_mas_conf_cursor; if(calculate_temp == 0) { calculate_temp = 7; } else { calculate_temp -= 1; } mod_mas_conf_cursor = (MOD_CONF_ITEMS)calculate_temp; config_items_check(mod_mas_conf_cursor, mod_mas_conf_cursor_prv); } break; case MODBUS_MASTER_TRX: { if(mod_mas_trx_cursor) { mod_mas_trx_cursor_prv = mod_mas_trx_cursor; mod_mas_trx_cursor = MOD_TRX_DATA; trx_items_check(mod_mas_trx_cursor, mod_mas_trx_cursor_prv); } } break; case MODBUS_MASTER_TRX_MODIFY: {} break; default: break; } } break; case KEY_DOWN: { key = 0; key_char2struct(); switch (current_operation) { case MODBUS_MASTER_CONFIG: { mod_mas_conf_cursor_prv = mod_mas_conf_cursor; calculate_temp = (uint8_t)mod_mas_conf_cursor; if(calculate_temp == 7) { calculate_temp = 0; } else { calculate_temp += 1; } mod_mas_conf_cursor = (MOD_CONF_ITEMS)calculate_temp; config_items_check(mod_mas_conf_cursor, mod_mas_conf_cursor_prv); } break; case MODBUS_MASTER_TRX: { if(!mod_mas_trx_cursor) { mod_mas_trx_cursor_prv = mod_mas_trx_cursor; mod_mas_trx_cursor = MOD_TRX_PREVIOUS; trx_items_check(mod_mas_trx_cursor, mod_mas_trx_cursor_prv); } } break; case MODBUS_MASTER_TRX_MODIFY: {} break; default: break; } } break; case KEY_LEFT: { key = 0; key_char2struct(); switch (current_operation) { case MODBUS_MASTER_CONFIG: { mod_mas_conf_cursor_prv = mod_mas_conf_cursor; calculate_temp = (uint8_t)mod_mas_conf_cursor; calculate_temp -= 4; if(calculate_temp > 200) { calculate_temp = (uint8_t)mod_mas_conf_cursor_prv + 4; } mod_mas_conf_cursor = (MOD_CONF_ITEMS)calculate_temp; config_items_check(mod_mas_conf_cursor, mod_mas_conf_cursor_prv); } break; case MODBUS_MASTER_TRX: { if(mod_mas_trx_cursor) { mod_mas_trx_cursor_prv = mod_mas_trx_cursor; calculate_temp = (uint8_t)mod_mas_trx_cursor; calculate_temp -= 1; if(calculate_temp == 0) calculate_temp = 3; mod_mas_trx_cursor = (MOD_TRX_ITEMS)calculate_temp; trx_items_check(mod_mas_trx_cursor, mod_mas_trx_cursor_prv); } } break; case MODBUS_MASTER_TRX_MODIFY: {} break; default: break; } } break; case KEY_RIGHT: { key = 0; key_char2struct(); switch (current_operation) { case MODBUS_MASTER_CONFIG: { mod_mas_conf_cursor_prv = mod_mas_conf_cursor; calculate_temp = (uint8_t)mod_mas_conf_cursor; calculate_temp += 4; if(calculate_temp > 7) { calculate_temp = (uint8_t)mod_mas_conf_cursor_prv - 4; } mod_mas_conf_cursor = (MOD_CONF_ITEMS)calculate_temp; config_items_check(mod_mas_conf_cursor, mod_mas_conf_cursor_prv); } break; case MODBUS_MASTER_TRX: { if(mod_mas_trx_cursor) { mod_mas_trx_cursor_prv = mod_mas_trx_cursor; calculate_temp = (uint8_t)mod_mas_trx_cursor; calculate_temp += 1; if(calculate_temp > 3) calculate_temp = 1; mod_mas_trx_cursor = (MOD_TRX_ITEMS)calculate_temp; trx_items_check(mod_mas_trx_cursor, mod_mas_trx_cursor_prv); } } break; case MODBUS_MASTER_TRX_MODIFY: {} break; default: break; } } break; case KEY_OK: { key = 0; key_char2struct(); switch (current_operation) { case MODBUS_MASTER_CONFIG: { if(mod_mas_conf_cursor == MOD_CONF_NEXT) { if(!mod_trx_set_flag) { mod_trx_set_flag = 1; setup_scr_screen_modbus_display(&guider_ui); delay_cnt(200); //不加延时有概率卡死 } //加载trx界面 scr_modbus_trx_recover(); lv_scr_load(guider_ui.screen_modbus_display); lv_obj_clear_flag(guider_ui.screen_modbus_display, LV_OBJ_FLAG_HIDDEN); menu_data.scr_now = SCREEN_MODBUS_MASTER_TRX; //隐藏配置界面,熄灭当前游标 lv_obj_add_flag(guider_ui.screen_modbus_config, LV_OBJ_FLAG_HIDDEN); config_items_check(MOD_CONF_NONE, mod_mas_conf_cursor); current_operation = MODBUS_MASTER_TRX; } } break; case MODBUS_MASTER_TRX: { switch (mod_mas_trx_cursor) { case MOD_TRX_DATA: { } break; case MOD_TRX_PREVIOUS: { key = KEY_BACK_VAL; key_char2struct(); } break; case MOD_TRX_SET: { trx_focus = 1; trx_items_check(mod_mas_trx_cursor, MOD_TRX_NONE); } break; case MOD_TRX_SEND: { trx_focus = 1; trx_items_check(mod_mas_trx_cursor, MOD_TRX_NONE); } break; default: break; } } break; case MODBUS_MASTER_TRX_MODIFY: {} break; default: break; } } break; case KEY_BACK: { key = 0; key_char2struct(); switch (current_operation) { case MODBUS_MASTER_CONFIG: { //加载设置界面的内容 setup_scr_screen_setting(&guider_ui); scr_setting_recover(); delay_cnt(200); //不加延时有概率卡死 lv_scr_load(guider_ui.screen_setting); //加载菜单界面 //删除modbus的相关内容,释放内存 lv_obj_del_async(guider_ui.screen_modbus_config); if(mod_trx_set_flag) { //加载过的情况下才能删除,否则会进入硬件错误中断 mod_trx_set_flag = 0; lv_obj_del_async(guider_ui.screen_modbus_display); } menu_data.scr_now = SCREEN_SETTING; //进入拓展功能选项卡 tabdata.item_cursor = ITEM_2; tabdata.item_cursor_prv = ITEM_0; setting_items_check(tabdata.item_cursor, tabdata.item_cursor_prv); //进入通讯选择 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 MODBUS_MASTER_TRX: { //加载配置界面 scr_modbus_config_recover(); lv_scr_load(guider_ui.screen_modbus_config); lv_obj_clear_flag(guider_ui.screen_modbus_config, LV_OBJ_FLAG_HIDDEN); menu_data.scr_now = SCREEN_MODBUS_MASTER_CONFIG; //隐藏trx界面 lv_obj_add_flag(guider_ui.screen_modbus_display, LV_OBJ_FLAG_HIDDEN); //熄灭当前游标 trx_items_check(MOD_TRX_NONE, mod_mas_trx_cursor); current_operation = MODBUS_MASTER_CONFIG; } break; case MODBUS_MASTER_TRX_MODIFY: {} break; default: break; } } break; default: break; } }