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"
23 #ifdef HAVE_LCD_BITMAP /* and also not for the Player */
27 /******************************* Globals ***********************************/
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
40 #elif (CONFIG_KEYPAD == IAUDIO_X5M5_PAD)
41 #define STARFIELD_QUIT BUTTON_POWER
42 #define STARFIELD_INCREASE_ZMOVE BUTTON_UP
43 #define STARFIELD_DECREASE_ZMOVE BUTTON_DOWN
44 #define STARFIELD_INCREASE_NB_STARS BUTTON_RIGHT
45 #define STARFIELD_DECREASE_NB_STARS BUTTON_LEFT
46 #define STARFIELD_TOGGLE_COLOR BUTTON_PLAY
48 #elif (CONFIG_KEYPAD == IRIVER_H10_PAD)
49 #define STARFIELD_QUIT BUTTON_POWER
50 #define STARFIELD_INCREASE_ZMOVE BUTTON_SCROLL_UP
51 #define STARFIELD_DECREASE_ZMOVE BUTTON_SCROLL_DOWN
52 #define STARFIELD_INCREASE_NB_STARS BUTTON_RIGHT
53 #define STARFIELD_DECREASE_NB_STARS BUTTON_LEFT
54 #define STARFIELD_TOGGLE_COLOR BUTTON_PLAY
56 #elif (CONFIG_KEYPAD == GIGABEAT_PAD)
57 #define STARFIELD_QUIT BUTTON_POWER
58 #define STARFIELD_INCREASE_ZMOVE BUTTON_UP
59 #define STARFIELD_DECREASE_ZMOVE BUTTON_DOWN
60 #define STARFIELD_INCREASE_NB_STARS BUTTON_RIGHT
61 #define STARFIELD_DECREASE_NB_STARS BUTTON_LEFT
62 #define STARFIELD_TOGGLE_COLOR BUTTON_SELECT
64 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
65 (CONFIG_KEYPAD == SANSA_C200_PAD) || \
66 (CONFIG_KEYPAD == SANSA_CLIP_PAD) || \
67 (CONFIG_KEYPAD == SANSA_M200_PAD)
68 #define STARFIELD_QUIT BUTTON_POWER
69 #define STARFIELD_INCREASE_ZMOVE BUTTON_UP
70 #define STARFIELD_DECREASE_ZMOVE BUTTON_DOWN
71 #define STARFIELD_INCREASE_NB_STARS BUTTON_RIGHT
72 #define STARFIELD_DECREASE_NB_STARS BUTTON_LEFT
73 #define STARFIELD_TOGGLE_COLOR BUTTON_SELECT
75 #elif (CONFIG_KEYPAD == SANSA_FUZE_PAD)
76 #define STARFIELD_QUIT (BUTTON_HOME|BUTTON_REPEAT)
77 #define STARFIELD_INCREASE_ZMOVE BUTTON_UP
78 #define STARFIELD_DECREASE_ZMOVE BUTTON_DOWN
79 #define STARFIELD_INCREASE_NB_STARS BUTTON_RIGHT
80 #define STARFIELD_DECREASE_NB_STARS BUTTON_LEFT
81 #define STARFIELD_TOGGLE_COLOR BUTTON_SELECT
83 #elif (CONFIG_KEYPAD == GIGABEAT_S_PAD)
84 #define STARFIELD_QUIT BUTTON_BACK
85 #define STARFIELD_INCREASE_ZMOVE BUTTON_UP
86 #define STARFIELD_DECREASE_ZMOVE BUTTON_DOWN
87 #define STARFIELD_INCREASE_NB_STARS BUTTON_RIGHT
88 #define STARFIELD_DECREASE_NB_STARS BUTTON_LEFT
89 #define STARFIELD_TOGGLE_COLOR BUTTON_SELECT
91 #elif (CONFIG_KEYPAD == MROBE100_PAD)
92 #define STARFIELD_QUIT BUTTON_POWER
93 #define STARFIELD_INCREASE_ZMOVE BUTTON_UP
94 #define STARFIELD_DECREASE_ZMOVE BUTTON_DOWN
95 #define STARFIELD_INCREASE_NB_STARS BUTTON_RIGHT
96 #define STARFIELD_DECREASE_NB_STARS BUTTON_LEFT
97 #define STARFIELD_TOGGLE_COLOR BUTTON_SELECT
99 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
100 #define STARFIELD_QUIT BUTTON_RC_REC
101 #define STARFIELD_INCREASE_ZMOVE BUTTON_RC_VOL_UP
102 #define STARFIELD_DECREASE_ZMOVE BUTTON_RC_VOL_DOWN
103 #define STARFIELD_INCREASE_NB_STARS BUTTON_RC_FF
104 #define STARFIELD_DECREASE_NB_STARS BUTTON_RC_REW
105 #define STARFIELD_TOGGLE_COLOR BUTTON_RC_MODE
107 #elif CONFIG_KEYPAD == IAUDIO67_PAD
108 #define STARFIELD_QUIT BUTTON_POWER
109 #define STARFIELD_INCREASE_ZMOVE BUTTON_STOP
110 #define STARFIELD_DECREASE_ZMOVE BUTTON_PLAY
111 #define STARFIELD_INCREASE_NB_STARS BUTTON_LEFT
112 #define STARFIELD_DECREASE_NB_STARS BUTTON_RIGHT
113 #define STARFIELD_TOGGLE_COLOR BUTTON_MENU
115 #elif (CONFIG_KEYPAD == COWOND2_PAD)
116 #define STARFIELD_QUIT BUTTON_POWER
118 #elif CONFIG_KEYPAD == CREATIVEZVM_PAD
119 #define STARFIELD_QUIT BUTTON_BACK
120 #define STARFIELD_INCREASE_ZMOVE BUTTON_UP
121 #define STARFIELD_DECREASE_ZMOVE BUTTON_DOWN
122 #define STARFIELD_INCREASE_NB_STARS BUTTON_RIGHT
123 #define STARFIELD_DECREASE_NB_STARS BUTTON_LEFT
124 #define STARFIELD_TOGGLE_COLOR BUTTON_SELECT
126 #elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
127 #define STARFIELD_QUIT BUTTON_POWER
128 #define STARFIELD_INCREASE_ZMOVE BUTTON_UP
129 #define STARFIELD_DECREASE_ZMOVE BUTTON_DOWN
130 #define STARFIELD_INCREASE_NB_STARS BUTTON_RIGHT
131 #define STARFIELD_DECREASE_NB_STARS BUTTON_LEFT
132 #define STARFIELD_TOGGLE_COLOR BUTTON_SELECT
134 #elif (CONFIG_KEYPAD == ONDAVX747_PAD) || CONFIG_KEYPAD == MROBE500_PAD
135 #define STARFIELD_QUIT BUTTON_POWER
137 #elif CONFIG_KEYPAD == SAMSUNG_YH_PAD
138 #define STARFIELD_QUIT BUTTON_FFWD
139 #define STARFIELD_INCREASE_ZMOVE BUTTON_UP
140 #define STARFIELD_DECREASE_ZMOVE BUTTON_DOWN
141 #define STARFIELD_INCREASE_NB_STARS BUTTON_RIGHT
142 #define STARFIELD_DECREASE_NB_STARS BUTTON_LEFT
143 #define STARFIELD_TOGGLE_COLOR BUTTON_PLAY
147 #ifdef HAVE_TOUCHSCREEN
148 #ifndef STARFIELD_QUIT
149 #define STARFIELD_QUIT BUTTON_TOPLEFT
151 #ifndef STARFIELD_INCREASE_ZMOVE
152 #define STARFIELD_INCREASE_ZMOVE BUTTON_TOPMIDDLE
154 #ifndef STARFIELD_DECREASE_ZMOVE
155 #define STARFIELD_DECREASE_ZMOVE BUTTON_BOTTOMMIDDLE
157 #ifndef STARFIELD_INCREASE_NB_STARS
158 #define STARFIELD_INCREASE_NB_STARS BUTTON_MIDRIGHT
160 #ifndef STARFIELD_DECREASE_NB_STARS
161 #define STARFIELD_DECREASE_NB_STARS BUTTON_MIDLEFT
163 #ifndef STARFIELD_TOGGLE_COLOR
164 #define STARFIELD_TOGGLE_COLOR BUTTON_CENTER
168 #ifndef STARFIELD_QUIT
169 #define STARFIELD_QUIT BUTTON_OFF
171 #ifndef STARFIELD_INCREASE_ZMOVE
172 #define STARFIELD_INCREASE_ZMOVE BUTTON_UP
174 #ifndef STARFIELD_DECREASE_ZMOVE
175 #define STARFIELD_DECREASE_ZMOVE BUTTON_DOWN
177 #ifndef STARFIELD_INCREASE_NB_STARS
178 #define STARFIELD_INCREASE_NB_STARS BUTTON_RIGHT
180 #ifndef STARFIELD_DECREASE_NB_STARS
181 #define STARFIELD_DECREASE_NB_STARS BUTTON_LEFT
184 #ifndef STARFIELD_TOGGLE_COLOR
186 #define STARFIELD_TOGGLE_COLOR BUTTON_SELECT
188 #define STARFIELD_TOGGLE_COLOR BUTTON_PLAY
191 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD)
192 #define STARFIELD_RC_QUIT BUTTON_RC_STOP
196 #define LCD_CENTER_X (LCD_WIDTH/2)
197 #define LCD_CENTER_Y (LCD_HEIGHT/2)
198 #define Z_MAX_DIST 100
201 #define MAX_STARS (LCD_WIDTH*LCD_HEIGHT*20)/100
202 #define INIT_STARS 200
203 #define STARFIELD_INCREASE_STEP 50
204 #define INIT_SPACE_SPEED 1
205 #define STAR_MAX_VELOCITY 2
207 * max 3d coord in the 2d screen :
209 * x2d=x3d/z+LCD_CENTER_X (+LCD_CENTER_X to center ...)
211 * max_x2d=max_x3d/max_z+LCD_CENTER_X
212 * max_x3d=(max_x2d-LCD_CENTER_X)*max_z
214 * max_x2d = LCD_WIDTH
217 * max_x3d=(LCD_WIDTH-LCD_CENTER_X)*Z_MAX_DIST
218 * max_x3d=LCD_CENTER_X*Z_MAX_DIST
221 #define MAX_INIT_STAR_X LCD_CENTER_X*Z_MAX_DIST
222 #define MAX_INIT_STAR_Y LCD_CENTER_Y*Z_MAX_DIST
224 #define MSG_DISP_TIME 30
233 #ifdef HAVE_LCD_COLOR
238 static inline void star_init(struct star
* star
, int z_move
, bool color
)
240 star
->velocity
=rb
->rand() % STAR_MAX_VELOCITY
+1;
241 /* choose x between -MAX_INIT_STAR_X and MAX_INIT_STAR_X */
242 star
->x
=rb
->rand() % (2*MAX_INIT_STAR_X
)-MAX_INIT_STAR_X
;
243 star
->y
=rb
->rand() % (2*MAX_INIT_STAR_Y
)-MAX_INIT_STAR_Y
;
244 #ifdef HAVE_LCD_COLOR
246 star
->color
=LCD_RGBPACK(rb
->rand()%128+128,rb
->rand()%128+128,
249 star
->color
=LCD_WHITE
;
256 star
->z
=rb
->rand() %Z_MAX_DIST
/2+1;
259 static inline void star_move(struct star
* star
, int z_move
, bool color
)
261 star
->z
-= z_move
*star
->velocity
;
262 if (star
->z
<= 0 || star
->z
> Z_MAX_DIST
)
263 star_init(star
, z_move
, color
);
266 static inline void star_draw(struct star
* star
, int z_move
, bool color
)
270 * 3d -> 2d : projection on the screen : x2d=x3d/z (thales theorem)
271 * we put the star in the center of the screen
273 x_draw
= star
->x
/ star
->z
+ LCD_CENTER_X
;
274 if (x_draw
< 1 || x_draw
>= LCD_WIDTH
)
276 star_init(star
, z_move
, color
);
279 y_draw
= star
->y
/ star
->z
+ LCD_CENTER_Y
;
280 if (y_draw
< 1 || y_draw
>= LCD_HEIGHT
)
282 star_init(star
, z_move
, color
);
286 #ifdef HAVE_LCD_COLOR
287 rb
->lcd_set_foreground(star
->color
);
290 rb
->lcd_drawpixel(x_draw
, y_draw
);
291 if(star
->z
<5*Z_MAX_DIST
/6)
293 rb
->lcd_drawpixel(x_draw
, y_draw
- 1);
294 rb
->lcd_drawpixel(x_draw
- 1, y_draw
);
295 if(star
->z
<Z_MAX_DIST
/2)
297 rb
->lcd_drawpixel(x_draw
+ 1, y_draw
);
298 rb
->lcd_drawpixel(x_draw
, y_draw
+ 1);
304 * Whole starfield operations
308 struct star tab
[MAX_STARS
];
314 static inline void starfield_init(struct starfield
* starfield
)
316 starfield
->nb_stars
=0;
317 starfield
->z_move
=INIT_SPACE_SPEED
;
318 starfield
->color
=false;
321 static inline void starfield_add_stars(struct starfield
* starfield
,
325 old_nb_stars
=starfield
->nb_stars
;
326 starfield
->nb_stars
+=nb_to_add
;
328 if(starfield
->nb_stars
> MAX_STARS
)
329 starfield
->nb_stars
=MAX_STARS
;
331 for( i
=old_nb_stars
; i
< starfield
->nb_stars
; ++i
)
333 star_init( &(starfield
->tab
[i
]), starfield
->z_move
, starfield
->color
);
337 static inline void starfield_del_stars(struct starfield
* starfield
,
340 starfield
->nb_stars
-=nb_to_add
;
341 if(starfield
->nb_stars
<0)
342 starfield
->nb_stars
=0;
345 static inline void starfield_move_and_draw(struct starfield
* starfield
)
348 for(i
=0;i
<starfield
->nb_stars
;++i
)
350 star_move(&(starfield
->tab
[i
]), starfield
->z_move
, starfield
->color
);
351 star_draw(&(starfield
->tab
[i
]), starfield
->z_move
, starfield
->color
);
355 static struct starfield starfield
;
357 int plugin_main(void)
360 int button
, avg_peak
, t_disp
=0;
363 rb
->lcd_getstringsize("A", &font_w
, &font_h
);
364 starfield_init(&starfield
);
365 starfield_add_stars(&starfield
, INIT_STARS
);
368 rb
->lcd_set_backdrop(NULL
);
370 #ifdef HAVE_LCD_COLOR
371 rb
->lcd_set_background(LCD_BLACK
);
372 rb
->lcd_set_foreground(LCD_WHITE
);
378 rb
->lcd_clear_display();
380 #if ((CONFIG_CODEC == SWCODEC) || !defined(SIMULATOR) && \
381 ((CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)))
383 /* This will make the stars pulse to the music */
386 /* Get the peaks. ( Borrowed from vu_meter ) */
387 #if (CONFIG_CODEC == SWCODEC)
388 int left_peak
, right_peak
;
389 rb
->pcm_calculate_peaks(&left_peak
, &right_peak
);
391 int left_peak
= rb
->mas_codec_readreg(0xC);
392 int right_peak
= rb
->mas_codec_readreg(0xD);
394 /* Devide peak data by 4098 to bring the max
395 value down from ~32k to 8 */
396 left_peak
= left_peak
/0x1000;
397 right_peak
= right_peak
/0x1000;
399 /* Make sure they dont stop */
405 /* And make sure they dont go over 8 */
411 /* We need the average of both chanels */
412 avg_peak
= ( left_peak
+ right_peak
)/2;
414 /* Set the speed to the peak meter */
415 starfield
.z_move
= avg_peak
;
421 starfield_move_and_draw(&starfield
);
423 #ifdef HAVE_LCD_COLOR
424 rb
->lcd_set_foreground(LCD_WHITE
);
427 /* if a parameter is updated (by the user), we must print it */
431 rb
->snprintf(str_buffer
, sizeof(str_buffer
),
435 #ifdef HAVE_LCD_COLOR
436 rb
->lcd_set_foreground(LCD_WHITE
);
438 rb
->lcd_putsxy(0, LCD_HEIGHT
-font_h
, str_buffer
);
442 button
= rb
->button_get(false);
445 case (STARFIELD_INCREASE_ZMOVE
):
446 case (STARFIELD_INCREASE_ZMOVE
| BUTTON_REPEAT
):
447 ++(starfield
.z_move
);
449 t_disp
=MSG_DISP_TIME
;
451 case (STARFIELD_DECREASE_ZMOVE
):
452 case (STARFIELD_DECREASE_ZMOVE
| BUTTON_REPEAT
):
453 --(starfield
.z_move
);
455 t_disp
=MSG_DISP_TIME
;
457 case(STARFIELD_INCREASE_NB_STARS
):
458 case(STARFIELD_INCREASE_NB_STARS
| BUTTON_REPEAT
):
459 starfield_add_stars(&starfield
, STARFIELD_INCREASE_STEP
);
460 t_disp
=MSG_DISP_TIME
;
462 case(STARFIELD_DECREASE_NB_STARS
):
463 case(STARFIELD_DECREASE_NB_STARS
| BUTTON_REPEAT
):
464 starfield_del_stars(&starfield
, STARFIELD_INCREASE_STEP
);
465 t_disp
=MSG_DISP_TIME
;
467 #ifdef HAVE_LCD_COLOR
468 case(STARFIELD_TOGGLE_COLOR
):
469 starfield
.color
=!starfield
.color
;
472 #ifdef STARFIELD_RC_QUIT
473 case STARFIELD_RC_QUIT
:
475 case(STARFIELD_QUIT
):
476 case(SYS_USB_CONNECTED
):
477 /* Turn on backlight timeout (revert to settings) */
478 backlight_use_settings(); /* backlight control in lib/helper.c*/
485 /*************************** Plugin entry point ****************************/
487 enum plugin_status
plugin_start(const void* parameter
)
492 /* Turn off backlight timeout */
493 backlight_force_on(); /* backlight control in lib/helper.c */
500 #endif /* #ifdef HAVE_LCD_BITMAP */