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 const struct plugin_api
* rb
; /* global api struct pointer */
42 static unsigned char wave_array
[256]; /* Pre calculated wave array */
44 static fb_data colours
[256]; /* Smooth transition of shades */
45 static int redfactor
= 1, greenfactor
= 2, bluefactor
= 3;
46 static int redphase
= 0, greenphase
= 50, bluephase
= 100;
47 /* lower chance of gray at regular intervals */
50 static unsigned char colours
[256]; /* Smooth transition of shades */
51 static unsigned char greybuffer
[LCD_HEIGHT
*LCD_WIDTH
]; /* off screen buffer */
52 static unsigned char *gbuf
;
53 static size_t gbuf_size
= 0;
55 static unsigned char sp1
, sp2
, sp3
, sp4
; /* Speed of plasma */
56 static int plasma_frequency
;
58 /* FIXME: Could use plugin lib actions */
59 /* Key assignement, all bitmapped models */
60 #if (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) || \
61 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
62 #define PLASMA_QUIT BUTTON_MENU
63 #define PLASMA_INCREASE_FREQUENCY BUTTON_SCROLL_FWD
64 #define PLASMA_DECREASE_FREQUENCY BUTTON_SCROLL_BACK
66 #elif (CONFIG_KEYPAD == GIGABEAT_PAD)
67 #define PLASMA_QUIT BUTTON_POWER
68 #define PLASMA_INCREASE_FREQUENCY BUTTON_UP
69 #define PLASMA_DECREASE_FREQUENCY BUTTON_DOWN
71 /* FIXME: Clip/fuze should use HOME instead of POWER */
72 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
73 (CONFIG_KEYPAD == SANSA_C200_PAD) || \
74 (CONFIG_KEYPAD == SANSA_CLIP_PAD) || \
75 (CONFIG_KEYPAD == SANSA_M200_PAD) || \
76 (CONFIG_KEYPAD == SANSA_FUZE_PAD)
77 #define PLASMA_QUIT BUTTON_POWER
78 #define PLASMA_INCREASE_FREQUENCY BUTTON_UP
79 #define PLASMA_DECREASE_FREQUENCY BUTTON_DOWN
81 #elif (CONFIG_KEYPAD == IAUDIO_X5M5_PAD)
82 #define PLASMA_QUIT BUTTON_POWER
83 #define PLASMA_INCREASE_FREQUENCY BUTTON_UP
84 #define PLASMA_DECREASE_FREQUENCY BUTTON_DOWN
86 #elif (CONFIG_KEYPAD == IRIVER_H10_PAD)
87 #define PLASMA_QUIT BUTTON_POWER
88 #define PLASMA_INCREASE_FREQUENCY BUTTON_SCROLL_UP
89 #define PLASMA_DECREASE_FREQUENCY BUTTON_SCROLL_DOWN
91 #elif (CONFIG_KEYPAD == GIGABEAT_S_PAD)
92 #define PLASMA_QUIT BUTTON_BACK
93 #define PLASMA_INCREASE_FREQUENCY BUTTON_UP
94 #define PLASMA_DECREASE_FREQUENCY BUTTON_DOWN
96 #elif (CONFIG_KEYPAD == MROBE100_PAD)
97 #define PLASMA_QUIT BUTTON_POWER
98 #define PLASMA_INCREASE_FREQUENCY BUTTON_UP
99 #define PLASMA_DECREASE_FREQUENCY BUTTON_DOWN
101 #elif (CONFIG_KEYPAD == IAUDIO_M3_PAD)
102 #define PLASMA_QUIT BUTTON_RC_REC
103 #define PLASMA_INCREASE_FREQUENCY BUTTON_RC_VOL_UP
104 #define PLASMA_DECREASE_FREQUENCY BUTTON_RC_VOL_DOWN
105 #define PLASMA_RC_QUIT BUTTON_REC
107 #elif (CONFIG_KEYPAD == COWOND2_PAD)
108 #define PLASMA_QUIT BUTTON_POWER
110 #elif (CONFIG_KEYPAD == IAUDIO67_PAD)
111 #define PLASMA_QUIT BUTTON_POWER
112 #define PLASMA_INCREASE_FREQUENCY BUTTON_RIGHT
113 #define PLASMA_DECREASE_FREQUENCY BUTTON_LEFT
114 #define PLASMA_RC_QUIT BUTTON_STOP
115 #define PLASMA_REGEN_COLORS BUTTON_PLAY
117 #elif CONFIG_KEYPAD == CREATIVEZVM_PAD
118 #define PLASMA_QUIT BUTTON_BACK
119 #define PLASMA_INCREASE_FREQUENCY BUTTON_UP
120 #define PLASMA_DECREASE_FREQUENCY BUTTON_DOWN
121 #define PLASMA_REGEN_COLORS BUTTON_SELECT
125 #ifdef HAVE_TOUCHSCREEN
127 #define PLASMA_QUIT BUTTON_TOPLEFT
129 #ifndef PLASMA_INCREASE_FREQUENCY
130 #define PLASMA_INCREASE_FREQUENCY BUTTON_MIDRIGHT
132 #ifndef PLASMA_DECREASE_FREQUENCY
133 #define PLASMA_DECREASE_FREQUENCY BUTTON_MIDLEFT
135 #endif /* HAVE_TOUCHSCREEN */
138 #define PLASMA_QUIT BUTTON_OFF
140 #ifndef PLASMA_INCREASE_FREQUENCY
141 #define PLASMA_INCREASE_FREQUENCY BUTTON_UP
143 #ifndef PLASMA_DECREASE_FREQUENCY
144 #define PLASMA_DECREASE_FREQUENCY BUTTON_DOWN
147 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD)
148 #define PLASMA_RC_QUIT BUTTON_RC_STOP
152 #ifdef HAVE_LCD_COLOR
153 #if CONFIG_KEYPAD == IAUDIO_X5M5_PAD
154 #define PLASMA_REGEN_COLORS BUTTON_PLAY
155 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
156 #define PLASMA_REGEN_COLORS BUTTON_PLAY
157 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
158 (CONFIG_KEYPAD == SANSA_C200_PAD) || \
159 (CONFIG_KEYPAD == SANSA_FUZE_PAD)
160 #define PLASMA_REGEN_COLORS BUTTON_SELECT
161 #elif CONFIG_KEYPAD == IPOD_4G_PAD
162 #define PLASMA_REGEN_COLORS BUTTON_SELECT
163 #elif CONFIG_KEYPAD == IRIVER_H300_PAD
164 #define PLASMA_REGEN_COLORS BUTTON_SELECT
165 #elif CONFIG_KEYPAD == GIGABEAT_PAD
166 #define PLASMA_REGEN_COLORS BUTTON_SELECT
167 #elif CONFIG_KEYPAD == GIGABEAT_S_PAD
168 #define PLASMA_REGEN_COLORS BUTTON_SELECT
170 #ifdef HAVE_TOUCHSCREEN
171 #ifndef PLASMA_REGEN_COLORS
172 #define PLASMA_REGEN_COLORS BUTTON_CENTER
174 #endif /* HAVE_TOUCHSCREEN */
175 #endif /* HAVE_LCD_COLOR */
180 * Main wave function so we don't have to re-calc the sine
181 * curve every time. Mess around WAV_AMP and FREQ to make slighlty
182 * weirder looking plasmas!
185 static void wave_table_generate(void)
190 wave_array
[i
] = (unsigned char)((WAV_AMP
191 * (sin_int((i
* 360 * plasma_frequency
) / 256))) / 16384);
195 #ifdef HAVE_LCD_COLOR
196 /* Make a smooth colour cycle. */
197 void shades_generate(int time
)
200 unsigned red
, green
, blue
;
201 unsigned r
= time
* redfactor
+ redphase
;
202 unsigned g
= time
* greenfactor
+ greenphase
;
203 unsigned b
= time
* bluefactor
+ bluephase
;
205 for(i
=0; i
< 256; ++i
)
207 r
&= 0xFF; g
&= 0xFF; b
&= 0xFF;
219 colours
[i
] = LCD_RGBPACK(red
, green
, blue
);
225 /* Make a smooth shade from black into white and back into black again. */
226 static void shades_generate(void)
230 for(i
=0; i
< 256; ++i
)
240 void cleanup(void *parameter
)
244 #ifndef HAVE_LCD_COLOR
247 /* Turn on backlight timeout (revert to settings) */
248 backlight_use_settings(rb
); /* backlight control in lib/helper.c */
252 * Main function that also contain the main plasma
258 plasma_frequency
= 1;
260 unsigned char p1
,p2
,p3
,p4
,t1
,t2
,t3
,t4
, z
;
261 #ifdef HAVE_LCD_COLOR
268 /*Generate the neccesary pre calced stuff*/
269 wave_table_generate();
271 #ifndef HAVE_LCD_COLOR
272 shades_generate(); /* statically */
274 /* get the remainder of the plugin buffer */
275 gbuf
= (unsigned char *) rb
->plugin_get_buffer(&gbuf_size
);
277 grey_init(rb
, gbuf
, gbuf_size
, GREY_ON_COP
, LCD_WIDTH
, LCD_HEIGHT
, NULL
);
278 /* switch on greyscale overlay */
288 #ifdef HAVE_LCD_COLOR
289 shades_generate(time
++); /* dynamically */
290 ptr
= rb
->lcd_framebuffer
;
296 for(y
= 0; y
< LCD_HEIGHT
; ++y
)
300 for(x
= 0; x
< LCD_WIDTH
; ++x
)
302 z
= wave_array
[t1
] + wave_array
[t2
] + wave_array
[t3
]
316 #ifdef HAVE_LCD_COLOR
319 grey_ub_gray_bitmap(greybuffer
, 0, 0, LCD_WIDTH
, LCD_HEIGHT
);
322 button
= rb
->button_get(false);
326 #ifdef PLASMA_RC_QUIT
334 case (PLASMA_INCREASE_FREQUENCY
):
336 wave_table_generate();
339 case (PLASMA_DECREASE_FREQUENCY
):
340 if(plasma_frequency
>1)
343 wave_table_generate();
346 #ifdef HAVE_LCD_COLOR
347 case (PLASMA_REGEN_COLORS
):
348 redfactor
=rb
->rand()%4;
349 greenfactor
=rb
->rand()%4;
350 bluefactor
=rb
->rand()%4;
351 redphase
=rb
->rand()%256;
352 greenphase
=rb
->rand()%256;
353 bluephase
=rb
->rand()%256;
358 if (rb
->default_event_handler_ex(button
, cleanup
, NULL
)
359 == SYS_USB_CONNECTED
)
360 return PLUGIN_USB_CONNECTED
;
366 /*************************** Plugin entry point ****************************/
368 enum plugin_status
plugin_start(const struct plugin_api
* api
, const void* parameter
)
372 rb
= api
; /* copy to global api pointer */
375 rb
->lcd_set_backdrop(NULL
);
377 /* Turn off backlight timeout */
378 backlight_force_on(rb
); /* backlight control in lib/helper.c */
385 #endif /* HAVE_LCD_BITMAP */