Fix warning about missing newline at the EOF
[maemo-rb.git] / apps / plugins / snow.c
blob6371a697da42667548993ea8c393aa57e4365531
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 Itai Shaked
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 **************************************************************************/
21 #include "plugin.h"
22 #include "lib/playergfx.h"
23 #include "lib/mylcd.h"
27 #ifdef HAVE_LCD_BITMAP
28 #define NUM_PARTICLES (LCD_WIDTH * LCD_HEIGHT / 72)
29 #define SNOW_HEIGHT LCD_HEIGHT
30 #define SNOW_WIDTH LCD_WIDTH
31 #else
32 #define NUM_PARTICLES 10
33 #define SNOW_HEIGHT 14
34 #define SNOW_WIDTH 20
35 #endif
37 /* variable button definitions */
38 #if CONFIG_KEYPAD == PLAYER_PAD
39 #define SNOW_QUIT BUTTON_STOP
41 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
42 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
43 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
44 #define SNOW_QUIT BUTTON_MENU
46 #elif (CONFIG_KEYPAD == IRIVER_IFP7XX_PAD) || \
47 (CONFIG_KEYPAD == SAMSUNG_YH_PAD)
48 #define SNOW_QUIT BUTTON_PLAY
50 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
51 (CONFIG_KEYPAD == SANSA_C200_PAD) || \
52 (CONFIG_KEYPAD == SANSA_CLIP_PAD) || \
53 (CONFIG_KEYPAD == SANSA_M200_PAD) || \
54 (CONFIG_KEYPAD == MROBE500_PAD) || \
55 (CONFIG_KEYPAD == IRIVER_H10_PAD) || \
56 (CONFIG_KEYPAD == MROBE100_PAD) || \
57 (CONFIG_KEYPAD == COWON_D2_PAD) || \
58 (CONFIG_KEYPAD == IAUDIO67_PAD) || \
59 (CONFIG_KEYPAD == ONDAVX747_PAD) || \
60 (CONFIG_KEYPAD == ONDAVX777_PAD) || \
61 (CONFIG_KEYPAD == GIGABEAT_PAD) || \
62 (CONFIG_KEYPAD == IAUDIO_X5M5_PAD) || \
63 (CONFIG_KEYPAD == SANSA_CONNECT_PAD)
64 #define SNOW_QUIT BUTTON_POWER
66 #elif (CONFIG_KEYPAD == SANSA_FUZE_PAD)
67 #define SNOW_QUIT (BUTTON_HOME|BUTTON_REPEAT)
69 #elif (CONFIG_KEYPAD == GIGABEAT_S_PAD) || \
70 (CONFIG_KEYPAD == CREATIVEZVM_PAD) || \
71 (CONFIG_KEYPAD == SAMSUNG_YPR0_PAD)
72 #define SNOW_QUIT BUTTON_BACK
74 #elif (CONFIG_KEYPAD == PHILIPS_HDD1630_PAD) || \
75 (CONFIG_KEYPAD == PHILIPS_HDD6330_PAD) || \
76 (CONFIG_KEYPAD == PHILIPS_SA9200_PAD)
77 #define SNOW_QUIT BUTTON_POWER
79 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
80 #define SNOW_QUIT BUTTON_REC
81 #define SNOW_RC_QUIT BUTTON_RC_REC
83 #elif CONFIG_KEYPAD == PBELL_VIBE500_PAD
84 #define SNOW_QUIT BUTTON_REC
86 #elif CONFIG_KEYPAD == MPIO_HD200_PAD
87 #define SNOW_QUIT (BUTTON_REC|BUTTON_PLAY)
89 #elif CONFIG_KEYPAD == MPIO_HD300_PAD
90 #define SNOW_QUIT (BUTTON_REC|BUTTON_REPEAT)
92 #elif CONFIG_KEYPAD == SANSA_FUZEPLUS_PAD
93 #define SNOW_QUIT BUTTON_POWER
95 #else
96 #define SNOW_QUIT BUTTON_OFF
97 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD)
98 #define SNOW_RC_QUIT BUTTON_RC_STOP
99 #endif
100 #endif
102 static short particles[NUM_PARTICLES][2];
104 #ifdef HAVE_LCD_BITMAP
105 #if LCD_WIDTH >= 160
106 #define FLAKE_WIDTH 5
107 static const unsigned char flake[] = {0x0a,0x04,0x1f,0x04,0x0a};
108 #else
109 #define FLAKE_WIDTH 3
110 static const unsigned char flake[] = {0x02,0x07,0x02};
111 #endif
112 #endif
114 static bool particle_exists(int particle)
116 if (particles[particle][0]>=0 && particles[particle][1]>=0 &&
117 particles[particle][0]<SNOW_WIDTH && particles[particle][1]<SNOW_HEIGHT)
118 return true;
119 else
120 return false;
123 static int create_particle(void)
125 int i;
127 for (i=0; i<NUM_PARTICLES; i++) {
128 if (!particle_exists(i)) {
129 particles[i][0]=(rb->rand()%SNOW_WIDTH);
130 particles[i][1]=0;
131 return i;
134 return -1;
137 static void snow_move(void)
139 int i;
141 if (!(rb->rand()%2))
142 create_particle();
144 for (i=0; i<NUM_PARTICLES; i++) {
145 if (particle_exists(i)) {
146 mylcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
147 #ifdef HAVE_LCD_BITMAP
148 rb->lcd_fillrect(particles[i][0],particles[i][1],
149 FLAKE_WIDTH,FLAKE_WIDTH);
150 #else
151 pgfx_drawpixel(particles[i][0],particles[i][1]);
152 #endif
153 mylcd_set_drawmode(DRMODE_SOLID);
154 #ifdef HAVE_REMOTE_LCD
155 if (particles[i][0] <= LCD_REMOTE_WIDTH
156 && particles[i][1] <= LCD_REMOTE_HEIGHT) {
157 rb->lcd_remote_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
158 rb->lcd_remote_fillrect(particles[i][0],particles[i][1],
159 FLAKE_WIDTH,FLAKE_WIDTH);
160 rb->lcd_remote_set_drawmode(DRMODE_SOLID);
162 #endif
163 switch ((rb->rand()%7)) {
164 case 0:
165 particles[i][0]++;
166 break;
168 case 1:
169 particles[i][0]--;
170 break;
172 case 2:
173 break;
175 default:
176 particles[i][1]++;
177 break;
179 if (particle_exists(i))
180 #ifdef HAVE_LCD_BITMAP
181 rb->lcd_mono_bitmap(flake,particles[i][0],particles[i][1],
182 FLAKE_WIDTH,FLAKE_WIDTH);
183 #else
184 pgfx_drawpixel(particles[i][0],particles[i][1]);
185 #endif
186 #ifdef HAVE_REMOTE_LCD
187 if (particles[i][0] <= LCD_REMOTE_WIDTH
188 && particles[i][1] <= LCD_REMOTE_HEIGHT) {
189 rb->lcd_remote_mono_bitmap(flake,particles[i][0],particles[i][1],
190 FLAKE_WIDTH,FLAKE_WIDTH);
192 #endif
198 static void snow_init(void)
200 int i;
202 for (i=0; i<NUM_PARTICLES; i++) {
203 particles[i][0]=-1;
204 particles[i][1]=-1;
206 #ifdef HAVE_LCD_CHARCELLS
207 pgfx_display(0, 0); /* display three times */
208 pgfx_display(4, 0);
209 pgfx_display(8, 0);
210 #endif
211 mylcd_clear_display();
212 #ifdef HAVE_REMOTE_LCD
213 rb->lcd_remote_clear_display();
214 #endif
217 enum plugin_status plugin_start(const void* parameter)
219 int button;
220 (void)(parameter);
222 #ifdef HAVE_LCD_CHARCELLS
223 if (!pgfx_init(4, 2))
225 rb->splash(HZ*2, "Old LCD :(");
226 return PLUGIN_OK;
228 #endif
229 #ifdef HAVE_LCD_COLOR
230 rb->lcd_clear_display();
231 rb->lcd_set_foreground(LCD_WHITE);
232 rb->lcd_set_background(LCD_DEFAULT_BG);
233 #endif
234 snow_init();
235 while (1) {
236 snow_move();
237 mylcd_update();
238 #ifdef HAVE_REMOTE_LCD
239 rb->lcd_remote_update();
240 #endif
241 rb->sleep(HZ/20);
243 button = rb->button_get(false);
245 if (button == SNOW_QUIT
246 #ifdef SNOW_RC_QUIT
247 || button == SNOW_RC_QUIT
248 #endif
251 #ifdef HAVE_LCD_CHARCELLS
252 pgfx_release();
253 #endif
254 return PLUGIN_OK;
256 else
257 if (rb->default_event_handler(button) == SYS_USB_CONNECTED)
259 #ifdef HAVE_LCD_CHARCELLS
260 pgfx_release();
261 #endif
262 return PLUGIN_USB_CONNECTED;