CQエレクトロニクス・セミナ「実習・マイコンを動かしながら学ぶディジタル・フィルタ」で使うプログラムを,入力として STM32F746 の内蔵 ADC を使うように変更したもの. http://seminar.cqpub.co.jp/ccm/ES18-0020

Dependencies:   mbed Array_Matrix BSP_DISCO_F746NG LCD_DISCO_F746NG TS_DISCO_F746NG

MyFiles/WaveformDisplay.cpp

Committer:
MikamiUitOpen
Date:
2018-03-12
Revision:
2:dd48e1e59daa
Parent:
0:ab7a35d87173

File content as of revision 2:dd48e1e59daa:

//-----------------------------------------------------------
//  Class for waveform display
//
//  2017/07/24, Copyright (c) 2017 MIKAMI, Naoki
//-----------------------------------------------------------

#include "WaveformDisplay.hpp"

namespace Mikami
{
    void WaveformDisplay::Execute(int start, int factor)
    {
        Axis();
        dt_ = factor;
        Draw(xn_, start, LINE_COLOR1_);
        Draw(yn_, start, LINE_COLOR2_);
        lcd_.SetTextColor(BACK_COLOR_);
    }
        
    // Clipping
    uint16_t WaveformDisplay::Clip(int16_t xn)
    {
        int16_t x = xn >> R_SHIFT_;
        if (x >  LIMIT_ ) x =  LIMIT2_;
        if (x < -LIMIT_ ) x = -LIMIT2_ ;
        return Y0_ - x;
    }
    
    void WaveformDisplay::Draw(const Array<int16_t>& xn, int start, uint32_t color)
    {
        lcd_.SetTextColor(color);
        uint16_t x1 = X0_;
        uint16_t y1 = Clip(xn[start]);
//        for (int n=1; n<N_DATA_; n++)
        for (int n=1; n<N_DATA_/dt_; n++)
        {
//            uint16_t x2 = X0_ + n;
            uint16_t x2 = X0_ + n*dt_;
            uint16_t y2 = Clip(xn[start+n]);
            lcd_.DrawLine(x1, y1, x2, y2);

            x1 = x2;
            y1 = y2;
        }
    }

    void WaveformDisplay::Axis()
    {
        lcd_.SetTextColor(BACK_COLOR_);
        lcd_.FillRect(X0_, Y0_-LIMIT2_, N_DATA_, LIMIT2_*2+1);

        lcd_.SetTextColor(AXIS_COLOR_);
        lcd_.DrawLine(X0_-5, Y0_, X0_+N_DATA_+5, Y0_);
    }        
}