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

#include "hv_mw_OsdComm.h"
#include "hv_mw_OsdLog.h"
#include "hv_app_OsdTest.h"
#include "hv_app_OsdMenu.h"
#include "hv_app_OsdFactory.h"
#include "hv_comm_DataBase.h"
#include "hv_mw_AppInterface.h"
#include "hv_mw_Channel_Manager.h"
#include "hv_res_OsdMenuOperation.h"
#include "hv_app_OsdDynamicUpdate.h"
#include "hv_mw_Factory.h"
#include "hv_app_OsdMenu.h"
#include "hv_app_Osd.h"
#include "hv_app_OsdDialog.h"
#include "hv_app_OsdFactory.h"
#include "hv_mw_OsdOperation.h"
#include "hv_cal_Osd.h"
#include "hv_mw_OsdEvent.h"
#include "hv_drv_Osd.h"
#include "hv_mw_EventHub.h"
#include "hv_mw_OsdDraw.h"
#include "hv_drv_Osd.h"
#include "hv_app_OsdTest.h"

#if (HV_OSD_CONFIG_AUTO_TEST == HV_CONFIG_ON)
static OsdTestInfo s_stOsdTestInfo;
static UINT32  s_uiDelayTimeMs =  TEST_DELAY_TIME;
static UINT32  s_uiDelayTimeMsBk = TEST_DELAY_TIME;
static BOOL s_bMenuAdjustable = HV_TRUE;
static OsdTestTextCfg s_stOsdTestText = {.usWinWidth = 600, .usWinHeight = 800, .usCurTextIndex = 0, .ucColumns = 4, .ucColorSel = 0, .ucCurFontType = 0, .ucCurPage = 1, .ucLangStart = 0};
static OsdColorType arColors[] = {OSD_WHITE, OSD_RED, OSD_GREEN, OSD_BLUE, OSD_YELLOW};
static UCHAR8 s_ucFontType[TEST_TEXT_FONTSIZE_NUM] = {OSD_RESOURCE_SIZE_16X18};
static UCHAR8 s_ucCurLangIndex = OSD_LANGUAGE_EN;
static USHORT16 s_usWinX[]  = {1400, 1000, 600, 200};

static VOID Hv_App_OsdTestInfoInit(VOID)
{
    s_stOsdTestInfo.bIsAutoTesting = HV_TRUE;
    s_stOsdTestInfo.ucTestIndex = OSDEVT_TEST_SCENESHOW;
    s_stOsdTestInfo.bTestInterrupt = HV_FALSE;
    s_stOsdTestInfo.bTestFirst = HV_TRUE;
    s_stOsdTestInfo.ucTestNextAct = OSDACT_NONE;;
    s_stOsdTestInfo.usLangIndex = 0;
    s_stOsdTestInfo.ucRotationIndex = 0;
    s_stOsdTestInfo.ucSceneIndex = 0;
    s_stOsdTestInfo.usCurrentSceneId = 0;
    s_stOsdTestInfo.ucCurrentItemId = 0;
    s_stOsdTestInfo.ucSelectedValue = 0;
    s_stOsdTestInfo.usLevel1TestedNum = 0;
    s_stOsdTestInfo.usLevel2TestedNum = 0;
    s_stOsdTestInfo.usLevel3TestedNum = 0;
    s_stOsdTestInfo.usLevel4TestedNum = 0;
    s_stOsdTestInfo.usLevel5TestedNum = 0;
}

static VOID Hv_App_OsdTestSceneEnter(VOID)
{
    UCHAR8 ucVideoSource = HV_COMMON_DATABASE_GET(UserData, ucVideoSource);

    if (SCENE_FACTORY_AGING == s_stOsdTestInfo.usCurrentSceneId)
    {
        Hv_App_OsdFactoryAgingEnter(0);
    }
    else if(SCENE_INPUT_SOURCE == s_stOsdTestInfo.usCurrentSceneId)
    {
        Hv_App_OsdSourcePlugInEnter(ucVideoSource);
    }
    else if(SCENE_INPUT_SOURCE_SUB == s_stOsdTestInfo.usCurrentSceneId)
    {
        Hv_App_OsdSubSourcePlugInEnter(ucVideoSource);
    }
    else if (SCENE_NOSIGNAL == s_stOsdTestInfo.usCurrentSceneId)
    {
        Hv_App_OsdNoSignalEnter(ucVideoSource);
    }
    else if (SCENE_SIGNAL_UNSUPPORT == s_stOsdTestInfo.usCurrentSceneId)
    {
        Hv_App_OsdSignalUnsupportEnter(0);
    }
    else if (SCENE_LOCK == s_stOsdTestInfo.usCurrentSceneId)
    {
        Hv_App_OsdLockEnter(0);
    }
    else
    {
        Hv_App_OsdHideAll();
        Hv_Mw_OsdSceneInit(s_stOsdTestInfo.usCurrentSceneId);
        Hv_Mw_OsdSceneShow(s_stOsdTestInfo.usCurrentSceneId);
        USHORT16 usFirstItem = s_stOsdTestInfo.ucCurrentItemId;
        if(ITEM_NONE_ID != usFirstItem)
        {
            Hv_Mw_OsdItemFocus(usFirstItem);
            Hv_Mw_OsdItemShowList(usFirstItem);
        }
    }
}

static const OsdTestKeyList s_astOsdTestKeyListTable[] =
{
    {
        OSDEVT_KEY_RIGHT, OSDEVT_KEY_LEFT, OSDEVT_KEY_DOWN,               /* usKeyLevel1_2   usKeyLevel2_1   usKeyLevel1Next */
        OSDEVT_KEY_RIGHT, OSDEVT_KEY_LEFT, OSDEVT_KEY_DOWN,               /* usKeyLevel2_3   usKeyLevel3_2   usKeyLevel2Next */
        OSDEVT_KEY_RIGHT, OSDEVT_KEY_LEFT, OSDEVT_KEY_DOWN,               /* usKeyLevel3_4   usKeyLevel4_3   usKeyLevel3Next */
        OSDEVT_KEY_RIGHT, OSDEVT_KEY_LEFT, OSDEVT_KEY_RIGHT,              /* usKeyLevel4_5   usKeyLevel5_4   usKeyLevel4Next */
        OSDEVT_KEY_DOWN                                                   /* usKeyLevel5Next */
    },

    {
        OSDEVT_KEY_RIGHT, OSDEVT_KEY_LEFT, OSDEVT_KEY_DOWN,               /* usKeyLevel1_2   usKeyLevel2_1   usKeyLevel1Next */
        OSDEVT_KEY_RIGHT, OSDEVT_KEY_LEFT, OSDEVT_KEY_DOWN,               /* usKeyLevel2_3   usKeyLevel3_2   usKeyLevel2Next */
        OSDEVT_KEY_RIGHT, OSDEVT_KEY_LEFT, OSDEVT_KEY_DOWN,               /* usKeyLevel3_4   usKeyLevel4_3   usKeyLevel3Next */
        OSDEVT_KEY_RIGHT, OSDEVT_KEY_LEFT, OSDEVT_KEY_DOWN,               /* usKeyLevel4_5   usKeyLevel5_4   usKeyLevel4Next */
        OSDEVT_KEY_DOWN                                                   /* usKeyLevel5Next */
    }
};

