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

menu_settings.c

Go to the documentation of this file.
00001 /****************** COPYRIGHT (C) 2007-2010 RAISONANCE S.A.S. *****************/
00012 /******************************************************************************/
00013 
00014 /* Includes ------------------------------------------------------------------*/
00015 #include "circle.h"
00016 
00018 
00019 /* Private define ------------------------------------------------------------*/
00020 
00021 /* Private macro -------------------------------------------------------------*/
00022 #if LCD_HIGH_DEF
00023 #define PACK_SQUARE  (Char_Width * DRAW_GetCharMagniCoeff() * 3)
00024 #else
00025 #define PACK_SQUARE  (Char_Width * DRAW_GetCharMagniCoeff() * 2)
00026 #endif
00027 
00028 /* Private variables ---------------------------------------------------------*/
00029 CONST_DATA u8                       max_values[]            = { 24, 60, 60 };
00030 CONST_DATA u8* CONST_DATA           Test_Melody             = "Test:d=16,o=6,b=140:a,b,c,d,e,f,g";
00031 CONST_DATA uint_t                   Speed_Range[5]          =
00032 { SPEED_VERY_LOW, SPEED_LOW, SPEED_MEDIUM, SPEED_HIGH, SPEED_VERY_HIGH };
00033 
00034 u8                           temp_values[3];   // Holds the hour, minutes and seconds
00035 index_t                      xCurSel;
00036 index_t                      yCurSel;
00037 bool                         FirstDisplay            = 1;
00038 const u8*                    SetLevel_Title;
00039 bool                         fDynamicChange          = 0;
00040 divider_t                    menu_divider_coord      = 0;
00041 Rotate_H12_V_Match_TypeDef   previous_Screen_Orientation;
00042 
00043 
00044 /* Private function prototypes -----------------------------------------------*/
00045 
00046 /* External ------------------------------------------------------------------*/
00047 #if BACKLIGHT_INTERFACE
00048 extern uint_t               Current_CCR_BackLightStart;
00049 extern CONST_DATA int_t     CCR_BackLight_Tab[5];
00050 #endif // BACKLIGHT_INTERFACE
00051 extern tMenu                ConfigMenu;
00052 
00053 /*******************************************************************************
00054 *
00055 *                                fSetPllRange_Mgr
00056 *
00057 *******************************************************************************/
00064 /******************************************************************************/
00065 NODEBUG2 enum MENU_code fSetPllRange_Mgr( void )
00066 {
00067     enum MENU_code ret;
00068     uint_t curspeed = CurrentSpeed; // Necessary because enums can have char type
00069 
00070     MENU_SetLevelTitle( " Freq Setting" );
00071 
00072     fDynamicChange = 0;
00073     ret            = MENU_SetLevel_Mgr( &curspeed, ( uint_t* )Speed_Range );
00074     CurrentSpeed = curspeed;
00075     UTIL_SetPll( CurrentSpeed );
00076 
00077     return ret;
00078 }
00079 
00080 #if BACKLIGHT_INTERFACE
00081 /*******************************************************************************
00082 *
00083 *                                fSetBacklight_Mgr
00084 *
00085 *******************************************************************************/
00092 /******************************************************************************/
00093 NODEBUG2 enum MENU_code fSetBacklight_Mgr( void )
00094 {
00095     enum MENU_code ret;
00096 
00097     MENU_SetLevelTitle( "Backlight Power" );
00098 
00099     fDynamicChange = 1;
00100     ret            = MENU_SetLevel_Mgr( &Current_CCR_BackLightStart, ( uint_t* ) CCR_BackLight_Tab ) ;
00101 
00102     return ret;
00103 }
00104 #endif // BACKLIGHT_INTERFACE
00105 
00106 
00107 /*******************************************************************************
00108 *
00109 *                                fSetTime_Ini
00110 *
00111 *******************************************************************************/
00118 /******************************************************************************/
00119 NODEBUG2 enum MENU_code fSetTime_Ini( void )
00120 {
00121     u8 THH;
00122     u8 TMM;
00123     u8 TSS;
00124 
00125     // No more screen rotation allowed.
00126     LCD_SetRotateScreen( 0 );
00127 
00128     // Get current time.
00129     RTC_GetTime( &THH, &TMM, &TSS );
00130 
00131     // Store values into global variables for later use in fSetTime_Mgr.
00132     temp_values[0] = THH;
00133     temp_values[1] = TMM;
00134     temp_values[2] = TSS;
00135 
00136     FirstDisplay = 1;
00137 
00138     POINTER_SetMode( POINTER_OFF );
00139     BUTTON_SetMode( BUTTON_ONOFF );
00140     MENU_Remove();
00141 
00142     xCurSel = -1;
00143     yCurSel = -1;
00144 
00145     return MENU_CONTINUE_COMMAND;
00146 }
00147 
00148 /*******************************************************************************
00149 *
00150 *                                fSetTime_Mgr
00151 *
00152 *******************************************************************************/
00160 /******************************************************************************/
00161 NODEBUG2 enum MENU_code fSetTime_Mgr( void )
00162 {
00163     bool fRedrawn = 0;
00164     u8 buffer[10];
00165     u8 i;
00166     coord_t Time_Title_H;
00167     coord_t CharHeight, CharWidth;
00168     coord_t pos;
00169     coord_t ysel;
00170     coord_t xsel;
00171 
00172     // Hide menu.
00173     CurrentMenu = 0;
00174 
00175     // Character magnify deponding on the platform !
00176     DRAW_RestoreCharMagniCoeff();
00177 
00178     CharHeight = Char_Height * DRAW_GetCharMagniCoeff();
00179     CharWidth = Char_Width * DRAW_GetCharMagniCoeff();
00180 
00181 Restart:
00182     if ( FirstDisplay )
00183     {
00184         previous_Screen_Orientation = LCD_GetScreenOrientation();
00185 
00186         if ( fRedrawn == 0 )
00187         {
00188             POINTER_SetMode( POINTER_OFF );
00189         }
00190 
00191         Time_Title_H = CharHeight * 2;
00192         LCD_FillRect_Circle( 0, Screen_Height - Time_Title_H, Screen_Width, Time_Title_H, RGB_BLACK );
00193 
00194         DRAW_SetBGndColor( RGB_BLACK );
00195         DRAW_SetTextColor( RGB_MAKE( 0, 183, 239 ) );
00196         DRAW_DisplayStringWithMode( 0, Screen_Height - ( ( 3 * CharHeight ) / 2 ), "Time setting", ALL_SCREEN, NORMAL_TEXT, CENTER );
00197         DRAW_SetDefaultColor();
00198 
00199         // Display current time.
00200         for ( i = 0 ; i < 3 ; i ++ )
00201         {
00202             UTIL_uint2str( buffer, temp_values[i], 2, 1 );
00203 
00204             DRAW_DisplayString( TIME_MARGIN + i * ( PACK_SQUARE + 2 ), TIME_BOTTOM, buffer, 2 );
00205             DRAW_DisplayString( TIME_MARGIN + i * ( PACK_SQUARE + 2 ), TIME_BOTTOM + ( CharHeight + 2 ), "++", 2 );
00206             DRAW_DisplayString( TIME_MARGIN + i * ( PACK_SQUARE + 2 ), TIME_BOTTOM - ( CharHeight + 2 ), "--", 2 );
00207         }
00208 
00209         // Draw a big X for the 'cancel' button.
00210         DRAW_SetTextColor( RGB_RED );
00211         DRAW_SetCharMagniCoeff( 2 );
00212         DRAW_DisplayString( TIME_MARGIN + ( -1 ) * ( PACK_SQUARE + 2 ) , LCD_HIGH_DEF ? TIME_BOTTOM : TIME_BOTTOM - 6, "X", 1 );
00213 
00214         // Draw a big V for the 'validate' button.
00215         DRAW_SetTextColor( RGB_BLUE );
00216 #if LCD_HIGH_DEF
00217         DRAW_DisplayString( TIME_MARGIN + 3 * ( PACK_SQUARE + 2 ) + 10, TIME_BOTTOM, "V", 1 );
00218 #else
00219         DRAW_DisplayString( TIME_MARGIN + 3 * ( PACK_SQUARE + 2 ) - 30, TIME_BOTTOM - 6, "V", 1 );
00220 #endif
00221 
00222         // Restore magnify coefficient.
00223         DRAW_RestoreCharMagniCoeff();
00224         DRAW_SetDefaultColor();
00225 
00226         // Restrict the pointer moves to a rectangle.
00227         POINTER_SetRect( TIME_MARGIN + ( -1 ) * ( PACK_SQUARE + 2 ), TIME_BOTTOM - ( CharHeight + 2 ),
00228                          5 * ( PACK_SQUARE + 2 ) - POINTER_WIDTH,
00229                          3 * ( CharHeight + 2 ) - POINTER_WIDTH );
00230 
00231         POINTER_SetMode( POINTER_MENU );
00232         fRedrawn = 1;
00233     }
00234 
00235     pos = POINTER_GetPos();
00236     ysel = ( ( ( pos >> 8 ) & 0xFF ) - ( TIME_BOTTOM - ( CharHeight + 2 ) ) ) / ( CharHeight + 2 );
00237     xsel;
00238     xsel = ( ( pos & 0xFF ) - ( TIME_MARGIN + 10 - ( CharWidth + 2 ) ) ) / ( CharWidth + 2 );
00239 
00240     // ysel value meanings:
00241     // 0 : decrement line.
00242     // 1 : X and V line.
00243     // 2 : increment line.
00244 
00245     // xsel value meanings:
00246     // -1: on the 'cancel' button.
00247     //  0: hours
00248     //  1: minutes
00249     //  2: seconds
00250     //  3: on the 'validate' button.
00251 
00252     // xsel can only be in the [-1 .. 3] range.
00253     if ( xsel > 3 )
00254     {
00255         xsel = 3;
00256     }
00257 
00258     if ( xsel < -1 )
00259     {
00260         xsel = -1;
00261     }
00262 
00263     if ( ( xsel == -1 ) || ( xsel == 3 ) )
00264         ysel = 1;
00265 
00266 
00267     // The user pushed the button. Action will be different according to the
00268     // cursor position (xsel).
00269     if ( BUTTON_GetState() == BUTTON_PUSHED )
00270     {
00271         BUTTON_WaitForRelease();
00272 
00273         switch ( xsel )
00274         {
00275             // Set time with modified values before leaving application.
00276         case 3   :
00277             RTC_SetTime( temp_values[0], temp_values[1], temp_values[2] );
00278 
00279             // Leave application restoring CircleOS state.
00280         case -1  :
00281             MENU_ClearCurrentCommand();
00282             DRAW_SetDefaultColor();
00283             DRAW_Clear();
00284             POINTER_SetMode( POINTER_ON );
00285             BUTTON_SetMode( BUTTON_ONOFF_FORMAIN );
00286             POINTER_SetRectScreen();
00287             DRAW_SetCharMagniCoeff( 1 );
00288             LCD_SetRotateScreen( 1 );
00289             return MENU_LEAVE;
00290 
00291             // Increment or decrement according to ysel.
00292         case 0   :
00293         case 1   :
00294         case 2   :
00295             // Decrement
00296             if ( ysel == 0 )
00297             {
00298                 // If selected value is null roll over to max value.
00299                 if ( temp_values[xsel] == 0 )
00300                 {
00301                     temp_values[xsel] = max_values[xsel] - 1;
00302                 }
00303                 else
00304                 {
00305                     temp_values[xsel]--;
00306                 }
00307             }
00308             else if ( ysel == 2 ) // increment
00309             {
00310                 temp_values[xsel]++;
00311 
00312                 // Maximum value reached, restart at 0.
00313                 if ( temp_values[xsel] == max_values[xsel] )
00314                 {
00315                     temp_values[xsel] = 0;
00316                 }
00317             }
00318             break;
00319         }
00320 
00321         // Something was changed, redraw screen!
00322         FirstDisplay = 1;
00323         fRedrawn     = 1;
00324 
00325         goto Restart;
00326     }
00327 
00328     // Cursor changed its position or a redraw is needed.
00329     if ( ( xsel != xCurSel ) || ( ysel != yCurSel ) || fRedrawn )
00330     {
00331         if ( FirstDisplay == 0 )
00332         {
00333             // Unselect previously selected button.
00334             if ( xCurSel == -1 )
00335             {
00336                 // 'Cancel' button.
00337                 DRAW_SetCharMagniCoeff( 2 );
00338                 DRAW_SetTextColor( RGB_RED );
00339                 DRAW_DisplayString( TIME_MARGIN + ( -1 ) * ( PACK_SQUARE + 2 ), LCD_HIGH_DEF ? TIME_BOTTOM : TIME_BOTTOM - 6, "X", 1 );
00340 
00341                 // Restore default settings.
00342                 DRAW_SetDefaultColor();
00343                 DRAW_RestoreCharMagniCoeff();
00344             }
00345             else if ( xCurSel == 3 )
00346             {
00347                 // 'Validate' button.
00348                 DRAW_SetCharMagniCoeff( 2 );
00349                 DRAW_SetTextColor( RGB_BLUE );
00350 #if LCD_HIGH_DEF
00351                 DRAW_DisplayString( TIME_MARGIN + 3 * ( PACK_SQUARE + 2 ) + 10, TIME_BOTTOM, "V", 1 );
00352 #else
00353                 DRAW_DisplayString( TIME_MARGIN + 3 * ( PACK_SQUARE + 2 ) - 30, TIME_BOTTOM - 6, "V", 1 );
00354 #endif
00355 
00356                 // Restore default settings.
00357                 DRAW_SetDefaultColor();
00358                 DRAW_RestoreCharMagniCoeff();
00359             }
00360             else
00361             {
00362                 switch ( yCurSel )
00363                 {
00364                 case 1 :
00365                     UTIL_uint2str( buffer, temp_values[xCurSel], 2, 1 );
00366                     DRAW_DisplayString( TIME_MARGIN + xCurSel * ( PACK_SQUARE + 2 ), TIME_BOTTOM, buffer, 2 );
00367                     break;
00368 
00369                 case 0 :
00370                     DRAW_DisplayString( TIME_MARGIN + xCurSel * ( PACK_SQUARE + 2 ), TIME_BOTTOM - ( CharHeight + 2 ), "--", 2 );
00371                     break;
00372 
00373                 case 2 :
00374                     DRAW_DisplayString( TIME_MARGIN + xCurSel * ( PACK_SQUARE + 2 ), TIME_BOTTOM + ( CharHeight + 2 ), "++", 2 );
00375                     break;
00376                 }
00377             }
00378         }
00379 
00380         // Select new selection.
00381         if ( xsel == -1 )
00382         {
00383             // 'Cancel' button.
00384             DRAW_SetCharMagniCoeff( 2 );
00385             DRAW_DisplayStringInverted( TIME_MARGIN + ( -1 ) * ( PACK_SQUARE + 2 ), LCD_HIGH_DEF ? TIME_BOTTOM : TIME_BOTTOM - 6, "X", 1 );
00386             DRAW_RestoreCharMagniCoeff();
00387         }
00388         else if ( xsel == 3 )
00389         {
00390             // 'Validate' button.
00391             DRAW_SetCharMagniCoeff( 2 );
00392 #if LCD_HIGH_DEF
00393             DRAW_DisplayStringInverted( TIME_MARGIN + 3 * ( PACK_SQUARE + 2 ) + 10, TIME_BOTTOM, "V", 1 );
00394 #else
00395             DRAW_DisplayStringInverted( TIME_MARGIN + 3 * ( PACK_SQUARE + 2 ) - 30, TIME_BOTTOM - 6, "V", 1 );
00396 #endif
00397             DRAW_RestoreCharMagniCoeff();
00398         }
00399         else
00400         {
00401             switch ( ysel )
00402             {
00403                 // Time
00404             case 1 :
00405                 UTIL_uint2str( buffer, temp_values[xsel], 2, 1 );
00406                 DRAW_DisplayStringInverted( TIME_MARGIN + xsel * ( PACK_SQUARE + 2 ), TIME_BOTTOM, buffer, 2 );
00407                 break;
00408 
00409                 // --
00410             case 0 :
00411                 DRAW_DisplayStringInverted( TIME_MARGIN + xsel * ( PACK_SQUARE + 2 ), TIME_BOTTOM - ( CharHeight + 2 ), "--", 2 );
00412                 break;
00413 
00414                 // ++
00415             case 2 :
00416                 DRAW_DisplayStringInverted( TIME_MARGIN + xsel * ( PACK_SQUARE + 2 ), TIME_BOTTOM + ( CharHeight + 2 ), "++", 2 );
00417                 break;
00418             }
00419         }
00420 
00421         xCurSel = xsel;
00422         yCurSel = ysel;
00423     }
00424 
00425     FirstDisplay = 0;
00426 
00427     return MENU_CONTINUE;
00428 
00429 }
00430 
00431 
00432 /* Public functions for CircleOS ---------------------------------------------*/
00433 
00434 /*******************************************************************************
00435 *
00436 *                                fConfig
00437 *
00438 *******************************************************************************/
00445 /******************************************************************************/
00446 NODEBUG2 enum MENU_code fConfig( void )
00447 {
00448     MENU_Set( ( tMenu* )&ConfigMenu );
00449 
00450     return MENU_CHANGE;
00451 }
00452 
00453 
00455 
00456 /* Public functions ----------------------------------------------------------*/
00457 
00458 /*******************************************************************************
00459 *
00460 *                                MENU_SetLevel_Ini
00461 *
00462 *******************************************************************************/
00470 /******************************************************************************/
00471 enum MENU_code MENU_SetLevel_Ini( void )
00472 {
00473     FirstDisplay = 1;
00474 
00475     MENU_Remove();
00476     BUTTON_SetMode( BUTTON_ONOFF );
00477     POINTER_SetMode( POINTER_OFF );
00478     DRAW_Clear();
00479 
00480     return MENU_CONTINUE_COMMAND;
00481 }
00482 
00483 /*******************************************************************************
00484 *
00485 *                                MENU_SetLevelTitle
00486 *
00487 *******************************************************************************/
00495 /******************************************************************************/
00496 void MENU_SetLevelTitle( const u8* title )
00497 {
00498     SetLevel_Title = title;
00499 }
00500 
00501 /*******************************************************************************
00502 *
00503 *                                MENU_SetLevel_Mgr
00504 *
00505 *******************************************************************************/
00519 /********************************************************************************/
00520 enum MENU_code MENU_SetLevel_Mgr( uint_t* value, uint_t* value_range )
00521 {
00522     u8 sel;
00523     bool fRedrawn = 0;
00524 
00525     // Hide menu
00526     CurrentMenu = 0;
00527 
00528     // No character magnify.
00529     DRAW_RestoreCharMagniCoeff();
00530 
00531     // Disable Screen orientation
00532     LCD_SetRotateScreen( 0 );
00533 
00534     if ( FirstDisplay )
00535     {
00536         u8 i;
00537         u8 buffer[2] = {0};
00538 
00539         CurSel = 0;
00540         for ( i = 0 ; i < 5; i++ )
00541         {
00542             if ( *value == value_range[i] )
00543             {
00544                 CurSel = i;
00545                 break;
00546             }
00547         }
00548 
00549         POINTER_SetMode( POINTER_OFF );
00550         DRAW_DisplayStringWithMode( 0, BAR_BOTTOM + ( 3 * WIDTH_SQUARE ), SetLevel_Title, ALL_SCREEN, NORMAL_TEXT, CENTER );
00551         POINTER_SetPos( BAR_LEFT + ( WIDTH_SQUARE + 2 ) * CurSel + WIDTH_SQUARE / 2, BAR_BOTTOM );
00552         FirstDisplay = 0;
00553 
00554         for ( i = 0; i < MAXLEVEL; i++ )
00555         {
00556             *buffer = '0' + i;
00557 
00558             LCD_FillRect_Circle( BAR_LEFT + i * ( WIDTH_SQUARE + 2 ), BAR_BOTTOM, WIDTH_SQUARE, WIDTH_SQUARE, 0x0f0f );
00559 
00560             // Display value.
00561             DRAW_DisplayString( BAR_LEFT + i * ( WIDTH_SQUARE + 2 ) + WIDTH_SQUARE / 2 - ( Char_Width * DRAW_GetCharMagniCoeff() ) / 2,
00562                                 BAR_BOTTOM + WIDTH_SQUARE + WIDTH_SQUARE / 2,
00563                                 buffer,
00564                                 1 );
00565         }
00566 
00567         // Restrict the pointer moves to a rectangle.
00568         POINTER_SetRect( BAR_LEFT, BAR_BOTTOM, MAXLEVEL * ( WIDTH_SQUARE + 2 ) - POINTER_WIDTH, WIDTH_SQUARE - POINTER_WIDTH );
00569         POINTER_SetMode( POINTER_MENU );
00570 
00571         fRedrawn = 1;
00572     }
00573 
00574     // Change current selection
00575     sel = ( ( POINTER_GetPos() & 0xFF ) - BAR_LEFT ) / ( WIDTH_SQUARE + 2 );
00576 
00577     // The user pushed the button!
00578     if ( BUTTON_GetState() == BUTTON_PUSHED )
00579     {
00580         BUTTON_WaitForRelease();
00581 
00582         // The returned value is the selected one!
00583         *value = value_range[CurSel];
00584 
00585         // Reset CircleOS state.
00586         MENU_ClearCurrentCommand();
00587         DRAW_SetDefaultColor();
00588         DRAW_Clear();
00589         POINTER_SetMode( POINTER_ON );
00590         BUTTON_SetMode( BUTTON_ONOFF_FORMAIN );
00591         POINTER_SetRectScreen();
00592         DRAW_SetCharMagniCoeff( 1 );
00593         LCD_SetRotateScreen( 1 );
00594 
00595         return MENU_LEAVE;
00596     }
00597 
00598     if ( ( ( menu_divider_coord++ % 5 ) != 0 ) && !fRedrawn )
00599     {
00600         return MENU_CONTINUE;
00601     }
00602 
00603     // Redraw
00604     if ( ( sel != CurSel ) || fRedrawn )
00605     {
00606         // Clear previously selected value.
00607         if ( CurSel >= 0 )
00608         {
00609             LCD_FillRect_Circle( BAR_LEFT + CurSel * ( WIDTH_SQUARE + 2 ), BAR_BOTTOM, WIDTH_SQUARE, WIDTH_SQUARE, 0x0f0f );
00610         }
00611 
00612         // Draw newly selected value.
00613         LCD_FillRect_Circle( BAR_LEFT + sel * ( WIDTH_SQUARE + 2 ), BAR_BOTTOM, WIDTH_SQUARE, WIDTH_SQUARE, 0x0f0f + 2 );
00614 
00615         CurSel = sel;
00616 
00617         // If dynamic change,
00618         if ( fDynamicChange )
00619         {
00620             *value = value_range[CurSel];
00621         }
00622     }
00623 
00624     return MENU_CONTINUE;
00625 }