1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
9 * Copyright (C) 2003 Lee Pilgrim
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
17 * KIND, either express or implied.
19 **************************************************************************/
21 #include "fixedpoint.h"
23 #if defined(HAVE_LCD_BITMAP)
27 /* variable button definitions */
28 #if CONFIG_KEYPAD == RECORDER_PAD
29 #define VUMETER_QUIT BUTTON_OFF
30 #define VUMETER_HELP BUTTON_ON
31 #define VUMETER_MENU BUTTON_F1
32 #define VUMETER_MENU_EXIT BUTTON_F1
33 #define VUMETER_MENU_EXIT2 BUTTON_OFF
34 #define VUMETER_UP BUTTON_UP
35 #define VUMETER_DOWN BUTTON_DOWN
36 #define LABEL_HELP "ON"
37 #define LABEL_QUIT "OFF"
38 #define LABEL_MENU "F1"
39 #define LABEL_VOLUME "UP/DOWN"
41 #elif CONFIG_KEYPAD == ARCHOS_AV300_PAD
42 #define VUMETER_QUIT BUTTON_OFF
43 #define VUMETER_HELP BUTTON_ON
44 #define VUMETER_MENU BUTTON_F1
45 #define VUMETER_MENU_EXIT BUTTON_F1
46 #define VUMETER_MENU_EXIT2 BUTTON_OFF
47 #define VUMETER_UP BUTTON_UP
48 #define VUMETER_DOWN BUTTON_DOWN
49 #define LABEL_HELP "ON"
50 #define LABEL_QUIT "OFF"
51 #define LABEL_MENU "F1"
52 #define LABEL_VOLUME "UP/DOWN"
54 #elif CONFIG_KEYPAD == ONDIO_PAD
55 #define VUMETER_QUIT BUTTON_OFF
56 #define VUMETER_HELP_PRE BUTTON_MENU
57 #define VUMETER_HELP (BUTTON_MENU | BUTTON_REL)
58 #define VUMETER_MENU_PRE BUTTON_MENU
59 #define VUMETER_MENU (BUTTON_MENU | BUTTON_REPEAT)
60 #define VUMETER_MENU_EXIT BUTTON_MENU
61 #define VUMETER_MENU_EXIT2 BUTTON_OFF
62 #define VUMETER_UP BUTTON_UP
63 #define VUMETER_DOWN BUTTON_DOWN
64 #define LABEL_HELP "MODE"
65 #define LABEL_QUIT "OFF"
66 #define LABEL_MENU "MODE.."
67 #define LABEL_VOLUME "UP/DOWN"
69 #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
70 (CONFIG_KEYPAD == IRIVER_H300_PAD)
71 #define VUMETER_QUIT BUTTON_OFF
72 #define VUMETER_HELP BUTTON_ON
73 #define VUMETER_MENU BUTTON_SELECT
74 #define VUMETER_MENU2 BUTTON_MODE
75 #define VUMETER_MENU_EXIT BUTTON_SELECT
76 #define VUMETER_MENU_EXIT2 BUTTON_OFF
77 #define VUMETER_UP BUTTON_UP
78 #define VUMETER_DOWN BUTTON_DOWN
79 #define LABEL_HELP "PLAY"
80 #define LABEL_QUIT "STOP"
81 #define LABEL_MENU "SELECT,MODE"
82 #define LABEL_VOLUME "UP/DOWN"
84 #define VUMETER_RC_QUIT BUTTON_RC_STOP
86 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
87 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
88 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
89 #define VUMETER_QUIT BUTTON_MENU
90 #define VUMETER_HELP BUTTON_PLAY
91 #define VUMETER_MENU BUTTON_SELECT
92 #define VUMETER_MENU_EXIT BUTTON_SELECT
93 #define VUMETER_MENU_EXIT2 BUTTON_MENU
94 #define VUMETER_UP BUTTON_SCROLL_FWD
95 #define VUMETER_DOWN BUTTON_SCROLL_BACK
96 #define LABEL_HELP "PLAY"
97 #define LABEL_QUIT "MENU"
98 #define LABEL_MENU "SELECT"
99 #define LABEL_VOLUME "Wheel"
101 #elif (CONFIG_KEYPAD == GIGABEAT_PAD)
102 #define VUMETER_QUIT BUTTON_POWER
103 #define VUMETER_HELP BUTTON_A
104 #define VUMETER_MENU BUTTON_MENU
105 #define VUMETER_MENU_EXIT BUTTON_MENU
106 #define VUMETER_MENU_EXIT2 BUTTON_POWER
107 #define VUMETER_UP BUTTON_UP
108 #define VUMETER_DOWN BUTTON_DOWN
109 #define LABEL_HELP "A"
110 #define LABEL_QUIT "POWER"
111 #define LABEL_MENU "MENU"
112 #define LABEL_VOLUME "UP/DOWN"
114 #elif (CONFIG_KEYPAD == SANSA_E200_PAD)
115 #define VUMETER_QUIT BUTTON_POWER
116 #define VUMETER_HELP BUTTON_REC
117 #define VUMETER_MENU BUTTON_SELECT
118 #define VUMETER_MENU_EXIT BUTTON_SELECT
119 #define VUMETER_MENU_EXIT2 BUTTON_POWER
120 #define VUMETER_UP BUTTON_SCROLL_FWD
121 #define VUMETER_DOWN BUTTON_SCROLL_BACK
122 #define LABEL_HELP "REC"
123 #define LABEL_QUIT "POWER"
124 #define LABEL_MENU "SELECT"
125 #define LABEL_VOLUME "Wheel"
127 #elif (CONFIG_KEYPAD == SANSA_C200_PAD)
128 #define VUMETER_QUIT BUTTON_POWER
129 #define VUMETER_HELP BUTTON_REC
130 #define VUMETER_MENU BUTTON_SELECT
131 #define VUMETER_MENU_EXIT BUTTON_SELECT
132 #define VUMETER_MENU_EXIT2 BUTTON_POWER
133 #define VUMETER_UP BUTTON_VOL_UP
134 #define VUMETER_DOWN BUTTON_VOL_DOWN
135 #define LABEL_HELP "REC"
136 #define LABEL_QUIT "POWER"
137 #define LABEL_MENU "SELECT"
138 #define LABEL_VOLUME "VOL UP/DN"
140 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
141 #define VUMETER_QUIT BUTTON_POWER
142 #define VUMETER_HELP BUTTON_PLAY
143 #define VUMETER_MENU BUTTON_SELECT
144 #define VUMETER_MENU_EXIT BUTTON_SELECT
145 #define VUMETER_MENU_EXIT2 BUTTON_POWER
146 #define VUMETER_UP BUTTON_UP
147 #define VUMETER_DOWN BUTTON_DOWN
148 #define LABEL_HELP "PLAY"
149 #define LABEL_QUIT "POWER"
150 #define LABEL_MENU "SELECT"
151 #define LABEL_VOLUME "UP/DOWN"
153 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
154 #define VUMETER_QUIT BUTTON_POWER
155 #define VUMETER_HELP BUTTON_PLAY
156 #define VUMETER_MENU BUTTON_REW
157 #define VUMETER_MENU_EXIT BUTTON_REW
158 #define VUMETER_MENU_EXIT2 BUTTON_POWER
159 #define VUMETER_UP BUTTON_SCROLL_UP
160 #define VUMETER_DOWN BUTTON_SCROLL_DOWN
161 #define LABEL_HELP "PLAY"
162 #define LABEL_QUIT "POWER"
163 #define LABEL_MENU "REW"
164 #define LABEL_VOLUME "Scroller"
166 #elif (CONFIG_KEYPAD == GIGABEAT_S_PAD)
167 #define VUMETER_QUIT BUTTON_BACK
168 #define VUMETER_HELP BUTTON_NEXT
169 #define VUMETER_MENU BUTTON_MENU
170 #define VUMETER_MENU_EXIT BUTTON_MENU
171 #define VUMETER_MENU_EXIT2 BUTTON_PLAY
172 #define VUMETER_UP BUTTON_UP
173 #define VUMETER_DOWN BUTTON_DOWN
174 #define LABEL_HELP "NEXT"
175 #define LABEL_QUIT "BACK"
176 #define LABEL_MENU "MENU"
177 #define LABEL_VOLUME "UP/DOWN"
179 #elif (CONFIG_KEYPAD == MROBE100_PAD)
180 #define VUMETER_QUIT BUTTON_POWER
181 #define VUMETER_HELP BUTTON_DISPLAY
182 #define VUMETER_MENU BUTTON_MENU
183 #define VUMETER_MENU_EXIT BUTTON_MENU
184 #define VUMETER_MENU_EXIT2 BUTTON_POWER
185 #define VUMETER_UP BUTTON_UP
186 #define VUMETER_DOWN BUTTON_DOWN
187 #define LABEL_HELP "DISPLAY"
188 #define LABEL_QUIT "POWER"
189 #define LABEL_MENU "MENU"
190 #define LABEL_VOLUME "UP/DOWN"
192 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
193 #define VUMETER_QUIT BUTTON_RC_REC
194 #define VUMETER_HELP BUTTON_RC_MODE
195 #define VUMETER_MENU BUTTON_RC_MENU
196 #define VUMETER_MENU_EXIT BUTTON_RC_MENU
197 #define VUMETER_MENU_EXIT2 BUTTON_RC_REC
198 #define VUMETER_UP BUTTON_RC_VOL_UP
199 #define VUMETER_DOWN BUTTON_RC_VOL_DOWN
200 #define LABEL_HELP "MODE"
201 #define LABEL_QUIT "REC"
202 #define LABEL_MENU "MENU"
203 #define LABEL_VOLUME "VOL UP/DN"
205 #elif CONFIG_KEYPAD == COWOND2_PAD
206 #define VUMETER_QUIT BUTTON_POWER
207 #define VUMETER_MENU BUTTON_MENU
208 #define VUMETER_MENU_EXIT BUTTON_POWER
209 #define LABEL_QUIT "POWER"
210 #define LABEL_MENU "MENU"
213 #error No keymap defined!
218 #define VUMETER_QUIT BUTTON_TOPLEFT
219 #define LABEL_QUIT "TOPLEFT"
222 #define VUMETER_HELP BUTTON_CENTER
223 #define LABEL_HELP "CENTRE"
226 #define VUMETER_MENU BUTTON_TOPRIGHT
227 #define LABEL_MENU "TOPRIGHT"
229 #ifndef VUMETER_MENU_EXIT
230 #define VUMETER_MENU_EXIT BUTTON_TOPLEFT
233 #define VUMETER_UP BUTTON_TOPMIDDLE
236 #define VUMETER_DOWN BUTTON_BOTTOMMIDDLE
239 #define LABEL_VOLUME "UP/DOWN"
243 const struct plugin_api
* rb
;
245 #if defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
246 #define mas_codec_readreg(x) rand()%MAX_PEAK
249 /* Defines x positions on a logarithmic (dBfs) scale. */
250 unsigned char analog_db_scale
[LCD_WIDTH
/2];
252 /* Define's y positions, to make the needle arch, like a real needle would. */
253 unsigned char y_values
[LCD_WIDTH
/2];
255 const unsigned char digital_db_scale
[] =
256 {0,2,3,5,5,6,6,6,7,7,7,7,8,8,8,8,8,9,9,9,9,9,9,9,9,10,10,
257 10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11};
259 const unsigned char needle_cover
[] =
260 {0x18, 0x1c, 0x1c, 0x1e, 0x1e, 0x1f, 0x1f, 0x1f, 0x1e, 0x1e, 0x1c, 0x1c, 0x18};
262 const unsigned char sound_speaker
[] = {0x18,0x24,0x42,0xFF};
263 const unsigned char sound_low_level
[] = {0x24,0x18};
264 const unsigned char sound_med_level
[] = {0x42,0x3C};
265 const unsigned char sound_high_level
[] = {0x81,0x7E};
266 const unsigned char sound_max_level
[] = {0x0E,0xDF,0x0E};
268 const int half_width
= LCD_WIDTH
/ 2;
269 const int quarter_width
= LCD_WIDTH
/ 4;
270 const int half_height
= LCD_HEIGHT
/ 2;
272 /* approx ratio of the previous hard coded values */
273 const int analog_mini_1
= (LCD_WIDTH
/ 2)*0.1;
274 const int analog_mini_2
= (LCD_WIDTH
/ 2)*0.25;
275 const int analog_mini_3
= (LCD_WIDTH
/ 2)*0.4;
276 const int analog_mini_4
= (LCD_WIDTH
/ 2)*0.75;
278 const int digital_block_width
= LCD_WIDTH
/ 11;
279 const int digital_block_gap
= (int)(LCD_WIDTH
/ 11) / 10;
280 /* ammount to lead in on left so 11x blocks are centered - is often 0 */
281 const int digital_lead
= (LCD_WIDTH
- (((int)(LCD_WIDTH
/ 11))*11) ) / 2;
283 const int digital_block_height
= (LCD_HEIGHT
- 54) / 2 ;
285 #define ANALOG 0 /* The two meter types */
288 int left_needle_top_y
;
289 int left_needle_top_x
;
290 int last_left_needle_top_x
;
291 int right_needle_top_y
;
292 int right_needle_top_x
;
293 int last_right_needle_top_x
= LCD_WIDTH
/ 2;
297 int last_num_left_leds
;
298 int last_num_right_leds
;
302 #define MAX_PEAK 0x8000
304 /* gap at the top for left/right etc */
305 #define NEEDLE_TOP 25
307 /* pow(M_E, 5) * 65536 */
308 #define E_POW_5 9726404
310 struct saved_settings
{
312 bool analog_use_db_scale
;
313 bool digital_use_db_scale
;
314 bool analog_minimeters
;
315 bool digital_minimeters
;
320 void reset_settings(void) {
321 vumeter_settings
.meter_type
=ANALOG
;
322 vumeter_settings
.analog_use_db_scale
=true;
323 vumeter_settings
.digital_use_db_scale
=true;
324 vumeter_settings
.analog_minimeters
=true;
325 vumeter_settings
.digital_minimeters
=false;
326 vumeter_settings
.analog_decay
=3;
327 vumeter_settings
.digital_decay
=0;
330 void calc_scales(void)
332 unsigned int fx_log_factor
= E_POW_5
/half_width
;
337 int nh
= LCD_HEIGHT
- NEEDLE_TOP
;
340 for (i
=1; i
<= half_width
; i
++)
343 y
= (half_width
/5)*flog(i
*fx_log_factor
);
345 /* better way of checking for negative values? */
350 analog_db_scale
[i
-1] = z
;
354 /* y values (analog needle co-ords) */
355 j
= i
- (int)(half_width
/2);
358 /* fsqrt+1 seems to give a closer approximation */
359 y_values
[i
-1] = LCD_HEIGHT
- (fsqrt(k
, 16)>>8) - 1;
364 void load_settings(void) {
365 int fp
= rb
->open(PLUGIN_DEMOS_DIR
"/.vu_meter", O_RDONLY
);
367 rb
->read(fp
, &vumeter_settings
, sizeof(struct saved_settings
));
372 rb
->splash(HZ
, "Press " LABEL_HELP
" for help");
376 void save_settings(void) {
377 int fp
= rb
->creat(PLUGIN_DEMOS_DIR
"/.vu_meter");
379 rb
->write (fp
, &vumeter_settings
, sizeof(struct saved_settings
));
384 void change_volume(int delta
) {
386 int minvol
= rb
->sound_min(SOUND_VOLUME
);
387 int maxvol
= rb
->sound_max(SOUND_VOLUME
);
388 int vol
= rb
->global_settings
->volume
+ delta
;
390 if (vol
> maxvol
) vol
= maxvol
;
391 else if (vol
< minvol
) vol
= minvol
;
392 if (vol
!= rb
->global_settings
->volume
) {
393 rb
->sound_set(SOUND_VOLUME
, vol
);
394 rb
->global_settings
->volume
= vol
;
395 rb
->snprintf(curr_vol
, sizeof(curr_vol
), "%d", vol
);
396 rb
->lcd_putsxy(0,0, curr_vol
);
402 static bool vu_meter_menu(void)
405 bool menu_quit
= false;
408 MENUITEM_STRINGLIST(menu
,"VU Meter Menu",NULL
,"Meter Type","Scale",
409 "Minimeters","Decay Speed","Quit");
411 static const struct opt_items meter_type_option
[2] = {
416 static const struct opt_items decay_speed_option
[7] = {
421 { "Medium-Slow", -1 },
427 switch(rb
->do_menu(&menu
, &selection
, NULL
, false))
430 rb
->set_option("Meter Type", &vumeter_settings
.meter_type
, INT
,
431 meter_type_option
, 2, NULL
);
435 if(vumeter_settings
.meter_type
==ANALOG
)
437 rb
->set_bool_options("Scale", &vumeter_settings
.analog_use_db_scale
,
438 "dBfs", -1, "Linear", -1, NULL
);
442 rb
->set_bool_options("Scale", &vumeter_settings
.digital_use_db_scale
,
443 "dBfs", -1, "Linear", -1, NULL
);
448 if(vumeter_settings
.meter_type
==ANALOG
)
450 rb
->set_bool("Enable Minimeters",
451 &vumeter_settings
.analog_minimeters
);
455 rb
->set_bool("Enable Minimeters",
456 &vumeter_settings
.digital_minimeters
);
461 if(vumeter_settings
.meter_type
==ANALOG
)
463 rb
->set_option("Decay Speed", &vumeter_settings
.analog_decay
, INT
,
464 decay_speed_option
, 7, NULL
);
468 rb
->set_option("Decay Speed", &vumeter_settings
.digital_decay
, INT
,
469 decay_speed_option
, 7, NULL
);
475 /* fall through to exit the menu */
481 /* the menu uses the userfont, set it back to sysfont */
482 rb
->lcd_setfont(FONT_SYSFIXED
);
486 void draw_analog_minimeters(void) {
487 rb
->lcd_mono_bitmap(sound_speaker
, quarter_width
-28, 12, 4, 8);
488 rb
->lcd_set_drawmode(DRMODE_FG
);
489 if(analog_mini_1
<left_needle_top_x
)
490 rb
->lcd_mono_bitmap(sound_low_level
, quarter_width
-23, 12, 2, 8);
491 if(analog_mini_2
<left_needle_top_x
)
492 rb
->lcd_mono_bitmap(sound_med_level
, quarter_width
-21, 12, 2, 8);
493 if(analog_mini_3
<left_needle_top_x
)
494 rb
->lcd_mono_bitmap(sound_high_level
, quarter_width
-19, 12, 2, 8);
495 if(analog_mini_4
<left_needle_top_x
)
496 rb
->lcd_mono_bitmap(sound_max_level
, quarter_width
-16, 12, 3, 8);
498 rb
->lcd_set_drawmode(DRMODE_SOLID
);
499 rb
->lcd_mono_bitmap(sound_speaker
, quarter_width
+half_width
-30, 12, 4, 8);
500 rb
->lcd_set_drawmode(DRMODE_FG
);
501 if(analog_mini_1
<(right_needle_top_x
-half_width
))
502 rb
->lcd_mono_bitmap(sound_low_level
, quarter_width
+half_width
-25, 12, 2, 8);
503 if(analog_mini_2
<(right_needle_top_x
-half_width
))
504 rb
->lcd_mono_bitmap(sound_med_level
, quarter_width
+half_width
-23, 12, 2, 8);
505 if(analog_mini_3
<(right_needle_top_x
-half_width
))
506 rb
->lcd_mono_bitmap(sound_high_level
, quarter_width
+half_width
-21, 12, 2, 8);
507 if(analog_mini_4
<(right_needle_top_x
-half_width
))
508 rb
->lcd_mono_bitmap(sound_max_level
, quarter_width
+half_width
-18, 12, 3, 8);
509 rb
->lcd_set_drawmode(DRMODE_SOLID
);
512 void draw_digital_minimeters(void) {
513 rb
->lcd_mono_bitmap(sound_speaker
, 34, half_height
-8, 4, 8);
514 rb
->lcd_set_drawmode(DRMODE_FG
);
516 rb
->lcd_mono_bitmap(sound_low_level
, 39, half_height
-8, 2, 8);
518 rb
->lcd_mono_bitmap(sound_med_level
, 41, half_height
-8, 2, 8);
520 rb
->lcd_mono_bitmap(sound_high_level
, 43, half_height
-8, 2, 8);
522 rb
->lcd_mono_bitmap(sound_max_level
, 46, half_height
-8, 3, 8);
524 rb
->lcd_set_drawmode(DRMODE_SOLID
);
525 rb
->lcd_mono_bitmap(sound_speaker
, 34, half_height
+8, 4, 8);
526 rb
->lcd_set_drawmode(DRMODE_FG
);
527 if(1<(num_right_leds
))
528 rb
->lcd_mono_bitmap(sound_low_level
, 39, half_height
+8, 2, 8);
529 if(2<(num_right_leds
))
530 rb
->lcd_mono_bitmap(sound_med_level
, 41, half_height
+8, 2, 8);
531 if(5<(num_right_leds
))
532 rb
->lcd_mono_bitmap(sound_high_level
, 43, half_height
+8, 2, 8);
533 if(8<(num_right_leds
))
534 rb
->lcd_mono_bitmap(sound_max_level
, 46, half_height
+8, 3, 8);
535 rb
->lcd_set_drawmode(DRMODE_SOLID
);
538 void analog_meter(void) {
540 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
541 int left_peak
= rb
->mas_codec_readreg(0xC);
542 int right_peak
= rb
->mas_codec_readreg(0xD);
543 #elif (CONFIG_CODEC == SWCODEC)
544 int left_peak
, right_peak
;
545 rb
->pcm_calculate_peaks(&left_peak
, &right_peak
);
548 if(vumeter_settings
.analog_use_db_scale
) {
549 left_needle_top_x
= analog_db_scale
[left_peak
* half_width
/ MAX_PEAK
];
550 right_needle_top_x
= analog_db_scale
[right_peak
* half_width
/ MAX_PEAK
] + half_width
;
553 left_needle_top_x
= left_peak
* half_width
/ MAX_PEAK
;
554 right_needle_top_x
= right_peak
* half_width
/ MAX_PEAK
+ half_width
;
557 /* Makes a decay on the needle */
558 left_needle_top_x
= (left_needle_top_x
+last_left_needle_top_x
*vumeter_settings
.analog_decay
)
559 /(vumeter_settings
.analog_decay
+1);
560 right_needle_top_x
= (right_needle_top_x
+last_right_needle_top_x
*vumeter_settings
.analog_decay
)
561 /(vumeter_settings
.analog_decay
+1);
563 last_left_needle_top_x
= left_needle_top_x
;
564 last_right_needle_top_x
= right_needle_top_x
;
566 left_needle_top_y
= y_values
[left_needle_top_x
];
567 right_needle_top_y
= y_values
[right_needle_top_x
-half_width
];
570 rb
->lcd_drawline(quarter_width
, LCD_HEIGHT
-1, left_needle_top_x
, left_needle_top_y
);
571 rb
->lcd_drawline((quarter_width
+half_width
), LCD_HEIGHT
-1, right_needle_top_x
, right_needle_top_y
);
573 if(vumeter_settings
.analog_minimeters
)
574 draw_analog_minimeters();
577 rb
->lcd_set_drawmode(DRMODE_FG
);
578 rb
->lcd_mono_bitmap(needle_cover
, quarter_width
-6, LCD_HEIGHT
-5, 13, 5);
579 rb
->lcd_mono_bitmap(needle_cover
, half_width
+quarter_width
-6, LCD_HEIGHT
-5, 13, 5);
580 rb
->lcd_set_drawmode(DRMODE_SOLID
);
582 /* Show Left/Right */
583 rb
->lcd_putsxy(quarter_width
-12, 12, "Left");
584 rb
->lcd_putsxy(half_width
+quarter_width
-12, 12, "Right");
586 /* Line above/below the Left/Right text */
587 rb
->lcd_hline(0,LCD_WIDTH
-1,9);
588 rb
->lcd_hline(0,LCD_WIDTH
-1,21);
590 for(i
=0; i
<half_width
; i
++) {
591 rb
->lcd_drawpixel(i
, (y_values
[i
])-2);
592 rb
->lcd_drawpixel(i
+half_width
, (y_values
[i
])-2);
596 void digital_meter(void) {
597 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
598 int left_peak
= rb
->mas_codec_readreg(0xC);
599 int right_peak
= rb
->mas_codec_readreg(0xD);
600 #elif (CONFIG_CODEC == SWCODEC)
601 int left_peak
, right_peak
;
602 rb
->pcm_calculate_peaks(&left_peak
, &right_peak
);
605 if(vumeter_settings
.digital_use_db_scale
) {
606 num_left_leds
= digital_db_scale
[left_peak
* 44 / MAX_PEAK
];
607 num_right_leds
= digital_db_scale
[right_peak
* 44 / MAX_PEAK
];
610 num_left_leds
= left_peak
* 11 / MAX_PEAK
;
611 num_right_leds
= right_peak
* 11 / MAX_PEAK
;
614 num_left_leds
= (num_left_leds
+last_num_left_leds
*vumeter_settings
.digital_decay
)
615 /(vumeter_settings
.digital_decay
+1);
616 num_right_leds
= (num_right_leds
+last_num_right_leds
*vumeter_settings
.digital_decay
)
617 /(vumeter_settings
.digital_decay
+1);
619 last_num_left_leds
= num_left_leds
;
620 last_num_right_leds
= num_right_leds
;
622 rb
->lcd_set_drawmode(DRMODE_FG
);
624 for(i
=0; i
<num_left_leds
; i
++)
625 rb
->lcd_fillrect((digital_lead
+ (i
*digital_block_width
)),
626 14, digital_block_width
- digital_block_gap
, digital_block_height
);
628 for(i
=0; i
<num_right_leds
; i
++)
629 rb
->lcd_fillrect((digital_lead
+ (i
*digital_block_width
)),
630 (half_height
+ 20), digital_block_width
- digital_block_gap
,
631 digital_block_height
);
633 rb
->lcd_set_drawmode(DRMODE_SOLID
);
635 if(vumeter_settings
.digital_minimeters
)
636 draw_digital_minimeters();
638 /* Lines above/below where the LEDS are */
639 rb
->lcd_hline(0,LCD_WIDTH
-1,12);
640 rb
->lcd_hline(0,LCD_WIDTH
-1,half_height
-12);
642 rb
->lcd_hline(0,LCD_WIDTH
-1,half_height
+18);
643 rb
->lcd_hline(0,LCD_WIDTH
-1,LCD_HEIGHT
-6);
645 /* Show Left/Right */
646 rb
->lcd_putsxy(2, half_height
-8, "Left");
647 rb
->lcd_putsxy(2, half_height
+8, "Right");
649 /* Line in the middle */
650 rb
->lcd_hline(0,LCD_WIDTH
-1,half_height
+3);
653 enum plugin_status
plugin_start(const struct plugin_api
* api
, const void* parameter
) {
655 int lastbutton
= BUTTON_NONE
;
663 rb
->lcd_setfont(FONT_SYSFIXED
);
667 rb
->lcd_clear_display();
669 rb
->lcd_putsxy(half_width
-23, 0, "VU Meter");
671 if(vumeter_settings
.meter_type
==ANALOG
)
678 button
= rb
->button_get_w_tmo(1);
681 #ifdef VUMETER_RC_QUIT
682 case VUMETER_RC_QUIT
:
690 #ifdef VUMETER_HELP_PRE
691 if (lastbutton
!= VUMETER_HELP_PRE
)
694 rb
->lcd_clear_display();
695 rb
->lcd_puts(0, 0, LABEL_QUIT
": Exit");
696 rb
->lcd_puts(0, 1, LABEL_MENU
": Settings");
697 rb
->lcd_puts(0, 2, LABEL_VOLUME
": Volume");
708 #ifdef VUMETER_MENU_PRE
709 if (lastbutton
!= VUMETER_MENU_PRE
)
717 case VUMETER_UP
| BUTTON_REPEAT
:
722 case VUMETER_DOWN
| BUTTON_REPEAT
:
727 if(rb
->default_event_handler(button
) == SYS_USB_CONNECTED
)
728 return PLUGIN_USB_CONNECTED
;
731 if (button
!= BUTTON_NONE
)
735 #endif /* #ifdef HAVE_LCD_BITMAP */