1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
8 * Copyright (C) 2005 Kevin Ferrare
10 * All files in this archive are subject to the GNU General Public License.
11 * See the file COPYING in the source tree root for full license agreement.
13 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
14 * KIND, either express or implied.
16 ****************************************************************************/
21 #ifdef HAVE_LCD_BITMAP /* and also not for the Player */
25 /******************************* Globals ***********************************/
27 static struct plugin_api
* rb
; /* global api struct pointer */
30 #if (CONFIG_KEYPAD == IPOD_4G_PAD) || \
31 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
32 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
33 #define STARFIELD_QUIT BUTTON_MENU
34 #define STARFIELD_INCREASE_ZMOVE BUTTON_SCROLL_FWD
35 #define STARFIELD_DECREASE_ZMOVE BUTTON_SCROLL_BACK
36 #define STARFIELD_INCREASE_NB_STARS BUTTON_RIGHT
37 #define STARFIELD_DECREASE_NB_STARS BUTTON_LEFT
38 #define STARFIELD_TOGGLE_COLOR BUTTON_PLAY
39 #elif (CONFIG_KEYPAD == IAUDIO_X5M5_PAD)
40 #define STARFIELD_QUIT BUTTON_POWER
41 #define STARFIELD_INCREASE_ZMOVE BUTTON_UP
42 #define STARFIELD_DECREASE_ZMOVE BUTTON_DOWN
43 #define STARFIELD_INCREASE_NB_STARS BUTTON_RIGHT
44 #define STARFIELD_DECREASE_NB_STARS BUTTON_LEFT
45 #define STARFIELD_TOGGLE_COLOR BUTTON_PLAY
46 #elif (CONFIG_KEYPAD == IRIVER_H10_PAD)
47 #define STARFIELD_QUIT BUTTON_POWER
48 #define STARFIELD_INCREASE_ZMOVE BUTTON_SCROLL_UP
49 #define STARFIELD_DECREASE_ZMOVE BUTTON_SCROLL_DOWN
50 #define STARFIELD_INCREASE_NB_STARS BUTTON_RIGHT
51 #define STARFIELD_DECREASE_NB_STARS BUTTON_LEFT
52 #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
60 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
61 (CONFIG_KEYPAD == SANSA_C200_PAD)
62 #define STARFIELD_QUIT BUTTON_POWER
63 #define STARFIELD_INCREASE_ZMOVE BUTTON_UP
64 #define STARFIELD_DECREASE_ZMOVE BUTTON_DOWN
65 #define STARFIELD_INCREASE_NB_STARS BUTTON_RIGHT
66 #define STARFIELD_DECREASE_NB_STARS BUTTON_LEFT
67 #define STARFIELD_TOGGLE_COLOR BUTTON_SELECT
70 #define STARFIELD_QUIT BUTTON_OFF
71 #define STARFIELD_INCREASE_ZMOVE BUTTON_UP
72 #define STARFIELD_DECREASE_ZMOVE BUTTON_DOWN
73 #define STARFIELD_INCREASE_NB_STARS BUTTON_RIGHT
74 #define STARFIELD_DECREASE_NB_STARS BUTTON_LEFT
76 #define STARFIELD_TOGGLE_COLOR BUTTON_SELECT
78 #define STARFIELD_TOGGLE_COLOR BUTTON_PLAY
80 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD)
81 #define STARFIELD_RC_QUIT BUTTON_RC_STOP
86 #define LCD_CENTER_X (LCD_WIDTH/2)
87 #define LCD_CENTER_Y (LCD_HEIGHT/2)
88 #define Z_MAX_DIST 100
91 #define MAX_STARS (LCD_WIDTH*LCD_HEIGHT*20)/100
92 #define INIT_STARS 200
93 #define STARFIELD_INCREASE_STEP 50
94 #define INIT_SPACE_SPEED 1
95 #define STAR_MAX_VELOCITY 2
97 * max 3d coord in the 2d screen :
99 * x2d=x3d/z+LCD_CENTER_X (+LCD_CENTER_X to center ...)
101 * max_x2d=max_x3d/max_z+LCD_CENTER_X
102 * max_x3d=(max_x2d-LCD_CENTER_X)*max_z
104 * max_x2d = LCD_WIDTH
107 * max_x3d=(LCD_WIDTH-LCD_CENTER_X)*Z_MAX_DIST
108 * max_x3d=LCD_CENTER_X*Z_MAX_DIST
111 #define MAX_INIT_STAR_X LCD_CENTER_X*Z_MAX_DIST
112 #define MAX_INIT_STAR_Y LCD_CENTER_Y*Z_MAX_DIST
114 #define MSG_DISP_TIME 30
116 static struct plugin_api
* rb
; /* global api struct pointer */
125 #ifdef HAVE_LCD_COLOR
130 static inline void star_init(struct star
* star
, int z_move
, bool color
)
132 star
->velocity
=rb
->rand() % STAR_MAX_VELOCITY
+1;
133 /* choose x between -MAX_INIT_STAR_X and MAX_INIT_STAR_X */
134 star
->x
=rb
->rand() % (2*MAX_INIT_STAR_X
)-MAX_INIT_STAR_X
;
135 star
->y
=rb
->rand() % (2*MAX_INIT_STAR_Y
)-MAX_INIT_STAR_Y
;
136 #ifdef HAVE_LCD_COLOR
138 star
->color
=LCD_RGBPACK(rb
->rand()%128+128,rb
->rand()%128+128,
141 star
->color
=LCD_WHITE
;
148 star
->z
=rb
->rand() %Z_MAX_DIST
/2+1;
151 static inline void star_move(struct star
* star
, int z_move
, bool color
)
153 star
->z
-= z_move
*star
->velocity
;
154 if (star
->z
<= 0 || star
->z
> Z_MAX_DIST
)
155 star_init(star
, z_move
, color
);
158 static inline void star_draw(struct star
* star
, int z_move
, bool color
)
162 * 3d -> 2d : projection on the screen : x2d=x3d/z (thales theorem)
163 * we put the star in the center of the screen
165 x_draw
= star
->x
/ star
->z
+ LCD_CENTER_X
;
166 if (x_draw
< 1 || x_draw
>= LCD_WIDTH
)
168 star_init(star
, z_move
, color
);
171 y_draw
= star
->y
/ star
->z
+ LCD_CENTER_Y
;
172 if (y_draw
< 1 || y_draw
>= LCD_HEIGHT
)
174 star_init(star
, z_move
, color
);
178 #ifdef HAVE_LCD_COLOR
179 rb
->lcd_set_foreground(star
->color
);
182 rb
->lcd_drawpixel(x_draw
, y_draw
);
183 if(star
->z
<5*Z_MAX_DIST
/6)
185 rb
->lcd_drawpixel(x_draw
, y_draw
- 1);
186 rb
->lcd_drawpixel(x_draw
- 1, y_draw
);
187 if(star
->z
<Z_MAX_DIST
/2)
189 rb
->lcd_drawpixel(x_draw
+ 1, y_draw
);
190 rb
->lcd_drawpixel(x_draw
, y_draw
+ 1);
196 * Whole starfield operations
200 struct star tab
[MAX_STARS
];
206 static inline void starfield_init(struct starfield
* starfield
)
208 starfield
->nb_stars
=0;
209 starfield
->z_move
=INIT_SPACE_SPEED
;
210 starfield
->color
=false;
213 static inline void starfield_add_stars(struct starfield
* starfield
,
217 old_nb_stars
=starfield
->nb_stars
;
218 starfield
->nb_stars
+=nb_to_add
;
220 if(starfield
->nb_stars
> MAX_STARS
)
221 starfield
->nb_stars
=MAX_STARS
;
223 for( i
=old_nb_stars
; i
< starfield
->nb_stars
; ++i
)
225 star_init( &(starfield
->tab
[i
]), starfield
->z_move
, starfield
->color
);
229 static inline void starfield_del_stars(struct starfield
* starfield
,
232 starfield
->nb_stars
-=nb_to_add
;
233 if(starfield
->nb_stars
<0)
234 starfield
->nb_stars
=0;
237 static inline void starfield_move_and_draw(struct starfield
* starfield
)
240 for(i
=0;i
<starfield
->nb_stars
;++i
)
242 star_move(&(starfield
->tab
[i
]), starfield
->z_move
, starfield
->color
);
243 star_draw(&(starfield
->tab
[i
]), starfield
->z_move
, starfield
->color
);
247 static struct starfield starfield
;
249 int plugin_main(void)
252 int button
, avg_peak
, t_disp
=0;
255 rb
->lcd_getstringsize("A", &font_w
, &font_h
);
256 starfield_init(&starfield
);
257 starfield_add_stars(&starfield
, INIT_STARS
);
260 rb
->lcd_set_backdrop(NULL
);
262 #ifdef HAVE_LCD_COLOR
263 rb
->lcd_set_background(LCD_BLACK
);
264 rb
->lcd_set_foreground(LCD_WHITE
);
270 rb
->lcd_clear_display();
272 #if ((CONFIG_CODEC == SWCODEC) || !defined(SIMULATOR) && \
273 ((CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)))
275 /* This will make the stars pulse to the music */
278 /* Get the peaks. ( Borrowed from vu_meter ) */
279 #if (CONFIG_CODEC == SWCODEC)
280 int left_peak
, right_peak
;
281 rb
->pcm_calculate_peaks(&left_peak
, &right_peak
);
283 int left_peak
= rb
->mas_codec_readreg(0xC);
284 int right_peak
= rb
->mas_codec_readreg(0xD);
286 /* Devide peak data by 4098 to bring the max
287 value down from ~32k to 8 */
288 left_peak
= left_peak
/0x1000;
289 right_peak
= right_peak
/0x1000;
291 /* Make sure they dont stop */
297 /* And make sure they dont go over 8 */
303 /* We need the average of both chanels */
304 avg_peak
= ( left_peak
+ right_peak
)/2;
306 /* Set the speed to the peak meter */
307 starfield
.z_move
= avg_peak
;
313 starfield_move_and_draw(&starfield
);
315 #ifdef HAVE_LCD_COLOR
316 rb
->lcd_set_foreground(LCD_WHITE
);
319 /* if a parameter is updated (by the user), we must print it */
323 rb
->snprintf(str_buffer
, sizeof(str_buffer
),
328 rb
->lcd_set_foreground(LCD_WHITE
);
330 rb
->lcd_putsxy(0, LCD_HEIGHT
-font_h
, str_buffer
);
334 button
= rb
->button_get(false);
337 case (STARFIELD_INCREASE_ZMOVE
):
338 case (STARFIELD_INCREASE_ZMOVE
| BUTTON_REPEAT
):
339 ++(starfield
.z_move
);
341 t_disp
=MSG_DISP_TIME
;
343 case (STARFIELD_DECREASE_ZMOVE
):
344 case (STARFIELD_DECREASE_ZMOVE
| BUTTON_REPEAT
):
345 --(starfield
.z_move
);
347 t_disp
=MSG_DISP_TIME
;
349 case(STARFIELD_INCREASE_NB_STARS
):
350 case(STARFIELD_INCREASE_NB_STARS
| BUTTON_REPEAT
):
351 starfield_add_stars(&starfield
, STARFIELD_INCREASE_STEP
);
352 t_disp
=MSG_DISP_TIME
;
354 case(STARFIELD_DECREASE_NB_STARS
):
355 case(STARFIELD_DECREASE_NB_STARS
| BUTTON_REPEAT
):
356 starfield_del_stars(&starfield
, STARFIELD_INCREASE_STEP
);
357 t_disp
=MSG_DISP_TIME
;
359 #ifdef HAVE_LCD_COLOR
360 case(STARFIELD_TOGGLE_COLOR
):
361 starfield
.color
=!starfield
.color
;
364 #ifdef STARFIELD_RC_QUIT
365 case STARFIELD_RC_QUIT
:
367 case(STARFIELD_QUIT
):
368 case(SYS_USB_CONNECTED
):
369 /* Turn on backlight timeout (revert to settings) */
370 backlight_use_settings(rb
); /* backlight control in lib/helper.c*/
377 /*************************** Plugin entry point ****************************/
379 enum plugin_status
plugin_start(struct plugin_api
* api
, void* parameter
)
383 rb
= api
; /* copy to global api pointer */
385 /* Turn off backlight timeout */
386 backlight_force_on(rb
); /* backlight control in lib/helper.c */
393 #endif /* #ifdef HAVE_LCD_BITMAP */