Index: apps/main.c
===================================================================
RCS file: /cvsroot/rockbox/apps/main.c,v
retrieving revision 1.53
diff -u -b -r1.53 main.c
--- apps/main.c	12 Sep 2002 13:33:57 -0000	1.53
+++ apps/main.c	19 Sep 2002 20:00:01 -0000
@@ -45,9 +45,11 @@
 #include "debug_menu.h"
 #include "version.h"
 #include "sprintf.h"
+#ifdef HAVE_LCD_BITMAP 
+#include "peakmeter.h"
+#endif
 #include "font.h"
 
-
 char appsversion[]=APPSVERSION;
 
 void init(void);
@@ -89,10 +91,10 @@
     
     lcd_init();
 
-    // FIXME should call font_init before this, 
-    // because may use loadable font in show_logo().
-    // I didn't call font_init here, since
-    // disk system isn't up yet.
+    /* FIXME should call font_init before this, 
+       because may use loadable font in show_logo().
+       I didn't call font_init here, since
+       disk system isn't up yet. */
     show_logo();
 
 #ifdef DEBUG
@@ -117,6 +119,11 @@
     button_init();
 
     rc = ata_init();
+
+#ifdef HAVE_LCD_BITMAP
+    peak_meter_init();
+#endif
+
     if(rc)
     {
 #ifdef HAVE_LCD_BITMAP
Index: apps/settings.c
===================================================================
RCS file: /cvsroot/rockbox/apps/settings.c,v
retrieving revision 1.59
diff -u -b -r1.59 settings.c
--- apps/settings.c	19 Sep 2002 09:00:25 -0000	1.59
+++ apps/settings.c	19 Sep 2002 20:00:07 -0000
@@ -52,6 +52,12 @@
 #define CONFIG_BLOCK_SIZE 512
 #define RTC_BLOCK_SIZE 44
 
+#ifdef HAVE_LCD_BITMAP
+#define MAX_LINES 10
+#else
+#define MAX_LINES 2
+#endif
+
 /********************************************
 
 Config block as saved on the battery-packed RTC user RAM memory block
@@ -404,6 +410,11 @@
         if (config_block[0x24] != 0xFF)
             memcpy(&global_settings.total_uptime, &config_block[0x24], 4);
 
+        /* This is dirty initialization. Maybe these peak_meter values 
+           should be saved in rtc */
+        global_settings.peak_meter_release = 200;
+        global_settings.peak_meter_overflow = 60;
+
         strncpy(global_settings.resume_file, &config_block[0xFC], MAX_PATH);
         global_settings.resume_file[MAX_PATH]=0;
     }
@@ -469,7 +480,7 @@
                                 break;
                             case 3:
                                 snprintf(buf_disp,sizeof(buf_disp),"[%s]%s", buf_set, buf_val);
-                                lcd_puts(0,line++ % 6,buf_disp);
+                                lcd_puts(0,line++ % MAX_LINES, buf_disp);
                                 lcd_update();
                                 sleep(HZ/2);
                                 if (!strcasecmp(buf_set,"volume")) {
@@ -609,6 +620,8 @@
     global_settings.disk_spindown = 5;
     global_settings.browse_current = false;
     global_settings.play_selected = true;
+    global_settings.peak_meter_release = 200;
+    global_settings.peak_meter_overflow = 60;
 }
 
 
Index: apps/settings.h
===================================================================
RCS file: /cvsroot/rockbox/apps/settings.h,v
retrieving revision 1.42
diff -u -b -r1.42 settings.h
--- apps/settings.h	18 Sep 2002 10:12:16 -0000	1.42
+++ apps/settings.h	19 Sep 2002 20:00:08 -0000
@@ -85,6 +85,8 @@
     int ff_rewind_min_step; /* FF/Rewind minimum step size */
     int ff_rewind_accel; /* FF/Rewind acceleration (in seconds per doubling) */
     int disk_spindown; /* time until disk spindown, in seconds (0=off) */
+    int peak_meter_release;  /* release time for peak meter: 20 - */
+    int peak_meter_overflow; /* release time for overflows in peak meter: 20 - */
 
     /* show status bar */
     bool statusbar;    /* 0=hide, 1=show */
