/**
 * @file hv_app_OsdFactory.c
 * @brief osd app menu c file.
 * @details This file provides the following functions: \n
 *          (1) Osd menu operation functions \n
 *          (2) Osd event operation functions \n
 *
 * @author HiView SoC Software Team
 * @version 1.0.0
 * @date 2022-09-01
 * @copyright Copyright(c),2022-8, Hiview Software. All rights reserved.
 * @par History:
 * <table>
 * <tr><th>Author       <th>Date            <th>Change Description
 * <tr><td>shanpeng     <td>2022-09-01      <td>create
 * </table>
 */

#include "hv_comm_DataBase.h"
#include "hv_mw_AppInterface.h"
#include "hv_mw_OsdComm.h"
#include "hv_mw_OsdLog.h"
#include "hv_mw_OsdDraw.h"
#include "hv_mw_OsdOperation.h"
#include "hv_app_OsdDynamicUpdate.h"
#include "hv_app_Osd.h"
#include "hv_app_OsdFactory.h"
#include "hv_mw_Factory.h"
#include "hv_drv_Eeprom.h"

/********* Factorydata enum define *********/
typedef enum
{
    E_FACTORYDATA_NONE,

    E_FACTORYDATA_FW,
    E_FACTORYDATA_MST,
    E_FACTORYDATA_DATE,
    E_FACTORYDATA_PANEL,
    E_FACTORYDATA_CHECKSUM,
    E_FACTORYDATA_SIZE,

    E_FACTORYDATA_WARM_RV,
    E_FACTORYDATA_WARM_GV,
    E_FACTORYDATA_WARM_BV,
    E_FACTORYDATA_NATURAL_RV,
    E_FACTORYDATA_NATURAL_GV,
    E_FACTORYDATA_NATURAL_BV,
    E_FACTORYDATA_COOL_RV,
    E_FACTORYDATA_COOL_GV,
    E_FACTORYDATA_COOL_BV,
    E_FACTORYDATA_SRGB_RV,
    E_FACTORYDATA_SRGB_GV,
    E_FACTORYDATA_SRGB_BV,
    E_FACTORYDATA_LOGO_V,
    E_FACTORYDATA_BURNLN_V,
    E_FACTORYDATA_PRODUCT_MODE_V,
    E_FACTORYDATA_EDIDWP_V,
    E_FACTORYDATA_PF_V,
    E_FACTORYDATA_PP_V,
    E_FACTORYDATA_DF_V,
    E_FACTORYDATA_DP_V,
    E_FACTORYDATA_DM_V,
    E_FACTORYDATA_BL_TIME,
    E_FACTORYDATA_EDP_FAIL_COUNT_V,
    E_FACTORYDATA_MAX,
}FactorydataId;

typedef struct _FactorydataProp
{
    SHORT16 sCurValue;
    SHORT16 sMinValue;
    SHORT16 sMaxValue;
    BOOL bCircle;
    UCHAR8 aucString[OSD_ASCII_STRING_LENGTH_MAX];
    UCHAR8 ucStringLength;
} FactorydataProp;

typedef struct _OsdItemFactorydata
{
    USHORT16 usItemId;
    USHORT16 usAsciiStringId;
    USHORT16 usFactorydataId;
} OsdItemFactorydata;

static const OsdItemFactorydata s_astFactorydataMapTable[] =
{
    /* SCENE_FACTORY */
    {ITEM_NONE_ID,                       ASCIISTRING_FW_SCENE_FACTORY_NORMAL,               E_FACTORYDATA_FW},
    {ITEM_NONE_ID,                       ASCIISTRING_MST_SCENE_FACTORY_NORMAL,              E_FACTORYDATA_MST},
    {ITEM_NONE_ID,                       ASCIISTRING_DATE_SCENE_FACTORY_NORMAL,             E_FACTORYDATA_DATE},
    {ITEM_NONE_ID,                       ASCIISTRING_PANEL_SCENE_FACTORY_NORMAL,            E_FACTORYDATA_PANEL},
    {ITEM_NONE_ID,                       ASCIISTRING_CHECKSUM_SCENE_FACTORY_NORMAL,         E_FACTORYDATA_CHECKSUM},
    {ITEM_NONE_ID,                       ASCIISTRING_SIZE_SCENE_FACTORY_NORMAL,             E_FACTORYDATA_SIZE},
    {ITEM_NONE_ID,                       ASCIISTRING_EDP_FAIL_COUNT_SCENE_FACTORY_NORMAL,   E_FACTORYDATA_EDP_FAIL_COUNT_V},

    {ITEM_WARM_RV_SCENE_FACTORY,         ASCIISTRING_WR_SCENE_FACTORY_NORMAL,               E_FACTORYDATA_WARM_RV},
    {ITEM_WARM_GV_SCENE_FACTORY,         ASCIISTRING_WG_SCENE_FACTORY_NORMAL,               E_FACTORYDATA_WARM_GV},
    {ITEM_WARM_BV_SCENE_FACTORY,         ASCIISTRING_WB_SCENE_FACTORY_NORMAL,               E_FACTORYDATA_WARM_BV},
    {ITEM_NATURAL_RV_SCENE_FACTORY,      ASCIISTRING_NR_SCENE_FACTORY_NORMAL,               E_FACTORYDATA_NATURAL_RV},
    {ITEM_NATURAL_GV_SCENE_FACTORY,      ASCIISTRING_NG_SCENE_FACTORY_NORMAL,               E_FACTORYDATA_NATURAL_GV},
    {ITEM_NATURAL_BV_SCENE_FACTORY,      ASCIISTRING_NB_SCENE_FACTORY_NORMAL,               E_FACTORYDATA_NATURAL_BV},
    {ITEM_COOL_RV_SCENE_FACTORY,         ASCIISTRING_CR_SCENE_FACTORY_NORMAL,               E_FACTORYDATA_COOL_RV},
    {ITEM_COOL_GV_SCENE_FACTORY,         ASCIISTRING_CG_SCENE_FACTORY_NORMAL,               E_FACTORYDATA_COOL_GV},
    {ITEM_COOL_BV_SCENE_FACTORY,         ASCIISTRING_CB_SCENE_FACTORY_NORMAL,               E_FACTORYDATA_COOL_BV},
    {ITEM_SRGB_RV_SCENE_FACTORY,         ASCIISTRING_SR_SCENE_FACTORY_NORMAL,               E_FACTORYDATA_SRGB_RV},
    {ITEM_SRGB_GV_SCENE_FACTORY,         ASCIISTRING_SG_SCENE_FACTORY_NORMAL,               E_FACTORYDATA_SRGB_GV},
    {ITEM_SRGB_BV_SCENE_FACTORY,         ASCIISTRING_SB_SCENE_FACTORY_NORMAL,               E_FACTORYDATA_SRGB_BV},

    {ITEM_LOGO_V_SCENE_FACTORY,          ASCIISTRING_LOGO_SCENE_FACTORY_NORMAL,             E_FACTORYDATA_LOGO_V},
    {ITEM_BURNLN_V_SCENE_FACTORY,        ASCIISTRING_BURNLN_SCENE_FACTORY_NORMAL,           E_FACTORYDATA_BURNLN_V},
    {ITEM_PRODUCT_MODE_V_SCENE_FACTORY,  ASCIISTRING_PRODUCT_MODE_SCENE_FACTORY_NORMAL,     E_FACTORYDATA_PRODUCT_MODE_V},
    {ITEM_EDIDWP_V_SCENE_FACTORY,        ASCIISTRING_EDIDWP_SCENE_FACTORY_NORMAL,           E_FACTORYDATA_EDIDWP_V},
    {ITEM_PF_V_SCENE_FACTORY,            ASCIISTRING_PF_SCENE_FACTORY_NORMAL,               E_FACTORYDATA_PF_V},
    {ITEM_PP_V_SCENE_FACTORY,            ASCIISTRING_PP_SCENE_FACTORY_NORMAL,               E_FACTORYDATA_PP_V},
    {ITEM_DF_V_SCENE_FACTORY,            ASCIISTRING_DF_SCENE_FACTORY_NORMAL,               E_FACTORYDATA_DF_V},
    {ITEM_DP_V_SCENE_FACTORY,            ASCIISTRING_DP_SCENE_FACTORY_NORMAL,               E_FACTORYDATA_DP_V},
    {ITEM_DM_V_SCENE_FACTORY,            ASCIISTRING_DM_SCENE_FACTORY_NORMAL,               E_FACTORYDATA_DM_V},
    {ITEM_BLIGHT_TIME_SCENE_FACTORY,     ASCIISTRING_TIME_SCENE_FACTORY_NORMAL,             E_FACTORYDATA_BL_TIME},

    /* SCENE_FACTORY_AGING */
    {ITEM_NONE_ID,                       ASCIISTRING_FW_SCENE_FACTORY_AGING_NORMAL,         E_FACTORYDATA_FW},
    {ITEM_NONE_ID,                       ASCIISTRING_MST_SCENE_FACTORY_AGING_NORMAL,        E_FACTORYDATA_MST},
    {ITEM_NONE_ID,                       ASCIISTRING_DATE_SCENE_FACTORY_AGING_NORMAL,       E_FACTORYDATA_DATE},
    {ITEM_NONE_ID,                       ASCIISTRING_PANEL_SCENE_FACTORY_AGING_NORMAL,      E_FACTORYDATA_PANEL},
    {ITEM_NONE_ID,                       ASCIISTRING_CHECKSUM_SCENE_FACTORY_AGING_NORMAL,   E_FACTORYDATA_CHECKSUM},
    {ITEM_NONE_ID,                       ASCIISTRING_SIZE_SCENE_FACTORY_AGING_NORMAL,       E_FACTORYDATA_SIZE},
    {ITEM_NONE_ID,                       ASCIISTRING_TIME_SCENE_FACTORY_AGING_NORMAL,       E_FACTORYDATA_BL_TIME},
};

