#include "esp_lcd_panel_ops.h"
#include "lcd_display_drv.h"
#include "log.h"
#include "rtos_drv.h"
#include "system_freertos_define.h"
#include "ui.h"
#include "events/ui_engineer_setting_screen_event.h"

#include "parameter.h"

#define C_TEMP_CALIBRATION_MIN  (-5)
#define C_TEMP_CALIBRATION_MAX  (5)
#define F_TEMP_CALIBRATION_MIN  (-10)
#define F_TEMP_CALIBRATION_MAX  (10)

#define C_SET_TEMP_UP_MIN  (20)
#define C_SET_TEMP_UP_MAX  (35)
#define F_SET_TEMP_UP_MIN  (68)
#define F_SET_TEMP_UP_MAX  (95)

#define C_SET_TEMP_DOWN_MIN  (5)
#define C_SET_TEMP_DOWN_MAX  (20)
#define F_SET_TEMP_DOWN_MIN  (41)
#define F_SET_TEMP_DOWN_MAX  (68)

#define C_ECO_HEAT_MIN  (5)
#define C_ECO_HEAT_MAX  (35)
#define F_ECO_HEAT_MIN  (41)
#define F_ECO_HEAT_MAX  (95)

#define C_ECO_COOL_MIN  (5)
#define C_ECO_COOL_MAX  (35)
#define F_ECO_COOL_MIN  (41)
#define F_ECO_COOL_MAX  (95)

#define C_PROPORTIONAL_BAND_MIN  (1)
#define C_PROPORTIONAL_BAND_MAX  (5)
#define F_PROPORTIONAL_BAND_MIN  (2)
#define F_PROPORTIONAL_BAND_MAX  (10)

static const char *TAG = "ui_engineer_setting_screen_event";

/*工程设置第几页*/
uint8_t engineer_setting_page_num = 1;

engineering_param_dis_t engineering_param_dis[5] = 
{
  { 
    &ui_EngineerSettingPanelSeg1PanelChildPanelLable, 
    &ui_EngineerSettingPanelSeg1PanelChildPanelMinusPanel,
    &ui_EngineerSettingPanelSeg1PanelChildPanelValueLable,
    &ui_EngineerSettingPanelSeg1PanelChildPanelAddPanel,
    &ui_EngineerSettingPanelSeg1PanelChildPanelSwitch,
    &ui_EngineerSettingPanelSeg1Panel,
  },
  { 
    &ui_EngineerSettingPanelSeg2PanelChildPanelLable, 
    &ui_EngineerSettingPanelSeg2PanelChildPanelMinusPanel,
    &ui_EngineerSettingPanelSeg2PanelChildPanelValueLable,
    &ui_EngineerSettingPanelSeg2PanelChildPanelAddPanel,
    &ui_EngineerSettingPanelSeg2PanelChildPanelSwitch,
    &ui_EngineerSettingPanelSeg2Panel,
  },
  { 
    &ui_EngineerSettingPanelSeg3PanelChildPanelLable, 
    &ui_EngineerSettingPanelSeg3PanelChildPanelMinusPanel,
    &ui_EngineerSettingPanelSeg3PanelChildPanelValueLable,
    &ui_EngineerSettingPanelSeg3PanelChildPanelAddPanel,
    &ui_EngineerSettingPanelSeg3PanelChildPanelSwitch,
    &ui_EngineerSettingPanelSeg3Panel,
  },
  { 
    &ui_EngineerSettingPanelSeg4PanelChildPanelLable, 
    &ui_EngineerSettingPanelSeg4PanelChildPanelMinusPanel,
    &ui_EngineerSettingPanelSeg4PanelChildPanelValueLable,
    &ui_EngineerSettingPanelSeg4PanelChildPanelAddPanel,
    &ui_EngineerSettingPanelSeg4PanelChildPanelSwitch,
    &ui_EngineerSettingPanelSeg4Panel,
  },
  { 
    &ui_EngineerSettingPanelSeg5PanelChildPanelLable, 
    &ui_EngineerSettingPanelSeg5PanelChildPanelMinusPanel,
    &ui_EngineerSettingPanelSeg5PanelChildPanelValueLable,
    &ui_EngineerSettingPanelSeg5PanelChildPanelAddPanel,
    &ui_EngineerSettingPanelSeg5PanelChildPanelSwitch,
    &ui_EngineerSettingPanelSeg5Panel,
  },
};


engineering_param_t engineering_param[25] = 
{
  {1, "RS485 address", DATA_TYPE, 1, "", 0, 1, 254},
  {2, "Baud rate", DATA_TYPE, 9600, "", 0, 4800, 38400},
  {3, "Temp calibration", DATA_TYPE, 0, "℃", 0, C_TEMP_CALIBRATION_MIN, C_TEMP_CALIBRATION_MAX},
  {4, "Maximum setpoint", DATA_TYPE, 35, "℃", 0, C_SET_TEMP_UP_MIN, C_SET_TEMP_UP_MAX},
  {5, "Minimum setpoint", DATA_TYPE, 18, "℃", 0, C_SET_TEMP_DOWN_MIN, C_SET_TEMP_DOWN_MAX},
  {6, "Power-off memory", SWITCH_TYPE, 0, "", 0, 0, 1},
  {7, "Fan delay off", DATA_TYPE, 30, "S", 0, 0, 60},
  {8, "Fan stop option(H)", SWITCH_TYPE, 0, "", 0, 0, 1},
  {9, "Fan stop option(C)", SWITCH_TYPE, 0, "", 0, 0, 1},
  {10, "Valve start delay", DATA_TYPE, 0, "Min", 0, 0, 5},
  {11, "2/4 pipe option", DATA_TYPE, 0, "", 0, 0, 1},
  {12, "System type", DATA_TYPE, 0, "", 0, 0, 1},
  {13, "External Input", DATA_TYPE, 0, "", 0, 0, 2},
  {14, "ECO Heat", DATA_TYPE, 18, "℃", 0, C_ECO_HEAT_MIN, C_ECO_HEAT_MAX},
  {15, "ECO Cool", DATA_TYPE, 28, "℃", 0, C_ECO_COOL_MIN, C_ECO_COOL_MAX},
  {16, "Program option", DATA_TYPE, 0, "", 0, 0, 2},
  {17, "℃/℉", DATA_TYPE, 0, "", 0, 0, 1},
  {18, "Proportional band", DATA_TYPE, 3, "℃", 0, C_PROPORTIONAL_BAND_MIN, C_PROPORTIONAL_BAND_MAX},
  {19, "Min Valve Open", DATA_TYPE, 2, "V", 0, 1, 5},
  {20, "Valve Interval", DATA_TYPE, 60, "S", 0, 30, 300},
  {21, "Max Fan Voltage", DATA_TYPE, 10, "V", 0, 1, 10},
  {22, "Min Fan Voltage", DATA_TYPE, 3, "V", 0, 1, 10},
  {23, "High Fan Voltage", DATA_TYPE, 9, "V", 0, 1, 10},
  {24, "Med Fan Voltage", DATA_TYPE, 5, "V", 0, 1, 10},
  {25, "Low Fan Voltage", DATA_TYPE, 3, "V", 0, 1, 10},
};


