1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Greyscale demo plugin
12 * Copyright (C) 2004-2008 Jens Arnold
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
22 ****************************************************************************/
25 #include "lib/helper.h"
27 #if defined(HAVE_LCD_BITMAP) && (LCD_DEPTH < 4)
32 /* variable button definitions */
33 #if CONFIG_KEYPAD == RECORDER_PAD
34 #define GREYSCALE_SHIFT BUTTON_ON
35 #define GREYSCALE_UP BUTTON_UP
36 #define GREYSCALE_DOWN BUTTON_DOWN
37 #define GREYSCALE_LEFT BUTTON_LEFT
38 #define GREYSCALE_RIGHT BUTTON_RIGHT
39 #define GREYSCALE_OFF BUTTON_OFF
41 #elif CONFIG_KEYPAD == ONDIO_PAD
42 #define GREYSCALE_SHIFT BUTTON_MENU
43 #define GREYSCALE_UP BUTTON_UP
44 #define GREYSCALE_DOWN BUTTON_DOWN
45 #define GREYSCALE_LEFT BUTTON_LEFT
46 #define GREYSCALE_RIGHT BUTTON_RIGHT
47 #define GREYSCALE_OFF BUTTON_OFF
49 #elif CONFIG_KEYPAD == IRIVER_H100_PAD
50 #define GREYSCALE_SHIFT BUTTON_ON
51 #define GREYSCALE_UP BUTTON_UP
52 #define GREYSCALE_DOWN BUTTON_DOWN
53 #define GREYSCALE_LEFT BUTTON_LEFT
54 #define GREYSCALE_RIGHT BUTTON_RIGHT
55 #define GREYSCALE_OFF BUTTON_OFF
57 #define GREYSCALE_RC_OFF BUTTON_RC_STOP
59 #elif (CONFIG_KEYPAD == IAUDIO_X5M5_PAD) || (CONFIG_KEYPAD == MROBE100_PAD)
60 #define GREYSCALE_SHIFT BUTTON_PLAY /* won't work, but define it anyway */
61 #define GREYSCALE_UP BUTTON_UP
62 #define GREYSCALE_DOWN BUTTON_DOWN
63 #define GREYSCALE_LEFT BUTTON_LEFT
64 #define GREYSCALE_RIGHT BUTTON_RIGHT
65 #define GREYSCALE_OFF BUTTON_POWER
67 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) || \
68 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
69 #define GREYSCALE_SHIFT BUTTON_SELECT
70 #define GREYSCALE_UP BUTTON_SCROLL_BACK
71 #define GREYSCALE_DOWN BUTTON_SCROLL_FWD
72 #define GREYSCALE_LEFT BUTTON_LEFT
73 #define GREYSCALE_RIGHT BUTTON_RIGHT
74 #define GREYSCALE_OFF BUTTON_MENU
76 #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
77 #define GREYSCALE_SHIFT BUTTON_PLAY
78 #define GREYSCALE_UP BUTTON_UP
79 #define GREYSCALE_DOWN BUTTON_DOWN
80 #define GREYSCALE_LEFT BUTTON_LEFT
81 #define GREYSCALE_RIGHT BUTTON_RIGHT
82 #define GREYSCALE_OFF BUTTON_EQ
84 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
85 #define GREYSCALE_SHIFT BUTTON_RC_PLAY /* somewhat dangerous... */
86 #define GREYSCALE_UP BUTTON_RC_VOL_UP
87 #define GREYSCALE_DOWN BUTTON_RC_VOL_DOWN
88 #define GREYSCALE_LEFT BUTTON_RC_REW
89 #define GREYSCALE_RIGHT BUTTON_RC_FF
90 #define GREYSCALE_OFF BUTTON_RC_REC
92 #define GREYSCALE_RC_OFF BUTTON_REC
94 #elif CONFIG_KEYPAD == SANSA_CLIP_PAD
95 #define GREYSCALE_SHIFT BUTTON_SELECT
96 #define GREYSCALE_UP BUTTON_UP
97 #define GREYSCALE_DOWN BUTTON_DOWN
98 #define GREYSCALE_LEFT BUTTON_LEFT
99 #define GREYSCALE_RIGHT BUTTON_RIGHT
100 #define GREYSCALE_OFF BUTTON_POWER
104 #define GFX_HEIGHT (LCD_HEIGHT-8)
106 #define GFX_GREYTONE_WIDTH 86
107 #define GFX_GREYTONE_STEP 3
109 #define GFX_GREYTONE_WIDTH 128
110 #define GFX_GREYTONE_STEP 2
112 /******************************* Globals ***********************************/
115 static char pbuf
[32]; /* global printf buffer */
116 static unsigned char *gbuf
;
117 static size_t gbuf_size
= 0;
119 /**************************** main function ********************************/
121 void cleanup(void *parameter
)
125 grey_release(); /* switch off overlay and deinitialize */
126 /* Turn on backlight timeout (revert to settings) */
127 backlight_use_settings(); /* backlight control in lib/helper.c */
130 /* this is only a demo of what the framework can do */
135 int button
, scroll_amount
;
136 bool black_border
= false;
138 static const unsigned char rockbox
[] = {
139 /* ...........................................
140 * .####...###...###..#...#.####...###..#...#.
141 * .#...#.#...#.#...#.#..#..#...#.#...#..#.#..
142 * .####..#...#.#.....###...####..#...#...#...
143 * .#..#..#...#.#...#.#..#..#...#.#...#..#.#..
144 * .#...#..###...###..#...#.####...###..#...#.
145 * ...........................................
146 * 43 x 7 pixel, 1 bpp
148 0x00, 0x3E, 0x0A, 0x0A, 0x1A, 0x24, 0x00, 0x1C, 0x22, 0x22,
149 0x22, 0x1C, 0x00, 0x1C, 0x22, 0x22, 0x22, 0x14, 0x00, 0x3E,
150 0x08, 0x08, 0x14, 0x22, 0x00, 0x3E, 0x2A, 0x2A, 0x2A, 0x14,
151 0x00, 0x1C, 0x22, 0x22, 0x22, 0x1C, 0x00, 0x22, 0x14, 0x08,
155 static const unsigned char showing
[] = {
156 /* .......................................
157 * ..####.#...#..###..#...#.#.#...#..####.
158 * .#.....#...#.#...#.#...#.#.##..#.#.....
159 * ..###..#####.#...#.#.#.#.#.#.#.#.#..##.
160 * .....#.#...#.#...#.#.#.#.#.#..##.#...#.
161 * .####..#...#..###...#.#..#.#...#..####.
162 * .......................................
163 * 39 x 7 pixel, 1 bpp
165 0x00, 0x24, 0x2A, 0x2A, 0x2A, 0x12, 0x00, 0x3E, 0x08, 0x08,
166 0x08, 0x3E, 0x00, 0x1C, 0x22, 0x22, 0x22, 0x1C, 0x00, 0x1E,
167 0x20, 0x18, 0x20, 0x1E, 0x00, 0x3E, 0x00, 0x3E, 0x04, 0x08,
168 0x10, 0x3E, 0x00, 0x1C, 0x22, 0x22, 0x2A, 0x3A, 0x00
171 static const unsigned char grayscale_grey
[] = {
172 /* .......................................................
173 * ..####.####...###..#...#..####..###...###..#.....#####.
174 * .#.....#...#.#...#.#...#.#.....#...#.#...#.#.....#.....
175 * .#..##.####..#####..#.#...###..#.....#####.#.....####..
176 * .#...#.#..#..#...#...#.......#.#...#.#...#.#.....#.....
177 * ..####.#...#.#...#...#...####...###..#...#.#####.#####.
178 * .......................................................
179 * 55 x 7 pixel, 8 bpp
181 110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
182 110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
183 110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
184 110,110,110,110,110,110,110,
185 120,120, 20, 20, 20, 20,120,222,222,222,222,120,120,120, 24, 24,
186 24,120,120,226,120,120,120,226,120,120, 28, 28, 28, 28,120,120,
187 230,230,230,120,120,120, 32, 32, 32,120,120,234,120,120,120,120,
188 120, 36, 36, 36, 36, 36,120,
189 130, 20,130,130,130,130,130,222,130,130,130,222,130, 24,130,130,
190 130, 24,130,226,130,130,130,226,130, 28,130,130,130,130,130,230,
191 130,130,130,230,130, 32,130,130,130, 32,130,234,130,130,130,130,
192 130, 36,130,130,130,130,130,
193 140, 20,140,140, 20, 20,140,222,222,222,222,140,140, 24, 24, 24,
194 24, 24,140,140,226,140,226,140,140,140, 28, 28, 28,140,140,230,
195 140,140,140,140,140, 32, 32, 32, 32, 32,140,234,140,140,140,140,
196 140, 36, 36, 36, 36,140,140,
197 130, 20,130,130,130, 20,130,222,130,130,222,130,130, 24,130,130,
198 130, 24,130,130,130,226,130,130,130,130,130,130,130, 28,130,230,
199 130,130,130,230,130, 32,130,130,130, 32,130,234,130,130,130,130,
200 130, 36,130,130,130,130,130,
201 120,120, 20, 20, 20, 20,120,222,120,120,120,222,120, 24,120,120,
202 120, 24,120,120,120,226,120,120,120, 28, 28, 28, 28,120,120,120,
203 230,230,230,120,120, 32,120,120,120, 32,120,234,234,234,234,234,
204 120, 36, 36, 36, 36, 36,120,
205 110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
206 110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
207 110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
208 110,110,110,110,110,110,110
211 /* Turn off backlight timeout */
212 backlight_force_on(); /* backlight control in lib/helper.c */
214 rb
->lcd_setfont(FONT_SYSFIXED
); /* select default font */
216 /* get the remainder of the plugin buffer */
217 gbuf
= (unsigned char *) rb
->plugin_get_buffer(&gbuf_size
);
219 /* initialize the greyscale buffer:
220 Archos: 112 pixels wide, 7 rows (56 pixels) high.
221 H1x0: 160 pixels wide, 30 rows (120 pixels) high. */
222 if (!grey_init(gbuf
, gbuf_size
, GREY_BUFFERED
|GREY_ON_COP
,
223 LCD_WIDTH
, GFX_HEIGHT
, NULL
))
225 rb
->splash(HZ
, "Not enough memory.");
229 /* place greyscale overlay 1 row down */
230 grey_set_position(0, 8);
232 rb
->lcd_puts(0, 0, "Shades: 129");
235 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
238 grey_show(true); /* switch on greyscale overlay */
240 time
= *rb
->current_tick
; /* start time measurement */
242 grey_set_background(150);
243 grey_clear_display(); /* fill everything with grey 150 */
245 /* draw a dark grey line star background */
246 grey_set_foreground(80);
247 for (y
= 0; y
< GFX_HEIGHT
; y
+= 8) /* horizontal part */
249 grey_drawline(0, y
, (LCD_WIDTH
-1), (GFX_HEIGHT
-1) - y
); /*grey lines */
251 for (x
= 10; x
<= LCD_WIDTH
; x
+= 10) /* vertical part */
253 grey_drawline(x
, 0, (LCD_WIDTH
-1) - x
, (GFX_HEIGHT
-1)); /*grey lines */
256 grey_set_foreground(0);
257 grey_drawrect(0, 0, LCD_WIDTH
, GFX_HEIGHT
); /* black border */
259 /* draw grey tones */
260 for (i
= 0; i
< GFX_GREYTONE_WIDTH
; i
++)
262 x
= ((LCD_WIDTH
-GFX_GREYTONE_WIDTH
)/2) + i
;
263 grey_set_foreground(GFX_GREYTONE_STEP
* i
);
265 grey_vline(x
, (GFX_HEIGHT
/8), (GFX_HEIGHT
-GFX_HEIGHT
/8-1));
268 grey_set_drawmode(DRMODE_COMPLEMENT
);
269 /* invert rectangle (lower half) */
270 grey_fillrect((LCD_WIDTH
-GFX_GREYTONE_WIDTH
)/2, (GFX_HEIGHT
/2+1),
271 GFX_GREYTONE_WIDTH
, (GFX_HEIGHT
/2-GFX_HEIGHT
/8-1));
273 grey_hline((LCD_WIDTH
-GFX_GREYTONE_WIDTH
)/2,
274 (LCD_WIDTH
+GFX_GREYTONE_WIDTH
)/2, (GFX_HEIGHT
/2-1));
276 /* show bitmaps (1 bit and 8 bit) */
278 grey_set_drawinfo(DRMODE_SOLID
, 255, 100);
279 grey_mono_bitmap(rockbox
,
280 MAX((LCD_WIDTH
/2-47), ((LCD_WIDTH
-GFX_GREYTONE_WIDTH
)/2)),
281 (5*GFX_HEIGHT
/16-4), 43, 7);
283 grey_set_drawinfo(DRMODE_FG
, 0, 100);
284 grey_mono_bitmap(showing
, (LCD_WIDTH
/2+4) , (5*GFX_HEIGHT
/16-4), 39, 7);
286 grey_gray_bitmap(grayscale_grey
, ((LCD_WIDTH
-55)/2), (11*GFX_HEIGHT
/16-4),
291 time
= *rb
->current_tick
- time
; /* end time measurement */
293 rb
->snprintf(pbuf
, sizeof(pbuf
), "Shades: 129, %d.%02ds",
294 time
/ 100, time
% 100);
295 rb
->lcd_puts(0, 0, pbuf
);
296 grey_deferred_lcd_update(); /* schedule an lcd_update() */
297 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
298 rb
->cpu_boost(false);
301 /* drawing is now finished, play around with scrolling
302 * until you press OFF or connect USB
304 grey_set_background(255);
309 button
= rb
->button_get(true);
311 if (rb
->default_event_handler_ex(button
, cleanup
, NULL
)
312 == SYS_USB_CONNECTED
)
313 return PLUGIN_USB_CONNECTED
;
315 if (button
& GREYSCALE_SHIFT
)
319 grey_set_background(0);
327 grey_set_background(255);
328 black_border
= false;
332 if (button
& BUTTON_REPEAT
)
335 switch (button
& ~(GREYSCALE_SHIFT
| BUTTON_REPEAT
))
339 grey_scroll_left(scroll_amount
); /* scroll left */
343 case GREYSCALE_RIGHT
:
345 grey_scroll_right(scroll_amount
); /* scroll right */
351 grey_scroll_up(scroll_amount
); /* scroll up */
357 grey_scroll_down(scroll_amount
); /* scroll down */
360 #ifdef GREYSCALE_RC_OFF
361 case GREYSCALE_RC_OFF
:
371 /*************************** Plugin entry point ****************************/
373 enum plugin_status
plugin_start(const void* parameter
)
380 #endif /* #ifdef HAVE_LCD_BITMAP */