static FactorydataId Hv_App_OsdGetFactorydataIdByItem(USHORT16 usItemId)
{
    if (usItemId < ITEM_ID_MAX)
    {
        for (USHORT16 usId = 0; usId < ARRAY_SIZE(s_astFactorydataMapTable); usId++)
        {
            if (s_astFactorydataMapTable[usId].usItemId == usItemId)
            {
                return s_astFactorydataMapTable[usId].usFactorydataId;
            }
        }
    }

    return E_FACTORYDATA_NONE;
}

static FactorydataId Hv_App_OsdGetFactorydataIdByAsciistring(USHORT16 usAsciiStringId)
{
    if (usAsciiStringId < ASCII_STRING_ID_MAX)
    {
        for (USHORT16 usId = 0; usId < ARRAY_SIZE(s_astFactorydataMapTable); usId++)
        {
            if (s_astFactorydataMapTable[usId].usAsciiStringId == usAsciiStringId)
            {
                return s_astFactorydataMapTable[usId].usFactorydataId;
            }
        }
    }

    return E_FACTORYDATA_NONE;
}

static VOID Hv_App_OsdSetFactorydata(FactorydataId enWhichData, SHORT16 sValue)
{
    switch (enWhichData)
    {
        case E_FACTORYDATA_WARM_RV:
        {
            ColorTemperature stColTemp = Hv_Mw_Factory_GetColorTemperature(FACTORY_COLOR_TEMPER_WARM);
            stColTemp.ucColorTempRGain = sValue;
            Hv_Mw_Factory_SetColorTemperature(FACTORY_COLOR_TEMPER_WARM, stColTemp);
            break;
        }
        case E_FACTORYDATA_WARM_GV:
        {
            ColorTemperature stColTemp = Hv_Mw_Factory_GetColorTemperature(FACTORY_COLOR_TEMPER_WARM);
            stColTemp.ucColorTempGGain = sValue;
            Hv_Mw_Factory_SetColorTemperature(FACTORY_COLOR_TEMPER_WARM, stColTemp);
            break;
        }
        case E_FACTORYDATA_WARM_BV:
        {
            ColorTemperature stColTemp = Hv_Mw_Factory_GetColorTemperature(FACTORY_COLOR_TEMPER_WARM);
            stColTemp.ucColorTempBGain = sValue;
            Hv_Mw_Factory_SetColorTemperature(FACTORY_COLOR_TEMPER_WARM, stColTemp);
            break;
        }
        case E_FACTORYDATA_NATURAL_RV:
        {
            ColorTemperature stColTemp = Hv_Mw_Factory_GetColorTemperature(FACTORY_COLOR_TEMPER_STANDARD);
            stColTemp.ucColorTempRGain = sValue;
            Hv_Mw_Factory_SetColorTemperature(FACTORY_COLOR_TEMPER_STANDARD, stColTemp);
            break;
        }
        case E_FACTORYDATA_NATURAL_GV:
        {
            ColorTemperature stColTemp = Hv_Mw_Factory_GetColorTemperature(FACTORY_COLOR_TEMPER_STANDARD);
            stColTemp.ucColorTempGGain = sValue;
            Hv_Mw_Factory_SetColorTemperature(FACTORY_COLOR_TEMPER_STANDARD, stColTemp);
            break;
        }
        case E_FACTORYDATA_NATURAL_BV:
        {
            ColorTemperature stColTemp = Hv_Mw_Factory_GetColorTemperature(FACTORY_COLOR_TEMPER_STANDARD);
            stColTemp.ucColorTempBGain = sValue;
            Hv_Mw_Factory_SetColorTemperature(FACTORY_COLOR_TEMPER_STANDARD, stColTemp);
            break;
        }
        case E_FACTORYDATA_COOL_RV:
        {
            ColorTemperature stColTemp = Hv_Mw_Factory_GetColorTemperature(FACTORY_COLOR_TEMPER_COOL);
            stColTemp.ucColorTempRGain = sValue;
            Hv_Mw_Factory_SetColorTemperature(FACTORY_COLOR_TEMPER_COOL, stColTemp);
            break;
        }
        case E_FACTORYDATA_COOL_GV:
        {
            ColorTemperature stColTemp = Hv_Mw_Factory_GetColorTemperature(FACTORY_COLOR_TEMPER_COOL);
            stColTemp.ucColorTempGGain = sValue;
            Hv_Mw_Factory_SetColorTemperature(FACTORY_COLOR_TEMPER_COOL, stColTemp);
            break;
        }
        case E_FACTORYDATA_COOL_BV:
        {
            ColorTemperature stColTemp = Hv_Mw_Factory_GetColorTemperature(FACTORY_COLOR_TEMPER_COOL);
            stColTemp.ucColorTempBGain = sValue;
            Hv_Mw_Factory_SetColorTemperature(FACTORY_COLOR_TEMPER_COOL, stColTemp);
            break;
        }
        case E_FACTORYDATA_SRGB_RV:
        {
            ColorTemperature stColTemp = Hv_Mw_Factory_GetColorTemperature(FACTORY_COLOR_TEMPER_CUSTOM);
            stColTemp.ucColorTempRGain = sValue;
            Hv_Mw_Factory_SetColorTemperature(FACTORY_COLOR_TEMPER_CUSTOM, stColTemp);
            break;
        }
        case E_FACTORYDATA_SRGB_GV:
        {
            ColorTemperature stColTemp = Hv_Mw_Factory_GetColorTemperature(FACTORY_COLOR_TEMPER_CUSTOM);
            stColTemp.ucColorTempGGain = sValue;
            Hv_Mw_Factory_SetColorTemperature(FACTORY_COLOR_TEMPER_CUSTOM, stColTemp);
            break;
        }
        case E_FACTORYDATA_SRGB_BV:
        {
            ColorTemperature stColTemp = Hv_Mw_Factory_GetColorTemperature(FACTORY_COLOR_TEMPER_CUSTOM);
            stColTemp.ucColorTempBGain = sValue;
            Hv_Mw_Factory_SetColorTemperature(FACTORY_COLOR_TEMPER_CUSTOM, stColTemp);
            break;
        }
        case E_FACTORYDATA_LOGO_V:
        {
            HV_COMMON_DATABASE_SET(SystemData, bShowLogoFlag, sValue);
            break;
        }
        case E_FACTORYDATA_BURNLN_V:
        {
            HV_COMMON_DATABASE_SET(SystemData, bBurnInEnable, sValue);
            break;
        }
        case E_FACTORYDATA_PRODUCT_MODE_V:
        {
            //HV_COMMON_DATABASE_SET(FactoryData, bProductMode, sValue);
            //Hv_Mw_Factory_SetProductModeFlag(sValue);
            break;
        }
        case E_FACTORYDATA_EDIDWP_V:
        {
            HV_COMMON_DATABASE_SET(SystemData, bEdidWp, sValue);
            break;
        }
        case E_FACTORYDATA_PF_V:
        {
            Hv_Mw_Factory_SetPanelSscFreq(sValue);
            break;
        }
        case E_FACTORYDATA_PP_V:
        {
            Hv_Mw_Factory_SetPanelSscStep(sValue);
            break;
        }
        case E_FACTORYDATA_DF_V:
        {
            Hv_Mw_Factory_SetDdrSscStep(sValue);
            break;
        }
        case E_FACTORYDATA_DP_V:
        {
            Hv_Mw_Factory_SetDdrSscStep(sValue);
            break;
        }
        case E_FACTORYDATA_DM_V:
        {
            HV_COMMON_DATABASE_SET(SystemData, bDeveloperMode, sValue);
            break;
        }
        default:
        {
            break;
        }
    }
}