static const OsdTestScene s_astOsdTestSceneMapTable[] =
{
    /* sceneId,                   绘制函数                             是否需要调整菜单           FirstItemId (调用Hv_App_OsdTestSceneEnter绘制时需要)            菜单调整按键       */
    {SCENE_MAIN,                  Hv_App_OsdMainMenuEnter,             HV_TRUE,       ITEM_GAME_SCENE_MAIN,                             s_astOsdTestKeyListTable[0]},
    {SCENE_BRIGHTNESS,            Hv_App_OsdBrightnessAdjustMenuEnter, HV_FALSE,      ITEM_NONE_ID,                                     s_astOsdTestKeyListTable[0]},
    {SCENE_CROSSHAIR_ADJUST,      Hv_App_OsdCrosshairAdjustMenuEnter,  HV_TRUE,      ITEM_NONE_ID,                                     s_astOsdTestKeyListTable[0]},
    {SCENE_FACTORY,               Hv_App_OsdFactoryMenuEnter,          HV_FALSE,      ITEM_NONE_ID,                                     s_astOsdTestKeyListTable[1]},
    {SCENE_FACTORY_AGING,         Hv_App_OsdTestSceneEnter,            HV_FALSE,      ITEM_NONE_ID,                                     s_astOsdTestKeyListTable[0]},
    {SCENE_INPUT,                 Hv_App_OsdInputMenuEnter,            HV_FALSE,      ITEM_NONE_ID,                                     s_astOsdTestKeyListTable[0]},
    {SCENE_INPUT_SOURCE,          Hv_App_OsdTestSceneEnter,            HV_FALSE,      ITEM_INPUT_TIMING_SCENE_INPUT_SOURCE,             s_astOsdTestKeyListTable[0]},
    {SCENE_INPUT_SOURCE_SUB,      Hv_App_OsdTestSceneEnter,            HV_FALSE,      ITEM_INPUT_TIMING_SCENE_INPUT_SOURCE_SUB,         s_astOsdTestKeyListTable[0]},
    {SCENE_LOCK,                  Hv_App_OsdTestSceneEnter,            HV_FALSE,      ITEM_NONE_ID,                                     s_astOsdTestKeyListTable[0]},
    //{SCENE_LOGO,                  Hv_App_OsdTestSceneEnter,            HV_FALSE,      ITEM_NONE_ID,                                     s_astOsdTestKeyListTable[0]},
    {SCENE_MODE,                  Hv_App_OsdModeMenuEnter,             HV_TRUE,       ITEM_MODE_ADJUST_SCENE_MODE,                      s_astOsdTestKeyListTable[0]},
    {SCENE_NOSIGNAL,              Hv_App_OsdTestSceneEnter,            HV_FALSE,      ITEM_NO_SIGNAL_SCENE_NOSIGNAL,                    s_astOsdTestKeyListTable[0]},
    {SCENE_NOSIGNAL_SUB,          Hv_App_OsdTestSceneEnter,            HV_FALSE,      ITEM_NO_SIGNAL_SUB_SCENE_NOSIGNAL_SUB,            s_astOsdTestKeyListTable[0]},
    {SCENE_OTA,                   Hv_App_OsdOtaEnter,                  HV_FALSE,      ITEM_YES_SCENE_OTA,                               s_astOsdTestKeyListTable[0]},
    {SCENE_REFRESH_RATE,          Hv_App_OsdTestSceneEnter,            HV_FALSE,      ITEM_NONE_ID,                                     s_astOsdTestKeyListTable[0]},
    {SCENE_SIGNAL_UNSUPPORT,      Hv_App_OsdTestSceneEnter,            HV_FALSE,      ITEM_NONE_ID,                                     s_astOsdTestKeyListTable[0]},
    {SCENE_TIMER,                 Hv_App_OsdTestSceneEnter,            HV_FALSE,      ITEM_NONE_ID,                                     s_astOsdTestKeyListTable[0]},
    {SCENE_VOLUME,                Hv_App_OsdTestSceneEnter,            HV_FALSE,      ITEM_VOLUME_ADJUST_SCENE_VOLUME,                                     s_astOsdTestKeyListTable[0]}
};

static USHORT16 Hv_App_OsdTestSceneLevel5(VOID)
{
    USHORT16 usValue = 0;
    USHORT16 usItem = OSD_GET_FOCUSING();
    USHORT16 usItemNum = Hv_Mw_OsdItemGetListNum(usItem);
    if (OSDACT_NEXT == s_stOsdTestInfo.ucTestNextAct)
    {
        if(s_stOsdTestInfo.usLevel5TestedNum < usItemNum -1)
        {
            usValue = s_astOsdTestSceneMapTable[s_stOsdTestInfo.ucSceneIndex].stKeyList.usKeyLevel4Next;
            s_stOsdTestInfo.ucTestNextAct = OSDACT_NEXT;
            s_stOsdTestInfo.usLevel5TestedNum ++;
            return usValue;
        }
        else
        {
            usValue = s_astOsdTestSceneMapTable[s_stOsdTestInfo.ucSceneIndex].stKeyList.usKeyLevel5_4;
            s_stOsdTestInfo.ucTestNextAct = OSDACT_NEXT;
            return usValue;
        }
    }
    else if (OSDACT_BACK == s_stOsdTestInfo.ucTestNextAct)
    {
        usValue = s_astOsdTestSceneMapTable[s_stOsdTestInfo.ucSceneIndex].stKeyList.usKeyLevel5_4;
        s_stOsdTestInfo.ucTestNextAct = OSDACT_NEXT;
    }
    return usValue;
}