void EngineerSettingInterfaceRefresh(bool all_en)
{
  if(lv_scr_act() == ui_EngineerSettingScreen)
  {
    char text[30] = {0};
    if(all_en)
    {
      for(uint j = 0; j < sizeof(engineering_param) / sizeof(engineering_param[0]); j++)
      {
        /*华氏度*/
        if((strcmp(engineering_param[j].unit, "℃") == 0) && (Gettemperature_unit() == 1))
        {
          engineering_param[j].unit = "℉";
        }
        else if((strcmp(engineering_param[j].unit, "℉") == 0) && (Gettemperature_unit() == 0))
        {
          engineering_param[j].unit = "℃";
        }

        if(engineering_param[j].type == DATA_TYPE)
        {
          switch(engineering_param[j].number)
          {
            case 1: 
              engineering_param[j].fvalue = GetRS485_address();
              break;

            case 2: 
              switch(GetBaud_rate())
              {
                case 1:
                  engineering_param[j].fvalue = 4800;
                  break;

                case 2:
                  engineering_param[j].fvalue = 9600;
                  break;

                case 3:
                  engineering_param[j].fvalue = 19200;
                  break;

                case 4:
                  engineering_param[j].fvalue = 38400;
                  break;
              }
              break;

            case 3: 
              engineering_param[j].fvalue = GetTemp_calibration();
              if(Gettemperature_unit() == 1)
              {
                engineering_param[j].min_value = F_TEMP_CALIBRATION_MIN;
                engineering_param[j].max_value = F_TEMP_CALIBRATION_MAX;
              }
              else
              {
                engineering_param[j].min_value = C_TEMP_CALIBRATION_MIN;
                engineering_param[j].max_value = C_TEMP_CALIBRATION_MAX;
              }
              break;

            case 4: 
              engineering_param[j].fvalue = GetSet_upper_temperature_limit();
              if(Gettemperature_unit() == 1)
              {
                engineering_param[j].min_value = F_SET_TEMP_UP_MIN;
                engineering_param[j].max_value = F_SET_TEMP_UP_MAX;
              }
              else
              {
                engineering_param[j].min_value = C_SET_TEMP_UP_MIN;
                engineering_param[j].max_value = C_SET_TEMP_UP_MAX;
              }
              break;

            case 5: 
              engineering_param[j].fvalue = GetSet_lower_temperature_limit();
              if(Gettemperature_unit() == 1)
              {
                engineering_param[j].min_value = F_SET_TEMP_DOWN_MIN;
                engineering_param[j].max_value = F_SET_TEMP_DOWN_MAX;
              }
              else
              {
                engineering_param[j].min_value = C_SET_TEMP_DOWN_MIN;
                engineering_param[j].max_value = C_SET_TEMP_DOWN_MAX;
              }
              break;

            case 6: 
              //engineering_param[j].fvalue = GetPower_off_memory();
              break;

            case 7: 
              engineering_param[j].fvalue = GetFan_delay_off();
              break;

            case 8: 
              //engineering_param[j].fvalue = GetFan_state_with_heat_valve();
              break;

            case 9: 
              //engineering_param[j].fvalue = GetFan_state_with_cool_valve();
              break;

            case 10: 
              engineering_param[j].fvalue = GetValve_start_delay();
              break;

            case 11: 
              engineering_param[j].fvalue = GetPipe_option();
              break;

            case 12: 
              engineering_param[j].fvalue = GetSystem_mode();
              break;

            case 13: 
              engineering_param[j].fvalue = GetExternal_Input();
              break;

            case 14: 
              engineering_param[j].fvalue = GetECO_Heat();
              if(Gettemperature_unit() == 1)
              {
                engineering_param[j].min_value = F_ECO_HEAT_MIN;
                engineering_param[j].max_value = F_ECO_HEAT_MAX;
              }
              else
              {
                engineering_param[j].min_value = C_ECO_HEAT_MIN;
                engineering_param[j].max_value = C_ECO_HEAT_MAX;
              }
              break;

            case 15: 
              engineering_param[j].fvalue = GetECO_Cool();
              if(Gettemperature_unit() == 1)
              {
                engineering_param[j].min_value = F_ECO_COOL_MIN;
                engineering_param[j].max_value = F_ECO_COOL_MAX;
              }
              else
              {
                engineering_param[j].min_value = C_ECO_COOL_MIN;
                engineering_param[j].max_value = C_ECO_COOL_MAX;
              }
              break;

            case 16: 
              engineering_param[j].fvalue = GetProgram_option();
              break;

            case 17: 
              engineering_param[j].fvalue = Gettemperature_unit();
              break;

            case 18: 
              engineering_param[j].fvalue = GetProportional_band();
              if(Gettemperature_unit() == 1)
              {
                engineering_param[j].min_value = F_PROPORTIONAL_BAND_MIN;
                engineering_param[j].max_value = F_PROPORTIONAL_BAND_MAX;
              }
              else
              {
                engineering_param[j].min_value = C_PROPORTIONAL_BAND_MIN;
                engineering_param[j].max_value = C_PROPORTIONAL_BAND_MAX;
              }
              break;

            case 19: 
              engineering_param[j].fvalue = GetMin_Valve_Open();
              break;

            case 20: 
              engineering_param[j].fvalue = GetValve_Interval();
              break;

            case 21: 
              engineering_param[j].fvalue = GetMax_Fan_Voltage();
              break;

            case 22: 
              engineering_param[j].fvalue = GetMin_Fan_Voltage();
              break;

            case 23: 
              engineering_param[j].fvalue = GetHigh_Fan_Voltage();
              break;

            case 24: 
              engineering_param[j].fvalue = GetMed_Fan_Voltage();
              break;

            case 25: 
              engineering_param[j].fvalue = GetLow_Fan_Voltage();
              break;
          }
        }
        else if(engineering_param[j].type == SWITCH_TYPE)
        {
          switch(engineering_param[j].number)
          {
            case 6:
              engineering_param[j].switch_value = GetPower_off_memory();
              break;

            case 8:
              engineering_param[j].switch_value = GetFan_state_with_heat_valve();
              break;

            case 9:
              engineering_param[j].switch_value = GetFan_state_with_cool_valve();
              break;
          }
        }
      }
    }

    for(uint8_t i = 0; i < 5; i++)
    {
      _ui_flag_modify(*(engineering_param_dis[i].param6), LV_OBJ_FLAG_HIDDEN, _UI_MODIFY_FLAG_ADD);

      if(engineering_param[(engineer_setting_page_num - 1)*5 + i].number <= (sizeof(engineering_param)/sizeof(engineering_param_t)))
      {
        /*是否显示相关栏目*/
        _ui_flag_modify(*(engineering_param_dis[i].param6), LV_OBJ_FLAG_HIDDEN, _UI_MODIFY_FLAG_REMOVE);
        /*判断此项为数值类型/开关类型*/
        if(engineering_param[(engineer_setting_page_num - 1)*5 + i].type == SWITCH_TYPE)
        {
          _ui_flag_modify(*(engineering_param_dis[i].param2), LV_OBJ_FLAG_HIDDEN, _UI_MODIFY_FLAG_ADD);
          _ui_flag_modify(*(engineering_param_dis[i].param3), LV_OBJ_FLAG_HIDDEN, _UI_MODIFY_FLAG_ADD);
          _ui_flag_modify(*(engineering_param_dis[i].param4), LV_OBJ_FLAG_HIDDEN, _UI_MODIFY_FLAG_ADD);
          _ui_flag_modify(*(engineering_param_dis[i].param5), LV_OBJ_FLAG_HIDDEN, _UI_MODIFY_FLAG_REMOVE);

          if(engineering_param[(engineer_setting_page_num - 1)*5 + i].switch_value)
          {
            _ui_state_modify(*(engineering_param_dis[i].param5), LV_STATE_CHECKED, _UI_MODIFY_STATE_ADD);
          }
          else
          {
            _ui_state_modify(*(engineering_param_dis[i].param5), LV_STATE_CHECKED, _UI_MODIFY_STATE_REMOVE);
          }
        }
        else
        {
          _ui_flag_modify(*(engineering_param_dis[i].param2), LV_OBJ_FLAG_HIDDEN, _UI_MODIFY_FLAG_REMOVE);
          _ui_flag_modify(*(engineering_param_dis[i].param3), LV_OBJ_FLAG_HIDDEN, _UI_MODIFY_FLAG_REMOVE);
          _ui_flag_modify(*(engineering_param_dis[i].param4), LV_OBJ_FLAG_HIDDEN, _UI_MODIFY_FLAG_REMOVE);
          _ui_flag_modify(*(engineering_param_dis[i].param5), LV_OBJ_FLAG_HIDDEN, _UI_MODIFY_FLAG_ADD);

          lv_snprintf(text, sizeof(text), "%d", (int)engineering_param[(engineer_setting_page_num - 1)*5 + i].fvalue);
          strcat(text, engineering_param[(engineer_setting_page_num - 1)*5 + i].unit);
          _ui_label_set_property(*(engineering_param_dis[i].param3), _UI_LABEL_PROPERTY_TEXT, text);

          /*温度校正*/
          if(engineering_param[(engineer_setting_page_num - 1)*5 + i].number == 3)
          {
            snprintf(text, sizeof(text), "%.1f", engineering_param[(engineer_setting_page_num - 1)*5 + i].fvalue);
            strcat(text, engineering_param[(engineer_setting_page_num - 1)*5 + i].unit);
            _ui_label_set_property(*(engineering_param_dis[i].param3), _UI_LABEL_PROPERTY_TEXT, text);
          }

          /*2/4管*/
          if(engineering_param[(engineer_setting_page_num - 1)*5 + i].number == 11)
          {
            if(engineering_param[(engineer_setting_page_num - 1)*5 + i].fvalue == 0)
            {
              _ui_label_set_property(*(engineering_param_dis[i].param3), _UI_LABEL_PROPERTY_TEXT, "2");
            }
            else if(engineering_param[(engineer_setting_page_num - 1)*5 + i].fvalue == 1)
            {
              _ui_label_set_property(*(engineering_param_dis[i].param3), _UI_LABEL_PROPERTY_TEXT, "4");
            }
          }
        
          /*模式选择*/
          if(engineering_param[(engineer_setting_page_num - 1)*5 + i].number == 12)
          {
            if(engineering_param[(engineer_setting_page_num - 1)*5 + i].fvalue == 0)
            {
              _ui_label_set_property(*(engineering_param_dis[i].param3), _UI_LABEL_PROPERTY_TEXT, "CO");
            }
            else if(engineering_param[(engineer_setting_page_num - 1)*5 + i].fvalue == 1)
            {
              _ui_label_set_property(*(engineering_param_dis[i].param3), _UI_LABEL_PROPERTY_TEXT, "CO&HE");
            }
          }
          /*外部输入*/
          else if(engineering_param[(engineer_setting_page_num - 1)*5 + i].number == 13)
          {
            if(engineering_param[(engineer_setting_page_num - 1)*5 + i].fvalue == 0)
            {
              _ui_label_set_property(*(engineering_param_dis[i].param3), _UI_LABEL_PROPERTY_TEXT, "No");
            }
            else if(engineering_param[(engineer_setting_page_num - 1)*5 + i].fvalue == 1)
            {
              _ui_label_set_property(*(engineering_param_dis[i].param3), _UI_LABEL_PROPERTY_TEXT, "Sen");
            }
            else if(engineering_param[(engineer_setting_page_num - 1)*5 + i].fvalue == 2)
            {
              _ui_label_set_property(*(engineering_param_dis[i].param3), _UI_LABEL_PROPERTY_TEXT, "Card");
            }
          }
          /*编程日程表*/
          else if(engineering_param[(engineer_setting_page_num - 1)*5 + i].number == 16)
          {
            if(engineering_param[(engineer_setting_page_num - 1)*5 + i].fvalue == 0)
            {
              _ui_label_set_property(*(engineering_param_dis[i].param3), _UI_LABEL_PROPERTY_TEXT, "OFF");
            }
            else if(engineering_param[(engineer_setting_page_num - 1)*5 + i].fvalue == 1)
            {
              _ui_label_set_property(*(engineering_param_dis[i].param3), _UI_LABEL_PROPERTY_TEXT, "Timer");
            }
            else if(engineering_param[(engineer_setting_page_num - 1)*5 + i].fvalue == 2)
            {
              _ui_label_set_property(*(engineering_param_dis[i].param3), _UI_LABEL_PROPERTY_TEXT, "PROG");
            }
          }
          /*℃/℉*/
          else if(engineering_param[(engineer_setting_page_num - 1)*5 + i].number == 17)
          {
            if(engineering_param[(engineer_setting_page_num - 1)*5 + i].fvalue == 0)
            {
              _ui_label_set_property(*(engineering_param_dis[i].param3), _UI_LABEL_PROPERTY_TEXT, "℃");
            }
            else if(engineering_param[(engineer_setting_page_num - 1)*5 + i].fvalue == 1)
            {
              _ui_label_set_property(*(engineering_param_dis[i].param3), _UI_LABEL_PROPERTY_TEXT, "℉");
            }
          }
        }
        _ui_label_set_property(*(engineering_param_dis[i].param1), _UI_LABEL_PROPERTY_TEXT, engineering_param[(engineer_setting_page_num - 1)*5 + i].assic_code);
      }
    }

    lv_snprintf(text, sizeof(text), "%01d/%01d", engineer_setting_page_num, 4);
    _ui_label_set_property(ui_EngineerSettingPanelPageNumbLable, _UI_LABEL_PROPERTY_TEXT, text);
  }
}


