Remove plugin-specific defines from the pdbox makefile, and add them to m_pd.h, which...
[kugel-rb.git] / apps / plugins / oscilloscope.c
blob4195d96d5fa554d1d46321cc11b3ab56c0eae31d
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 == COWON_D2_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 == PHILIPS_SA9200_PAD
247 #define OSCILLOSCOPE_QUIT BUTTON_POWER
248 #define OSCILLOSCOPE_DRAWMODE BUTTON_MENU
249 #define OSCILLOSCOPE_ADVMODE BUTTON_RIGHT
250 #define OSCILLOSCOPE_ORIENTATION BUTTON_UP
251 #define OSCILLOSCOPE_PAUSE BUTTON_PLAY
252 #define OSCILLOSCOPE_SPEED_UP BUTTON_NEXT
253 #define OSCILLOSCOPE_SPEED_DOWN BUTTON_PREV
254 #define OSCILLOSCOPE_VOL_UP BUTTON_VOL_UP
255 #define OSCILLOSCOPE_VOL_DOWN BUTTON_VOL_DOWN
257 #elif CONFIG_KEYPAD == ONDAVX747_PAD
258 #define OSCILLOSCOPE_QUIT BUTTON_POWER
259 #define OSCILLOSCOPE_VOL_UP BUTTON_VOL_UP
260 #define OSCILLOSCOPE_VOL_DOWN BUTTON_VOL_DOWN
262 #elif CONFIG_KEYPAD == ONDAVX777_PAD
263 #define OSCILLOSCOPE_QUIT BUTTON_POWER
265 #elif CONFIG_KEYPAD == MROBE500_PAD
266 #define OSCILLOSCOPE_QUIT BUTTON_POWER
268 #elif CONFIG_KEYPAD == SAMSUNG_YH_PAD
269 #define OSCILLOSCOPE_QUIT BUTTON_REC
270 #define OSCILLOSCOPE_DRAWMODE (BUTTON_PLAY|BUTTON_LEFT)
271 #define OSCILLOSCOPE_ADVMODE (BUTTON_PLAY|BUTTON_RIGHT)
272 #define OSCILLOSCOPE_ORIENTATION (BUTTON_PLAY|BUTTON_UP)
273 #define OSCILLOSCOPE_PAUSE (BUTTON_PLAY|BUTTON_DOWN)
274 #define OSCILLOSCOPE_SPEED_UP BUTTON_RIGHT
275 #define OSCILLOSCOPE_SPEED_DOWN BUTTON_LEFT
276 #define OSCILLOSCOPE_VOL_UP BUTTON_UP
277 #define OSCILLOSCOPE_VOL_DOWN BUTTON_DOWN
279 #elif CONFIG_KEYPAD == PBELL_VIBE500_PAD
280 #define OSCILLOSCOPE_QUIT BUTTON_REC
281 #define OSCILLOSCOPE_DRAWMODE BUTTON_MENU
282 #define OSCILLOSCOPE_ADVMODE BUTTON_CANCEL
283 #define OSCILLOSCOPE_ORIENTATION BUTTON_OK
284 #define OSCILLOSCOPE_PAUSE BUTTON_PLAY
285 #define OSCILLOSCOPE_SPEED_UP BUTTON_PREV
286 #define OSCILLOSCOPE_SPEED_DOWN BUTTON_NEXT
287 #define OSCILLOSCOPE_VOL_UP BUTTON_UP
288 #define OSCILLOSCOPE_VOL_DOWN BUTTON_DOWN
290 #elif CONFIG_KEYPAD == MPIO_HD200_PAD
291 #define OSCILLOSCOPE_QUIT (BUTTON_REC | BUTTON_PLAY)
292 #define OSCILLOSCOPE_DRAWMODE BUTTON_SELECT
293 #define OSCILLOSCOPE_ADVMODE BUTTON_REC
294 #define OSCILLOSCOPE_ORIENTATION (BUTTON_SELECT|BUTTON_REPEAT)
295 #define OSCILLOSCOPE_PAUSE BUTTON_PLAY
296 #define OSCILLOSCOPE_SPEED_UP BUTTON_NEXT
297 #define OSCILLOSCOPE_SPEED_DOWN BUTTON_PREV
298 #define OSCILLOSCOPE_VOL_UP BUTTON_VOL_UP
299 #define OSCILLOSCOPE_VOL_DOWN BUTTON_VOL_DOWN
301 #else
302 #error No keymap defined!
303 #endif
305 #ifdef HAVE_TOUCHSCREEN
306 #ifndef OSCILLOSCOPE_QUIT
307 #define OSCILLOSCOPE_QUIT BUTTON_TOPLEFT
308 #endif
309 #ifndef OSCILLOSCOPE_DRAWMODE
310 #define OSCILLOSCOPE_DRAWMODE BUTTON_TOPMIDDLE
311 #endif
312 #ifndef OSCILLOSCOPE_ADVMODE
313 #define OSCILLOSCOPE_ADVMODE BUTTON_BOTTOMMIDDLE
314 #endif
315 #ifndef OSCILLOSCOPE_ORIENTATION
316 #define OSCILLOSCOPE_ORIENTATION BUTTON_BOTTOMLEFT
317 #endif
318 #ifndef OSCILLOSCOPE_PAUSE
319 #define OSCILLOSCOPE_PAUSE BUTTON_CENTER
320 #endif
321 #ifndef OSCILLOSCOPE_SPEED_UP
322 #define OSCILLOSCOPE_SPEED_UP BUTTON_MIDRIGHT
323 #endif
324 #ifndef OSCILLOSCOPE_SPEED_DOWN
325 #define OSCILLOSCOPE_SPEED_DOWN BUTTON_MIDLEFT
326 #endif
327 #ifndef OSCILLOSCOPE_VOL_UP
328 #define OSCILLOSCOPE_VOL_UP BUTTON_TOPRIGHT
329 #endif
330 #ifndef OSCILLOSCOPE_VOL_DOWN
331 #define OSCILLOSCOPE_VOL_DOWN BUTTON_BOTTOMRIGHT
332 #endif
333 #endif
335 /* colours */
336 #if LCD_DEPTH > 1
337 #ifdef HAVE_LCD_COLOR
338 #define BACKG_COLOR LCD_BLACK
339 #define GRAPH_COLOR LCD_RGBPACK(128, 255, 0)
340 #define CURSOR_COLOR LCD_RGBPACK(255, 0, 0)
341 #else
342 #define BACKG_COLOR LCD_WHITE
343 #define GRAPH_COLOR LCD_BLACK
344 #define CURSOR_COLOR LCD_DARKGRAY
345 #endif
346 #endif
348 enum { DRAW_FILLED, DRAW_LINE, DRAW_PIXEL, MAX_DRAW };
349 enum { ADV_SCROLL, ADV_WRAP, MAX_ADV };
350 enum { OSC_HORIZ, OSC_VERT, MAX_OSC };
352 #define CFGFILE_VERSION 0 /* Current config file version */
353 #define CFGFILE_MINVERSION 0 /* Minimum config file version to accept */
356 #define MAX_PEAK 0x8000
358 #if defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
359 #define mas_codec_readreg(x) rand()%MAX_PEAK
360 #endif
362 /* global variables */
364 /* settings */
365 struct osc_config {
366 int delay; /* in ticks */
367 int draw;
368 int advance;
369 int orientation;
372 struct osc_config osc_disk = { 2, DRAW_FILLED, ADV_SCROLL, OSC_HORIZ };
373 struct osc_config osc; /* running config */
375 static const char cfg_filename[] = "oscilloscope.cfg";
376 static char *draw_str[3] = { "filled", "line", "pixel" };
377 static char *advance_str[2] = { "scroll", "wrap" };
378 static char *orientation_str[2] = { "horizontal", "vertical" };
380 struct configdata disk_config[] = {
381 { TYPE_INT, 1, 99, { .int_p = &osc_disk.delay }, "delay", NULL },
382 { TYPE_ENUM, 0, MAX_DRAW, { .int_p = &osc_disk.draw }, "draw", draw_str },
383 { TYPE_ENUM, 0, MAX_ADV, { .int_p = &osc_disk.advance }, "advance",
384 advance_str },
385 { TYPE_ENUM, 0, MAX_OSC, { .int_p = &osc_disk.orientation }, "orientation",
386 orientation_str }
390 long last_tick = 0; /* time of last drawing */
391 int last_pos = 0; /* last x or y drawing position. Reset for aspect switch. */
392 int last_left; /* last channel values */
393 int last_right;
395 unsigned char message[16]; /* message to display */
396 bool displaymsg = false;
397 int font_height = 8;
399 /* implementation */
401 void anim_horizontal(int cur_left, int cur_right)
403 int cur_x, x;
404 int left, right, dl, dr;
405 long cur_tick = *rb->current_tick;
406 long d = (cur_tick - last_tick) / osc.delay;
407 bool full_update = false;
409 if (d == 0) /* too early, bail out */
410 return;
412 last_tick = cur_tick;
414 if (d > HZ) /* first call or too much delay, (re)start */
416 last_left = cur_left;
417 last_right = cur_right;
418 return;
420 cur_x = last_pos + d;
422 if (cur_x >= LCD_WIDTH)
424 if (osc.advance == ADV_SCROLL)
426 int shift = cur_x - (LCD_WIDTH-1);
427 xlcd_scroll_left(shift);
428 full_update = true;
429 cur_x -= shift;
430 last_pos -= shift;
432 else
434 cur_x -= LCD_WIDTH;
437 rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
439 if (cur_x > last_pos)
441 rb->lcd_fillrect(last_pos + 1, 0, d, LCD_HEIGHT);
443 else
445 rb->lcd_fillrect(last_pos + 1, 0, LCD_WIDTH - last_pos, LCD_HEIGHT);
446 rb->lcd_fillrect(0, 0, cur_x + 1, LCD_HEIGHT);
448 rb->lcd_set_drawmode(DRMODE_SOLID);
450 switch (osc.draw)
452 case DRAW_FILLED:
453 left = last_left;
454 right = last_right;
455 dl = (cur_left - left) / d;
456 dr = (cur_right - right) / d;
458 for (x = last_pos + 1; d > 0; x++, d--)
460 if (x == LCD_WIDTH)
461 x = 0;
463 left += dl;
464 right += dr;
466 rb->lcd_vline(x, LCD_HEIGHT/2-1,
467 LCD_HEIGHT/2-1 - (((LCD_HEIGHT-2) * left) >> 16));
468 rb->lcd_vline(x, LCD_HEIGHT/2+1,
469 LCD_HEIGHT/2+1 + (((LCD_HEIGHT-2) * right) >> 16));
471 break;
473 case DRAW_LINE:
474 if (cur_x > last_pos)
476 rb->lcd_drawline(
477 last_pos, LCD_HEIGHT/2-1 - (((LCD_HEIGHT-2) * last_left) >> 16),
478 cur_x, LCD_HEIGHT/2-1 - (((LCD_HEIGHT-2) * cur_left) >> 16)
480 rb->lcd_drawline(
481 last_pos, LCD_HEIGHT/2+1 + (((LCD_HEIGHT-2) * last_right) >> 16),
482 cur_x, LCD_HEIGHT/2+1 + (((LCD_HEIGHT-2) * cur_right) >> 16)
485 else
487 left = last_left
488 + (LCD_WIDTH - last_pos) * (last_left - cur_left) / d;
489 right = last_right
490 + (LCD_WIDTH - last_pos) * (last_right - cur_right) / d;
492 rb->lcd_drawline(
493 last_pos, LCD_HEIGHT/2-1 - (((LCD_HEIGHT-2) * last_left) >> 16),
494 LCD_WIDTH, LCD_HEIGHT/2-1 - (((LCD_HEIGHT-2) * left) >> 16)
496 rb->lcd_drawline(
497 last_pos, LCD_HEIGHT/2+1 + (((LCD_HEIGHT-2) * last_right) >> 16),
498 LCD_WIDTH, LCD_HEIGHT/2+1 + (((LCD_HEIGHT-2) * right) >> 16)
500 if (cur_x > 0)
502 rb->lcd_drawline(
503 0, LCD_HEIGHT/2-1 - (((LCD_HEIGHT-2) * left) >> 16),
504 cur_x, LCD_HEIGHT/2-1 - (((LCD_HEIGHT-2) * cur_left) >> 16)
506 rb->lcd_drawline(
507 0, LCD_HEIGHT/2+1 + (((LCD_HEIGHT-2) * right) >> 16),
508 cur_x, LCD_HEIGHT/2+1 + (((LCD_HEIGHT-2) * cur_right) >> 16)
512 break;
514 case DRAW_PIXEL:
515 left = last_left;
516 right = last_right;
517 dl = (cur_left - left) / d;
518 dr = (cur_right - right) / d;
520 for (x = last_pos + 1; d > 0; x++, d--)
522 if (x == LCD_WIDTH)
523 x = 0;
525 left += dl;
526 right += dr;
528 rb->lcd_drawpixel(x, LCD_HEIGHT/2-1 - (((LCD_HEIGHT-2) * left) >> 16));
529 rb->lcd_drawpixel(x, LCD_HEIGHT/2+1 + (((LCD_HEIGHT-2) * right) >> 16));
531 break;
534 last_left = cur_left;
535 last_right = cur_right;
537 if (displaymsg)
539 int width;
541 rb->lcd_getstringsize(message, &width, NULL);
542 last_pos -= width - 1;
543 rb->lcd_putsxy(last_pos, 0, message);
544 displaymsg = false;
546 if (last_pos < 0)
547 last_pos = 0;
550 if (full_update)
552 rb->lcd_update();
554 else
556 #if LCD_DEPTH > 1 /* cursor bar */
557 rb->lcd_set_foreground(CURSOR_COLOR);
558 rb->lcd_vline(cur_x + 1, 0, LCD_HEIGHT-1);
559 rb->lcd_set_foreground(GRAPH_COLOR);
560 #else
561 rb->lcd_set_drawmode(DRMODE_COMPLEMENT);
562 rb->lcd_vline(cur_x + 1, 0, LCD_HEIGHT-1);
563 rb->lcd_set_drawmode(DRMODE_SOLID);
564 #endif
566 if (cur_x > last_pos)
568 rb->lcd_update_rect(last_pos, 0, cur_x - last_pos + 2, LCD_HEIGHT);
570 else
572 rb->lcd_update_rect(last_pos, 0, LCD_WIDTH - last_pos, LCD_HEIGHT);
573 rb->lcd_update_rect(0, 0, cur_x + 2, LCD_HEIGHT);
576 last_pos = cur_x;
579 void anim_vertical(int cur_left, int cur_right)
581 int cur_y, y;
582 int left, right, dl, dr;
583 long cur_tick = *rb->current_tick;
584 long d = (cur_tick - last_tick) / osc.delay;
585 bool full_update = false;
587 if (d == 0) /* too early, bail out */
588 return;
590 last_tick = cur_tick;
592 if (d > HZ) /* first call or too much delay, (re)start */
594 last_left = cur_left;
595 last_right = cur_right;
596 return;
598 cur_y = last_pos + d;
600 if (cur_y >= LCD_HEIGHT)
602 if (osc.advance == ADV_SCROLL)
604 int shift = cur_y - (LCD_HEIGHT-1);
605 xlcd_scroll_up(shift);
606 full_update = true;
607 cur_y -= shift;
608 last_pos -= shift;
610 else
612 cur_y -= LCD_HEIGHT;
615 rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
617 if (cur_y > last_pos)
619 rb->lcd_fillrect(0, last_pos + 1, LCD_WIDTH, d);
621 else
623 rb->lcd_fillrect(0, last_pos + 1, LCD_WIDTH, LCD_HEIGHT - last_pos);
624 rb->lcd_fillrect(0, 0, LCD_WIDTH, cur_y + 1);
626 rb->lcd_set_drawmode(DRMODE_SOLID);
628 switch (osc.draw)
630 case DRAW_FILLED:
631 left = last_left;
632 right = last_right;
633 dl = (cur_left - left) / d;
634 dr = (cur_right - right) / d;
636 for (y = last_pos + 1; d > 0; y++, d--)
638 if (y == LCD_HEIGHT)
639 y = 0;
641 left += dl;
642 right += dr;
644 rb->lcd_hline(LCD_WIDTH/2-1,
645 LCD_WIDTH/2-1 - (((LCD_WIDTH-2) * left) >> 16), y);
646 rb->lcd_hline(LCD_WIDTH/2+1,
647 LCD_WIDTH/2+1 + (((LCD_WIDTH-2) * right) >> 16), y);
649 break;
651 case DRAW_LINE:
652 if (cur_y > last_pos)
654 rb->lcd_drawline(
655 LCD_WIDTH/2-1 - (((LCD_WIDTH-2) * last_left) >> 16), last_pos,
656 LCD_WIDTH/2-1 - (((LCD_WIDTH-2) * cur_left) >> 16), cur_y
658 rb->lcd_drawline(
659 LCD_WIDTH/2+1 + (((LCD_WIDTH-2) * last_right) >> 16), last_pos,
660 LCD_WIDTH/2+1 + (((LCD_WIDTH-2) * cur_right) >> 16), cur_y
663 else
665 left = last_left
666 + (LCD_HEIGHT - last_pos) * (last_left - cur_left) / d;
667 right = last_right
668 + (LCD_HEIGHT - last_pos) * (last_right - cur_right) / d;
670 rb->lcd_drawline(
671 LCD_WIDTH/2-1 - (((LCD_WIDTH-2) * last_left) >> 16), last_pos,
672 LCD_WIDTH/2-1 - (((LCD_WIDTH-2) * left) >> 16), LCD_HEIGHT
674 rb->lcd_drawline(
675 LCD_WIDTH/2+1 + (((LCD_WIDTH-2) * last_right) >> 16), last_pos,
676 LCD_WIDTH/2+1 + (((LCD_WIDTH-2) * right) >> 16), LCD_HEIGHT
678 if (cur_y > 0)
680 rb->lcd_drawline(
681 LCD_WIDTH/2-1 - (((LCD_WIDTH-2) * left) >> 16), 0,
682 LCD_WIDTH/2-1 - (((LCD_WIDTH-2) * cur_left) >> 16), cur_y
684 rb->lcd_drawline(
685 LCD_WIDTH/2+1 + (((LCD_WIDTH-2) * right) >> 16), 0,
686 LCD_WIDTH/2+1 + (((LCD_WIDTH-2) * cur_right) >> 16), cur_y
690 break;
692 case DRAW_PIXEL:
693 left = last_left;
694 right = last_right;
695 dl = (cur_left - left) / d;
696 dr = (cur_right - right) / d;
698 for (y = last_pos + 1; d > 0; y++, d--)
700 if (y == LCD_HEIGHT)
701 y = 0;
703 left += dl;
704 right += dr;
706 rb->lcd_drawpixel(LCD_WIDTH/2-1 - (((LCD_WIDTH-2) * left) >> 16), y);
707 rb->lcd_drawpixel(LCD_WIDTH/2+1 + (((LCD_WIDTH-2) * right) >> 16), y);
709 break;
712 last_left = cur_left;
713 last_right = cur_right;
715 if (displaymsg)
717 last_pos -= font_height - 1;
718 rb->lcd_putsxy(0, last_pos, message);
719 displaymsg = false;
721 if (last_pos < 0)
722 last_pos = 0;
725 if (full_update)
727 rb->lcd_update();
729 else
731 #if LCD_DEPTH > 1 /* cursor bar */
732 rb->lcd_set_foreground(CURSOR_COLOR);
733 rb->lcd_hline(0, LCD_WIDTH-1, cur_y + 1);
734 rb->lcd_set_foreground(GRAPH_COLOR);
735 #else
736 rb->lcd_set_drawmode(DRMODE_COMPLEMENT);
737 rb->lcd_hline(0, LCD_WIDTH-1, cur_y + 1);
738 rb->lcd_set_drawmode(DRMODE_SOLID);
739 #endif
741 if (cur_y > last_pos)
743 rb->lcd_update_rect(0, last_pos, LCD_WIDTH, cur_y - last_pos + 2);
745 else
747 rb->lcd_update_rect(0, last_pos, LCD_WIDTH, LCD_HEIGHT - last_pos);
748 rb->lcd_update_rect(0, 0, LCD_WIDTH, cur_y + 2);
751 last_pos = cur_y;
754 void cleanup(void *parameter)
756 (void)parameter;
757 #if LCD_DEPTH > 1
758 rb->lcd_set_foreground(LCD_DEFAULT_FG);
759 rb->lcd_set_background(LCD_DEFAULT_BG);
760 #endif
761 /* Turn on backlight timeout (revert to settings) */
762 backlight_use_settings(); /* backlight control in lib/helper.c */
765 enum plugin_status plugin_start(const void* parameter)
767 int button, vol;
768 int lastbutton = BUTTON_NONE;
769 bool exit = false;
770 bool paused = false;
771 bool tell_speed;
773 (void)parameter;
775 configfile_load(cfg_filename, disk_config,
776 sizeof(disk_config) / sizeof(disk_config[0]),
777 CFGFILE_MINVERSION);
778 rb->memcpy(&osc, &osc_disk, sizeof(osc)); /* copy to running config */
780 #if LCD_DEPTH > 1
781 rb->lcd_set_foreground(GRAPH_COLOR);
782 rb->lcd_set_background(BACKG_COLOR);
783 rb->lcd_set_backdrop(NULL);
784 rb->lcd_clear_display();
785 rb->lcd_update();
786 #endif
788 /* Turn off backlight timeout */
789 backlight_force_on(); /* backlight control in lib/helper.c */
791 rb->lcd_getstringsize("A", NULL, &font_height);
793 while (!exit)
795 if (!paused)
797 int left, right;
799 rb->sleep(MAX(last_tick + osc.delay - *rb->current_tick - 1, 0));
801 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
802 left = rb->mas_codec_readreg(0xC);
803 right = rb->mas_codec_readreg(0xD);
804 #elif (CONFIG_CODEC == SWCODEC)
805 rb->pcm_calculate_peaks(&left, &right);
806 #endif
807 if (osc.orientation == OSC_HORIZ)
808 anim_horizontal(left, right);
809 else
810 anim_vertical(left, right);
813 tell_speed = false;
814 button = rb->button_get(paused);
815 switch (button)
817 #ifdef OSCILLOSCOPE_RC_QUIT
818 case OSCILLOSCOPE_RC_QUIT:
819 #endif
820 case OSCILLOSCOPE_QUIT:
821 exit = true;
822 break;
824 case OSCILLOSCOPE_ADVMODE:
825 if (++osc.advance >= MAX_ADV)
826 osc.advance = 0;
827 break;
829 case OSCILLOSCOPE_DRAWMODE:
830 #ifdef OSCILLOSCOPE_DRAWMODE_PRE
831 if (lastbutton != OSCILLOSCOPE_DRAWMODE_PRE)
832 break;
833 #endif
834 if (++osc.draw >= MAX_DRAW)
835 osc.draw = 0;
836 break;
838 case OSCILLOSCOPE_ORIENTATION:
839 #ifdef OSCILLOSCOPE_ORIENTATION_PRE
840 if (lastbutton != OSCILLOSCOPE_ORIENTATION_PRE)
841 break;
842 #endif
843 if (++osc.orientation >= MAX_OSC)
844 osc.orientation = 0;
845 last_pos = 0;
846 last_tick = 0;
847 displaymsg = false;
848 rb->lcd_clear_display();
849 rb->lcd_update();
850 break;
852 case OSCILLOSCOPE_PAUSE:
853 paused = !paused;
854 last_tick = 0;
855 break;
857 case OSCILLOSCOPE_SPEED_UP:
858 case OSCILLOSCOPE_SPEED_UP | BUTTON_REPEAT:
859 if (osc.delay > 1)
861 osc.delay--;
862 tell_speed = true;
864 break;
866 case OSCILLOSCOPE_SPEED_DOWN:
867 case OSCILLOSCOPE_SPEED_DOWN | BUTTON_REPEAT:
868 osc.delay++;
869 tell_speed = true;
870 break;
872 case OSCILLOSCOPE_VOL_UP:
873 case OSCILLOSCOPE_VOL_UP | BUTTON_REPEAT:
874 vol = rb->global_settings->volume;
875 if (vol < rb->sound_max(SOUND_VOLUME))
877 vol++;
878 rb->sound_set(SOUND_VOLUME, vol);
879 rb->global_settings->volume = vol;
881 break;
883 case OSCILLOSCOPE_VOL_DOWN:
884 case OSCILLOSCOPE_VOL_DOWN | BUTTON_REPEAT:
885 vol = rb->global_settings->volume;
886 if (vol > rb->sound_min(SOUND_VOLUME))
888 vol--;
889 rb->sound_set(SOUND_VOLUME, vol);
890 rb->global_settings->volume = vol;
892 break;
894 default:
895 if (rb->default_event_handler_ex(button, cleanup, NULL)
896 == SYS_USB_CONNECTED)
897 return PLUGIN_USB_CONNECTED;
898 break;
900 if (button != BUTTON_NONE)
901 lastbutton = button;
903 if (tell_speed)
905 rb->snprintf(message, sizeof(message), "%s%d",
906 (osc.orientation == OSC_VERT) ? "Speed: " : "",
907 100 / osc.delay);
908 displaymsg = true;
911 cleanup(NULL);
912 if (rb->memcmp(&osc, &osc_disk, sizeof(osc))) /* save settings if changed */
914 rb->memcpy(&osc_disk, &osc, sizeof(osc));
915 configfile_save(cfg_filename, disk_config,
916 sizeof(disk_config) / sizeof(disk_config[0]),
917 CFGFILE_VERSION);
919 return PLUGIN_OK;
921 #endif /* HAVE_LCD_BITMAP */