static USHORT16 Hv_App_OsdTestSceneLevel4(VOID)
{
    USHORT16 usValue = 0;
    USHORT16 usItem = OSD_GET_FOCUSING();
    USHORT16 usItemNum = Hv_Mw_OsdItemGetListNum(usItem);
    if (OSDACT_ENTER == s_stOsdTestInfo.ucTestNextAct)
    {
        if (ITEM_NONE_ID != CHILD_ITEM(usItem))
        {
            usValue = s_astOsdTestSceneMapTable[s_stOsdTestInfo.ucSceneIndex].stKeyList.usKeyLevel4_5;
            s_stOsdTestInfo.usLevel5TestedNum = 0;
            s_stOsdTestInfo.ucTestNextAct = OSDACT_NEXT;
            return usValue;
        }
        else
        {
            if(s_stOsdTestInfo.usLevel4TestedNum < usItemNum -1)
            {
                usValue = s_astOsdTestSceneMapTable[s_stOsdTestInfo.ucSceneIndex].stKeyList.usKeyLevel4Next;
                s_stOsdTestInfo.ucTestNextAct = OSDACT_ENTER;
                s_stOsdTestInfo.usLevel4TestedNum ++;
                return usValue;
            }
            else
            {
                usValue = s_astOsdTestSceneMapTable[s_stOsdTestInfo.ucSceneIndex].stKeyList.usKeyLevel4_3;
                s_stOsdTestInfo.ucTestNextAct = OSDACT_NEXT;
                return usValue;
            }
        }
    }
    else if (OSDACT_NEXT == s_stOsdTestInfo.ucTestNextAct)
    {
        if(s_stOsdTestInfo.usLevel4TestedNum < usItemNum -1)
        {
            usValue = s_astOsdTestSceneMapTable[s_stOsdTestInfo.ucSceneIndex].stKeyList.usKeyLevel4Next;
            s_stOsdTestInfo.ucTestNextAct = OSDACT_ENTER;
            s_stOsdTestInfo.usLevel4TestedNum ++;
            return usValue;
        }
        else
        {
            usValue = s_astOsdTestSceneMapTable[s_stOsdTestInfo.ucSceneIndex].stKeyList.usKeyLevel4_3;
            s_stOsdTestInfo.ucTestNextAct = OSDACT_NEXT;
            return usValue;
        }
    }
    else if (OSDACT_BACK == s_stOsdTestInfo.ucTestNextAct)
    {
        usValue = s_astOsdTestSceneMapTable[s_stOsdTestInfo.ucSceneIndex].stKeyList.usKeyLevel4_3;
        s_stOsdTestInfo.ucTestNextAct = OSDACT_NEXT;
    }
    return usValue;
}

static USHORT16 Hv_App_OsdTestSceneLevel3(VOID)
{
    USHORT16 usValue = 0;
    USHORT16 usItem = OSD_GET_FOCUSING();
    USHORT16 usItemNum = Hv_Mw_OsdItemGetListNum(usItem);
    if (OSDACT_ENTER == s_stOsdTestInfo.ucTestNextAct)
    {
        if (ITEM_NONE_ID != CHILD_ITEM(usItem))
        {
            usValue = s_astOsdTestSceneMapTable[s_stOsdTestInfo.ucSceneIndex].stKeyList.usKeyLevel3_4;
            s_stOsdTestInfo.usLevel4TestedNum = 0;
            s_stOsdTestInfo.usLevel5TestedNum = 0;
            s_stOsdTestInfo.ucTestNextAct = OSDACT_ENTER;
#if (HV_CONFIG_OFF == TEST_SELECT_ENTER)
            USHORT16 usChildItem = CHILD_ITEM(usItem);
            if (ITEM_NONE_ID != Hv_Mw_OsdItemFindSelected(usChildItem, HV_FALSE))
            {
                usValue = s_astOsdTestSceneMapTable[s_stOsdTestInfo.ucSceneIndex].stKeyList.usKeyLevel3Next;
                s_stOsdTestInfo.usLevel2TestedNum ++;
                s_stOsdTestInfo.ucTestNextAct = OSDACT_ENTER;
            }
#endif
            return usValue;
        }
        else
        {
            if(s_stOsdTestInfo.usLevel3TestedNum < usItemNum -1)
            {
                usValue = s_astOsdTestSceneMapTable[s_stOsdTestInfo.ucSceneIndex].stKeyList.usKeyLevel3Next;
                s_stOsdTestInfo.ucTestNextAct = OSDACT_ENTER;
                s_stOsdTestInfo.usLevel3TestedNum ++;
                return usValue;
            }
            else
            {
                usValue = s_astOsdTestSceneMapTable[s_stOsdTestInfo.ucSceneIndex].stKeyList.usKeyLevel3_2;
                s_stOsdTestInfo.ucTestNextAct = OSDACT_NEXT;
                return usValue;
            }
        }
    }
    else if (OSDACT_NEXT == s_stOsdTestInfo.ucTestNextAct)
    {
        if(s_stOsdTestInfo.usLevel3TestedNum < usItemNum -1)
        {
            usValue = s_astOsdTestSceneMapTable[s_stOsdTestInfo.ucSceneIndex].stKeyList.usKeyLevel3Next;
            s_stOsdTestInfo.ucTestNextAct = OSDACT_ENTER;
            s_stOsdTestInfo.usLevel3TestedNum ++;
            return usValue;
        }
        else
        {
            usValue = s_astOsdTestSceneMapTable[s_stOsdTestInfo.ucSceneIndex].stKeyList.usKeyLevel3_2;
            s_stOsdTestInfo.ucTestNextAct = OSDACT_NEXT;
            return usValue;
        }
    }
    else if (OSDACT_BACK == s_stOsdTestInfo.ucTestNextAct)
    {
        usValue = s_astOsdTestSceneMapTable[s_stOsdTestInfo.ucSceneIndex].stKeyList.usKeyLevel3_2;
        s_stOsdTestInfo.ucTestNextAct = OSDACT_NEXT;
    }
    return usValue;
}