void EngineerSettingScreenLoadStartCallback(lv_event_t * e)
{

}

void EngineerSettingScreenLoadedCallback(lv_event_t * e)
{
  engineer_setting_page_num = 1;
  EngineerSettingInterfaceRefresh(1);
}

void EngineerSettingScreenUnloadedCallback(lv_event_t * e)
{
  lv_obj_t* target = lv_event_get_target(e);
  if (target != ui_EngineerSettingScreen) {
    USER_LOGE(TAG, "ui_EngineerSettingScreen target error");
    goto End;
  }

  lvgl_obj_delete(&ui_EngineerSettingPanelPageNumbLable);
  lvgl_obj_delete(&ui_Image2);
  lvgl_obj_delete(&ui_EngineerSettingPanelNextPanel);
  lvgl_obj_delete(&ui_Image1);
  lvgl_obj_delete(&ui_EngineerSettingPanelPrePanel);
//  lvgl_obj_delete(&ui_EngineerSettingPanelSeg5PanelChildPanelAddPanel1);
  lvgl_obj_delete(&ui_EngineerSettingPanelSeg5PanelChildPanelSwitch);
  lvgl_obj_delete(&ui_EngineerSettingPanelSeg5PanelChildPanelAddPanel);
  lvgl_obj_delete(&ui_EngineerSettingPanelSeg5PanelChildPanelValueLable);
  lvgl_obj_delete(&ui_EngineerSettingPanelSeg5PanelChildPanelMinusPanel);
  lvgl_obj_delete(&ui_EngineerSettingPanelSeg5PanelChildPanelLable);
  lvgl_obj_delete(&ui_EngineerSettingPanelSeg5PanelChildPanel);
  lvgl_obj_delete(&ui_EngineerSettingPanelSeg5Panel);
  lvgl_obj_delete(&ui_EngineerSettingPanelSeg4PanelChildPanelSwitch);
  lvgl_obj_delete(&ui_EngineerSettingPanelSeg4PanelChildPanelAddPanel);
  lvgl_obj_delete(&ui_EngineerSettingPanelSeg4PanelChildPanelValueLable);
  lvgl_obj_delete(&ui_EngineerSettingPanelSeg4PanelChildPanelMinusPanel);
  lvgl_obj_delete(&ui_EngineerSettingPanelSeg4PanelChildPanelLable);
  lvgl_obj_delete(&ui_EngineerSettingPanelSeg4PanelChildPanel);
  lvgl_obj_delete(&ui_EngineerSettingPanelSeg4Panel);
  lvgl_obj_delete(&ui_EngineerSettingPanelSeg3PanelChildPanelSwitch);
  lvgl_obj_delete(&ui_EngineerSettingPanelSeg3PanelChildPanelAddPanel);
  lvgl_obj_delete(&ui_EngineerSettingPanelSeg3PanelChildPanelValueLable);
  lvgl_obj_delete(&ui_EngineerSettingPanelSeg3PanelChildPanelMinusPanel);
  lvgl_obj_delete(&ui_EngineerSettingPanelSeg3PanelChildPanelLable);
  lvgl_obj_delete(&ui_EngineerSettingPanelSeg3PanelChildPanel);
  lvgl_obj_delete(&ui_EngineerSettingPanelSeg3Panel);
  lvgl_obj_delete(&ui_EngineerSettingPanelSeg2PanelChildPanelSwitch);
  lvgl_obj_delete(&ui_EngineerSettingPanelSeg2PanelChildPanelAddPanel);
  lvgl_obj_delete(&ui_EngineerSettingPanelSeg2PanelChildPanelValueLable);
  lvgl_obj_delete(&ui_EngineerSettingPanelSeg2PanelChildPanelMinusPanel);
  lvgl_obj_delete(&ui_EngineerSettingPanelSeg2PanelChildPanelLable);
  lvgl_obj_delete(&ui_EngineerSettingPanelSeg2PanelChildPanel);
  lvgl_obj_delete(&ui_EngineerSettingPanelSeg2Panel);
  lvgl_obj_delete(&ui_EngineerSettingPanelSeg1PanelChildPanelSwitch);
  lvgl_obj_delete(&ui_EngineerSettingPanelSeg1PanelChildPanelAddPanel);
  lvgl_obj_delete(&ui_EngineerSettingPanelSeg1PanelChildPanelValueLable);
  lvgl_obj_delete(&ui_EngineerSettingPanelSeg1PanelChildPanelMinusPanel);
  lvgl_obj_delete(&ui_EngineerSettingPanelSeg1PanelChildPanelLable);
  lvgl_obj_delete(&ui_EngineerSettingPanelSeg1PanelChildPanel);
  lvgl_obj_delete(&ui_EngineerSettingPanelSeg1Panel);
  lvgl_obj_delete(&ui_EngineerSettingPanelLabel);
  lvgl_obj_delete(&ui_EngineerSettingPanelReturnPanel);
  lvgl_obj_delete(&ui_EngineerSettingPanel);
  lvgl_obj_delete(&ui_EngineerSettingScreen);
 

End:
  return;
}

void EngineerSettingPanelReturnPanelClickedCallback(lv_event_t * e)
{
  _ui_screen_change(&ui_UserSettingScreen, LV_SCR_LOAD_ANIM_NONE, 0, 50, &ui_UserSettingScreen_screen_init);  
}


  lv_obj_t **add_minus[10] = {
  {&ui_EngineerSettingPanelSeg1PanelChildPanelMinusPanel},
  {&ui_EngineerSettingPanelSeg1PanelChildPanelAddPanel},
  {&ui_EngineerSettingPanelSeg2PanelChildPanelMinusPanel},
  {&ui_EngineerSettingPanelSeg2PanelChildPanelAddPanel},
  {&ui_EngineerSettingPanelSeg3PanelChildPanelMinusPanel},
  {&ui_EngineerSettingPanelSeg3PanelChildPanelAddPanel},
  {&ui_EngineerSettingPanelSeg4PanelChildPanelMinusPanel},
  {&ui_EngineerSettingPanelSeg4PanelChildPanelAddPanel},
  {&ui_EngineerSettingPanelSeg5PanelChildPanelMinusPanel},
  {&ui_EngineerSettingPanelSeg5PanelChildPanelAddPanel},
  };
