CircleOS  1
menu_settings.c
Go to the documentation of this file.
1 /****************** COPYRIGHT (C) 2007-2013 KEOLABS S.A.S. ********************/
12 /******************************************************************************/
13 
14 /* Includes ------------------------------------------------------------------*/
15 #include "circle.h"
16 
18 
19 /* Private define ------------------------------------------------------------*/
20 
21 /* Private macro -------------------------------------------------------------*/
22 #if LCD_HIGH_DEF
23 #define PACK_SQUARE (Char_Width * DRAW_GetCharMagniCoeff() * 3)
24 #else
25 #define PACK_SQUARE (Char_Width * DRAW_GetCharMagniCoeff() * 2)
26 #endif
27 
28 /* Private variables ---------------------------------------------------------*/
29 CONST_DATA u8 max_values[] = { 24, 60, 60 };
30 CONST_DATA u8* CONST_DATA Test_Melody = "Test:d=16,o=6,b=140:a,b,c,d,e,f,g";
31 CONST_DATA uint_t Speed_Range[5] =
33 
34 u8 temp_values[3]; // Holds the hour, minutes and seconds
35 index_t xCurSel;
36 index_t yCurSel;
37 bool FirstDisplay = 1;
38 char* SetLevel_Title;
39 bool fDynamicChange = 0;
40 divider_t menu_divider_coord = 0;
41 Rotate_H12_V_Match_TypeDef previous_Screen_Orientation;
42 
43 
44 /* Private function prototypes -----------------------------------------------*/
45 
46 /* External ------------------------------------------------------------------*/
47 #if BACKLIGHT_INTERFACE
48 extern uint_t Current_CCR_BackLightStart;
49 extern CONST_DATA int_t CCR_BackLight_Tab[5];
50 #endif // BACKLIGHT_INTERFACE
51 extern tMenu ConfigMenu;
52 
53 /*******************************************************************************
54 *
55 * fSetPllRange_Mgr
56 *
57 *******************************************************************************/
64 /******************************************************************************/
65 NODEBUG2 enum MENU_code fSetPllRange_Mgr( void )
66 {
67  enum MENU_code ret;
68  uint_t curspeed = CurrentSpeed; // Necessary because enums can have char type
69 
70  MENU_SetLevelTitle( " Freq Setting" );
71 
72  fDynamicChange = 0;
73  ret = MENU_SetLevel_Mgr( &curspeed, ( uint_t* )Speed_Range );
74  CurrentSpeed = curspeed;
76 
77  return ret;
78 }
79 
80 #if BACKLIGHT_INTERFACE
81 /*******************************************************************************
82 *
83 * fSetBacklight_Mgr
84 *
85 *******************************************************************************/
92 /******************************************************************************/
93 NODEBUG2 enum MENU_code fSetBacklight_Mgr( void )
94 {
95  enum MENU_code ret;
96 
97  MENU_SetLevelTitle( "Backlight Power" );
98 
99  fDynamicChange = 1;
100  ret = MENU_SetLevel_Mgr( &Current_CCR_BackLightStart, ( uint_t* ) CCR_BackLight_Tab ) ;
101 
102  return ret;
103 }
104 #endif // BACKLIGHT_INTERFACE
105 
106 
107 /*******************************************************************************
108 *
109 * fSetTime_Ini
110 *
111 *******************************************************************************/
118 /******************************************************************************/
119 NODEBUG enum MENU_code fSetTime_Ini( void )
120 {
121  u8 THH;
122  u8 TMM;
123  u8 TSS;
124 
125  // No more screen rotation allowed.
126  LCD_SetRotateScreen( 0 );
127 
128  // Get current time.
129  RTC_GetTime( &THH, &TMM, &TSS );
130 
131  // Store values into global variables for later use in fSetTime_Mgr.
132  temp_values[0] = THH;
133  temp_values[1] = TMM;
134  temp_values[2] = TSS;
135 
136  FirstDisplay = 1;
137 
140  MENU_Remove();
141 
142  xCurSel = -1;
143  yCurSel = -1;
144 
146 
147  return MENU_CONTINUE_COMMAND;
148 }
149 
150 /*******************************************************************************
151 *
152 * fSetTime_Mgr
153 *
154 *******************************************************************************/
162 /******************************************************************************/
163 NODEBUG2 enum MENU_code fSetTime_Mgr( void )
164 {
165  bool fRedrawn = 0;
166  u8 buffer[10];
167  u8 i;
168  coord_t Time_Title_H;
169  coord_t CharHeight, CharWidth;
170  coord_t pos;
171  coord_t ysel;
172  coord_t xsel;
173 
174  // Hide menu.
175  CurrentMenu = 0;
176 
177  // Character magnify deponding on the platform !
178  DRAW_RestoreCharMagniCoeff();
179 
180  CharHeight = Char_Height * DRAW_GetCharMagniCoeff();
181  CharWidth = Char_Width * DRAW_GetCharMagniCoeff();
182 
183 Restart:
184  if ( FirstDisplay )
185  {
186  previous_Screen_Orientation = LCD_GetScreenOrientation();
187 
188  if ( fRedrawn == 0 )
189  {
191  }
192 
193  Time_Title_H = CharHeight * 2;
194  LCD_FillRect_Circle( 0, Screen_Height - Time_Title_H, Screen_Width, Time_Title_H, RGB_BLACK );
195 
197  DRAW_SetTextColor( RGB_MAKE( 0, 183, 239 ) );
198  DRAW_DisplayStringWithMode( 0, Screen_Height - ( ( 3 * CharHeight ) / 2 ), "Time setting", ALL_SCREEN, NORMAL_TEXT, CENTER );
200 
201  // Display current time.
202  for ( i = 0 ; i < 3 ; i ++ )
203  {
204  UTIL_uint2str( buffer, temp_values[i], 2, 1 );
205 
206  DRAW_DisplayString( TIME_MARGIN + i * ( PACK_SQUARE + 2 ), TIME_BOTTOM, buffer, 2 );
207  DRAW_DisplayString( TIME_MARGIN + i * ( PACK_SQUARE + 2 ), TIME_BOTTOM + ( CharHeight + 2 ), "++", 2 );
208  DRAW_DisplayString( TIME_MARGIN + i * ( PACK_SQUARE + 2 ), TIME_BOTTOM - ( CharHeight + 2 ), "--", 2 );
209  }
210 
211  // Draw a big X for the 'cancel' button.
214  DRAW_DisplayString( TIME_MARGIN + ( -1 ) * ( PACK_SQUARE + 2 ) , LCD_HIGH_DEF ? TIME_BOTTOM : TIME_BOTTOM - 6, "X", 1 );
215 
216  // Draw a big V for the 'validate' button.
218 #if LCD_HIGH_DEF
219  DRAW_DisplayString( TIME_MARGIN + 3 * ( PACK_SQUARE + 2 ) + 10, TIME_BOTTOM, "V", 1 );
220 #else
221  DRAW_DisplayString( TIME_MARGIN + 3 * ( PACK_SQUARE + 2 ) - 30, TIME_BOTTOM - 6, "V", 1 );
222 #endif
223 
224  // Restore magnify coefficient.
225  DRAW_RestoreCharMagniCoeff();
227 
228  // Restrict the pointer moves to a rectangle.
229  POINTER_SetRect( TIME_MARGIN + ( -1 ) * ( PACK_SQUARE + 2 ), TIME_BOTTOM - ( CharHeight + 2 ),
230  5 * ( PACK_SQUARE + 2 ) - POINTER_WIDTH,
231  3 * ( CharHeight + 2 ) - POINTER_WIDTH );
232 
234  fRedrawn = 1;
235  }
236 
237  pos = POINTER_GetPos();
238  ysel = ( ( ( pos >> 8 ) & 0xFF ) - ( TIME_BOTTOM - ( CharHeight + 2 ) ) ) / ( CharHeight + 2 );
239  xsel = ( ( pos & 0xFF ) - ( TIME_MARGIN + 10 - ( CharWidth + 2 ) ) ) / ( CharWidth + 2 );
240 
241  // ysel value meanings:
242  // 0 : decrement line.
243  // 1 : X and V line.
244  // 2 : increment line.
245 
246  // xsel value meanings:
247  // -1: on the 'cancel' button.
248  // 0: hours
249  // 1: minutes
250  // 2: seconds
251  // 3: on the 'validate' button.
252 
253  // xsel can only be in the [-1 .. 3] range.
254  if ( xsel > 3 )
255  {
256  xsel = 3;
257  }
258 
259  if ( xsel < -1 )
260  {
261  xsel = -1;
262  }
263 
264  if ( ( xsel == -1 ) || ( xsel == 3 ) )
265  ysel = 1;
266 
267 
268  // The user pushed the button. Action will be different according to the
269  // cursor position (xsel).
270  if ( BUTTON_GetState() == BUTTON_PUSHED )
271  {
273 
274  switch ( xsel )
275  {
276  // Set time with modified values before leaving application.
277  case 3 :
278  RTC_SetTime( temp_values[0], temp_values[1], temp_values[2] );
279 
280  // Leave application restoring CircleOS state.
281  case -1 :
284  DRAW_Clear();
289  LCD_SetRotateScreen( 1 );
291  return MENU_LEAVE;
292 
293  // Increment or decrement according to ysel.
294  case 0 :
295  case 1 :
296  case 2 :
297  // Decrement
298  if ( ysel == 0 )
299  {
300  // If selected value is null roll over to max value.
301  if ( temp_values[xsel] == 0 )
302  {
303  temp_values[xsel] = max_values[xsel] - 1;
304  }
305  else
306  {
307  temp_values[xsel]--;
308  }
309  }
310  else if ( ysel == 2 ) // increment
311  {
312  temp_values[xsel]++;
313 
314  // Maximum value reached, restart at 0.
315  if ( temp_values[xsel] == max_values[xsel] )
316  {
317  temp_values[xsel] = 0;
318  }
319  }
320  break;
321  }
322 
323  // Something was changed, redraw screen!
324  FirstDisplay = 1;
325  fRedrawn = 1;
326 
327  goto Restart;
328  }
329 
330  // Cursor changed its position or a redraw is needed.
331  if ( ( xsel != xCurSel ) || ( ysel != yCurSel ) || fRedrawn )
332  {
333  if ( FirstDisplay == 0 )
334  {
335  // Unselect previously selected button.
336  if ( xCurSel == -1 )
337  {
338  // 'Cancel' button.
341  DRAW_DisplayString( TIME_MARGIN + ( -1 ) * ( PACK_SQUARE + 2 ), LCD_HIGH_DEF ? TIME_BOTTOM : TIME_BOTTOM - 6, "X", 1 );
342 
343  // Restore default settings.
345  DRAW_RestoreCharMagniCoeff();
346  }
347  else if ( xCurSel == 3 )
348  {
349  // 'Validate' button.
352 #if LCD_HIGH_DEF
353  DRAW_DisplayString( TIME_MARGIN + 3 * ( PACK_SQUARE + 2 ) + 10, TIME_BOTTOM, "V", 1 );
354 #else
355  DRAW_DisplayString( TIME_MARGIN + 3 * ( PACK_SQUARE + 2 ) - 30, TIME_BOTTOM - 6, "V", 1 );
356 #endif
357 
358  // Restore default settings.
360  DRAW_RestoreCharMagniCoeff();
361  }
362  else
363  {
364  switch ( yCurSel )
365  {
366  case 1 :
367  UTIL_uint2str( buffer, temp_values[xCurSel], 2, 1 );
368  DRAW_DisplayString( TIME_MARGIN + xCurSel * ( PACK_SQUARE + 2 ), TIME_BOTTOM, buffer, 2 );
369  break;
370 
371  case 0 :
372  DRAW_DisplayString( TIME_MARGIN + xCurSel * ( PACK_SQUARE + 2 ), TIME_BOTTOM - ( CharHeight + 2 ), "--", 2 );
373  break;
374 
375  case 2 :
376  DRAW_DisplayString( TIME_MARGIN + xCurSel * ( PACK_SQUARE + 2 ), TIME_BOTTOM + ( CharHeight + 2 ), "++", 2 );
377  break;
378  }
379  }
380  }
381 
382  // Select new selection.
383  if ( xsel == -1 )
384  {
385  // 'Cancel' button.
387  DRAW_DisplayStringInverted( TIME_MARGIN + ( -1 ) * ( PACK_SQUARE + 2 ), LCD_HIGH_DEF ? TIME_BOTTOM : TIME_BOTTOM - 6, "X", 1 );
388  DRAW_RestoreCharMagniCoeff();
389  }
390  else if ( xsel == 3 )
391  {
392  // 'Validate' button.
394 #if LCD_HIGH_DEF
395  DRAW_DisplayStringInverted( TIME_MARGIN + 3 * ( PACK_SQUARE + 2 ) + 10, TIME_BOTTOM, "V", 1 );
396 #else
397  DRAW_DisplayStringInverted( TIME_MARGIN + 3 * ( PACK_SQUARE + 2 ) - 30, TIME_BOTTOM - 6, "V", 1 );
398 #endif
399  DRAW_RestoreCharMagniCoeff();
400  }
401  else
402  {
403  switch ( ysel )
404  {
405  // Time
406  case 1 :
407  UTIL_uint2str( buffer, temp_values[xsel], 2, 1 );
408  DRAW_DisplayStringInverted( TIME_MARGIN + xsel * ( PACK_SQUARE + 2 ), TIME_BOTTOM, buffer, 2 );
409  break;
410 
411  // --
412  case 0 :
413  DRAW_DisplayStringInverted( TIME_MARGIN + xsel * ( PACK_SQUARE + 2 ), TIME_BOTTOM - ( CharHeight + 2 ), "--", 2 );
414  break;
415 
416  // ++
417  case 2 :
418  DRAW_DisplayStringInverted( TIME_MARGIN + xsel * ( PACK_SQUARE + 2 ), TIME_BOTTOM + ( CharHeight + 2 ), "++", 2 );
419  break;
420  }
421  }
422 
423  xCurSel = xsel;
424  yCurSel = ysel;
425  }
426 
427  FirstDisplay = 0;
428 
429  return MENU_CONTINUE;
430 
431 }
432 
433 
434 /* Public functions for CircleOS ---------------------------------------------*/
435 
436 /*******************************************************************************
437 *
438 * fConfig
439 *
440 *******************************************************************************/
447 /******************************************************************************/
448 NODEBUG2 enum MENU_code fConfig( void )
449 {
450  MENU_Set( ( tMenu* )&ConfigMenu );
451 
452  return MENU_CHANGE;
453 }
454 
455 
457 
458 /* Public functions ----------------------------------------------------------*/
459 
460 /*******************************************************************************
461 *
462 * MENU_SetLevel_Ini
463 *
464 *******************************************************************************/
472 /******************************************************************************/
474 {
475  FirstDisplay = 1;
476 
477  MENU_Remove();
480  DRAW_Clear();
482 
483  return MENU_CONTINUE_COMMAND;
484 }
485 
486 /*******************************************************************************
487 *
488 * MENU_SetLevelTitle
489 *
490 *******************************************************************************/
498 /******************************************************************************/
499 void MENU_SetLevelTitle( u8* title )
500 {
501  SetLevel_Title = title;
502 }
503 
504 /*******************************************************************************
505 *
506 * MENU_SetLevel_Mgr
507 *
508 *******************************************************************************/
522 /********************************************************************************/
523 enum MENU_code MENU_SetLevel_Mgr( uint_t* value, uint_t* value_range )
524 {
525  u8 sel;
526  bool fRedrawn = 0;
527 
528  // Hide menu
529  CurrentMenu = 0;
530 
531  // No character magnify.
532  DRAW_RestoreCharMagniCoeff();
533 
534  // Disable Screen orientation
535  LCD_SetRotateScreen( 0 );
536 
537  if ( FirstDisplay )
538  {
539  u8 i;
540  u8 buffer[2] = {0};
541 
542  CurSel = 0;
543  for ( i = 0 ; i < 5; i++ )
544  {
545  if ( *value == value_range[i] )
546  {
547  CurSel = i;
548  break;
549  }
550  }
551 
553  DRAW_DisplayStringWithMode( 0, BAR_BOTTOM + ( 3 * WIDTH_SQUARE ), SetLevel_Title, ALL_SCREEN, NORMAL_TEXT, CENTER );
554  POINTER_SetPos( BAR_LEFT + ( WIDTH_SQUARE + 2 ) * CurSel + WIDTH_SQUARE / 2, BAR_BOTTOM );
555  FirstDisplay = 0;
556 
557  for ( i = 0; i < MAXLEVEL; i++ )
558  {
559  *buffer = '0' + i;
560 
561  LCD_FillRect_Circle( BAR_LEFT + i * ( WIDTH_SQUARE + 2 ), BAR_BOTTOM, WIDTH_SQUARE, WIDTH_SQUARE, 0x0f0f );
562 
563  // Display value.
564  DRAW_DisplayString( BAR_LEFT + i * ( WIDTH_SQUARE + 2 ) + WIDTH_SQUARE / 2 - ( Char_Width * DRAW_GetCharMagniCoeff() ) / 2,
565  BAR_BOTTOM + WIDTH_SQUARE + WIDTH_SQUARE / 2,
566  buffer,
567  1 );
568  }
569 
570  // Restrict the pointer moves to a rectangle.
571  POINTER_SetRect( BAR_LEFT, BAR_BOTTOM, MAXLEVEL * ( WIDTH_SQUARE + 2 ) - POINTER_WIDTH, WIDTH_SQUARE - POINTER_WIDTH );
573 
574  fRedrawn = 1;
575  }
576 
577  // Change current selection
578  sel = ( ( POINTER_GetPos() & 0xFF ) - BAR_LEFT ) / ( WIDTH_SQUARE + 2 );
579 
580  // The user pushed the button!
581  if ( BUTTON_GetState() == BUTTON_PUSHED )
582  {
584 
585  // The returned value is the selected one!
586  *value = value_range[CurSel];
587 
588  // Reset CircleOS state.
591  DRAW_Clear();
596  LCD_SetRotateScreen( 1 );
597 
599 
600  return MENU_LEAVE;
601  }
602 
603  if ( ( ( menu_divider_coord++ % 5 ) != 0 ) && !fRedrawn )
604  {
605  return MENU_CONTINUE;
606  }
607 
608  // Redraw
609  if ( ( sel != CurSel ) || fRedrawn )
610  {
611  // Clear previously selected value.
612  if ( CurSel >= 0 )
613  {
614  LCD_FillRect_Circle( BAR_LEFT + CurSel * ( WIDTH_SQUARE + 2 ), BAR_BOTTOM, WIDTH_SQUARE, WIDTH_SQUARE, 0x0f0f );
615  }
616 
617  // Draw newly selected value.
618  LCD_FillRect_Circle( BAR_LEFT + sel * ( WIDTH_SQUARE + 2 ), BAR_BOTTOM, WIDTH_SQUARE, WIDTH_SQUARE, 0x0f0f + 2 );
619 
620  CurSel = sel;
621 
622  // If dynamic change,
623  if ( fDynamicChange )
624  {
625  *value = value_range[CurSel];
626  }
627  }
628 
629  return MENU_CONTINUE;
630 }