static USHORT16 Hv_App_OsdTestSceneLevel2(VOID)
{
    USHORT16 usValue = 0;
    USHORT16 usItem = OSD_GET_FOCUSING();
    USHORT16 usItemNum = Hv_Mw_OsdItemGetListNum(usItem);
    if (OSDACT_ENTER == s_stOsdTestInfo.ucTestNextAct)
    {
        if (ITEM_NONE_ID != CHILD_ITEM(usItem))
        {
            usValue = s_astOsdTestSceneMapTable[s_stOsdTestInfo.ucSceneIndex].stKeyList.usKeyLevel2_3;
            s_stOsdTestInfo.usLevel3TestedNum = 0;
            s_stOsdTestInfo.usLevel4TestedNum = 0;
            s_stOsdTestInfo.usLevel5TestedNum = 0;
            s_stOsdTestInfo.ucSelectedValue = 0;
            s_stOsdTestInfo.ucTestNextAct = OSDACT_ENTER;
#if (HV_CONFIG_OFF == TEST_SELECT_ENTER)
            USHORT16 usChildItem = CHILD_ITEM(usItem);
            if (ITEM_NONE_ID != Hv_Mw_OsdItemFindSelected(usChildItem, HV_FALSE))
            {
                usValue = s_astOsdTestSceneMapTable[s_stOsdTestInfo.ucSceneIndex].stKeyList.usKeyLevel2Next;
                s_stOsdTestInfo.usLevel2TestedNum ++;
                s_stOsdTestInfo.ucTestNextAct = OSDACT_ENTER;
            }
#endif
            return usValue;
        }
        else
        {
            if(s_stOsdTestInfo.usLevel2TestedNum < usItemNum -1)
            {
                usValue = s_astOsdTestSceneMapTable[s_stOsdTestInfo.ucSceneIndex].stKeyList.usKeyLevel2Next;
                s_stOsdTestInfo.ucTestNextAct = OSDACT_ENTER;
                s_stOsdTestInfo.usLevel2TestedNum ++;
                return usValue;
            }
            else
            {
                usValue = s_astOsdTestSceneMapTable[s_stOsdTestInfo.ucSceneIndex].stKeyList.usKeyLevel2_1;
                s_stOsdTestInfo.ucTestNextAct = OSDACT_NEXT;
                return usValue;
            }
        }
    }
    else if (OSDACT_NEXT == s_stOsdTestInfo.ucTestNextAct)
    {
        if(s_stOsdTestInfo.usLevel2TestedNum < usItemNum -1)
        {
            usValue = s_astOsdTestSceneMapTable[s_stOsdTestInfo.ucSceneIndex].stKeyList.usKeyLevel2Next;
            s_stOsdTestInfo.ucTestNextAct = OSDACT_ENTER;
            s_stOsdTestInfo.usLevel2TestedNum ++;
            return usValue;
        }
        else
        {
            usValue = s_astOsdTestSceneMapTable[s_stOsdTestInfo.ucSceneIndex].stKeyList.usKeyLevel2_1;
            s_stOsdTestInfo.ucTestNextAct = OSDACT_NEXT;
            return usValue;
        }
    }
    else if (OSDACT_BACK == s_stOsdTestInfo.ucTestNextAct)
    {
        usValue = s_astOsdTestSceneMapTable[s_stOsdTestInfo.ucSceneIndex].stKeyList.usKeyLevel2_1;
        s_stOsdTestInfo.ucTestNextAct = OSDACT_NEXT;
    }
    return usValue;
}

static USHORT16 Hv_App_OsdTestSceneLevel1(VOID)
{
    USHORT16 usValue = 0;
    USHORT16 usItem = OSD_GET_FOCUSING();
    USHORT16 usItemNum = Hv_Mw_OsdItemGetListNum(usItem);
    if (OSDACT_ENTER == s_stOsdTestInfo.ucTestNextAct)
    {
        if (ITEM_NONE_ID != CHILD_ITEM(usItem))
        {
            usValue = s_astOsdTestSceneMapTable[s_stOsdTestInfo.ucSceneIndex].stKeyList.usKeyLevel1_2;
            s_stOsdTestInfo.usLevel2TestedNum = 0;
            s_stOsdTestInfo.usLevel3TestedNum = 0;
            s_stOsdTestInfo.usLevel4TestedNum = 0;
            s_stOsdTestInfo.usLevel5TestedNum = 0;
            s_stOsdTestInfo.ucSelectedValue = 0;
            s_stOsdTestInfo.ucTestNextAct = OSDACT_ENTER;
            return usValue;
        }
        else
        {
            if(s_stOsdTestInfo.usLevel1TestedNum < usItemNum -1)
            {
                usValue = s_astOsdTestSceneMapTable[s_stOsdTestInfo.ucSceneIndex].stKeyList.usKeyLevel1Next;
                s_stOsdTestInfo.ucTestNextAct = OSDACT_ENTER;
                s_stOsdTestInfo.usLevel1TestedNum ++;
                OSD_LOG_DEBUG("level1 tested num-%d, Level1 item nums- %d",s_stOsdTestInfo.usLevel1TestedNum, usItemNum);
                /* 菜单轮询完毕，进入一下Scene            */
                if (s_stOsdTestInfo.usLevel1TestedNum == usItemNum)
                {
                    s_stOsdTestInfo.bTestFirst = HV_TRUE;
                }
                return usValue;
            }
            else
            {
                if (usItemNum == 1)
                {
                   
                    USHORT16 usUserdata = OSD_GET_USERDATA(usItem);
                    if(usUserdata != E_USERDATA_NONE)
                    {
                        UserdataProp stProp = { 0 };
                        Hv_App_GetOsdUserdataProp(usUserdata, &stProp);
                        OSD_LOG_INFO("MinValue-%d, MaxValue-%d",stProp.sMinValue, stProp.sMaxValue);
                        if (s_stOsdTestInfo.ucSelectedValue < stProp.sMaxValue)
                        {
                            usValue = TEST_SELECTEED_EVT_KEY;
                            s_stOsdTestInfo.ucSelectedValue ++;
                            return usValue;
                        }
                        else
                        {
                            usValue = 0xFF;
                            s_stOsdTestInfo.bTestFirst = HV_TRUE;
                        }
                    }
                    return usValue;
                }
                else
                {
                    usValue = 0xFF;
                    return usValue;
                }
            }
        }
    }
    else if (OSDACT_NEXT == s_stOsdTestInfo.ucTestNextAct)
    {
        if(s_stOsdTestInfo.usLevel1TestedNum < usItemNum -1)
        {
            usValue = s_astOsdTestSceneMapTable[s_stOsdTestInfo.ucSceneIndex].stKeyList.usKeyLevel1Next;
            s_stOsdTestInfo.ucTestNextAct = OSDACT_ENTER;
            s_stOsdTestInfo.usLevel1TestedNum ++;
            OSD_LOG_DEBUG("level1 tested num-%d, Level1 item nums- %d",s_stOsdTestInfo.usLevel1TestedNum, usItemNum);
            /* 菜单轮询完毕，进入一下Scene            */
            if (s_stOsdTestInfo.usLevel1TestedNum == usItemNum)
            {
                s_stOsdTestInfo.bTestFirst = HV_TRUE;
            }
            return usValue;
        }
        else
        {
            usValue = 0xFF;
            return usValue;
        }
    }
    return usValue;
}