void EngineerSettingPanelSegXPanelChildPanelActPanelClickedCallback(lv_event_t * e)
{
  for(uint8_t i = 0; i < 10; i++)
  {
    if(e->target == *(add_minus[i]))
    {
      for(uint8_t j = 1; j <= ENGI_PAGE_ALL; j++)
      {
        if(j == engineer_setting_page_num)
        {
          uint8_t switch_value = (engineer_setting_page_num-1)*10 +i;
          switch(switch_value)
          { 
            /*通讯地址*/
            case 0: 
              if(e->code != LV_EVENT_CLICKED)
              {
                engineering_param[(engineer_setting_page_num-1)*10 +i].fvalue = GetRS485_address();
                if(engineering_param[(engineer_setting_page_num-1)*10 +i].fvalue > engineering_param[(engineer_setting_page_num-1)*10 +i].min_value)
                {
                  engineering_param[(engineer_setting_page_num-1)*10 +i].fvalue -=1;
                  SetRS485_address((uint16_t)engineering_param[(engineer_setting_page_num-1)*10 +i].fvalue);
                }
              }
              break;

            case 1: 
              if(e->code != LV_EVENT_CLICKED)
              {
                engineering_param[(engineer_setting_page_num-1)*10 +i -1].fvalue = GetRS485_address();
                if(engineering_param[(engineer_setting_page_num-1)*10 +i -1].fvalue < engineering_param[(engineer_setting_page_num-1)*10 +i -1].max_value)
                {
                  engineering_param[(engineer_setting_page_num-1)*10 +i -1].fvalue +=1;
                  SetRS485_address((uint16_t)engineering_param[(engineer_setting_page_num-1)*10 +i -1].fvalue);
                }
              }
              break;

            /*波特率*/
            case 2: 
              if(e->code != LV_EVENT_CLICKED)
              {
                engineering_param[(engineer_setting_page_num-1)*10 +i -1].fvalue = GetBaud_rate();
                if(engineering_param[(engineer_setting_page_num-1)*10 +i -1].fvalue == 1)
                {
                  engineering_param[(engineer_setting_page_num-1)*10 +i -1].fvalue = 4800;
                  SetBaud_rate(1);
                }
                else if(engineering_param[(engineer_setting_page_num-1)*10 +i -1] .fvalue == 2)
                {
                  engineering_param[(engineer_setting_page_num-1)*10 +i -1].fvalue = 4800;
                  SetBaud_rate(1);
                }
                else if(engineering_param[(engineer_setting_page_num-1)*10 +i -1].fvalue == 3)
                {
                  engineering_param[(engineer_setting_page_num-1)*10 +i -1].fvalue = 9600;
                  SetBaud_rate(2);
                }
                else if(engineering_param[(engineer_setting_page_num-1)*10 +i -1].fvalue == 4)
                {
                  engineering_param[(engineer_setting_page_num-1)*10 +i -1].fvalue = 19200;
                  SetBaud_rate(3);
                }
              }
              break;

            case 3: 
              if(e->code != LV_EVENT_CLICKED)
              {
                engineering_param[(engineer_setting_page_num-1)*10 +i -2].fvalue = GetBaud_rate();
                if(engineering_param[(engineer_setting_page_num-1)*10 +i -2].fvalue == 1)
                {
                  engineering_param[(engineer_setting_page_num-1)*10 +i -2].fvalue = 9600;
                  SetBaud_rate(2);
                }
                else if(engineering_param[(engineer_setting_page_num-1)*10 +i -2].fvalue == 2)
                {
                  engineering_param[(engineer_setting_page_num-1)*10 +i -2].fvalue = 19200;
                  SetBaud_rate(3);
                }
                else if(engineering_param[(engineer_setting_page_num-1)*10 +i -2].fvalue == 3)
                {
                  engineering_param[(engineer_setting_page_num-1)*10 +i -2].fvalue = 38400;
                  SetBaud_rate(4);
                }
                else if(engineering_param[(engineer_setting_page_num-1)*10 +i -2].fvalue == 4)
                {
                  engineering_param[(engineer_setting_page_num-1)*10 +i -2].fvalue = 38400;
                  SetBaud_rate(4);
                }
              }
              break;

            /*温度校正*/
            case 4: 
              if(e->code != LV_EVENT_CLICKED)
              {
                engineering_param[(engineer_setting_page_num-1)*10 +i -2].fvalue = GetTemp_calibration();
                //printf("engineering_param[(engineer_setting_page_num-1)*10 +i -2].min_value = %f\r\n", engineering_param[(engineer_setting_page_num-1)*10 +i -2].min_value);
                if(engineering_param[(engineer_setting_page_num-1)*10 +i -2].fvalue > engineering_param[(engineer_setting_page_num-1)*10 +i -2].min_value)
                {
                  engineering_param[(engineer_setting_page_num-1)*10 +i -2].fvalue -= 0.50;
                  SetTemp_calibration(engineering_param[(engineer_setting_page_num-1)*10 +i -2].fvalue);
                }
              }
              break;

            case 5: 
              if(e->code != LV_EVENT_CLICKED)
              {
                engineering_param[(engineer_setting_page_num-1)*10 +i -3].fvalue = GetTemp_calibration();
                //printf("engineering_param[(engineer_setting_page_num-1)*10 +i -2].max_value = %f\r\n", engineering_param[(engineer_setting_page_num-1)*10 +i -2].max_value);
                if(engineering_param[(engineer_setting_page_num-1)*10 +i -3].fvalue < engineering_param[(engineer_setting_page_num-1)*10 +i -3].max_value)
                {
                  engineering_param[(engineer_setting_page_num-1)*10 +i -3].fvalue += 0.50;
                  SetTemp_calibration(engineering_param[(engineer_setting_page_num-1)*10 +i -3].fvalue);
                }
              }
              break;

            /*设定温度上限*/
            case 6: 
              if(e->code != LV_EVENT_CLICKED)
              {
                engineering_param[(engineer_setting_page_num-1)*10 +i -3].fvalue = GetSet_upper_temperature_limit();
                if(engineering_param[(engineer_setting_page_num-1)*10 +i -3].fvalue > engineering_param[(engineer_setting_page_num-1)*10 +i -3].min_value)
                {
                  engineering_param[(engineer_setting_page_num-1)*10 +i -3].fvalue -= 1;
                  SetSet_upper_temperature_limit((uint16_t)engineering_param[(engineer_setting_page_num-1)*10 +i -3].fvalue);
                }
              }
              break;

            case 7: 
              if(e->code != LV_EVENT_CLICKED)
              {
                engineering_param[(engineer_setting_page_num-1)*10 +i -4].fvalue = GetSet_upper_temperature_limit();
                if(engineering_param[(engineer_setting_page_num-1)*10 +i -4].fvalue < engineering_param[(engineer_setting_page_num-1)*10 +i -4].max_value)
                {
                  engineering_param[(engineer_setting_page_num-1)*10 +i -4].fvalue += 1;
                  SetSet_upper_temperature_limit((uint16_t)engineering_param[(engineer_setting_page_num-1)*10 +i -4].fvalue);
                }
              }
              break;

            /*设定温度下限*/
            case 8: 
              if(e->code != LV_EVENT_CLICKED)
              {
                engineering_param[(engineer_setting_page_num-1)*10 +i -4].fvalue = GetSet_lower_temperature_limit();
                if(engineering_param[(engineer_setting_page_num-1)*10 +i -4].fvalue > engineering_param[(engineer_setting_page_num-1)*10 +i -4].min_value)
                {
                  engineering_param[(engineer_setting_page_num-1)*10 +i -4].fvalue -= 1;
                  SetSet_lower_temperature_limit((uint16_t)engineering_param[(engineer_setting_page_num-1)*10 +i -4].fvalue);
                }
              }
              break;

            case 9: 
              if(e->code != LV_EVENT_CLICKED)
              {
                engineering_param[(engineer_setting_page_num-1)*10 +i -5].fvalue = GetSet_lower_temperature_limit();
                if(engineering_param[(engineer_setting_page_num-1)*10 +i -5].fvalue < engineering_param[(engineer_setting_page_num-1)*10 +i -5].max_value)
                {
                  engineering_param[(engineer_setting_page_num-1)*10 +i -5].fvalue += 1;
                  SetSet_lower_temperature_limit((uint16_t)engineering_param[(engineer_setting_page_num-1)*10 +i -5].fvalue);
                }
              }
              break;

            /*断电记忆*/
            case 10: 
              
              break;

            case 11: 
              
              break;

            /*风机延时关闭*/
            case 12: 
              if(e->code != LV_EVENT_CLICKED)
              {
                engineering_param[(engineer_setting_page_num-1)*10 +i -6].fvalue = GetFan_delay_off();
                if(engineering_param[(engineer_setting_page_num-1)*10 +i -6].fvalue > engineering_param[(engineer_setting_page_num-1)*10 +i -6].min_value)
                {
                  engineering_param[(engineer_setting_page_num-1)*10 +i -6].fvalue -= 30;
                  SetFan_delay_off((uint16_t)engineering_param[(engineer_setting_page_num-1)*10 +i -6].fvalue);
                }
              }
              break;

            case 13: 
              if(e->code != LV_EVENT_CLICKED)
              {
                engineering_param[(engineer_setting_page_num-1)*10 +i -7].fvalue = GetFan_delay_off();
                if(engineering_param[(engineer_setting_page_num-1)*10 +i -7].fvalue < engineering_param[(engineer_setting_page_num-1)*10 +i -7].max_value)
                {
                  engineering_param[(engineer_setting_page_num-1)*10 +i -7].fvalue += 30;
                  SetFan_delay_off((uint16_t)engineering_param[(engineer_setting_page_num-1)*10 +i -7].fvalue);
                }
              }
              break;

            /*制热风机联动*/
            case 14: 
              
              break;

            case 15: 
              
              break;

            /*制冷风机联动*/
             case 16: 
              
              break;

            case 17: 
              
              break;
            
            /*阀门输出延时*/
            case 18: 
              if(e->code != LV_EVENT_CLICKED)
              {
                engineering_param[(engineer_setting_page_num-1)*10 +i -9].fvalue = GetValve_start_delay();
                if(engineering_param[(engineer_setting_page_num-1)*10 +i -9].fvalue == 0)
                {
                  engineering_param[(engineer_setting_page_num-1)*10 +i -9].fvalue = 0;
                  SetValve_start_delay((uint16_t)engineering_param[(engineer_setting_page_num-1)*10 +i -9].fvalue);
                }
                else if(engineering_param[(engineer_setting_page_num-1)*10 +i -9].fvalue == 3)
                {
                  engineering_param[(engineer_setting_page_num-1)*10 +i -9].fvalue = 0;
                  SetValve_start_delay((uint16_t)engineering_param[(engineer_setting_page_num-1)*10 +i -9].fvalue);
                }
                else if(engineering_param[(engineer_setting_page_num-1)*10 +i -9].fvalue == 5)
                {
                  engineering_param[(engineer_setting_page_num-1)*10 +i -9].fvalue = 3;
                  SetValve_start_delay((uint16_t)engineering_param[(engineer_setting_page_num-1)*10 +i -9].fvalue);
                }
              }
              break;

            case 19: 
              if(e->code != LV_EVENT_CLICKED)
              {
                engineering_param[(engineer_setting_page_num-1)*10 +i -10].fvalue = GetValve_start_delay();
                if(engineering_param[(engineer_setting_page_num-1)*10 +i -10].fvalue == 0)
                {
                  engineering_param[(engineer_setting_page_num-1)*10 +i -10].fvalue = 3;
                  SetValve_start_delay((uint16_t)engineering_param[(engineer_setting_page_num-1)*10 +i -10].fvalue);
                }
                else if(engineering_param[(engineer_setting_page_num-1)*10 +i -10].fvalue == 3)
                {
                  engineering_param[(engineer_setting_page_num-1)*10 +i -10].fvalue = 5;
                  SetValve_start_delay((uint16_t)engineering_param[(engineer_setting_page_num-1)*10 +i -10].fvalue);
                }
                else if(engineering_param[(engineer_setting_page_num-1)*10 +i -10].fvalue == 5)
                {
                  engineering_param[(engineer_setting_page_num-1)*10 +i -10].fvalue = 5;
                  SetValve_start_delay((uint16_t)engineering_param[(engineer_setting_page_num-1)*10 +i -10].fvalue);
                }
              }
              break;

            /*2&4管制选择*/
            case 20: 
              if(e->code != LV_EVENT_CLICKED)
              {
                engineering_param[(engineer_setting_page_num-1)*10 +i -10].fvalue = GetPipe_option();
                if(engineering_param[(engineer_setting_page_num-1)*10 +i -10].fvalue > engineering_param[(engineer_setting_page_num-1)*10 +i -10].min_value)
                {
                  engineering_param[(engineer_setting_page_num-1)*10 +i -10].fvalue -= 1;
                  SetPipe_option((uint16_t)engineering_param[(engineer_setting_page_num-1)*10 +i -10].fvalue);
                }
              }
              break;

            case 21: 
              if(e->code != LV_EVENT_CLICKED)
              {
                engineering_param[(engineer_setting_page_num-1)*10 +i -11].fvalue = GetPipe_option();
                if(engineering_param[(engineer_setting_page_num-1)*10 +i -11].fvalue < engineering_param[(engineer_setting_page_num-1)*10 +i -11].max_value)
                {
                  // engineering_param[(engineer_setting_page_num-1)*10 +i -11].fvalue += 1;
                  // SetPipe_option((uint16_t)engineering_param[(engineer_setting_page_num-1)*10 +i -11].fvalue);
                  if(GetSystem_mode() == 0)
                  {
                    SetPipe_option(0);
                  }
                  else
                  {
                    engineering_param[(engineer_setting_page_num-1)*10 +i -11].fvalue += 1;
                    SetPipe_option((uint16_t)engineering_param[(engineer_setting_page_num-1)*10 +i -11].fvalue);
                  }
                }
              }
              break;

            /*模式选择*/
            case 22: 
              if(e->code != LV_EVENT_CLICKED)
              {
                engineering_param[(engineer_setting_page_num-1)*10 +i -11].fvalue = GetSystem_mode();
                if(engineering_param[(engineer_setting_page_num-1)*10 +i -11].fvalue > engineering_param[(engineer_setting_page_num-1)*10 +i -11].min_value)
                {
                  engineering_param[(engineer_setting_page_num-1)*10 +i -11].fvalue -= 1;
                  SetSystem_mode((uint16_t)engineering_param[(engineer_setting_page_num-1)*10 +i -11].fvalue);

                  /*CO模式*/
                  if(GetSystem_mode() == 0)
                  {
                    SetPipe_option(0);
                  }
                }
              }
              break;

            case 23: 
              if(e->code != LV_EVENT_CLICKED)
              {
                engineering_param[(engineer_setting_page_num-1)*10 +i -12].fvalue = GetSystem_mode();
                if(engineering_param[(engineer_setting_page_num-1)*10 +i -12].fvalue < engineering_param[(engineer_setting_page_num-1)*10 +i -12].max_value)
                {
                  engineering_param[(engineer_setting_page_num-1)*10 +i -12].fvalue += 1;
                  SetSystem_mode((uint16_t)engineering_param[(engineer_setting_page_num-1)*10 +i -12].fvalue);
                }
              }
              break;

            /*外部输入*/
            case 24: 
              if(e->code != LV_EVENT_CLICKED)
              {
                engineering_param[(engineer_setting_page_num-1)*10 +i -12].fvalue = GetExternal_Input();
                if(engineering_param[(engineer_setting_page_num-1)*10 +i -12].fvalue > engineering_param[(engineer_setting_page_num-1)*10 +i -12].min_value)
                {
                  engineering_param[(engineer_setting_page_num-1)*10 +i -12].fvalue -= 1;
                  SetExternal_Input((uint16_t)engineering_param[(engineer_setting_page_num-1)*10 +i -12].fvalue);
                }
              }
              break;

            case 25: 
              if(e->code != LV_EVENT_CLICKED)
              {
                engineering_param[(engineer_setting_page_num-1)*10 +i -13].fvalue = GetExternal_Input();
                if(engineering_param[(engineer_setting_page_num-1)*10 +i -13].fvalue < engineering_param[(engineer_setting_page_num-1)*10 +i -13].max_value)
                {
                  engineering_param[(engineer_setting_page_num-1)*10 +i -13].fvalue += 1;
                  SetExternal_Input((uint16_t)engineering_param[(engineer_setting_page_num-1)*10 +i -13].fvalue);
                }
              }
              break;

            /*无房卡制热节能温度*/
            case 26: 
              if(e->code != LV_EVENT_CLICKED)
              {
                engineering_param[(engineer_setting_page_num-1)*10 +i -13].fvalue = GetECO_Heat();
                if(engineering_param[(engineer_setting_page_num-1)*10 +i -13].fvalue > engineering_param[(engineer_setting_page_num-1)*10 +i -13].min_value)
                {
                  engineering_param[(engineer_setting_page_num-1)*10 +i -13].fvalue -= 1;
                  SetECO_Heat((uint16_t)engineering_param[(engineer_setting_page_num-1)*10 +i -13].fvalue);
                }
              }
              break;

            case 27: 
              if(e->code != LV_EVENT_CLICKED)
              {
                engineering_param[(engineer_setting_page_num-1)*10 +i -14].fvalue = GetECO_Heat();
                if(engineering_param[(engineer_setting_page_num-1)*10 +i -14].fvalue < engineering_param[(engineer_setting_page_num-1)*10 +i -14].max_value)
                {
                  engineering_param[(engineer_setting_page_num-1)*10 +i -14].fvalue += 1;
                  SetECO_Heat((uint16_t)engineering_param[(engineer_setting_page_num-1)*10 +i -14].fvalue);
                }
              }
              break;

            /*无房卡制冷节能温度*/
            case 28: 
              if(e->code != LV_EVENT_CLICKED)
              {
                engineering_param[(engineer_setting_page_num-1)*10 +i -14].fvalue = GetECO_Cool();
                if(engineering_param[(engineer_setting_page_num-1)*10 +i -14].fvalue > engineering_param[(engineer_setting_page_num-1)*10 +i -14].min_value)
                {
                  engineering_param[(engineer_setting_page_num-1)*10 +i -14].fvalue -= 1;
                  SetECO_Cool((uint16_t)engineering_param[(engineer_setting_page_num-1)*10 +i -14].fvalue);
                }
              }
              break;

            case 29: 
              if(e->code != LV_EVENT_CLICKED)
              {
                engineering_param[(engineer_setting_page_num-1)*10 +i -15].fvalue = GetECO_Cool();
                if(engineering_param[(engineer_setting_page_num-1)*10 +i -15].fvalue < engineering_param[(engineer_setting_page_num-1)*10 +i -15].max_value)
                {
                  engineering_param[(engineer_setting_page_num-1)*10 +i -15].fvalue += 1;
                  SetECO_Cool((uint16_t)engineering_param[(engineer_setting_page_num-1)*10 +i -15].fvalue);
                }
              }
              break;

            /*"编程日程表*/
            case 30:
              if(e->code != LV_EVENT_CLICKED)
              { 
                engineering_param[(engineer_setting_page_num-1)*10 +i -15].fvalue = GetProgram_option();
                if(engineering_param[(engineer_setting_page_num-1)*10 +i -15].fvalue > engineering_param[(engineer_setting_page_num-1)*10 +i -15].min_value)
                {
                  engineering_param[(engineer_setting_page_num-1)*10 +i -15].fvalue -= 1;
                  SetProgram_option((uint16_t)engineering_param[(engineer_setting_page_num-1)*10 +i -15].fvalue);
                }
              }
              break;

            case 31: 
              if(e->code != LV_EVENT_CLICKED)
              {
                engineering_param[(engineer_setting_page_num-1)*10 +i -16].fvalue = GetProgram_option();
                if(engineering_param[(engineer_setting_page_num-1)*10 +i -16].fvalue < engineering_param[(engineer_setting_page_num-1)*10 +i -16].max_value)
                {
                  engineering_param[(engineer_setting_page_num-1)*10 +i -16].fvalue += 1;
                  SetProgram_option((uint16_t)engineering_param[(engineer_setting_page_num-1)*10 +i -16].fvalue);
                }
              }
              break;

            /*℃/℉*/
            case 32: 
              if(e->code != LV_EVENT_CLICKED)
              {
                engineering_param[(engineer_setting_page_num-1)*10 +i -16].fvalue = Gettemperature_unit();
                if(engineering_param[(engineer_setting_page_num-1)*10 +i -16].fvalue > engineering_param[(engineer_setting_page_num-1)*10 +i -16].min_value)
                {
                  engineering_param[(engineer_setting_page_num-1)*10 +i -16].fvalue -= 1;
                  Settemperature_unit((uint16_t)engineering_param[(engineer_setting_page_num-1)*10 +i -16].fvalue);
                }
              }
              break;

            case 33: 
              if(e->code != LV_EVENT_CLICKED)
              {
                engineering_param[(engineer_setting_page_num-1)*10 +i -17].fvalue = Gettemperature_unit();
                if(engineering_param[(engineer_setting_page_num-1)*10 +i -17].fvalue < engineering_param[(engineer_setting_page_num-1)*10 +i -17].max_value)
                {
                  engineering_param[(engineer_setting_page_num-1)*10 +i -17].fvalue += 1;
                  Settemperature_unit((uint16_t)engineering_param[(engineer_setting_page_num-1)*10 +i -17].fvalue);
                }
              }
              break;

            /*阀门比例带*/
            case 34: 
              if(e->code != LV_EVENT_CLICKED)
              {
                engineering_param[(engineer_setting_page_num-1)*10 +i -17].fvalue = GetProportional_band();
                if(engineering_param[(engineer_setting_page_num-1)*10 +i -17].fvalue > engineering_param[(engineer_setting_page_num-1)*10 +i -17].min_value)
                {
                  if(Gettemperature_unit())
                  {
                    engineering_param[(engineer_setting_page_num-1)*10 +i -17].fvalue -= 2;
                  }
                  else
                  {
                    engineering_param[(engineer_setting_page_num-1)*10 +i -17].fvalue -= 1;
                  }
                  SetProportional_band((uint16_t)engineering_param[(engineer_setting_page_num-1)*10 +i -17].fvalue);
                }
              }
              break;

            case 35: 
              if(e->code != LV_EVENT_CLICKED)
              {
                engineering_param[(engineer_setting_page_num-1)*10 +i -18].fvalue = GetProportional_band();
                if(engineering_param[(engineer_setting_page_num-1)*10 +i -18].fvalue < engineering_param[(engineer_setting_page_num-1)*10 +i -18].max_value)
                {
                  if(Gettemperature_unit())
                  {
                    engineering_param[(engineer_setting_page_num-1)*10 +i -18].fvalue += 2;
                  }
                  else
                  {
                    engineering_param[(engineer_setting_page_num-1)*10 +i -18].fvalue += 1;
                  }
                  SetProportional_band((uint16_t)engineering_param[(engineer_setting_page_num-1)*10 +i -18].fvalue);
                }
              }
              break;

            /*阀门最小开度*/
            case 36: 
              if(e->code != LV_EVENT_CLICKED)
              {
                engineering_param[(engineer_setting_page_num-1)*10 +i -18].fvalue = GetMin_Valve_Open();
                if(engineering_param[(engineer_setting_page_num-1)*10 +i -18].fvalue > engineering_param[(engineer_setting_page_num-1)*10 +i -18].min_value)
                {
                  engineering_param[(engineer_setting_page_num-1)*10 +i -18].fvalue -= 1;
                  SetMin_Valve_Open((uint16_t)engineering_param[(engineer_setting_page_num-1)*10 +i -18].fvalue);
                }
              }
              break;

            case 37: 
              if(e->code != LV_EVENT_CLICKED)
              {
                engineering_param[(engineer_setting_page_num-1)*10 +i -19].fvalue = GetMin_Valve_Open();
                if(engineering_param[(engineer_setting_page_num-1)*10 +i -19].fvalue < engineering_param[(engineer_setting_page_num-1)*10 +i -19].max_value)
                {
                  engineering_param[(engineer_setting_page_num-1)*10 +i -19].fvalue += 1;
                  SetMin_Valve_Open((uint16_t)engineering_param[(engineer_setting_page_num-1)*10 +i -19].fvalue);
                }
              }
              break;

            /*阀门动作间隔时间*/
            case 38: 
              if(e->code != LV_EVENT_CLICKED)
              {
                engineering_param[(engineer_setting_page_num-1)*10 +i -19].fvalue = GetValve_Interval();
                if(engineering_param[(engineer_setting_page_num-1)*10 +i -19].fvalue > engineering_param[(engineer_setting_page_num-1)*10 +i -19].min_value)
                {
                  engineering_param[(engineer_setting_page_num-1)*10 +i -19].fvalue -= 30;
                  SetValve_Interval((uint16_t)engineering_param[(engineer_setting_page_num-1)*10 +i -19].fvalue);
                }
              }
              break;

            case 39: 
              if(e->code != LV_EVENT_CLICKED)
              {
                engineering_param[(engineer_setting_page_num-1)*10 +i -20].fvalue = GetValve_Interval();
                if(engineering_param[(engineer_setting_page_num-1)*10 +i -20].fvalue < engineering_param[(engineer_setting_page_num-1)*10 +i -20].max_value)
                {
                  engineering_param[(engineer_setting_page_num-1)*10 +i -20].fvalue += 30;
                  SetValve_Interval((uint16_t)engineering_param[(engineer_setting_page_num-1)*10 +i -20].fvalue);
                }
              }
              break;

            /*最大风速电压*/
            case 40: 
              if(e->code != LV_EVENT_CLICKED)
              {
                engineering_param[(engineer_setting_page_num-1)*10 +i -20].fvalue = GetMax_Fan_Voltage();
                if(engineering_param[(engineer_setting_page_num-1)*10 +i -20].fvalue > GetMin_Fan_Voltage()/*engineering_param[(engineer_setting_page_num-1)*10 +i -20].min_value*/)
                {
                  engineering_param[(engineer_setting_page_num-1)*10 +i -20].fvalue -= 1;
                  SetMax_Fan_Voltage((uint16_t)engineering_param[(engineer_setting_page_num-1)*10 +i -20].fvalue);
                }
              }
              break;

            case 41: 
              if(e->code != LV_EVENT_CLICKED)
              {
                engineering_param[(engineer_setting_page_num-1)*10 +i -21].fvalue = GetMax_Fan_Voltage();
                if(engineering_param[(engineer_setting_page_num-1)*10 +i -21].fvalue < engineering_param[(engineer_setting_page_num-1)*10 +i -21].max_value)
                {
                  engineering_param[(engineer_setting_page_num-1)*10 +i -21].fvalue += 1;
                  SetMax_Fan_Voltage((uint16_t)engineering_param[(engineer_setting_page_num-1)*10 +i -21].fvalue);
                }
              }
              break;

            /*最小风速电压*/
            case 42: 
              if(e->code != LV_EVENT_CLICKED)
              {
                engineering_param[(engineer_setting_page_num-1)*10 +i -21].fvalue = GetMin_Fan_Voltage();
                if(engineering_param[(engineer_setting_page_num-1)*10 +i -21].fvalue > engineering_param[(engineer_setting_page_num-1)*10 +i -21].min_value)
                {
                  engineering_param[(engineer_setting_page_num-1)*10 +i -21].fvalue -= 1;
                  SetMin_Fan_Voltage((uint16_t)engineering_param[(engineer_setting_page_num-1)*10 +i -21].fvalue);
                }
              }
              break;

            case 43: 
              if(e->code != LV_EVENT_CLICKED)
              {
                engineering_param[(engineer_setting_page_num-1)*10 +i -22].fvalue = GetMin_Fan_Voltage();
                if(engineering_param[(engineer_setting_page_num-1)*10 +i -22].fvalue < GetMax_Fan_Voltage()/*engineering_param[(engineer_setting_page_num-1)*10 +i -22].max_value*/)
                {
                  engineering_param[(engineer_setting_page_num-1)*10 +i -22].fvalue += 1;
                  SetMin_Fan_Voltage((uint16_t)engineering_param[(engineer_setting_page_num-1)*10 +i -22].fvalue);
                }
              }
              break;

            /*高风档电压*/
            case 44: 
              if(e->code != LV_EVENT_CLICKED)
              {
                engineering_param[(engineer_setting_page_num-1)*10 +i -22].fvalue = GetHigh_Fan_Voltage();
                if(engineering_param[(engineer_setting_page_num-1)*10 +i -22].fvalue > engineering_param[(engineer_setting_page_num-1)*10 +i -22].min_value)
                {
                  engineering_param[(engineer_setting_page_num-1)*10 +i -22].fvalue -= 1;
                  SetHigh_Fan_Voltage((uint16_t)engineering_param[(engineer_setting_page_num-1)*10 +i -22].fvalue);
                }
              }
              break;

            case 45: 
              if(e->code != LV_EVENT_CLICKED)
              {
                engineering_param[(engineer_setting_page_num-1)*10 +i -23].fvalue = GetHigh_Fan_Voltage();
                if(engineering_param[(engineer_setting_page_num-1)*10 +i -23].fvalue < engineering_param[(engineer_setting_page_num-1)*10 +i -23].max_value)
                {
                  engineering_param[(engineer_setting_page_num-1)*10 +i -23].fvalue += 1;
                  SetHigh_Fan_Voltage((uint16_t)engineering_param[(engineer_setting_page_num-1)*10 +i -23].fvalue);
                }
              }
              break;

            /*中风档电压*/
            case 46: 
              if(e->code != LV_EVENT_CLICKED)
              {
                engineering_param[(engineer_setting_page_num-1)*10 +i -23].fvalue = GetMed_Fan_Voltage();
                if(engineering_param[(engineer_setting_page_num-1)*10 +i -23].fvalue > engineering_param[(engineer_setting_page_num-1)*10 +i -23].min_value)
                {
                  engineering_param[(engineer_setting_page_num-1)*10 +i -23].fvalue -= 1;
                  SetMed_Fan_Voltage((uint16_t)engineering_param[(engineer_setting_page_num-1)*10 +i -23].fvalue);
                }
              }
              break;

            case 47: 
              if(e->code != LV_EVENT_CLICKED)
              {
                engineering_param[(engineer_setting_page_num-1)*10 +i -24].fvalue = GetMed_Fan_Voltage();
                if(engineering_param[(engineer_setting_page_num-1)*10 +i -24].fvalue < engineering_param[(engineer_setting_page_num-1)*10 +i -24].max_value)
                {
                  engineering_param[(engineer_setting_page_num-1)*10 +i -24].fvalue += 1;
                  SetMed_Fan_Voltage((uint16_t)engineering_param[(engineer_setting_page_num-1)*10 +i -24].fvalue);
                }
              }
              break;

            /*低风档电压*/
            case 48: 
              if(e->code != LV_EVENT_CLICKED)
              {
                engineering_param[(engineer_setting_page_num-1)*10 +i -24].fvalue = GetLow_Fan_Voltage();
                if(engineering_param[(engineer_setting_page_num-1)*10 +i -24].fvalue > engineering_param[(engineer_setting_page_num-1)*10 +i -24].min_value)
                {
                  engineering_param[(engineer_setting_page_num-1)*10 +i -24].fvalue -= 1;
                  SetLow_Fan_Voltage((uint16_t)engineering_param[(engineer_setting_page_num-1)*10 +i -24].fvalue);
                }
              }
              break;

            case 49: 
              if(e->code != LV_EVENT_CLICKED)
              {
                engineering_param[(engineer_setting_page_num-1)*10 +i -25].fvalue = GetLow_Fan_Voltage();
                if(engineering_param[(engineer_setting_page_num-1)*10 +i -25].fvalue < engineering_param[(engineer_setting_page_num-1)*10 +i -25].max_value)
                {
                  engineering_param[(engineer_setting_page_num-1)*10 +i -25].fvalue += 1;
                  SetLow_Fan_Voltage((uint16_t)engineering_param[(engineer_setting_page_num-1)*10 +i -25].fvalue);
                }
              }
              break;

            default:
              break;
          }
        }
      }
    }
  }
  EngineerSettingInterfaceRefresh(0);
}

