![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
CQエレクトロニクス・セミナ「実習・マイコンを動かしながら学ぶディジタル・フィルタ」で使うプログラム.雛形として使う. http://seminar.cqpub.co.jp/ccm/ES18-0020
Dependencies: F746_GUI F746_SAI_IO mbed
MyFiles/WaveformDisplay.cpp@0:b6d17af0f47a, 2017-09-29 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Fri Sep 29 12:50:44 2017 +0000
- Revision:
- 0:b6d17af0f47a
- Child:
- 3:05c8d0ee9c37
1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 0:b6d17af0f47a | 1 | //----------------------------------------------------------- |
MikamiUitOpen | 0:b6d17af0f47a | 2 | // Class for waveform display |
MikamiUitOpen | 0:b6d17af0f47a | 3 | // |
MikamiUitOpen | 0:b6d17af0f47a | 4 | // 2017/07/24, Copyright (c) 2017 MIKAMI, Naoki |
MikamiUitOpen | 0:b6d17af0f47a | 5 | //----------------------------------------------------------- |
MikamiUitOpen | 0:b6d17af0f47a | 6 | |
MikamiUitOpen | 0:b6d17af0f47a | 7 | #include "WaveformDisplay.hpp" |
MikamiUitOpen | 0:b6d17af0f47a | 8 | |
MikamiUitOpen | 0:b6d17af0f47a | 9 | namespace Mikami |
MikamiUitOpen | 0:b6d17af0f47a | 10 | { |
MikamiUitOpen | 0:b6d17af0f47a | 11 | void WaveformDisplay::Execute(int start, int factor) |
MikamiUitOpen | 0:b6d17af0f47a | 12 | { |
MikamiUitOpen | 0:b6d17af0f47a | 13 | Axis(); |
MikamiUitOpen | 0:b6d17af0f47a | 14 | dt_ = factor; |
MikamiUitOpen | 0:b6d17af0f47a | 15 | Draw(xn_, start, LINE_COLOR1_); |
MikamiUitOpen | 0:b6d17af0f47a | 16 | Draw(yn_, start, LINE_COLOR2_); |
MikamiUitOpen | 0:b6d17af0f47a | 17 | lcd_.SetTextColor(BACK_COLOR_); |
MikamiUitOpen | 0:b6d17af0f47a | 18 | } |
MikamiUitOpen | 0:b6d17af0f47a | 19 | |
MikamiUitOpen | 0:b6d17af0f47a | 20 | // Clipping |
MikamiUitOpen | 0:b6d17af0f47a | 21 | uint16_t WaveformDisplay::Clip(int16_t xn) |
MikamiUitOpen | 0:b6d17af0f47a | 22 | { |
MikamiUitOpen | 0:b6d17af0f47a | 23 | int16_t x = xn >> R_SHIFT_; |
MikamiUitOpen | 0:b6d17af0f47a | 24 | if (x > LIMIT_ ) x = LIMIT2_; |
MikamiUitOpen | 0:b6d17af0f47a | 25 | if (x < -LIMIT_ ) x = -LIMIT2_ ; |
MikamiUitOpen | 0:b6d17af0f47a | 26 | return Y0_ - x; |
MikamiUitOpen | 0:b6d17af0f47a | 27 | } |
MikamiUitOpen | 0:b6d17af0f47a | 28 | |
MikamiUitOpen | 0:b6d17af0f47a | 29 | void WaveformDisplay::Draw(const Array<int16_t>& xn, int start, uint32_t color) |
MikamiUitOpen | 0:b6d17af0f47a | 30 | { |
MikamiUitOpen | 0:b6d17af0f47a | 31 | lcd_.SetTextColor(color); |
MikamiUitOpen | 0:b6d17af0f47a | 32 | uint16_t x1 = X0_; |
MikamiUitOpen | 0:b6d17af0f47a | 33 | uint16_t y1 = Clip(xn[start]); |
MikamiUitOpen | 0:b6d17af0f47a | 34 | // for (int n=1; n<N_DATA_; n++) |
MikamiUitOpen | 0:b6d17af0f47a | 35 | for (int n=1; n<N_DATA_/dt_; n++) |
MikamiUitOpen | 0:b6d17af0f47a | 36 | { |
MikamiUitOpen | 0:b6d17af0f47a | 37 | // uint16_t x2 = X0_ + n; |
MikamiUitOpen | 0:b6d17af0f47a | 38 | uint16_t x2 = X0_ + n*dt_; |
MikamiUitOpen | 0:b6d17af0f47a | 39 | uint16_t y2 = Clip(xn[start+n]); |
MikamiUitOpen | 0:b6d17af0f47a | 40 | lcd_.DrawLine(x1, y1, x2, y2); |
MikamiUitOpen | 0:b6d17af0f47a | 41 | |
MikamiUitOpen | 0:b6d17af0f47a | 42 | x1 = x2; |
MikamiUitOpen | 0:b6d17af0f47a | 43 | y1 = y2; |
MikamiUitOpen | 0:b6d17af0f47a | 44 | } |
MikamiUitOpen | 0:b6d17af0f47a | 45 | } |
MikamiUitOpen | 0:b6d17af0f47a | 46 | |
MikamiUitOpen | 0:b6d17af0f47a | 47 | void WaveformDisplay::Axis() |
MikamiUitOpen | 0:b6d17af0f47a | 48 | { |
MikamiUitOpen | 0:b6d17af0f47a | 49 | lcd_.SetTextColor(BACK_COLOR_); |
MikamiUitOpen | 0:b6d17af0f47a | 50 | lcd_.FillRect(X0_, Y0_-LIMIT2_, N_DATA_, LIMIT2_*2+1); |
MikamiUitOpen | 0:b6d17af0f47a | 51 | |
MikamiUitOpen | 0:b6d17af0f47a | 52 | lcd_.SetTextColor(AXIS_COLOR_); |
MikamiUitOpen | 0:b6d17af0f47a | 53 | lcd_.DrawLine(X0_-5, Y0_, X0_+N_DATA_+5, Y0_); |
MikamiUitOpen | 0:b6d17af0f47a | 54 | } |
MikamiUitOpen | 0:b6d17af0f47a | 55 | } |