1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
|
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Grayscale demo plugin
*
* Copyright (C) 2004 Jens Arnold
*
* All files in this archive are subject to the GNU General Public License.
* See the file COPYING in the source tree root for full license agreement.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#ifndef SIMULATOR /* not for simulator by now */
#include "plugin.h"
#if CONFIG_LCD == LCD_SSD1815 /* only for Recorder/Ondio displays */
#include "gray.h"
/* variable button definitions */
#if CONFIG_KEYPAD == RECORDER_PAD
#define GRAYSCALE_SHIFT BUTTON_ON
#elif CONFIG_KEYPAD == ONDIO_PAD
#define GRAYSCALE_SHIFT BUTTON_MENU
#endif
/******************************* Globals ***********************************/
static struct plugin_api* rb; /* global api struct pointer */
static char pbuf[32]; /* global printf buffer */
static unsigned char *gbuf;
static unsigned int gbuf_size = 0;
/**************************** main function ********************************/
void cleanup(void *parameter)
{
(void)parameter;
gray_release_buffer(); /* switch off overlay and deinitialize */
/* restore normal backlight setting */
rb->backlight_set_timeout(rb->global_settings->backlight_timeout);
}
/* this is only a demo of what the framework can do */
int main(void)
{
int shades, time;
int x, y, i;
int button, scroll_amount;
bool black_border;
static const unsigned char rockbox[] = {
/* ...........................................
* .####...###...###..#...#.####...###..#...#.
* .#...#.#...#.#...#.#..#..#...#.#...#..#.#..
* .####..#...#.#.....###...####..#...#...#...
* .#..#..#...#.#...#.#..#..#...#.#...#..#.#..
* .#...#..###...###..#...#.####...###..#...#.
* ...........................................
* 43 x 7 pixel, 1 bpp
*/
0x00, 0x3E, 0x0A, 0x0A, 0x1A, 0x24, 0x00, 0x1C, 0x22, 0x22,
0x22, 0x1C, 0x00, 0x1C, 0x22, 0x22, 0x22, 0x14, 0x00, 0x3E,
0x08, 0x08, 0x14, 0x22, 0x00, 0x3E, 0x2A, 0x2A, 0x2A, 0x14,
0x00, 0x1C, 0x22, 0x22, 0x22, 0x1C, 0x00, 0x22, 0x14, 0x08,
0x14, 0x22, 0x00
};
static const unsigned char showing[] = {
/* .......................................
* ..####.#...#..###..#...#.#.#...#..####.
* .#.....#...#.#...#.#...#.#.##..#.#.....
* ..###..#####.#...#.#.#.#.#.#.#.#.#..##.
* .....#.#...#.#...#.#.#.#.#.#..##.#...#.
* .####..#...#..###...#.#..#.#...#..####.
* .......................................
* 39 x 7 pixel, 1 bpp
*/
0x00, 0x24, 0x2A, 0x2A, 0x2A, 0x12, 0x00, 0x3E, 0x08, 0x08,
0x08, 0x3E, 0x00, 0x1C, 0x22, 0x22, 0x22, 0x1C, 0x00, 0x1E,
0x20, 0x18, 0x20, 0x1E, 0x00, 0x3E, 0x00, 0x3E, 0x04, 0x08,
0x10, 0x3E, 0x00, 0x1C, 0x22, 0x22, 0x2A, 0x3A, 0x00
};
static const unsigned char grayscale_gray[] = {
/* .......................................................
* ..####.####...###..#...#..####..###...###..#.....#####.
* .#.....#...#.#...#.#...#.#.....#...#.#...#.#.....#.....
* .#..##.####..#####..#.#...###..#.....#####.#.....####..
* .#...#.#..#..#...#...#.......#.#...#.#...#.#.....#.....
* ..####.#...#.#...#...#...####...###..#...#.#####.#####.
* .......................................................
* 55 x 7 pixel, 8 bpp
*/
110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
110,110,110,110,110,110,110,
120,120, 20, 20, 20, 20,120,222,222,222,222,120,120,120, 24, 24,
24,120,120,226,120,120,120,226,120,120, 28, 28, 28, 28,120,120,
230,230,230,120,120,120, 32, 32, 32,120,120,234,120,120,120,120,
120, 36, 36, 36, 36, 36,120,
130, 20,130,130,130,130,130,222,130,130,130,222,130, 24,130,130,
130, 24,130,226,130,130,130,226,130, 28,130,130,130,130,130,230,
130,130,130,230,130, 32,130,130,130, 32,130,234,130,130,130,130,
130, 36,130,130,130,130,130,
140, 20,140,140, 20, 20,140,222,222,222,222,140,140, 24, 24, 24,
24, 24,140,140,226,140,226,140,140,140, 28, 28, 28,140,140,230,
140,140,140,140,140, 32, 32, 32, 32, 32,140,234,140,140,140,140,
140, 36, 36, 36, 36,140,140,
130, 20,130,130,130, 20,130,222,130,130,222,130,130, 24,130,130,
130, 24,130,130,130,226,130,130,130,130,130,130,130, 28,130,230,
130,130,130,230,130, 32,130,130,130, 32,130,234,130,130,130,130,
130, 36,130,130,130,130,130,
120,120, 20, 20, 20, 20,120,222,120,120,120,222,120, 24,120,120,
120, 24,120,120,120,226,120,120,120, 28, 28, 28, 28,120,120,120,
230,230,230,120,120, 32,120,120,120, 32,120,234,234,234,234,234,
120, 36, 36, 36, 36, 36,120,
110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,
110,110,110,110,110,110,110
};
if (rb->global_settings->backlight_timeout > 0)
rb->backlight_set_timeout(1); /* keep the light on */
rb->lcd_setfont(FONT_SYSFIXED); /* select default font */
/* get the remainder of the plugin buffer */
gbuf = (unsigned char *) rb->plugin_get_buffer(&gbuf_size);
/* initialize the grayscale buffer:
* 112 pixels wide, 7 rows (56 pixels) high, (try to) reserve
* 32 bitplanes for 33 shades of gray. (uses 25268 bytes)*/
shades = gray_init_buffer(gbuf, gbuf_size, 112, 7, 32, NULL) + 1;
/* place grayscale overlay 1 row down */
gray_position_display(0, 1);
rb->snprintf(pbuf, sizeof(pbuf), "Shades: %d", shades);
rb->lcd_puts(0, 0, pbuf);
rb->lcd_update();
gray_show_display(true); /* switch on grayscale overlay */
time = *rb->current_tick; /* start time measurement */
gray_set_foreground(150);
gray_fillrect(0, 0, 112, 56); /* fill everything with gray 150 */
/* draw a dark gray line star background */
gray_set_foreground(80);
for (y = 0; y < 56; y += 8) /* horizontal part */
{
gray_drawline(0, y, 111, 55 - y); /* gray lines */
}
for (x = 10; x < 112; x += 10) /* vertical part */
{
gray_drawline(x, 0, 111 - x, 55); /* gray lines */
}
gray_set_foreground(0);
gray_drawrect(0, 0, 112, 56); /* black border */
/* draw gray tones */
for (i = 0; i < 86; i++)
{
x = 13 + i;
gray_set_foreground(3 * i);
gray_verline(x, 6, 49); /* vertical lines */
}
gray_set_drawmode(GRAY_DRAW_INVERSE);
gray_fillrect(13, 29, 86, 21); /* invert rectangle (lower half) */
gray_drawline(13, 27, 98, 27); /* invert a line */
/* show bitmaps (1 bit and 8 bit) */
gray_set_drawinfo(GRAY_DRAW_SOLID, 255, 100);
gray_drawbitmap(rockbox, 14, 13, 43, 7, 43); /* opaque */
gray_set_drawinfo(GRAY_DRAW_FG, 0, -1);
gray_drawbitmap(showing, 58, 13, 39, 7, 39); /* transparent */
gray_drawgraymap(grayscale_gray, 28, 35, 55, 7, 55);
time = *rb->current_tick - time; /* end time measurement */
rb->snprintf(pbuf, sizeof(pbuf), "Shades: %d, %d.%02ds", shades,
time / 100, time % 100);
rb->lcd_puts(0, 0, pbuf);
gray_deferred_update(); /* schedule an lcd_update() */
/* drawing is now finished, play around with scrolling
* until you press OFF or connect USB
*/
while (true)
{
scroll_amount = 1;
black_border = false;
button = rb->button_get(true);
if (rb->default_event_handler_ex(button, cleanup, NULL)
== SYS_USB_CONNECTED)
return PLUGIN_USB_CONNECTED;
if (button & GRAYSCALE_SHIFT)
black_border = true;
if (button & BUTTON_REPEAT)
scroll_amount = 4;
switch(button & ~(GRAYSCALE_SHIFT | BUTTON_REPEAT))
{
case BUTTON_LEFT:
gray_scroll_left(scroll_amount, black_border); /* scroll left */
break;
case BUTTON_RIGHT:
gray_scroll_right(scroll_amount, black_border); /* scroll right */
break;
case BUTTON_UP:
gray_scroll_up(scroll_amount, black_border); /* scroll up */
break;
case BUTTON_DOWN:
gray_scroll_down(scroll_amount, black_border); /* scroll down */
break;
case BUTTON_OFF:
cleanup(NULL);
return PLUGIN_OK;
}
}
}
/*************************** Plugin entry point ****************************/
enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
{
/* this macro should be called as the first thing you do in the plugin.
it test that the api version and model the plugin was compiled for
matches the machine it is running on */
TEST_PLUGIN_API(api);
rb = api; // copy to global api pointer
(void)parameter;
/* This plugin uses the grayscale framework, so initialize */
gray_init(api);
return main();
}
#endif // #ifdef HAVE_LCD_BITMAP
#endif // #ifndef SIMULATOR
|