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 */
48 static unsigned char colours
[256]; /* Smooth transition of shades */
49 static unsigned char greybuffer
[LCD_HEIGHT
*LCD_WIDTH
]; /* off screen buffer */
50 static unsigned char *gbuf
;
51 static size_t gbuf_size
= 0;
53 static unsigned char sp1
, sp2
, sp3
, sp4
; /* Speed of plasma */
54 static int plasma_frequency
;
56 /* Key assignement, all bitmapped models */
57 #if (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) || \
58 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
59 #define PLASMA_QUIT BUTTON_MENU
60 #define PLASMA_INCREASE_FREQUENCY BUTTON_SCROLL_FWD
61 #define PLASMA_DECREASE_FREQUENCY BUTTON_SCROLL_BACK
62 #elif (CONFIG_KEYPAD == GIGABEAT_PAD)
63 #define PLASMA_QUIT BUTTON_A
64 #define PLASMA_INCREASE_FREQUENCY BUTTON_UP
65 #define PLASMA_DECREASE_FREQUENCY BUTTON_DOWN
67 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
68 (CONFIG_KEYPAD == SANSA_C200_PAD)
69 #define PLASMA_QUIT BUTTON_POWER
70 #define PLASMA_INCREASE_FREQUENCY BUTTON_UP
71 #define PLASMA_DECREASE_FREQUENCY BUTTON_DOWN
73 #elif (CONFIG_KEYPAD == IAUDIO_X5M5_PAD)
74 #define PLASMA_QUIT BUTTON_POWER
75 #define PLASMA_INCREASE_FREQUENCY BUTTON_UP
76 #define PLASMA_DECREASE_FREQUENCY BUTTON_DOWN
77 #elif (CONFIG_KEYPAD == IRIVER_H10_PAD)
78 #define PLASMA_QUIT BUTTON_POWER
79 #define PLASMA_INCREASE_FREQUENCY BUTTON_SCROLL_UP
80 #define PLASMA_DECREASE_FREQUENCY BUTTON_SCROLL_DOWN
81 #elif (CONFIG_KEYPAD == GIGABEAT_S_PAD)
82 #define PLASMA_QUIT BUTTON_BACK
83 #define PLASMA_INCREASE_FREQUENCY BUTTON_UP
84 #define PLASMA_DECREASE_FREQUENCY BUTTON_DOWN
85 #elif (CONFIG_KEYPAD == MROBE100_PAD)
86 #define PLASMA_QUIT BUTTON_POWER
87 #define PLASMA_INCREASE_FREQUENCY BUTTON_UP
88 #define PLASMA_DECREASE_FREQUENCY BUTTON_DOWN
90 #define PLASMA_QUIT BUTTON_OFF
91 #define PLASMA_INCREASE_FREQUENCY BUTTON_UP
92 #define PLASMA_DECREASE_FREQUENCY BUTTON_DOWN
93 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD)
94 #define PLASMA_RC_QUIT BUTTON_RC_STOP
99 #if CONFIG_KEYPAD == IAUDIO_X5M5_PAD
100 #define PLASMA_REGEN_COLORS BUTTON_PLAY
101 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
102 #define PLASMA_REGEN_COLORS BUTTON_PLAY
103 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
104 (CONFIG_KEYPAD == SANSA_C200_PAD)
105 #define PLASMA_REGEN_COLORS BUTTON_SELECT
106 #elif CONFIG_KEYPAD == IPOD_4G_PAD
107 #define PLASMA_REGEN_COLORS BUTTON_SELECT
108 #elif CONFIG_KEYPAD == IRIVER_H300_PAD
109 #define PLASMA_REGEN_COLORS BUTTON_SELECT
110 #elif CONFIG_KEYPAD == GIGABEAT_PAD
111 #define PLASMA_REGEN_COLORS BUTTON_SELECT
112 #elif CONFIG_KEYPAD == GIGABEAT_S_PAD
113 #define PLASMA_REGEN_COLORS BUTTON_SELECT
120 * Main wave function so we don't have to re-calc the sine
121 * curve every time. Mess around WAV_AMP and FREQ to make slighlty
122 * weirder looking plasmas!
125 static void wave_table_generate(void)
130 wave_array
[i
] = (unsigned char)((WAV_AMP
131 * (sin_int((i
* 360 * plasma_frequency
) / 256))) / 16384);
135 #ifdef HAVE_LCD_COLOR
136 /* Make a smooth colour cycle. */
137 void shades_generate(int time
)
140 unsigned red
, green
, blue
;
141 unsigned r
= time
* redfactor
+ redphase
;
142 unsigned g
= time
* greenfactor
+ greenphase
;
143 unsigned b
= time
* bluefactor
+ bluephase
;
145 for(i
=0; i
< 256; ++i
)
147 r
&= 0xFF; g
&= 0xFF; b
&= 0xFF;
159 colours
[i
] = LCD_RGBPACK(red
, green
, blue
);
165 /* Make a smooth shade from black into white and back into black again. */
166 static void shades_generate(void)
170 for(i
=0; i
< 256; ++i
)
180 void cleanup(void *parameter
)
184 #ifndef HAVE_LCD_COLOR
187 /* Turn on backlight timeout (revert to settings) */
188 backlight_use_settings(rb
); /* backlight control in lib/helper.c */
192 * Main function that also contain the main plasma
198 plasma_frequency
= 1;
200 unsigned char p1
,p2
,p3
,p4
,t1
,t2
,t3
,t4
, z
;
201 #ifdef HAVE_LCD_COLOR
208 /*Generate the neccesary pre calced stuff*/
209 wave_table_generate();
211 #ifndef HAVE_LCD_COLOR
212 shades_generate(); /* statically */
214 /* get the remainder of the plugin buffer */
215 gbuf
= (unsigned char *) rb
->plugin_get_buffer(&gbuf_size
);
217 grey_init(rb
, gbuf
, gbuf_size
, false, LCD_WIDTH
, LCD_HEIGHT
, NULL
);
218 /* switch on greyscale overlay */
228 #ifdef HAVE_LCD_COLOR
229 shades_generate(time
++); /* dynamically */
230 ptr
= rb
->lcd_framebuffer
;
236 for(y
= 0; y
< LCD_HEIGHT
; ++y
)
240 for(x
= 0; x
< LCD_WIDTH
; ++x
)
242 z
= wave_array
[t1
] + wave_array
[t2
] + wave_array
[t3
]
256 #ifdef HAVE_LCD_COLOR
259 grey_ub_gray_bitmap(greybuffer
, 0, 0, LCD_WIDTH
, LCD_HEIGHT
);
262 button
= rb
->button_get(false);
266 #ifdef PLASMA_RC_QUIT
274 case (PLASMA_INCREASE_FREQUENCY
):
276 wave_table_generate();
279 case (PLASMA_DECREASE_FREQUENCY
):
280 if(plasma_frequency
>1)
283 wave_table_generate();
286 #ifdef HAVE_LCD_COLOR
287 case (PLASMA_REGEN_COLORS
):
288 redfactor
=rb
->rand()%4;
289 greenfactor
=rb
->rand()%4;
290 bluefactor
=rb
->rand()%4;
291 redphase
=rb
->rand()%256;
292 greenphase
=rb
->rand()%256;
293 bluephase
=rb
->rand()%256;
298 if (rb
->default_event_handler_ex(button
, cleanup
, NULL
)
299 == SYS_USB_CONNECTED
)
300 return PLUGIN_USB_CONNECTED
;
306 /*************************** Plugin entry point ****************************/
308 enum plugin_status
plugin_start(struct plugin_api
* api
, void* parameter
)
312 rb
= api
; /* copy to global api pointer */
315 rb
->lcd_set_backdrop(NULL
);
317 /* Turn off backlight timeout */
318 backlight_force_on(rb
); /* backlight control in lib/helper.c */
325 #endif /* HAVE_LCD_BITMAP */