Rearange menu of mpegplayer. Add new menu with "settings" and "quit", and remove...
[kugel-rb.git] / apps / plugins / oscilloscope.c
blob15943ef53e23c2bb51c120a79646e5c256031500
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 == MROBE500_PAD
252 #define OSCILLOSCOPE_QUIT BUTTON_POWER
254 #elif CONFIG_KEYPAD == SAMSUNG_YH_PAD
255 #define OSCILLOSCOPE_QUIT BUTTON_REC
256 #define OSCILLOSCOPE_DRAWMODE (BUTTON_PLAY|BUTTON_LEFT)
257 #define OSCILLOSCOPE_ADVMODE (BUTTON_PLAY|BUTTON_RIGHT)
258 #define OSCILLOSCOPE_ORIENTATION (BUTTON_PLAY|BUTTON_UP)
259 #define OSCILLOSCOPE_PAUSE (BUTTON_PLAY|BUTTON_DOWN)
260 #define OSCILLOSCOPE_SPEED_UP BUTTON_RIGHT
261 #define OSCILLOSCOPE_SPEED_DOWN BUTTON_LEFT
262 #define OSCILLOSCOPE_VOL_UP BUTTON_UP
263 #define OSCILLOSCOPE_VOL_DOWN BUTTON_DOWN
265 #else
266 #error No keymap defined!
267 #endif
269 #ifdef HAVE_TOUCHSCREEN
270 #ifndef OSCILLOSCOPE_QUIT
271 #define OSCILLOSCOPE_QUIT BUTTON_TOPLEFT
272 #endif
273 #ifndef OSCILLOSCOPE_DRAWMODE
274 #define OSCILLOSCOPE_DRAWMODE BUTTON_TOPMIDDLE
275 #endif
276 #ifndef OSCILLOSCOPE_ADVMODE
277 #define OSCILLOSCOPE_ADVMODE BUTTON_BOTTOMMIDDLE
278 #endif
279 #ifndef OSCILLOSCOPE_ORIENTATION
280 #define OSCILLOSCOPE_ORIENTATION BUTTON_BOTTOMLEFT
281 #endif
282 #ifndef OSCILLOSCOPE_PAUSE
283 #define OSCILLOSCOPE_PAUSE BUTTON_CENTER
284 #endif
285 #ifndef OSCILLOSCOPE_SPEED_UP
286 #define OSCILLOSCOPE_SPEED_UP BUTTON_MIDRIGHT
287 #endif
288 #ifndef OSCILLOSCOPE_SPEED_DOWN
289 #define OSCILLOSCOPE_SPEED_DOWN BUTTON_MIDLEFT
290 #endif
291 #ifndef OSCILLOSCOPE_VOL_UP
292 #define OSCILLOSCOPE_VOL_UP BUTTON_TOPRIGHT
293 #endif
294 #ifndef OSCILLOSCOPE_VOL_DOWN
295 #define OSCILLOSCOPE_VOL_DOWN BUTTON_BOTTOMRIGHT
296 #endif
297 #endif
299 /* colours */
300 #if LCD_DEPTH > 1
301 #ifdef HAVE_LCD_COLOR
302 #define BACKG_COLOR LCD_BLACK
303 #define GRAPH_COLOR LCD_RGBPACK(128, 255, 0)
304 #define CURSOR_COLOR LCD_RGBPACK(255, 0, 0)
305 #else
306 #define BACKG_COLOR LCD_WHITE
307 #define GRAPH_COLOR LCD_BLACK
308 #define CURSOR_COLOR LCD_DARKGRAY
309 #endif
310 #endif
312 enum { DRAW_FILLED, DRAW_LINE, DRAW_PIXEL, MAX_DRAW };
313 enum { ADV_SCROLL, ADV_WRAP, MAX_ADV };
314 enum { OSC_HORIZ, OSC_VERT, MAX_OSC };
316 #define CFGFILE_VERSION 0 /* Current config file version */
317 #define CFGFILE_MINVERSION 0 /* Minimum config file version to accept */
320 #define MAX_PEAK 0x8000
322 #if defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
323 #define mas_codec_readreg(x) rand()%MAX_PEAK
324 #endif
326 /* global variables */
328 /* settings */
329 struct osc_config {
330 int delay; /* in ticks */
331 int draw;
332 int advance;
333 int orientation;
336 struct osc_config osc_disk = { 2, DRAW_FILLED, ADV_SCROLL, OSC_HORIZ };
337 struct osc_config osc; /* running config */
339 static const char cfg_filename[] = "oscilloscope.cfg";
340 static char *draw_str[3] = { "filled", "line", "pixel" };
341 static char *advance_str[2] = { "scroll", "wrap" };
342 static char *orientation_str[2] = { "horizontal", "vertical" };
344 struct configdata disk_config[] = {
345 { TYPE_INT, 1, 99, { .int_p = &osc_disk.delay }, "delay", NULL },
346 { TYPE_ENUM, 0, MAX_DRAW, { .int_p = &osc_disk.draw }, "draw", draw_str },
347 { TYPE_ENUM, 0, MAX_ADV, { .int_p = &osc_disk.advance }, "advance",
348 advance_str },
349 { TYPE_ENUM, 0, MAX_OSC, { .int_p = &osc_disk.orientation }, "orientation",
350 orientation_str }
354 long last_tick = 0; /* time of last drawing */
355 int last_pos = 0; /* last x or y drawing position. Reset for aspect switch. */
356 int last_left; /* last channel values */
357 int last_right;
359 unsigned char message[16]; /* message to display */
360 bool displaymsg = false;
361 int font_height = 8;
363 /* implementation */
365 void anim_horizontal(int cur_left, int cur_right)
367 int cur_x, x;
368 int left, right, dl, dr;
369 long cur_tick = *rb->current_tick;
370 long d = (cur_tick - last_tick) / osc.delay;
371 bool full_update = false;
373 if (d == 0) /* too early, bail out */
374 return;
376 last_tick = cur_tick;
378 if (d > HZ) /* first call or too much delay, (re)start */
380 last_left = cur_left;
381 last_right = cur_right;
382 return;
384 cur_x = last_pos + d;
386 if (cur_x >= LCD_WIDTH)
388 if (osc.advance == ADV_SCROLL)
390 int shift = cur_x - (LCD_WIDTH-1);
391 xlcd_scroll_left(shift);
392 full_update = true;
393 cur_x -= shift;
394 last_pos -= shift;
396 else
398 cur_x -= LCD_WIDTH;
401 rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
403 if (cur_x > last_pos)
405 rb->lcd_fillrect(last_pos + 1, 0, d, LCD_HEIGHT);
407 else
409 rb->lcd_fillrect(last_pos + 1, 0, LCD_WIDTH - last_pos, LCD_HEIGHT);
410 rb->lcd_fillrect(0, 0, cur_x + 1, LCD_HEIGHT);
412 rb->lcd_set_drawmode(DRMODE_SOLID);
414 switch (osc.draw)
416 case DRAW_FILLED:
417 left = last_left;
418 right = last_right;
419 dl = (cur_left - left) / d;
420 dr = (cur_right - right) / d;
422 for (x = last_pos + 1; d > 0; x++, d--)
424 if (x == LCD_WIDTH)
425 x = 0;
427 left += dl;
428 right += dr;
430 rb->lcd_vline(x, LCD_HEIGHT/2-1,
431 LCD_HEIGHT/2-1 - (((LCD_HEIGHT-2) * left) >> 16));
432 rb->lcd_vline(x, LCD_HEIGHT/2+1,
433 LCD_HEIGHT/2+1 + (((LCD_HEIGHT-2) * right) >> 16));
435 break;
437 case DRAW_LINE:
438 if (cur_x > last_pos)
440 rb->lcd_drawline(
441 last_pos, LCD_HEIGHT/2-1 - (((LCD_HEIGHT-2) * last_left) >> 16),
442 cur_x, LCD_HEIGHT/2-1 - (((LCD_HEIGHT-2) * cur_left) >> 16)
444 rb->lcd_drawline(
445 last_pos, LCD_HEIGHT/2+1 + (((LCD_HEIGHT-2) * last_right) >> 16),
446 cur_x, LCD_HEIGHT/2+1 + (((LCD_HEIGHT-2) * cur_right) >> 16)
449 else
451 left = last_left
452 + (LCD_WIDTH - last_pos) * (last_left - cur_left) / d;
453 right = last_right
454 + (LCD_WIDTH - last_pos) * (last_right - cur_right) / d;
456 rb->lcd_drawline(
457 last_pos, LCD_HEIGHT/2-1 - (((LCD_HEIGHT-2) * last_left) >> 16),
458 LCD_WIDTH, LCD_HEIGHT/2-1 - (((LCD_HEIGHT-2) * left) >> 16)
460 rb->lcd_drawline(
461 last_pos, LCD_HEIGHT/2+1 + (((LCD_HEIGHT-2) * last_right) >> 16),
462 LCD_WIDTH, LCD_HEIGHT/2+1 + (((LCD_HEIGHT-2) * right) >> 16)
464 if (cur_x > 0)
466 rb->lcd_drawline(
467 0, LCD_HEIGHT/2-1 - (((LCD_HEIGHT-2) * left) >> 16),
468 cur_x, LCD_HEIGHT/2-1 - (((LCD_HEIGHT-2) * cur_left) >> 16)
470 rb->lcd_drawline(
471 0, LCD_HEIGHT/2+1 + (((LCD_HEIGHT-2) * right) >> 16),
472 cur_x, LCD_HEIGHT/2+1 + (((LCD_HEIGHT-2) * cur_right) >> 16)
476 break;
478 case DRAW_PIXEL:
479 left = last_left;
480 right = last_right;
481 dl = (cur_left - left) / d;
482 dr = (cur_right - right) / d;
484 for (x = last_pos + 1; d > 0; x++, d--)
486 if (x == LCD_WIDTH)
487 x = 0;
489 left += dl;
490 right += dr;
492 rb->lcd_drawpixel(x, LCD_HEIGHT/2-1 - (((LCD_HEIGHT-2) * left) >> 16));
493 rb->lcd_drawpixel(x, LCD_HEIGHT/2+1 + (((LCD_HEIGHT-2) * right) >> 16));
495 break;
498 last_left = cur_left;
499 last_right = cur_right;
501 if (displaymsg)
503 int width;
505 rb->lcd_getstringsize(message, &width, NULL);
506 last_pos -= width - 1;
507 rb->lcd_putsxy(last_pos, 0, message);
508 displaymsg = false;
510 if (last_pos < 0)
511 last_pos = 0;
514 if (full_update)
516 rb->lcd_update();
518 else
520 #if LCD_DEPTH > 1 /* cursor bar */
521 rb->lcd_set_foreground(CURSOR_COLOR);
522 rb->lcd_vline(cur_x + 1, 0, LCD_HEIGHT-1);
523 rb->lcd_set_foreground(GRAPH_COLOR);
524 #else
525 rb->lcd_set_drawmode(DRMODE_COMPLEMENT);
526 rb->lcd_vline(cur_x + 1, 0, LCD_HEIGHT-1);
527 rb->lcd_set_drawmode(DRMODE_SOLID);
528 #endif
530 if (cur_x > last_pos)
532 rb->lcd_update_rect(last_pos, 0, cur_x - last_pos + 2, LCD_HEIGHT);
534 else
536 rb->lcd_update_rect(last_pos, 0, LCD_WIDTH - last_pos, LCD_HEIGHT);
537 rb->lcd_update_rect(0, 0, cur_x + 2, LCD_HEIGHT);
540 last_pos = cur_x;
543 void anim_vertical(int cur_left, int cur_right)
545 int cur_y, y;
546 int left, right, dl, dr;
547 long cur_tick = *rb->current_tick;
548 long d = (cur_tick - last_tick) / osc.delay;
549 bool full_update = false;
551 if (d == 0) /* too early, bail out */
552 return;
554 last_tick = cur_tick;
556 if (d > HZ) /* first call or too much delay, (re)start */
558 last_left = cur_left;
559 last_right = cur_right;
560 return;
562 cur_y = last_pos + d;
564 if (cur_y >= LCD_HEIGHT)
566 if (osc.advance == ADV_SCROLL)
568 int shift = cur_y - (LCD_HEIGHT-1);
569 xlcd_scroll_up(shift);
570 full_update = true;
571 cur_y -= shift;
572 last_pos -= shift;
574 else
576 cur_y -= LCD_HEIGHT;
579 rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
581 if (cur_y > last_pos)
583 rb->lcd_fillrect(0, last_pos + 1, LCD_WIDTH, d);
585 else
587 rb->lcd_fillrect(0, last_pos + 1, LCD_WIDTH, LCD_HEIGHT - last_pos);
588 rb->lcd_fillrect(0, 0, LCD_WIDTH, cur_y + 1);
590 rb->lcd_set_drawmode(DRMODE_SOLID);
592 switch (osc.draw)
594 case DRAW_FILLED:
595 left = last_left;
596 right = last_right;
597 dl = (cur_left - left) / d;
598 dr = (cur_right - right) / d;
600 for (y = last_pos + 1; d > 0; y++, d--)
602 if (y == LCD_HEIGHT)
603 y = 0;
605 left += dl;
606 right += dr;
608 rb->lcd_hline(LCD_WIDTH/2-1,
609 LCD_WIDTH/2-1 - (((LCD_WIDTH-2) * left) >> 16), y);
610 rb->lcd_hline(LCD_WIDTH/2+1,
611 LCD_WIDTH/2+1 + (((LCD_WIDTH-2) * right) >> 16), y);
613 break;
615 case DRAW_LINE:
616 if (cur_y > last_pos)
618 rb->lcd_drawline(
619 LCD_WIDTH/2-1 - (((LCD_WIDTH-2) * last_left) >> 16), last_pos,
620 LCD_WIDTH/2-1 - (((LCD_WIDTH-2) * cur_left) >> 16), cur_y
622 rb->lcd_drawline(
623 LCD_WIDTH/2+1 + (((LCD_WIDTH-2) * last_right) >> 16), last_pos,
624 LCD_WIDTH/2+1 + (((LCD_WIDTH-2) * cur_right) >> 16), cur_y
627 else
629 left = last_left
630 + (LCD_HEIGHT - last_pos) * (last_left - cur_left) / d;
631 right = last_right
632 + (LCD_HEIGHT - last_pos) * (last_right - cur_right) / d;
634 rb->lcd_drawline(
635 LCD_WIDTH/2-1 - (((LCD_WIDTH-2) * last_left) >> 16), last_pos,
636 LCD_WIDTH/2-1 - (((LCD_WIDTH-2) * left) >> 16), LCD_HEIGHT
638 rb->lcd_drawline(
639 LCD_WIDTH/2+1 + (((LCD_WIDTH-2) * last_right) >> 16), last_pos,
640 LCD_WIDTH/2+1 + (((LCD_WIDTH-2) * right) >> 16), LCD_HEIGHT
642 if (cur_y > 0)
644 rb->lcd_drawline(
645 LCD_WIDTH/2-1 - (((LCD_WIDTH-2) * left) >> 16), 0,
646 LCD_WIDTH/2-1 - (((LCD_WIDTH-2) * cur_left) >> 16), cur_y
648 rb->lcd_drawline(
649 LCD_WIDTH/2+1 + (((LCD_WIDTH-2) * right) >> 16), 0,
650 LCD_WIDTH/2+1 + (((LCD_WIDTH-2) * cur_right) >> 16), cur_y
654 break;
656 case DRAW_PIXEL:
657 left = last_left;
658 right = last_right;
659 dl = (cur_left - left) / d;
660 dr = (cur_right - right) / d;
662 for (y = last_pos + 1; d > 0; y++, d--)
664 if (y == LCD_HEIGHT)
665 y = 0;
667 left += dl;
668 right += dr;
670 rb->lcd_drawpixel(LCD_WIDTH/2-1 - (((LCD_WIDTH-2) * left) >> 16), y);
671 rb->lcd_drawpixel(LCD_WIDTH/2+1 + (((LCD_WIDTH-2) * right) >> 16), y);
673 break;
676 last_left = cur_left;
677 last_right = cur_right;
679 if (displaymsg)
681 last_pos -= font_height - 1;
682 rb->lcd_putsxy(0, last_pos, message);
683 displaymsg = false;
685 if (last_pos < 0)
686 last_pos = 0;
689 if (full_update)
691 rb->lcd_update();
693 else
695 #if LCD_DEPTH > 1 /* cursor bar */
696 rb->lcd_set_foreground(CURSOR_COLOR);
697 rb->lcd_hline(0, LCD_WIDTH-1, cur_y + 1);
698 rb->lcd_set_foreground(GRAPH_COLOR);
699 #else
700 rb->lcd_set_drawmode(DRMODE_COMPLEMENT);
701 rb->lcd_hline(0, LCD_WIDTH-1, cur_y + 1);
702 rb->lcd_set_drawmode(DRMODE_SOLID);
703 #endif
705 if (cur_y > last_pos)
707 rb->lcd_update_rect(0, last_pos, LCD_WIDTH, cur_y - last_pos + 2);
709 else
711 rb->lcd_update_rect(0, last_pos, LCD_WIDTH, LCD_HEIGHT - last_pos);
712 rb->lcd_update_rect(0, 0, LCD_WIDTH, cur_y + 2);
715 last_pos = cur_y;
718 void cleanup(void *parameter)
720 (void)parameter;
721 #if LCD_DEPTH > 1
722 rb->lcd_set_foreground(LCD_DEFAULT_FG);
723 rb->lcd_set_background(LCD_DEFAULT_BG);
724 #endif
725 /* Turn on backlight timeout (revert to settings) */
726 backlight_use_settings(); /* backlight control in lib/helper.c */
729 enum plugin_status plugin_start(const void* parameter)
731 int button, vol;
732 int lastbutton = BUTTON_NONE;
733 bool exit = false;
734 bool paused = false;
735 bool tell_speed;
737 (void)parameter;
739 configfile_load(cfg_filename, disk_config,
740 sizeof(disk_config) / sizeof(disk_config[0]),
741 CFGFILE_MINVERSION);
742 rb->memcpy(&osc, &osc_disk, sizeof(osc)); /* copy to running config */
744 #if LCD_DEPTH > 1
745 rb->lcd_set_foreground(GRAPH_COLOR);
746 rb->lcd_set_background(BACKG_COLOR);
747 rb->lcd_set_backdrop(NULL);
748 rb->lcd_clear_display();
749 rb->lcd_update();
750 #endif
752 /* Turn off backlight timeout */
753 backlight_force_on(); /* backlight control in lib/helper.c */
755 rb->lcd_getstringsize("A", NULL, &font_height);
757 while (!exit)
759 if (!paused)
761 int left, right;
763 rb->sleep(MAX(last_tick + osc.delay - *rb->current_tick - 1, 0));
765 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
766 left = rb->mas_codec_readreg(0xC);
767 right = rb->mas_codec_readreg(0xD);
768 #elif (CONFIG_CODEC == SWCODEC)
769 rb->pcm_calculate_peaks(&left, &right);
770 #endif
771 if (osc.orientation == OSC_HORIZ)
772 anim_horizontal(left, right);
773 else
774 anim_vertical(left, right);
777 tell_speed = false;
778 button = rb->button_get(paused);
779 switch (button)
781 #ifdef OSCILLOSCOPE_RC_QUIT
782 case OSCILLOSCOPE_RC_QUIT:
783 #endif
784 case OSCILLOSCOPE_QUIT:
785 exit = true;
786 break;
788 case OSCILLOSCOPE_ADVMODE:
789 if (++osc.advance >= MAX_ADV)
790 osc.advance = 0;
791 break;
793 case OSCILLOSCOPE_DRAWMODE:
794 #ifdef OSCILLOSCOPE_DRAWMODE_PRE
795 if (lastbutton != OSCILLOSCOPE_DRAWMODE_PRE)
796 break;
797 #endif
798 if (++osc.draw >= MAX_DRAW)
799 osc.draw = 0;
800 break;
802 case OSCILLOSCOPE_ORIENTATION:
803 #ifdef OSCILLOSCOPE_ORIENTATION_PRE
804 if (lastbutton != OSCILLOSCOPE_ORIENTATION_PRE)
805 break;
806 #endif
807 if (++osc.orientation >= MAX_OSC)
808 osc.orientation = 0;
809 last_pos = 0;
810 last_tick = 0;
811 displaymsg = false;
812 rb->lcd_clear_display();
813 rb->lcd_update();
814 break;
816 case OSCILLOSCOPE_PAUSE:
817 paused = !paused;
818 last_tick = 0;
819 break;
821 case OSCILLOSCOPE_SPEED_UP:
822 case OSCILLOSCOPE_SPEED_UP | BUTTON_REPEAT:
823 if (osc.delay > 1)
825 osc.delay--;
826 tell_speed = true;
828 break;
830 case OSCILLOSCOPE_SPEED_DOWN:
831 case OSCILLOSCOPE_SPEED_DOWN | BUTTON_REPEAT:
832 osc.delay++;
833 tell_speed = true;
834 break;
836 case OSCILLOSCOPE_VOL_UP:
837 case OSCILLOSCOPE_VOL_UP | BUTTON_REPEAT:
838 vol = rb->global_settings->volume;
839 if (vol < rb->sound_max(SOUND_VOLUME))
841 vol++;
842 rb->sound_set(SOUND_VOLUME, vol);
843 rb->global_settings->volume = vol;
845 break;
847 case OSCILLOSCOPE_VOL_DOWN:
848 case OSCILLOSCOPE_VOL_DOWN | BUTTON_REPEAT:
849 vol = rb->global_settings->volume;
850 if (vol > rb->sound_min(SOUND_VOLUME))
852 vol--;
853 rb->sound_set(SOUND_VOLUME, vol);
854 rb->global_settings->volume = vol;
856 break;
858 default:
859 if (rb->default_event_handler_ex(button, cleanup, NULL)
860 == SYS_USB_CONNECTED)
861 return PLUGIN_USB_CONNECTED;
862 break;
864 if (button != BUTTON_NONE)
865 lastbutton = button;
867 if (tell_speed)
869 rb->snprintf(message, sizeof(message), "%s%d",
870 (osc.orientation == OSC_VERT) ? "Speed: " : "",
871 100 / osc.delay);
872 displaymsg = true;
875 cleanup(NULL);
876 if (rb->memcmp(&osc, &osc_disk, sizeof(osc))) /* save settings if changed */
878 rb->memcpy(&osc_disk, &osc, sizeof(osc));
879 configfile_save(cfg_filename, disk_config,
880 sizeof(disk_config) / sizeof(disk_config[0]),
881 CFGFILE_VERSION);
883 return PLUGIN_OK;
885 #endif /* HAVE_LCD_BITMAP */