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 "lib/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!
216 #ifdef HAVE_TOUCHSCREEN
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
;
301 #ifdef HAVE_LCD_COLOR
302 int screen_foreground
;
305 #define MAX_PEAK 0x8000
307 /* gap at the top for left/right etc */
308 #define NEEDLE_TOP 25
310 /* pow(M_E, 5) * 65536 */
311 #define E_POW_5 9726404
313 struct saved_settings
{
315 bool analog_use_db_scale
;
316 bool digital_use_db_scale
;
317 bool analog_minimeters
;
318 bool digital_minimeters
;
323 void reset_settings(void) {
324 vumeter_settings
.meter_type
=ANALOG
;
325 vumeter_settings
.analog_use_db_scale
=true;
326 vumeter_settings
.digital_use_db_scale
=true;
327 vumeter_settings
.analog_minimeters
=true;
328 vumeter_settings
.digital_minimeters
=false;
329 vumeter_settings
.analog_decay
=3;
330 vumeter_settings
.digital_decay
=0;
333 void calc_scales(void)
335 unsigned int fx_log_factor
= E_POW_5
/half_width
;
340 int nh
= LCD_HEIGHT
- NEEDLE_TOP
;
343 for (i
=1; i
<= half_width
; i
++)
346 y
= (half_width
/5)*flog(i
*fx_log_factor
);
348 /* better way of checking for negative values? */
353 analog_db_scale
[i
-1] = z
;
357 /* y values (analog needle co-ords) */
358 j
= i
- (int)(half_width
/2);
361 /* fsqrt+1 seems to give a closer approximation */
362 y_values
[i
-1] = LCD_HEIGHT
- (fsqrt(k
, 16)>>8) - 1;
367 void load_settings(void) {
368 int fp
= rb
->open(PLUGIN_DEMOS_DIR
"/.vu_meter", O_RDONLY
);
370 rb
->read(fp
, &vumeter_settings
, sizeof(struct saved_settings
));
375 rb
->splash(HZ
, "Press " LABEL_HELP
" for help");
379 void save_settings(void) {
380 int fp
= rb
->creat(PLUGIN_DEMOS_DIR
"/.vu_meter");
382 rb
->write (fp
, &vumeter_settings
, sizeof(struct saved_settings
));
387 void change_volume(int delta
) {
389 int minvol
= rb
->sound_min(SOUND_VOLUME
);
390 int maxvol
= rb
->sound_max(SOUND_VOLUME
);
391 int vol
= rb
->global_settings
->volume
+ delta
;
393 if (vol
> maxvol
) vol
= maxvol
;
394 else if (vol
< minvol
) vol
= minvol
;
395 if (vol
!= rb
->global_settings
->volume
) {
396 rb
->sound_set(SOUND_VOLUME
, vol
);
397 rb
->global_settings
->volume
= vol
;
398 rb
->snprintf(curr_vol
, sizeof(curr_vol
), "%d", vol
);
399 rb
->lcd_putsxy(0,0, curr_vol
);
405 static bool vu_meter_menu(void)
408 bool menu_quit
= false;
411 MENUITEM_STRINGLIST(menu
,"VU Meter Menu",NULL
,"Meter Type","Scale",
412 "Minimeters","Decay Speed","Quit");
414 static const struct opt_items meter_type_option
[2] = {
419 static const struct opt_items decay_speed_option
[7] = {
424 { "Medium-Slow", -1 },
430 switch(rb
->do_menu(&menu
, &selection
, NULL
, false))
433 rb
->set_option("Meter Type", &vumeter_settings
.meter_type
, INT
,
434 meter_type_option
, 2, NULL
);
438 if(vumeter_settings
.meter_type
==ANALOG
)
440 rb
->set_bool_options("Scale", &vumeter_settings
.analog_use_db_scale
,
441 "dBfs", -1, "Linear", -1, NULL
);
445 rb
->set_bool_options("Scale", &vumeter_settings
.digital_use_db_scale
,
446 "dBfs", -1, "Linear", -1, NULL
);
451 if(vumeter_settings
.meter_type
==ANALOG
)
453 rb
->set_bool("Enable Minimeters",
454 &vumeter_settings
.analog_minimeters
);
458 rb
->set_bool("Enable Minimeters",
459 &vumeter_settings
.digital_minimeters
);
464 if(vumeter_settings
.meter_type
==ANALOG
)
466 rb
->set_option("Decay Speed", &vumeter_settings
.analog_decay
, INT
,
467 decay_speed_option
, 7, NULL
);
471 rb
->set_option("Decay Speed", &vumeter_settings
.digital_decay
, INT
,
472 decay_speed_option
, 7, NULL
);
478 /* fall through to exit the menu */
484 /* the menu uses the userfont, set it back to sysfont */
485 rb
->lcd_setfont(FONT_SYSFIXED
);
489 void draw_analog_minimeters(void) {
490 rb
->lcd_mono_bitmap(sound_speaker
, quarter_width
-28, 12, 4, 8);
491 rb
->lcd_set_drawmode(DRMODE_FG
);
492 if(analog_mini_1
<left_needle_top_x
)
493 rb
->lcd_mono_bitmap(sound_low_level
, quarter_width
-23, 12, 2, 8);
494 if(analog_mini_2
<left_needle_top_x
)
495 rb
->lcd_mono_bitmap(sound_med_level
, quarter_width
-21, 12, 2, 8);
496 if(analog_mini_3
<left_needle_top_x
)
497 rb
->lcd_mono_bitmap(sound_high_level
, quarter_width
-19, 12, 2, 8);
498 if(analog_mini_4
<left_needle_top_x
)
499 rb
->lcd_mono_bitmap(sound_max_level
, quarter_width
-16, 12, 3, 8);
501 rb
->lcd_set_drawmode(DRMODE_SOLID
);
502 rb
->lcd_mono_bitmap(sound_speaker
, quarter_width
+half_width
-30, 12, 4, 8);
503 rb
->lcd_set_drawmode(DRMODE_FG
);
504 if(analog_mini_1
<(right_needle_top_x
-half_width
))
505 rb
->lcd_mono_bitmap(sound_low_level
, quarter_width
+half_width
-25, 12, 2, 8);
506 if(analog_mini_2
<(right_needle_top_x
-half_width
))
507 rb
->lcd_mono_bitmap(sound_med_level
, quarter_width
+half_width
-23, 12, 2, 8);
508 if(analog_mini_3
<(right_needle_top_x
-half_width
))
509 rb
->lcd_mono_bitmap(sound_high_level
, quarter_width
+half_width
-21, 12, 2, 8);
510 if(analog_mini_4
<(right_needle_top_x
-half_width
))
511 rb
->lcd_mono_bitmap(sound_max_level
, quarter_width
+half_width
-18, 12, 3, 8);
512 rb
->lcd_set_drawmode(DRMODE_SOLID
);
515 void draw_digital_minimeters(void) {
516 #ifdef HAVE_LCD_COLOR
517 rb
->lcd_set_foreground(LCD_RGBPACK(255, 255 - 23 * num_left_leds
, 0));
519 rb
->lcd_mono_bitmap(sound_speaker
, 34, half_height
-8, 4, 8);
520 rb
->lcd_set_drawmode(DRMODE_FG
);
522 rb
->lcd_mono_bitmap(sound_low_level
, 39, half_height
-8, 2, 8);
524 rb
->lcd_mono_bitmap(sound_med_level
, 41, half_height
-8, 2, 8);
526 rb
->lcd_mono_bitmap(sound_high_level
, 43, half_height
-8, 2, 8);
528 rb
->lcd_mono_bitmap(sound_max_level
, 46, half_height
-8, 3, 8);
530 #ifdef HAVE_LCD_COLOR
531 rb
->lcd_set_foreground(LCD_RGBPACK(255, 255 - 23 * num_right_leds
, 0));
533 rb
->lcd_set_drawmode(DRMODE_SOLID
);
534 rb
->lcd_mono_bitmap(sound_speaker
, 34, half_height
+8, 4, 8);
535 rb
->lcd_set_drawmode(DRMODE_FG
);
536 if(1<(num_right_leds
))
537 rb
->lcd_mono_bitmap(sound_low_level
, 39, half_height
+8, 2, 8);
538 if(2<(num_right_leds
))
539 rb
->lcd_mono_bitmap(sound_med_level
, 41, half_height
+8, 2, 8);
540 if(5<(num_right_leds
))
541 rb
->lcd_mono_bitmap(sound_high_level
, 43, half_height
+8, 2, 8);
542 if(8<(num_right_leds
))
543 rb
->lcd_mono_bitmap(sound_max_level
, 46, half_height
+8, 3, 8);
544 rb
->lcd_set_drawmode(DRMODE_SOLID
);
546 #ifdef HAVE_LCD_COLOR
547 rb
->lcd_set_foreground(screen_foreground
);
551 void analog_meter(void) {
553 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
554 int left_peak
= rb
->mas_codec_readreg(0xC);
555 int right_peak
= rb
->mas_codec_readreg(0xD);
556 #elif (CONFIG_CODEC == SWCODEC)
557 int left_peak
, right_peak
;
558 rb
->pcm_calculate_peaks(&left_peak
, &right_peak
);
561 if(vumeter_settings
.analog_use_db_scale
) {
562 left_needle_top_x
= analog_db_scale
[left_peak
* half_width
/ MAX_PEAK
];
563 right_needle_top_x
= analog_db_scale
[right_peak
* half_width
/ MAX_PEAK
] + half_width
;
566 left_needle_top_x
= left_peak
* half_width
/ MAX_PEAK
;
567 right_needle_top_x
= right_peak
* half_width
/ MAX_PEAK
+ half_width
;
570 /* Makes a decay on the needle */
571 left_needle_top_x
= (left_needle_top_x
+last_left_needle_top_x
*vumeter_settings
.analog_decay
)
572 /(vumeter_settings
.analog_decay
+1);
573 right_needle_top_x
= (right_needle_top_x
+last_right_needle_top_x
*vumeter_settings
.analog_decay
)
574 /(vumeter_settings
.analog_decay
+1);
576 last_left_needle_top_x
= left_needle_top_x
;
577 last_right_needle_top_x
= right_needle_top_x
;
579 left_needle_top_y
= y_values
[left_needle_top_x
];
580 right_needle_top_y
= y_values
[right_needle_top_x
-half_width
];
583 rb
->lcd_drawline(quarter_width
, LCD_HEIGHT
-1, left_needle_top_x
, left_needle_top_y
);
584 rb
->lcd_drawline((quarter_width
+half_width
), LCD_HEIGHT
-1, right_needle_top_x
, right_needle_top_y
);
586 if(vumeter_settings
.analog_minimeters
)
587 draw_analog_minimeters();
590 rb
->lcd_set_drawmode(DRMODE_FG
);
591 rb
->lcd_mono_bitmap(needle_cover
, quarter_width
-6, LCD_HEIGHT
-5, 13, 5);
592 rb
->lcd_mono_bitmap(needle_cover
, half_width
+quarter_width
-6, LCD_HEIGHT
-5, 13, 5);
593 rb
->lcd_set_drawmode(DRMODE_SOLID
);
595 /* Show Left/Right */
596 rb
->lcd_putsxy(quarter_width
-12, 12, "Left");
597 rb
->lcd_putsxy(half_width
+quarter_width
-12, 12, "Right");
599 /* Line above/below the Left/Right text */
600 rb
->lcd_hline(0,LCD_WIDTH
-1,9);
601 rb
->lcd_hline(0,LCD_WIDTH
-1,21);
603 for(i
=0; i
<half_width
; i
++) {
604 rb
->lcd_drawpixel(i
, (y_values
[i
])-2);
605 rb
->lcd_drawpixel(i
+half_width
, (y_values
[i
])-2);
609 void digital_meter(void) {
610 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
611 int left_peak
= rb
->mas_codec_readreg(0xC);
612 int right_peak
= rb
->mas_codec_readreg(0xD);
613 #elif (CONFIG_CODEC == SWCODEC)
614 int left_peak
, right_peak
;
615 rb
->pcm_calculate_peaks(&left_peak
, &right_peak
);
618 if(vumeter_settings
.digital_use_db_scale
) {
619 num_left_leds
= digital_db_scale
[left_peak
* 44 / MAX_PEAK
];
620 num_right_leds
= digital_db_scale
[right_peak
* 44 / MAX_PEAK
];
623 num_left_leds
= left_peak
* 11 / MAX_PEAK
;
624 num_right_leds
= right_peak
* 11 / MAX_PEAK
;
627 num_left_leds
= (num_left_leds
+last_num_left_leds
*vumeter_settings
.digital_decay
)
628 /(vumeter_settings
.digital_decay
+1);
629 num_right_leds
= (num_right_leds
+last_num_right_leds
*vumeter_settings
.digital_decay
)
630 /(vumeter_settings
.digital_decay
+1);
632 last_num_left_leds
= num_left_leds
;
633 last_num_right_leds
= num_right_leds
;
635 rb
->lcd_set_drawmode(DRMODE_FG
);
637 for(i
=0; i
<num_left_leds
; i
++) {
638 #ifdef HAVE_LCD_COLOR
639 rb
->lcd_set_foreground(LCD_RGBPACK(255, 255 - 23 * i
, 0));
641 rb
->lcd_fillrect((digital_lead
+ (i
*digital_block_width
)),
642 14, digital_block_width
- digital_block_gap
, digital_block_height
);
645 for(i
=0; i
<num_right_leds
; i
++) {
646 #ifdef HAVE_LCD_COLOR
647 rb
->lcd_set_foreground(LCD_RGBPACK(255, 255 - 23 * i
, 0));
649 rb
->lcd_fillrect((digital_lead
+ (i
*digital_block_width
)),
650 (half_height
+ 20), digital_block_width
- digital_block_gap
,
651 digital_block_height
);
654 #ifdef HAVE_LCD_COLOR
655 rb
->lcd_set_foreground(screen_foreground
);
657 rb
->lcd_set_drawmode(DRMODE_SOLID
);
659 if(vumeter_settings
.digital_minimeters
)
660 draw_digital_minimeters();
662 /* Lines above/below where the LEDS are */
663 rb
->lcd_hline(0,LCD_WIDTH
-1,12);
664 rb
->lcd_hline(0,LCD_WIDTH
-1,half_height
-12);
666 rb
->lcd_hline(0,LCD_WIDTH
-1,half_height
+18);
667 rb
->lcd_hline(0,LCD_WIDTH
-1,LCD_HEIGHT
-6);
669 /* Show Left/Right */
670 rb
->lcd_putsxy(2, half_height
-8, "Left");
671 rb
->lcd_putsxy(2, half_height
+8, "Right");
673 /* Line in the middle */
674 rb
->lcd_hline(0,LCD_WIDTH
-1,half_height
+3);
677 enum plugin_status
plugin_start(const struct plugin_api
* api
, const void* parameter
) {
679 int lastbutton
= BUTTON_NONE
;
687 rb
->lcd_setfont(FONT_SYSFIXED
);
688 #ifdef HAVE_LCD_COLOR
689 screen_foreground
= rb
->lcd_get_foreground();
694 rb
->lcd_clear_display();
696 rb
->lcd_putsxy(half_width
-23, 0, "VU Meter");
698 if(vumeter_settings
.meter_type
==ANALOG
)
705 button
= rb
->button_get_w_tmo(1);
708 #ifdef VUMETER_RC_QUIT
709 case VUMETER_RC_QUIT
:
717 #ifdef VUMETER_HELP_PRE
718 if (lastbutton
!= VUMETER_HELP_PRE
)
721 rb
->lcd_clear_display();
722 rb
->lcd_puts(0, 0, LABEL_QUIT
": Exit");
723 rb
->lcd_puts(0, 1, LABEL_MENU
": Settings");
724 rb
->lcd_puts(0, 2, LABEL_VOLUME
": Volume");
735 #ifdef VUMETER_MENU_PRE
736 if (lastbutton
!= VUMETER_MENU_PRE
)
744 case VUMETER_UP
| BUTTON_REPEAT
:
749 case VUMETER_DOWN
| BUTTON_REPEAT
:
754 if(rb
->default_event_handler(button
) == SYS_USB_CONNECTED
)
755 return PLUGIN_USB_CONNECTED
;
758 if (button
!= BUTTON_NONE
)
762 #endif /* #ifdef HAVE_LCD_BITMAP */