不韋 呂 / Mbed 2 deprecated F746_RealtimeSpectrumAnalyzer_MEMS_Mic

Dependencies:   BSP_DISCO_F746NG BUTTON_GROUP LCD_DISCO_F746NG TS_DISCO_F746NG UIT_FFT_Real mbed

Revision:
4:2cdaad00d208
Parent:
2:5644475f01ea
Child:
6:16d668c3aa1e
--- a/MyClasses_Functions/WaveformDisplay.hpp	Fri Jan 08 13:03:24 2016 +0000
+++ b/MyClasses_Functions/WaveformDisplay.hpp	Sun Jan 10 09:58:43 2016 +0000
@@ -1,7 +1,7 @@
 //-----------------------------------------------------------
 //  Class for waveform display
 //
-//  2015/01/07, Copyright (c) 2015 MIKAMI, Naoki
+//  2015/01/10, Copyright (c) 2015 MIKAMI, Naoki
 //-----------------------------------------------------------
 
 #ifndef F746_WAVEFORM_DISPLAY_HPP
@@ -25,6 +25,8 @@
         
         void Execute(const int16_t xn[])
         {
+            static const uint16_t LIMIT1 = Y0_ + LIMIT2_;
+            static const uint16_t LIMIT2 = Y0_ - LIMIT2_;
             Axis();
             lcd_.SetTextColor(LINE_COLOR_);
             uint16_t x1 = X0_;
@@ -33,13 +35,21 @@
             {
                 uint16_t x2 = X0_ + n;
                 uint16_t y2 = Clip(xn[n]);
-                lcd_.DrawLine(x1, y1, x2, y2);
+                if ( ((y2 == LIMIT1) && (y1 == LIMIT1)) ||
+                     ((y2 == LIMIT2) && (y1 == LIMIT2)) )
+                {   // Out of displaying boundaries
+                    lcd_.SetTextColor(LCD_COLOR_RED);
+                    lcd_.DrawHLine(x1, y1, 1);
+                    lcd_.SetTextColor(LINE_COLOR_);
+                }
+                else
+                    lcd_.DrawLine(x1, y1, x2, y2);
+                if ((y1 == LIMIT1) || (y1 == LIMIT2))
+                    lcd_.DrawPixel(x1, y1, LCD_COLOR_RED);
                 x1 = x2;
                 y1 = y2;
             }
             lcd_.SetTextColor(BACK_COLOR_);
-            lcd_.DrawLine(X0_, Y0_-LIMIT_ , X0_+N_DATA_, Y0_-LIMIT_ );       
-            lcd_.DrawLine(X0_, Y0_+LIMIT_ , X0_+N_DATA_, Y0_+LIMIT_ );       
         }
         
     private:
@@ -51,6 +61,7 @@
         const uint32_t LINE_COLOR_;
         const uint32_t BACK_COLOR_;
         static const int LIMIT_ = 32;
+        static const int LIMIT2_ = LIMIT_ + 1;
         
         LCD_DISCO_F746NG& lcd_;
         
@@ -58,15 +69,15 @@
         uint16_t Clip(int16_t xn)
         {
             int16_t x = xn >> R_SHIFT_;
-            if (x >  LIMIT_ ) x =  LIMIT_ ;
-            if (x < -LIMIT_ ) x = -LIMIT_ ;
+            if (x >  LIMIT_ ) x =  LIMIT2_;
+            if (x < -LIMIT_ ) x = -LIMIT2_ ;
             return Y0_ - x;
         }
         
         void Axis()
         {
             lcd_.SetTextColor(BACK_COLOR_);
-            lcd_.FillRect(X0_, Y0_-LIMIT_, N_DATA_, LIMIT_*2);
+            lcd_.FillRect(X0_, Y0_-LIMIT2_, N_DATA_, LIMIT2_*2+1);
 
             lcd_.SetTextColor(AXIS_COLOR_);
             lcd_.DrawLine(X0_-5, Y0_, X0_+N_DATA_+5, Y0_);