不韋 呂 / F746_MySoundMachine

Dependencies:   F746_GUI F746_SAI_IO FrequencyResponseDrawer SD_PlayerSkeleton UIT_FFT_Real

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers WaveformDisplay.hpp Source File

WaveformDisplay.hpp

00001 //-----------------------------------------------------------
00002 //  Class for waveform display
00003 //
00004 //  2017/04/06, Copyright (c) 2016 MIKAMI, Naoki
00005 //-----------------------------------------------------------
00006 
00007 #ifndef F746_WAVEFORM_DISPLAY_HPP
00008 #define F746_WAVEFORM_DISPLAY_HPP
00009 
00010 #include "Array.hpp"
00011 
00012 namespace Mikami
00013 {
00014     class WaveformDisplay
00015     {
00016     public:
00017         WaveformDisplay(LCD_DISCO_F746NG &lcd,
00018                         uint16_t x0, uint16_t y0, int nData,
00019                         uint16_t rShift)
00020             : X0_(x0), Y0_(y0), R_SHIFT_(rShift),
00021               H1_(Y0_+LIMIT_+1), H2_(Y0_-LIMIT_-1),
00022               lcd_(lcd) { Axis(nData); }
00023 
00024         void Execute(const Array<int16_t> &xn)
00025         {
00026             lcd_.SetTextColor(GuiBase::ENUM_BACK);
00027             lcd_.FillRect(X0_, Y0_-LIMIT_-1,
00028                           xn.Length(), (LIMIT_+1)*2+1);
00029             Axis(xn.Length());
00030             lcd_.SetTextColor(LINE_COLOR_);
00031             uint16_t x1 = X0_;
00032             uint16_t y1 = Clip(xn[0]);
00033             for (int n=1; n<xn.Length(); n++)
00034             {
00035                 uint16_t x2 = X0_ + n;
00036                 uint16_t y2 = Clip(xn[n]);
00037                 lcd_.DrawLine(x1, y1, x2, y2);
00038                 if ((y1 == H1_) || (y1 == H2_))
00039                     lcd_.DrawPixel(x1, y1, LCD_COLOR_RED);
00040                 x1 = x2;
00041                 y1 = y2;
00042             }
00043         }
00044 
00045     private:
00046         static const uint16_t LIMIT_ = 32;
00047         static const uint32_t LINE_COLOR_ = LCD_COLOR_CYAN;
00048         const uint16_t X0_, Y0_;
00049         const uint16_t R_SHIFT_;
00050         const uint16_t H1_, H2_;
00051 
00052         LCD_DISCO_F746NG& lcd_;
00053 
00054         // Clipping
00055         uint16_t Clip(int16_t xn)
00056         {
00057             int16_t x = xn >> R_SHIFT_;
00058             if (x >  LIMIT_ ) x =  LIMIT_ + 1;
00059             if (x < -LIMIT_ ) x = -(LIMIT_ + 1) ;
00060             return Y0_ - x;
00061         }
00062 
00063         void Axis(int nData)
00064         {
00065             lcd_.SetTextColor(LCD_COLOR_WHITE);
00066             lcd_.DrawLine(X0_-5, Y0_, X0_+nData+5, Y0_);
00067         }
00068 
00069         // disallow copy constructor and assignment operator
00070         WaveformDisplay(const WaveformDisplay& );
00071         WaveformDisplay& operator=(const WaveformDisplay& );
00072     };
00073 }
00074 #endif  // F746_WAVEFORM_DISPLAY_HPP