Correct beast manual install instructions in Windows.
[kugel-rb.git] / apps / plugins / oscilloscope.c
blob43b0bb4423569529dbeea77c191eb6a264ea2a5f
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Oscilloscope, with many different modes of operation.
12 * Copyright (C) 2004-2006 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 ****************************************************************************/
24 #include "plugin.h"
25 #include "lib/helper.h"
27 #ifdef HAVE_LCD_BITMAP
28 #include "lib/xlcd.h"
29 #include "lib/configfile.h"
31 PLUGIN_HEADER
33 /* variable button definitions */
34 #if CONFIG_KEYPAD == RECORDER_PAD
35 #define OSCILLOSCOPE_QUIT BUTTON_OFF
36 #define OSCILLOSCOPE_DRAWMODE BUTTON_F1
37 #define OSCILLOSCOPE_ADVMODE BUTTON_F2
38 #define OSCILLOSCOPE_ORIENTATION BUTTON_F3
39 #define OSCILLOSCOPE_PAUSE BUTTON_PLAY
40 #define OSCILLOSCOPE_SPEED_UP BUTTON_RIGHT
41 #define OSCILLOSCOPE_SPEED_DOWN BUTTON_LEFT
42 #define OSCILLOSCOPE_VOL_UP BUTTON_UP
43 #define OSCILLOSCOPE_VOL_DOWN BUTTON_DOWN
45 #elif CONFIG_KEYPAD == ARCHOS_AV300_PAD
46 #define OSCILLOSCOPE_QUIT BUTTON_OFF
47 #define OSCILLOSCOPE_DRAWMODE BUTTON_F1
48 #define OSCILLOSCOPE_ADVMODE BUTTON_F2
49 #define OSCILLOSCOPE_ORIENTATION BUTTON_F3
50 #define OSCILLOSCOPE_PAUSE BUTTON_SELECT
51 #define OSCILLOSCOPE_SPEED_UP BUTTON_RIGHT
52 #define OSCILLOSCOPE_SPEED_DOWN BUTTON_LEFT
53 #define OSCILLOSCOPE_VOL_UP BUTTON_UP
54 #define OSCILLOSCOPE_VOL_DOWN BUTTON_DOWN
56 #elif CONFIG_KEYPAD == ONDIO_PAD
57 #define OSCILLOSCOPE_QUIT BUTTON_OFF
58 #define OSCILLOSCOPE_DRAWMODE_PRE BUTTON_MENU
59 #define OSCILLOSCOPE_DRAWMODE (BUTTON_MENU | BUTTON_REL)
60 #define OSCILLOSCOPE_ADVMODE (BUTTON_MENU | BUTTON_RIGHT)
61 #define OSCILLOSCOPE_ORIENTATION (BUTTON_MENU | BUTTON_LEFT)
62 #define OSCILLOSCOPE_PAUSE (BUTTON_MENU | BUTTON_OFF)
63 #define OSCILLOSCOPE_SPEED_UP BUTTON_RIGHT
64 #define OSCILLOSCOPE_SPEED_DOWN BUTTON_LEFT
65 #define OSCILLOSCOPE_VOL_UP BUTTON_UP
66 #define OSCILLOSCOPE_VOL_DOWN BUTTON_DOWN
68 #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD)
69 #define OSCILLOSCOPE_QUIT BUTTON_OFF
70 #define OSCILLOSCOPE_DRAWMODE BUTTON_SELECT
71 #define OSCILLOSCOPE_ADVMODE BUTTON_MODE
72 #define OSCILLOSCOPE_ORIENTATION BUTTON_REC
73 #define OSCILLOSCOPE_PAUSE BUTTON_ON
74 #define OSCILLOSCOPE_SPEED_UP BUTTON_RIGHT
75 #define OSCILLOSCOPE_SPEED_DOWN BUTTON_LEFT
76 #define OSCILLOSCOPE_VOL_UP BUTTON_UP
77 #define OSCILLOSCOPE_VOL_DOWN BUTTON_DOWN
78 #define OSCILLOSCOPE_RC_QUIT BUTTON_RC_STOP
80 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) || \
81 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
82 #define OSCILLOSCOPE_QUIT (BUTTON_SELECT | BUTTON_MENU)
83 #define OSCILLOSCOPE_DRAWMODE (BUTTON_SELECT | BUTTON_PLAY)
84 #define OSCILLOSCOPE_ADVMODE (BUTTON_SELECT | BUTTON_RIGHT)
85 #define OSCILLOSCOPE_ORIENTATION (BUTTON_SELECT | BUTTON_LEFT)
86 #define OSCILLOSCOPE_PAUSE BUTTON_PLAY
87 #define OSCILLOSCOPE_SPEED_UP BUTTON_RIGHT
88 #define OSCILLOSCOPE_SPEED_DOWN BUTTON_LEFT
89 #define OSCILLOSCOPE_VOL_UP BUTTON_SCROLL_FWD
90 #define OSCILLOSCOPE_VOL_DOWN BUTTON_SCROLL_BACK
92 #elif (CONFIG_KEYPAD == GIGABEAT_PAD)
93 #define OSCILLOSCOPE_QUIT BUTTON_POWER
94 #define OSCILLOSCOPE_DRAWMODE BUTTON_SELECT
95 #define OSCILLOSCOPE_ADVMODE BUTTON_DOWN
96 #define OSCILLOSCOPE_ORIENTATION BUTTON_UP
97 #define OSCILLOSCOPE_PAUSE BUTTON_A
98 #define OSCILLOSCOPE_SPEED_UP BUTTON_RIGHT
99 #define OSCILLOSCOPE_SPEED_DOWN BUTTON_LEFT
100 #define OSCILLOSCOPE_VOL_UP BUTTON_VOL_UP
101 #define OSCILLOSCOPE_VOL_DOWN BUTTON_VOL_DOWN
103 #elif (CONFIG_KEYPAD == SANSA_E200_PAD)
104 #define OSCILLOSCOPE_QUIT BUTTON_POWER
105 #define OSCILLOSCOPE_DRAWMODE BUTTON_SELECT
106 #define OSCILLOSCOPE_ADVMODE BUTTON_DOWN
107 #define OSCILLOSCOPE_ORIENTATION BUTTON_UP
108 #define OSCILLOSCOPE_PAUSE BUTTON_REC
109 #define OSCILLOSCOPE_SPEED_UP BUTTON_RIGHT
110 #define OSCILLOSCOPE_SPEED_DOWN BUTTON_LEFT
111 #define OSCILLOSCOPE_VOL_UP BUTTON_SCROLL_FWD
112 #define OSCILLOSCOPE_VOL_DOWN BUTTON_SCROLL_BACK
114 #elif (CONFIG_KEYPAD == SANSA_FUZE_PAD)
115 #define OSCILLOSCOPE_QUIT (BUTTON_HOME|BUTTON_REPEAT)
116 #define OSCILLOSCOPE_DRAWMODE (BUTTON_SELECT | BUTTON_REL)
117 #define OSCILLOSCOPE_ADVMODE (BUTTON_SELECT | BUTTON_RIGHT)
118 #define OSCILLOSCOPE_ORIENTATION (BUTTON_SELECT | BUTTON_LEFT)
119 #define OSCILLOSCOPE_PAUSE BUTTON_UP
120 #define OSCILLOSCOPE_SPEED_UP BUTTON_RIGHT
121 #define OSCILLOSCOPE_SPEED_DOWN BUTTON_LEFT
122 #define OSCILLOSCOPE_VOL_UP BUTTON_SCROLL_FWD
123 #define OSCILLOSCOPE_VOL_DOWN BUTTON_SCROLL_BACK
125 #elif (CONFIG_KEYPAD == SANSA_C200_PAD)
126 #define OSCILLOSCOPE_QUIT BUTTON_POWER
127 #define OSCILLOSCOPE_DRAWMODE BUTTON_SELECT
128 #define OSCILLOSCOPE_ADVMODE BUTTON_DOWN
129 #define OSCILLOSCOPE_ORIENTATION BUTTON_UP
130 #define OSCILLOSCOPE_PAUSE BUTTON_REC
131 #define OSCILLOSCOPE_SPEED_UP BUTTON_RIGHT
132 #define OSCILLOSCOPE_SPEED_DOWN BUTTON_LEFT
133 #define OSCILLOSCOPE_VOL_UP BUTTON_VOL_UP
134 #define OSCILLOSCOPE_VOL_DOWN BUTTON_VOL_DOWN
136 #elif (CONFIG_KEYPAD == SANSA_CLIP_PAD)
137 #define OSCILLOSCOPE_QUIT BUTTON_POWER
138 #define OSCILLOSCOPE_DRAWMODE BUTTON_SELECT
139 #define OSCILLOSCOPE_ADVMODE BUTTON_DOWN
140 #define OSCILLOSCOPE_ORIENTATION BUTTON_UP
141 #define OSCILLOSCOPE_PAUSE BUTTON_HOME
142 #define OSCILLOSCOPE_SPEED_UP BUTTON_RIGHT
143 #define OSCILLOSCOPE_SPEED_DOWN BUTTON_LEFT
144 #define OSCILLOSCOPE_VOL_UP BUTTON_VOL_UP
145 #define OSCILLOSCOPE_VOL_DOWN BUTTON_VOL_DOWN
147 #elif (CONFIG_KEYPAD == SANSA_M200_PAD)
148 #define OSCILLOSCOPE_QUIT BUTTON_POWER
149 #define OSCILLOSCOPE_DRAWMODE (BUTTON_SELECT | BUTTON_REL)
150 #define OSCILLOSCOPE_ADVMODE BUTTON_DOWN
151 #define OSCILLOSCOPE_ORIENTATION BUTTON_UP
152 #define OSCILLOSCOPE_PAUSE (BUTTON_SELECT | BUTTON_UP)
153 #define OSCILLOSCOPE_SPEED_UP BUTTON_RIGHT
154 #define OSCILLOSCOPE_SPEED_DOWN BUTTON_LEFT
155 #define OSCILLOSCOPE_VOL_UP BUTTON_VOL_UP
156 #define OSCILLOSCOPE_VOL_DOWN BUTTON_VOL_DOWN
158 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
159 #define OSCILLOSCOPE_QUIT BUTTON_POWER
160 #define OSCILLOSCOPE_DRAWMODE_PRE BUTTON_SELECT
161 #define OSCILLOSCOPE_DRAWMODE (BUTTON_SELECT | BUTTON_REL)
162 #define OSCILLOSCOPE_ADVMODE BUTTON_REC
163 #define OSCILLOSCOPE_ORIENTATION_PRE BUTTON_SELECT
164 #define OSCILLOSCOPE_ORIENTATION (BUTTON_SELECT | BUTTON_REPEAT)
165 #define OSCILLOSCOPE_PAUSE BUTTON_PLAY
166 #define OSCILLOSCOPE_SPEED_UP BUTTON_RIGHT
167 #define OSCILLOSCOPE_SPEED_DOWN BUTTON_LEFT
168 #define OSCILLOSCOPE_VOL_UP BUTTON_UP
169 #define OSCILLOSCOPE_VOL_DOWN BUTTON_DOWN
171 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
172 #define OSCILLOSCOPE_QUIT BUTTON_POWER
173 #define OSCILLOSCOPE_DRAWMODE_PRE BUTTON_REW
174 #define OSCILLOSCOPE_DRAWMODE (BUTTON_REW | BUTTON_REL)
175 #define OSCILLOSCOPE_ADVMODE BUTTON_FF
176 #define OSCILLOSCOPE_ORIENTATION_PRE BUTTON_REW
177 #define OSCILLOSCOPE_ORIENTATION (BUTTON_REW | BUTTON_REPEAT)
178 #define OSCILLOSCOPE_PAUSE BUTTON_PLAY
179 #define OSCILLOSCOPE_SPEED_UP BUTTON_RIGHT
180 #define OSCILLOSCOPE_SPEED_DOWN BUTTON_LEFT
181 #define OSCILLOSCOPE_VOL_UP BUTTON_SCROLL_UP
182 #define OSCILLOSCOPE_VOL_DOWN BUTTON_SCROLL_DOWN
184 #elif CONFIG_KEYPAD == GIGABEAT_S_PAD
185 #define OSCILLOSCOPE_QUIT BUTTON_BACK
186 #define OSCILLOSCOPE_DRAWMODE BUTTON_PREV
187 #define OSCILLOSCOPE_ADVMODE BUTTON_NEXT
188 #define OSCILLOSCOPE_ORIENTATION BUTTON_MENU
189 #define OSCILLOSCOPE_PAUSE BUTTON_PLAY
190 #define OSCILLOSCOPE_SPEED_UP BUTTON_RIGHT
191 #define OSCILLOSCOPE_SPEED_DOWN BUTTON_LEFT
192 #define OSCILLOSCOPE_VOL_UP BUTTON_VOL_UP
193 #define OSCILLOSCOPE_VOL_DOWN BUTTON_VOL_DOWN
195 #elif (CONFIG_KEYPAD == MROBE100_PAD)
196 #define OSCILLOSCOPE_QUIT BUTTON_POWER
197 #define OSCILLOSCOPE_DRAWMODE BUTTON_SELECT
198 #define OSCILLOSCOPE_ADVMODE BUTTON_MENU
199 #define OSCILLOSCOPE_ORIENTATION BUTTON_PLAY
200 #define OSCILLOSCOPE_PAUSE BUTTON_DISPLAY
201 #define OSCILLOSCOPE_SPEED_UP BUTTON_RIGHT
202 #define OSCILLOSCOPE_SPEED_DOWN BUTTON_LEFT
203 #define OSCILLOSCOPE_VOL_UP BUTTON_UP
204 #define OSCILLOSCOPE_VOL_DOWN BUTTON_DOWN
206 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
207 #define OSCILLOSCOPE_QUIT BUTTON_RC_REC
208 #define OSCILLOSCOPE_DRAWMODE_PRE BUTTON_RC_MODE
209 #define OSCILLOSCOPE_DRAWMODE (BUTTON_RC_MODE|BUTTON_REL)
210 #define OSCILLOSCOPE_ADVMODE BUTTON_RC_MENU
211 #define OSCILLOSCOPE_ORIENTATION_PRE BUTTON_RC_MODE
212 #define OSCILLOSCOPE_ORIENTATION (BUTTON_RC_MODE|BUTTON_REPEAT)
213 #define OSCILLOSCOPE_PAUSE BUTTON_RC_PLAY
214 #define OSCILLOSCOPE_SPEED_UP BUTTON_RC_FF
215 #define OSCILLOSCOPE_SPEED_DOWN BUTTON_RC_REW
216 #define OSCILLOSCOPE_VOL_UP BUTTON_RC_VOL_UP
217 #define OSCILLOSCOPE_VOL_DOWN BUTTON_RC_VOL_DOWN
219 #elif CONFIG_KEYPAD == COWOND2_PAD
220 #define OSCILLOSCOPE_QUIT BUTTON_POWER
221 #define OSCILLOSCOPE_VOL_UP BUTTON_PLUS
222 #define OSCILLOSCOPE_VOL_DOWN BUTTON_MINUS
224 #elif CONFIG_KEYPAD == CREATIVEZVM_PAD
225 #define OSCILLOSCOPE_QUIT BUTTON_BACK
226 #define OSCILLOSCOPE_DRAWMODE BUTTON_SELECT
227 #define OSCILLOSCOPE_ADVMODE BUTTON_CUSTOM
228 #define OSCILLOSCOPE_ORIENTATION BUTTON_MENU
229 #define OSCILLOSCOPE_PAUSE BUTTON_PLAY
230 #define OSCILLOSCOPE_SPEED_UP BUTTON_RIGHT
231 #define OSCILLOSCOPE_SPEED_DOWN BUTTON_LEFT
232 #define OSCILLOSCOPE_VOL_UP BUTTON_UP
233 #define OSCILLOSCOPE_VOL_DOWN BUTTON_DOWN
235 #elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
236 #define OSCILLOSCOPE_QUIT BUTTON_POWER
237 #define OSCILLOSCOPE_DRAWMODE BUTTON_MENU
238 #define OSCILLOSCOPE_ADVMODE BUTTON_VIEW
239 #define OSCILLOSCOPE_ORIENTATION BUTTON_UP
240 #define OSCILLOSCOPE_PAUSE BUTTON_SELECT
241 #define OSCILLOSCOPE_SPEED_UP BUTTON_RIGHT
242 #define OSCILLOSCOPE_SPEED_DOWN BUTTON_LEFT
243 #define OSCILLOSCOPE_VOL_UP BUTTON_VOL_UP
244 #define OSCILLOSCOPE_VOL_DOWN BUTTON_VOL_DOWN
246 #elif CONFIG_KEYPAD == ONDAVX747_PAD
247 #define OSCILLOSCOPE_QUIT BUTTON_POWER
248 #define OSCILLOSCOPE_VOL_UP BUTTON_VOL_UP
249 #define OSCILLOSCOPE_VOL_DOWN BUTTON_VOL_DOWN
251 #elif CONFIG_KEYPAD == ONDAVX777_PAD
252 #define OSCILLOSCOPE_QUIT BUTTON_POWER
254 #elif CONFIG_KEYPAD == MROBE500_PAD
255 #define OSCILLOSCOPE_QUIT BUTTON_POWER
257 #elif CONFIG_KEYPAD == SAMSUNG_YH_PAD
258 #define OSCILLOSCOPE_QUIT BUTTON_REC
259 #define OSCILLOSCOPE_DRAWMODE (BUTTON_PLAY|BUTTON_LEFT)
260 #define OSCILLOSCOPE_ADVMODE (BUTTON_PLAY|BUTTON_RIGHT)
261 #define OSCILLOSCOPE_ORIENTATION (BUTTON_PLAY|BUTTON_UP)
262 #define OSCILLOSCOPE_PAUSE (BUTTON_PLAY|BUTTON_DOWN)
263 #define OSCILLOSCOPE_SPEED_UP BUTTON_RIGHT
264 #define OSCILLOSCOPE_SPEED_DOWN BUTTON_LEFT
265 #define OSCILLOSCOPE_VOL_UP BUTTON_UP
266 #define OSCILLOSCOPE_VOL_DOWN BUTTON_DOWN
268 #else
269 #error No keymap defined!
270 #endif
272 #ifdef HAVE_TOUCHSCREEN
273 #ifndef OSCILLOSCOPE_QUIT
274 #define OSCILLOSCOPE_QUIT BUTTON_TOPLEFT
275 #endif
276 #ifndef OSCILLOSCOPE_DRAWMODE
277 #define OSCILLOSCOPE_DRAWMODE BUTTON_TOPMIDDLE
278 #endif
279 #ifndef OSCILLOSCOPE_ADVMODE
280 #define OSCILLOSCOPE_ADVMODE BUTTON_BOTTOMMIDDLE
281 #endif
282 #ifndef OSCILLOSCOPE_ORIENTATION
283 #define OSCILLOSCOPE_ORIENTATION BUTTON_BOTTOMLEFT
284 #endif
285 #ifndef OSCILLOSCOPE_PAUSE
286 #define OSCILLOSCOPE_PAUSE BUTTON_CENTER
287 #endif
288 #ifndef OSCILLOSCOPE_SPEED_UP
289 #define OSCILLOSCOPE_SPEED_UP BUTTON_MIDRIGHT
290 #endif
291 #ifndef OSCILLOSCOPE_SPEED_DOWN
292 #define OSCILLOSCOPE_SPEED_DOWN BUTTON_MIDLEFT
293 #endif
294 #ifndef OSCILLOSCOPE_VOL_UP
295 #define OSCILLOSCOPE_VOL_UP BUTTON_TOPRIGHT
296 #endif
297 #ifndef OSCILLOSCOPE_VOL_DOWN
298 #define OSCILLOSCOPE_VOL_DOWN BUTTON_BOTTOMRIGHT
299 #endif
300 #endif
302 /* colours */
303 #if LCD_DEPTH > 1
304 #ifdef HAVE_LCD_COLOR
305 #define BACKG_COLOR LCD_BLACK
306 #define GRAPH_COLOR LCD_RGBPACK(128, 255, 0)
307 #define CURSOR_COLOR LCD_RGBPACK(255, 0, 0)
308 #else
309 #define BACKG_COLOR LCD_WHITE
310 #define GRAPH_COLOR LCD_BLACK
311 #define CURSOR_COLOR LCD_DARKGRAY
312 #endif
313 #endif
315 enum { DRAW_FILLED, DRAW_LINE, DRAW_PIXEL, MAX_DRAW };
316 enum { ADV_SCROLL, ADV_WRAP, MAX_ADV };
317 enum { OSC_HORIZ, OSC_VERT, MAX_OSC };
319 #define CFGFILE_VERSION 0 /* Current config file version */
320 #define CFGFILE_MINVERSION 0 /* Minimum config file version to accept */
323 #define MAX_PEAK 0x8000
325 #if defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
326 #define mas_codec_readreg(x) rand()%MAX_PEAK
327 #endif
329 /* global variables */
331 /* settings */
332 struct osc_config {
333 int delay; /* in ticks */
334 int draw;
335 int advance;
336 int orientation;
339 struct osc_config osc_disk = { 2, DRAW_FILLED, ADV_SCROLL, OSC_HORIZ };
340 struct osc_config osc; /* running config */
342 static const char cfg_filename[] = "oscilloscope.cfg";
343 static char *draw_str[3] = { "filled", "line", "pixel" };
344 static char *advance_str[2] = { "scroll", "wrap" };
345 static char *orientation_str[2] = { "horizontal", "vertical" };
347 struct configdata disk_config[] = {
348 { TYPE_INT, 1, 99, { .int_p = &osc_disk.delay }, "delay", NULL },
349 { TYPE_ENUM, 0, MAX_DRAW, { .int_p = &osc_disk.draw }, "draw", draw_str },
350 { TYPE_ENUM, 0, MAX_ADV, { .int_p = &osc_disk.advance }, "advance",
351 advance_str },
352 { TYPE_ENUM, 0, MAX_OSC, { .int_p = &osc_disk.orientation }, "orientation",
353 orientation_str }
357 long last_tick = 0; /* time of last drawing */
358 int last_pos = 0; /* last x or y drawing position. Reset for aspect switch. */
359 int last_left; /* last channel values */
360 int last_right;
362 unsigned char message[16]; /* message to display */
363 bool displaymsg = false;
364 int font_height = 8;
366 /* implementation */
368 void anim_horizontal(int cur_left, int cur_right)
370 int cur_x, x;
371 int left, right, dl, dr;
372 long cur_tick = *rb->current_tick;
373 long d = (cur_tick - last_tick) / osc.delay;
374 bool full_update = false;
376 if (d == 0) /* too early, bail out */
377 return;
379 last_tick = cur_tick;
381 if (d > HZ) /* first call or too much delay, (re)start */
383 last_left = cur_left;
384 last_right = cur_right;
385 return;
387 cur_x = last_pos + d;
389 if (cur_x >= LCD_WIDTH)
391 if (osc.advance == ADV_SCROLL)
393 int shift = cur_x - (LCD_WIDTH-1);
394 xlcd_scroll_left(shift);
395 full_update = true;
396 cur_x -= shift;
397 last_pos -= shift;
399 else
401 cur_x -= LCD_WIDTH;
404 rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
406 if (cur_x > last_pos)
408 rb->lcd_fillrect(last_pos + 1, 0, d, LCD_HEIGHT);
410 else
412 rb->lcd_fillrect(last_pos + 1, 0, LCD_WIDTH - last_pos, LCD_HEIGHT);
413 rb->lcd_fillrect(0, 0, cur_x + 1, LCD_HEIGHT);
415 rb->lcd_set_drawmode(DRMODE_SOLID);
417 switch (osc.draw)
419 case DRAW_FILLED:
420 left = last_left;
421 right = last_right;
422 dl = (cur_left - left) / d;
423 dr = (cur_right - right) / d;
425 for (x = last_pos + 1; d > 0; x++, d--)
427 if (x == LCD_WIDTH)
428 x = 0;
430 left += dl;
431 right += dr;
433 rb->lcd_vline(x, LCD_HEIGHT/2-1,
434 LCD_HEIGHT/2-1 - (((LCD_HEIGHT-2) * left) >> 16));
435 rb->lcd_vline(x, LCD_HEIGHT/2+1,
436 LCD_HEIGHT/2+1 + (((LCD_HEIGHT-2) * right) >> 16));
438 break;
440 case DRAW_LINE:
441 if (cur_x > last_pos)
443 rb->lcd_drawline(
444 last_pos, LCD_HEIGHT/2-1 - (((LCD_HEIGHT-2) * last_left) >> 16),
445 cur_x, LCD_HEIGHT/2-1 - (((LCD_HEIGHT-2) * cur_left) >> 16)
447 rb->lcd_drawline(
448 last_pos, LCD_HEIGHT/2+1 + (((LCD_HEIGHT-2) * last_right) >> 16),
449 cur_x, LCD_HEIGHT/2+1 + (((LCD_HEIGHT-2) * cur_right) >> 16)
452 else
454 left = last_left
455 + (LCD_WIDTH - last_pos) * (last_left - cur_left) / d;
456 right = last_right
457 + (LCD_WIDTH - last_pos) * (last_right - cur_right) / d;
459 rb->lcd_drawline(
460 last_pos, LCD_HEIGHT/2-1 - (((LCD_HEIGHT-2) * last_left) >> 16),
461 LCD_WIDTH, LCD_HEIGHT/2-1 - (((LCD_HEIGHT-2) * left) >> 16)
463 rb->lcd_drawline(
464 last_pos, LCD_HEIGHT/2+1 + (((LCD_HEIGHT-2) * last_right) >> 16),
465 LCD_WIDTH, LCD_HEIGHT/2+1 + (((LCD_HEIGHT-2) * right) >> 16)
467 if (cur_x > 0)
469 rb->lcd_drawline(
470 0, LCD_HEIGHT/2-1 - (((LCD_HEIGHT-2) * left) >> 16),
471 cur_x, LCD_HEIGHT/2-1 - (((LCD_HEIGHT-2) * cur_left) >> 16)
473 rb->lcd_drawline(
474 0, LCD_HEIGHT/2+1 + (((LCD_HEIGHT-2) * right) >> 16),
475 cur_x, LCD_HEIGHT/2+1 + (((LCD_HEIGHT-2) * cur_right) >> 16)
479 break;
481 case DRAW_PIXEL:
482 left = last_left;
483 right = last_right;
484 dl = (cur_left - left) / d;
485 dr = (cur_right - right) / d;
487 for (x = last_pos + 1; d > 0; x++, d--)
489 if (x == LCD_WIDTH)
490 x = 0;
492 left += dl;
493 right += dr;
495 rb->lcd_drawpixel(x, LCD_HEIGHT/2-1 - (((LCD_HEIGHT-2) * left) >> 16));
496 rb->lcd_drawpixel(x, LCD_HEIGHT/2+1 + (((LCD_HEIGHT-2) * right) >> 16));
498 break;
501 last_left = cur_left;
502 last_right = cur_right;
504 if (displaymsg)
506 int width;
508 rb->lcd_getstringsize(message, &width, NULL);
509 last_pos -= width - 1;
510 rb->lcd_putsxy(last_pos, 0, message);
511 displaymsg = false;
513 if (last_pos < 0)
514 last_pos = 0;
517 if (full_update)
519 rb->lcd_update();
521 else
523 #if LCD_DEPTH > 1 /* cursor bar */
524 rb->lcd_set_foreground(CURSOR_COLOR);
525 rb->lcd_vline(cur_x + 1, 0, LCD_HEIGHT-1);
526 rb->lcd_set_foreground(GRAPH_COLOR);
527 #else
528 rb->lcd_set_drawmode(DRMODE_COMPLEMENT);
529 rb->lcd_vline(cur_x + 1, 0, LCD_HEIGHT-1);
530 rb->lcd_set_drawmode(DRMODE_SOLID);
531 #endif
533 if (cur_x > last_pos)
535 rb->lcd_update_rect(last_pos, 0, cur_x - last_pos + 2, LCD_HEIGHT);
537 else
539 rb->lcd_update_rect(last_pos, 0, LCD_WIDTH - last_pos, LCD_HEIGHT);
540 rb->lcd_update_rect(0, 0, cur_x + 2, LCD_HEIGHT);
543 last_pos = cur_x;
546 void anim_vertical(int cur_left, int cur_right)
548 int cur_y, y;
549 int left, right, dl, dr;
550 long cur_tick = *rb->current_tick;
551 long d = (cur_tick - last_tick) / osc.delay;
552 bool full_update = false;
554 if (d == 0) /* too early, bail out */
555 return;
557 last_tick = cur_tick;
559 if (d > HZ) /* first call or too much delay, (re)start */
561 last_left = cur_left;
562 last_right = cur_right;
563 return;
565 cur_y = last_pos + d;
567 if (cur_y >= LCD_HEIGHT)
569 if (osc.advance == ADV_SCROLL)
571 int shift = cur_y - (LCD_HEIGHT-1);
572 xlcd_scroll_up(shift);
573 full_update = true;
574 cur_y -= shift;
575 last_pos -= shift;
577 else
579 cur_y -= LCD_HEIGHT;
582 rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
584 if (cur_y > last_pos)
586 rb->lcd_fillrect(0, last_pos + 1, LCD_WIDTH, d);
588 else
590 rb->lcd_fillrect(0, last_pos + 1, LCD_WIDTH, LCD_HEIGHT - last_pos);
591 rb->lcd_fillrect(0, 0, LCD_WIDTH, cur_y + 1);
593 rb->lcd_set_drawmode(DRMODE_SOLID);
595 switch (osc.draw)
597 case DRAW_FILLED:
598 left = last_left;
599 right = last_right;
600 dl = (cur_left - left) / d;
601 dr = (cur_right - right) / d;
603 for (y = last_pos + 1; d > 0; y++, d--)
605 if (y == LCD_HEIGHT)
606 y = 0;
608 left += dl;
609 right += dr;
611 rb->lcd_hline(LCD_WIDTH/2-1,
612 LCD_WIDTH/2-1 - (((LCD_WIDTH-2) * left) >> 16), y);
613 rb->lcd_hline(LCD_WIDTH/2+1,
614 LCD_WIDTH/2+1 + (((LCD_WIDTH-2) * right) >> 16), y);
616 break;
618 case DRAW_LINE:
619 if (cur_y > last_pos)
621 rb->lcd_drawline(
622 LCD_WIDTH/2-1 - (((LCD_WIDTH-2) * last_left) >> 16), last_pos,
623 LCD_WIDTH/2-1 - (((LCD_WIDTH-2) * cur_left) >> 16), cur_y
625 rb->lcd_drawline(
626 LCD_WIDTH/2+1 + (((LCD_WIDTH-2) * last_right) >> 16), last_pos,
627 LCD_WIDTH/2+1 + (((LCD_WIDTH-2) * cur_right) >> 16), cur_y
630 else
632 left = last_left
633 + (LCD_HEIGHT - last_pos) * (last_left - cur_left) / d;
634 right = last_right
635 + (LCD_HEIGHT - last_pos) * (last_right - cur_right) / d;
637 rb->lcd_drawline(
638 LCD_WIDTH/2-1 - (((LCD_WIDTH-2) * last_left) >> 16), last_pos,
639 LCD_WIDTH/2-1 - (((LCD_WIDTH-2) * left) >> 16), LCD_HEIGHT
641 rb->lcd_drawline(
642 LCD_WIDTH/2+1 + (((LCD_WIDTH-2) * last_right) >> 16), last_pos,
643 LCD_WIDTH/2+1 + (((LCD_WIDTH-2) * right) >> 16), LCD_HEIGHT
645 if (cur_y > 0)
647 rb->lcd_drawline(
648 LCD_WIDTH/2-1 - (((LCD_WIDTH-2) * left) >> 16), 0,
649 LCD_WIDTH/2-1 - (((LCD_WIDTH-2) * cur_left) >> 16), cur_y
651 rb->lcd_drawline(
652 LCD_WIDTH/2+1 + (((LCD_WIDTH-2) * right) >> 16), 0,
653 LCD_WIDTH/2+1 + (((LCD_WIDTH-2) * cur_right) >> 16), cur_y
657 break;
659 case DRAW_PIXEL:
660 left = last_left;
661 right = last_right;
662 dl = (cur_left - left) / d;
663 dr = (cur_right - right) / d;
665 for (y = last_pos + 1; d > 0; y++, d--)
667 if (y == LCD_HEIGHT)
668 y = 0;
670 left += dl;
671 right += dr;
673 rb->lcd_drawpixel(LCD_WIDTH/2-1 - (((LCD_WIDTH-2) * left) >> 16), y);
674 rb->lcd_drawpixel(LCD_WIDTH/2+1 + (((LCD_WIDTH-2) * right) >> 16), y);
676 break;
679 last_left = cur_left;
680 last_right = cur_right;
682 if (displaymsg)
684 last_pos -= font_height - 1;
685 rb->lcd_putsxy(0, last_pos, message);
686 displaymsg = false;
688 if (last_pos < 0)
689 last_pos = 0;
692 if (full_update)
694 rb->lcd_update();
696 else
698 #if LCD_DEPTH > 1 /* cursor bar */
699 rb->lcd_set_foreground(CURSOR_COLOR);
700 rb->lcd_hline(0, LCD_WIDTH-1, cur_y + 1);
701 rb->lcd_set_foreground(GRAPH_COLOR);
702 #else
703 rb->lcd_set_drawmode(DRMODE_COMPLEMENT);
704 rb->lcd_hline(0, LCD_WIDTH-1, cur_y + 1);
705 rb->lcd_set_drawmode(DRMODE_SOLID);
706 #endif
708 if (cur_y > last_pos)
710 rb->lcd_update_rect(0, last_pos, LCD_WIDTH, cur_y - last_pos + 2);
712 else
714 rb->lcd_update_rect(0, last_pos, LCD_WIDTH, LCD_HEIGHT - last_pos);
715 rb->lcd_update_rect(0, 0, LCD_WIDTH, cur_y + 2);
718 last_pos = cur_y;
721 void cleanup(void *parameter)
723 (void)parameter;
724 #if LCD_DEPTH > 1
725 rb->lcd_set_foreground(LCD_DEFAULT_FG);
726 rb->lcd_set_background(LCD_DEFAULT_BG);
727 #endif
728 /* Turn on backlight timeout (revert to settings) */
729 backlight_use_settings(); /* backlight control in lib/helper.c */
732 enum plugin_status plugin_start(const void* parameter)
734 int button, vol;
735 int lastbutton = BUTTON_NONE;
736 bool exit = false;
737 bool paused = false;
738 bool tell_speed;
740 (void)parameter;
742 configfile_load(cfg_filename, disk_config,
743 sizeof(disk_config) / sizeof(disk_config[0]),
744 CFGFILE_MINVERSION);
745 rb->memcpy(&osc, &osc_disk, sizeof(osc)); /* copy to running config */
747 #if LCD_DEPTH > 1
748 rb->lcd_set_foreground(GRAPH_COLOR);
749 rb->lcd_set_background(BACKG_COLOR);
750 rb->lcd_set_backdrop(NULL);
751 rb->lcd_clear_display();
752 rb->lcd_update();
753 #endif
755 /* Turn off backlight timeout */
756 backlight_force_on(); /* backlight control in lib/helper.c */
758 rb->lcd_getstringsize("A", NULL, &font_height);
760 while (!exit)
762 if (!paused)
764 int left, right;
766 rb->sleep(MAX(last_tick + osc.delay - *rb->current_tick - 1, 0));
768 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
769 left = rb->mas_codec_readreg(0xC);
770 right = rb->mas_codec_readreg(0xD);
771 #elif (CONFIG_CODEC == SWCODEC)
772 rb->pcm_calculate_peaks(&left, &right);
773 #endif
774 if (osc.orientation == OSC_HORIZ)
775 anim_horizontal(left, right);
776 else
777 anim_vertical(left, right);
780 tell_speed = false;
781 button = rb->button_get(paused);
782 switch (button)
784 #ifdef OSCILLOSCOPE_RC_QUIT
785 case OSCILLOSCOPE_RC_QUIT:
786 #endif
787 case OSCILLOSCOPE_QUIT:
788 exit = true;
789 break;
791 case OSCILLOSCOPE_ADVMODE:
792 if (++osc.advance >= MAX_ADV)
793 osc.advance = 0;
794 break;
796 case OSCILLOSCOPE_DRAWMODE:
797 #ifdef OSCILLOSCOPE_DRAWMODE_PRE
798 if (lastbutton != OSCILLOSCOPE_DRAWMODE_PRE)
799 break;
800 #endif
801 if (++osc.draw >= MAX_DRAW)
802 osc.draw = 0;
803 break;
805 case OSCILLOSCOPE_ORIENTATION:
806 #ifdef OSCILLOSCOPE_ORIENTATION_PRE
807 if (lastbutton != OSCILLOSCOPE_ORIENTATION_PRE)
808 break;
809 #endif
810 if (++osc.orientation >= MAX_OSC)
811 osc.orientation = 0;
812 last_pos = 0;
813 last_tick = 0;
814 displaymsg = false;
815 rb->lcd_clear_display();
816 rb->lcd_update();
817 break;
819 case OSCILLOSCOPE_PAUSE:
820 paused = !paused;
821 last_tick = 0;
822 break;
824 case OSCILLOSCOPE_SPEED_UP:
825 case OSCILLOSCOPE_SPEED_UP | BUTTON_REPEAT:
826 if (osc.delay > 1)
828 osc.delay--;
829 tell_speed = true;
831 break;
833 case OSCILLOSCOPE_SPEED_DOWN:
834 case OSCILLOSCOPE_SPEED_DOWN | BUTTON_REPEAT:
835 osc.delay++;
836 tell_speed = true;
837 break;
839 case OSCILLOSCOPE_VOL_UP:
840 case OSCILLOSCOPE_VOL_UP | BUTTON_REPEAT:
841 vol = rb->global_settings->volume;
842 if (vol < rb->sound_max(SOUND_VOLUME))
844 vol++;
845 rb->sound_set(SOUND_VOLUME, vol);
846 rb->global_settings->volume = vol;
848 break;
850 case OSCILLOSCOPE_VOL_DOWN:
851 case OSCILLOSCOPE_VOL_DOWN | BUTTON_REPEAT:
852 vol = rb->global_settings->volume;
853 if (vol > rb->sound_min(SOUND_VOLUME))
855 vol--;
856 rb->sound_set(SOUND_VOLUME, vol);
857 rb->global_settings->volume = vol;
859 break;
861 default:
862 if (rb->default_event_handler_ex(button, cleanup, NULL)
863 == SYS_USB_CONNECTED)
864 return PLUGIN_USB_CONNECTED;
865 break;
867 if (button != BUTTON_NONE)
868 lastbutton = button;
870 if (tell_speed)
872 rb->snprintf(message, sizeof(message), "%s%d",
873 (osc.orientation == OSC_VERT) ? "Speed: " : "",
874 100 / osc.delay);
875 displaymsg = true;
878 cleanup(NULL);
879 if (rb->memcmp(&osc, &osc_disk, sizeof(osc))) /* save settings if changed */
881 rb->memcpy(&osc_disk, &osc, sizeof(osc));
882 configfile_save(cfg_filename, disk_config,
883 sizeof(disk_config) / sizeof(disk_config[0]),
884 CFGFILE_VERSION);
886 return PLUGIN_OK;
888 #endif /* HAVE_LCD_BITMAP */