MultiPurposeStopwatch.c
上传用户:lqx1163
上传日期:2014-08-13
资源大小:9183k
文件大小:18k
源码类别:

MTK

开发平台:

C/C++

  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.  * MultiPurposeStopwatch.c
  40.  *
  41.  * Project:
  42.  * --------
  43.  *   MAUI
  44.  *
  45.  * Description:
  46.  * ------------
  47.  *   This file is intends for phone setup application
  48.  *
  49.  * Author:
  50.  * -------
  51.  * -------
  52.  *
  53.  *============================================================================
  54.  *             HISTORY
  55.  * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  56.  *------------------------------------------------------------------------------
  57.  * removed!
  58.  *
  59.  * removed!
  60.  * removed!
  61.  * removed!
  62.  *
  63.  * removed!
  64.  * removed!
  65.  * removed!
  66.  *
  67.  *------------------------------------------------------------------------------
  68.  * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  69.  *============================================================================
  70.  ****************************************************************************/
  71. /**
  72.  * Copyright Notice
  73.  * ?2002 - 2003, Pixtel Communications, Inc., 1489 43rd Ave. W.,
  74.  * Vancouver, B.C. V6M 4K8 Canada. All Rights Reserved.
  75.  *  (It is illegal to remove this copyright notice from this software or any
  76.  *  portion of it)
  77.  */
  78. /***************** Stopwatch Application implementation *********************/
  79. /**************************************************************
  80.    FILENAME : MultiPurposeStopwatch.c
  81.    PURPOSE     : Multi Purpose Stopwatch application implementation
  82.    REMARKS     : nil
  83.    AUTHOR      : Deepali Gupta
  84.    DATE     : 05/01/2004
  85. **************************************************************/
  86. #include "MMI_features.h"
  87. #ifdef __MMI_STOPWATCH__
  88. /***********  Include: MMI header file **************/
  89. #include "PixtelDataTypes.h"
  90. #include "EventsGprot.h"
  91. #include "historyGprot.h"
  92. #include "ProtocolEvents.h"
  93. #include "wgui_categories.h"
  94. #include "wgui_categories_stopwatch.h"
  95. #include "Globaldefs.h"
  96. #include "HardwareEvents.h"
  97. #include "CustMenuRes.h"
  98. #include "CommonScreens.h"
  99. #include "MainMenuDef.h"
  100. #include "ProfileGprots.h"
  101. #include "StopwatchDef.h"
  102. #include "StopwatchGprot.h"
  103. #include "StopwatchProt.h"
  104. #include "StopwatchGexdcl.h"
  105. // #include "wallpaper.h"
  106. #include "gpioInc.h"
  107. #include "wgui_status_icons.h"
  108. /***************************************************************************** 
  109. * Define
  110. *****************************************************************************/
  111. /***************************************************************************** 
  112. * Typedef 
  113. *****************************************************************************/
  114. /***************************************************************************** 
  115. * Local Variable (Local to this file - static)
  116. *****************************************************************************/
  117. /***************************************************************************** 
  118. * Local Function (local to this file - static)
  119. *****************************************************************************/
  120. /***************************************************************************** 
  121. * Global Variable
  122. *****************************************************************************/
  123. /***************************************************************************** 
  124. * Global Function
  125. *****************************************************************************/
  126. /**********************************************************************
  127. *****************************************************************************/
  128. /*****************************************************************************
  129.  * FUNCTION
  130.  *  InitMultipurposeStopwatch
  131.  * DESCRIPTION
  132.  *  Init fn for Multipurpose stop watch.
  133.  * PARAMETERS
  134.  *  void
  135.  * RETURNS
  136.  *  void
  137.  *****************************************************************************/
  138. void InitMultipurposeStopwatch(void)
  139. {
  140.     /*----------------------------------------------------------------*/
  141.     /* Local Variables                                                */
  142.     /*----------------------------------------------------------------*/
  143.     U8 index;
  144.     /*----------------------------------------------------------------*/
  145.     /* Code Body                                                      */
  146.     /*----------------------------------------------------------------*/
  147.     memset(&gLastMPTimeRecord, 0, sizeof(UI_stop_watch));
  148.     memset(gMultiPurposeTimerList, 0, sizeof(UI_stop_watch) * MAX_MULTIPURPOSE_TIMER);
  149.     for (index = 0; index < MAX_MULTIPURPOSE_TIMER; index++)
  150.     {
  151.         gMultiPurposeTimerList[index].normalimagedata = GetImage((U16) (IMG_MULTIPURPOSE_TIMER1 + index));
  152.         gMultiPurposeTimerList[index].highlightimagedata = GetImage((U16) (IMG_MULTIPURPOSE_TIMER1 + index));
  153.     }
  154.     gMPTimerInit.assignedKey[0] = KEY_LEFT_ARROW;
  155.     gMPTimerInit.timerIndex[0] = 0;
  156.     gMPTimerInit.assignedKey[1] = KEY_UP_ARROW;
  157.     gMPTimerInit.timerIndex[1] = 1;
  158.     gMPTimerInit.assignedKey[2] = KEY_RIGHT_ARROW;
  159.     gMPTimerInit.timerIndex[2] = 2;
  160.     gMPTimerInit.assignedKey[3] = KEY_DOWN_ARROW;
  161.     gMPTimerInit.timerIndex[3] = 3;
  162. }
  163. /*****************************************************************************
  164.  * FUNCTION
  165.  *  EntryWtchScrMultipurposeStopwatch
  166.  * DESCRIPTION
  167.  *  Entry fn for Multipurpose stop watch.
  168.  * PARAMETERS
  169.  *  void
  170.  * RETURNS
  171.  *  void
  172.  *****************************************************************************/
  173. void EntryWtchScrMultipurposeStopwatch(void)
  174. {
  175.     /*----------------------------------------------------------------*/
  176.     /* Local Variables                                                */
  177.     /*----------------------------------------------------------------*/
  178.     U16 nStrItemList[15];   /* Stores the strings id of submenus returned */
  179.     U16 nNumofItem;         /* Stores no of children in the submenu */
  180.     U16 nDispAttribute;     /* Stores display attribue */
  181.     U8 *guiBuffer;          /* Buffer holding history data */
  182.     /*----------------------------------------------------------------*/
  183.     /* Code Body                                                      */
  184.     /*----------------------------------------------------------------*/
  185.     /* 1 Call Exit Handler */
  186.     EntryNewScreen(
  187.         SCR_MULTIPURPOSE_STOPWATCH,
  188.         ExitWtchScrMultiPurposeStopwatch,
  189.         EntryWtchScrMultipurposeStopwatch,
  190.         NULL);
  191.     /* 2 Get current screen to gui buffer  for history purposes */
  192.     guiBuffer = GetCurrGuiBuffer(SCR_MULTIPURPOSE_STOPWATCH);
  193.     /* 3. Retrieve no of child of menu item to be displayed */
  194.     nNumofItem = GetNumOfChild(MENU_MULTIPURPOSEWATCH);
  195.     /* 4. Get attribute of menu to be displayed */
  196.     nDispAttribute = GetDispAttributeOfItem(MENU_MULTIPURPOSEWATCH);
  197.     /* 5. Retrieve string ids in sequence of given menu item to be displayed */
  198.     GetSequenceStringIds(MENU_MULTIPURPOSEWATCH, nStrItemList);
  199.     /* 6 Set current parent id */
  200.     SetParentHandler(MENU_MULTIPURPOSEWATCH);
  201.     /* 7 Register highlight handler to be called in menu screen */
  202.     RegisterHighlightHandler(ExecuteCurrHiliteHandler);
  203.     /* 8 Display Category Screen */
  204.     if (gStopwatchAppInfo.MPTimerState == TIMER_NOT_STARTED)
  205.     {
  206.         ShowCategory306Screen(
  207.             &gLastMPTimeRecord,
  208.             0,
  209.             STR_MUTIPURPOSE_TITLE_SIDE_MSG,
  210.             STR_STOPWATCH_START,
  211.             0,
  212.             STR_GLOBAL_BACK,
  213.             IMG_GLOBAL_BACK,
  214.             MAX_MULTIPURPOSE_TIMER,
  215.             gMultiPurposeTimerList,
  216.             0,
  217.             STR_MUTIPURPOSE_TITLE_MSG,
  218.             guiBuffer,
  219.             gStopwatchAppInfo.currentHiliteTimer);
  220.         SetLeftSoftkeyFunction(ResetAllTimer, KEY_LONG_PRESS);
  221.         SetLeftSoftkeyFunction(StartIndexTimer, KEY_EVENT_UP);
  222.     }
  223.     else if (gStopwatchAppInfo.MPTimerState == TIMER_STOPPED)
  224.     {
  225.         ShowCategory306Screen(
  226.             &gLastMPTimeRecord,
  227.             0,
  228.             STR_MUTIPURPOSE_TITLE_SIDE_MSG,
  229.             STR_STOPWATCH_RESUME,
  230.             0,
  231.             STR_GLOBAL_BACK,
  232.             IMG_GLOBAL_BACK,
  233.             MAX_MULTIPURPOSE_TIMER,
  234.             gMultiPurposeTimerList,
  235.             0,
  236.             STR_MUTIPURPOSE_TITLE_MSG,
  237.             guiBuffer,
  238.             gStopwatchAppInfo.currentHiliteTimer);
  239.         SetLeftSoftkeyFunction(ResetAllTimer, KEY_LONG_PRESS);
  240.         SetLeftSoftkeyFunction(StartIndexTimer, KEY_EVENT_UP);
  241.     }
  242.     else
  243.     {
  244.         ShowCategory306Screen(
  245.             &gLastMPTimeRecord,
  246.             0,
  247.             STR_MUTIPURPOSE_TITLE_SIDE_MSG,
  248.             STR_STOPWATCH_STOP,
  249.             0,
  250.             STR_GLOBAL_BACK,
  251.             IMG_GLOBAL_BACK,
  252.             MAX_MULTIPURPOSE_TIMER,
  253.             gMultiPurposeTimerList,
  254.             0,
  255.             STR_MUTIPURPOSE_TITLE_MSG,
  256.             guiBuffer,
  257.             gStopwatchAppInfo.currentHiliteTimer);
  258.         SetLeftSoftkeyFunction(StopCurrentTimer, KEY_EVENT_UP);
  259.         SetLeftSoftkeyFunction(0, KEY_LONG_PRESS);
  260.     }
  261.     SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
  262.     /* Robin 0728 */
  263.     /* If using EVENT_UP as action key event, when pressing left key entering the nWay Stopwatch at the previous menu */
  264.     /* The key up event will trigger the related stopwatch start */
  265.     SetGroupKeyHandler(StartKeyTimer, gMPTimerInit.assignedKey, MAX_MULTIPURPOSE_TIMER, KEY_EVENT_DOWN);
  266.     /* SetExitHandler(SCR_MULTIPURPOSE_STOPWATCH,ExitWtchScrMultiPurposeStopwatch); */
  267. }
  268. /*****************************************************************************
  269.  * FUNCTION
  270.  *  ExitWtchScrMultiPurposeStopwatch
  271.  * DESCRIPTION
  272.  *  Exit fn for Multipurpose Stopwatch screen.
  273.  * PARAMETERS
  274.  *  void
  275.  * RETURNS
  276.  *  void
  277.  *****************************************************************************/
  278. void ExitWtchScrMultiPurposeStopwatch(void)
  279. {
  280.     /*----------------------------------------------------------------*/
  281.     /* Local Variables                                                */
  282.     /*----------------------------------------------------------------*/
  283.     /*----------------------------------------------------------------*/
  284.     /* Code Body                                                      */
  285.     /*----------------------------------------------------------------*/
  286.     GetMultipurposeTimeValues( /* &gLastMPTimeRecord,gMultiPurposeTimerList, */ &gStopwatchAppInfo.currentHiliteTimer);
  287.     if (gStopwatchAppInfo.MPTimerState == TIMER_RUNNING || gStopwatchAppInfo.TimerState == TIMER_RUNNING)
  288.     {
  289.         ShowStatusIcon(STATUS_ICON_STOP_WATCH);
  290.     }
  291.     else
  292.     {
  293.         HideStatusIcon(STATUS_ICON_STOP_WATCH);
  294.     }
  295.     UpdateStatusIcons();
  296. }
  297. /*****************************************************************************
  298.  * FUNCTION
  299.  *  StartKeyTimer
  300.  * DESCRIPTION
  301.  *  Start timer associated with any Key.
  302.  * PARAMETERS
  303.  *  void
  304.  * RETURNS
  305.  *  void
  306.  *****************************************************************************/
  307. void StartKeyTimer(void)
  308. {
  309.     /*----------------------------------------------------------------*/
  310.     /* Local Variables                                                */
  311.     /*----------------------------------------------------------------*/
  312.     U8 count = 0;
  313.     U16 keycode, keytype;
  314.     /*----------------------------------------------------------------*/
  315.     /* Code Body                                                      */
  316.     /*----------------------------------------------------------------*/
  317.     GetkeyInfo(&keycode, &keytype);
  318.     for (count = 0; count < MAX_MULTIPURPOSE_TIMER; count++)
  319.     {
  320.         if (keycode == gMPTimerInit.assignedKey[count])
  321.         {
  322.             gStopwatchAppInfo.currentTimerIndex = gMPTimerInit.timerIndex[count];
  323.             StartIndexTimer();
  324.             break;
  325.         }
  326.     }
  327. }
  328. /*****************************************************************************
  329.  * FUNCTION
  330.  *  StopCurrentTimer
  331.  * DESCRIPTION
  332.  *  Stop Currently active timer.
  333.  * PARAMETERS
  334.  *  void
  335.  * RETURNS
  336.  *  void
  337.  *****************************************************************************/
  338. void StopCurrentTimer(void)
  339. {
  340.     /*----------------------------------------------------------------*/
  341.     /* Local Variables                                                */
  342.     /*----------------------------------------------------------------*/
  343.     /*----------------------------------------------------------------*/
  344.     /* Code Body                                                      */
  345.     /*----------------------------------------------------------------*/
  346.     ChangeLeftSoftkey(STR_STOPWATCH_RESUME, 0);
  347.     SetLeftSoftkeyFunction(StartIndexTimer, KEY_EVENT_UP);
  348.     SetLeftSoftkeyFunction(ResetAllTimer, KEY_LONG_PRESS);
  349.     stop_multipurpose_timers();
  350.     /* TurnOnBacklight(1); */
  351.     gStopwatchAppInfo.MPTimerState = TIMER_STOPPED;
  352. }
  353. /*****************************************************************************
  354.  * FUNCTION
  355.  *  ResetAllTimer
  356.  * DESCRIPTION
  357.  *  Reset All Timer when Resume is long
  358.  *  pressed.
  359.  * PARAMETERS
  360.  *  void
  361.  * RETURNS
  362.  *  void
  363.  *****************************************************************************/
  364. void ResetAllTimer(void)
  365. {
  366.     /*----------------------------------------------------------------*/
  367.     /* Local Variables                                                */
  368.     /*----------------------------------------------------------------*/
  369.     /*----------------------------------------------------------------*/
  370.     /* Code Body                                                      */
  371.     /*----------------------------------------------------------------*/
  372.     ChangeLeftSoftkey(STR_STOPWATCH_START, 0);
  373.     SetLeftSoftkeyFunction(SetLSKMultiPurposeTimerResumeLongPress, KEY_EVENT_UP);
  374.     SetLeftSoftkeyFunction(0, KEY_LONG_PRESS);
  375.     reset_all_multipurpose_time();
  376.     gStopwatchAppInfo.currentTimerIndex = 0;
  377.     gStopwatchAppInfo.currentHiliteTimer = 0;
  378.     gStopwatchAppInfo.MPTimerState = TIMER_NOT_STARTED;
  379. }
  380. /*****************************************************************************
  381.  * FUNCTION
  382.  *  SetLSKMultiPurposeTimerResumeLongPress
  383.  * DESCRIPTION
  384.  *  Set LSK handler fn when Resume is long
  385.  *  pressed to reset the Multipurpose timer.
  386.  * PARAMETERS
  387.  *  void
  388.  * RETURNS
  389.  *  void
  390.  *****************************************************************************/
  391. void SetLSKMultiPurposeTimerResumeLongPress(void)
  392. {
  393.     /*----------------------------------------------------------------*/
  394.     /* Local Variables                                                */
  395.     /*----------------------------------------------------------------*/
  396.     /*----------------------------------------------------------------*/
  397.     /* Code Body                                                      */
  398.     /*----------------------------------------------------------------*/
  399.     gStopwatchAppInfo.currentTimerIndex = 0;
  400.     SetLeftSoftkeyFunction(StartIndexTimer, KEY_EVENT_UP);
  401. }
  402. /*****************************************************************************
  403.  * FUNCTION
  404.  *  StartIndexTimer
  405.  * DESCRIPTION
  406.  *  Call back fn to start Timer set in gCurrentTimerIndex.
  407.  * PARAMETERS
  408.  *  void
  409.  * RETURNS
  410.  *  void
  411.  *****************************************************************************/
  412. void StartIndexTimer(void)
  413. {
  414.     /*----------------------------------------------------------------*/
  415.     /* Local Variables                                                */
  416.     /*----------------------------------------------------------------*/
  417.     /*----------------------------------------------------------------*/
  418.     /* Code Body                                                      */
  419.     /*----------------------------------------------------------------*/
  420.     gStopwatchAppInfo.MPTimerState = TIMER_RUNNING;
  421.     ChangeLeftSoftkey(STR_STOPWATCH_STOP, 0);
  422.     SetLeftSoftkeyFunction(StopCurrentTimer, KEY_EVENT_UP);
  423.     SetLeftSoftkeyFunction(0, KEY_LONG_PRESS);
  424.     start_multipurpose_list_watch(gStopwatchAppInfo.currentTimerIndex);
  425.     /* TurnOnBacklight(0); */
  426. }
  427. #endif /* __MMI_STOPWATCH__ */