static VOID Hv_App_OsdTestScene(VOID)
{
    USHORT16 usEventId = OSD_EVENT_KEY_PRESS;
    USHORT16 usValue = 0;
    const OsdItemProp* pstItemProp = OSD_GET_ITEM_PROP(OSD_GET_FOCUSING());
    if (NULL == pstItemProp)
    {
        /* 没有焦点则进入下一个scene           */
        {
            Hv_Mw_OsdStartAutoTestTimer(s_uiDelayTimeMs);
            s_stOsdTestInfo.bTestFirst = HV_TRUE;
            return;
        }
    }
    else
    {
        USHORT16 usItem = OSD_GET_FOCUSING();
        USHORT16 usLevel = Hv_Mw_OsdItemGetLevel(usItem);
        if (0 == usLevel)
        {
           usValue = Hv_App_OsdTestSceneLevel1();
        }
        else if(1 == usLevel)
        {
            usValue = Hv_App_OsdTestSceneLevel2();
        }
        else if(2 == usLevel)
        {
            usValue = Hv_App_OsdTestSceneLevel3();
        }
        else if(3 == usLevel)
        {
            usValue = Hv_App_OsdTestSceneLevel4();
        }
        else
        {
            usValue = Hv_App_OsdTestSceneLevel5();
        }
    }

    if (usValue == 0xFF)
    {
        s_stOsdTestInfo.bTestFirst = HV_TRUE;
        Hv_App_OsdAutoTestNextAct(0);
    }
    else
    {
        hv_mw_EventHub_SendOsdEvent(usEventId, usValue);
        Hv_Mw_OsdStartAutoTestTimer(s_uiDelayTimeMs);
    }
}

static BOOL Hv_App_OsdTestSetFunction(VOID)
{
    BOOL bIsTestOver = HV_FALSE;
    switch (s_stOsdTestInfo.ucTestIndex)
    {
#if (HV_CONFIG_ON == HV_PROJECT_CONFIG_OSD_ROTATION)
        case OSDEVT_TEST_ROTATION:
        {
            if (s_stOsdTestInfo.ucRotationIndex < OSD_ROTATION_270)    /* rotation检测   */
            {
                s_stOsdTestInfo.ucRotationIndex ++;
                //Hv_Mw_OsdSetRotateType(s_stOsdTestInfo.ucRotationIndex);
                Hv_Mw_OsdAdjustFunction(E_USERDATA_ROTATION, ACT_SET, s_stOsdTestInfo.ucRotationIndex, SET_ALL);
                Hv_Mw_OsdSceneClearAll();
                s_stOsdTestInfo.ucSceneIndex = 0;
            }
            else
            {
                bIsTestOver = HV_TRUE;
            }
            break;
        }
#endif
        default:
        {
            bIsTestOver = HV_TRUE;
            break;
        }
    }
    return bIsTestOver;
}

VOID Hv_App_OsdAutoTestNextAct(USHORT16 usValue1)
{
    OSD_LOG_DEBUG("Osd auto test next action");
    if(s_stOsdTestInfo.bTestInterrupt)
    {
        Hv_Mw_OsdStopAutoTestTimer();
        return;
    }

    if (s_stOsdTestInfo.bTestFirst)
    {
        s_stOsdTestInfo.ucSceneIndex++;
        OSD_LOG_INFO("test next scene");
        if(s_stOsdTestInfo.ucSceneIndex == ARRAY_SIZE(s_astOsdTestSceneMapTable))
        {
            s_uiDelayTimeMs = s_uiDelayTimeMsBk;
            BOOL bIsTestOver = Hv_App_OsdTestSetFunction();
            if (bIsTestOver)
            {
                Hv_Mw_OsdStopAutoTestTimer();
                Hv_Mw_OsdSceneClearAll();
                s_stOsdTestInfo.bTestInterrupt = HV_FALSE;
                s_stOsdTestInfo.bIsAutoTesting = HV_FALSE;
                OSD_LOG_INFO("Auto test over");
                return;
            }
        }
        hv_mw_EventHub_SendOsdEvent(OSD_EVENT_TEST, OSDEVT_TEST_SCENESHOW);
        Hv_Mw_OsdStartAutoTestTimer(s_uiDelayTimeMs);
        return;
    }

    Hv_App_OsdTestScene();
}

static VOID Hv_App_OsdTestSceneShow(VOID)
{
    UCHAR8 ucSceneId = s_astOsdTestSceneMapTable[s_stOsdTestInfo.ucSceneIndex].ucSceneId;
    s_stOsdTestInfo.usCurrentSceneId = ucSceneId;
    OSD_LOG_INFO("Show scene %s", SCENE_NAME(ucSceneId));
    s_stOsdTestInfo.ucCurrentItemId = s_astOsdTestSceneMapTable[s_stOsdTestInfo.ucSceneIndex].usFirstItem;
    Hv_App_OsdHideAll();
    s_astOsdTestSceneMapTable[s_stOsdTestInfo.ucSceneIndex].pfSceneEnterHandle();
    s_stOsdTestInfo.usLevel1TestedNum =0;
    s_stOsdTestInfo.usLevel2TestedNum =0;
    s_stOsdTestInfo.usLevel3TestedNum =0;
    s_stOsdTestInfo.usLevel4TestedNum =0;
    s_stOsdTestInfo.usLevel5TestedNum =0;
    s_stOsdTestInfo.ucSelectedValue = 0;

    /* 需要切界面则进入菜单下一级              */
    if (s_bMenuAdjustable && s_astOsdTestSceneMapTable[s_stOsdTestInfo.ucSceneIndex].bIsAdjustable)
    {
        s_stOsdTestInfo.ucTestNextAct = OSDACT_ENTER;
        s_stOsdTestInfo.bTestFirst = HV_FALSE;
    }
    else
    {
        if (s_uiDelayTimeMs < 3000)
        {
            s_uiDelayTimeMsBk = s_uiDelayTimeMs;
            s_uiDelayTimeMs = 3000;
        }
    }
}

VOID Hv_App_OsdTestSetDelayTime(UINT32 uiTimeMs)
{
    s_uiDelayTimeMs = uiTimeMs;
}

VOID Hv_App_OsdTestPauseContinue(VOID)
{
    if(s_stOsdTestInfo.bTestInterrupt)
    {
        s_stOsdTestInfo.bIsAutoTesting = HV_TRUE;
        s_stOsdTestInfo.bTestInterrupt = HV_FALSE;
        Hv_App_OsdAutoTestNextAct(0);
    }
    else
    {
        s_stOsdTestInfo.bTestInterrupt = HV_TRUE;
        Hv_Mw_OsdStopAutoTestTimer();
        s_stOsdTestInfo.bIsAutoTesting = HV_FALSE;
    }
}

BOOL Hv_Mw_OsdIsAutoTestRunning(VOID)
{
    return s_stOsdTestInfo.bIsAutoTesting;
}

VOID Hv_App_OsdTestSceneAllStart(VOID)
{
    Hv_Mw_OsdSetAutoCloseTimerEnable(HV_FALSE);
    Hv_App_OsdTestInfoInit();
    Hv_Mw_OsdSceneClearAll();

    s_bMenuAdjustable = HV_TRUE;
    s_stOsdTestInfo.ucTestIndex = OSDEVT_TEST_SCENESHOW;
    s_stOsdTestInfo.bTestFirst = HV_TRUE;
    hv_mw_EventHub_SendOsdEvent(OSD_EVENT_TEST, OSDEVT_TEST_SCENESHOW);
    Hv_Mw_OsdStartAutoTestTimer(s_uiDelayTimeMs);
    return;
}

