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 * This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU General Public License
19 * as published by the Free Software Foundation; either version 2
20 * of the License, or (at your option) any later version.
22 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
23 * KIND, either express or implied.
25 ****************************************************************************/
28 #include "lib/helper.h"
30 #ifdef HAVE_LCD_BITMAP
32 #ifndef HAVE_LCD_COLOR
35 #include "lib/fixedpoint.h"
39 /******************************* Globals ***********************************/
41 static unsigned char wave_array
[256]; /* Pre calculated wave array */
43 static fb_data colours
[256]; /* Smooth transition of shades */
44 static int redfactor
= 1, greenfactor
= 2, bluefactor
= 3;
45 static int redphase
= 0, greenphase
= 50, bluephase
= 100;
46 /* lower chance of gray at regular intervals */
49 static unsigned char colours
[256]; /* Smooth transition of shades */
50 static unsigned char greybuffer
[LCD_HEIGHT
*LCD_WIDTH
]; /* off screen buffer */
51 static unsigned char *gbuf
;
52 static size_t gbuf_size
= 0;
54 static unsigned char sp1
, sp2
, sp3
, sp4
; /* Speed of plasma */
55 static int plasma_frequency
;
57 /* Key assignement, all bitmapped models */
58 #if (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) || \
59 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
60 #define PLASMA_QUIT BUTTON_MENU
61 #define PLASMA_INCREASE_FREQUENCY BUTTON_SCROLL_FWD
62 #define PLASMA_DECREASE_FREQUENCY BUTTON_SCROLL_BACK
64 #elif (CONFIG_KEYPAD == GIGABEAT_PAD)
65 #define PLASMA_QUIT BUTTON_POWER
66 #define PLASMA_INCREASE_FREQUENCY BUTTON_UP
67 #define PLASMA_DECREASE_FREQUENCY BUTTON_DOWN
69 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
70 (CONFIG_KEYPAD == SANSA_C200_PAD) || \
71 (CONFIG_KEYPAD == SANSA_CLIP_PAD) || \
72 (CONFIG_KEYPAD == SANSA_M200_PAD)
73 #define PLASMA_QUIT BUTTON_POWER
74 #define PLASMA_INCREASE_FREQUENCY BUTTON_UP
75 #define PLASMA_DECREASE_FREQUENCY BUTTON_DOWN
77 #elif (CONFIG_KEYPAD == SANSA_FUZE_PAD)
78 #define PLASMA_QUIT (BUTTON_HOME|BUTTON_REPEAT)
79 #define PLASMA_INCREASE_FREQUENCY BUTTON_UP
80 #define PLASMA_DECREASE_FREQUENCY BUTTON_DOWN
82 #elif (CONFIG_KEYPAD == IAUDIO_X5M5_PAD)
83 #define PLASMA_QUIT BUTTON_POWER
84 #define PLASMA_INCREASE_FREQUENCY BUTTON_UP
85 #define PLASMA_DECREASE_FREQUENCY BUTTON_DOWN
87 #elif (CONFIG_KEYPAD == IRIVER_H10_PAD)
88 #define PLASMA_QUIT BUTTON_POWER
89 #define PLASMA_INCREASE_FREQUENCY BUTTON_SCROLL_UP
90 #define PLASMA_DECREASE_FREQUENCY BUTTON_SCROLL_DOWN
92 #elif (CONFIG_KEYPAD == GIGABEAT_S_PAD)
93 #define PLASMA_QUIT BUTTON_BACK
94 #define PLASMA_INCREASE_FREQUENCY BUTTON_UP
95 #define PLASMA_DECREASE_FREQUENCY BUTTON_DOWN
97 #elif (CONFIG_KEYPAD == MROBE100_PAD)
98 #define PLASMA_QUIT BUTTON_POWER
99 #define PLASMA_INCREASE_FREQUENCY BUTTON_UP
100 #define PLASMA_DECREASE_FREQUENCY BUTTON_DOWN
102 #elif (CONFIG_KEYPAD == IAUDIO_M3_PAD)
103 #define PLASMA_QUIT BUTTON_RC_REC
104 #define PLASMA_INCREASE_FREQUENCY BUTTON_RC_VOL_UP
105 #define PLASMA_DECREASE_FREQUENCY BUTTON_RC_VOL_DOWN
106 #define PLASMA_RC_QUIT BUTTON_REC
108 #elif (CONFIG_KEYPAD == COWOND2_PAD)
109 #define PLASMA_QUIT BUTTON_POWER
111 #elif (CONFIG_KEYPAD == IAUDIO67_PAD)
112 #define PLASMA_QUIT BUTTON_POWER
113 #define PLASMA_INCREASE_FREQUENCY BUTTON_RIGHT
114 #define PLASMA_DECREASE_FREQUENCY BUTTON_LEFT
115 #define PLASMA_RC_QUIT BUTTON_STOP
116 #define PLASMA_REGEN_COLORS BUTTON_PLAY
118 #elif CONFIG_KEYPAD == CREATIVEZVM_PAD
119 #define PLASMA_QUIT BUTTON_BACK
120 #define PLASMA_INCREASE_FREQUENCY BUTTON_UP
121 #define PLASMA_DECREASE_FREQUENCY BUTTON_DOWN
122 #define PLASMA_REGEN_COLORS BUTTON_SELECT
124 #elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
125 #define PLASMA_QUIT BUTTON_POWER
126 #define PLASMA_INCREASE_FREQUENCY BUTTON_UP
127 #define PLASMA_DECREASE_FREQUENCY BUTTON_DOWN
128 #define PLASMA_REGEN_COLORS BUTTON_SELECT
130 #elif (CONFIG_KEYPAD == ONDAVX747_PAD)
131 #define PLASMA_QUIT BUTTON_POWER
135 #ifdef HAVE_TOUCHSCREEN
137 #define PLASMA_QUIT BUTTON_TOPLEFT
139 #ifndef PLASMA_INCREASE_FREQUENCY
140 #define PLASMA_INCREASE_FREQUENCY BUTTON_MIDRIGHT
142 #ifndef PLASMA_DECREASE_FREQUENCY
143 #define PLASMA_DECREASE_FREQUENCY BUTTON_MIDLEFT
145 #endif /* HAVE_TOUCHSCREEN */
148 #define PLASMA_QUIT BUTTON_OFF
150 #ifndef PLASMA_INCREASE_FREQUENCY
151 #define PLASMA_INCREASE_FREQUENCY BUTTON_UP
153 #ifndef PLASMA_DECREASE_FREQUENCY
154 #define PLASMA_DECREASE_FREQUENCY BUTTON_DOWN
157 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD)
158 #define PLASMA_RC_QUIT BUTTON_RC_STOP
162 #ifdef HAVE_LCD_COLOR
163 #if CONFIG_KEYPAD == IAUDIO_X5M5_PAD
164 #define PLASMA_REGEN_COLORS BUTTON_PLAY
165 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
166 #define PLASMA_REGEN_COLORS BUTTON_PLAY
167 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
168 (CONFIG_KEYPAD == SANSA_C200_PAD) || \
169 (CONFIG_KEYPAD == SANSA_FUZE_PAD)
170 #define PLASMA_REGEN_COLORS BUTTON_SELECT
171 #elif CONFIG_KEYPAD == IPOD_4G_PAD
172 #define PLASMA_REGEN_COLORS BUTTON_SELECT
173 #elif CONFIG_KEYPAD == IRIVER_H300_PAD
174 #define PLASMA_REGEN_COLORS BUTTON_SELECT
175 #elif CONFIG_KEYPAD == GIGABEAT_PAD
176 #define PLASMA_REGEN_COLORS BUTTON_SELECT
177 #elif CONFIG_KEYPAD == GIGABEAT_S_PAD
178 #define PLASMA_REGEN_COLORS BUTTON_SELECT
180 #ifdef HAVE_TOUCHSCREEN
181 #ifndef PLASMA_REGEN_COLORS
182 #define PLASMA_REGEN_COLORS BUTTON_CENTER
184 #endif /* HAVE_TOUCHSCREEN */
185 #endif /* HAVE_LCD_COLOR */
190 * Main wave function so we don't have to re-calc the sine
191 * curve every time. Mess around WAV_AMP and FREQ to make slighlty
192 * weirder looking plasmas!
195 static void wave_table_generate(void)
200 wave_array
[i
] = (unsigned char)((WAV_AMP
201 * (fp14_sin((i
* 360 * plasma_frequency
) / 256))) / 16384);
205 #ifdef HAVE_LCD_COLOR
206 /* Make a smooth colour cycle. */
207 void shades_generate(int time
)
210 unsigned red
, green
, blue
;
211 unsigned r
= time
* redfactor
+ redphase
;
212 unsigned g
= time
* greenfactor
+ greenphase
;
213 unsigned b
= time
* bluefactor
+ bluephase
;
215 for(i
=0; i
< 256; ++i
)
217 r
&= 0xFF; g
&= 0xFF; b
&= 0xFF;
229 colours
[i
] = LCD_RGBPACK(red
, green
, blue
);
235 /* Make a smooth shade from black into white and back into black again. */
236 static void shades_generate(void)
240 for(i
=0; i
< 256; ++i
)
250 void cleanup(void *parameter
)
254 #ifndef HAVE_LCD_COLOR
257 /* Turn on backlight timeout (revert to settings) */
258 backlight_use_settings(); /* backlight control in lib/helper.c */
262 * Main function that also contain the main plasma
268 plasma_frequency
= 1;
270 unsigned char p1
,p2
,p3
,p4
,t1
,t2
,t3
,t4
, z
;
271 #ifdef HAVE_LCD_COLOR
278 /*Generate the neccesary pre calced stuff*/
279 wave_table_generate();
281 #ifndef HAVE_LCD_COLOR
282 shades_generate(); /* statically */
284 /* get the remainder of the plugin buffer */
285 gbuf
= (unsigned char *) rb
->plugin_get_buffer(&gbuf_size
);
287 grey_init(gbuf
, gbuf_size
, GREY_ON_COP
, LCD_WIDTH
, LCD_HEIGHT
, NULL
);
288 /* switch on greyscale overlay */
298 #ifdef HAVE_LCD_COLOR
299 shades_generate(time
++); /* dynamically */
300 ptr
= rb
->lcd_framebuffer
;
306 for(y
= 0; y
< LCD_HEIGHT
; ++y
)
310 for(x
= 0; x
< LCD_WIDTH
; ++x
)
312 z
= wave_array
[t1
] + wave_array
[t2
] + wave_array
[t3
]
326 #ifdef HAVE_LCD_COLOR
329 grey_ub_gray_bitmap(greybuffer
, 0, 0, LCD_WIDTH
, LCD_HEIGHT
);
332 button
= rb
->button_get(false);
336 #ifdef PLASMA_RC_QUIT
344 case (PLASMA_INCREASE_FREQUENCY
):
346 wave_table_generate();
349 case (PLASMA_DECREASE_FREQUENCY
):
350 if(plasma_frequency
>1)
353 wave_table_generate();
356 #ifdef HAVE_LCD_COLOR
357 case (PLASMA_REGEN_COLORS
):
358 redfactor
=rb
->rand()%4;
359 greenfactor
=rb
->rand()%4;
360 bluefactor
=rb
->rand()%4;
361 redphase
=rb
->rand()%256;
362 greenphase
=rb
->rand()%256;
363 bluephase
=rb
->rand()%256;
368 if (rb
->default_event_handler_ex(button
, cleanup
, NULL
)
369 == SYS_USB_CONNECTED
)
370 return PLUGIN_USB_CONNECTED
;
376 /*************************** Plugin entry point ****************************/
378 enum plugin_status
plugin_start(const void* parameter
)
384 rb
->lcd_set_backdrop(NULL
);
386 /* Turn off backlight timeout */
387 backlight_force_on(); /* backlight control in lib/helper.c */
394 #endif /* HAVE_LCD_BITMAP */