static VOID Hv_App_OsdGetFactorydataProp(FactorydataId enWhichData, FactorydataProp *pstFactoryDataProp)
{
    switch (enWhichData)
    {
        case E_FACTORYDATA_FW:
        {
            pstFactoryDataProp->sMinValue = 0;
            pstFactoryDataProp->sMaxValue = 0x7fff;
            pstFactoryDataProp->bCircle = HV_FALSE;
            pstFactoryDataProp->sCurValue = 0;
            pstFactoryDataProp->ucStringLength = Hv_App_OsdSetFirmwareVersionString(pstFactoryDataProp->aucString);
            break;
        }
        case E_FACTORYDATA_MST:
        {
            pstFactoryDataProp->sMinValue = 0;
            pstFactoryDataProp->sMaxValue = 0x7fff;
            pstFactoryDataProp->bCircle = HV_FALSE;
            pstFactoryDataProp->sCurValue = 0;
            pstFactoryDataProp->ucStringLength = HV_SNPRINTF(pstFactoryDataProp->aucString, OSD_ASCII_STRING_LENGTH_MAX, HV_PROJECT_CONFIG_FACTORY_SCALER_MODE);
            break;
        }
        case E_FACTORYDATA_DATE:
        {
            pstFactoryDataProp->sMinValue = 0;
            pstFactoryDataProp->sMaxValue = 0x7fff;
            pstFactoryDataProp->bCircle = HV_FALSE;
            pstFactoryDataProp->sCurValue = 0;
            pstFactoryDataProp->ucStringLength = HV_SNPRINTF(pstFactoryDataProp->aucString, OSD_ASCII_STRING_LENGTH_MAX, HV_PROJECT_CONFIG_FACTORY_FW_CHANGE_DATE);
            break;
        }
        case E_FACTORYDATA_PANEL:
        {
            pstFactoryDataProp->sMinValue = 0;
            pstFactoryDataProp->sMaxValue = 0x7fff;
            pstFactoryDataProp->bCircle = HV_FALSE;
            pstFactoryDataProp->sCurValue = 0;
            pstFactoryDataProp->ucStringLength = HV_SNPRINTF(pstFactoryDataProp->aucString, OSD_ASCII_STRING_LENGTH_MAX, HV_PROJECT_CONFIG_FACTORY_PANEL_TYPE);
            break;
        }
        case E_FACTORYDATA_CHECKSUM:
        {
            pstFactoryDataProp->sMinValue = 0;
            pstFactoryDataProp->sMaxValue = 0x7fff;
            pstFactoryDataProp->bCircle = HV_FALSE;
            pstFactoryDataProp->sCurValue = 0;
            UINT32 uiCheckSum = Hv_Comm_GetCodeVersion();
            pstFactoryDataProp->ucStringLength = HV_SNPRINTF(pstFactoryDataProp->aucString, OSD_ASCII_STRING_LENGTH_MAX, "0x%x", uiCheckSum);
            break;
        }
        case E_FACTORYDATA_SIZE:
        {
            pstFactoryDataProp->sMinValue = 0;
            pstFactoryDataProp->sMaxValue = 0x7fff;
            pstFactoryDataProp->bCircle = HV_FALSE;
            pstFactoryDataProp->sCurValue = 0;
            pstFactoryDataProp->ucStringLength = HV_SNPRINTF(pstFactoryDataProp->aucString, OSD_ASCII_STRING_LENGTH_MAX, HV_PROJECT_CONFIG_FACTORY_PANEL_SIZE);
            break;
        }

        case E_FACTORYDATA_WARM_RV:
        {
            pstFactoryDataProp->sMinValue = 0;
            pstFactoryDataProp->sMaxValue = 255;
            pstFactoryDataProp->bCircle = HV_FALSE;
            ColorTemperature stColTemp = Hv_Mw_Factory_GetColorTemperature(FACTORY_COLOR_TEMPER_WARM);
            pstFactoryDataProp->sCurValue = stColTemp.ucColorTempRGain;
            pstFactoryDataProp->ucStringLength = HV_SNPRINTF(pstFactoryDataProp->aucString, OSD_ASCII_STRING_LENGTH_MAX,
                                                             "%d", pstFactoryDataProp->sCurValue);
            break;
        }
        case E_FACTORYDATA_WARM_GV:
        {
            pstFactoryDataProp->sMinValue = 0;
            pstFactoryDataProp->sMaxValue = 255;
            pstFactoryDataProp->bCircle = HV_FALSE;
            ColorTemperature stColTemp = Hv_Mw_Factory_GetColorTemperature(FACTORY_COLOR_TEMPER_WARM);
            pstFactoryDataProp->sCurValue = stColTemp.ucColorTempGGain;
            pstFactoryDataProp->ucStringLength = HV_SNPRINTF(pstFactoryDataProp->aucString, OSD_ASCII_STRING_LENGTH_MAX,
                                                             "%d", pstFactoryDataProp->sCurValue);
            break;
        }
        case E_FACTORYDATA_WARM_BV:
        {
            pstFactoryDataProp->sMinValue = 0;
            pstFactoryDataProp->sMaxValue = 255;
            pstFactoryDataProp->bCircle = HV_FALSE;
            ColorTemperature stColTemp = Hv_Mw_Factory_GetColorTemperature(FACTORY_COLOR_TEMPER_WARM);
            pstFactoryDataProp->sCurValue = stColTemp.ucColorTempBGain;
            pstFactoryDataProp->ucStringLength = HV_SNPRINTF(pstFactoryDataProp->aucString, OSD_ASCII_STRING_LENGTH_MAX,
                                                             "%d", pstFactoryDataProp->sCurValue);
            break;
        }
        case E_FACTORYDATA_NATURAL_RV:
        {
            pstFactoryDataProp->sMinValue = 0;
            pstFactoryDataProp->sMaxValue = 255;
            pstFactoryDataProp->bCircle = HV_FALSE;
            ColorTemperature stColTemp = Hv_Mw_Factory_GetColorTemperature(FACTORY_COLOR_TEMPER_STANDARD);
            pstFactoryDataProp->sCurValue = stColTemp.ucColorTempRGain;
            pstFactoryDataProp->ucStringLength = HV_SNPRINTF(pstFactoryDataProp->aucString, OSD_ASCII_STRING_LENGTH_MAX,
                                                             "%d", pstFactoryDataProp->sCurValue);
            break;
        }
        case E_FACTORYDATA_NATURAL_GV:
        {
            pstFactoryDataProp->sMinValue = 0;
            pstFactoryDataProp->sMaxValue = 255;
            pstFactoryDataProp->bCircle = HV_FALSE;
            ColorTemperature stColTemp = Hv_Mw_Factory_GetColorTemperature(FACTORY_COLOR_TEMPER_STANDARD);
            pstFactoryDataProp->sCurValue = stColTemp.ucColorTempGGain;
            pstFactoryDataProp->ucStringLength = HV_SNPRINTF(pstFactoryDataProp->aucString, OSD_ASCII_STRING_LENGTH_MAX,
                                                             "%d", pstFactoryDataProp->sCurValue);
            break;
        }
        case E_FACTORYDATA_NATURAL_BV:
        {
            pstFactoryDataProp->sMinValue = 0;
            pstFactoryDataProp->sMaxValue = 255;
            pstFactoryDataProp->bCircle = HV_FALSE;
            ColorTemperature stColTemp = Hv_Mw_Factory_GetColorTemperature(FACTORY_COLOR_TEMPER_STANDARD);
            pstFactoryDataProp->sCurValue = stColTemp.ucColorTempBGain;
            pstFactoryDataProp->ucStringLength = HV_SNPRINTF(pstFactoryDataProp->aucString, OSD_ASCII_STRING_LENGTH_MAX,
                                                             "%d", pstFactoryDataProp->sCurValue);
            break;
        }
        case E_FACTORYDATA_COOL_RV:
        {
            pstFactoryDataProp->sMinValue = 0;
            pstFactoryDataProp->sMaxValue = 255;
            pstFactoryDataProp->bCircle = HV_FALSE;
            ColorTemperature stColTemp = Hv_Mw_Factory_GetColorTemperature(FACTORY_COLOR_TEMPER_COOL);
            pstFactoryDataProp->sCurValue = stColTemp.ucColorTempRGain;
            pstFactoryDataProp->ucStringLength = HV_SNPRINTF(pstFactoryDataProp->aucString, OSD_ASCII_STRING_LENGTH_MAX,
                                                             "%d", pstFactoryDataProp->sCurValue);
            break;
        }
        case E_FACTORYDATA_COOL_GV:
        {
            pstFactoryDataProp->sMinValue = 0;
            pstFactoryDataProp->sMaxValue = 255;
            pstFactoryDataProp->bCircle = HV_FALSE;
            ColorTemperature stColTemp = Hv_Mw_Factory_GetColorTemperature(FACTORY_COLOR_TEMPER_COOL);
            pstFactoryDataProp->sCurValue = stColTemp.ucColorTempGGain;
            pstFactoryDataProp->ucStringLength = HV_SNPRINTF(pstFactoryDataProp->aucString, OSD_ASCII_STRING_LENGTH_MAX,
                                                             "%d", pstFactoryDataProp->sCurValue);
            break;
        }
        case E_FACTORYDATA_COOL_BV:
        {
            pstFactoryDataProp->sMinValue = 0;
            pstFactoryDataProp->sMaxValue = 255;
            pstFactoryDataProp->bCircle = HV_FALSE;
            ColorTemperature stColTemp = Hv_Mw_Factory_GetColorTemperature(FACTORY_COLOR_TEMPER_COOL);
            pstFactoryDataProp->sCurValue = stColTemp.ucColorTempBGain;
            pstFactoryDataProp->ucStringLength = HV_SNPRINTF(pstFactoryDataProp->aucString, OSD_ASCII_STRING_LENGTH_MAX,
                                                             "%d", pstFactoryDataProp->sCurValue);
            break;
        }
        case E_FACTORYDATA_SRGB_RV:
        {
            pstFactoryDataProp->sMinValue = 0;
            pstFactoryDataProp->sMaxValue = 255;
            pstFactoryDataProp->bCircle = HV_FALSE;
            ColorTemperature stColTemp = Hv_Mw_Factory_GetColorTemperature(FACTORY_COLOR_TEMPER_CUSTOM);
            pstFactoryDataProp->sCurValue = stColTemp.ucColorTempRGain;
            pstFactoryDataProp->ucStringLength = HV_SNPRINTF(pstFactoryDataProp->aucString, OSD_ASCII_STRING_LENGTH_MAX,
                                                             "%d", pstFactoryDataProp->sCurValue);
            break;
        }
        case E_FACTORYDATA_SRGB_GV:
        {
            pstFactoryDataProp->sMinValue = 0;
            pstFactoryDataProp->sMaxValue = 255;
            pstFactoryDataProp->bCircle = HV_FALSE;
            ColorTemperature stColTemp = Hv_Mw_Factory_GetColorTemperature(FACTORY_COLOR_TEMPER_CUSTOM);
            pstFactoryDataProp->sCurValue = stColTemp.ucColorTempGGain;
            pstFactoryDataProp->ucStringLength = HV_SNPRINTF(pstFactoryDataProp->aucString, OSD_ASCII_STRING_LENGTH_MAX,
                                                             "%d", pstFactoryDataProp->sCurValue);
            break;
        }
        case E_FACTORYDATA_SRGB_BV:
        {
            pstFactoryDataProp->sMinValue = 0;
            pstFactoryDataProp->sMaxValue = 255;
            pstFactoryDataProp->bCircle = HV_FALSE;
            ColorTemperature stColTemp = Hv_Mw_Factory_GetColorTemperature(FACTORY_COLOR_TEMPER_CUSTOM);
            pstFactoryDataProp->sCurValue = stColTemp.ucColorTempBGain;
            pstFactoryDataProp->ucStringLength = HV_SNPRINTF(pstFactoryDataProp->aucString, OSD_ASCII_STRING_LENGTH_MAX,
                                                             "%d", pstFactoryDataProp->sCurValue);
            break;
        }
        case E_FACTORYDATA_LOGO_V:
        {
            pstFactoryDataProp->sMinValue = HV_FALSE;
            pstFactoryDataProp->sMaxValue = HV_TRUE;
            pstFactoryDataProp->bCircle = HV_TRUE;
            pstFactoryDataProp->sCurValue = HV_COMMON_DATABASE_GET(SystemData, bShowLogoFlag);
            pstFactoryDataProp->ucStringLength = HV_SNPRINTF(pstFactoryDataProp->aucString, OSD_ASCII_STRING_LENGTH_MAX,
                                                             pstFactoryDataProp->sCurValue ? "ON" : "OFF");
            break;
        }
        case E_FACTORYDATA_BURNLN_V:
        {
            pstFactoryDataProp->sMinValue = HV_FALSE;
            pstFactoryDataProp->sMaxValue = HV_TRUE;
            pstFactoryDataProp->bCircle = HV_TRUE;
            pstFactoryDataProp->sCurValue = HV_COMMON_DATABASE_GET(SystemData, bBurnInEnable);
            pstFactoryDataProp->ucStringLength = HV_SNPRINTF(pstFactoryDataProp->aucString, OSD_ASCII_STRING_LENGTH_MAX,
                                                             pstFactoryDataProp->sCurValue ? "ON" : "OFF");
            break;
        }
        case E_FACTORYDATA_PRODUCT_MODE_V:
        {
            pstFactoryDataProp->sMinValue = HV_FALSE;
            pstFactoryDataProp->sMaxValue = HV_TRUE;
            pstFactoryDataProp->bCircle = HV_TRUE;
            pstFactoryDataProp->sCurValue = 0;  //HV_COMMON_DATABASE_GET(FactoryData, bProductMode);
            //pstFactoryDataProp->sCurValue = Hv_Mw_Factory_GetProductModeFlag();
            pstFactoryDataProp->ucStringLength = HV_SNPRINTF(pstFactoryDataProp->aucString, OSD_ASCII_STRING_LENGTH_MAX,
                                                             pstFactoryDataProp->sCurValue ? "ON" : "OFF");
            break;
        }
        case E_FACTORYDATA_EDIDWP_V:
        {
            pstFactoryDataProp->sMinValue = HV_FALSE;
            pstFactoryDataProp->sMaxValue = HV_TRUE;
            pstFactoryDataProp->bCircle = HV_TRUE;
            pstFactoryDataProp->sCurValue = HV_COMMON_DATABASE_GET(SystemData, bEdidWp);
            pstFactoryDataProp->ucStringLength = HV_SNPRINTF(pstFactoryDataProp->aucString, OSD_ASCII_STRING_LENGTH_MAX,
                                                             pstFactoryDataProp->sCurValue ? "ON" : "OFF");
            break;
        }
        case E_FACTORYDATA_PF_V:
        {
            pstFactoryDataProp->sMinValue = 30;
            pstFactoryDataProp->sMaxValue = 33;
            pstFactoryDataProp->bCircle = HV_FALSE;
            pstFactoryDataProp->sCurValue = Hv_Mw_Factory_GetPanelSscFreq();
            pstFactoryDataProp->ucStringLength = HV_SNPRINTF(pstFactoryDataProp->aucString, OSD_ASCII_STRING_LENGTH_MAX,
                                                             "%d", pstFactoryDataProp->sCurValue);
            break;
        }
        case E_FACTORYDATA_PP_V:
        {
            pstFactoryDataProp->sMinValue = 0;
            pstFactoryDataProp->sMaxValue = 5;
            pstFactoryDataProp->bCircle = HV_FALSE;
            pstFactoryDataProp->sCurValue = Hv_Mw_Factory_GetPanelSscSetp();
            pstFactoryDataProp->ucStringLength = HV_SNPRINTF(pstFactoryDataProp->aucString, OSD_ASCII_STRING_LENGTH_MAX,
                                                             "%d", pstFactoryDataProp->sCurValue);
            break;
        }
        case E_FACTORYDATA_DF_V:
        {
            pstFactoryDataProp->sMinValue = 30;
            pstFactoryDataProp->sMaxValue = 100;
            pstFactoryDataProp->bCircle = HV_FALSE;
            pstFactoryDataProp->sCurValue = Hv_Mw_Factory_GetDdrSscFreq();
            pstFactoryDataProp->ucStringLength = HV_SNPRINTF(pstFactoryDataProp->aucString, OSD_ASCII_STRING_LENGTH_MAX,
                                                             "%d", pstFactoryDataProp->sCurValue);
            break;
        }
        case E_FACTORYDATA_DP_V:
        {
            pstFactoryDataProp->sMinValue = 0;
            pstFactoryDataProp->sMaxValue = 15;
            pstFactoryDataProp->bCircle = HV_FALSE;
            pstFactoryDataProp->sCurValue = Hv_Mw_Factory_GetDdrSscSetp();
            pstFactoryDataProp->ucStringLength = HV_SNPRINTF(pstFactoryDataProp->aucString, OSD_ASCII_STRING_LENGTH_MAX,
                                                             "%d", pstFactoryDataProp->sCurValue);
            break;
        }
        case E_FACTORYDATA_DM_V:
        {
            pstFactoryDataProp->sMinValue = HV_FALSE;
            pstFactoryDataProp->sMaxValue = HV_TRUE;
            pstFactoryDataProp->bCircle = HV_TRUE;
            pstFactoryDataProp->sCurValue = HV_COMMON_DATABASE_GET(SystemData, bDeveloperMode);
            pstFactoryDataProp->ucStringLength = HV_SNPRINTF(pstFactoryDataProp->aucString, OSD_ASCII_STRING_LENGTH_MAX,
                                                             pstFactoryDataProp->sCurValue ? "ON" : "OFF");
            break;
        }

        case E_FACTORYDATA_BL_TIME:
        {
            pstFactoryDataProp->sMinValue = 0;
            pstFactoryDataProp->sMaxValue = 0x7fff;
            pstFactoryDataProp->bCircle = HV_TRUE;
            USHORT16 usPanelOnTimeHour = 0;
            USHORT16 usPanelOnTimeMin = 0;
            Hv_Mw_Factory_GetPanelOnTime(&usPanelOnTimeHour, &usPanelOnTimeMin);
            pstFactoryDataProp->sCurValue = usPanelOnTimeHour;
            pstFactoryDataProp->ucStringLength = HV_SNPRINTF(pstFactoryDataProp->aucString, OSD_ASCII_STRING_LENGTH_MAX,
                                                             "%d H", usPanelOnTimeHour);
            break;
        }
        case E_FACTORYDATA_EDP_FAIL_COUNT_V:
        {
            pstFactoryDataProp->sMinValue = 0;
            pstFactoryDataProp->sMaxValue = 0x7fff;
            pstFactoryDataProp->bCircle = HV_FALSE;
            pstFactoryDataProp->sCurValue = 0;  //HV_COMMON_DATABASE_GET(SystemData, ucEdpTrainingNum);
            pstFactoryDataProp->ucStringLength = HV_SNPRINTF(pstFactoryDataProp->aucString, OSD_ASCII_STRING_LENGTH_MAX,
                                                             "%d", pstFactoryDataProp->sCurValue);
            break;
        }

        default:
        {
            break;
        }
    }
}