VOID Hv_App_OsdTestSceneStart(VOID)
{
    Hv_Mw_OsdSetAutoCloseTimerEnable(HV_FALSE);
    Hv_App_OsdTestInfoInit();
    Hv_Mw_OsdSceneClearAll();

    s_bMenuAdjustable = HV_FALSE;
    s_stOsdTestInfo.ucTestIndex = OSDEVT_TEST_SCENESHOW;
    s_stOsdTestInfo.bTestFirst = HV_TRUE;
    hv_mw_EventHub_SendOsdEvent(OSD_EVENT_TEST, OSDEVT_TEST_SCENESHOW);
    Hv_Mw_OsdStartAutoTestTimer(s_uiDelayTimeMs);
    return;
}

VOID Hv_App_OsdTestLanguage(VOID)
{
    Hv_Mw_OsdSetAutoCloseTimerEnable(HV_FALSE);
    Hv_App_OsdTestInfoInit();

    s_stOsdTestInfo.bTestFirst = HV_TRUE;
    Hv_Mw_OsdSetLanguage(s_stOsdTestInfo.usLangIndex);
    hv_mw_EventHub_SendOsdEvent(OSD_EVENT_TEST, OSDEVT_TEST_SCENESHOW);
    Hv_Mw_OsdStartAutoTestTimer(s_uiDelayTimeMs);
    return;
}

VOID Hv_App_OsdTestPosition(VOID)
{
    OSD_LOG_INFO("Position test start");
    Hv_Mw_OsdSetAutoCloseTimerEnable(HV_FALSE);
    Hv_Mw_OsdSceneSetPositionRatio(SCENE_MAIN, HV_TRUE, 100, 0, INVALID_PARAM_USHORT16);
    Hv_Mw_OsdSceneSetPositionRatio(SCENE_MAIN, HV_FALSE, 0, 0, INVALID_PARAM_USHORT16);

    Hv_Mw_OsdSceneClearAll();
    Hv_App_OsdMainMenuEnter();
    Hv_Cal_Osd_TimeDelayMs(50);

    OsdEvent stOsdEvent;
    HV_MEMSET(&stOsdEvent, 0, sizeof(OsdEvent));
    stOsdEvent.usEventId = OSD_EVENT_KEY_PRESS;
    stOsdEvent.usValue = OSDEVT_KEY_ENTER;

    OSD_LOG_INFO("Position left moving");
    for (USHORT16 usRatio = 100; usRatio > 0; usRatio--)
    {
        Hv_App_OsdSetMenuPostion(HV_TRUE, usRatio);
        Hv_Mw_OsdDraw(&stOsdEvent);
        Hv_Cal_Osd_TimeDelayMs(50);
    }

    OSD_LOG_INFO("Position up moving");
    for (USHORT16 usRatio = 0; usRatio <100; usRatio++)
    {
        Hv_App_OsdSetMenuPostion(HV_FALSE, usRatio);
        Hv_Mw_OsdDraw(&stOsdEvent);
        Hv_Cal_Osd_TimeDelayMs(50);
    }

    OSD_LOG_INFO("Position right moving");
    for (USHORT16 usRatio = 0; usRatio < 100; usRatio++)
    {
        Hv_App_OsdSetMenuPostion(HV_TRUE, usRatio);
        Hv_Mw_OsdDraw(&stOsdEvent);
        Hv_Cal_Osd_TimeDelayMs(50);
    }

    OSD_LOG_INFO("Position down moving");
    for (USHORT16 usRatio = 100; usRatio > 0; usRatio--)
    {
        Hv_App_OsdSetMenuPostion(HV_FALSE, usRatio);
        Hv_Mw_OsdDraw(&stOsdEvent);
        Hv_Cal_Osd_TimeDelayMs(50);
    }

    Hv_Mw_OsdSceneClearAll();
    Hv_Mw_OsdDraw(&stOsdEvent);
    Hv_Mw_OsdSetAutoCloseTimerEnable(HV_TRUE);
    Hv_Mw_SetFromOsdUserdata(E_USERDATA_MENUX);
    Hv_Mw_SetFromOsdUserdata(E_USERDATA_MENUY);
    OSD_LOG_INFO("Position test over");
}

VOID Hv_App_OsdTestRotation(VOID)
{
#if (HV_CONFIG_ON == HV_PROJECT_CONFIG_OSD_ROTATION)
    OSD_LOG_INFO("Rotation test start");

    Hv_Mw_OsdSetAutoCloseTimerEnable(HV_FALSE);
    Hv_App_OsdTestInfoInit();
    s_stOsdTestInfo.ucTestIndex = OSDEVT_TEST_ROTATION;
    s_stOsdTestInfo.ucRotationIndex = 1;

    Hv_Mw_OsdAdjustFunction(E_USERDATA_ROTATION, ACT_SET, s_stOsdTestInfo.ucRotationIndex, SET_ALL);
    //Hv_Mw_OsdSetRotateType(s_stOsdTestInfo.ucRotationIndex);

    Hv_Mw_OsdSceneClearAll();
    hv_mw_EventHub_SendOsdEvent(OSD_EVENT_TEST, OSDEVT_TEST_SCENESHOW);
    Hv_Mw_OsdStartAutoTestTimer(s_uiDelayTimeMs);
    return;
#endif
}

VOID Hv_App_OsdTestAlpha(VOID)
{
    Hv_Mw_OsdSetAutoCloseTimerEnable(HV_FALSE);

    USHORT16 usEventId = OSD_EVENT_KEY_PRESS;
    hv_mw_EventHub_SendOsdEvent(usEventId, OSDEVT_KEY_ENTER);
    Hv_Cal_Osd_TimeDelayMs(50);

    OsdEvent stOsdEvent;
    HV_MEMSET(&stOsdEvent, 0, sizeof(OsdEvent));
    stOsdEvent.usEventId = usEventId;
    stOsdEvent.usValue = OSDEVT_KEY_ENTER;
    Hv_App_OsdMainMenuEnter();

    for (USHORT16 usTrans = USERDATA_MENUTRANSPARENCY_MIN; usTrans <= USERDATA_MENUTRANSPARENCY_MAX; usTrans++)
    {
        Hv_Mw_OsdAdjustFunction(E_USERDATA_MENUTRANSPARENCY, ACT_SET, usTrans, SET_ALL);
        Hv_Mw_OsdDraw(&stOsdEvent);
        Hv_Cal_Osd_TimeDelayMs(500);
    }

    Hv_Mw_OsdSceneClearAll();
    Hv_Mw_OsdDraw(&stOsdEvent);

    OSD_LOG_INFO("Alpha test over");
    Hv_Mw_OsdSetAutoCloseTimerEnable(HV_TRUE);
    Hv_App_OsdMainMenuExit();
    Hv_Mw_OsdDraw(&stOsdEvent);
}

