1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
8 * Copyright (C) 2005 Kevin Ferrare
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
21 #include "lib/helper.h"
22 #include "lib/pluginlib_exit.h"
24 /******************************* Globals ***********************************/
27 #if (CONFIG_KEYPAD == IPOD_4G_PAD) || \
28 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
29 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
30 #define STARFIELD_QUIT BUTTON_MENU
31 #define STARFIELD_INCREASE_ZMOVE BUTTON_SCROLL_FWD
32 #define STARFIELD_DECREASE_ZMOVE BUTTON_SCROLL_BACK
33 #define STARFIELD_INCREASE_NB_STARS BUTTON_RIGHT
34 #define STARFIELD_DECREASE_NB_STARS BUTTON_LEFT
35 #define STARFIELD_TOGGLE_COLOR BUTTON_PLAY
37 #elif (CONFIG_KEYPAD == IAUDIO_X5M5_PAD)
38 #define STARFIELD_QUIT BUTTON_POWER
39 #define STARFIELD_INCREASE_ZMOVE BUTTON_UP
40 #define STARFIELD_DECREASE_ZMOVE BUTTON_DOWN
41 #define STARFIELD_INCREASE_NB_STARS BUTTON_RIGHT
42 #define STARFIELD_DECREASE_NB_STARS BUTTON_LEFT
43 #define STARFIELD_TOGGLE_COLOR BUTTON_PLAY
45 #elif (CONFIG_KEYPAD == IRIVER_H10_PAD)
46 #define STARFIELD_QUIT BUTTON_POWER
47 #define STARFIELD_INCREASE_ZMOVE BUTTON_SCROLL_UP
48 #define STARFIELD_DECREASE_ZMOVE BUTTON_SCROLL_DOWN
49 #define STARFIELD_INCREASE_NB_STARS BUTTON_RIGHT
50 #define STARFIELD_DECREASE_NB_STARS BUTTON_LEFT
51 #define STARFIELD_TOGGLE_COLOR BUTTON_PLAY
53 #elif (CONFIG_KEYPAD == GIGABEAT_PAD)
54 #define STARFIELD_QUIT BUTTON_POWER
55 #define STARFIELD_INCREASE_ZMOVE BUTTON_UP
56 #define STARFIELD_DECREASE_ZMOVE BUTTON_DOWN
57 #define STARFIELD_INCREASE_NB_STARS BUTTON_RIGHT
58 #define STARFIELD_DECREASE_NB_STARS BUTTON_LEFT
59 #define STARFIELD_TOGGLE_COLOR BUTTON_SELECT
61 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
62 (CONFIG_KEYPAD == SANSA_C200_PAD) || \
63 (CONFIG_KEYPAD == SANSA_CLIP_PAD) || \
64 (CONFIG_KEYPAD == SANSA_M200_PAD)
65 #define STARFIELD_QUIT BUTTON_POWER
66 #define STARFIELD_INCREASE_ZMOVE BUTTON_UP
67 #define STARFIELD_DECREASE_ZMOVE BUTTON_DOWN
68 #define STARFIELD_INCREASE_NB_STARS BUTTON_RIGHT
69 #define STARFIELD_DECREASE_NB_STARS BUTTON_LEFT
70 #define STARFIELD_TOGGLE_COLOR BUTTON_SELECT
72 #elif (CONFIG_KEYPAD == SANSA_FUZE_PAD)
73 #define STARFIELD_QUIT (BUTTON_HOME|BUTTON_REPEAT)
74 #define STARFIELD_INCREASE_ZMOVE BUTTON_UP
75 #define STARFIELD_DECREASE_ZMOVE BUTTON_DOWN
76 #define STARFIELD_INCREASE_NB_STARS BUTTON_RIGHT
77 #define STARFIELD_DECREASE_NB_STARS BUTTON_LEFT
78 #define STARFIELD_TOGGLE_COLOR BUTTON_SELECT
80 #elif (CONFIG_KEYPAD == GIGABEAT_S_PAD)
81 #define STARFIELD_QUIT BUTTON_BACK
82 #define STARFIELD_INCREASE_ZMOVE BUTTON_UP
83 #define STARFIELD_DECREASE_ZMOVE BUTTON_DOWN
84 #define STARFIELD_INCREASE_NB_STARS BUTTON_RIGHT
85 #define STARFIELD_DECREASE_NB_STARS BUTTON_LEFT
86 #define STARFIELD_TOGGLE_COLOR BUTTON_SELECT
88 #elif (CONFIG_KEYPAD == MROBE100_PAD)
89 #define STARFIELD_QUIT BUTTON_POWER
90 #define STARFIELD_INCREASE_ZMOVE BUTTON_UP
91 #define STARFIELD_DECREASE_ZMOVE BUTTON_DOWN
92 #define STARFIELD_INCREASE_NB_STARS BUTTON_RIGHT
93 #define STARFIELD_DECREASE_NB_STARS BUTTON_LEFT
94 #define STARFIELD_TOGGLE_COLOR BUTTON_SELECT
96 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
97 #define STARFIELD_QUIT BUTTON_RC_REC
98 #define STARFIELD_INCREASE_ZMOVE BUTTON_RC_VOL_UP
99 #define STARFIELD_DECREASE_ZMOVE BUTTON_RC_VOL_DOWN
100 #define STARFIELD_INCREASE_NB_STARS BUTTON_RC_FF
101 #define STARFIELD_DECREASE_NB_STARS BUTTON_RC_REW
102 #define STARFIELD_TOGGLE_COLOR BUTTON_RC_MODE
104 #elif CONFIG_KEYPAD == IAUDIO67_PAD
105 #define STARFIELD_QUIT BUTTON_POWER
106 #define STARFIELD_INCREASE_ZMOVE BUTTON_STOP
107 #define STARFIELD_DECREASE_ZMOVE BUTTON_PLAY
108 #define STARFIELD_INCREASE_NB_STARS BUTTON_LEFT
109 #define STARFIELD_DECREASE_NB_STARS BUTTON_RIGHT
110 #define STARFIELD_TOGGLE_COLOR BUTTON_MENU
112 #elif (CONFIG_KEYPAD == COWON_D2_PAD)
113 #define STARFIELD_QUIT BUTTON_POWER
115 #elif CONFIG_KEYPAD == CREATIVEZVM_PAD
116 #define STARFIELD_QUIT BUTTON_BACK
117 #define STARFIELD_INCREASE_ZMOVE BUTTON_UP
118 #define STARFIELD_DECREASE_ZMOVE BUTTON_DOWN
119 #define STARFIELD_INCREASE_NB_STARS BUTTON_RIGHT
120 #define STARFIELD_DECREASE_NB_STARS BUTTON_LEFT
121 #define STARFIELD_TOGGLE_COLOR BUTTON_SELECT
123 #elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
124 #define STARFIELD_QUIT BUTTON_POWER
125 #define STARFIELD_INCREASE_ZMOVE BUTTON_UP
126 #define STARFIELD_DECREASE_ZMOVE BUTTON_DOWN
127 #define STARFIELD_INCREASE_NB_STARS BUTTON_RIGHT
128 #define STARFIELD_DECREASE_NB_STARS BUTTON_LEFT
129 #define STARFIELD_TOGGLE_COLOR BUTTON_SELECT
131 #elif CONFIG_KEYPAD == PHILIPS_HDD6330_PAD
132 #define STARFIELD_QUIT BUTTON_POWER
133 #define STARFIELD_INCREASE_ZMOVE BUTTON_UP
134 #define STARFIELD_DECREASE_ZMOVE BUTTON_DOWN
135 #define STARFIELD_INCREASE_NB_STARS BUTTON_RIGHT
136 #define STARFIELD_DECREASE_NB_STARS BUTTON_LEFT
137 #define STARFIELD_TOGGLE_COLOR BUTTON_PLAY
139 #elif CONFIG_KEYPAD == PHILIPS_SA9200_PAD
140 #define STARFIELD_QUIT BUTTON_POWER
141 #define STARFIELD_INCREASE_ZMOVE BUTTON_UP
142 #define STARFIELD_DECREASE_ZMOVE BUTTON_DOWN
143 #define STARFIELD_INCREASE_NB_STARS BUTTON_NEXT
144 #define STARFIELD_DECREASE_NB_STARS BUTTON_PREV
145 #define STARFIELD_TOGGLE_COLOR BUTTON_PLAY
147 #elif (CONFIG_KEYPAD == ONDAVX747_PAD) || (CONFIG_KEYPAD == ONDAVX777_PAD) || (CONFIG_KEYPAD == MROBE500_PAD)
148 #define STARFIELD_QUIT BUTTON_POWER
150 #elif CONFIG_KEYPAD == SAMSUNG_YH_PAD
151 #define STARFIELD_QUIT BUTTON_FFWD
152 #define STARFIELD_INCREASE_ZMOVE BUTTON_UP
153 #define STARFIELD_DECREASE_ZMOVE BUTTON_DOWN
154 #define STARFIELD_INCREASE_NB_STARS BUTTON_RIGHT
155 #define STARFIELD_DECREASE_NB_STARS BUTTON_LEFT
156 #define STARFIELD_TOGGLE_COLOR BUTTON_PLAY
158 #elif CONFIG_KEYPAD == PBELL_VIBE500_PAD
159 #define STARFIELD_QUIT BUTTON_REC
160 #define STARFIELD_INCREASE_ZMOVE BUTTON_UP
161 #define STARFIELD_DECREASE_ZMOVE BUTTON_DOWN
162 #define STARFIELD_INCREASE_NB_STARS BUTTON_NEXT
163 #define STARFIELD_DECREASE_NB_STARS BUTTON_PREV
164 #define STARFIELD_TOGGLE_COLOR BUTTON_PLAY
166 #elif CONFIG_KEYPAD == MPIO_HD200_PAD
167 #define STARFIELD_QUIT (BUTTON_REC|BUTTON_PLAY)
168 #define STARFIELD_INCREASE_ZMOVE BUTTON_VOL_UP
169 #define STARFIELD_DECREASE_ZMOVE BUTTON_VOL_DOWN
170 #define STARFIELD_INCREASE_NB_STARS BUTTON_FF
171 #define STARFIELD_DECREASE_NB_STARS BUTTON_REW
172 #define STARFIELD_TOGGLE_COLOR BUTTON_PLAY
174 #elif CONFIG_KEYPAD == MPIO_HD300_PAD
175 #define STARFIELD_QUIT (BUTTON_REC|BUTTON_REPEAT)
176 #define STARFIELD_INCREASE_ZMOVE BUTTON_UP
177 #define STARFIELD_DECREASE_ZMOVE BUTTON_DOWN
178 #define STARFIELD_INCREASE_NB_STARS BUTTON_FF
179 #define STARFIELD_DECREASE_NB_STARS BUTTON_REW
180 #define STARFIELD_TOGGLE_COLOR BUTTON_PLAY
184 #ifdef HAVE_TOUCHSCREEN
185 #ifndef STARFIELD_QUIT
186 #define STARFIELD_QUIT BUTTON_TOPLEFT
188 #ifndef STARFIELD_INCREASE_ZMOVE
189 #define STARFIELD_INCREASE_ZMOVE BUTTON_TOPMIDDLE
191 #ifndef STARFIELD_DECREASE_ZMOVE
192 #define STARFIELD_DECREASE_ZMOVE BUTTON_BOTTOMMIDDLE
194 #ifndef STARFIELD_INCREASE_NB_STARS
195 #define STARFIELD_INCREASE_NB_STARS BUTTON_MIDRIGHT
197 #ifndef STARFIELD_DECREASE_NB_STARS
198 #define STARFIELD_DECREASE_NB_STARS BUTTON_MIDLEFT
200 #ifndef STARFIELD_TOGGLE_COLOR
201 #define STARFIELD_TOGGLE_COLOR BUTTON_CENTER
205 #ifndef STARFIELD_QUIT
206 #define STARFIELD_QUIT BUTTON_OFF
208 #ifndef STARFIELD_INCREASE_ZMOVE
209 #define STARFIELD_INCREASE_ZMOVE BUTTON_UP
211 #ifndef STARFIELD_DECREASE_ZMOVE
212 #define STARFIELD_DECREASE_ZMOVE BUTTON_DOWN
214 #ifndef STARFIELD_INCREASE_NB_STARS
215 #define STARFIELD_INCREASE_NB_STARS BUTTON_RIGHT
217 #ifndef STARFIELD_DECREASE_NB_STARS
218 #define STARFIELD_DECREASE_NB_STARS BUTTON_LEFT
221 #ifndef STARFIELD_TOGGLE_COLOR
223 #define STARFIELD_TOGGLE_COLOR BUTTON_SELECT
225 #define STARFIELD_TOGGLE_COLOR BUTTON_PLAY
228 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD)
229 #define STARFIELD_RC_QUIT BUTTON_RC_STOP
233 #define LCD_CENTER_X (LCD_WIDTH/2)
234 #define LCD_CENTER_Y (LCD_HEIGHT/2)
235 #define Z_MAX_DIST 100
238 #define MAX_STARS (LCD_WIDTH*LCD_HEIGHT*20)/100
239 #define INIT_STARS 200
240 #define STARFIELD_INCREASE_STEP 50
241 #define INIT_SPACE_SPEED 1
242 #define STAR_MAX_VELOCITY 2
244 * max 3d coord in the 2d screen :
246 * x2d=x3d/z+LCD_CENTER_X (+LCD_CENTER_X to center ...)
248 * max_x2d=max_x3d/max_z+LCD_CENTER_X
249 * max_x3d=(max_x2d-LCD_CENTER_X)*max_z
251 * max_x2d = LCD_WIDTH
254 * max_x3d=(LCD_WIDTH-LCD_CENTER_X)*Z_MAX_DIST
255 * max_x3d=LCD_CENTER_X*Z_MAX_DIST
258 #define MAX_INIT_STAR_X LCD_CENTER_X*Z_MAX_DIST
259 #define MAX_INIT_STAR_Y LCD_CENTER_Y*Z_MAX_DIST
261 #define MSG_DISP_TIME 30
270 #ifdef HAVE_LCD_COLOR
275 static inline void star_init(struct star
* star
, int z_move
, bool color
)
277 star
->velocity
=rb
->rand() % STAR_MAX_VELOCITY
+1;
278 /* choose x between -MAX_INIT_STAR_X and MAX_INIT_STAR_X */
279 star
->x
=rb
->rand() % (2*MAX_INIT_STAR_X
)-MAX_INIT_STAR_X
;
280 star
->y
=rb
->rand() % (2*MAX_INIT_STAR_Y
)-MAX_INIT_STAR_Y
;
281 #ifdef HAVE_LCD_COLOR
283 star
->color
=LCD_RGBPACK(rb
->rand()%128+128,rb
->rand()%128+128,
286 star
->color
=LCD_WHITE
;
293 star
->z
=rb
->rand() %Z_MAX_DIST
/2+1;
296 static inline void star_move(struct star
* star
, int z_move
, bool color
)
298 star
->z
-= z_move
*star
->velocity
;
299 if (star
->z
<= 0 || star
->z
> Z_MAX_DIST
)
300 star_init(star
, z_move
, color
);
303 static inline void star_draw(struct star
* star
, int z_move
, bool color
)
307 * 3d -> 2d : projection on the screen : x2d=x3d/z (thales theorem)
308 * we put the star in the center of the screen
310 x_draw
= star
->x
/ star
->z
+ LCD_CENTER_X
;
311 if (x_draw
< 1 || x_draw
>= LCD_WIDTH
)
313 star_init(star
, z_move
, color
);
316 y_draw
= star
->y
/ star
->z
+ LCD_CENTER_Y
;
317 if (y_draw
< 1 || y_draw
>= LCD_HEIGHT
)
319 star_init(star
, z_move
, color
);
323 #ifdef HAVE_LCD_COLOR
324 rb
->lcd_set_foreground(star
->color
);
327 rb
->lcd_drawpixel(x_draw
, y_draw
);
328 if(star
->z
<5*Z_MAX_DIST
/6)
330 rb
->lcd_drawpixel(x_draw
, y_draw
- 1);
331 rb
->lcd_drawpixel(x_draw
- 1, y_draw
);
332 if(star
->z
<Z_MAX_DIST
/2)
334 rb
->lcd_drawpixel(x_draw
+ 1, y_draw
);
335 rb
->lcd_drawpixel(x_draw
, y_draw
+ 1);
341 * Whole starfield operations
345 struct star tab
[MAX_STARS
];
351 static inline void starfield_init(struct starfield
* starfield
)
353 starfield
->nb_stars
=0;
354 starfield
->z_move
=INIT_SPACE_SPEED
;
355 starfield
->color
=false;
358 static inline void starfield_add_stars(struct starfield
* starfield
,
362 old_nb_stars
=starfield
->nb_stars
;
363 starfield
->nb_stars
+=nb_to_add
;
365 if(starfield
->nb_stars
> MAX_STARS
)
366 starfield
->nb_stars
=MAX_STARS
;
368 for( i
=old_nb_stars
; i
< starfield
->nb_stars
; ++i
)
370 star_init( &(starfield
->tab
[i
]), starfield
->z_move
, starfield
->color
);
374 static inline void starfield_del_stars(struct starfield
* starfield
,
377 starfield
->nb_stars
-=nb_to_add
;
378 if(starfield
->nb_stars
<0)
379 starfield
->nb_stars
=0;
382 static inline void starfield_move_and_draw(struct starfield
* starfield
)
385 for(i
=0;i
<starfield
->nb_stars
;++i
)
387 star_move(&(starfield
->tab
[i
]), starfield
->z_move
, starfield
->color
);
388 star_draw(&(starfield
->tab
[i
]), starfield
->z_move
, starfield
->color
);
392 static struct starfield starfield
;
394 int plugin_main(void)
396 int button
, avg_peak
, t_disp
=0;
399 rb
->lcd_getstringsize("A", &font_w
, &font_h
);
400 starfield_init(&starfield
);
401 starfield_add_stars(&starfield
, INIT_STARS
);
404 rb
->lcd_set_backdrop(NULL
);
406 #ifdef HAVE_LCD_COLOR
407 rb
->lcd_set_background(LCD_BLACK
);
408 rb
->lcd_set_foreground(LCD_WHITE
);
414 rb
->lcd_clear_display();
416 #if ((CONFIG_CODEC == SWCODEC) || !defined(SIMULATOR) && \
417 ((CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)))
419 /* This will make the stars pulse to the music */
422 /* Get the peaks. ( Borrowed from vu_meter ) */
423 #if (CONFIG_CODEC == SWCODEC)
424 int left_peak
, right_peak
;
425 rb
->pcm_calculate_peaks(&left_peak
, &right_peak
);
427 int left_peak
= rb
->mas_codec_readreg(0xC);
428 int right_peak
= rb
->mas_codec_readreg(0xD);
430 /* Devide peak data by 4098 to bring the max
431 value down from ~32k to 8 */
432 left_peak
= left_peak
/0x1000;
433 right_peak
= right_peak
/0x1000;
435 /* Make sure they dont stop */
441 /* And make sure they dont go over 8 */
447 /* We need the average of both chanels */
448 avg_peak
= ( left_peak
+ right_peak
)/2;
450 /* Set the speed to the peak meter */
451 starfield
.z_move
= avg_peak
;
457 starfield_move_and_draw(&starfield
);
459 #ifdef HAVE_LCD_COLOR
460 rb
->lcd_set_foreground(LCD_WHITE
);
463 /* if a parameter is updated (by the user), we must print it */
467 #ifdef HAVE_LCD_COLOR
468 rb
->lcd_set_foreground(LCD_WHITE
);
470 rb
->lcd_putsxyf(0, LCD_HEIGHT
-font_h
, "star:%d speed:%d",
471 starfield
.nb_stars
, starfield
.z_move
);
475 button
= rb
->button_get(false);
478 case (STARFIELD_INCREASE_ZMOVE
):
479 case (STARFIELD_INCREASE_ZMOVE
| BUTTON_REPEAT
):
480 ++(starfield
.z_move
);
482 t_disp
=MSG_DISP_TIME
;
484 case (STARFIELD_DECREASE_ZMOVE
):
485 case (STARFIELD_DECREASE_ZMOVE
| BUTTON_REPEAT
):
486 --(starfield
.z_move
);
488 t_disp
=MSG_DISP_TIME
;
490 case(STARFIELD_INCREASE_NB_STARS
):
491 case(STARFIELD_INCREASE_NB_STARS
| BUTTON_REPEAT
):
492 starfield_add_stars(&starfield
, STARFIELD_INCREASE_STEP
);
493 t_disp
=MSG_DISP_TIME
;
495 case(STARFIELD_DECREASE_NB_STARS
):
496 case(STARFIELD_DECREASE_NB_STARS
| BUTTON_REPEAT
):
497 starfield_del_stars(&starfield
, STARFIELD_INCREASE_STEP
);
498 t_disp
=MSG_DISP_TIME
;
500 #ifdef HAVE_LCD_COLOR
501 case(STARFIELD_TOGGLE_COLOR
):
502 starfield
.color
=!starfield
.color
;
505 #ifdef STARFIELD_RC_QUIT
506 case STARFIELD_RC_QUIT
:
508 case(STARFIELD_QUIT
):
518 /*************************** Plugin entry point ****************************/
520 enum plugin_status
plugin_start(const void* parameter
)
525 /* Turn off backlight timeout */
526 backlight_ignore_timeout();
530 /* Turn on backlight timeout (revert to settings) */
531 backlight_use_settings();