1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
12 * My crack at making a 80's style retro plasma effect for the fantastic
14 * Okay, I could've hard-coded the sine wave values, I just wanted the
15 * challange of calculating them! silly: maybe, fun: yes!
17 * All files in this archive are subject to the GNU General Public License.
18 * See the file COPYING in the source tree root for full license agreement.
20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21 * KIND, either express or implied.
23 ****************************************************************************/
28 #ifdef HAVE_LCD_BITMAP
30 #ifndef HAVE_LCD_COLOR
33 #include "fixedpoint.h"
37 /******************************* Globals ***********************************/
39 static struct plugin_api
* rb
; /* global api struct pointer */
40 static unsigned char wave_array
[256]; /* Pre calculated wave array */
42 static fb_data colours
[256]; /* Smooth transition of shades */
43 static int redfactor
= 1, greenfactor
= 2, bluefactor
= 3;
44 static int redphase
= 0, greenphase
= 50, bluephase
= 100;
45 /* lower chance of gray at regular intervals */
47 static unsigned char colours
[256]; /* Smooth transition of shades */
48 static unsigned char graybuffer
[LCD_HEIGHT
*LCD_WIDTH
]; /* off screen buffer */
49 static unsigned char *gbuf
;
50 static size_t gbuf_size
= 0;
52 static unsigned char sp1
, sp2
, sp3
, sp4
; /* Speed of plasma */
53 static int plasma_frequency
;
55 /* Key assignement, all bitmapped models */
56 #if (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) || \
57 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
58 #define PLASMA_QUIT BUTTON_MENU
59 #define PLASMA_INCREASE_FREQUENCY BUTTON_SCROLL_FWD
60 #define PLASMA_DECREASE_FREQUENCY BUTTON_SCROLL_BACK
61 #elif (CONFIG_KEYPAD == GIGABEAT_PAD)
62 #define PLASMA_QUIT BUTTON_A
63 #define PLASMA_INCREASE_FREQUENCY BUTTON_UP
64 #define PLASMA_DECREASE_FREQUENCY BUTTON_DOWN
66 #elif (CONFIG_KEYPAD == SANSA_E200_PAD)
67 #define PLASMA_QUIT BUTTON_POWER
68 #define PLASMA_INCREASE_FREQUENCY BUTTON_UP
69 #define PLASMA_DECREASE_FREQUENCY BUTTON_DOWN
71 #elif (CONFIG_KEYPAD == IAUDIO_X5M5_PAD)
72 #define PLASMA_QUIT BUTTON_POWER
73 #define PLASMA_INCREASE_FREQUENCY BUTTON_UP
74 #define PLASMA_DECREASE_FREQUENCY BUTTON_DOWN
75 #elif (CONFIG_KEYPAD == IRIVER_H10_PAD)
76 #define PLASMA_QUIT BUTTON_POWER
77 #define PLASMA_INCREASE_FREQUENCY BUTTON_SCROLL_UP
78 #define PLASMA_DECREASE_FREQUENCY BUTTON_SCROLL_DOWN
80 #define PLASMA_QUIT BUTTON_OFF
81 #define PLASMA_INCREASE_FREQUENCY BUTTON_UP
82 #define PLASMA_DECREASE_FREQUENCY BUTTON_DOWN
83 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD)
84 #define PLASMA_RC_QUIT BUTTON_RC_STOP
89 #if CONFIG_KEYPAD == IAUDIO_X5M5_PAD
90 #define PLASMA_REGEN_COLORS BUTTON_PLAY
91 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
92 #define PLASMA_REGEN_COLORS BUTTON_PLAY
93 #elif CONFIG_KEYPAD == SANSA_E200_PAD
94 #define PLASMA_REGEN_COLORS BUTTON_SELECT
95 #elif CONFIG_KEYPAD == IPOD_4G_PAD
96 #define PLASMA_REGEN_COLORS BUTTON_SELECT
97 #elif CONFIG_KEYPAD == IRIVER_H300_PAD
98 #define PLASMA_REGEN_COLORS BUTTON_SELECT
99 #elif CONFIG_KEYPAD == GIGABEAT_PAD
100 #define PLASMA_REGEN_COLORS BUTTON_SELECT
107 * Main wave function so we don't have to re-calc the sine
108 * curve every time. Mess around WAV_AMP and FREQ to make slighlty
109 * weirder looking plasmas!
112 static void wave_table_generate(void)
117 wave_array
[i
] = (unsigned char)((WAV_AMP
118 * (sin_int((i
* 360 * plasma_frequency
) / 256))) / 16384);
122 #ifdef HAVE_LCD_COLOR
123 /* Make a smooth colour cycle. */
124 void shades_generate(int time
)
127 unsigned red
, green
, blue
;
128 unsigned r
= time
* redfactor
+ redphase
;
129 unsigned g
= time
* greenfactor
+ greenphase
;
130 unsigned b
= time
* bluefactor
+ bluephase
;
132 for(i
=0; i
< 256; ++i
)
134 r
&= 0xFF; g
&= 0xFF; b
&= 0xFF;
146 colours
[i
] = LCD_RGBPACK(red
, green
, blue
);
152 /* Make a smooth shade from black into white and back into black again. */
153 static void shades_generate(void)
157 for(i
=0; i
< 256; ++i
)
167 void cleanup(void *parameter
)
171 #ifndef HAVE_LCD_COLOR
174 /* Turn on backlight timeout (revert to settings) */
175 backlight_use_settings(rb
); /* backlight control in lib/helper.c */
179 * Main function that also contain the main plasma
185 plasma_frequency
= 1;
187 unsigned char p1
,p2
,p3
,p4
,t1
,t2
,t3
,t4
, z
;
188 #ifdef HAVE_LCD_COLOR
195 /*Generate the neccesary pre calced stuff*/
196 wave_table_generate();
198 #ifndef HAVE_LCD_COLOR
199 shades_generate(); /* statically */
201 /* get the remainder of the plugin buffer */
202 gbuf
= (unsigned char *) rb
->plugin_get_buffer(&gbuf_size
);
204 gray_init(rb
, gbuf
, gbuf_size
, false, LCD_WIDTH
, LCD_HEIGHT
, 32, 2<<8, NULL
);
205 /* switch on grayscale overlay */
215 #ifdef HAVE_LCD_COLOR
216 shades_generate(time
++); /* dynamically */
217 ptr
= rb
->lcd_framebuffer
;
223 for(y
= 0; y
< LCD_HEIGHT
; ++y
)
227 for(x
= 0; x
< LCD_WIDTH
; ++x
)
229 z
= wave_array
[t1
] + wave_array
[t2
] + wave_array
[t3
]
243 #ifdef HAVE_LCD_COLOR
246 gray_ub_gray_bitmap(graybuffer
, 0, 0, LCD_WIDTH
, LCD_HEIGHT
);
249 button
= rb
->button_get(false);
253 #ifdef PLASMA_RC_QUIT
261 case (PLASMA_INCREASE_FREQUENCY
):
263 wave_table_generate();
266 case (PLASMA_DECREASE_FREQUENCY
):
267 if(plasma_frequency
>1)
270 wave_table_generate();
273 #ifdef HAVE_LCD_COLOR
274 case (PLASMA_REGEN_COLORS
):
275 redfactor
=rb
->rand()%4;
276 greenfactor
=rb
->rand()%4;
277 bluefactor
=rb
->rand()%4;
278 redphase
=rb
->rand()%256;
279 greenphase
=rb
->rand()%256;
280 bluephase
=rb
->rand()%256;
285 if (rb
->default_event_handler_ex(button
, cleanup
, NULL
)
286 == SYS_USB_CONNECTED
)
287 return PLUGIN_USB_CONNECTED
;
293 /*************************** Plugin entry point ****************************/
295 enum plugin_status
plugin_start(struct plugin_api
* api
, void* parameter
)
299 rb
= api
; /* copy to global api pointer */
302 rb
->lcd_set_backdrop(NULL
);
304 /* Turn off backlight timeout */
305 backlight_force_on(rb
); /* backlight control in lib/helper.c */
312 #endif /* HAVE_LCD_BITMAP */