UCHAR8 Hv_App_OsdFactoryUpdateAsciiString(USHORT16 usAsciiStringId, UCHAR8 *pucString)
{
    USHORT16 usFdataId = Hv_App_OsdGetFactorydataIdByAsciistring(usAsciiStringId);

    if (E_FACTORYDATA_NONE != usFdataId)
    {
        OSD_LOG_DEBUG("Update usAsciiStringId=%d, by fdataId=%d", usAsciiStringId, usFdataId);
        FactorydataProp stFactorydataProp = {0};
        Hv_App_OsdGetFactorydataProp(usFdataId, &stFactorydataProp);
        if (stFactorydataProp.ucStringLength > 0)
        {
            HV_MEMCPY(pucString, &stFactorydataProp.aucString[0], stFactorydataProp.ucStringLength);
        }
        return stFactorydataProp.ucStringLength;
    }
    else
    {
        return 0;
    }
}

static SHORT16 Hv_App_OsdGetFactorydataValue(FactorydataId enWhichData)
{
    FactorydataProp stFactorydataProp = {0};
    Hv_App_OsdGetFactorydataProp(enWhichData, &stFactorydataProp);
    return stFactorydataProp.sCurValue;
}

static SHORT16 Hv_App_OsdAdjustFactoryValue(FactorydataId enWhichData, AdjustAct enAdjustAct, SHORT16 sAdjustValue)
{
    FactorydataProp stFactoryDataProp = {0};
    SHORT16 sValue = 0;

    Hv_App_OsdGetFactorydataProp(enWhichData, &stFactoryDataProp);

    switch (enAdjustAct)
    {
        case ACT_SET:
        {
            sValue = sAdjustValue;
            if (sValue > stFactoryDataProp.sMaxValue)
            {
                OSD_LOG_WARN("Factorydata-%d: set value = %d, limit to max = %d", enWhichData, sValue, stFactoryDataProp.sMaxValue);
                sValue = stFactoryDataProp.sMaxValue;
            }
            else if (sValue < stFactoryDataProp.sMinValue)
            {
                OSD_LOG_WARN("Factorydata-%d: set value = %d, limit to min = %d", enWhichData, sValue, stFactoryDataProp.sMinValue);
                sValue = stFactoryDataProp.sMinValue;
            }
            break;
        }

        case ACT_INCREASE:
        {
            sValue = stFactoryDataProp.sCurValue;
            sValue += sAdjustValue;
            if (sValue > stFactoryDataProp.sMaxValue)
            {
                if (stFactoryDataProp.bCircle)
                {
                    sValue = stFactoryDataProp.sMinValue;
                }
                else
                {
                    sValue = stFactoryDataProp.sMaxValue;
                }
            }
            break;
        }

        case ACT_DECREASE:
        {
            sValue = stFactoryDataProp.sCurValue;
            sValue -= sAdjustValue;
            if (sValue < stFactoryDataProp.sMinValue)
            {
                if (stFactoryDataProp.bCircle)
                {
                    sValue = stFactoryDataProp.sMaxValue;
                }
                else
                {
                    sValue = stFactoryDataProp.sMinValue;
                }
            }
            break;
        }

        default:
        {
            return sValue;
        }
    }

    //if (stFactoryDataProp->sCurValue != sValue)
    //{
        OSD_LOG_DEBUG("Update %d = %d -> %d", enWhichData, stFactoryDataProp.sCurValue, sValue);
        Hv_App_OsdSetFactorydata(enWhichData, sValue);
    //}

    return sValue;
}

