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 ****************************************************************************/
24 #if defined(HAVE_LCD_BITMAP) && (LCD_DEPTH < 4)
29 /* variable button definitions */
30 #if CONFIG_KEYPAD == RECORDER_PAD
31 #define GRAYSCALE_SHIFT BUTTON_ON
32 #define GRAYSCALE_UP BUTTON_UP
33 #define GRAYSCALE_DOWN BUTTON_DOWN
34 #define GRAYSCALE_LEFT BUTTON_LEFT
35 #define GRAYSCALE_RIGHT BUTTON_RIGHT
36 #define GRAYSCALE_OFF BUTTON_OFF
38 #elif CONFIG_KEYPAD == ONDIO_PAD
39 #define GRAYSCALE_SHIFT BUTTON_MENU
40 #define GRAYSCALE_UP BUTTON_UP
41 #define GRAYSCALE_DOWN BUTTON_DOWN
42 #define GRAYSCALE_LEFT BUTTON_LEFT
43 #define GRAYSCALE_RIGHT BUTTON_RIGHT
44 #define GRAYSCALE_OFF BUTTON_OFF
46 #elif CONFIG_KEYPAD == IRIVER_H100_PAD
47 #define GRAYSCALE_SHIFT BUTTON_ON
48 #define GRAYSCALE_UP BUTTON_UP
49 #define GRAYSCALE_DOWN BUTTON_DOWN
50 #define GRAYSCALE_LEFT BUTTON_LEFT
51 #define GRAYSCALE_RIGHT BUTTON_RIGHT
52 #define GRAYSCALE_OFF BUTTON_OFF
54 #define GRAYSCALE_RC_OFF BUTTON_RC_STOP
56 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) || \
57 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
58 #define GRAYSCALE_SHIFT BUTTON_SELECT
59 #define GRAYSCALE_UP BUTTON_SCROLL_BACK
60 #define GRAYSCALE_DOWN BUTTON_SCROLL_FWD
61 #define GRAYSCALE_LEFT BUTTON_LEFT
62 #define GRAYSCALE_RIGHT BUTTON_RIGHT
63 #define GRAYSCALE_OFF BUTTON_MENU
66 #define GFX_HEIGHT (LCD_HEIGHT-8)
68 #define GFX_GRAYTONE_WIDTH 86
69 #define GFX_GRAYTONE_STEP 3
71 #define GFX_GRAYTONE_WIDTH 128
72 #define GFX_GRAYTONE_STEP 2
74 /******************************* Globals ***********************************/
76 static struct plugin_api
* rb
; /* global api struct pointer */
77 static char pbuf
[32]; /* global printf buffer */
78 static unsigned char *gbuf
;
79 static size_t gbuf_size
= 0;
81 /**************************** main function ********************************/
83 void cleanup(void *parameter
)
87 gray_release(); /* switch off overlay and deinitialize */
88 /* restore normal backlight setting */
89 rb
->backlight_set_timeout(rb
->global_settings
->backlight_timeout
);
92 /* this is only a demo of what the framework can do */
97 int button
, scroll_amount
;
98 bool black_border
= false;
100 static const unsigned char rockbox
[] = {
101 /* ...........................................
102 * .####...###...###..#...#.####...###..#...#.
103 * .#...#.#...#.#...#.#..#..#...#.#...#..#.#..
104 * .####..#...#.#.....###...####..#...#...#...
105 * .#..#..#...#.#...#.#..#..#...#.#...#..#.#..
106 * .#...#..###...###..#...#.####...###..#...#.
107 * ...........................................
108 * 43 x 7 pixel, 1 bpp
110 0x00, 0x3E, 0x0A, 0x0A, 0x1A, 0x24, 0x00, 0x1C, 0x22, 0x22,
111 0x22, 0x1C, 0x00, 0x1C, 0x22, 0x22, 0x22, 0x14, 0x00, 0x3E,
112 0x08, 0x08, 0x14, 0x22, 0x00, 0x3E, 0x2A, 0x2A, 0x2A, 0x14,
113 0x00, 0x1C, 0x22, 0x22, 0x22, 0x1C, 0x00, 0x22, 0x14, 0x08,
117 static const unsigned char showing
[] = {
118 /* .......................................
119 * ..####.#...#..###..#...#.#.#...#..####.
120 * .#.....#...#.#...#.#...#.#.##..#.#.....
121 * ..###..#####.#...#.#.#.#.#.#.#.#.#..##.
122 * .....#.#...#.#...#.#.#.#.#.#..##.#...#.
123 * .####..#...#..###...#.#..#.#...#..####.
124 * .......................................
125 * 39 x 7 pixel, 1 bpp
127 0x00, 0x24, 0x2A, 0x2A, 0x2A, 0x12, 0x00, 0x3E, 0x08, 0x08,
128 0x08, 0x3E, 0x00, 0x1C, 0x22, 0x22, 0x22, 0x1C, 0x00, 0x1E,
129 0x20, 0x18, 0x20, 0x1E, 0x00, 0x3E, 0x00, 0x3E, 0x04, 0x08,
130 0x10, 0x3E, 0x00, 0x1C, 0x22, 0x22, 0x2A, 0x3A, 0x00
133 static const unsigned char grayscale_gray
[] = {
134 /* .......................................................
135 * ..####.####...###..#...#..####..###...###..#.....#####.
136 * .#.....#...#.#...#.#...#.#.....#...#.#...#.#.....#.....
137 * .#..##.####..#####..#.#...###..#.....#####.#.....####..
138 * .#...#.#..#..#...#...#.......#.#...#.#...#.#.....#.....
139 * ..####.#...#.#...#...#...####...###..#...#.#####.#####.
140 * .......................................................
141 * 55 x 7 pixel, 8 bpp
143 110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
144 110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
145 110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
146 110,110,110,110,110,110,110,
147 120,120, 20, 20, 20, 20,120,222,222,222,222,120,120,120, 24, 24,
148 24,120,120,226,120,120,120,226,120,120, 28, 28, 28, 28,120,120,
149 230,230,230,120,120,120, 32, 32, 32,120,120,234,120,120,120,120,
150 120, 36, 36, 36, 36, 36,120,
151 130, 20,130,130,130,130,130,222,130,130,130,222,130, 24,130,130,
152 130, 24,130,226,130,130,130,226,130, 28,130,130,130,130,130,230,
153 130,130,130,230,130, 32,130,130,130, 32,130,234,130,130,130,130,
154 130, 36,130,130,130,130,130,
155 140, 20,140,140, 20, 20,140,222,222,222,222,140,140, 24, 24, 24,
156 24, 24,140,140,226,140,226,140,140,140, 28, 28, 28,140,140,230,
157 140,140,140,140,140, 32, 32, 32, 32, 32,140,234,140,140,140,140,
158 140, 36, 36, 36, 36,140,140,
159 130, 20,130,130,130, 20,130,222,130,130,222,130,130, 24,130,130,
160 130, 24,130,130,130,226,130,130,130,130,130,130,130, 28,130,230,
161 130,130,130,230,130, 32,130,130,130, 32,130,234,130,130,130,130,
162 130, 36,130,130,130,130,130,
163 120,120, 20, 20, 20, 20,120,222,120,120,120,222,120, 24,120,120,
164 120, 24,120,120,120,226,120,120,120, 28, 28, 28, 28,120,120,120,
165 230,230,230,120,120, 32,120,120,120, 32,120,234,234,234,234,234,
166 120, 36, 36, 36, 36, 36,120,
167 110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
168 110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
169 110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
170 110,110,110,110,110,110,110
173 if (rb
->global_settings
->backlight_timeout
> 0)
174 rb
->backlight_set_timeout(1); /* keep the light on */
176 rb
->lcd_setfont(FONT_SYSFIXED
); /* select default font */
178 /* get the remainder of the plugin buffer */
179 gbuf
= (unsigned char *) rb
->plugin_get_buffer(&gbuf_size
);
181 /* initialize the greyscale buffer:
182 Archos: 112 pixels wide, 7 rows (56 pixels) high, (try to) reserve
183 32 bitplanes for 33 shades of grey.
184 H1x0: 160 pixels wide, 30 rows (120 pixels) high, (try to) reserve
185 32 bitplanes for 33 shades of grey. */
186 shades
= gray_init(rb
, gbuf
, gbuf_size
, true, LCD_WIDTH
, GFX_HEIGHT
,
189 /* place greyscale overlay 1 row down */
190 gray_set_position(0, 8);
192 rb
->snprintf(pbuf
, sizeof(pbuf
), "Shades: %d", shades
);
193 rb
->lcd_puts(0, 0, pbuf
);
196 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
199 gray_show(true); /* switch on greyscale overlay */
201 time
= *rb
->current_tick
; /* start time measurement */
203 gray_set_background(150);
204 gray_clear_display(); /* fill everything with grey 150 */
206 /* draw a dark grey line star background */
207 gray_set_foreground(80);
208 for (y
= 0; y
< GFX_HEIGHT
; y
+= 8) /* horizontal part */
210 gray_drawline(0, y
, (LCD_WIDTH
-1), (GFX_HEIGHT
-1) - y
); /*grey lines */
212 for (x
= 10; x
<= LCD_WIDTH
; x
+= 10) /* vertical part */
214 gray_drawline(x
, 0, (LCD_WIDTH
-1) - x
, (GFX_HEIGHT
-1)); /*grey lines */
217 gray_set_foreground(0);
218 gray_drawrect(0, 0, LCD_WIDTH
, GFX_HEIGHT
); /* black border */
220 /* draw grey tones */
221 for (i
= 0; i
< GFX_GRAYTONE_WIDTH
; i
++)
223 x
= ((LCD_WIDTH
-GFX_GRAYTONE_WIDTH
)/2) + i
;
224 gray_set_foreground(GFX_GRAYTONE_STEP
* i
);
226 gray_vline(x
, (GFX_HEIGHT
/8), (GFX_HEIGHT
-GFX_HEIGHT
/8-1));
229 gray_set_drawmode(DRMODE_COMPLEMENT
);
230 /* invert rectangle (lower half) */
231 gray_fillrect((LCD_WIDTH
-GFX_GRAYTONE_WIDTH
)/2, (GFX_HEIGHT
/2+1),
232 GFX_GRAYTONE_WIDTH
, (GFX_HEIGHT
/2-GFX_HEIGHT
/8-1));
234 gray_hline((LCD_WIDTH
-GFX_GRAYTONE_WIDTH
)/2,
235 (LCD_WIDTH
+GFX_GRAYTONE_WIDTH
)/2, (GFX_HEIGHT
/2-1));
237 /* show bitmaps (1 bit and 8 bit) */
239 gray_set_drawinfo(DRMODE_SOLID
, 255, 100);
240 gray_mono_bitmap(rockbox
,
241 MAX((LCD_WIDTH
/2-47), ((LCD_WIDTH
-GFX_GRAYTONE_WIDTH
)/2)),
242 (5*GFX_HEIGHT
/16-4), 43, 7);
244 gray_set_drawinfo(DRMODE_FG
, 0, 100);
245 gray_mono_bitmap(showing
, (LCD_WIDTH
/2+4) , (5*GFX_HEIGHT
/16-4), 39, 7);
247 gray_gray_bitmap(grayscale_gray
, ((LCD_WIDTH
-55)/2), (11*GFX_HEIGHT
/16-4),
252 time
= *rb
->current_tick
- time
; /* end time measurement */
254 rb
->snprintf(pbuf
, sizeof(pbuf
), "Shades: %d, %d.%02ds", shades
,
255 time
/ 100, time
% 100);
256 rb
->lcd_puts(0, 0, pbuf
);
257 gray_deferred_lcd_update(); /* schedule an lcd_update() */
258 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
259 rb
->cpu_boost(false);
262 /* drawing is now finished, play around with scrolling
263 * until you press OFF or connect USB
265 gray_set_background(255);
270 button
= rb
->button_get(true);
272 if (rb
->default_event_handler_ex(button
, cleanup
, NULL
)
273 == SYS_USB_CONNECTED
)
274 return PLUGIN_USB_CONNECTED
;
276 if (button
& GRAYSCALE_SHIFT
)
280 gray_set_background(0);
288 gray_set_background(255);
289 black_border
= false;
293 if (button
& BUTTON_REPEAT
)
296 switch (button
& ~(GRAYSCALE_SHIFT
| BUTTON_REPEAT
))
300 gray_scroll_left(scroll_amount
); /* scroll left */
304 case GRAYSCALE_RIGHT
:
306 gray_scroll_right(scroll_amount
); /* scroll right */
312 gray_scroll_up(scroll_amount
); /* scroll up */
318 gray_scroll_down(scroll_amount
); /* scroll down */
321 #ifdef GRAYSCALE_RC_OFF
322 case GRAYSCALE_RC_OFF
:
332 /*************************** Plugin entry point ****************************/
334 enum plugin_status
plugin_start(struct plugin_api
* api
, void* parameter
)
336 rb
= api
; /* copy to global api pointer */
342 #endif /* #ifdef HAVE_LCD_BITMAP */