1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Grayscale demo plugin
12 * Copyright (C) 2004 Jens Arnold
14 * All files in this archive are subject to the GNU General Public License.
15 * See the file COPYING in the source tree root for full license agreement.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
25 #if defined(HAVE_LCD_BITMAP) && (LCD_DEPTH < 4)
30 /* variable button definitions */
31 #if CONFIG_KEYPAD == RECORDER_PAD
32 #define GRAYSCALE_SHIFT BUTTON_ON
33 #define GRAYSCALE_UP BUTTON_UP
34 #define GRAYSCALE_DOWN BUTTON_DOWN
35 #define GRAYSCALE_LEFT BUTTON_LEFT
36 #define GRAYSCALE_RIGHT BUTTON_RIGHT
37 #define GRAYSCALE_OFF BUTTON_OFF
39 #elif CONFIG_KEYPAD == ONDIO_PAD
40 #define GRAYSCALE_SHIFT BUTTON_MENU
41 #define GRAYSCALE_UP BUTTON_UP
42 #define GRAYSCALE_DOWN BUTTON_DOWN
43 #define GRAYSCALE_LEFT BUTTON_LEFT
44 #define GRAYSCALE_RIGHT BUTTON_RIGHT
45 #define GRAYSCALE_OFF BUTTON_OFF
47 #elif CONFIG_KEYPAD == IRIVER_H100_PAD
48 #define GRAYSCALE_SHIFT BUTTON_ON
49 #define GRAYSCALE_UP BUTTON_UP
50 #define GRAYSCALE_DOWN BUTTON_DOWN
51 #define GRAYSCALE_LEFT BUTTON_LEFT
52 #define GRAYSCALE_RIGHT BUTTON_RIGHT
53 #define GRAYSCALE_OFF BUTTON_OFF
55 #define GRAYSCALE_RC_OFF BUTTON_RC_STOP
57 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) || \
58 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
59 #define GRAYSCALE_SHIFT BUTTON_SELECT
60 #define GRAYSCALE_UP BUTTON_SCROLL_BACK
61 #define GRAYSCALE_DOWN BUTTON_SCROLL_FWD
62 #define GRAYSCALE_LEFT BUTTON_LEFT
63 #define GRAYSCALE_RIGHT BUTTON_RIGHT
64 #define GRAYSCALE_OFF BUTTON_MENU
66 #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
67 #define GRAYSCALE_SHIFT BUTTON_PLAY
68 #define GRAYSCALE_UP BUTTON_UP
69 #define GRAYSCALE_DOWN BUTTON_DOWN
70 #define GRAYSCALE_LEFT BUTTON_LEFT
71 #define GRAYSCALE_RIGHT BUTTON_RIGHT
72 #define GRAYSCALE_OFF BUTTON_EQ
75 #define GFX_HEIGHT (LCD_HEIGHT-8)
77 #define GFX_GRAYTONE_WIDTH 86
78 #define GFX_GRAYTONE_STEP 3
80 #define GFX_GRAYTONE_WIDTH 128
81 #define GFX_GRAYTONE_STEP 2
83 /******************************* Globals ***********************************/
85 static struct plugin_api
* rb
; /* global api struct pointer */
86 static char pbuf
[32]; /* global printf buffer */
87 static unsigned char *gbuf
;
88 static size_t gbuf_size
= 0;
90 /**************************** main function ********************************/
92 void cleanup(void *parameter
)
96 gray_release(); /* switch off overlay and deinitialize */
97 /* Turn on backlight timeout (revert to settings) */
98 backlight_use_settings(rb
); /* backlight control in lib/helper.c */
101 /* this is only a demo of what the framework can do */
106 int button
, scroll_amount
;
107 bool black_border
= false;
109 static const unsigned char rockbox
[] = {
110 /* ...........................................
111 * .####...###...###..#...#.####...###..#...#.
112 * .#...#.#...#.#...#.#..#..#...#.#...#..#.#..
113 * .####..#...#.#.....###...####..#...#...#...
114 * .#..#..#...#.#...#.#..#..#...#.#...#..#.#..
115 * .#...#..###...###..#...#.####...###..#...#.
116 * ...........................................
117 * 43 x 7 pixel, 1 bpp
119 0x00, 0x3E, 0x0A, 0x0A, 0x1A, 0x24, 0x00, 0x1C, 0x22, 0x22,
120 0x22, 0x1C, 0x00, 0x1C, 0x22, 0x22, 0x22, 0x14, 0x00, 0x3E,
121 0x08, 0x08, 0x14, 0x22, 0x00, 0x3E, 0x2A, 0x2A, 0x2A, 0x14,
122 0x00, 0x1C, 0x22, 0x22, 0x22, 0x1C, 0x00, 0x22, 0x14, 0x08,
126 static const unsigned char showing
[] = {
127 /* .......................................
128 * ..####.#...#..###..#...#.#.#...#..####.
129 * .#.....#...#.#...#.#...#.#.##..#.#.....
130 * ..###..#####.#...#.#.#.#.#.#.#.#.#..##.
131 * .....#.#...#.#...#.#.#.#.#.#..##.#...#.
132 * .####..#...#..###...#.#..#.#...#..####.
133 * .......................................
134 * 39 x 7 pixel, 1 bpp
136 0x00, 0x24, 0x2A, 0x2A, 0x2A, 0x12, 0x00, 0x3E, 0x08, 0x08,
137 0x08, 0x3E, 0x00, 0x1C, 0x22, 0x22, 0x22, 0x1C, 0x00, 0x1E,
138 0x20, 0x18, 0x20, 0x1E, 0x00, 0x3E, 0x00, 0x3E, 0x04, 0x08,
139 0x10, 0x3E, 0x00, 0x1C, 0x22, 0x22, 0x2A, 0x3A, 0x00
142 static const unsigned char grayscale_gray
[] = {
143 /* .......................................................
144 * ..####.####...###..#...#..####..###...###..#.....#####.
145 * .#.....#...#.#...#.#...#.#.....#...#.#...#.#.....#.....
146 * .#..##.####..#####..#.#...###..#.....#####.#.....####..
147 * .#...#.#..#..#...#...#.......#.#...#.#...#.#.....#.....
148 * ..####.#...#.#...#...#...####...###..#...#.#####.#####.
149 * .......................................................
150 * 55 x 7 pixel, 8 bpp
152 110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
153 110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
154 110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
155 110,110,110,110,110,110,110,
156 120,120, 20, 20, 20, 20,120,222,222,222,222,120,120,120, 24, 24,
157 24,120,120,226,120,120,120,226,120,120, 28, 28, 28, 28,120,120,
158 230,230,230,120,120,120, 32, 32, 32,120,120,234,120,120,120,120,
159 120, 36, 36, 36, 36, 36,120,
160 130, 20,130,130,130,130,130,222,130,130,130,222,130, 24,130,130,
161 130, 24,130,226,130,130,130,226,130, 28,130,130,130,130,130,230,
162 130,130,130,230,130, 32,130,130,130, 32,130,234,130,130,130,130,
163 130, 36,130,130,130,130,130,
164 140, 20,140,140, 20, 20,140,222,222,222,222,140,140, 24, 24, 24,
165 24, 24,140,140,226,140,226,140,140,140, 28, 28, 28,140,140,230,
166 140,140,140,140,140, 32, 32, 32, 32, 32,140,234,140,140,140,140,
167 140, 36, 36, 36, 36,140,140,
168 130, 20,130,130,130, 20,130,222,130,130,222,130,130, 24,130,130,
169 130, 24,130,130,130,226,130,130,130,130,130,130,130, 28,130,230,
170 130,130,130,230,130, 32,130,130,130, 32,130,234,130,130,130,130,
171 130, 36,130,130,130,130,130,
172 120,120, 20, 20, 20, 20,120,222,120,120,120,222,120, 24,120,120,
173 120, 24,120,120,120,226,120,120,120, 28, 28, 28, 28,120,120,120,
174 230,230,230,120,120, 32,120,120,120, 32,120,234,234,234,234,234,
175 120, 36, 36, 36, 36, 36,120,
176 110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
177 110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
178 110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
179 110,110,110,110,110,110,110
182 /* Turn off backlight timeout */
183 backlight_force_on(rb
); /* backlight control in lib/helper.c */
185 rb
->lcd_setfont(FONT_SYSFIXED
); /* select default font */
187 /* get the remainder of the plugin buffer */
188 gbuf
= (unsigned char *) rb
->plugin_get_buffer(&gbuf_size
);
190 /* initialize the greyscale buffer:
191 Archos: 112 pixels wide, 7 rows (56 pixels) high, (try to) reserve
192 32 bitplanes for 33 shades of grey.
193 H1x0: 160 pixels wide, 30 rows (120 pixels) high, (try to) reserve
194 32 bitplanes for 33 shades of grey. */
195 shades
= gray_init(rb
, gbuf
, gbuf_size
, true, LCD_WIDTH
, GFX_HEIGHT
,
198 /* place greyscale overlay 1 row down */
199 gray_set_position(0, 8);
201 rb
->snprintf(pbuf
, sizeof(pbuf
), "Shades: %d", shades
);
202 rb
->lcd_puts(0, 0, pbuf
);
205 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
208 gray_show(true); /* switch on greyscale overlay */
210 time
= *rb
->current_tick
; /* start time measurement */
212 gray_set_background(150);
213 gray_clear_display(); /* fill everything with grey 150 */
215 /* draw a dark grey line star background */
216 gray_set_foreground(80);
217 for (y
= 0; y
< GFX_HEIGHT
; y
+= 8) /* horizontal part */
219 gray_drawline(0, y
, (LCD_WIDTH
-1), (GFX_HEIGHT
-1) - y
); /*grey lines */
221 for (x
= 10; x
<= LCD_WIDTH
; x
+= 10) /* vertical part */
223 gray_drawline(x
, 0, (LCD_WIDTH
-1) - x
, (GFX_HEIGHT
-1)); /*grey lines */
226 gray_set_foreground(0);
227 gray_drawrect(0, 0, LCD_WIDTH
, GFX_HEIGHT
); /* black border */
229 /* draw grey tones */
230 for (i
= 0; i
< GFX_GRAYTONE_WIDTH
; i
++)
232 x
= ((LCD_WIDTH
-GFX_GRAYTONE_WIDTH
)/2) + i
;
233 gray_set_foreground(GFX_GRAYTONE_STEP
* i
);
235 gray_vline(x
, (GFX_HEIGHT
/8), (GFX_HEIGHT
-GFX_HEIGHT
/8-1));
238 gray_set_drawmode(DRMODE_COMPLEMENT
);
239 /* invert rectangle (lower half) */
240 gray_fillrect((LCD_WIDTH
-GFX_GRAYTONE_WIDTH
)/2, (GFX_HEIGHT
/2+1),
241 GFX_GRAYTONE_WIDTH
, (GFX_HEIGHT
/2-GFX_HEIGHT
/8-1));
243 gray_hline((LCD_WIDTH
-GFX_GRAYTONE_WIDTH
)/2,
244 (LCD_WIDTH
+GFX_GRAYTONE_WIDTH
)/2, (GFX_HEIGHT
/2-1));
246 /* show bitmaps (1 bit and 8 bit) */
248 gray_set_drawinfo(DRMODE_SOLID
, 255, 100);
249 gray_mono_bitmap(rockbox
,
250 MAX((LCD_WIDTH
/2-47), ((LCD_WIDTH
-GFX_GRAYTONE_WIDTH
)/2)),
251 (5*GFX_HEIGHT
/16-4), 43, 7);
253 gray_set_drawinfo(DRMODE_FG
, 0, 100);
254 gray_mono_bitmap(showing
, (LCD_WIDTH
/2+4) , (5*GFX_HEIGHT
/16-4), 39, 7);
256 gray_gray_bitmap(grayscale_gray
, ((LCD_WIDTH
-55)/2), (11*GFX_HEIGHT
/16-4),
261 time
= *rb
->current_tick
- time
; /* end time measurement */
263 rb
->snprintf(pbuf
, sizeof(pbuf
), "Shades: %d, %d.%02ds", shades
,
264 time
/ 100, time
% 100);
265 rb
->lcd_puts(0, 0, pbuf
);
266 gray_deferred_lcd_update(); /* schedule an lcd_update() */
267 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
268 rb
->cpu_boost(false);
271 /* drawing is now finished, play around with scrolling
272 * until you press OFF or connect USB
274 gray_set_background(255);
279 button
= rb
->button_get(true);
281 if (rb
->default_event_handler_ex(button
, cleanup
, NULL
)
282 == SYS_USB_CONNECTED
)
283 return PLUGIN_USB_CONNECTED
;
285 if (button
& GRAYSCALE_SHIFT
)
289 gray_set_background(0);
297 gray_set_background(255);
298 black_border
= false;
302 if (button
& BUTTON_REPEAT
)
305 switch (button
& ~(GRAYSCALE_SHIFT
| BUTTON_REPEAT
))
309 gray_scroll_left(scroll_amount
); /* scroll left */
313 case GRAYSCALE_RIGHT
:
315 gray_scroll_right(scroll_amount
); /* scroll right */
321 gray_scroll_up(scroll_amount
); /* scroll up */
327 gray_scroll_down(scroll_amount
); /* scroll down */
330 #ifdef GRAYSCALE_RC_OFF
331 case GRAYSCALE_RC_OFF
:
341 /*************************** Plugin entry point ****************************/
343 enum plugin_status
plugin_start(struct plugin_api
* api
, void* parameter
)
345 rb
= api
; /* copy to global api pointer */
351 #endif /* #ifdef HAVE_LCD_BITMAP */