static VOID Hv_App_OsdSetAgingDisplaySetting(BOOL bIsAging)
{
    if (bIsAging)
    {
        OSD_LOG_INFO("Set default to enter aging");
        Hv_Mw_OsdAdjustFunction(E_USERDATA_BRIGHTNESS, ACT_SET_DEFAULT, 0, SET_INTERFACE);
        Hv_Mw_OsdAdjustFunction(E_USERDATA_CONTRAST, ACT_SET_DEFAULT, 0, SET_INTERFACE);
        Hv_Mw_OsdAdjustFunction(E_USERDATA_COLOR_SPACE, ACT_SET_DEFAULT, 0, SET_INTERFACE); /* Native */
        Hv_Mw_OsdAdjustFunction(E_USERDATA_GAMMA, ACT_SET_DEFAULT, 0, SET_INTERFACE);
        Hv_Mw_OsdAdjustFunction(E_USERDATA_COLOR_TEMP, ACT_SET_DEFAULT, 0, SET_INTERFACE);
        Hv_Mw_OsdAdjustFunction(E_USERDATA_HUE, ACT_SET_DEFAULT, 0, SET_INTERFACE);
        Hv_Mw_OsdAdjustFunction(E_USERDATA_SATURATION, ACT_SET_DEFAULT, 0, SET_INTERFACE);
        Hv_Mw_OsdAdjustFunction(E_USERDATA_BLACK_LEVEL, ACT_SET_DEFAULT, 0, SET_INTERFACE);
        Hv_Mw_OsdAdjustFunction(E_USERDATA_VARIABLE_BACK_LIGHT, ACT_SET, 0, SET_INTERFACE); /* 关闭动态背光 */
        Hv_Mw_OsdAdjustFunction(E_USERDATA_OSD_TRANS, ACT_SET, 0, SET_INTERFACE); /* 关闭菜单透明度 */
#if (HV_PROJECT_CONFIG_OSD_ROTATION == HV_CONFIG_ON)
        Hv_Mw_OsdAdjustFunction(E_USERDATA_ROTATION, ACT_SET, UD_ROTATION_V_OFF, SET_INTERFACE); /* 关闭旋转 */
#endif
    }
    else
    {
        Hv_Mw_SetFromOsdUserdata(E_USERDATA_BRIGHTNESS);
        Hv_Mw_SetFromOsdUserdata(E_USERDATA_CONTRAST);
        Hv_Mw_SetFromOsdUserdata(E_USERDATA_COLOR_SPACE);
        Hv_Mw_SetFromOsdUserdata(E_USERDATA_GAMMA);
        Hv_Mw_SetFromOsdUserdata(E_USERDATA_COLOR_TEMP);
        Hv_Mw_SetFromOsdUserdata(E_USERDATA_HUE);
        Hv_Mw_SetFromOsdUserdata(E_USERDATA_SATURATION);
        Hv_Mw_SetFromOsdUserdata(E_USERDATA_BLACK_LEVEL);
        Hv_Mw_SetFromOsdUserdata(E_USERDATA_VARIABLE_BACK_LIGHT);
        Hv_Mw_SetFromOsdUserdata(E_USERDATA_OSD_TRANS);
#if (HV_PROJECT_CONFIG_OSD_ROTATION == HV_CONFIG_ON)
        Hv_Mw_SetFromOsdUserdata(E_USERDATA_ROTATION);
#endif
    }
}

