bb_cust_hw.cpp
上传用户:gelin96
上传日期:2017-01-08
资源大小:20993k
文件大小:29k
源码类别:

MTK

开发平台:

C++ Builder

  1. /*****************************************************************************
  2. *  Copyright Statement:
  3. *  --------------------
  4. *  This software is protected by Copyright and the information contained
  5. *  herein is confidential. The software may not be copied and the information
  6. *  contained herein may not be used or disclosed except with the written
  7. *  permission of MediaTek Inc. (C) 2005
  8. *
  9. *  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
  10. *  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
  11. *  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
  12. *  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
  13. *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
  14. *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
  15. *  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
  16. *  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
  17. *  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
  18. *  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
  19. *  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
  20. *  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
  21. *
  22. *  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
  23. *  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
  24. *  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
  25. *  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
  26. *  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
  27. *
  28. *  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
  29. *  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
  30. *  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
  31. *  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
  32. *  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
  33. *
  34. *****************************************************************************/
  35. /*****************************************************************************
  36.  *
  37.  * Filename:
  38.  * ---------
  39.  *   bb_cust_hw.cpp
  40.  *
  41.  * Project:
  42.  * --------
  43.  *   Maui META APP
  44.  *
  45.  * Description:
  46.  * ------------
  47.  *  Baseband custom hardware level setting source
  48.  *
  49.  * Author:
  50.  * -------
  51.  *  Andy Ueng (mtk00490)
  52.  *
  53.  *============================================================================
  54.  *             HISTORY
  55.  * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  56.  *------------------------------------------------------------------------------
  57.  * $Revision$
  58.  * $Modtime$
  59.  * $Log$
  60.  * 
  61.  *------------------------------------------------------------------------------
  62.  * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  63.  *============================================================================
  64.  ****************************************************************************/
  65. #include <IniFiles.hpp>
  66. #pragma hdrstop
  67. #ifndef  _MAN_ACTIVE_H_
  68. #include "man_active.h"
  69. #endif
  70. #ifndef  _MAN_FDM_H_
  71. #include "man_fdm.h"
  72. #endif
  73. #ifndef  _BB_CUST_HW_H_
  74. #include "bb_cust_hw.h"
  75. #endif
  76. //===========================================================================
  77. static const char  Battery_Level_Name[][32] =
  78. {
  79.    "Shutdown voltage",
  80.    "No MO call voltage",
  81.    "Low battery warning voltage",
  82.    "Level 1 votage",
  83.    "Level 2 votage",
  84.    "Level 3 votage"
  85. };
  86. static CBBCUSTHW*  bb_custhw_ptr;
  87. static bool g_bIsRunning;
  88. //===========================================================================
  89. static  void  CNF_ReadFromNVRAM( void )
  90. {
  91.     bb_custhw_ptr->CNF_ReadFromNVRAM( );
  92. }
  93. //---------------------------------------------------------------------------
  94. static  void  CNF_WriteToNVRAM(void)
  95. {
  96.     bb_custhw_ptr->CNF_WriteToNVRAM();
  97. }
  98. //---------------------------------------------------------------------------
  99. static void  REQ_TimeOut( void )
  100. {   bb_custhw_ptr->REQ_TimeOut();
  101. }
  102. //------------------------------------------------------------------------
  103. static void  REQ_Finish( void )
  104. {   bb_custhw_ptr->REQ_Finish();
  105. }
  106. //===========================================================================
  107. CBBCUSTHW::CBBCUSTHW( void )
  108. {
  109.    g_bIsRunning = false;
  110.    ConfirmCallback = 0;
  111.    
  112. }
  113. //---------------------------------------------------------------------------
  114. CBBCUSTHW::~CBBCUSTHW( )
  115. {
  116.    g_bIsRunning = false;
  117.    ConfirmCallback = 0;
  118.    
  119. }
  120. //---------------------------------------------------------------------------
  121. void  CBBCUSTHW::REQ_Finish( void )
  122. {
  123.    if(!g_bIsRunning)  return;
  124.    Confirm( STATE_CUST_HW_OK );
  125.    g_bIsRunning = false;
  126. }
  127. //---------------------------------------------------------------------------
  128. void  CBBCUSTHW::REQ_Stop( void )
  129. {
  130.    if(!g_bIsRunning)  return;
  131.    META_Cancel_r( m_META_HANDLE_Obj.Get_MainHandle(), m_sBBID_CUSTHW );
  132.    Confirm( STATE_CUST_HW_STOP );
  133.    g_bIsRunning = false;
  134. }
  135. //---------------------------------------------------------------------------
  136. void  CBBCUSTHW::REQ_TimeOut( void )
  137. {
  138.    if(!g_bIsRunning)  return;
  139.    META_Cancel_r( m_META_HANDLE_Obj.Get_MainHandle(), m_sBBID_CUSTHW );
  140.    Confirm( STATE_CUST_HW_TIMEOUT );
  141.    g_bIsRunning = false;
  142. }
  143. //---------------------------------------------------------------------------
  144. void  CBBCUSTHW::Confirm( int confirm_state )
  145. {
  146.    if(!g_bIsRunning)  return;
  147.    if(ConfirmCallback==0)  return;
  148.    m_iConfirmState = confirm_state;
  149.    ActiveMan->SetActiveFunction( ConfirmCallback );
  150. }
  151. //===========================================================================
  152. bool  CBBCUSTHW::Decompose_CustHwLevel( void )
  153. {
  154.     int  i, j;
  155.     AnsiString as_str;
  156.     META_RESULT MetaResult;
  157.     // PWM1
  158.     for( i=0; i<PWM_MAX_LEVEL; i++ )
  159.     {
  160.         for( j=0; j<2; j++ )
  161.         {
  162.             as_str = "";
  163.             as_str = as_str+ "PWM1" + "[" + IntToStr(i) + "]" + "[" + IntToStr(j) + "]";
  164.             MetaResult = META_NVRAM_GetRecFieldValue( "NVRAM_EF_CUST_HW_LEVEL_TBL_LID",
  165.                                                       as_str.c_str(),
  166.                                                       m_pcCustHwBuf,
  167.                                                       m_iCustHwBufSize,
  168.                                                       &m_sCustomHwLevel.PWM1[i][j],
  169.                                                       sizeof(m_sCustomHwLevel.PWM1[i][j]) );
  170.             if(MetaResult!=META_SUCCESS)  return(false);
  171.         }
  172.     }
  173.     // PWM2
  174.     for( i=0; i<PWM_MAX_LEVEL; i++ )
  175.     {
  176.         for( j=0; j<2; j++ )
  177.         {
  178.             as_str = "";
  179.             as_str = as_str + "PWM2" + "[" + IntToStr(i) + "]" + "[" + IntToStr(j) + "]";
  180.             MetaResult = META_NVRAM_GetRecFieldValue( "NVRAM_EF_CUST_HW_LEVEL_TBL_LID",
  181.                                                       as_str.c_str(),
  182.                                                       m_pcCustHwBuf,
  183.                                                       m_iCustHwBufSize,
  184.                                                       &m_sCustomHwLevel.PWM2[i][j],
  185.                                                       sizeof(m_sCustomHwLevel.PWM2[i][j]) );
  186.             if(MetaResult!=META_SUCCESS)  return(false);
  187.         }
  188.     }
  189.     // PWM3
  190.     for( i=0; i<PWM_MAX_LEVEL; i++ )
  191.     {
  192.         for( j=0; j<2; j++ )
  193.         {
  194.             as_str = "";
  195.             as_str = as_str + "PWM3" + "[" + IntToStr(i) + "]" + "[" + IntToStr(j) + "]";
  196.             MetaResult = META_NVRAM_GetRecFieldValue( "NVRAM_EF_CUST_HW_LEVEL_TBL_LID",
  197.                                                       as_str.c_str(),
  198.                                                       m_pcCustHwBuf,
  199.                                                       m_iCustHwBufSize,
  200.                                                       &m_sCustomHwLevel.PWM3[i][j],
  201.                                                       sizeof(m_sCustomHwLevel.PWM3[i][j]) );
  202.             if(MetaResult!=META_SUCCESS)  return(false);
  203.         }
  204.     }
  205.     // Main LCD contrast
  206.     for( i=0; i<LCD_CONTRAST_MAX_LEVEL; i++ )
  207.     {
  208.         as_str = "";
  209.         as_str = as_str + "MainLCD_Contrast" + "[" + IntToStr(i) + "]";
  210.         MetaResult = META_NVRAM_GetRecFieldValue( "NVRAM_EF_CUST_HW_LEVEL_TBL_LID",
  211.                                                       as_str.c_str(),
  212.                                                       m_pcCustHwBuf,
  213.                                                       m_iCustHwBufSize,
  214.                                                       &m_sCustomHwLevel.MainLCD_Contrast[i],
  215.                                                       sizeof(m_sCustomHwLevel.MainLCD_Contrast[i]) );
  216.         if(MetaResult!=META_SUCCESS)  return(false);
  217.     }
  218.     // Main LCD bias
  219.     for( i=0; i<LCD_PARAM_MAX_LEVEL; i++ )
  220.     {
  221.         as_str = "";
  222.         as_str = as_str + "MainLCD_Bias" + "[" + IntToStr(i) + "]";
  223.         MetaResult = META_NVRAM_GetRecFieldValue( "NVRAM_EF_CUST_HW_LEVEL_TBL_LID",
  224.                                                       as_str.c_str(),
  225.                                                       m_pcCustHwBuf,
  226.                                                       m_iCustHwBufSize,
  227.                                                       &m_sCustomHwLevel.MainLCD_Bias[i],
  228.                                                       sizeof(m_sCustomHwLevel.MainLCD_Bias[i]) );
  229.         if(MetaResult!=META_SUCCESS)  return(false);
  230.     }
  231.     // Main LCD linerate
  232.     for( i=0; i<LCD_PARAM_MAX_LEVEL; i++ )
  233.     {
  234.         as_str = "";
  235.         as_str = as_str + "MainLCD_Linerate" + "[" + IntToStr(i) + "]";
  236.         MetaResult = META_NVRAM_GetRecFieldValue( "NVRAM_EF_CUST_HW_LEVEL_TBL_LID",
  237.                                                       as_str.c_str(),
  238.                                                       m_pcCustHwBuf,
  239.                                                       m_iCustHwBufSize,
  240.                                                       &m_sCustomHwLevel.MainLCD_Linerate[i],
  241.                                                       sizeof(m_sCustomHwLevel.MainLCD_Linerate[i]) );
  242.         if(MetaResult!=META_SUCCESS)  return(false);
  243.     }
  244.     // Main LCD temperature
  245.     for( i=0; i<LCD_PARAM_MAX_LEVEL; i++ )
  246.     {
  247.         as_str = "";
  248.         as_str = as_str + "MainLCD_Temp" + "[" + IntToStr(i) + "]";
  249.         MetaResult = META_NVRAM_GetRecFieldValue( "NVRAM_EF_CUST_HW_LEVEL_TBL_LID",
  250.                                                       as_str.c_str(),
  251.                                                       m_pcCustHwBuf,
  252.                                                       m_iCustHwBufSize,
  253.                                                       &m_sCustomHwLevel.MainLCD_Temp[i],
  254.                                                       sizeof(m_sCustomHwLevel.MainLCD_Temp[i]) );
  255.         if(MetaResult!=META_SUCCESS)  return(false);
  256.     }
  257.     // Sub LCD contrast
  258.     for( i=0; i<LCD_CONTRAST_MAX_LEVEL; i++ )
  259.     {
  260.         as_str = "";
  261.         as_str = as_str + "SubLCD_Contrast" + "[" + IntToStr(i) + "]";
  262.         MetaResult = META_NVRAM_GetRecFieldValue( "NVRAM_EF_CUST_HW_LEVEL_TBL_LID",
  263.                                                       as_str.c_str(),
  264.                                                       m_pcCustHwBuf,
  265.                                                       m_iCustHwBufSize,
  266.                                                       &m_sCustomHwLevel.SubLCD_Contrast[i],
  267.                                                       sizeof(m_sCustomHwLevel.SubLCD_Contrast[i]) );
  268.         if(MetaResult!=META_SUCCESS)  return(false);
  269.     }
  270.     // Sub LCD bias
  271.     for( i=0; i<LCD_PARAM_MAX_LEVEL; i++ )
  272.     {
  273.         as_str = "";
  274.         as_str = as_str + "SubLCD_Bias" + "[" + IntToStr(i) + "]";
  275.         MetaResult = META_NVRAM_GetRecFieldValue( "NVRAM_EF_CUST_HW_LEVEL_TBL_LID",
  276.                                                       as_str.c_str(),
  277.                                                       m_pcCustHwBuf,
  278.                                                       m_iCustHwBufSize,
  279.                                                       &m_sCustomHwLevel.SubLCD_Bias[i],
  280.                                                       sizeof(m_sCustomHwLevel.SubLCD_Bias[i]) );
  281.         if(MetaResult!=META_SUCCESS)  return(false);
  282.     }
  283.     // Sub LCD linerate
  284.     for( i=0; i<LCD_PARAM_MAX_LEVEL; i++ )
  285.     {
  286.         as_str = "";
  287.         as_str = as_str + "SubLCD_Linerate" + "[" + IntToStr(i) + "]";
  288.         MetaResult = META_NVRAM_GetRecFieldValue( "NVRAM_EF_CUST_HW_LEVEL_TBL_LID",
  289.                                                       as_str.c_str(),
  290.                                                       m_pcCustHwBuf,
  291.                                                       m_iCustHwBufSize,
  292.                                                       &m_sCustomHwLevel.SubLCD_Linerate[i],
  293.                                                       sizeof(m_sCustomHwLevel.SubLCD_Linerate[i]) );
  294.         if(MetaResult!=META_SUCCESS)  return(false);
  295.     }
  296.     // Sub LCD temperature
  297.     for( i=0; i<LCD_PARAM_MAX_LEVEL; i++ )
  298.     {
  299.         as_str = "";
  300.         as_str = as_str + "SubLCD_Temp" + "[" + IntToStr(i) + "]";
  301.         MetaResult = META_NVRAM_GetRecFieldValue( "NVRAM_EF_CUST_HW_LEVEL_TBL_LID",
  302.                                                       as_str.c_str(),
  303.                                                       m_pcCustHwBuf,
  304.                                                       m_iCustHwBufSize,
  305.                                                       &m_sCustomHwLevel.SubLCD_Temp[i],
  306.                                                       sizeof(m_sCustomHwLevel.SubLCD_Temp[i]) );
  307.         if(MetaResult!=META_SUCCESS)  return(false);
  308.     }
  309.     // Battery level
  310.     for( i=0; i<BATTERY_MAX_LEVEL; i++ )
  311.     {
  312.         as_str = "";
  313.         as_str = as_str + "BatteryLevel" + "[" + IntToStr(i) + "]";
  314.         MetaResult = META_NVRAM_GetRecFieldValue( "NVRAM_EF_CUST_HW_LEVEL_TBL_LID",
  315.                                                       as_str.c_str(),
  316.                                                       m_pcCustHwBuf,
  317.                                                       m_iCustHwBufSize,
  318.                                                       &m_sCustomHwLevel.BatteryLevel[i],
  319.                                                       sizeof(m_sCustomHwLevel.BatteryLevel[i]) );
  320.         if(MetaResult!=META_SUCCESS)  return(false);
  321.     }
  322.     return(true);
  323. }
  324. //---------------------------------------------------------------------------
  325. bool  CBBCUSTHW::Compose_CustHwLevel( void )
  326. {
  327.     int  i, j;
  328.     AnsiString as_str;
  329.     META_RESULT MetaResult;
  330.     // PWM1
  331.     for( i=0; i<PWM_MAX_LEVEL; i++ )
  332.     {
  333.         for( j=0; j<2; j++ )
  334.         {
  335.             as_str = "";
  336.             as_str = as_str+ "PWM1" + "[" + IntToStr(i) + "]" + "[" + IntToStr(j) + "]";
  337.             MetaResult = META_NVRAM_SetRecFieldValue( "NVRAM_EF_CUST_HW_LEVEL_TBL_LID",
  338.                                                       as_str.c_str(),
  339.                                                       m_pcCustHwBuf,
  340.                                                       m_iCustHwBufSize,
  341.                                                       &m_sCustomHwLevel.PWM1[i][j],
  342.                                                       sizeof(m_sCustomHwLevel.PWM1[i][j]) );
  343.             if(MetaResult!=META_SUCCESS)  return(false);
  344.         }
  345.     }
  346.     // PWM2
  347.     for( i=0; i<PWM_MAX_LEVEL; i++ )
  348.     {
  349.         for( j=0; j<2; j++ )
  350.         {
  351.             as_str = "";
  352.             as_str = as_str + "PWM2" + "[" + IntToStr(i) + "]" + "[" + IntToStr(j) + "]";
  353.             MetaResult = META_NVRAM_SetRecFieldValue( "NVRAM_EF_CUST_HW_LEVEL_TBL_LID",
  354.                                                       as_str.c_str(),
  355.                                                       m_pcCustHwBuf,
  356.                                                       m_iCustHwBufSize,
  357.                                                       &m_sCustomHwLevel.PWM2[i][j],
  358.                                                       sizeof(m_sCustomHwLevel.PWM2[i][j]) );
  359.             if(MetaResult!=META_SUCCESS)  return(false);
  360.         }
  361.     }
  362.     // PWM3
  363.     for( i=0; i<PWM_MAX_LEVEL; i++ )
  364.     {
  365.         for( j=0; j<2; j++ )
  366.         {
  367.             as_str = "";
  368.             as_str = as_str + "PWM3" + "[" + IntToStr(i) + "]" + "[" + IntToStr(j) + "]";
  369.             MetaResult = META_NVRAM_SetRecFieldValue( "NVRAM_EF_CUST_HW_LEVEL_TBL_LID",
  370.                                                       as_str.c_str(),
  371.                                                       m_pcCustHwBuf,
  372.                                                       m_iCustHwBufSize,
  373.                                                       &m_sCustomHwLevel.PWM3[i][j],
  374.                                                       sizeof(m_sCustomHwLevel.PWM3[i][j]) );
  375.             if(MetaResult!=META_SUCCESS)  return(false);
  376.         }
  377.     }
  378.     // Main LCD contrast
  379.     for( i=0; i<LCD_CONTRAST_MAX_LEVEL; i++ )
  380.     {
  381.         as_str = "";
  382.         as_str = as_str + "MainLCD_Contrast" + "[" + IntToStr(i) + "]";
  383.         MetaResult = META_NVRAM_SetRecFieldValue( "NVRAM_EF_CUST_HW_LEVEL_TBL_LID",
  384.                                                       as_str.c_str(),
  385.                                                       m_pcCustHwBuf,
  386.                                                       m_iCustHwBufSize,
  387.                                                       &m_sCustomHwLevel.MainLCD_Contrast[i],
  388.                                                       sizeof(m_sCustomHwLevel.MainLCD_Contrast[i]) );
  389.         if(MetaResult!=META_SUCCESS)  return(false);
  390.     }
  391.     // Main LCD bias
  392.     for( i=0; i<LCD_PARAM_MAX_LEVEL; i++ )
  393.     {
  394.         as_str = "";
  395.         as_str = as_str + "MainLCD_Bias" + "[" + IntToStr(i) + "]";
  396.         MetaResult = META_NVRAM_SetRecFieldValue( "NVRAM_EF_CUST_HW_LEVEL_TBL_LID",
  397.                                                       as_str.c_str(),
  398.                                                       m_pcCustHwBuf,
  399.                                                       m_iCustHwBufSize,
  400.                                                       &m_sCustomHwLevel.MainLCD_Bias[i],
  401.                                                       sizeof(m_sCustomHwLevel.MainLCD_Bias[i]) );
  402.         if(MetaResult!=META_SUCCESS)  return(false);
  403.     }
  404.     // Main LCD linerate
  405.     for( i=0; i<LCD_PARAM_MAX_LEVEL; i++ )
  406.     {
  407.         as_str = "";
  408.         as_str = as_str + "MainLCD_Linerate" + "[" + IntToStr(i) + "]";
  409.         MetaResult = META_NVRAM_SetRecFieldValue( "NVRAM_EF_CUST_HW_LEVEL_TBL_LID",
  410.                                                       as_str.c_str(),
  411.                                                       m_pcCustHwBuf,
  412.                                                       m_iCustHwBufSize,
  413.                                                       &m_sCustomHwLevel.MainLCD_Linerate[i],
  414.                                                       sizeof(m_sCustomHwLevel.MainLCD_Linerate[i]) );
  415.         if(MetaResult!=META_SUCCESS)  return(false);
  416.     }
  417.     // Main LCD temperature
  418.     for( i=0; i<LCD_PARAM_MAX_LEVEL; i++ )
  419.     {
  420.         as_str = "";
  421.         as_str = as_str + "MainLCD_Temp" + "[" + IntToStr(i) + "]";
  422.         MetaResult = META_NVRAM_SetRecFieldValue( "NVRAM_EF_CUST_HW_LEVEL_TBL_LID",
  423.                                                       as_str.c_str(),
  424.                                                       m_pcCustHwBuf,
  425.                                                       m_iCustHwBufSize,
  426.                                                       &m_sCustomHwLevel.MainLCD_Temp[i],
  427.                                                       sizeof(m_sCustomHwLevel.MainLCD_Temp[i]) );
  428.         if(MetaResult!=META_SUCCESS)  return(false);
  429.     }
  430.     // Sub LCD contrast
  431.     for( i=0; i<LCD_CONTRAST_MAX_LEVEL; i++ )
  432.     {
  433.         as_str = "";
  434.         as_str = as_str + "SubLCD_Contrast" + "[" + IntToStr(i) + "]";
  435.         MetaResult = META_NVRAM_SetRecFieldValue( "NVRAM_EF_CUST_HW_LEVEL_TBL_LID",
  436.                                                       as_str.c_str(),
  437.                                                       m_pcCustHwBuf,
  438.                                                       m_iCustHwBufSize,
  439.                                                       &m_sCustomHwLevel.SubLCD_Contrast[i],
  440.                                                       sizeof(m_sCustomHwLevel.SubLCD_Contrast[i]) );
  441.         if(MetaResult!=META_SUCCESS)  return(false);
  442.     }
  443.     // Sub LCD bias
  444.     for( i=0; i<LCD_PARAM_MAX_LEVEL; i++ )
  445.     {
  446.         as_str = "";
  447.         as_str = as_str + "SubLCD_Bias" + "[" + IntToStr(i) + "]";
  448.         MetaResult = META_NVRAM_SetRecFieldValue( "NVRAM_EF_CUST_HW_LEVEL_TBL_LID",
  449.                                                       as_str.c_str(),
  450.                                                       m_pcCustHwBuf,
  451.                                                       m_iCustHwBufSize,
  452.                                                       &m_sCustomHwLevel.SubLCD_Bias[i],
  453.                                                       sizeof(m_sCustomHwLevel.SubLCD_Bias[i]) );
  454.         if(MetaResult!=META_SUCCESS)  return(false);
  455.     }
  456.     // Sub LCD linerate
  457.     for( i=0; i<LCD_PARAM_MAX_LEVEL; i++ )
  458.     {
  459.         as_str = "";
  460.         as_str = as_str + "SubLCD_Linerate" + "[" + IntToStr(i) + "]";
  461.         MetaResult = META_NVRAM_SetRecFieldValue( "NVRAM_EF_CUST_HW_LEVEL_TBL_LID",
  462.                                                       as_str.c_str(),
  463.                                                       m_pcCustHwBuf,
  464.                                                       m_iCustHwBufSize,
  465.                                                       &m_sCustomHwLevel.SubLCD_Linerate[i],
  466.                                                       sizeof(m_sCustomHwLevel.SubLCD_Linerate[i]) );
  467.         if(MetaResult!=META_SUCCESS)  return(false);
  468.     }
  469.     // Sub LCD temperature
  470.     for( i=0; i<LCD_PARAM_MAX_LEVEL; i++ )
  471.     {
  472.         as_str = "";
  473.         as_str = as_str + "SubLCD_Temp" + "[" + IntToStr(i) + "]";
  474.         MetaResult = META_NVRAM_SetRecFieldValue( "NVRAM_EF_CUST_HW_LEVEL_TBL_LID",
  475.                                                       as_str.c_str(),
  476.                                                       m_pcCustHwBuf,
  477.                                                       m_iCustHwBufSize,
  478.                                                       &m_sCustomHwLevel.SubLCD_Temp[i],
  479.                                                       sizeof(m_sCustomHwLevel.SubLCD_Temp[i]) );
  480.         if(MetaResult!=META_SUCCESS)  return(false);
  481.     }
  482.     // Battery level
  483.     for( i=0; i<BATTERY_MAX_LEVEL; i++ )
  484.     {
  485.         as_str = "";
  486.         as_str = as_str + "BatteryLevel" + "[" + IntToStr(i) + "]";
  487.         MetaResult = META_NVRAM_SetRecFieldValue( "NVRAM_EF_CUST_HW_LEVEL_TBL_LID",
  488.                                                       as_str.c_str(),
  489.                                                       m_pcCustHwBuf,
  490.                                                       m_iCustHwBufSize,
  491.                                                       &m_sCustomHwLevel.BatteryLevel[i],
  492.                                                       sizeof(m_sCustomHwLevel.BatteryLevel[i]) );
  493.         if(MetaResult!=META_SUCCESS)  return(false);
  494.     }
  495.     return(true);
  496. }
  497. //===========================================================================
  498. void  CBBCUSTHW::REQ_Read_From_NVRAM( void )
  499. {
  500.     bb_custhw_ptr = this;
  501.     g_bIsRunning = true;
  502.     META_RESULT MetaResult;
  503.     if( NULL == m_pcCustHwBuf )
  504.     {
  505.         MetaResult = META_NVRAM_GetRecLen( "NVRAM_EF_CUST_HW_LEVEL_TBL_LID",
  506.                                           &m_iCustHwBufSize );
  507.         if(MetaResult!=META_SUCCESS)
  508.         {   Confirm( STATE_CUST_HW_FAIL );  return;  }
  509.         m_pcCustHwBuf = new  char[m_iCustHwBufSize];
  510.     }
  511.     NVRAMMan->ConfirmCallback = ::CNF_ReadFromNVRAM;
  512.     NVRAMMan->REQ_ReadNVRAM_Start( "NVRAM_EF_CUST_HW_LEVEL_TBL_LID",
  513.                                    1, // only one record
  514.                                    m_iCustHwBufSize,
  515.                                    m_pcCustHwBuf );
  516. }
  517. //-------------------------------------
  518. void  CBBCUSTHW::CNF_ReadFromNVRAM( void )
  519. {
  520.     if(!g_bIsRunning)  return;
  521.     E_METAAPP_RESULT_T state = NVRAMMan->Get_ConfirmState();
  522.     switch( state )
  523.     {
  524.         case METAAPP_SUCCESS:
  525.         {
  526.             if( !Decompose_CustHwLevel() )
  527.             {   Confirm( STATE_CUST_HW_FAIL );  return;  }
  528.             ActiveMan->SetActiveFunction( ::REQ_Finish );
  529.         }
  530.         break;
  531.         case METAAPP_TIMEOUT:
  532.         {
  533.             Confirm( STATE_CUST_HW_TIMEOUT );
  534.         }
  535.         break;
  536.         case METAAPP_STOP:
  537.         {
  538.            Confirm( STATE_CUST_HW_STOP );
  539.         }
  540.         break;
  541.         case STATE_CUST_HW_FAIL:
  542.         {
  543.             Confirm( STATE_CUST_HW_FAIL );
  544.         }
  545.         break;
  546.     }    
  547. }
  548. //------------------------------------------------------------------------------
  549. void  CBBCUSTHW::REQ_Write_To_NVRAM( void )
  550. {
  551.     bb_custhw_ptr = this;
  552.     g_bIsRunning = true;
  553.     META_RESULT MetaResult;
  554.     
  555.     if( NULL == m_pcCustHwBuf )
  556.     {
  557.         MetaResult = META_NVRAM_GetRecLen( "NVRAM_EF_CUST_HW_LEVEL_TBL_LID",
  558.                                            &m_iCustHwBufSize );
  559.         if(MetaResult!=META_SUCCESS)
  560.         {   Confirm( STATE_CUST_HW_FAIL );  return;  }
  561.         m_pcCustHwBuf = new  char[m_iCustHwBufSize];
  562.     }
  563.     if( !Compose_CustHwLevel() )
  564.     {   Confirm( STATE_CUST_HW_FAIL );  return;  }
  565.     NVRAMMan->ConfirmCallback = ::CNF_WriteToNVRAM;
  566.     NVRAMMan->REQ_WriteNVRAM_Start( "NVRAM_EF_CUST_HW_LEVEL_TBL_LID",
  567.                             1, // temp set to 1
  568.                                     m_iCustHwBufSize,
  569.                                     m_pcCustHwBuf );
  570. }
  571. //-------------------------------------
  572. void  CBBCUSTHW::CNF_WriteToNVRAM( void )
  573. {
  574.    if(!g_bIsRunning)  return;
  575.     E_METAAPP_RESULT_T state = NVRAMMan->Get_ConfirmState();
  576.     switch( state )
  577.     {
  578.         case METAAPP_SUCCESS:
  579.         {
  580.             ActiveMan->SetActiveFunction( ::REQ_Finish );
  581.         }
  582.         break;
  583.         case METAAPP_TIMEOUT:
  584.         {
  585.             Confirm( STATE_CUST_HW_TIMEOUT );
  586.         }
  587.         break;
  588.         case METAAPP_STOP:
  589.         {
  590.             Confirm( STATE_CUST_HW_STOP );
  591.         }
  592.         break;
  593.         case METAAPP_FAIL:
  594.         {
  595.             Confirm( STATE_CUST_HW_FAIL );
  596.         }
  597.         break;
  598.    }
  599. }
  600. //===========================================================================
  601. bool  CBBCUSTHW::REQ_Read_From_File( char *filename )
  602. {
  603.     TIniFile   *ini_file;
  604.     int         i;
  605.     AnsiString  as_str;
  606.     ini_file = new TIniFile( filename );
  607.     if( ini_file == NULL )  return  false;
  608.     for( i=0; i<VISIBLE_BATTERY_LEVEL_NUM; i++ )
  609.     {
  610.         as_str = ini_file->ReadString( "Battery level",
  611.                                        Battery_Level_Name[i],
  612.                                        "0" );
  613.         m_sCustomHwLevel.BatteryLevel[i] = as_str.ToInt();
  614.     }
  615.     delete  ini_file;
  616.     return  true;
  617. }
  618. //------------------------------------------------------------------------
  619. bool   CBBCUSTHW::REQ_Write_To_File( char *filename )
  620. {
  621.     TIniFile   *ini_file;
  622.     int         i;
  623.     ini_file = new TIniFile( filename );
  624.     if( ini_file == NULL )  return  false;
  625.     for( i=0; i<VISIBLE_BATTERY_LEVEL_NUM; i++ )
  626.     {
  627.        ini_file->WriteString( "Battery level",
  628.                               Battery_Level_Name[i],
  629.                               IntToStr( m_sCustomHwLevel.BatteryLevel[i] ) );
  630.     }
  631.     delete  ini_file;
  632.     return  true;
  633. }
  634. //===========================================================================
  635. ////////////////////////////  Global information  ///////////////////////////
  636. //===========================================================================
  637. int  CBBCUSTHW::Get_ConfirmState( void )
  638. {
  639.     return  m_iConfirmState;
  640. }
  641. //--------------------------------------------------------------------------
  642. S_CUSTOM_HW_LEVEL  CBBCUSTHW::Get_CustomHwLevel( void )
  643. {
  644.     return  m_sCustomHwLevel;
  645. }
  646. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  647. unsigned int CBBCUSTHW::Get_BatteryLevel( int idx )
  648. {   return m_sCustomHwLevel.BatteryLevel[idx];
  649. }
  650. //--------------------------------------------------------------------------
  651. void CBBCUSTHW::Set_BatteryLevel( int idx, unsigned int level )
  652. {
  653.     m_sCustomHwLevel.BatteryLevel[idx] = level;
  654. }