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 ****************************************************************************/
27 #ifdef HAVE_LCD_BITMAP
29 #ifndef HAVE_LCD_COLOR
32 #include "fixedpoint.h"
36 /******************************* Globals ***********************************/
38 static struct plugin_api
* rb
; /* global api struct pointer */
39 static unsigned char wave_array
[256]; /* Pre calculated wave array */
41 static fb_data colours
[256]; /* Smooth transition of shades */
42 static int redfactor
= 1, greenfactor
= 2, bluefactor
= 3;
43 static int redphase
= 0, greenphase
= 50, bluephase
= 100;
44 /* lower chance of gray at regular intervals */
46 static unsigned char colours
[256]; /* Smooth transition of shades */
47 static unsigned char graybuffer
[LCD_HEIGHT
*LCD_WIDTH
]; /* off screen buffer */
48 static unsigned char *gbuf
;
49 static size_t gbuf_size
= 0;
51 static unsigned char sp1
, sp2
, sp3
, sp4
; /* Speed of plasma */
52 static int plasma_frequency
;
54 /* Key assignement, all bitmapped models */
55 #if (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) || \
56 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
57 #define PLASMA_QUIT BUTTON_MENU
58 #define PLASMA_INCREASE_FREQUENCY BUTTON_SCROLL_FWD
59 #define PLASMA_DECREASE_FREQUENCY BUTTON_SCROLL_BACK
60 #elif (CONFIG_KEYPAD == GIGABEAT_PAD)
61 #define PLASMA_QUIT BUTTON_A
62 #define PLASMA_INCREASE_FREQUENCY BUTTON_UP
63 #define PLASMA_DECREASE_FREQUENCY BUTTON_DOWN
65 #elif (CONFIG_KEYPAD == SANSA_E200_PAD)
66 #define PLASMA_QUIT BUTTON_POWER
67 #define PLASMA_INCREASE_FREQUENCY BUTTON_UP
68 #define PLASMA_DECREASE_FREQUENCY BUTTON_DOWN
70 #elif (CONFIG_KEYPAD == IAUDIO_X5M5_PAD)
71 #define PLASMA_QUIT BUTTON_POWER
72 #define PLASMA_INCREASE_FREQUENCY BUTTON_UP
73 #define PLASMA_DECREASE_FREQUENCY BUTTON_DOWN
74 #elif (CONFIG_KEYPAD == IRIVER_H10_PAD)
75 #define PLASMA_QUIT BUTTON_POWER
76 #define PLASMA_INCREASE_FREQUENCY BUTTON_SCROLL_UP
77 #define PLASMA_DECREASE_FREQUENCY BUTTON_SCROLL_DOWN
79 #define PLASMA_QUIT BUTTON_OFF
80 #define PLASMA_INCREASE_FREQUENCY BUTTON_UP
81 #define PLASMA_DECREASE_FREQUENCY BUTTON_DOWN
82 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD)
83 #define PLASMA_RC_QUIT BUTTON_RC_STOP
88 #if CONFIG_KEYPAD == IAUDIO_X5M5_PAD
89 #define PLASMA_REGEN_COLORS BUTTON_PLAY
90 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
91 #define PLASMA_REGEN_COLORS BUTTON_PLAY
92 #elif CONFIG_KEYPAD == SANSA_E200_PAD
93 #define PLASMA_REGEN_COLORS BUTTON_SELECT
94 #elif CONFIG_KEYPAD == IPOD_4G_PAD
95 #define PLASMA_REGEN_COLORS BUTTON_SELECT
96 #elif CONFIG_KEYPAD == IRIVER_H300_PAD
97 #define PLASMA_REGEN_COLORS BUTTON_SELECT
98 #elif CONFIG_KEYPAD == GIGABEAT_PAD
99 #define PLASMA_REGEN_COLORS BUTTON_SELECT
106 * Main wave function so we don't have to re-calc the sine
107 * curve every time. Mess around WAV_AMP and FREQ to make slighlty
108 * weirder looking plasmas!
111 static void wave_table_generate(void)
116 wave_array
[i
] = (unsigned char)((WAV_AMP
117 * (sin_int((i
* 360 * plasma_frequency
) / 256))) / 16384);
121 #ifdef HAVE_LCD_COLOR
122 /* Make a smooth colour cycle. */
123 void shades_generate(int time
)
126 unsigned red
, green
, blue
;
127 unsigned r
= time
* redfactor
+ redphase
;
128 unsigned g
= time
* greenfactor
+ greenphase
;
129 unsigned b
= time
* bluefactor
+ bluephase
;
131 for(i
=0; i
< 256; ++i
)
133 r
&= 0xFF; g
&= 0xFF; b
&= 0xFF;
145 colours
[i
] = LCD_RGBPACK(red
, green
, blue
);
151 /* Make a smooth shade from black into white and back into black again. */
152 static void shades_generate(void)
156 for(i
=0; i
< 256; ++i
)
166 void cleanup(void *parameter
)
170 #ifndef HAVE_LCD_COLOR
173 rb
->backlight_set_timeout(rb
->global_settings
->backlight_timeout
);
177 * Main function that also contain the main plasma
183 plasma_frequency
= 1;
185 unsigned char p1
,p2
,p3
,p4
,t1
,t2
,t3
,t4
, z
;
186 #ifdef HAVE_LCD_COLOR
193 /*Generate the neccesary pre calced stuff*/
194 wave_table_generate();
196 #ifndef HAVE_LCD_COLOR
197 shades_generate(); /* statically */
199 /* get the remainder of the plugin buffer */
200 gbuf
= (unsigned char *) rb
->plugin_get_buffer(&gbuf_size
);
202 gray_init(rb
, gbuf
, gbuf_size
, false, LCD_WIDTH
, LCD_HEIGHT
, 32, 2<<8, NULL
);
203 /* switch on grayscale overlay */
213 #ifdef HAVE_LCD_COLOR
214 shades_generate(time
++); /* dynamically */
215 ptr
= rb
->lcd_framebuffer
;
221 for(y
= 0; y
< LCD_HEIGHT
; ++y
)
225 for(x
= 0; x
< LCD_WIDTH
; ++x
)
227 z
= wave_array
[t1
] + wave_array
[t2
] + wave_array
[t3
]
241 #ifdef HAVE_LCD_COLOR
244 gray_ub_gray_bitmap(graybuffer
, 0, 0, LCD_WIDTH
, LCD_HEIGHT
);
247 button
= rb
->button_get(false);
251 #ifdef PLASMA_RC_QUIT
259 case (PLASMA_INCREASE_FREQUENCY
):
261 wave_table_generate();
264 case (PLASMA_DECREASE_FREQUENCY
):
265 if(plasma_frequency
>1)
268 wave_table_generate();
271 #ifdef HAVE_LCD_COLOR
272 case (PLASMA_REGEN_COLORS
):
273 redfactor
=rb
->rand()%4;
274 greenfactor
=rb
->rand()%4;
275 bluefactor
=rb
->rand()%4;
276 redphase
=rb
->rand()%256;
277 greenphase
=rb
->rand()%256;
278 bluephase
=rb
->rand()%256;
283 if (rb
->default_event_handler_ex(button
, cleanup
, NULL
)
284 == SYS_USB_CONNECTED
)
285 return PLUGIN_USB_CONNECTED
;
291 /*************************** Plugin entry point ****************************/
293 enum plugin_status
plugin_start(struct plugin_api
* api
, void* parameter
)
297 rb
= api
; /* copy to global api pointer */
300 rb
->lcd_set_backdrop(NULL
);
302 if (rb
->global_settings
->backlight_timeout
> 0)
303 rb
->backlight_set_timeout(1);/* keep the light on */
310 #endif /* HAVE_LCD_BITMAP */