VOID Hv_App_OsdTestCrosshair(VOID)
{
#if (HV_CONFIG_ON == TEST_SCENE_CROSSHAIR)
    USHORT16 usFullWidth = 0;
    USHORT16 usFullHeight = 0;
    Hv_Mw_OsdGetDisplaySize(&usFullWidth, &usFullHeight);

    HV_W32_FIELD(DISP_TOP_SUB_LDG_D8, reg_cursor_en, 1);
    HV_W32_FIELD(DISP_TOP_SUB_LDG_D8, reg_cursor_hwidth, 2);
    HV_W32_FIELD(DISP_TOP_SUB_LDG_D8, reg_cursor_vwidth, 2);
    HV_W32_FIELD(DISP_TOP_SUB_LDG_E0, reg_cursor_hcnt, usFullWidth/2 - 1);
    HV_W32_FIELD(DISP_TOP_SUB_LDG_E0, reg_cursor_vcnt, usFullHeight/2 - 1);

    OsdEvent stOsdEvent;
    HV_MEMSET(&stOsdEvent, 0, sizeof(OsdEvent));
    stOsdEvent.usEventId = OSD_EVENT_KEY_PRESS;
    stOsdEvent.usValue = OSDEVT_KEY_ENTER;

    for (UCHAR8 ucIndex = 0; ucIndex <= USERDATA_CROSSHAIR_MAX; ucIndex++)
    {
        Hv_Mw_OsdAdjustFunction(E_USERDATA_CROSSHAIR, ACT_SET, ucIndex, SET_ALL);
        Hv_App_OsdHideAll();
        Hv_App_OsdCrosshairEnter();
        Hv_Mw_OsdDraw(&stOsdEvent);
        Hv_Cal_Osd_TimeDelayMs(3000);
    }

    Hv_Mw_OsdSceneHide(SCENE_CROSSHAIR);
    Hv_Mw_OsdSceneClear(SCENE_CROSSHAIR);

    HV_W32_FIELD(DISP_TOP_SUB_LDG_D8, reg_cursor_en, 0);
    OSD_LOG_INFO("Crosshair test over");
#endif
}

VOID Hv_App_OsdTestTextSetWinWidth(UINT32 uiWinWidth)
{
    s_stOsdTestText.usWinWidth = uiWinWidth;
}

VOID Hv_App_OsdTestTextSetWinHeight(UINT32 uiWinHeight)
{
    s_stOsdTestText.usWinHeight = uiWinHeight;
}

VOID Hv_App_OsdTestTextSetColumns(UCHAR8 ucColumns)
{
    s_stOsdTestText.ucColumns = ucColumns;
}

VOID Hv_App_OsdTestTextSetColor(UCHAR8 ucColorSel)
{
    s_stOsdTestText.ucColorSel = ucColorSel;
}

VOID Hv_App_OsdTestTextSetSartLang(UCHAR8 ucLangStart)
{
    if (OSD_LANGUAGE_COUNT <= 4)
    {
        OSD_LOG_INFO("All Language can show together, no need set");
        return;
    }

    if (ucLangStart < OSD_LANGUAGE_COUNT)
    {
        s_stOsdTestText.ucLangStart = ucLangStart;
    }
}

static OsdComponentNode* Hv_App_OsdTest_NewFont(USHORT16 usX, USHORT16 usY, UCHAR8 ucBlockID, USHORT16 usStringId)
{
    OsdComponentNode *pstNode = NULL;
    OsdText *pstText = NULL;
    UCHAR8 ucIndex = 0;

    pstNode = HV_MALLOC(sizeof(*pstNode));
    HV_MEMSET(pstNode, 0, sizeof(*pstNode));

    pstNode->stCp.enType = OSD_CP_TYPE_TEXT;
    pstText = HV_MALLOC(sizeof(*pstText));
    pstNode->pvCpData = pstText;
    HV_MEMSET(pstText, 0, sizeof(*pstText));

    pstText->usX = usX;
    pstText->usY = usY;
    pstText->usAlignType = OSD_STRING_ALIGN_LEFT;
    pstText->ucWindowIndex = 0;
    pstText->ucColorIndex = 1;
    pstText->ucBlockID = ucBlockID;
    pstText->usIsLongText = 0;
    pstText->uiDynamicFlag = 0;
    pstText->uiDynamicIndex = 0;
    pstText->usReserved = 0;
    pstText->usStringId = usStringId;
    pstText->usWidth = 300;

    return pstNode;
}

static VOID Hv_App_OsdTest_Init_WindowProp(OsdWindowPhyId enWinIndex, OsdWindowProp *pstProp, BOOL bXAligned)
{
    OSD_LOG_DEBUG("Init_WindowProp");
    Hv_Drv_OsdPalette_ChangeColor(enWinIndex, 1, arColors[s_stOsdTestText.ucColorSel]);

    HV_MEMSET(pstProp, 0, sizeof(*pstProp));
    pstProp->ucWindowID = enWinIndex;
    pstProp->usX = s_usWinX[enWinIndex];
    pstProp->usY = 200;
    pstProp->usWidth = s_stOsdTestText.usWinWidth;
    pstProp->usHeight = s_stOsdTestText.usWinHeight;
    if (bXAligned)
    {
        pstProp->usX = ALIGN(pstProp->usX, 16);
        pstProp->usWidth = ALIGN(pstProp->usWidth, 16);
    }
    pstProp->ucBorderEnable = 0;
    pstProp->usBorderColor = 0;
    pstProp->ucBgEnable = 1;
    pstProp->usBgColor = 0x0;
}

static VOID Hv_App_OsdTest_FreeFont(OsdComponentNode *pstNode)
{
    HV_FREE(pstNode->pvCpData);
    HV_FREE(pstNode);
}

