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 /* Key assignement, all bitmapped models */
59 #if (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) || \
60 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
61 #define PLASMA_QUIT BUTTON_MENU
62 #define PLASMA_INCREASE_FREQUENCY BUTTON_SCROLL_FWD
63 #define PLASMA_DECREASE_FREQUENCY BUTTON_SCROLL_BACK
65 #elif (CONFIG_KEYPAD == GIGABEAT_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 == SANSA_E200_PAD) || \
71 (CONFIG_KEYPAD == SANSA_C200_PAD)
72 #define PLASMA_QUIT BUTTON_POWER
73 #define PLASMA_INCREASE_FREQUENCY BUTTON_UP
74 #define PLASMA_DECREASE_FREQUENCY BUTTON_DOWN
76 #elif (CONFIG_KEYPAD == IAUDIO_X5M5_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 == IRIVER_H10_PAD)
82 #define PLASMA_QUIT BUTTON_POWER
83 #define PLASMA_INCREASE_FREQUENCY BUTTON_SCROLL_UP
84 #define PLASMA_DECREASE_FREQUENCY BUTTON_SCROLL_DOWN
86 #elif (CONFIG_KEYPAD == GIGABEAT_S_PAD)
87 #define PLASMA_QUIT BUTTON_BACK
88 #define PLASMA_INCREASE_FREQUENCY BUTTON_UP
89 #define PLASMA_DECREASE_FREQUENCY BUTTON_DOWN
91 #elif (CONFIG_KEYPAD == MROBE100_PAD)
92 #define PLASMA_QUIT BUTTON_POWER
93 #define PLASMA_INCREASE_FREQUENCY BUTTON_UP
94 #define PLASMA_DECREASE_FREQUENCY BUTTON_DOWN
96 #elif (CONFIG_KEYPAD == IAUDIO_M3_PAD)
97 #define PLASMA_QUIT BUTTON_RC_REC
98 #define PLASMA_INCREASE_FREQUENCY BUTTON_RC_VOL_UP
99 #define PLASMA_DECREASE_FREQUENCY BUTTON_RC_VOL_DOWN
100 #define PLASMA_RC_QUIT BUTTON_REC
102 #elif (CONFIG_KEYPAD == COWOND2_PAD)
103 #define PLASMA_QUIT BUTTON_POWER
105 #elif (CONFIG_KEYPAD == IAUDIO67_PAD)
106 #define PLASMA_QUIT BUTTON_POWER
107 #define PLASMA_INCREASE_FREQUENCY BUTTON_RIGHT
108 #define PLASMA_DECREASE_FREQUENCY BUTTON_LEFT
109 #define PLASMA_RC_QUIT BUTTON_STOP
110 #define PLASMA_REGEN_COLORS BUTTON_PLAY
114 #ifdef HAVE_TOUCHSCREEN
116 #define PLASMA_QUIT BUTTON_TOPLEFT
118 #ifndef PLASMA_INCREASE_FREQUENCY
119 #define PLASMA_INCREASE_FREQUENCY BUTTON_MIDRIGHT
121 #ifndef PLASMA_DECREASE_FREQUENCY
122 #define PLASMA_DECREASE_FREQUENCY BUTTON_MIDLEFT
124 #endif /* HAVE_TOUCHSCREEN */
127 #define PLASMA_QUIT BUTTON_OFF
129 #ifndef PLASMA_INCREASE_FREQUENCY
130 #define PLASMA_INCREASE_FREQUENCY BUTTON_UP
132 #ifndef PLASMA_DECREASE_FREQUENCY
133 #define PLASMA_DECREASE_FREQUENCY BUTTON_DOWN
136 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD)
137 #define PLASMA_RC_QUIT BUTTON_RC_STOP
140 #ifdef HAVE_LCD_COLOR
141 #if CONFIG_KEYPAD == IAUDIO_X5M5_PAD
142 #define PLASMA_REGEN_COLORS BUTTON_PLAY
143 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
144 #define PLASMA_REGEN_COLORS BUTTON_PLAY
145 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
146 (CONFIG_KEYPAD == SANSA_C200_PAD)
147 #define PLASMA_REGEN_COLORS BUTTON_SELECT
148 #elif CONFIG_KEYPAD == IPOD_4G_PAD
149 #define PLASMA_REGEN_COLORS BUTTON_SELECT
150 #elif CONFIG_KEYPAD == IRIVER_H300_PAD
151 #define PLASMA_REGEN_COLORS BUTTON_SELECT
152 #elif CONFIG_KEYPAD == GIGABEAT_PAD
153 #define PLASMA_REGEN_COLORS BUTTON_SELECT
154 #elif CONFIG_KEYPAD == GIGABEAT_S_PAD
155 #define PLASMA_REGEN_COLORS BUTTON_SELECT
157 #ifdef HAVE_TOUCHSCREEN
158 #ifndef PLASMA_REGEN_COLORS
159 #define PLASMA_REGEN_COLORS BUTTON_CENTER
161 #endif /* HAVE_TOUCHSCREEN */
162 #endif /* HAVE_LCD_COLOR */
167 * Main wave function so we don't have to re-calc the sine
168 * curve every time. Mess around WAV_AMP and FREQ to make slighlty
169 * weirder looking plasmas!
172 static void wave_table_generate(void)
177 wave_array
[i
] = (unsigned char)((WAV_AMP
178 * (sin_int((i
* 360 * plasma_frequency
) / 256))) / 16384);
182 #ifdef HAVE_LCD_COLOR
183 /* Make a smooth colour cycle. */
184 void shades_generate(int time
)
187 unsigned red
, green
, blue
;
188 unsigned r
= time
* redfactor
+ redphase
;
189 unsigned g
= time
* greenfactor
+ greenphase
;
190 unsigned b
= time
* bluefactor
+ bluephase
;
192 for(i
=0; i
< 256; ++i
)
194 r
&= 0xFF; g
&= 0xFF; b
&= 0xFF;
206 colours
[i
] = LCD_RGBPACK(red
, green
, blue
);
212 /* Make a smooth shade from black into white and back into black again. */
213 static void shades_generate(void)
217 for(i
=0; i
< 256; ++i
)
227 void cleanup(void *parameter
)
231 #ifndef HAVE_LCD_COLOR
234 /* Turn on backlight timeout (revert to settings) */
235 backlight_use_settings(rb
); /* backlight control in lib/helper.c */
239 * Main function that also contain the main plasma
245 plasma_frequency
= 1;
247 unsigned char p1
,p2
,p3
,p4
,t1
,t2
,t3
,t4
, z
;
248 #ifdef HAVE_LCD_COLOR
255 /*Generate the neccesary pre calced stuff*/
256 wave_table_generate();
258 #ifndef HAVE_LCD_COLOR
259 shades_generate(); /* statically */
261 /* get the remainder of the plugin buffer */
262 gbuf
= (unsigned char *) rb
->plugin_get_buffer(&gbuf_size
);
264 grey_init(rb
, gbuf
, gbuf_size
, GREY_ON_COP
, LCD_WIDTH
, LCD_HEIGHT
, NULL
);
265 /* switch on greyscale overlay */
275 #ifdef HAVE_LCD_COLOR
276 shades_generate(time
++); /* dynamically */
277 ptr
= rb
->lcd_framebuffer
;
283 for(y
= 0; y
< LCD_HEIGHT
; ++y
)
287 for(x
= 0; x
< LCD_WIDTH
; ++x
)
289 z
= wave_array
[t1
] + wave_array
[t2
] + wave_array
[t3
]
303 #ifdef HAVE_LCD_COLOR
306 grey_ub_gray_bitmap(greybuffer
, 0, 0, LCD_WIDTH
, LCD_HEIGHT
);
309 button
= rb
->button_get(false);
313 #ifdef PLASMA_RC_QUIT
321 case (PLASMA_INCREASE_FREQUENCY
):
323 wave_table_generate();
326 case (PLASMA_DECREASE_FREQUENCY
):
327 if(plasma_frequency
>1)
330 wave_table_generate();
333 #ifdef HAVE_LCD_COLOR
334 case (PLASMA_REGEN_COLORS
):
335 redfactor
=rb
->rand()%4;
336 greenfactor
=rb
->rand()%4;
337 bluefactor
=rb
->rand()%4;
338 redphase
=rb
->rand()%256;
339 greenphase
=rb
->rand()%256;
340 bluephase
=rb
->rand()%256;
345 if (rb
->default_event_handler_ex(button
, cleanup
, NULL
)
346 == SYS_USB_CONNECTED
)
347 return PLUGIN_USB_CONNECTED
;
353 /*************************** Plugin entry point ****************************/
355 enum plugin_status
plugin_start(const struct plugin_api
* api
, const void* parameter
)
359 rb
= api
; /* copy to global api pointer */
362 rb
->lcd_set_backdrop(NULL
);
364 /* Turn off backlight timeout */
365 backlight_force_on(rb
); /* backlight control in lib/helper.c */
372 #endif /* HAVE_LCD_BITMAP */