sggt/App/APP_WU/Src/app_screen_setting_trans.c

509 lines
16 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "app_screen_setting_trans.h"
uint8_t com_switch_cursor = 0; //设置界面中,通讯选择的游标
uint8_t com_switch_cursor_prv = 99;
uint8_t mod_mas_conf_cursor = 0; //modbus配置项的游标从上往下-从左往右0~7
uint8_t mod_mas_conf_cursor_prv = 99;
uint8_t config_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(uint8_t cur, uint32_t color)
{
switch (cur)
{
case 0:
{
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 1:
{
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 2:
{
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 3:
{
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 4:
{
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 5:
{
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 6:
{
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 7:
{
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(uint8_t cur, uint8_t 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 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 = 0; //配置项的游标,从上往下-从左往右0~7
mod_mas_conf_cursor_prv = 99;
}
void key_functions_modbus(void)
{
if( key_pv.status == KEY_STATUS_DISABLE ) return;
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;
if(mod_mas_conf_cursor == 0)
{
mod_mas_conf_cursor = 7;
}
else
{
mod_mas_conf_cursor -= 1;
}
config_items_check(mod_mas_conf_cursor, mod_mas_conf_cursor_prv);
}
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;
if(mod_mas_conf_cursor == 7)
{
mod_mas_conf_cursor = 0;
}
else
{
mod_mas_conf_cursor += 1;
}
config_items_check(mod_mas_conf_cursor, mod_mas_conf_cursor_prv);
}
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;
mod_mas_conf_cursor -= 4;
if(mod_mas_conf_cursor > 200)
{
mod_mas_conf_cursor = mod_mas_conf_cursor_prv + 4;
}
config_items_check(mod_mas_conf_cursor, mod_mas_conf_cursor_prv);
}
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;
mod_mas_conf_cursor += 4;
if(mod_mas_conf_cursor > 7)
{
mod_mas_conf_cursor = mod_mas_conf_cursor_prv - 4;
}
config_items_check(mod_mas_conf_cursor, mod_mas_conf_cursor_prv);
}
break;
default:
break;
}
}
break;
case KEY_OK:
{
key = 0;
key_char2struct();
}
break;
case KEY_BACK:
{
key = 0;
key_char2struct();
switch (current_operation)
{
case MODBUS_MASTER_CONFIG:
{
//设置主界面和配置界面的内容
setup_scr_screen_main(&guider_ui);
delay_cnt(200); //不加延时有概率卡死
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);
lv_obj_del_async(guider_ui.screen_modbus_display);
m5data.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:
{
//返回modbus配置界面
}
break;
default:
break;
}
}
break;
default:
break;
}
}