static VOID Hv_App_OsdTest_DrawFont(OsdWindowProp *pstProp, UCHAR8 ucCols)
{
    OsdWindow stWindow;
    OsdNodeHead stHead;
    OsdComponentNode **ppComponent = &stHead.pstNode;
    OsdComponentNode *pstCur = NULL, *pstNext = NULL;
    USHORT16 usRowIndex = 0;
    USHORT16 usColIndex = 0;
    UCHAR8 ucTemp = 0;
    USHORT16 usCurY = 20;
    UCHAR8 ucLen = 0;
    USHORT16 usX = 20;
    UCHAR8 ucRows = pstProp->usHeight/36 - 2;
    UCHAR8 ucTextRows = 0;
    USHORT16 usResourceSize;
    UCHAR8 ucBitType;

    HV_MEMSET(&stWindow, 0, sizeof(stWindow));
    HV_MEMSET(&stHead, 0, sizeof(stHead));

    /* 第一行显示语言 */
    if (s_ucCurLangIndex == OSD_LANGUAGE_EN)
    {
        *ppComponent = Hv_App_OsdTest_NewFont(usX, 20, 1, EN_OSD_LANGUAGE_ENLANG);
    }
    else if (s_ucCurLangIndex == OSD_LANGUAGE_CN)
    {
        *ppComponent = Hv_App_OsdTest_NewFont(usX, 20, 1, EN_OSD_LANGUAGE_CNLANG);
    }
    ppComponent = &((*ppComponent)->pstNext);
    usCurY += 36;

    for (usRowIndex = 0; usRowIndex < ucRows; usRowIndex++)
    {
        usX = 20;
        if (s_stOsdTestText.usCurTextIndex >= usTestStringMax)
        {
            break;
        }
        OsdTestStringProp stTestStringProp = g_astTestStringPropArray[s_stOsdTestText.usCurTextIndex];
        OSD_LOG_DEBUG("CurTextIndex-%d, stringId-%d",s_stOsdTestText.usCurTextIndex, stTestStringProp.usStringId);
        if (stTestStringProp.usStringId != 0xFFFF)   /* 非空白行则显示  */
        {
            *ppComponent = Hv_App_OsdTest_NewFont(usX, usCurY, stTestStringProp.ucBlockID, stTestStringProp.usStringId);
            OSD_LOG_DEBUG("NewFont 3");
            ppComponent = &((*ppComponent)->pstNext);
            ucTextRows ++;
        }
        s_stOsdTestText.usCurTextIndex ++;
        usCurY += 36;
    }

    stWindow.stFontShowListHead = stHead;
    stWindow.usFontAreaWidth = pstProp->usWidth;
    stWindow.ucPhyId = pstProp->ucWindowID;
    OSD_LOG_DEBUG("DrawMenuFontList");

    Hv_Drv_OsdFont_DrawMenuFontList(&stWindow);

    pstCur = stHead.pstNode;
    for (usRowIndex = 0; usRowIndex < ucTextRows; usRowIndex++)
    {
        pstNext = pstCur->pstNext;
        Hv_App_OsdTest_FreeFont(pstCur);
        pstCur = pstNext;
    }
    OSD_LOG_INFO("Draw Font Over");
}

VOID Hv_App_OsdTestTextDraw(VOID)
{
    UCHAR8 ucLangShowNum = s_stOsdTestText.ucLangStart + 3;
    USHORT16 usCurPageTextIndex = s_stOsdTestText.usCurTextIndex;

    OsdWindowProp stWindowProp;
    OsdWindowPhyId enWinIndex = PHY_WIN_3;

    Hv_Drv_OsdFrame_DrawPre();
    s_ucCurLangIndex = OSD_LANGUAGE_EN;
    Hv_Drv_OsdResource_SetLanguageOnly(OSD_LANGUAGE_EN);
    Hv_App_OsdTest_Init_WindowProp(PHY_WIN_3,&stWindowProp, 0);
    Hv_Drv_OsdWindow_DrawWindow(&stWindowProp);
    Hv_App_OsdTest_DrawFont(&stWindowProp, s_stOsdTestText.ucColumns);

    if (OSD_LANGUAGE_COUNT - s_stOsdTestText.ucLangStart <= 3)
    {
        ucLangShowNum = OSD_LANGUAGE_COUNT;
    }
    OSD_LOG_DEBUG("ucLangShowNum - %d", ucLangShowNum);

    for (s_ucCurLangIndex = s_stOsdTestText.ucLangStart; s_ucCurLangIndex < ucLangShowNum; s_ucCurLangIndex++)
    {
        if (s_ucCurLangIndex != OSD_LANGUAGE_EN)
        {
            enWinIndex --;
            OSD_LOG_INFO("Current Language-%d", s_ucCurLangIndex);
            Hv_Drv_OsdResource_SetLanguageOnly(s_ucCurLangIndex);
            s_stOsdTestText.usCurTextIndex = usCurPageTextIndex;
            Hv_App_OsdTest_Init_WindowProp(enWinIndex,&stWindowProp, 0);
            Hv_Drv_OsdWindow_DrawWindow(&stWindowProp);
            Hv_App_OsdTest_DrawFont(&stWindowProp, s_stOsdTestText.ucColumns);
        }
    }

    Hv_Drv_OsdFrame_DrawPost();
    Hv_Drv_OsdFrame_SetSync();
    OSD_LOG_INFO("CurrentTextIndex-%d", s_stOsdTestText.usCurTextIndex);
}

VOID Hv_App_OsdTestText(VOID)
{
    s_stOsdTestText.usCurTextIndex = 0;
    s_stOsdTestText.ucCurPage = 1;
    OSD_LOG_INFO("Text test start.Current page-%d", s_stOsdTestText.ucCurPage);
    Hv_App_OsdTestTextDraw();
}

VOID Hv_App_OsdTestTextNextPage(VOID)
{
    if (s_stOsdTestText.usCurTextIndex >= usTestStringMax)
    {
        OSD_LOG_INFO("Text test has over!");
        if (s_ucCurLangIndex == OSD_LANGUAGE_COUNT)
        {
            return;
        }
        else
        {
            s_stOsdTestText.ucLangStart = s_ucCurLangIndex;
            s_stOsdTestText.usCurTextIndex  = 0;
            s_stOsdTestText.ucCurPage = 0;
        }
    }

    OsdWindowProp stWindowProp;
    s_stOsdTestText.ucCurPage ++;
    OSD_LOG_INFO("Current page-%d", s_stOsdTestText.ucCurPage);
    Hv_App_OsdTestTextDraw();
}

VOID Hv_App_OsdTestEnter(USHORT16 usValue1)
{
    switch (usValue1)
    {
        case OSDEVT_TEST_SCENESHOW:
        {
            Hv_App_OsdTestSceneShow();
            break;
        }
        case OSDEVT_TEST_POSITION:
        {
            s_stOsdTestInfo.bIsAutoTesting = HV_FALSE;
            Hv_App_OsdTestPosition();
            break;
        }
        case OSDEVT_TEST_ROTATION:
        {
            Hv_App_OsdTestRotation();
            break;
        }
        case OSDEVT_TEST_ALPHA:
        {
            s_stOsdTestInfo.bIsAutoTesting = HV_FALSE;
            Hv_App_OsdTestAlpha();
            break;
        }
        case OSDEVT_TEST_CROSSHARE:
        {
            Hv_App_OsdTestCrosshair();
            break;
        }
        case OSDEVT_TEST_TEXT:
        {
            Hv_App_OsdTestText();
            break;
        }
        default:
        {
            break;
        }
    }
}
#endif