void EngineerSettingPanelSegXPanelChildPanelSwitchClickedCallback(lv_event_t * e)
{
  if(e->target  == ui_EngineerSettingPanelSeg1PanelChildPanelSwitch)
  {
    if(engineer_setting_page_num == 2)
    { 
      if(lv_obj_has_state(e->target, LV_STATE_CHECKED))
      {
        SetPower_off_memory(1);
      }
      else
      {
        SetPower_off_memory(0);
      }
    }
  }
  else if(e->target  == ui_EngineerSettingPanelSeg2PanelChildPanelSwitch)
  {
    if(engineer_setting_page_num == 2)
    { 
    }
  }
  else if(e->target  == ui_EngineerSettingPanelSeg3PanelChildPanelSwitch)
  {
    if(engineer_setting_page_num == 2)
    { 
      if(lv_obj_has_state(e->target, LV_STATE_CHECKED))
      {
        SetFan_state_with_heat_valve(1);
      }
      else
      {
        SetFan_state_with_heat_valve(0);
      }
    }
  }
  else if(e->target  == ui_EngineerSettingPanelSeg4PanelChildPanelSwitch)
  {
    if(engineer_setting_page_num == 2)
    { 
      if(lv_obj_has_state(e->target, LV_STATE_CHECKED))
      {
        SetFan_state_with_cool_valve(1);
      }
      else
      {
        SetFan_state_with_cool_valve(0);
      }
    }
  }
  else if(e->target  == ui_EngineerSettingPanelSeg5PanelChildPanelSwitch)
  {
    if(engineer_setting_page_num == 2)
    { 
    }
  }
}