Index: apps/settings_menu.c
===================================================================
RCS file: /cvsroot/rockbox/apps/settings_menu.c,v
retrieving revision 1.56
diff -u -b -r1.56 settings_menu.c
--- apps/settings_menu.c	18 Sep 2002 14:08:03 -0000	1.56
+++ apps/settings_menu.c	19 Sep 2002 20:00:09 -0000
@@ -36,6 +36,7 @@
 #include "powermgmt.h"
 #include "rtc.h"
 #include "ata.h"
+#include "peakmeter.h"
 #include "lang.h"
 
 static Menu show_hidden_files(void)
@@ -52,6 +53,38 @@
     return MENU_OK;
 }
 
+#ifdef HAVE_LCD_BITMAP
+static Menu peak_meter_release(void) {
+    set_int( str(LANG_PM_PEAK_RELEASE), "x 10 ms", 
+             &global_settings.peak_meter_release,
+             NULL, 1, 20, 10000);
+    return MENU_OK;
+}
+
+static Menu peak_meter_overflow(void) {
+    set_int( str(LANG_PM_OVER_RELEASE), "sec", 
+             &global_settings.peak_meter_overflow,
+             peak_meter_reset_overflow, 1, 1, 10000);
+    return MENU_OK;
+}
+
+static Menu peak_meter_menu(void) 
+{
+    int m;
+    Menu result;
+
+    struct menu_items items[] = {
+        { str(LANG_PM_PEAK_RELEASE), peak_meter_release    },  
+        { str(LANG_PM_OVER_RELEASE), peak_meter_overflow   },
+    };
+    
+    m=menu_init( items, sizeof items / sizeof(struct menu_items) );
+    result = menu_run(m);
+    menu_exit(m);
+    return result;
+}
+#endif
+
 #ifndef HAVE_RECORDER_KEYPAD
 static Menu shuffle(void)
 {
@@ -301,6 +334,9 @@
         { str(LANG_SCROLL_MENU),     scroll_speed    },  
         { str(LANG_BACKLIGHT),       backlight_timer },
         { str(LANG_CONTRAST),        contrast        },  
+#ifdef HAVE_LCD_BITMAP
+        { str(LANG_PM_MENU),         peak_meter_menu },  
+#endif
     };
     
     m=menu_init( items, sizeof items / sizeof(struct menu_items) );
Index: apps/wps-display.c
===================================================================
RCS file: /cvsroot/rockbox/apps/wps-display.c,v
retrieving revision 1.20
diff -u -b -r1.20 wps-display.c
--- apps/wps-display.c	18 Sep 2002 14:08:04 -0000	1.20
+++ apps/wps-display.c	19 Sep 2002 20:00:13 -0000
@@ -37,10 +37,14 @@
 #include "status.h"
 #include "wps-display.h"
 #include "debug.h"
+#include "mas.h"
 #include "lang.h"
+
 #ifdef HAVE_LCD_BITMAP
 #include "icons.h"
 #include "widgets.h"
+#include "menu.h" /* peakmeter.h depends on this */
+#include "peakmeter.h"
 #endif
 
 #define WPS_CONFIG ROCKBOX_DIR "/default.wps"
@@ -52,12 +56,12 @@
 #endif
 
 #define FORMAT_BUFFER_SIZE 300
-
 struct format_flags
 {
     bool dynamic;
     bool scroll;
     bool player_progress;
+    bool peak_meter;
 };
 
 static char format_buffer[FORMAT_BUFFER_SIZE];
@@ -331,6 +335,13 @@
                 case 't':  /* Total Time */
                     format_time(buf, buf_size, id3->length);
                     return buf;
+
+#ifdef HAVE_LCD_BITMAP
+                case 'm': /* Peak Meter */
+                    flags->peak_meter = true;
+                    flags->dynamic = true;
+                    return "\x01";
+#endif
             }
             break;
     
@@ -518,6 +529,15 @@
     bool scroll_active = false;
     int i;
 
+    /* to find out wether the peak meter is enabled we
+       assume it wasn't until we find a line that contains
+       the peak meter. We can't use peak_meter_enabled itself
+       because that would mean to turn off the meter thread 
+       temporarily. (That shouldn't matter unless yield 
+       or sleep is called but who knows...)
+    */
+    bool enable_pm = false;
+
     if (!id3)
     {
         lcd_stop_scroll();
@@ -537,6 +557,7 @@
             flags.dynamic = false;
             flags.scroll = false;
             flags.player_progress = false;
+            flags.peak_meter = false;
             format_display(buf, sizeof(buf), id3, format_lines[i], &flags);
             dynamic_lines[i] = flags.dynamic;
             
@@ -556,6 +577,23 @@
 #endif
             }
 
