fix wrong score recording.
[kugel-rb.git] / apps / plugins / oscilloscope.c
blob1e9e873ae7e837b7080ac7ef953090c0c9d37f72
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 #else
255 #error No keymap defined!
256 #endif
258 #ifdef HAVE_TOUCHSCREEN
259 #ifndef OSCILLOSCOPE_QUIT
260 #define OSCILLOSCOPE_QUIT BUTTON_TOPLEFT
261 #endif
262 #ifndef OSCILLOSCOPE_DRAWMODE
263 #define OSCILLOSCOPE_DRAWMODE BUTTON_TOPMIDDLE
264 #endif
265 #ifndef OSCILLOSCOPE_ADVMODE
266 #define OSCILLOSCOPE_ADVMODE BUTTON_BOTTOMMIDDLE
267 #endif
268 #ifndef OSCILLOSCOPE_ORIENTATION
269 #define OSCILLOSCOPE_ORIENTATION BUTTON_BOTTOMLEFT
270 #endif
271 #ifndef OSCILLOSCOPE_PAUSE
272 #define OSCILLOSCOPE_PAUSE BUTTON_CENTER
273 #endif
274 #ifndef OSCILLOSCOPE_SPEED_UP
275 #define OSCILLOSCOPE_SPEED_UP BUTTON_MIDRIGHT
276 #endif
277 #ifndef OSCILLOSCOPE_SPEED_DOWN
278 #define OSCILLOSCOPE_SPEED_DOWN BUTTON_MIDLEFT
279 #endif
280 #ifndef OSCILLOSCOPE_VOL_UP
281 #define OSCILLOSCOPE_VOL_UP BUTTON_TOPRIGHT
282 #endif
283 #ifndef OSCILLOSCOPE_VOL_DOWN
284 #define OSCILLOSCOPE_VOL_DOWN BUTTON_BOTTOMRIGHT
285 #endif
286 #endif
288 /* colours */
289 #if LCD_DEPTH > 1
290 #ifdef HAVE_LCD_COLOR
291 #define BACKG_COLOR LCD_BLACK
292 #define GRAPH_COLOR LCD_RGBPACK(128, 255, 0)
293 #define CURSOR_COLOR LCD_RGBPACK(255, 0, 0)
294 #else
295 #define BACKG_COLOR LCD_WHITE
296 #define GRAPH_COLOR LCD_BLACK
297 #define CURSOR_COLOR LCD_DARKGRAY
298 #endif
299 #endif
301 enum { DRAW_FILLED, DRAW_LINE, DRAW_PIXEL, MAX_DRAW };
302 enum { ADV_SCROLL, ADV_WRAP, MAX_ADV };
303 enum { OSC_HORIZ, OSC_VERT, MAX_OSC };
305 #define CFGFILE_VERSION 0 /* Current config file version */
306 #define CFGFILE_MINVERSION 0 /* Minimum config file version to accept */
309 #define MAX_PEAK 0x8000
311 #if defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
312 #define mas_codec_readreg(x) rand()%MAX_PEAK
313 #endif
315 /* global variables */
317 /* settings */
318 struct osc_config {
319 int delay; /* in ticks */
320 int draw;
321 int advance;
322 int orientation;
325 struct osc_config osc_disk = { 2, DRAW_FILLED, ADV_SCROLL, OSC_HORIZ };
326 struct osc_config osc; /* running config */
328 static const char cfg_filename[] = "oscilloscope.cfg";
329 static char *draw_str[3] = { "filled", "line", "pixel" };
330 static char *advance_str[2] = { "scroll", "wrap" };
331 static char *orientation_str[2] = { "horizontal", "vertical" };
333 struct configdata disk_config[] = {
334 { TYPE_INT, 1, 99, { .int_p = &osc_disk.delay }, "delay", NULL },
335 { TYPE_ENUM, 0, MAX_DRAW, { .int_p = &osc_disk.draw }, "draw", draw_str },
336 { TYPE_ENUM, 0, MAX_ADV, { .int_p = &osc_disk.advance }, "advance",
337 advance_str },
338 { TYPE_ENUM, 0, MAX_OSC, { .int_p = &osc_disk.orientation }, "orientation",
339 orientation_str }
343 long last_tick = 0; /* time of last drawing */
344 int last_pos = 0; /* last x or y drawing position. Reset for aspect switch. */
345 int last_left; /* last channel values */
346 int last_right;
348 unsigned char message[16]; /* message to display */
349 bool displaymsg = false;
350 int font_height = 8;
352 /* implementation */
354 void anim_horizontal(int cur_left, int cur_right)
356 int cur_x, x;
357 int left, right, dl, dr;
358 long cur_tick = *rb->current_tick;
359 long d = (cur_tick - last_tick) / osc.delay;
360 bool full_update = false;
362 if (d == 0) /* too early, bail out */
363 return;
365 last_tick = cur_tick;
367 if (d > HZ) /* first call or too much delay, (re)start */
369 last_left = cur_left;
370 last_right = cur_right;
371 return;
373 cur_x = last_pos + d;
375 if (cur_x >= LCD_WIDTH)
377 if (osc.advance == ADV_SCROLL)
379 int shift = cur_x - (LCD_WIDTH-1);
380 xlcd_scroll_left(shift);
381 full_update = true;
382 cur_x -= shift;
383 last_pos -= shift;
385 else
387 cur_x -= LCD_WIDTH;
390 rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
392 if (cur_x > last_pos)
394 rb->lcd_fillrect(last_pos + 1, 0, d, LCD_HEIGHT);
396 else
398 rb->lcd_fillrect(last_pos + 1, 0, LCD_WIDTH - last_pos, LCD_HEIGHT);
399 rb->lcd_fillrect(0, 0, cur_x + 1, LCD_HEIGHT);
401 rb->lcd_set_drawmode(DRMODE_SOLID);
403 switch (osc.draw)
405 case DRAW_FILLED:
406 left = last_left;
407 right = last_right;
408 dl = (cur_left - left) / d;
409 dr = (cur_right - right) / d;
411 for (x = last_pos + 1; d > 0; x++, d--)
413 if (x == LCD_WIDTH)
414 x = 0;
416 left += dl;
417 right += dr;
419 rb->lcd_vline(x, LCD_HEIGHT/2-1,
420 LCD_HEIGHT/2-1 - (((LCD_HEIGHT-2) * left) >> 16));
421 rb->lcd_vline(x, LCD_HEIGHT/2+1,
422 LCD_HEIGHT/2+1 + (((LCD_HEIGHT-2) * right) >> 16));
424 break;
426 case DRAW_LINE:
427 if (cur_x > last_pos)
429 rb->lcd_drawline(
430 last_pos, LCD_HEIGHT/2-1 - (((LCD_HEIGHT-2) * last_left) >> 16),
431 cur_x, LCD_HEIGHT/2-1 - (((LCD_HEIGHT-2) * cur_left) >> 16)
433 rb->lcd_drawline(
434 last_pos, LCD_HEIGHT/2+1 + (((LCD_HEIGHT-2) * last_right) >> 16),
435 cur_x, LCD_HEIGHT/2+1 + (((LCD_HEIGHT-2) * cur_right) >> 16)
438 else
440 left = last_left
441 + (LCD_WIDTH - last_pos) * (last_left - cur_left) / d;
442 right = last_right
443 + (LCD_WIDTH - last_pos) * (last_right - cur_right) / d;
445 rb->lcd_drawline(
446 last_pos, LCD_HEIGHT/2-1 - (((LCD_HEIGHT-2) * last_left) >> 16),
447 LCD_WIDTH, LCD_HEIGHT/2-1 - (((LCD_HEIGHT-2) * left) >> 16)
449 rb->lcd_drawline(
450 last_pos, LCD_HEIGHT/2+1 + (((LCD_HEIGHT-2) * last_right) >> 16),
451 LCD_WIDTH, LCD_HEIGHT/2+1 + (((LCD_HEIGHT-2) * right) >> 16)
453 if (cur_x > 0)
455 rb->lcd_drawline(
456 0, LCD_HEIGHT/2-1 - (((LCD_HEIGHT-2) * left) >> 16),
457 cur_x, LCD_HEIGHT/2-1 - (((LCD_HEIGHT-2) * cur_left) >> 16)
459 rb->lcd_drawline(
460 0, LCD_HEIGHT/2+1 + (((LCD_HEIGHT-2) * right) >> 16),
461 cur_x, LCD_HEIGHT/2+1 + (((LCD_HEIGHT-2) * cur_right) >> 16)
465 break;
467 case DRAW_PIXEL:
468 left = last_left;
469 right = last_right;
470 dl = (cur_left - left) / d;
471 dr = (cur_right - right) / d;
473 for (x = last_pos + 1; d > 0; x++, d--)
475 if (x == LCD_WIDTH)
476 x = 0;
478 left += dl;
479 right += dr;
481 rb->lcd_drawpixel(x, LCD_HEIGHT/2-1 - (((LCD_HEIGHT-2) * left) >> 16));
482 rb->lcd_drawpixel(x, LCD_HEIGHT/2+1 + (((LCD_HEIGHT-2) * right) >> 16));
484 break;
487 last_left = cur_left;
488 last_right = cur_right;
490 if (displaymsg)
492 int width;
494 rb->lcd_getstringsize(message, &width, NULL);
495 last_pos -= width - 1;
496 rb->lcd_putsxy(last_pos, 0, message);
497 displaymsg = false;
499 if (last_pos < 0)
500 last_pos = 0;
503 if (full_update)
505 rb->lcd_update();
507 else
509 #if LCD_DEPTH > 1 /* cursor bar */
510 rb->lcd_set_foreground(CURSOR_COLOR);
511 rb->lcd_vline(cur_x + 1, 0, LCD_HEIGHT-1);
512 rb->lcd_set_foreground(GRAPH_COLOR);
513 #else
514 rb->lcd_set_drawmode(DRMODE_COMPLEMENT);
515 rb->lcd_vline(cur_x + 1, 0, LCD_HEIGHT-1);
516 rb->lcd_set_drawmode(DRMODE_SOLID);
517 #endif
519 if (cur_x > last_pos)
521 rb->lcd_update_rect(last_pos, 0, cur_x - last_pos + 2, LCD_HEIGHT);
523 else
525 rb->lcd_update_rect(last_pos, 0, LCD_WIDTH - last_pos, LCD_HEIGHT);
526 rb->lcd_update_rect(0, 0, cur_x + 2, LCD_HEIGHT);
529 last_pos = cur_x;
532 void anim_vertical(int cur_left, int cur_right)
534 int cur_y, y;
535 int left, right, dl, dr;
536 long cur_tick = *rb->current_tick;
537 long d = (cur_tick - last_tick) / osc.delay;
538 bool full_update = false;
540 if (d == 0) /* too early, bail out */
541 return;
543 last_tick = cur_tick;
545 if (d > HZ) /* first call or too much delay, (re)start */
547 last_left = cur_left;
548 last_right = cur_right;
549 return;
551 cur_y = last_pos + d;
553 if (cur_y >= LCD_HEIGHT)
555 if (osc.advance == ADV_SCROLL)
557 int shift = cur_y - (LCD_HEIGHT-1);
558 xlcd_scroll_up(shift);
559 full_update = true;
560 cur_y -= shift;
561 last_pos -= shift;
563 else
565 cur_y -= LCD_HEIGHT;
568 rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
570 if (cur_y > last_pos)
572 rb->lcd_fillrect(0, last_pos + 1, LCD_WIDTH, d);
574 else
576 rb->lcd_fillrect(0, last_pos + 1, LCD_WIDTH, LCD_HEIGHT - last_pos);
577 rb->lcd_fillrect(0, 0, LCD_WIDTH, cur_y + 1);
579 rb->lcd_set_drawmode(DRMODE_SOLID);
581 switch (osc.draw)
583 case DRAW_FILLED:
584 left = last_left;
585 right = last_right;
586 dl = (cur_left - left) / d;
587 dr = (cur_right - right) / d;
589 for (y = last_pos + 1; d > 0; y++, d--)
591 if (y == LCD_HEIGHT)
592 y = 0;
594 left += dl;
595 right += dr;
597 rb->lcd_hline(LCD_WIDTH/2-1,
598 LCD_WIDTH/2-1 - (((LCD_WIDTH-2) * left) >> 16), y);
599 rb->lcd_hline(LCD_WIDTH/2+1,
600 LCD_WIDTH/2+1 + (((LCD_WIDTH-2) * right) >> 16), y);
602 break;
604 case DRAW_LINE:
605 if (cur_y > last_pos)
607 rb->lcd_drawline(
608 LCD_WIDTH/2-1 - (((LCD_WIDTH-2) * last_left) >> 16), last_pos,
609 LCD_WIDTH/2-1 - (((LCD_WIDTH-2) * cur_left) >> 16), cur_y
611 rb->lcd_drawline(
612 LCD_WIDTH/2+1 + (((LCD_WIDTH-2) * last_right) >> 16), last_pos,
613 LCD_WIDTH/2+1 + (((LCD_WIDTH-2) * cur_right) >> 16), cur_y
616 else
618 left = last_left
619 + (LCD_HEIGHT - last_pos) * (last_left - cur_left) / d;
620 right = last_right
621 + (LCD_HEIGHT - last_pos) * (last_right - cur_right) / d;
623 rb->lcd_drawline(
624 LCD_WIDTH/2-1 - (((LCD_WIDTH-2) * last_left) >> 16), last_pos,
625 LCD_WIDTH/2-1 - (((LCD_WIDTH-2) * left) >> 16), LCD_HEIGHT
627 rb->lcd_drawline(
628 LCD_WIDTH/2+1 + (((LCD_WIDTH-2) * last_right) >> 16), last_pos,
629 LCD_WIDTH/2+1 + (((LCD_WIDTH-2) * right) >> 16), LCD_HEIGHT
631 if (cur_y > 0)
633 rb->lcd_drawline(
634 LCD_WIDTH/2-1 - (((LCD_WIDTH-2) * left) >> 16), 0,
635 LCD_WIDTH/2-1 - (((LCD_WIDTH-2) * cur_left) >> 16), cur_y
637 rb->lcd_drawline(
638 LCD_WIDTH/2+1 + (((LCD_WIDTH-2) * right) >> 16), 0,
639 LCD_WIDTH/2+1 + (((LCD_WIDTH-2) * cur_right) >> 16), cur_y
643 break;
645 case DRAW_PIXEL:
646 left = last_left;
647 right = last_right;
648 dl = (cur_left - left) / d;
649 dr = (cur_right - right) / d;
651 for (y = last_pos + 1; d > 0; y++, d--)
653 if (y == LCD_HEIGHT)
654 y = 0;
656 left += dl;
657 right += dr;
659 rb->lcd_drawpixel(LCD_WIDTH/2-1 - (((LCD_WIDTH-2) * left) >> 16), y);
660 rb->lcd_drawpixel(LCD_WIDTH/2+1 + (((LCD_WIDTH-2) * right) >> 16), y);
662 break;
665 last_left = cur_left;
666 last_right = cur_right;
668 if (displaymsg)
670 last_pos -= font_height - 1;
671 rb->lcd_putsxy(0, last_pos, message);
672 displaymsg = false;
674 if (last_pos < 0)
675 last_pos = 0;
678 if (full_update)
680 rb->lcd_update();
682 else
684 #if LCD_DEPTH > 1 /* cursor bar */
685 rb->lcd_set_foreground(CURSOR_COLOR);
686 rb->lcd_hline(0, LCD_WIDTH-1, cur_y + 1);
687 rb->lcd_set_foreground(GRAPH_COLOR);
688 #else
689 rb->lcd_set_drawmode(DRMODE_COMPLEMENT);
690 rb->lcd_hline(0, LCD_WIDTH-1, cur_y + 1);
691 rb->lcd_set_drawmode(DRMODE_SOLID);
692 #endif
694 if (cur_y > last_pos)
696 rb->lcd_update_rect(0, last_pos, LCD_WIDTH, cur_y - last_pos + 2);
698 else
700 rb->lcd_update_rect(0, last_pos, LCD_WIDTH, LCD_HEIGHT - last_pos);
701 rb->lcd_update_rect(0, 0, LCD_WIDTH, cur_y + 2);
704 last_pos = cur_y;
707 void cleanup(void *parameter)
709 (void)parameter;
710 #if LCD_DEPTH > 1
711 rb->lcd_set_foreground(LCD_DEFAULT_FG);
712 rb->lcd_set_background(LCD_DEFAULT_BG);
713 #endif
714 /* Turn on backlight timeout (revert to settings) */
715 backlight_use_settings(); /* backlight control in lib/helper.c */
718 enum plugin_status plugin_start(const void* parameter)
720 int button, vol;
721 int lastbutton = BUTTON_NONE;
722 bool exit = false;
723 bool paused = false;
724 bool tell_speed;
726 (void)parameter;
728 configfile_load(cfg_filename, disk_config,
729 sizeof(disk_config) / sizeof(disk_config[0]),
730 CFGFILE_MINVERSION);
731 rb->memcpy(&osc, &osc_disk, sizeof(osc)); /* copy to running config */
733 #if LCD_DEPTH > 1
734 rb->lcd_set_foreground(GRAPH_COLOR);
735 rb->lcd_set_background(BACKG_COLOR);
736 rb->lcd_set_backdrop(NULL);
737 rb->lcd_clear_display();
738 rb->lcd_update();
739 #endif
741 /* Turn off backlight timeout */
742 backlight_force_on(); /* backlight control in lib/helper.c */
744 rb->lcd_getstringsize("A", NULL, &font_height);
746 while (!exit)
748 if (!paused)
750 int left, right;
752 rb->sleep(MAX(last_tick + osc.delay - *rb->current_tick - 1, 0));
754 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
755 left = rb->mas_codec_readreg(0xC);
756 right = rb->mas_codec_readreg(0xD);
757 #elif (CONFIG_CODEC == SWCODEC)
758 rb->pcm_calculate_peaks(&left, &right);
759 #endif
760 if (osc.orientation == OSC_HORIZ)
761 anim_horizontal(left, right);
762 else
763 anim_vertical(left, right);
766 tell_speed = false;
767 button = rb->button_get(paused);
768 switch (button)
770 #ifdef OSCILLOSCOPE_RC_QUIT
771 case OSCILLOSCOPE_RC_QUIT:
772 #endif
773 case OSCILLOSCOPE_QUIT:
774 exit = true;
775 break;
777 case OSCILLOSCOPE_ADVMODE:
778 if (++osc.advance >= MAX_ADV)
779 osc.advance = 0;
780 break;
782 case OSCILLOSCOPE_DRAWMODE:
783 #ifdef OSCILLOSCOPE_DRAWMODE_PRE
784 if (lastbutton != OSCILLOSCOPE_DRAWMODE_PRE)
785 break;
786 #endif
787 if (++osc.draw >= MAX_DRAW)
788 osc.draw = 0;
789 break;
791 case OSCILLOSCOPE_ORIENTATION:
792 #ifdef OSCILLOSCOPE_ORIENTATION_PRE
793 if (lastbutton != OSCILLOSCOPE_ORIENTATION_PRE)
794 break;
795 #endif
796 if (++osc.orientation >= MAX_OSC)
797 osc.orientation = 0;
798 last_pos = 0;
799 last_tick = 0;
800 displaymsg = false;
801 rb->lcd_clear_display();
802 rb->lcd_update();
803 break;
805 case OSCILLOSCOPE_PAUSE:
806 paused = !paused;
807 last_tick = 0;
808 break;
810 case OSCILLOSCOPE_SPEED_UP:
811 case OSCILLOSCOPE_SPEED_UP | BUTTON_REPEAT:
812 if (osc.delay > 1)
814 osc.delay--;
815 tell_speed = true;
817 break;
819 case OSCILLOSCOPE_SPEED_DOWN:
820 case OSCILLOSCOPE_SPEED_DOWN | BUTTON_REPEAT:
821 osc.delay++;
822 tell_speed = true;
823 break;
825 case OSCILLOSCOPE_VOL_UP:
826 case OSCILLOSCOPE_VOL_UP | BUTTON_REPEAT:
827 vol = rb->global_settings->volume;
828 if (vol < rb->sound_max(SOUND_VOLUME))
830 vol++;
831 rb->sound_set(SOUND_VOLUME, vol);
832 rb->global_settings->volume = vol;
834 break;
836 case OSCILLOSCOPE_VOL_DOWN:
837 case OSCILLOSCOPE_VOL_DOWN | BUTTON_REPEAT:
838 vol = rb->global_settings->volume;
839 if (vol > rb->sound_min(SOUND_VOLUME))
841 vol--;
842 rb->sound_set(SOUND_VOLUME, vol);
843 rb->global_settings->volume = vol;
845 break;
847 default:
848 if (rb->default_event_handler_ex(button, cleanup, NULL)
849 == SYS_USB_CONNECTED)
850 return PLUGIN_USB_CONNECTED;
851 break;
853 if (button != BUTTON_NONE)
854 lastbutton = button;
856 if (tell_speed)
858 rb->snprintf(message, sizeof(message), "%s%d",
859 (osc.orientation == OSC_VERT) ? "Speed: " : "",
860 100 / osc.delay);
861 displaymsg = true;
864 cleanup(NULL);
865 if (rb->memcmp(&osc, &osc_disk, sizeof(osc))) /* save settings if changed */
867 rb->memcpy(&osc_disk, &osc, sizeof(osc));
868 configfile_save(cfg_filename, disk_config,
869 sizeof(disk_config) / sizeof(disk_config[0]),
870 CFGFILE_VERSION);
872 return PLUGIN_OK;
874 #endif /* HAVE_LCD_BITMAP */