void EngineerSettingPanelPreNextPanelClickedCallback(lv_event_t * e)
{
  if(e->target  == ui_EngineerSettingPanelPrePanel)
  {
    engineer_setting_page_num--;
    if(engineer_setting_page_num <= 1)
    {
      engineer_setting_page_num = 1;
    }

    if(engineer_setting_page_num == 4)
    {
      /*第十项屏蔽*/
      if(lv_obj_has_flag(ui_EngineerSettingPanelSeg3PanelChildPanelMinusPanel, LV_OBJ_FLAG_CLICKABLE))
      {
        /*设置面板透明度为100*/
        lv_obj_set_style_opa(ui_EngineerSettingPanelSeg3Panel, 100, LV_PART_MAIN | LV_STATE_DEFAULT);
        /*取消点击*/
        _ui_flag_modify(ui_EngineerSettingPanelSeg3PanelChildPanelMinusPanel, LV_OBJ_FLAG_CLICKABLE, _UI_MODIFY_FLAG_REMOVE);
        _ui_flag_modify(ui_EngineerSettingPanelSeg3PanelChildPanelAddPanel, LV_OBJ_FLAG_CLICKABLE, _UI_MODIFY_FLAG_REMOVE);
      }
    }
    else
    {
      if(!lv_obj_has_flag(ui_EngineerSettingPanelSeg3PanelChildPanelMinusPanel, LV_OBJ_FLAG_CLICKABLE))
      {
        /*设置面板透明度为100*/
        lv_obj_set_style_opa(ui_EngineerSettingPanelSeg3Panel, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
        /*取消点击*/
        _ui_flag_modify(ui_EngineerSettingPanelSeg3PanelChildPanelMinusPanel, LV_OBJ_FLAG_CLICKABLE, _UI_MODIFY_FLAG_ADD);
        _ui_flag_modify(ui_EngineerSettingPanelSeg3PanelChildPanelAddPanel, LV_OBJ_FLAG_CLICKABLE, _UI_MODIFY_FLAG_ADD);
      }
    }

    if(engineer_setting_page_num == 4)
    {
      /*第4项屏蔽*/
      if(lv_obj_has_flag(ui_EngineerSettingPanelSeg4PanelChildPanelMinusPanel, LV_OBJ_FLAG_CLICKABLE))
      {
        /*设置面板透明度为100*/
        lv_obj_set_style_opa(ui_EngineerSettingPanelSeg4Panel, 100, LV_PART_MAIN | LV_STATE_DEFAULT);
        /*取消点击*/
        _ui_flag_modify(ui_EngineerSettingPanelSeg4PanelChildPanelMinusPanel, LV_OBJ_FLAG_CLICKABLE, _UI_MODIFY_FLAG_REMOVE);
        _ui_flag_modify(ui_EngineerSettingPanelSeg4PanelChildPanelAddPanel, LV_OBJ_FLAG_CLICKABLE, _UI_MODIFY_FLAG_REMOVE);
      }
    }
    else
    {
      if(!lv_obj_has_flag(ui_EngineerSettingPanelSeg4PanelChildPanelMinusPanel, LV_OBJ_FLAG_CLICKABLE))
      {
        /*设置面板透明度为100*/
        lv_obj_set_style_opa(ui_EngineerSettingPanelSeg4Panel, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
        /*取消点击*/
        _ui_flag_modify(ui_EngineerSettingPanelSeg4PanelChildPanelMinusPanel, LV_OBJ_FLAG_CLICKABLE, _UI_MODIFY_FLAG_ADD);
        _ui_flag_modify(ui_EngineerSettingPanelSeg4PanelChildPanelAddPanel, LV_OBJ_FLAG_CLICKABLE, _UI_MODIFY_FLAG_ADD);
      }
    }

    if(engineer_setting_page_num == 4)
    {
      /*第5项屏蔽*/
      if(lv_obj_has_flag(ui_EngineerSettingPanelSeg5PanelChildPanelMinusPanel, LV_OBJ_FLAG_CLICKABLE))
      {
        /*设置面板透明度为100*/
        lv_obj_set_style_opa(ui_EngineerSettingPanelSeg5Panel, 100, LV_PART_MAIN | LV_STATE_DEFAULT);
        /*取消点击*/
        _ui_flag_modify(ui_EngineerSettingPanelSeg5PanelChildPanelMinusPanel, LV_OBJ_FLAG_CLICKABLE, _UI_MODIFY_FLAG_REMOVE);
        _ui_flag_modify(ui_EngineerSettingPanelSeg5PanelChildPanelAddPanel, LV_OBJ_FLAG_CLICKABLE, _UI_MODIFY_FLAG_REMOVE);
      }
    }
    else
    {
      if(!lv_obj_has_flag(ui_EngineerSettingPanelSeg5PanelChildPanelMinusPanel, LV_OBJ_FLAG_CLICKABLE))
      {
        /*设置面板透明度为100*/
        lv_obj_set_style_opa(ui_EngineerSettingPanelSeg5Panel, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
        /*取消点击*/
        _ui_flag_modify(ui_EngineerSettingPanelSeg5PanelChildPanelMinusPanel, LV_OBJ_FLAG_CLICKABLE, _UI_MODIFY_FLAG_ADD);
        _ui_flag_modify(ui_EngineerSettingPanelSeg5PanelChildPanelAddPanel, LV_OBJ_FLAG_CLICKABLE, _UI_MODIFY_FLAG_ADD);
      }
    }
  }

  if(e->target  == ui_EngineerSettingPanelNextPanel)
  {
    engineer_setting_page_num++;
    if(engineer_setting_page_num >= 4)
    {
      engineer_setting_page_num = 4;
    }

    if(engineer_setting_page_num == 4)
    {
      /*第十项屏蔽*/
      if(lv_obj_has_flag(ui_EngineerSettingPanelSeg3PanelChildPanelMinusPanel, LV_OBJ_FLAG_CLICKABLE))
      {
        /*设置面板透明度为100*/
        lv_obj_set_style_opa(ui_EngineerSettingPanelSeg3Panel, 100, LV_PART_MAIN | LV_STATE_DEFAULT);
        /*取消点击*/
        _ui_flag_modify(ui_EngineerSettingPanelSeg3PanelChildPanelMinusPanel, LV_OBJ_FLAG_CLICKABLE, _UI_MODIFY_FLAG_REMOVE);
        _ui_flag_modify(ui_EngineerSettingPanelSeg3PanelChildPanelAddPanel, LV_OBJ_FLAG_CLICKABLE, _UI_MODIFY_FLAG_REMOVE);
      }
    }
    else
    {
      if(!lv_obj_has_flag(ui_EngineerSettingPanelSeg3PanelChildPanelMinusPanel, LV_OBJ_FLAG_CLICKABLE))
      {
        /*设置面板透明度为100*/
        lv_obj_set_style_opa(ui_EngineerSettingPanelSeg3Panel, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
        /*取消点击*/
        _ui_flag_modify(ui_EngineerSettingPanelSeg3PanelChildPanelMinusPanel, LV_OBJ_FLAG_CLICKABLE, _UI_MODIFY_FLAG_ADD);
        _ui_flag_modify(ui_EngineerSettingPanelSeg3PanelChildPanelAddPanel, LV_OBJ_FLAG_CLICKABLE, _UI_MODIFY_FLAG_ADD);
      }
    }

    if(engineer_setting_page_num == 4)
    {
      /*第十项屏蔽*/
      if(lv_obj_has_flag(ui_EngineerSettingPanelSeg4PanelChildPanelMinusPanel, LV_OBJ_FLAG_CLICKABLE))
      {
        /*设置面板透明度为100*/
        lv_obj_set_style_opa(ui_EngineerSettingPanelSeg4Panel, 100, LV_PART_MAIN | LV_STATE_DEFAULT);
        /*取消点击*/
        _ui_flag_modify(ui_EngineerSettingPanelSeg4PanelChildPanelMinusPanel, LV_OBJ_FLAG_CLICKABLE, _UI_MODIFY_FLAG_REMOVE);
        _ui_flag_modify(ui_EngineerSettingPanelSeg4PanelChildPanelAddPanel, LV_OBJ_FLAG_CLICKABLE, _UI_MODIFY_FLAG_REMOVE);
      }
    }
    else
    {
      if(!lv_obj_has_flag(ui_EngineerSettingPanelSeg4PanelChildPanelMinusPanel, LV_OBJ_FLAG_CLICKABLE))
      {
        /*设置面板透明度为100*/
        lv_obj_set_style_opa(ui_EngineerSettingPanelSeg4Panel, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
        /*取消点击*/
        _ui_flag_modify(ui_EngineerSettingPanelSeg4PanelChildPanelMinusPanel, LV_OBJ_FLAG_CLICKABLE, _UI_MODIFY_FLAG_ADD);
        _ui_flag_modify(ui_EngineerSettingPanelSeg4PanelChildPanelAddPanel, LV_OBJ_FLAG_CLICKABLE, _UI_MODIFY_FLAG_ADD);
      }
    }

    if(engineer_setting_page_num == 4)
    {
      /*第十项屏蔽*/
      if(lv_obj_has_flag(ui_EngineerSettingPanelSeg5PanelChildPanelMinusPanel, LV_OBJ_FLAG_CLICKABLE))
      {
        /*设置面板透明度为100*/
        lv_obj_set_style_opa(ui_EngineerSettingPanelSeg5Panel, 100, LV_PART_MAIN | LV_STATE_DEFAULT);
        /*取消点击*/
        _ui_flag_modify(ui_EngineerSettingPanelSeg5PanelChildPanelMinusPanel, LV_OBJ_FLAG_CLICKABLE, _UI_MODIFY_FLAG_REMOVE);
        _ui_flag_modify(ui_EngineerSettingPanelSeg5PanelChildPanelAddPanel, LV_OBJ_FLAG_CLICKABLE, _UI_MODIFY_FLAG_REMOVE);
      }
    }
    else
    {
      if(!lv_obj_has_flag(ui_EngineerSettingPanelSeg5PanelChildPanelMinusPanel, LV_OBJ_FLAG_CLICKABLE))
      {
        /*设置面板透明度为100*/
        lv_obj_set_style_opa(ui_EngineerSettingPanelSeg5Panel, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
        /*取消点击*/
        _ui_flag_modify(ui_EngineerSettingPanelSeg5PanelChildPanelMinusPanel, LV_OBJ_FLAG_CLICKABLE, _UI_MODIFY_FLAG_ADD);
        _ui_flag_modify(ui_EngineerSettingPanelSeg5PanelChildPanelAddPanel, LV_OBJ_FLAG_CLICKABLE, _UI_MODIFY_FLAG_ADD);
      }
    }
  }
  EngineerSettingInterfaceRefresh(1);
}