+#ifdef HAVE_LCD_BITMAP
+            if (flags.peak_meter) {
+                int w,h;
+                int offset = global_settings.statusbar ? STATUSBAR_HEIGHT : 0;
+                lcd_getstringsize("M",FONT_UI,&w,&h);
+
+                int peak_meter_y = i * h + offset + 1;
+                int peak_meter_h = h;
+
+                /* found a line with a peak meter -> remember that we must
+                   enable it later */
+                enable_pm = true;
+                peak_meter_draw(0, peak_meter_y, LCD_WIDTH, peak_meter_h);
+                continue;
+            }
+#endif
+
             if (!scroll_active && flags.scroll && !flags.dynamic)
             {
                 scroll_active = true;
@@ -567,6 +605,10 @@
             }
         }
     }
+
+    /* Now we know wether the peak meter is used. 
+       So we can enable / disable the peak meter thread */
+    peak_meter_enabled = enable_pm;
     lcd_update();
 
     return true;
Index: apps/wps.c
===================================================================
RCS file: /cvsroot/rockbox/apps/wps.c,v
retrieving revision 1.147
diff -u -b -r1.147 wps.c
--- apps/wps.c	18 Sep 2002 14:08:04 -0000	1.147
+++ apps/wps.c	19 Sep 2002 20:00:16 -0000
@@ -39,6 +39,8 @@
 #include "ata.h"
 #ifdef HAVE_LCD_BITMAP
 #include "icons.h"
+#include "menu.h"
+#include "peakmeter.h"
 #endif
 #include "lang.h"
 #define FF_REWIND_MAX_PERCENT 3 /* cap ff/rewind step size at max % of file */ 
@@ -881,7 +883,7 @@
 /* demonstrates showing different formats from playtune */
 int wps_show(void)
 {
-    int button, lastbutton = 0;
+    int button = 0, lastbutton = 0;
     int old_repeat_mask;
     bool ignore_keyup = true;
     bool restore = false;
@@ -915,7 +917,27 @@
 
     while ( 1 )
     {
+
+#ifdef HAVE_LCD_BITMAP
+        /* when the peak meter is enabled we want to have a
+            few extra updates to make it look smooth. On the
+            other hand we don't want to waste enerty if it 
+            isn't displayed */
+        if (peak_meter_enabled) {
+            int i;
+            for (i = 0; i < 4; i++) {
+                button = button_get_w_tmo(HZ / 20);
+                if (button != 0) {
+                    break;
+                }
+                wps_refresh(id3, 0, false);
+            }
+        } else {
             button = button_get_w_tmo(HZ/5);
+        }
+#else
+        button = button_get_w_tmo(HZ/5);
+#endif
 
         /* discard first event if it's a button release */
         if (button && ignore_keyup)
@@ -1112,4 +1134,5 @@
         if(button != BUTTON_NONE)
             lastbutton = button;
     }
+    return 0; /* unreachable */
 }
Index: apps/lang/english.lang
===================================================================
RCS file: /cvsroot/rockbox/apps/lang/english.lang,v
retrieving revision 1.3
diff -u -b -r1.3 english.lang
--- apps/lang/english.lang	18 Sep 2002 14:08:04 -0000	1.3
+++ apps/lang/english.lang	19 Sep 2002 20:00:17 -0000
@@ -781,3 +781,17 @@
 desc: tetris game
 eng: "0 Rows - Level 0"
 new:
+id: LANG_PM_MENU
+desc: in the display menu
+eng: "Peak meter"
+new: 
+
+id: LANG_PM_PEAK_RELEASE
+desc: in the peak meter menu
+eng: "Peak release time"
+new: 
+
+id: LANG_PM_OVER_RELEASE
+desc: in the peak meter menu
+eng: "Overflow release time"
+new: 
Index: firmware/drivers/mas.h
===================================================================
RCS file: /cvsroot/rockbox/firmware/drivers/mas.h,v
retrieving revision 1.10
diff -u -b -r1.10 mas.h
--- firmware/drivers/mas.h	25 Jul 2002 15:54:15 -0000	1.10
+++ firmware/drivers/mas.h	19 Sep 2002 20:00:19 -0000
@@ -22,6 +22,8 @@
 #define MAS_BANK_D0 0
 #define MAS_BANK_D1 1
 
+#define MAX_PEAK 0x8000
+
 /*
 	MAS I2C	defs
 */

