1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
25 #include "lib/helper.h"
27 #ifdef HAVE_LCD_BITMAP
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_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
291 #error No keymap defined!
294 #ifdef HAVE_TOUCHSCREEN
295 #ifndef OSCILLOSCOPE_QUIT
296 #define OSCILLOSCOPE_QUIT BUTTON_TOPLEFT
298 #ifndef OSCILLOSCOPE_DRAWMODE
299 #define OSCILLOSCOPE_DRAWMODE BUTTON_TOPMIDDLE
301 #ifndef OSCILLOSCOPE_ADVMODE
302 #define OSCILLOSCOPE_ADVMODE BUTTON_BOTTOMMIDDLE
304 #ifndef OSCILLOSCOPE_ORIENTATION
305 #define OSCILLOSCOPE_ORIENTATION BUTTON_BOTTOMLEFT
307 #ifndef OSCILLOSCOPE_PAUSE
308 #define OSCILLOSCOPE_PAUSE BUTTON_CENTER
310 #ifndef OSCILLOSCOPE_SPEED_UP
311 #define OSCILLOSCOPE_SPEED_UP BUTTON_MIDRIGHT
313 #ifndef OSCILLOSCOPE_SPEED_DOWN
314 #define OSCILLOSCOPE_SPEED_DOWN BUTTON_MIDLEFT
316 #ifndef OSCILLOSCOPE_VOL_UP
317 #define OSCILLOSCOPE_VOL_UP BUTTON_TOPRIGHT
319 #ifndef OSCILLOSCOPE_VOL_DOWN
320 #define OSCILLOSCOPE_VOL_DOWN BUTTON_BOTTOMRIGHT
326 #ifdef HAVE_LCD_COLOR
327 #define BACKG_COLOR LCD_BLACK
328 #define GRAPH_COLOR LCD_RGBPACK(128, 255, 0)
329 #define CURSOR_COLOR LCD_RGBPACK(255, 0, 0)
331 #define BACKG_COLOR LCD_WHITE
332 #define GRAPH_COLOR LCD_BLACK
333 #define CURSOR_COLOR LCD_DARKGRAY
337 enum { DRAW_FILLED
, DRAW_LINE
, DRAW_PIXEL
, MAX_DRAW
};
338 enum { ADV_SCROLL
, ADV_WRAP
, MAX_ADV
};
339 enum { OSC_HORIZ
, OSC_VERT
, MAX_OSC
};
341 #define CFGFILE_VERSION 0 /* Current config file version */
342 #define CFGFILE_MINVERSION 0 /* Minimum config file version to accept */
345 #define MAX_PEAK 0x8000
347 #if defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
348 #define mas_codec_readreg(x) rand()%MAX_PEAK
351 /* global variables */
355 int delay
; /* in ticks */
361 struct osc_config osc_disk
= { 2, DRAW_FILLED
, ADV_SCROLL
, OSC_HORIZ
};
362 struct osc_config osc
; /* running config */
364 static const char cfg_filename
[] = "oscilloscope.cfg";
365 static char *draw_str
[3] = { "filled", "line", "pixel" };
366 static char *advance_str
[2] = { "scroll", "wrap" };
367 static char *orientation_str
[2] = { "horizontal", "vertical" };
369 struct configdata disk_config
[] = {
370 { TYPE_INT
, 1, 99, { .int_p
= &osc_disk
.delay
}, "delay", NULL
},
371 { TYPE_ENUM
, 0, MAX_DRAW
, { .int_p
= &osc_disk
.draw
}, "draw", draw_str
},
372 { TYPE_ENUM
, 0, MAX_ADV
, { .int_p
= &osc_disk
.advance
}, "advance",
374 { TYPE_ENUM
, 0, MAX_OSC
, { .int_p
= &osc_disk
.orientation
}, "orientation",
379 long last_tick
= 0; /* time of last drawing */
380 int last_pos
= 0; /* last x or y drawing position. Reset for aspect switch. */
381 int last_left
; /* last channel values */
384 unsigned char message
[16]; /* message to display */
385 bool displaymsg
= false;
390 void anim_horizontal(int cur_left
, int cur_right
)
393 int left
, right
, dl
, dr
;
394 long cur_tick
= *rb
->current_tick
;
395 long d
= (cur_tick
- last_tick
) / osc
.delay
;
396 bool full_update
= false;
398 if (d
== 0) /* too early, bail out */
401 last_tick
= cur_tick
;
403 if (d
> HZ
) /* first call or too much delay, (re)start */
405 last_left
= cur_left
;
406 last_right
= cur_right
;
409 cur_x
= last_pos
+ d
;
411 if (cur_x
>= LCD_WIDTH
)
413 if (osc
.advance
== ADV_SCROLL
)
415 int shift
= cur_x
- (LCD_WIDTH
-1);
416 xlcd_scroll_left(shift
);
426 rb
->lcd_set_drawmode(DRMODE_SOLID
|DRMODE_INVERSEVID
);
428 if (cur_x
> last_pos
)
430 rb
->lcd_fillrect(last_pos
+ 1, 0, d
, LCD_HEIGHT
);
434 rb
->lcd_fillrect(last_pos
+ 1, 0, LCD_WIDTH
- last_pos
, LCD_HEIGHT
);
435 rb
->lcd_fillrect(0, 0, cur_x
+ 1, LCD_HEIGHT
);
437 rb
->lcd_set_drawmode(DRMODE_SOLID
);
444 dl
= (cur_left
- left
) / d
;
445 dr
= (cur_right
- right
) / d
;
447 for (x
= last_pos
+ 1; d
> 0; x
++, d
--)
455 rb
->lcd_vline(x
, LCD_HEIGHT
/2-1,
456 LCD_HEIGHT
/2-1 - (((LCD_HEIGHT
-2) * left
) >> 16));
457 rb
->lcd_vline(x
, LCD_HEIGHT
/2+1,
458 LCD_HEIGHT
/2+1 + (((LCD_HEIGHT
-2) * right
) >> 16));
463 if (cur_x
> last_pos
)
466 last_pos
, LCD_HEIGHT
/2-1 - (((LCD_HEIGHT
-2) * last_left
) >> 16),
467 cur_x
, LCD_HEIGHT
/2-1 - (((LCD_HEIGHT
-2) * cur_left
) >> 16)
470 last_pos
, LCD_HEIGHT
/2+1 + (((LCD_HEIGHT
-2) * last_right
) >> 16),
471 cur_x
, LCD_HEIGHT
/2+1 + (((LCD_HEIGHT
-2) * cur_right
) >> 16)
477 + (LCD_WIDTH
- last_pos
) * (last_left
- cur_left
) / d
;
479 + (LCD_WIDTH
- last_pos
) * (last_right
- cur_right
) / d
;
482 last_pos
, LCD_HEIGHT
/2-1 - (((LCD_HEIGHT
-2) * last_left
) >> 16),
483 LCD_WIDTH
, LCD_HEIGHT
/2-1 - (((LCD_HEIGHT
-2) * left
) >> 16)
486 last_pos
, LCD_HEIGHT
/2+1 + (((LCD_HEIGHT
-2) * last_right
) >> 16),
487 LCD_WIDTH
, LCD_HEIGHT
/2+1 + (((LCD_HEIGHT
-2) * right
) >> 16)
492 0, LCD_HEIGHT
/2-1 - (((LCD_HEIGHT
-2) * left
) >> 16),
493 cur_x
, LCD_HEIGHT
/2-1 - (((LCD_HEIGHT
-2) * cur_left
) >> 16)
496 0, LCD_HEIGHT
/2+1 + (((LCD_HEIGHT
-2) * right
) >> 16),
497 cur_x
, LCD_HEIGHT
/2+1 + (((LCD_HEIGHT
-2) * cur_right
) >> 16)
506 dl
= (cur_left
- left
) / d
;
507 dr
= (cur_right
- right
) / d
;
509 for (x
= last_pos
+ 1; d
> 0; x
++, d
--)
517 rb
->lcd_drawpixel(x
, LCD_HEIGHT
/2-1 - (((LCD_HEIGHT
-2) * left
) >> 16));
518 rb
->lcd_drawpixel(x
, LCD_HEIGHT
/2+1 + (((LCD_HEIGHT
-2) * right
) >> 16));
523 last_left
= cur_left
;
524 last_right
= cur_right
;
530 rb
->lcd_getstringsize(message
, &width
, NULL
);
531 last_pos
-= width
- 1;
532 rb
->lcd_putsxy(last_pos
, 0, message
);
545 #if LCD_DEPTH > 1 /* cursor bar */
546 rb
->lcd_set_foreground(CURSOR_COLOR
);
547 rb
->lcd_vline(cur_x
+ 1, 0, LCD_HEIGHT
-1);
548 rb
->lcd_set_foreground(GRAPH_COLOR
);
550 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
551 rb
->lcd_vline(cur_x
+ 1, 0, LCD_HEIGHT
-1);
552 rb
->lcd_set_drawmode(DRMODE_SOLID
);
555 if (cur_x
> last_pos
)
557 rb
->lcd_update_rect(last_pos
, 0, cur_x
- last_pos
+ 2, LCD_HEIGHT
);
561 rb
->lcd_update_rect(last_pos
, 0, LCD_WIDTH
- last_pos
, LCD_HEIGHT
);
562 rb
->lcd_update_rect(0, 0, cur_x
+ 2, LCD_HEIGHT
);
568 void anim_vertical(int cur_left
, int cur_right
)
571 int left
, right
, dl
, dr
;
572 long cur_tick
= *rb
->current_tick
;
573 long d
= (cur_tick
- last_tick
) / osc
.delay
;
574 bool full_update
= false;
576 if (d
== 0) /* too early, bail out */
579 last_tick
= cur_tick
;
581 if (d
> HZ
) /* first call or too much delay, (re)start */
583 last_left
= cur_left
;
584 last_right
= cur_right
;
587 cur_y
= last_pos
+ d
;
589 if (cur_y
>= LCD_HEIGHT
)
591 if (osc
.advance
== ADV_SCROLL
)
593 int shift
= cur_y
- (LCD_HEIGHT
-1);
594 xlcd_scroll_up(shift
);
604 rb
->lcd_set_drawmode(DRMODE_SOLID
|DRMODE_INVERSEVID
);
606 if (cur_y
> last_pos
)
608 rb
->lcd_fillrect(0, last_pos
+ 1, LCD_WIDTH
, d
);
612 rb
->lcd_fillrect(0, last_pos
+ 1, LCD_WIDTH
, LCD_HEIGHT
- last_pos
);
613 rb
->lcd_fillrect(0, 0, LCD_WIDTH
, cur_y
+ 1);
615 rb
->lcd_set_drawmode(DRMODE_SOLID
);
622 dl
= (cur_left
- left
) / d
;
623 dr
= (cur_right
- right
) / d
;
625 for (y
= last_pos
+ 1; d
> 0; y
++, d
--)
633 rb
->lcd_hline(LCD_WIDTH
/2-1,
634 LCD_WIDTH
/2-1 - (((LCD_WIDTH
-2) * left
) >> 16), y
);
635 rb
->lcd_hline(LCD_WIDTH
/2+1,
636 LCD_WIDTH
/2+1 + (((LCD_WIDTH
-2) * right
) >> 16), y
);
641 if (cur_y
> last_pos
)
644 LCD_WIDTH
/2-1 - (((LCD_WIDTH
-2) * last_left
) >> 16), last_pos
,
645 LCD_WIDTH
/2-1 - (((LCD_WIDTH
-2) * cur_left
) >> 16), cur_y
648 LCD_WIDTH
/2+1 + (((LCD_WIDTH
-2) * last_right
) >> 16), last_pos
,
649 LCD_WIDTH
/2+1 + (((LCD_WIDTH
-2) * cur_right
) >> 16), cur_y
655 + (LCD_HEIGHT
- last_pos
) * (last_left
- cur_left
) / d
;
657 + (LCD_HEIGHT
- last_pos
) * (last_right
- cur_right
) / d
;
660 LCD_WIDTH
/2-1 - (((LCD_WIDTH
-2) * last_left
) >> 16), last_pos
,
661 LCD_WIDTH
/2-1 - (((LCD_WIDTH
-2) * left
) >> 16), LCD_HEIGHT
664 LCD_WIDTH
/2+1 + (((LCD_WIDTH
-2) * last_right
) >> 16), last_pos
,
665 LCD_WIDTH
/2+1 + (((LCD_WIDTH
-2) * right
) >> 16), LCD_HEIGHT
670 LCD_WIDTH
/2-1 - (((LCD_WIDTH
-2) * left
) >> 16), 0,
671 LCD_WIDTH
/2-1 - (((LCD_WIDTH
-2) * cur_left
) >> 16), cur_y
674 LCD_WIDTH
/2+1 + (((LCD_WIDTH
-2) * right
) >> 16), 0,
675 LCD_WIDTH
/2+1 + (((LCD_WIDTH
-2) * cur_right
) >> 16), cur_y
684 dl
= (cur_left
- left
) / d
;
685 dr
= (cur_right
- right
) / d
;
687 for (y
= last_pos
+ 1; d
> 0; y
++, d
--)
695 rb
->lcd_drawpixel(LCD_WIDTH
/2-1 - (((LCD_WIDTH
-2) * left
) >> 16), y
);
696 rb
->lcd_drawpixel(LCD_WIDTH
/2+1 + (((LCD_WIDTH
-2) * right
) >> 16), y
);
701 last_left
= cur_left
;
702 last_right
= cur_right
;
706 last_pos
-= font_height
- 1;
707 rb
->lcd_putsxy(0, last_pos
, message
);
720 #if LCD_DEPTH > 1 /* cursor bar */
721 rb
->lcd_set_foreground(CURSOR_COLOR
);
722 rb
->lcd_hline(0, LCD_WIDTH
-1, cur_y
+ 1);
723 rb
->lcd_set_foreground(GRAPH_COLOR
);
725 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
726 rb
->lcd_hline(0, LCD_WIDTH
-1, cur_y
+ 1);
727 rb
->lcd_set_drawmode(DRMODE_SOLID
);
730 if (cur_y
> last_pos
)
732 rb
->lcd_update_rect(0, last_pos
, LCD_WIDTH
, cur_y
- last_pos
+ 2);
736 rb
->lcd_update_rect(0, last_pos
, LCD_WIDTH
, LCD_HEIGHT
- last_pos
);
737 rb
->lcd_update_rect(0, 0, LCD_WIDTH
, cur_y
+ 2);
743 void cleanup(void *parameter
)
747 rb
->lcd_set_foreground(LCD_DEFAULT_FG
);
748 rb
->lcd_set_background(LCD_DEFAULT_BG
);
750 /* Turn on backlight timeout (revert to settings) */
751 backlight_use_settings(); /* backlight control in lib/helper.c */
754 enum plugin_status
plugin_start(const void* parameter
)
757 int lastbutton
= BUTTON_NONE
;
764 configfile_load(cfg_filename
, disk_config
,
765 sizeof(disk_config
) / sizeof(disk_config
[0]),
767 rb
->memcpy(&osc
, &osc_disk
, sizeof(osc
)); /* copy to running config */
770 rb
->lcd_set_foreground(GRAPH_COLOR
);
771 rb
->lcd_set_background(BACKG_COLOR
);
772 rb
->lcd_set_backdrop(NULL
);
773 rb
->lcd_clear_display();
777 /* Turn off backlight timeout */
778 backlight_force_on(); /* backlight control in lib/helper.c */
780 rb
->lcd_getstringsize("A", NULL
, &font_height
);
788 rb
->sleep(MAX(last_tick
+ osc
.delay
- *rb
->current_tick
- 1, 0));
790 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
791 left
= rb
->mas_codec_readreg(0xC);
792 right
= rb
->mas_codec_readreg(0xD);
793 #elif (CONFIG_CODEC == SWCODEC)
794 rb
->pcm_calculate_peaks(&left
, &right
);
796 if (osc
.orientation
== OSC_HORIZ
)
797 anim_horizontal(left
, right
);
799 anim_vertical(left
, right
);
803 button
= rb
->button_get(paused
);
806 #ifdef OSCILLOSCOPE_RC_QUIT
807 case OSCILLOSCOPE_RC_QUIT
:
809 case OSCILLOSCOPE_QUIT
:
813 case OSCILLOSCOPE_ADVMODE
:
814 if (++osc
.advance
>= MAX_ADV
)
818 case OSCILLOSCOPE_DRAWMODE
:
819 #ifdef OSCILLOSCOPE_DRAWMODE_PRE
820 if (lastbutton
!= OSCILLOSCOPE_DRAWMODE_PRE
)
823 if (++osc
.draw
>= MAX_DRAW
)
827 case OSCILLOSCOPE_ORIENTATION
:
828 #ifdef OSCILLOSCOPE_ORIENTATION_PRE
829 if (lastbutton
!= OSCILLOSCOPE_ORIENTATION_PRE
)
832 if (++osc
.orientation
>= MAX_OSC
)
837 rb
->lcd_clear_display();
841 case OSCILLOSCOPE_PAUSE
:
846 case OSCILLOSCOPE_SPEED_UP
:
847 case OSCILLOSCOPE_SPEED_UP
| BUTTON_REPEAT
:
855 case OSCILLOSCOPE_SPEED_DOWN
:
856 case OSCILLOSCOPE_SPEED_DOWN
| BUTTON_REPEAT
:
861 case OSCILLOSCOPE_VOL_UP
:
862 case OSCILLOSCOPE_VOL_UP
| BUTTON_REPEAT
:
863 vol
= rb
->global_settings
->volume
;
864 if (vol
< rb
->sound_max(SOUND_VOLUME
))
867 rb
->sound_set(SOUND_VOLUME
, vol
);
868 rb
->global_settings
->volume
= vol
;
872 case OSCILLOSCOPE_VOL_DOWN
:
873 case OSCILLOSCOPE_VOL_DOWN
| BUTTON_REPEAT
:
874 vol
= rb
->global_settings
->volume
;
875 if (vol
> rb
->sound_min(SOUND_VOLUME
))
878 rb
->sound_set(SOUND_VOLUME
, vol
);
879 rb
->global_settings
->volume
= vol
;
884 if (rb
->default_event_handler_ex(button
, cleanup
, NULL
)
885 == SYS_USB_CONNECTED
)
886 return PLUGIN_USB_CONNECTED
;
889 if (button
!= BUTTON_NONE
)
894 rb
->snprintf(message
, sizeof(message
), "%s%d",
895 (osc
.orientation
== OSC_VERT
) ? "Speed: " : "",
901 if (rb
->memcmp(&osc
, &osc_disk
, sizeof(osc
))) /* save settings if changed */
903 rb
->memcpy(&osc_disk
, &osc
, sizeof(osc
));
904 configfile_save(cfg_filename
, disk_config
,
905 sizeof(disk_config
) / sizeof(disk_config
[0]),
910 #endif /* HAVE_LCD_BITMAP */