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
102 #elif CONFIG_KEYPAD == SAMSUNG_YH_PAD
103 #define GREYSCALE_SHIFT BUTTON_FFWD
104 #define GREYSCALE_UP BUTTON_UP
105 #define GREYSCALE_DOWN BUTTON_DOWN
106 #define GREYSCALE_LEFT BUTTON_LEFT
107 #define GREYSCALE_RIGHT BUTTON_RIGHT
108 #define GREYSCALE_OFF BUTTON_PLAY
112 #define GFX_HEIGHT (LCD_HEIGHT-8)
114 #define GFX_GREYTONE_WIDTH 86
115 #define GFX_GREYTONE_STEP 3
117 #define GFX_GREYTONE_WIDTH 128
118 #define GFX_GREYTONE_STEP 2
120 /******************************* Globals ***********************************/
123 static char pbuf
[32]; /* global printf buffer */
124 static unsigned char *gbuf
;
125 static size_t gbuf_size
= 0;
127 /**************************** main function ********************************/
129 void cleanup(void *parameter
)
133 grey_release(); /* switch off overlay and deinitialize */
134 /* Turn on backlight timeout (revert to settings) */
135 backlight_use_settings(); /* backlight control in lib/helper.c */
138 /* this is only a demo of what the framework can do */
143 int button
, scroll_amount
;
144 bool black_border
= false;
146 static const unsigned char rockbox
[] = {
147 /* ...........................................
148 * .####...###...###..#...#.####...###..#...#.
149 * .#...#.#...#.#...#.#..#..#...#.#...#..#.#..
150 * .####..#...#.#.....###...####..#...#...#...
151 * .#..#..#...#.#...#.#..#..#...#.#...#..#.#..
152 * .#...#..###...###..#...#.####...###..#...#.
153 * ...........................................
154 * 43 x 7 pixel, 1 bpp
156 0x00, 0x3E, 0x0A, 0x0A, 0x1A, 0x24, 0x00, 0x1C, 0x22, 0x22,
157 0x22, 0x1C, 0x00, 0x1C, 0x22, 0x22, 0x22, 0x14, 0x00, 0x3E,
158 0x08, 0x08, 0x14, 0x22, 0x00, 0x3E, 0x2A, 0x2A, 0x2A, 0x14,
159 0x00, 0x1C, 0x22, 0x22, 0x22, 0x1C, 0x00, 0x22, 0x14, 0x08,
163 static const unsigned char showing
[] = {
164 /* .......................................
165 * ..####.#...#..###..#...#.#.#...#..####.
166 * .#.....#...#.#...#.#...#.#.##..#.#.....
167 * ..###..#####.#...#.#.#.#.#.#.#.#.#..##.
168 * .....#.#...#.#...#.#.#.#.#.#..##.#...#.
169 * .####..#...#..###...#.#..#.#...#..####.
170 * .......................................
171 * 39 x 7 pixel, 1 bpp
173 0x00, 0x24, 0x2A, 0x2A, 0x2A, 0x12, 0x00, 0x3E, 0x08, 0x08,
174 0x08, 0x3E, 0x00, 0x1C, 0x22, 0x22, 0x22, 0x1C, 0x00, 0x1E,
175 0x20, 0x18, 0x20, 0x1E, 0x00, 0x3E, 0x00, 0x3E, 0x04, 0x08,
176 0x10, 0x3E, 0x00, 0x1C, 0x22, 0x22, 0x2A, 0x3A, 0x00
179 static const unsigned char grayscale_grey
[] = {
180 /* .......................................................
181 * ..####.####...###..#...#..####..###...###..#.....#####.
182 * .#.....#...#.#...#.#...#.#.....#...#.#...#.#.....#.....
183 * .#..##.####..#####..#.#...###..#.....#####.#.....####..
184 * .#...#.#..#..#...#...#.......#.#...#.#...#.#.....#.....
185 * ..####.#...#.#...#...#...####...###..#...#.#####.#####.
186 * .......................................................
187 * 55 x 7 pixel, 8 bpp
189 110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
190 110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
191 110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
192 110,110,110,110,110,110,110,
193 120,120, 20, 20, 20, 20,120,222,222,222,222,120,120,120, 24, 24,
194 24,120,120,226,120,120,120,226,120,120, 28, 28, 28, 28,120,120,
195 230,230,230,120,120,120, 32, 32, 32,120,120,234,120,120,120,120,
196 120, 36, 36, 36, 36, 36,120,
197 130, 20,130,130,130,130,130,222,130,130,130,222,130, 24,130,130,
198 130, 24,130,226,130,130,130,226,130, 28,130,130,130,130,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 140, 20,140,140, 20, 20,140,222,222,222,222,140,140, 24, 24, 24,
202 24, 24,140,140,226,140,226,140,140,140, 28, 28, 28,140,140,230,
203 140,140,140,140,140, 32, 32, 32, 32, 32,140,234,140,140,140,140,
204 140, 36, 36, 36, 36,140,140,
205 130, 20,130,130,130, 20,130,222,130,130,222,130,130, 24,130,130,
206 130, 24,130,130,130,226,130,130,130,130,130,130,130, 28,130,230,
207 130,130,130,230,130, 32,130,130,130, 32,130,234,130,130,130,130,
208 130, 36,130,130,130,130,130,
209 120,120, 20, 20, 20, 20,120,222,120,120,120,222,120, 24,120,120,
210 120, 24,120,120,120,226,120,120,120, 28, 28, 28, 28,120,120,120,
211 230,230,230,120,120, 32,120,120,120, 32,120,234,234,234,234,234,
212 120, 36, 36, 36, 36, 36,120,
213 110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
214 110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
215 110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
216 110,110,110,110,110,110,110
219 /* Turn off backlight timeout */
220 backlight_force_on(); /* backlight control in lib/helper.c */
222 rb
->lcd_setfont(FONT_SYSFIXED
); /* select default font */
224 /* get the remainder of the plugin buffer */
225 gbuf
= (unsigned char *) rb
->plugin_get_buffer(&gbuf_size
);
227 /* initialize the greyscale buffer:
228 Archos: 112 pixels wide, 7 rows (56 pixels) high.
229 H1x0: 160 pixels wide, 30 rows (120 pixels) high. */
230 if (!grey_init(gbuf
, gbuf_size
, GREY_BUFFERED
|GREY_ON_COP
,
231 LCD_WIDTH
, GFX_HEIGHT
, NULL
))
233 rb
->splash(HZ
, "Not enough memory.");
237 /* place greyscale overlay 1 row down */
238 grey_set_position(0, 8);
240 rb
->lcd_puts(0, 0, "Shades: 129");
243 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
246 grey_show(true); /* switch on greyscale overlay */
248 time
= *rb
->current_tick
; /* start time measurement */
250 grey_set_background(150);
251 grey_clear_display(); /* fill everything with grey 150 */
253 /* draw a dark grey line star background */
254 grey_set_foreground(80);
255 for (y
= 0; y
< GFX_HEIGHT
; y
+= 8) /* horizontal part */
257 grey_drawline(0, y
, (LCD_WIDTH
-1), (GFX_HEIGHT
-1) - y
); /*grey lines */
259 for (x
= 10; x
<= LCD_WIDTH
; x
+= 10) /* vertical part */
261 grey_drawline(x
, 0, (LCD_WIDTH
-1) - x
, (GFX_HEIGHT
-1)); /*grey lines */
264 grey_set_foreground(0);
265 grey_drawrect(0, 0, LCD_WIDTH
, GFX_HEIGHT
); /* black border */
267 /* draw grey tones */
268 for (i
= 0; i
< GFX_GREYTONE_WIDTH
; i
++)
270 x
= ((LCD_WIDTH
-GFX_GREYTONE_WIDTH
)/2) + i
;
271 grey_set_foreground(GFX_GREYTONE_STEP
* i
);
273 grey_vline(x
, (GFX_HEIGHT
/8), (GFX_HEIGHT
-GFX_HEIGHT
/8-1));
276 grey_set_drawmode(DRMODE_COMPLEMENT
);
277 /* invert rectangle (lower half) */
278 grey_fillrect((LCD_WIDTH
-GFX_GREYTONE_WIDTH
)/2, (GFX_HEIGHT
/2+1),
279 GFX_GREYTONE_WIDTH
, (GFX_HEIGHT
/2-GFX_HEIGHT
/8-1));
281 grey_hline((LCD_WIDTH
-GFX_GREYTONE_WIDTH
)/2,
282 (LCD_WIDTH
+GFX_GREYTONE_WIDTH
)/2, (GFX_HEIGHT
/2-1));
284 /* show bitmaps (1 bit and 8 bit) */
286 grey_set_drawinfo(DRMODE_SOLID
, 255, 100);
287 grey_mono_bitmap(rockbox
,
288 MAX((LCD_WIDTH
/2-47), ((LCD_WIDTH
-GFX_GREYTONE_WIDTH
)/2)),
289 (5*GFX_HEIGHT
/16-4), 43, 7);
291 grey_set_drawinfo(DRMODE_FG
, 0, 100);
292 grey_mono_bitmap(showing
, (LCD_WIDTH
/2+4) , (5*GFX_HEIGHT
/16-4), 39, 7);
294 grey_gray_bitmap(grayscale_grey
, ((LCD_WIDTH
-55)/2), (11*GFX_HEIGHT
/16-4),
299 time
= *rb
->current_tick
- time
; /* end time measurement */
301 rb
->snprintf(pbuf
, sizeof(pbuf
), "Shades: 129, %d.%02ds",
302 time
/ 100, time
% 100);
303 rb
->lcd_puts(0, 0, pbuf
);
304 grey_deferred_lcd_update(); /* schedule an lcd_update() */
305 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
306 rb
->cpu_boost(false);
309 /* drawing is now finished, play around with scrolling
310 * until you press OFF or connect USB
312 grey_set_background(255);
317 button
= rb
->button_get(true);
319 if (rb
->default_event_handler_ex(button
, cleanup
, NULL
)
320 == SYS_USB_CONNECTED
)
321 return PLUGIN_USB_CONNECTED
;
323 if (button
& GREYSCALE_SHIFT
)
327 grey_set_background(0);
335 grey_set_background(255);
336 black_border
= false;
340 if (button
& BUTTON_REPEAT
)
343 switch (button
& ~(GREYSCALE_SHIFT
| BUTTON_REPEAT
))
347 grey_scroll_left(scroll_amount
); /* scroll left */
351 case GREYSCALE_RIGHT
:
353 grey_scroll_right(scroll_amount
); /* scroll right */
359 grey_scroll_up(scroll_amount
); /* scroll up */
365 grey_scroll_down(scroll_amount
); /* scroll down */
368 #ifdef GREYSCALE_RC_OFF
369 case GREYSCALE_RC_OFF
:
379 /*************************** Plugin entry point ****************************/
381 enum plugin_status
plugin_start(const void* parameter
)
388 #endif /* #ifdef HAVE_LCD_BITMAP */