Re-add the lseek to the beginning of the file which was accidentally removed.
[kugel-rb.git] / apps / plugins / oscilloscope.c
blob2d0d58eca5e70922a16547db1c1bb76a5a67d4ae
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"
26 #include "lib/pluginlib_exit.h"
28 #include "lib/xlcd.h"
29 #include "lib/configfile.h"
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_HDD6330_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 == PHILIPS_SA9200_PAD
258 #define OSCILLOSCOPE_QUIT BUTTON_POWER
259 #define OSCILLOSCOPE_DRAWMODE BUTTON_MENU
260 #define OSCILLOSCOPE_ADVMODE BUTTON_RIGHT
261 #define OSCILLOSCOPE_ORIENTATION BUTTON_UP
262 #define OSCILLOSCOPE_PAUSE BUTTON_PLAY
263 #define OSCILLOSCOPE_SPEED_UP BUTTON_NEXT
264 #define OSCILLOSCOPE_SPEED_DOWN BUTTON_PREV
265 #define OSCILLOSCOPE_VOL_UP BUTTON_VOL_UP
266 #define OSCILLOSCOPE_VOL_DOWN BUTTON_VOL_DOWN
268 #elif CONFIG_KEYPAD == ONDAVX747_PAD
269 #define OSCILLOSCOPE_QUIT BUTTON_POWER
270 #define OSCILLOSCOPE_VOL_UP BUTTON_VOL_UP
271 #define OSCILLOSCOPE_VOL_DOWN BUTTON_VOL_DOWN
273 #elif CONFIG_KEYPAD == ONDAVX777_PAD
274 #define OSCILLOSCOPE_QUIT BUTTON_POWER
276 #elif CONFIG_KEYPAD == MROBE500_PAD
277 #define OSCILLOSCOPE_QUIT BUTTON_POWER
279 #elif CONFIG_KEYPAD == SAMSUNG_YH_PAD
280 #define OSCILLOSCOPE_QUIT BUTTON_REC
281 #define OSCILLOSCOPE_DRAWMODE (BUTTON_PLAY|BUTTON_LEFT)
282 #define OSCILLOSCOPE_ADVMODE (BUTTON_PLAY|BUTTON_RIGHT)
283 #define OSCILLOSCOPE_ORIENTATION (BUTTON_PLAY|BUTTON_UP)
284 #define OSCILLOSCOPE_PAUSE (BUTTON_PLAY|BUTTON_DOWN)
285 #define OSCILLOSCOPE_SPEED_UP BUTTON_RIGHT
286 #define OSCILLOSCOPE_SPEED_DOWN BUTTON_LEFT
287 #define OSCILLOSCOPE_VOL_UP BUTTON_UP
288 #define OSCILLOSCOPE_VOL_DOWN BUTTON_DOWN
290 #elif CONFIG_KEYPAD == PBELL_VIBE500_PAD
291 #define OSCILLOSCOPE_QUIT BUTTON_REC
292 #define OSCILLOSCOPE_DRAWMODE BUTTON_MENU
293 #define OSCILLOSCOPE_ADVMODE BUTTON_CANCEL
294 #define OSCILLOSCOPE_ORIENTATION BUTTON_OK
295 #define OSCILLOSCOPE_PAUSE BUTTON_PLAY
296 #define OSCILLOSCOPE_SPEED_UP BUTTON_PREV
297 #define OSCILLOSCOPE_SPEED_DOWN BUTTON_NEXT
298 #define OSCILLOSCOPE_VOL_UP BUTTON_UP
299 #define OSCILLOSCOPE_VOL_DOWN BUTTON_DOWN
301 #elif CONFIG_KEYPAD == MPIO_HD200_PAD
302 #define OSCILLOSCOPE_QUIT (BUTTON_REC | BUTTON_PLAY)
303 #define OSCILLOSCOPE_DRAWMODE BUTTON_FUNC
304 #define OSCILLOSCOPE_ADVMODE BUTTON_REC
305 #define OSCILLOSCOPE_ORIENTATION (BUTTON_FUNC|BUTTON_REPEAT)
306 #define OSCILLOSCOPE_PAUSE BUTTON_PLAY
307 #define OSCILLOSCOPE_SPEED_UP BUTTON_FF
308 #define OSCILLOSCOPE_SPEED_DOWN BUTTON_REW
309 #define OSCILLOSCOPE_VOL_UP BUTTON_VOL_UP
310 #define OSCILLOSCOPE_VOL_DOWN BUTTON_VOL_DOWN
312 #else
313 #error No keymap defined!
314 #endif
316 #ifdef HAVE_TOUCHSCREEN
317 #ifndef OSCILLOSCOPE_QUIT
318 #define OSCILLOSCOPE_QUIT BUTTON_TOPLEFT
319 #endif
320 #ifndef OSCILLOSCOPE_DRAWMODE
321 #define OSCILLOSCOPE_DRAWMODE BUTTON_TOPMIDDLE
322 #endif
323 #ifndef OSCILLOSCOPE_ADVMODE
324 #define OSCILLOSCOPE_ADVMODE BUTTON_BOTTOMMIDDLE
325 #endif
326 #ifndef OSCILLOSCOPE_ORIENTATION
327 #define OSCILLOSCOPE_ORIENTATION BUTTON_BOTTOMLEFT
328 #endif
329 #ifndef OSCILLOSCOPE_PAUSE
330 #define OSCILLOSCOPE_PAUSE BUTTON_CENTER
331 #endif
332 #ifndef OSCILLOSCOPE_SPEED_UP
333 #define OSCILLOSCOPE_SPEED_UP BUTTON_MIDRIGHT
334 #endif
335 #ifndef OSCILLOSCOPE_SPEED_DOWN
336 #define OSCILLOSCOPE_SPEED_DOWN BUTTON_MIDLEFT
337 #endif
338 #ifndef OSCILLOSCOPE_VOL_UP
339 #define OSCILLOSCOPE_VOL_UP BUTTON_TOPRIGHT
340 #endif
341 #ifndef OSCILLOSCOPE_VOL_DOWN
342 #define OSCILLOSCOPE_VOL_DOWN BUTTON_BOTTOMRIGHT
343 #endif
344 #endif
346 /* colours */
347 #if LCD_DEPTH > 1
348 #ifdef HAVE_LCD_COLOR
349 #define BACKG_COLOR LCD_BLACK
350 #define GRAPH_COLOR LCD_RGBPACK(128, 255, 0)
351 #define CURSOR_COLOR LCD_RGBPACK(255, 0, 0)
352 #else
353 #define BACKG_COLOR LCD_WHITE
354 #define GRAPH_COLOR LCD_BLACK
355 #define CURSOR_COLOR LCD_DARKGRAY
356 #endif
357 #endif
359 enum { DRAW_FILLED, DRAW_LINE, DRAW_PIXEL, MAX_DRAW };
360 enum { ADV_SCROLL, ADV_WRAP, MAX_ADV };
361 enum { OSC_HORIZ, OSC_VERT, MAX_OSC };
363 #define CFGFILE_VERSION 0 /* Current config file version */
364 #define CFGFILE_MINVERSION 0 /* Minimum config file version to accept */
367 #define MAX_PEAK 0x8000
369 #if defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
370 #define mas_codec_readreg(x) rand()%MAX_PEAK
371 #endif
373 /* global variables */
375 /* settings */
376 struct osc_config {
377 int delay; /* in ticks */
378 int draw;
379 int advance;
380 int orientation;
383 struct osc_config osc_disk = { 2, DRAW_FILLED, ADV_SCROLL, OSC_HORIZ };
384 struct osc_config osc; /* running config */
386 static const char cfg_filename[] = "oscilloscope.cfg";
387 static char *draw_str[3] = { "filled", "line", "pixel" };
388 static char *advance_str[2] = { "scroll", "wrap" };
389 static char *orientation_str[2] = { "horizontal", "vertical" };
391 struct configdata disk_config[] = {
392 { TYPE_INT, 1, 99, { .int_p = &osc_disk.delay }, "delay", NULL },
393 { TYPE_ENUM, 0, MAX_DRAW, { .int_p = &osc_disk.draw }, "draw", draw_str },
394 { TYPE_ENUM, 0, MAX_ADV, { .int_p = &osc_disk.advance }, "advance",
395 advance_str },
396 { TYPE_ENUM, 0, MAX_OSC, { .int_p = &osc_disk.orientation }, "orientation",
397 orientation_str }
401 long last_tick = 0; /* time of last drawing */
402 int last_pos = 0; /* last x or y drawing position. Reset for aspect switch. */
403 int last_left; /* last channel values */
404 int last_right;
406 unsigned char message[16]; /* message to display */
407 bool displaymsg = false;
408 int font_height = 8;
410 /* implementation */
412 void anim_horizontal(int cur_left, int cur_right)
414 int cur_x, x;
415 int left, right, dl, dr;
416 long cur_tick = *rb->current_tick;
417 long d = (cur_tick - last_tick) / osc.delay;
418 bool full_update = false;
420 if (d == 0) /* too early, bail out */
421 return;
423 last_tick = cur_tick;
425 if (d > HZ) /* first call or too much delay, (re)start */
427 last_left = cur_left;
428 last_right = cur_right;
429 return;
431 cur_x = last_pos + d;
433 if (cur_x >= LCD_WIDTH)
435 if (osc.advance == ADV_SCROLL)
437 int shift = cur_x - (LCD_WIDTH-1);
438 xlcd_scroll_left(shift);
439 full_update = true;
440 cur_x -= shift;
441 last_pos -= shift;
443 else
445 cur_x -= LCD_WIDTH;
448 rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
450 if (cur_x > last_pos)
452 rb->lcd_fillrect(last_pos + 1, 0, d, LCD_HEIGHT);
454 else
456 rb->lcd_fillrect(last_pos + 1, 0, LCD_WIDTH - last_pos, LCD_HEIGHT);
457 rb->lcd_fillrect(0, 0, cur_x + 1, LCD_HEIGHT);
459 rb->lcd_set_drawmode(DRMODE_SOLID);
461 switch (osc.draw)
463 case DRAW_FILLED:
464 left = last_left;
465 right = last_right;
466 dl = (cur_left - left) / d;
467 dr = (cur_right - right) / d;
469 for (x = last_pos + 1; d > 0; x++, d--)
471 if (x == LCD_WIDTH)
472 x = 0;
474 left += dl;
475 right += dr;
477 rb->lcd_vline(x, LCD_HEIGHT/2-1,
478 LCD_HEIGHT/2-1 - (((LCD_HEIGHT-2) * left) >> 16));
479 rb->lcd_vline(x, LCD_HEIGHT/2+1,
480 LCD_HEIGHT/2+1 + (((LCD_HEIGHT-2) * right) >> 16));
482 break;
484 case DRAW_LINE:
485 if (cur_x > last_pos)
487 rb->lcd_drawline(
488 last_pos, LCD_HEIGHT/2-1 - (((LCD_HEIGHT-2) * last_left) >> 16),
489 cur_x, LCD_HEIGHT/2-1 - (((LCD_HEIGHT-2) * cur_left) >> 16)
491 rb->lcd_drawline(
492 last_pos, LCD_HEIGHT/2+1 + (((LCD_HEIGHT-2) * last_right) >> 16),
493 cur_x, LCD_HEIGHT/2+1 + (((LCD_HEIGHT-2) * cur_right) >> 16)
496 else
498 left = last_left
499 + (LCD_WIDTH - last_pos) * (last_left - cur_left) / d;
500 right = last_right
501 + (LCD_WIDTH - last_pos) * (last_right - cur_right) / d;
503 rb->lcd_drawline(
504 last_pos, LCD_HEIGHT/2-1 - (((LCD_HEIGHT-2) * last_left) >> 16),
505 LCD_WIDTH, LCD_HEIGHT/2-1 - (((LCD_HEIGHT-2) * left) >> 16)
507 rb->lcd_drawline(
508 last_pos, LCD_HEIGHT/2+1 + (((LCD_HEIGHT-2) * last_right) >> 16),
509 LCD_WIDTH, LCD_HEIGHT/2+1 + (((LCD_HEIGHT-2) * right) >> 16)
511 if (cur_x > 0)
513 rb->lcd_drawline(
514 0, LCD_HEIGHT/2-1 - (((LCD_HEIGHT-2) * left) >> 16),
515 cur_x, LCD_HEIGHT/2-1 - (((LCD_HEIGHT-2) * cur_left) >> 16)
517 rb->lcd_drawline(
518 0, LCD_HEIGHT/2+1 + (((LCD_HEIGHT-2) * right) >> 16),
519 cur_x, LCD_HEIGHT/2+1 + (((LCD_HEIGHT-2) * cur_right) >> 16)
523 break;
525 case DRAW_PIXEL:
526 left = last_left;
527 right = last_right;
528 dl = (cur_left - left) / d;
529 dr = (cur_right - right) / d;
531 for (x = last_pos + 1; d > 0; x++, d--)
533 if (x == LCD_WIDTH)
534 x = 0;
536 left += dl;
537 right += dr;
539 rb->lcd_drawpixel(x, LCD_HEIGHT/2-1 - (((LCD_HEIGHT-2) * left) >> 16));
540 rb->lcd_drawpixel(x, LCD_HEIGHT/2+1 + (((LCD_HEIGHT-2) * right) >> 16));
542 break;
545 last_left = cur_left;
546 last_right = cur_right;
548 if (displaymsg)
550 int width;
552 rb->lcd_getstringsize(message, &width, NULL);
553 last_pos -= width - 1;
554 rb->lcd_putsxy(last_pos, 0, message);
555 displaymsg = false;
557 if (last_pos < 0)
558 last_pos = 0;
561 if (full_update)
563 rb->lcd_update();
565 else
567 #if LCD_DEPTH > 1 /* cursor bar */
568 rb->lcd_set_foreground(CURSOR_COLOR);
569 rb->lcd_vline(cur_x + 1, 0, LCD_HEIGHT-1);
570 rb->lcd_set_foreground(GRAPH_COLOR);
571 #else
572 rb->lcd_set_drawmode(DRMODE_COMPLEMENT);
573 rb->lcd_vline(cur_x + 1, 0, LCD_HEIGHT-1);
574 rb->lcd_set_drawmode(DRMODE_SOLID);
575 #endif
577 if (cur_x > last_pos)
579 rb->lcd_update_rect(last_pos, 0, cur_x - last_pos + 2, LCD_HEIGHT);
581 else
583 rb->lcd_update_rect(last_pos, 0, LCD_WIDTH - last_pos, LCD_HEIGHT);
584 rb->lcd_update_rect(0, 0, cur_x + 2, LCD_HEIGHT);
587 last_pos = cur_x;
590 void anim_vertical(int cur_left, int cur_right)
592 int cur_y, y;
593 int left, right, dl, dr;
594 long cur_tick = *rb->current_tick;
595 long d = (cur_tick - last_tick) / osc.delay;
596 bool full_update = false;
598 if (d == 0) /* too early, bail out */
599 return;
601 last_tick = cur_tick;
603 if (d > HZ) /* first call or too much delay, (re)start */
605 last_left = cur_left;
606 last_right = cur_right;
607 return;
609 cur_y = last_pos + d;
611 if (cur_y >= LCD_HEIGHT)
613 if (osc.advance == ADV_SCROLL)
615 int shift = cur_y - (LCD_HEIGHT-1);
616 xlcd_scroll_up(shift);
617 full_update = true;
618 cur_y -= shift;
619 last_pos -= shift;
621 else
623 cur_y -= LCD_HEIGHT;
626 rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
628 if (cur_y > last_pos)
630 rb->lcd_fillrect(0, last_pos + 1, LCD_WIDTH, d);
632 else
634 rb->lcd_fillrect(0, last_pos + 1, LCD_WIDTH, LCD_HEIGHT - last_pos);
635 rb->lcd_fillrect(0, 0, LCD_WIDTH, cur_y + 1);
637 rb->lcd_set_drawmode(DRMODE_SOLID);
639 switch (osc.draw)
641 case DRAW_FILLED:
642 left = last_left;
643 right = last_right;
644 dl = (cur_left - left) / d;
645 dr = (cur_right - right) / d;
647 for (y = last_pos + 1; d > 0; y++, d--)
649 if (y == LCD_HEIGHT)
650 y = 0;
652 left += dl;
653 right += dr;
655 rb->lcd_hline(LCD_WIDTH/2-1,
656 LCD_WIDTH/2-1 - (((LCD_WIDTH-2) * left) >> 16), y);
657 rb->lcd_hline(LCD_WIDTH/2+1,
658 LCD_WIDTH/2+1 + (((LCD_WIDTH-2) * right) >> 16), y);
660 break;
662 case DRAW_LINE:
663 if (cur_y > last_pos)
665 rb->lcd_drawline(
666 LCD_WIDTH/2-1 - (((LCD_WIDTH-2) * last_left) >> 16), last_pos,
667 LCD_WIDTH/2-1 - (((LCD_WIDTH-2) * cur_left) >> 16), cur_y
669 rb->lcd_drawline(
670 LCD_WIDTH/2+1 + (((LCD_WIDTH-2) * last_right) >> 16), last_pos,
671 LCD_WIDTH/2+1 + (((LCD_WIDTH-2) * cur_right) >> 16), cur_y
674 else
676 left = last_left
677 + (LCD_HEIGHT - last_pos) * (last_left - cur_left) / d;
678 right = last_right
679 + (LCD_HEIGHT - last_pos) * (last_right - cur_right) / d;
681 rb->lcd_drawline(
682 LCD_WIDTH/2-1 - (((LCD_WIDTH-2) * last_left) >> 16), last_pos,
683 LCD_WIDTH/2-1 - (((LCD_WIDTH-2) * left) >> 16), LCD_HEIGHT
685 rb->lcd_drawline(
686 LCD_WIDTH/2+1 + (((LCD_WIDTH-2) * last_right) >> 16), last_pos,
687 LCD_WIDTH/2+1 + (((LCD_WIDTH-2) * right) >> 16), LCD_HEIGHT
689 if (cur_y > 0)
691 rb->lcd_drawline(
692 LCD_WIDTH/2-1 - (((LCD_WIDTH-2) * left) >> 16), 0,
693 LCD_WIDTH/2-1 - (((LCD_WIDTH-2) * cur_left) >> 16), cur_y
695 rb->lcd_drawline(
696 LCD_WIDTH/2+1 + (((LCD_WIDTH-2) * right) >> 16), 0,
697 LCD_WIDTH/2+1 + (((LCD_WIDTH-2) * cur_right) >> 16), cur_y
701 break;
703 case DRAW_PIXEL:
704 left = last_left;
705 right = last_right;
706 dl = (cur_left - left) / d;
707 dr = (cur_right - right) / d;
709 for (y = last_pos + 1; d > 0; y++, d--)
711 if (y == LCD_HEIGHT)
712 y = 0;
714 left += dl;
715 right += dr;
717 rb->lcd_drawpixel(LCD_WIDTH/2-1 - (((LCD_WIDTH-2) * left) >> 16), y);
718 rb->lcd_drawpixel(LCD_WIDTH/2+1 + (((LCD_WIDTH-2) * right) >> 16), y);
720 break;
723 last_left = cur_left;
724 last_right = cur_right;
726 if (displaymsg)
728 last_pos -= font_height - 1;
729 rb->lcd_putsxy(0, last_pos, message);
730 displaymsg = false;
732 if (last_pos < 0)
733 last_pos = 0;
736 if (full_update)
738 rb->lcd_update();
740 else
742 #if LCD_DEPTH > 1 /* cursor bar */
743 rb->lcd_set_foreground(CURSOR_COLOR);
744 rb->lcd_hline(0, LCD_WIDTH-1, cur_y + 1);
745 rb->lcd_set_foreground(GRAPH_COLOR);
746 #else
747 rb->lcd_set_drawmode(DRMODE_COMPLEMENT);
748 rb->lcd_hline(0, LCD_WIDTH-1, cur_y + 1);
749 rb->lcd_set_drawmode(DRMODE_SOLID);
750 #endif
752 if (cur_y > last_pos)
754 rb->lcd_update_rect(0, last_pos, LCD_WIDTH, cur_y - last_pos + 2);
756 else
758 rb->lcd_update_rect(0, last_pos, LCD_WIDTH, LCD_HEIGHT - last_pos);
759 rb->lcd_update_rect(0, 0, LCD_WIDTH, cur_y + 2);
762 last_pos = cur_y;
765 void cleanup(void)
767 #if LCD_DEPTH > 1
768 rb->lcd_set_foreground(LCD_DEFAULT_FG);
769 rb->lcd_set_background(LCD_DEFAULT_BG);
770 #endif
771 /* Turn on backlight timeout (revert to settings) */
772 backlight_use_settings(); /* backlight control in lib/helper.c */
775 enum plugin_status plugin_start(const void* parameter)
777 int button, vol;
778 int lastbutton = BUTTON_NONE;
779 bool exit = false;
780 bool paused = false;
781 bool tell_speed;
783 (void)parameter;
785 atexit(cleanup);
786 configfile_load(cfg_filename, disk_config,
787 sizeof(disk_config) / sizeof(disk_config[0]),
788 CFGFILE_MINVERSION);
789 rb->memcpy(&osc, &osc_disk, sizeof(osc)); /* copy to running config */
791 #if LCD_DEPTH > 1
792 rb->lcd_set_foreground(GRAPH_COLOR);
793 rb->lcd_set_background(BACKG_COLOR);
794 rb->lcd_set_backdrop(NULL);
795 rb->lcd_clear_display();
796 rb->lcd_update();
797 #endif
799 /* Turn off backlight timeout */
800 backlight_force_on(); /* backlight control in lib/helper.c */
802 rb->lcd_getstringsize("A", NULL, &font_height);
804 while (!exit)
806 if (!paused)
808 int left, right;
810 rb->sleep(MAX(last_tick + osc.delay - *rb->current_tick - 1, 0));
812 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
813 left = rb->mas_codec_readreg(0xC);
814 right = rb->mas_codec_readreg(0xD);
815 #elif (CONFIG_CODEC == SWCODEC)
816 rb->pcm_calculate_peaks(&left, &right);
817 #endif
818 if (osc.orientation == OSC_HORIZ)
819 anim_horizontal(left, right);
820 else
821 anim_vertical(left, right);
824 tell_speed = false;
825 button = rb->button_get(paused);
826 switch (button)
828 #ifdef OSCILLOSCOPE_RC_QUIT
829 case OSCILLOSCOPE_RC_QUIT:
830 #endif
831 case OSCILLOSCOPE_QUIT:
832 exit = true;
833 break;
835 case OSCILLOSCOPE_ADVMODE:
836 if (++osc.advance >= MAX_ADV)
837 osc.advance = 0;
838 break;
840 case OSCILLOSCOPE_DRAWMODE:
841 #ifdef OSCILLOSCOPE_DRAWMODE_PRE
842 if (lastbutton != OSCILLOSCOPE_DRAWMODE_PRE)
843 break;
844 #endif
845 if (++osc.draw >= MAX_DRAW)
846 osc.draw = 0;
847 break;
849 case OSCILLOSCOPE_ORIENTATION:
850 #ifdef OSCILLOSCOPE_ORIENTATION_PRE
851 if (lastbutton != OSCILLOSCOPE_ORIENTATION_PRE)
852 break;
853 #endif
854 if (++osc.orientation >= MAX_OSC)
855 osc.orientation = 0;
856 last_pos = 0;
857 last_tick = 0;
858 displaymsg = false;
859 rb->lcd_clear_display();
860 rb->lcd_update();
861 break;
863 case OSCILLOSCOPE_PAUSE:
864 paused = !paused;
865 last_tick = 0;
866 break;
868 case OSCILLOSCOPE_SPEED_UP:
869 case OSCILLOSCOPE_SPEED_UP | BUTTON_REPEAT:
870 if (osc.delay > 1)
872 osc.delay--;
873 tell_speed = true;
875 break;
877 case OSCILLOSCOPE_SPEED_DOWN:
878 case OSCILLOSCOPE_SPEED_DOWN | BUTTON_REPEAT:
879 osc.delay++;
880 tell_speed = true;
881 break;
883 case OSCILLOSCOPE_VOL_UP:
884 case OSCILLOSCOPE_VOL_UP | BUTTON_REPEAT:
885 vol = rb->global_settings->volume;
886 if (vol < rb->sound_max(SOUND_VOLUME))
888 vol++;
889 rb->sound_set(SOUND_VOLUME, vol);
890 rb->global_settings->volume = vol;
892 break;
894 case OSCILLOSCOPE_VOL_DOWN:
895 case OSCILLOSCOPE_VOL_DOWN | BUTTON_REPEAT:
896 vol = rb->global_settings->volume;
897 if (vol > rb->sound_min(SOUND_VOLUME))
899 vol--;
900 rb->sound_set(SOUND_VOLUME, vol);
901 rb->global_settings->volume = vol;
903 break;
905 default:
906 exit_on_usb(button);
907 break;
909 if (button != BUTTON_NONE)
910 lastbutton = button;
912 if (tell_speed)
914 rb->snprintf(message, sizeof(message), "%s%d",
915 (osc.orientation == OSC_VERT) ? "Speed: " : "",
916 100 / osc.delay);
917 displaymsg = true;
920 if (rb->memcmp(&osc, &osc_disk, sizeof(osc))) /* save settings if changed */
922 rb->memcpy(&osc_disk, &osc, sizeof(osc));
923 configfile_save(cfg_filename, disk_config,
924 sizeof(disk_config) / sizeof(disk_config[0]),
925 CFGFILE_VERSION);
927 return PLUGIN_OK;