static VOID Hv_App_OsdFactoryAgingRefresh(VOID)
{
    OsdBox stScreen = {0};
    OsdBox stSceneBox = {0};
    OsdScene *pstScene = OSD_GET_SCENE(SCENE_FACTORY_AGING);

    Hv_Mw_OsdGetDisplaySize(&stScreen.usW, &stScreen.usH);
    stSceneBox.usX = pstScene->usX;
    stSceneBox.usY = pstScene->usY;
    stSceneBox.usW = pstScene->usWidth;
    stSceneBox.usH = pstScene->usHeight;
    Hv_Mw_OsdCalculateCollisionBox(stScreen, &stSceneBox, 123, 101);
    Hv_Mw_OsdSceneSetPosition(SCENE_FACTORY_AGING, stSceneBox.usX, stSceneBox.usY);

    Hv_Mw_OsdComponentShow(COMPONENT(OSD_CP_TYPE_ASCII_STRING, ASCIISTRING_TIME_SCENE_FACTORY_AGING_NORMAL));
}

VOID Hv_App_OsdFactoryAgingEnter(USHORT16 usValue)
{
    if (Hv_Mw_OsdSceneIsShowing(SCENE_FACTORY_AGING))
    {
        Hv_App_OsdFactoryAgingRefresh();
        return;
    }

    Hv_App_OsdHideAll();
    Hv_Mw_OsdSceneInit(SCENE_FACTORY_AGING);
    Hv_Mw_OsdSceneShow(SCENE_FACTORY_AGING);

    Hv_Mw_OsdSceneSetPositionRatio(SCENE_FACTORY_AGING, HV_TRUE, rand() % 101, 0, INVALID_PARAM_USHORT16);
    Hv_Mw_OsdSceneSetPositionRatio(SCENE_FACTORY_AGING, HV_FALSE, rand() % 101, 0, INVALID_PARAM_USHORT16);

    Hv_Mw_OsdSetAllKeyEnable(HV_FALSE);
    Hv_App_OsdSetAgingDisplaySetting(HV_TRUE);

    OSD_LOG_INFO("Show factory aging");
}

VOID Hv_App_OsdFactoryAgingExit(USHORT16 usValue)
{
    Hv_Mw_OsdSceneHide(SCENE_FACTORY_AGING);
    Hv_Mw_OsdSceneClear(SCENE_FACTORY_AGING);
    Hv_App_OsdSetAgingDisplaySetting(HV_FALSE);
    Hv_Mw_OsdSetAllKeyEnable(HV_TRUE);
}

VOID Hv_App_OsdFactoryMenuEnter(VOID)
{
    USHORT16 usFirstItem = ITEM_WARM_SCENE_FACTORY;
    USHORT16 usChild = ITEM_NONE_ID;

    Hv_Mw_OsdAdjustFunction(E_USERDATA_OSD_TRANS, ACT_SET, 0, SET_INTERFACE);
#if (HV_PROJECT_CONFIG_OSD_ROTATION == HV_CONFIG_ON)
    Hv_Mw_OsdAdjustFunction(E_USERDATA_ROTATION, ACT_SET, UD_ROTATION_V_OFF, SET_INTERFACE); /* 关闭旋转 */
#endif

    Hv_Mw_OsdSetAllKeyEnable(HV_TRUE);

    Hv_App_OsdHideAll();
    Hv_Mw_OsdSceneInit(SCENE_FACTORY);
    Hv_Mw_OsdSceneShow(SCENE_FACTORY);

    Hv_Mw_OsdSetItemNumInPage(20);
    Hv_Mw_OsdItemFocus(usFirstItem);
    Hv_Mw_OsdItemShowListWithSingleChild(usFirstItem);
    
    usChild = CHILD_ITEM(ITEM_WARM_SCENE_FACTORY);
    Hv_Mw_OsdItemShowListWithSingleChild(usChild);
    usChild = CHILD_ITEM(ITEM_NATURAL_SCENE_FACTORY);
    Hv_Mw_OsdItemShowListWithSingleChild(usChild);
    usChild = CHILD_ITEM(ITEM_COOL_SCENE_FACTORY);
    Hv_Mw_OsdItemShowListWithSingleChild(usChild);
    usChild = CHILD_ITEM(ITEM_SRGB_SCENE_FACTORY);
    Hv_Mw_OsdItemShowListWithSingleChild(usChild);

    Hv_Mw_OsdSetKeyRepeatPeriod(OSD_DEFAULT_KEY_REPEAT_PERIOD_MS);
    Hv_Mw_OsdSetKeyState(OSDEVT_KEY_UP, KEY_STATE_REPEATABLE, HV_TRUE);
    Hv_Mw_OsdSetKeyState(OSDEVT_KEY_DOWN, KEY_STATE_REPEATABLE, HV_TRUE);

    Hv_Mw_Factory_SetPanelSscEable(HV_TRUE);
    Hv_Mw_Factory_SetDdrSscEable(HV_TRUE);
    OSD_LOG_INFO("Show factory menu");
}

