• Main Page
  • Related Pages
  • Data Structures
  • Files
  • File List
  • Globals

menu.c

Go to the documentation of this file.
00001 /****************** COPYRIGHT (C) 2007-2010 RAISONANCE S.A.S. *****************/
00015 /******************************************************************************/
00016 
00017 /* Includes ------------------------------------------------------------------*/
00018 #include "circle.h"
00019 
00021 
00022 /* Public function prototypes ------------------------------------------------*/
00023 
00024 /* Private define ------------------------------------------------------------*/
00025 #define MENU_DIVIDER    100
00026 #define MENU_DIVIDER2   10          // Divider for list management PRIMER2
00027 #define DELAY_AFTER_SEL 80          
00028 #define TIME_FOR_TOUCH_MENU  (2000)
00029 #define MENU_MIDD_POS   (-350)
00030 
00031 /* Private function prototypes -----------------------------------------------*/
00032 void MENU_SetCurrentApp( void );
00033 enum MENU_code fYes( void );
00034 enum MENU_code fNo( void );
00035 
00036 /* External variables --------------------------------------------------------*/
00037 
00038 /* Private variables ---------------------------------------------------------*/
00039 //u16                                 CharMagniCoeff_Menu           = 1;
00040 color_t                             BGndColor_Menu                = RGB_MAKE( 0xe6, 0xe6, 0xe6 ); //RGB_GREEN;
00041 color_t                             TextColor_Menu                = RGB_MAKE( 0x0, 0x0, 0x0 ); //RGB_BLUE;
00042 tMenu*                              CurrentMenu                   = 0;
00043 tMenuItem*                          CurrentCommand                = 0;
00044 tMenuItem*                          OldCommand                    = 0;
00045 divider_t                           divider                       = 0;
00046 bool                                iToShutDown                   = 0;
00047 index_t                             CurSel                        = -1;    
00048 index_t                             Oldsel                        = 0;     
00049 index_t                             Newsel                        = 0;     
00050 u8                                  MenuCharWidth                 = 7;
00051 u8                                  MenuCharHeight                = 14;
00052 s32 MenuTimePressed = 0;
00053 s16                                 DoubleClickCounter_Menu       = 0;     
00054 bool                                JoystickAsInput               = 1;
00055 bool                                MemsAsInput                   = 1;
00056 bool                                TchscrAsInput                 = 1;
00057 static s32                          Counter_Joystick_Touch        = 0;
00058 divider_t Menu_Divider          = MENU_DIVIDER;
00059 divider_t Appli_Divider         = MENU_DIVIDER;
00060 color_t title_BGndColor         = RGB_MAKE( 0xE6, 0x0, 0x0 );
00061 color_t title_TextColor         = RGB_WHITE;
00062 color_t selected_BGndColor      = RGB_MAKE( 0x8C, 0xBE, 0x0 );
00063 color_t selected_TextColor      = RGB_WHITE;
00064 tMenu* oldCurrentMenu;
00065 extern tMenu AppMenu;
00066 
00067 tMenu QuestionMenu =
00068 {
00069     1,
00070     0,
00071     2, 0, 0, 0, 0, 0,
00072     0,
00073     {
00074         { "Yes",    fYes,       0,  0 },
00075         { "No",     fNo,        0,  0 }
00076     }
00077 };
00078 
00079 tMenu PrintMenu =
00080 {
00081     1,
00082     0,
00083     0, 0, 0, 0, 0, 0,
00084     0,
00085     {
00086         { 0, 0, 0, 0 },
00087         { 0, 0, 0, 0 }
00088     }
00089 };
00090 
00091 #if TOUCHSCREEN_AVAIL
00092 tListMin ListMenu =
00093 {
00094     1,
00095     "Title",
00096     MENU_MAXITEM,
00097     0, 0, 0, 0, 0,
00098     MENU_MAXITEM,
00099     0,
00100     0
00101 };
00102 #endif
00103 
00104 bool* CurrentAnswer = 0;
00105 
00106 /* Private functions ---------------------------------------------------------*/
00107 enum MENU_code fQuit( void );
00108 
00109 /*******************************************************************************
00110 *
00111 *                                fShutDown
00112 *
00113 *******************************************************************************/
00120 /******************************************************************************/
00121 NODEBUG2 enum MENU_code fShutdown( void )
00122 {
00123     MENU_Question( "Shutdown?", &iToShutDown );
00124 
00125     return MENU_CHANGE;
00126 }
00127 
00128 /*******************************************************************************
00129 *
00130 *                                fSDCard
00131 *
00132 *******************************************************************************/
00139 /******************************************************************************/
00140 #if SDCARD_AVAIL
00141 NODEBUG2 enum MENU_code fSDCard( void )
00142 {
00143     MENU_Set( &SDcardMenu );
00144 
00145     return MENU_CHANGE;
00146 }
00147 #endif
00148 
00149 
00150 /*******************************************************************************
00151 *
00152 *                                RefreshItem
00153 *
00154 *******************************************************************************/
00162 /******************************************************************************/
00163 #if !TOUCHSCREEN_AVAIL
00164 NODEBUG2 void RefreshItem( index_t sel, bool isInverted )
00165 {
00166     color_t save_BGndColor      = DRAW_GetBGndColor();
00167     color_t save_TextColor      = DRAW_GetTextColor();
00168 
00169     // Set menu DRAW params
00170     LCD_ChangeFont( Menu_Font );
00171     DRAW_SetBGndColor( ( sel == -1 ) ? title_BGndColor : BGndColor_Menu );
00172     DRAW_SetTextColor( ( sel == -1 ) ? title_TextColor : TextColor_Menu );
00173 
00174     MenuCharWidth = Char_Width * CharMagniCoeff;
00175     MenuCharHeight = Char_Height * CharMagniCoeff;
00176 
00177     // Standard display
00178     if ( !isInverted )
00179     {
00180         DRAW_DisplayString( ( Char_Width / 2 ) + CurrentMenu->XPos + 0,
00181                             ( Char_Width / 2 ) + CurrentMenu->YPos + ( CurrentMenu->NbItems - sel - 1 ) * MenuCharHeight,
00182                             ( sel == -1 ) ? ( u8* )CurrentMenu->Title : ( u8* )( CurrentMenu->Items[sel].Text ),
00183                             CurrentMenu->LgMax );
00184     }
00185     else
00186     {
00187         DRAW_SetBGndColor( ( sel == CurrentMenu->SelectedItem ) ? selected_BGndColor : title_BGndColor );
00188         DRAW_SetTextColor( ( sel == CurrentMenu->SelectedItem ) ? selected_TextColor : title_TextColor );
00189 
00190         // Inverted display.
00191         DRAW_DisplayString( ( Char_Width / 2 ) + CurrentMenu->XPos,
00192                             ( Char_Width / 2 ) + CurrentMenu->YPos + ( CurrentMenu->NbItems - sel - 1 ) * MenuCharHeight,
00193                             ( sel == -1 ) ? ( u8* ) CurrentMenu->Title : ( u8* )( CurrentMenu->Items[sel].Text ),
00194                             CurrentMenu->LgMax );
00195     }
00196 
00197     // Draw a white rectangle around selected item, or background color for the others itmes.
00198     LCD_DrawRect( CurrentMenu->XPos + 2,
00199                   ( Char_Width / 2 ) + CurrentMenu->YPos + ( CurrentMenu->NbItems - sel - 1 ) * MenuCharHeight,
00200                   CurrentMenu->LgMax  * MenuCharWidth + 1,
00201                   Char_Height * CharMagniCoeff,
00202                   ( isInverted ) ? RGB_WHITE : BGndColor_Menu );
00203 
00204     // Restore previous DRAW params.
00205     LCD_SetDefaultFont();
00206     DRAW_SetBGndColor( save_BGndColor );
00207     DRAW_SetTextColor( save_TextColor );
00208 }
00209 #endif
00210 
00211 
00212 /*******************************************************************************
00213 *
00214 *                                fYes
00215 *
00216 *******************************************************************************/
00223 /******************************************************************************/
00224 NODEBUG2 enum MENU_code fYes( void )
00225 {
00226     if ( CurrentAnswer )
00227     {
00228         *CurrentAnswer = 1;
00229     }
00230 
00231     return fQuit();
00232 }
00233 
00234 /*******************************************************************************
00235 *
00236 *                                fNo
00237 *
00238 *******************************************************************************/
00245 /******************************************************************************/
00246 NODEBUG2 enum MENU_code fNo( void )
00247 {
00248     if ( CurrentAnswer )
00249     {
00250         *CurrentAnswer = 0;
00251     }
00252     return fQuit();
00253 }
00254 
00255 
00256 /* Public functions for CircleOS ---------------------------------------------*/
00257 
00258 /*******************************************************************************
00259 *
00260 *                                MENU_Handler
00261 *
00262 *******************************************************************************/
00270 /******************************************************************************/
00271 void MENU_Handler( void )
00272 {
00273     int            ret;
00274     static u32     bdelay = 0;
00275     index_t        app;
00276 
00277     if ( fInitDone  == FALSE )
00278         return;
00279 
00280     //-----------------------------------------------------------------------------
00281     // In the 'home' page, the push button calls the main menu
00282     //-----------------------------------------------------------------------------
00283     if ( ( CurrentMenu == 0 ) && ( BUTTON_GetState() == BUTTON_PUSHED_FORMAIN ) )
00284     {
00285 
00286         BUTTON_WaitForRelease();
00287 
00288         // Add current application into main menu
00289         MENU_SetCurrentApp();
00290 
00291         // Display main menu
00292         MENU_Set( &MainMenu );
00293     }
00294 
00295     //-----------------------------------------------------------------------------
00296     // iToShutDown is a global flag to indicate that a shutdown has been requested
00297     // In any situation, a long push will shutdown the power.
00298     // This part is managed by the power handler if exists
00299     //-----------------------------------------------------------------------------
00300 #if !POWER_MNGT
00301     if ( iToShutDown )
00302     {
00303         while ( 1 )
00304         {
00305             SHUTDOWN_Action();
00306         }
00307     }
00308 #endif
00309 
00310     //-----------------------------------------------------------------------------
00311     // No active menu (nor command) => nothing to do in this handler
00312     //-----------------------------------------------------------------------------
00313     if ( ( CurrentMenu == 0 ) && ( CurrentCommand == 0 ) )
00314     {
00315         return;
00316     }
00317 
00318 
00319     //-----------------------------------------------------------------------------
00320     // When a menu is active, we check whether a command is to be launched
00321     //-----------------------------------------------------------------------------
00322 #if !TOUCHSCREEN_AVAIL
00323     if ( ( CurrentMenu != 0 )    &&
00324             ( CurrentCommand == 0 ) &&
00325             ( ( BUTTON_GetState() == BUTTON_PUSHED_FORMAIN ) ||
00326               ( DoubleClickCounter_Menu != MEMS_Info.DoubleClick )
00327             ) )
00328     {
00329 #endif
00330 
00331 #if TOUCHSCREEN_AVAIL
00332 
00333         //----------------------------------------------------------------------------------
00334         // Continue only each MENU_DIVIDER2 calls (specific for the LIST management).
00335         //----------------------------------------------------------------------------------
00336         divider++;
00337         if ( divider % MENU_DIVIDER2 )
00338         {
00339             return;
00340         }
00341 
00342         if ( ( CurrentMenu != 0 ) && ( CurrentCommand == 0 ) )
00343         {
00344             index_t index = -1;
00345 
00346             // Management menu by List
00347             index = LIST_Manager();
00348 
00349             // Item selected
00350             if ( index != -1 )
00351             {
00352                 CurrentMenu->SelectedItem = index;
00353 #endif
00354                 oldCurrentMenu = CurrentMenu;
00355 
00356                 BUTTON_WaitForRelease();
00357                 DoubleClickCounter_Menu = MEMS_Info.DoubleClick;
00358 
00359                 // Handle the application change selection
00360                 if ( ( CurrentMenu == &AppMenu )
00361                         && ( AppMenu.Items[AppMenu.SelectedItem].Fct_Init != MENU_Quit ) )
00362                 {
00363                     app = APP_FindAppIndex( CurrentMenu->SelectedItem );
00364                     UTIL_WriteBackupRegister( BKP_SYS1, app );
00365                     UTIL_LoadApp( app );
00366                 }
00367 
00368                 CurrentCommand = &( oldCurrentMenu->Items[oldCurrentMenu->SelectedItem] );
00369 
00370                 if ( CurrentCommand->fMenuFlag & REMOVE_MENU )
00371                 {
00372                     MENU_Remove();
00373                 }
00374 
00375                 if ( oldCurrentMenu->NbItems )
00376                 {
00377                     if ( CurrentCommand->fMenuFlag & APP_MENU )
00378                     {
00379                         MENU_Remove();
00380                         POINTER_SetMode( POINTER_OFF );
00381                         BUTTON_SetMode( BUTTON_ONOFF );
00382                         LCD_SetRotateScreen( 0 );
00383 
00384                         // By default, set the offset for application compatibility with Open4
00385                         if ( UTIL_GetPrimerType() > 2 )
00386                             LCD_SetOffset( OFFSET_ON );
00387                     }
00388 
00389                     // Call application initialization function.
00390 #if POWER_MNGT
00391                     POWER_Reset_Time();
00392 #endif
00393                     ret = CurrentCommand ->Fct_Init();
00394 
00395                     MENU_ClearCurrentCommand();
00396 
00397                     if ( ret != MENU_CHANGE )
00398                     {
00399                         if ( ret != MENU_CONTINUE_COMMAND )
00400                         {
00401                             CurrentMenu = oldCurrentMenu;
00402                         }
00403                     }
00404                 }
00405                 else
00406                 {
00407                     CurrentMenu = 0;
00408 
00409                     MENU_ClearCurrentCommand();
00410                     MENU_Remove();
00411                     fQuit();
00412 
00413                     return;
00414                 }
00415 
00416                 switch ( ret )
00417                 {
00418                 case MENU_LEAVE_AS_IT      :
00419                     CurrentMenu = 0;
00420                     CurrentCommand = 0;
00421                     LCD_SetOffset( OFFSET_OFF );
00422                     LCD_SetDefaultFont();
00423                     LCD_SetTransparency( 0 );
00424                     break;
00425 
00426                 case MENU_LEAVE            :
00427                     if ( !( CurrentMenu->Items[CurrentMenu->SelectedItem].fMenuFlag & REMOVE_MENU ) )
00428                     {
00429                         MENU_Remove();
00430                     }
00431                     CurrentCommand = 0;
00432                     CurrentMenu = 0;
00433                     LCD_SetOffset( OFFSET_OFF );
00434                     LCD_SetDefaultFont();
00435                     LCD_SetTransparency( 0 );
00436                     break;
00437 
00438                 case MENU_REFRESH          :
00439                     MENU_Set( CurrentMenu );
00440                     break;
00441 
00442                 case MENU_CHANGE           :
00443                 case MENU_CONTINUE         :
00444                     break;
00445 
00446                 case MENU_CONTINUE_COMMAND :
00447                     CurrentCommand = &( oldCurrentMenu->Items[oldCurrentMenu->SelectedItem] );
00448                     break;
00449                 }
00450 
00451                 return;
00452 
00453 #if TOUCHSCREEN_AVAIL
00454             } // end if((index != -1))
00455 #endif
00456         } // end if(CurrentMenu != 0)
00457 
00458 #if !TOUCHSCREEN_AVAIL
00459         //-----------------------------------------------------------------------------
00460         // Continue only each Appli_Divider calls.
00461         //-----------------------------------------------------------------------------
00462         divider++;
00463 #endif
00464 
00465         //-----------------------------------------------------------------------------
00466         // A command is active and we redirect the execution to the application (or the configuration procedure)
00467         //-----------------------------------------------------------------------------
00468         if ( CurrentCommand && CurrentCommand->Fct_Manage )
00469         {
00470             if ( divider % Appli_Divider )
00471             {
00472                 return;
00473             }
00474 
00475             // Call application 'main' function.
00476 #if POWER_MNGT
00477             POWER_Reset_Time();
00478 #endif
00479 
00480             ret = CurrentCommand->Fct_Manage();
00481 
00482             if ( ret == MENU_LEAVE )
00483             {
00484                 LCD_SetOffset( OFFSET_OFF );
00485                 LCD_SetDefaultFont();
00486                 LCD_SetTransparency( 0 );
00487                 MENU_Remove();
00488                 CurrentMenu = 0;
00489                 CurrentCommand = 0;
00490                 LCD_SetRotateScreen( 1 );           // YRT20090305
00491             }
00492             else if ( ( ret == MENU_RESTORE_COMMAND ) && OldCommand )
00493             {
00494                 // YRT20090402 restore previous command,
00495                 CurrentCommand  = OldCommand;       // like application for example
00496             }
00497 
00498             return;
00499         }
00500 
00501         //-----------------------------------------------------------------------------
00502         // Continue only each MENU_DIVIDER calls.
00503         //-----------------------------------------------------------------------------
00504         if ( divider % Menu_Divider )
00505         {
00506             return;
00507         }
00508 
00509         //-----------------------------------------------------------------------------
00510         // Check again whether a menu is active
00511         //-----------------------------------------------------------------------------
00512         if ( CurrentMenu == 0 )
00513         {
00514             return;
00515         }
00516 
00517 #if !TOUCHSCREEN_AVAIL
00518         //-----------------------------------------------------------------------------
00519         // Manage the selection change within a menu
00520         //-----------------------------------------------------------------------------
00521 #if JOYSTICK_AVAIL
00522         //-----------------------------------------------------------------------------
00523         // Manage the command selection with joystick according to interface configuration
00524         //-----------------------------------------------------------------------------
00525         if ( JoystickAsInput )
00526         {
00527 #if POWER_MNGT
00528             POWER_Reset_Time();
00529 #endif
00530             switch ( JOYSTICK_GetState() )
00531             {
00532             case JOYSTICK_DOWN:
00533                 Newsel = Oldsel + 1;
00534                 JOYSTICK_WaitForRelease();
00535                 Counter_Joystick_Touch = WEIGHTED_TIME( DELAY_AFTER_SEL ); // to leave the hand to the joystick for a while
00536                 break;
00537 
00538             case JOYSTICK_UP:
00539                 Newsel = Oldsel - 1;
00540                 JOYSTICK_WaitForRelease();
00541                 Counter_Joystick_Touch = WEIGHTED_TIME( DELAY_AFTER_SEL ); // to leave the hand to the joystick for a while
00542                 break;
00543             default:
00544                 if ( Counter_Joystick_Touch )
00545                     Counter_Joystick_Touch-- ;
00546                 break;
00547             }
00548         }
00549 
00550 #endif // if Joystick  
00551 
00552         if ( ( MemsAsInput && ( Counter_Joystick_Touch == 0 ) ) || !JoystickAsInput )
00553         {
00554             // Manage the command selection with the current menu with mems
00555             s16 MenuMaxPosY = MENU_MIDD_POS - 20 * CurrentMenu->NbItems;
00556             s16 MenuMinPosY = MENU_MIDD_POS + 20 * CurrentMenu->NbItems;
00557 
00558             // Filtering of the moves in the menu:
00559             //  Oldsel and Newsel defines the new selected items.
00560             //  Newsel is the current selected item, and Oldsel the previous one.
00561             // When the selection is stable (Newsel==Oldsel for MAXBTIME times),
00562             //  we consider that the current selection (sel) can be changed by Newsel.
00563 
00564             // Try absolute angle for positionning.
00565             if ( MEMS_Info.RELATIVE_Y > MenuMinPosY )
00566             {
00567                 // Out of range: too low.
00568                 Newsel = 0;
00569             }
00570             else if ( MEMS_Info.RELATIVE_Y < MenuMaxPosY )
00571             {
00572                 // Out of range: too high.
00573                 Newsel = CurrentMenu->NbItems - 1;
00574             }
00575             else  // In the range
00576             {
00577                 Newsel = ( ( MenuMinPosY  - MEMS_Info.RELATIVE_Y ) * ( CurrentMenu->NbItems - 2 ) ) / ( MenuMinPosY  - MenuMaxPosY ) + 1 ;
00578             }
00579         }
00580 
00581         //-----------------------------------------------------------------------------
00582         // Manage the command selection also with mems according to interface configuration
00583         //-----------------------------------------------------------------------------
00584         if ( Newsel >= CurrentMenu->NbItems )
00585         {
00586             Newsel = CurrentMenu->NbItems - 1;
00587         }
00588 
00589         if ( Newsel < 0 )
00590         {
00591             Newsel = 0;
00592         }
00593 
00594         if ( Newsel != Oldsel )
00595         {
00596             Oldsel = Newsel;
00597         }
00598         else
00599         {
00600             // Hysteresis
00601             bdelay++;
00602 
00603             if ( bdelay >= WEIGHTED_TIME( MAXBTIME ) )
00604             {
00605                 CurSel = Newsel;
00606                 bdelay = 0;
00607             }
00608         }
00609 
00610         if ( ( CurrentMenu->SelectedItem != CurSel ) && CurrentMenu->NbItems )
00611         {
00612             // First refresh old selected item
00613             if ( CurrentMenu->SelectedItem >= 0 )
00614             {
00615                 RefreshItem( CurrentMenu->SelectedItem, NORMAL_TEXT );
00616             }
00617 
00618             // Then select the new selected item
00619             CurrentMenu->SelectedItem = CurSel;
00620             RefreshItem( CurrentMenu->SelectedItem, INVERTED_TEXT );
00621         }
00622 
00623 #endif // if !Touchscreen    
00624     }
00625 
00626     /*******************************************************************************
00627     *
00628     *                                fQuit
00629     *
00630     *******************************************************************************/
00637     /******************************************************************************/
00638     NODEBUG2 enum MENU_code fQuit( void )
00639     {
00640         BUTTON_WaitForRelease();
00641         DRAW_SetDefaultColor();
00642 
00643         LCD_SetOffset( OFFSET_OFF );
00644 
00645         POINTER_SetApplication_Pointer_Mgr( 0 );
00646         POINTER_SetMode( POINTER_OFF );
00647         POINTER_Init();
00648 
00649         MENU_ClearCurrentCommand();
00650         DRAW_Clear();
00651         LCD_SetDefaultFont();
00652         LCD_SetTransparency( 0 );
00653 
00654         LED_Set( LED_GREEN, LED_OFF );
00655         LED_Set( LED_RED, LED_OFF );
00656 
00657 #if SDCARD_AVAIL
00658         FS_SetPathFilter( 0 );
00659 #endif
00660 
00661         POINTER_SetMode( POINTER_ON );
00662         LCD_SetRotateScreen( 1 );
00663         BUTTON_SetMode( BUTTON_ONOFF_FORMAIN );
00664 
00665         return MENU_LEAVE;
00666     }
00667 
00668     /*******************************************************************************
00669     *
00670     *                                FS_Explorer_Handler
00671     *
00672     *******************************************************************************/
00680     /******************************************************************************/
00681 #if SDCARD_AVAIL
00682     NODEBUG2 enum MENU_code FS_Explorer_Handler( void )
00683     {
00684         if ( FS_Explorer() == -1 )
00685             return MENU_CONTINUE;
00686         else
00687             return fQuit();
00688     }
00689 #endif //SDCARD_AVAIL
00690 
00692 
00693     /* Public functions ----------------------------------------------------------*/
00694 
00695     /*******************************************************************************
00696     *
00697     *                                MENU_Quit
00698     *
00699     *******************************************************************************/
00706     /******************************************************************************/
00707     enum MENU_code MENU_Quit( void )
00708     {
00709         return fQuit();
00710     }
00711 
00712     /*******************************************************************************
00713     *
00714     *                                MENU_SetTextColor
00715     *
00716     *******************************************************************************/
00724     /********************************************************************************/
00725     void MENU_SetTextColor( color_t TxtColor )
00726     {
00727         TextColor_Menu = TxtColor;
00728     }
00729 
00730     /*******************************************************************************
00731     *
00732     *                                MENU_GetTextColor
00733     *
00734     *******************************************************************************/
00742     /******************************************************************************/
00743     color_t MENU_GetTextColor( void )
00744     {
00745         return TextColor_Menu;
00746     }
00747 
00748     /*******************************************************************************
00749     *
00750     *                                MENU_SetBGndColor
00751     *
00752     *******************************************************************************/
00760     /******************************************************************************/
00761     void MENU_SetBGndColor( color_t BGndColor )
00762     {
00763         BGndColor_Menu = BGndColor;
00764     }
00765 
00766     /*******************************************************************************
00767     *
00768     *                                MENU_GetBGndColor
00769     *
00770     *******************************************************************************/
00778     /******************************************************************************/
00779     color_t MENU_GetBGndColor( void )
00780     {
00781         return BGndColor_Menu;
00782     }
00783 
00784     /*******************************************************************************
00785     *
00786     *                                MENU_Remove
00787     *
00788     *******************************************************************************/
00794     /******************************************************************************/
00795     void MENU_Remove( void )
00796     {
00797         CurrentMenu = 0;
00798         DRAW_Clear();
00799         POINTER_SetMode( POINTER_ON );
00800         POINTER_SetRectScreen();
00801         LCD_SetDefaultFont();
00802         LCD_SetTransparency( 0 );
00803         /*#if TOUCHSCREEN_AVAIL
00804                 CharMagniCoeff_List = 1;
00805         #endif*/
00806     }
00807 
00808     /*******************************************************************************
00809     *
00810     *                                MENU_Set
00811     *
00812     *******************************************************************************/
00820     /******************************************************************************/
00821     void MENU_Set( tMenu * mptr )
00822     {
00823         int lg;
00824         int lg_max     = 0;
00825         int i;
00826         int n          = mptr->NbItems;
00827         int nlines     = n;
00828 
00829 #if TOUCHSCREEN_AVAIL
00830 
00831         // Menu management by list
00832         if ( CurrentToolbar == &DefaultToolbar )
00833         {
00834             TOOLBAR_ChangeButton( 0, 0, 0 ); // Remove the 'config' button
00835             TOUCHSCR_SetMode( TS_NORMAL );
00836         }
00837 
00838         // Primer menu management by LIST
00839         ListMenu.fdispTitle = mptr->fdispTitle;
00840         ListMenu.Title = mptr->Title;
00841         ListMenu.NbItems = mptr->NbItems;
00842         ListMenu.NbDisp = mptr->NbItems;
00843         ListMenu.XPos = mptr->XPos;
00844         ListMenu.YPos = mptr->YPos;
00845         ListMenu.FirstDisplayItem = 0;
00846 
00847         for ( i = 0; i < ListMenu.NbItems; i++ )
00848         {
00849             ListMenu.Items[i].Text = ( char* )mptr->Items[i].Text;
00850         }
00851 
00852         if ( ( ListMenu.XPos + ListMenu.YPos ) == 0 )
00853             LIST_Set( ( tList* ) &ListMenu, 0, 0, TRUE );
00854         else
00855             LIST_Set( ( tList* ) &ListMenu, ListMenu.XPos, ListMenu.YPos, FALSE );
00856 
00857 #endif  // Touchscreen     
00858 
00859         CurrentMenu = mptr;
00860         OldCommand = CurrentCommand;
00861 
00862         MENU_ClearCurrentCommand();
00863         POINTER_SetMode( POINTER_MENU );
00864 
00865 #if !TOUCHSCREEN_AVAIL
00866 
00867         // Old menu management
00868         for ( i = 0; i < n; i++ )
00869         {
00870             lg = my_strlen( ( char* )mptr->Items[i].Text );
00871 
00872             if ( lg > lg_max )
00873             {
00874                 lg_max = lg;
00875             }
00876         }
00877 
00878         if ( mptr->fdispTitle )
00879         {
00880             lg = my_strlen( ( char* )mptr->Title );
00881 
00882             if ( lg > lg_max )
00883             {
00884                 lg_max = lg;
00885             }
00886 
00887             nlines++;
00888         }
00889 
00890 #if !EXT_FONT
00891         Menu_Font = ( MENU_BigFont ? 1 : 0 );
00892 #endif
00893         LCD_ChangeFont( Menu_Font );
00894         mptr->LgMax = lg_max;
00895         mptr->XSize = ( lg_max * Char_Width * CharMagniCoeff ) + Char_Width;
00896         mptr->YSize = ( nlines * Char_Height * CharMagniCoeff ) + Char_Width;
00897         mptr->XPos  = ( Screen_Width  - mptr->XSize ) / 2;
00898         mptr->YPos  = ( Screen_Height - mptr->YSize ) / 2;
00899 
00900         //
00901         LCD_FillRect_Circle( mptr->XPos, mptr->YPos, mptr->XSize, mptr->YSize, BGndColor_Menu );
00902         LCD_DrawRect( mptr->XPos, mptr->YPos, mptr->XSize, mptr->YSize, 0 );
00903 
00904         // Display title.
00905         if ( mptr->fdispTitle )
00906         {
00907             RefreshItem( -1, NORMAL_TEXT );
00908         }
00909 
00910         // Set variables used for filtering/stability.
00911         CurSel = mptr->SelectedItem;
00912         Oldsel = CurSel;
00913         Newsel = CurSel;
00914 
00915         // Display the list of items.
00916         for ( i = 0 ; i < n ; i++ )
00917         {
00918             RefreshItem( i, ( i == mptr->SelectedItem ) ? INVERTED_TEXT : NORMAL_TEXT );
00919         }
00920 
00921         // No time display while a menu is active.
00922         fDisplayTime = 0;
00923 
00924         DoubleClickCounter_Menu = MEMS_Info.DoubleClick;
00925 
00926         LCD_SetDefaultFont();
00927 
00928 #endif // if !TOUCHSCREEN_AVAIL
00929 
00930         BUTTON_SetMode( BUTTON_ONOFF_FORMAIN );
00931     }
00932 
00933     /*******************************************************************************
00934     *
00935     *                                MENU_Question
00936     *
00937     *******************************************************************************/
00946     /********************************************************************************/
00947     void MENU_Question( const u8 * str, bool * answer )
00948     {
00949         QuestionMenu.Title   = str;
00950         CurrentAnswer        = answer;
00951 
00952         MENU_Set( &QuestionMenu );
00953     }
00954 
00955     /***********************************************************************************
00956     *
00957     *                                MENU_ClearCurrentCommand
00958     *
00959     ************************************************************************************/
00965     /********************************************************************************/
00966     void MENU_ClearCurrentCommand( void )
00967     {
00968         CurrentCommand = 0;
00969     }
00970 
00971     /***********************************************************************************
00972     *
00973     *                                MENU_ClearCurrentMenu
00974     *
00975     ************************************************************************************/
00981     /********************************************************************************/
00982     void MENU_ClearCurrentMenu( void )
00983     {
00984         CurrentMenu = 0;
00985     }
00986 
00987     /***********************************************************************************
00988     *
00989     *                                MENU_Print
00990     *
00991     ************************************************************************************/
00999     /********************************************************************************/
01000     void MENU_Print( const u8 * str )
01001     {
01002         PrintMenu.Title = str;
01003 
01004         MENU_Set( &PrintMenu );
01005     }
01006 
01007     /***********************************************************************************
01008     *
01009     *                                MENU_SetAppliDivider
01010     *
01011     ************************************************************************************/
01023     /********************************************************************************/
01024     void MENU_SetAppliDivider( divider_t divider )
01025     {
01026         Appli_Divider = divider;
01027     }
01028 
01029     /***********************************************************************************
01030     *
01031     *                                MENU_RestoreAppliDivider
01032     *
01033     ************************************************************************************/
01039     /********************************************************************************/
01040     void MENU_RestoreAppliDivider( void )
01041     {
01042         Appli_Divider = MENU_DIVIDER;
01043     }