VOID Hv_App_OsdFactoryMenuExit(VOID)
{
    Hv_Mw_OsdSetKeyState(OSDEVT_KEY_UP, KEY_STATE_REPEATABLE, HV_FALSE);
    Hv_Mw_OsdSetKeyState(OSDEVT_KEY_DOWN, KEY_STATE_REPEATABLE, HV_FALSE);

    Hv_Mw_OsdItemFocusClear();
    Hv_Mw_OsdSceneHide(SCENE_FACTORY);
    Hv_Mw_OsdSceneClear(SCENE_FACTORY);
    Hv_Mw_SetFromOsdUserdata(E_USERDATA_OSD_TRANS);
#if (HV_PROJECT_CONFIG_OSD_ROTATION == HV_CONFIG_ON)
    Hv_Mw_SetFromOsdUserdata(E_USERDATA_ROTATION);
#endif
    Hv_Mw_OsdSetItemNumInPage(0);
}

static VOID Hv_App_OsdFactoryMenuMainf(VOID)
{
    switch (Hv_Mw_OsdGetKeyValue())
    {
        case OSDEVT_KEY_ENTER:
        {
            Hv_Mw_OsdItemFocusChild();
            break;
        }
        case OSDEVT_KEY_UP:
        {
            Hv_Mw_OsdItemFocusPrev();
            break;
        }
        case OSDEVT_KEY_DOWN:
        {
            Hv_Mw_OsdItemFocusNext();
            break;
        }
        case OSDEVT_KEY_EXIT:
        {
            Hv_App_OsdFactoryMenuExit();
            break;
        }
        default:
        {
            break;
        }
    }
}

static VOID Hv_App_OsdFactoryMenuMainf_AdjustItemChild(VOID)
{
    switch (Hv_Mw_OsdGetKeyValue())
    {
        case OSDEVT_KEY_ENTER:
        case OSDEVT_KEY_EXIT:
        {
            Hv_Mw_OsdItemFocusParent();
            break;
        }
        case OSDEVT_KEY_UP:
        {
            USHORT16 usItem = OSD_GET_FOCUSING();
            USHORT16 usFdataId = Hv_App_OsdGetFactorydataIdByItem(usItem);
            /* 更新对应factorydata */
            Hv_App_OsdAdjustFactoryValue(usFdataId, ACT_INCREASE, 1);
            OSD_LOG_DEBUG("Adjust %s: usFdataId = %d", ITEM_NAME(usItem), usFdataId);
            /* 更新显示当前聚焦item */
            Hv_Mw_OsdItemRefresh(usItem);
            break;
        }
        case OSDEVT_KEY_DOWN:
        {
            USHORT16 usItem = OSD_GET_FOCUSING();
            USHORT16 usFdataId = Hv_App_OsdGetFactorydataIdByItem(usItem);
            /* 更新对应factorydata */
            Hv_App_OsdAdjustFactoryValue(usFdataId, ACT_DECREASE, 1);
            OSD_LOG_DEBUG("Adjust %s: usFdataId = %d", ITEM_NAME(usItem), usFdataId);
            /* 更新显示当前聚焦item */
            Hv_Mw_OsdItemRefresh(usItem);
            break;
        }
        default:
        {
            break;
        }
    }
}

static VOID Hv_App_OsdFactoryMenuColorTemp(VOID)
{
    switch (Hv_Mw_OsdGetKeyValue())
    {
        case OSDEVT_KEY_ENTER:
        {
            Hv_Mw_OsdItemFocusChild();
            break;
        }
        case OSDEVT_KEY_UP:
        {
            Hv_Mw_OsdItemFocusPrev();
            break;
        }
        case OSDEVT_KEY_DOWN:
        {
            Hv_Mw_OsdItemFocusNext();
            break;
        }
        case OSDEVT_KEY_EXIT:
        {
            Hv_Mw_OsdItemFocusParent();
            break;
        }
        default:
        {
            break;
        }
    }
}

static VOID Hv_App_OsdUpdataColorTempInterface(USHORT16 usFItemId)
{
    USHORT16 usFdataId = Hv_App_OsdGetFactorydataIdByItem(usFItemId);
    USHORT16 usValue = Hv_App_OsdGetFactorydataValue(usFdataId);
    Hv_App_OsdAdjustFactoryValue(usFdataId, ACT_SET, usValue);
}

/* Item operation begin */
VOID Hv_App_OsdItemWarm_MenuMainf_SceneFactory(VOID)
{
    Hv_App_OsdFactoryMenuMainf();
    if (OSDEVT_KEY_ENTER == Hv_Mw_OsdGetKeyValue())
    {
        Hv_App_OsdUpdataColorTempInterface(ITEM_WARM_RV_SCENE_FACTORY);
        Hv_App_OsdUpdataColorTempInterface(ITEM_WARM_GV_SCENE_FACTORY);
        Hv_App_OsdUpdataColorTempInterface(ITEM_WARM_BV_SCENE_FACTORY);
    }
}
VOID Hv_App_OsdItemNatural_MenuMainf_SceneFactory(VOID)
{
    Hv_App_OsdFactoryMenuMainf();
    if (OSDEVT_KEY_ENTER == Hv_Mw_OsdGetKeyValue())
    {
        Hv_App_OsdUpdataColorTempInterface(ITEM_NATURAL_RV_SCENE_FACTORY);
        Hv_App_OsdUpdataColorTempInterface(ITEM_NATURAL_GV_SCENE_FACTORY);
        Hv_App_OsdUpdataColorTempInterface(ITEM_NATURAL_BV_SCENE_FACTORY);
    }
}
VOID Hv_App_OsdItemCool_MenuMainf_SceneFactory(VOID)
{
    Hv_App_OsdFactoryMenuMainf();
    if (OSDEVT_KEY_ENTER == Hv_Mw_OsdGetKeyValue())
    {
        Hv_App_OsdUpdataColorTempInterface(ITEM_COOL_RV_SCENE_FACTORY);
        Hv_App_OsdUpdataColorTempInterface(ITEM_COOL_GV_SCENE_FACTORY);
        Hv_App_OsdUpdataColorTempInterface(ITEM_COOL_BV_SCENE_FACTORY);
    }
}
VOID Hv_App_OsdItemSrgb_MenuMainf_SceneFactory(VOID)
{
    Hv_App_OsdFactoryMenuMainf();
    if (OSDEVT_KEY_ENTER == Hv_Mw_OsdGetKeyValue())
    {
        Hv_App_OsdUpdataColorTempInterface(ITEM_SRGB_RV_SCENE_FACTORY);
        Hv_App_OsdUpdataColorTempInterface(ITEM_SRGB_GV_SCENE_FACTORY);
        Hv_App_OsdUpdataColorTempInterface(ITEM_SRGB_BV_SCENE_FACTORY);
    }
}

VOID Hv_App_OsdItemLogo_MenuMainf_SceneFactory(VOID)
{
    Hv_App_OsdFactoryMenuMainf();
}
VOID Hv_App_OsdItemLogoV_MenuMainf_SceneFactory(VOID)
{
    Hv_App_OsdFactoryMenuMainf_AdjustItemChild();
}
VOID Hv_App_OsdItemBurnln_MenuMainf_SceneFactory(VOID)
{
    Hv_App_OsdFactoryMenuMainf();
}
VOID Hv_App_OsdItemBurnlnV_MenuMainf_SceneFactory(VOID)
{
    Hv_App_OsdFactoryMenuMainf_AdjustItemChild();
}
VOID Hv_App_OsdItemProductMode_MenuMainf_SceneFactory(VOID)
{
    Hv_App_OsdFactoryMenuMainf();
}
VOID Hv_App_OsdItemProductModeV_MenuMainf_SceneFactory(VOID)
{
    Hv_App_OsdFactoryMenuMainf_AdjustItemChild();
}
VOID Hv_App_OsdItemEdidwp_MenuMainf_SceneFactory(VOID)
{
    Hv_App_OsdFactoryMenuMainf();
}
VOID Hv_App_OsdItemEdidwpV_MenuMainf_SceneFactory(VOID)
{
    Hv_App_OsdFactoryMenuMainf_AdjustItemChild();
}
VOID Hv_App_OsdItemPf_MenuMainf_SceneFactory(VOID)
{
    Hv_App_OsdFactoryMenuMainf();
}
VOID Hv_App_OsdItemPfV_MenuMainf_SceneFactory(VOID)
{
    Hv_App_OsdFactoryMenuMainf_AdjustItemChild();
}
VOID Hv_App_OsdItemPp_MenuMainf_SceneFactory(VOID)
{
    Hv_App_OsdFactoryMenuMainf();
}
VOID Hv_App_OsdItemPpV_MenuMainf_SceneFactory(VOID)
{
    Hv_App_OsdFactoryMenuMainf_AdjustItemChild();
}
VOID Hv_App_OsdItemDf_MenuMainf_SceneFactory(VOID)
{
    Hv_App_OsdFactoryMenuMainf();
}
VOID Hv_App_OsdItemDfV_MenuMainf_SceneFactory(VOID)
{
    Hv_App_OsdFactoryMenuMainf_AdjustItemChild();
}
VOID Hv_App_OsdItemDp_MenuMainf_SceneFactory(VOID)
{
    Hv_App_OsdFactoryMenuMainf();
}
VOID Hv_App_OsdItemDpV_MenuMainf_SceneFactory(VOID)
{
    Hv_App_OsdFactoryMenuMainf_AdjustItemChild();
}
VOID Hv_App_OsdItemDm_MenuMainf_SceneFactory(VOID)
{
    Hv_App_OsdFactoryMenuMainf();
}
VOID Hv_App_OsdItemDmV_MenuMainf_SceneFactory(VOID)
{
    Hv_App_OsdFactoryMenuMainf_AdjustItemChild();
}
VOID Hv_App_OsdItemEepromErase_MenuMainf_SceneFactory(VOID)
{
    if (OSDEVT_KEY_ENTER == Hv_Mw_OsdGetKeyValue())
    {
        /* Erase EEPROM */
        //Hv_Common_Db_Nvm_Init();
    }
    else
    {
        Hv_App_OsdFactoryMenuMainf();
    }
}
VOID Hv_App_OsdItemResetbl_MenuMainf_SceneFactory(VOID)
{
    if (OSDEVT_KEY_ENTER == Hv_Mw_OsdGetKeyValue())
    {
        Hv_Mw_Factory_ResetPanelOnCountTime();
        Hv_Mw_OsdComponentShow(COMPONENT(OSD_CP_TYPE_ASCII_STRING, ASCIISTRING_TIME_SCENE_FACTORY_NORMAL));
    }
    else
    {
        Hv_App_OsdFactoryMenuMainf();
    }
}
VOID Hv_App_OsdItemBlightTime_MenuMainf_SceneFactory(VOID)
{
    /* NEVER FOCUS, DO NOTHING */
}
VOID Hv_App_OsdItemExit_MenuMainf_SceneFactory(VOID)
{
    if (OSDEVT_KEY_ENTER == Hv_Mw_OsdGetKeyValue())
    {
        Hv_App_OsdFactoryMenuExit();
    }
    else
    {
        Hv_App_OsdFactoryMenuMainf();
    }
}
VOID Hv_App_OsdItemCoolr_MenuCool_SceneFactory(VOID)
{
    Hv_App_OsdFactoryMenuColorTemp();
}
VOID Hv_App_OsdItemCoolRv_MenuCool_SceneFactory(VOID)
{
    Hv_App_OsdFactoryMenuMainf_AdjustItemChild();
}
VOID Hv_App_OsdItemCoolg_MenuCool_SceneFactory(VOID)
{
    Hv_App_OsdFactoryMenuColorTemp();
}
VOID Hv_App_OsdItemCoolGv_MenuCool_SceneFactory(VOID)
{
    Hv_App_OsdFactoryMenuMainf_AdjustItemChild();
}
VOID Hv_App_OsdItemCoolb_MenuCool_SceneFactory(VOID)
{
    Hv_App_OsdFactoryMenuColorTemp();
}
VOID Hv_App_OsdItemCoolBv_MenuCool_SceneFactory(VOID)
{
    Hv_App_OsdFactoryMenuMainf_AdjustItemChild();
}
VOID Hv_App_OsdItemNaturalr_MenuNatural_SceneFactory(VOID)
{
    Hv_App_OsdFactoryMenuColorTemp();
}
VOID Hv_App_OsdItemNaturalRv_MenuNatural_SceneFactory(VOID)
{
    Hv_App_OsdFactoryMenuMainf_AdjustItemChild();
}
VOID Hv_App_OsdItemNaturalg_MenuNatural_SceneFactory(VOID)
{
    Hv_App_OsdFactoryMenuColorTemp();
}
VOID Hv_App_OsdItemNaturalGv_MenuNatural_SceneFactory(VOID)
{
    Hv_App_OsdFactoryMenuMainf_AdjustItemChild();
}
VOID Hv_App_OsdItemNaturalb_MenuNatural_SceneFactory(VOID)
{
    Hv_App_OsdFactoryMenuColorTemp();
}
VOID Hv_App_OsdItemNaturalBv_MenuNatural_SceneFactory(VOID)
{
    Hv_App_OsdFactoryMenuMainf_AdjustItemChild();
}
VOID Hv_App_OsdItemWarmr_MenuWarm_SceneFactory(VOID)
{
    Hv_App_OsdFactoryMenuColorTemp();
}
VOID Hv_App_OsdItemWarmRv_MenuWarm_SceneFactory(VOID)
{
    Hv_App_OsdFactoryMenuMainf_AdjustItemChild();
}
VOID Hv_App_OsdItemWarmg_MenuWarm_SceneFactory(VOID)
{
    Hv_App_OsdFactoryMenuColorTemp();
}
VOID Hv_App_OsdItemWarmGv_MenuWarm_SceneFactory(VOID)
{
    Hv_App_OsdFactoryMenuMainf_AdjustItemChild();
}
VOID Hv_App_OsdItemWarmb_MenuWarm_SceneFactory(VOID)
{
    Hv_App_OsdFactoryMenuColorTemp();
}
VOID Hv_App_OsdItemWarmBv_MenuWarm_SceneFactory(VOID)
{
    Hv_App_OsdFactoryMenuMainf_AdjustItemChild();
}
VOID Hv_App_OsdItemSrgbr_MenuSrgb_SceneFactory(VOID)
{
    Hv_App_OsdFactoryMenuColorTemp();
}
VOID Hv_App_OsdItemSrgbRv_MenuSrgb_SceneFactory(VOID)
{
    Hv_App_OsdFactoryMenuMainf_AdjustItemChild();
}
VOID Hv_App_OsdItemSrgbg_MenuSrgb_SceneFactory(VOID)
{
    Hv_App_OsdFactoryMenuColorTemp();
}
VOID Hv_App_OsdItemSrgbGv_MenuSrgb_SceneFactory(VOID)
{
    Hv_App_OsdFactoryMenuMainf_AdjustItemChild();
}
VOID Hv_App_OsdItemSrgbb_MenuSrgb_SceneFactory(VOID)
{
    Hv_App_OsdFactoryMenuColorTemp();
}
VOID Hv_App_OsdItemSrgbBv_MenuSrgb_SceneFactory(VOID)
{
    Hv_App_OsdFactoryMenuMainf_AdjustItemChild();
}
