![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Waveform display for input signal using SAI from MEMS microphone or line. MEMS マイクまたはラインから SAI により入力した信号の波形を表示する.
Dependencies: BSP_DISCO_F746NG F746_GUI F746_SAI_IO LCD_DISCO_F746NG TS_DISCO_F746NG mbed
MyClasses/WaveformDisplay.cpp@5:92bb7f2bf714, 2018-03-12 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Mon Mar 12 05:27:19 2018 +0000
- Revision:
- 5:92bb7f2bf714
- Parent:
- 4:bf927b50098b
6
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 0:e2c6c8630aab | 1 | //----------------------------------------------------------- |
MikamiUitOpen | 0:e2c6c8630aab | 2 | // Class for waveform display |
MikamiUitOpen | 0:e2c6c8630aab | 3 | // |
MikamiUitOpen | 4:bf927b50098b | 4 | // 2017/03/17, Copyright (c) 2017 MIKAMI, Naoki |
MikamiUitOpen | 0:e2c6c8630aab | 5 | //----------------------------------------------------------- |
MikamiUitOpen | 0:e2c6c8630aab | 6 | |
MikamiUitOpen | 0:e2c6c8630aab | 7 | #include "WaveformDisplay.hpp" |
MikamiUitOpen | 0:e2c6c8630aab | 8 | |
MikamiUitOpen | 0:e2c6c8630aab | 9 | namespace Mikami |
MikamiUitOpen | 0:e2c6c8630aab | 10 | { |
MikamiUitOpen | 0:e2c6c8630aab | 11 | void WaveformDisplay::Execute() |
MikamiUitOpen | 0:e2c6c8630aab | 12 | { |
MikamiUitOpen | 2:afff5ec35233 | 13 | uint16_t lim1 = Y0_ + LIMIT2_; |
MikamiUitOpen | 2:afff5ec35233 | 14 | uint16_t lim2 = Y0_ - LIMIT2_; |
MikamiUitOpen | 0:e2c6c8630aab | 15 | Axis(); |
MikamiUitOpen | 4:bf927b50098b | 16 | lcd_.SetTextColor(LINE_COLOR_); |
MikamiUitOpen | 0:e2c6c8630aab | 17 | uint16_t x1 = X0_; |
MikamiUitOpen | 0:e2c6c8630aab | 18 | uint16_t y1 = Clip(xn_[0]); |
MikamiUitOpen | 0:e2c6c8630aab | 19 | for (int n=1; n<N_DATA_; n++) |
MikamiUitOpen | 0:e2c6c8630aab | 20 | { |
MikamiUitOpen | 0:e2c6c8630aab | 21 | uint16_t x2 = X0_ + n; |
MikamiUitOpen | 0:e2c6c8630aab | 22 | uint16_t y2 = Clip(xn_[n]); |
MikamiUitOpen | 2:afff5ec35233 | 23 | if ( ((y2 == lim1) && (y1 == lim1)) || |
MikamiUitOpen | 2:afff5ec35233 | 24 | ((y2 == lim2) && (y1 == lim2)) ) |
MikamiUitOpen | 0:e2c6c8630aab | 25 | { // Out of displaying boundaries |
MikamiUitOpen | 4:bf927b50098b | 26 | lcd_.SetTextColor(LCD_COLOR_RED); |
MikamiUitOpen | 4:bf927b50098b | 27 | lcd_.DrawHLine(x1, y1, 1); |
MikamiUitOpen | 4:bf927b50098b | 28 | lcd_.SetTextColor(LINE_COLOR_); |
MikamiUitOpen | 0:e2c6c8630aab | 29 | } |
MikamiUitOpen | 0:e2c6c8630aab | 30 | else |
MikamiUitOpen | 4:bf927b50098b | 31 | lcd_.DrawLine(x1, y1, x2, y2); |
MikamiUitOpen | 2:afff5ec35233 | 32 | if ((y1 == lim1) || (y1 == lim2)) |
MikamiUitOpen | 4:bf927b50098b | 33 | lcd_.DrawPixel(x1, y1, LCD_COLOR_RED); |
MikamiUitOpen | 0:e2c6c8630aab | 34 | x1 = x2; |
MikamiUitOpen | 0:e2c6c8630aab | 35 | y1 = y2; |
MikamiUitOpen | 0:e2c6c8630aab | 36 | } |
MikamiUitOpen | 4:bf927b50098b | 37 | lcd_.SetTextColor(BACK_COLOR_); |
MikamiUitOpen | 0:e2c6c8630aab | 38 | } |
MikamiUitOpen | 0:e2c6c8630aab | 39 | |
MikamiUitOpen | 0:e2c6c8630aab | 40 | // Clipping |
MikamiUitOpen | 0:e2c6c8630aab | 41 | uint16_t WaveformDisplay::Clip(int16_t xn) |
MikamiUitOpen | 0:e2c6c8630aab | 42 | { |
MikamiUitOpen | 0:e2c6c8630aab | 43 | int16_t x = xn >> R_SHIFT_; |
MikamiUitOpen | 0:e2c6c8630aab | 44 | if (x > LIMIT_ ) x = LIMIT2_; |
MikamiUitOpen | 0:e2c6c8630aab | 45 | if (x < -LIMIT_ ) x = -LIMIT2_ ; |
MikamiUitOpen | 0:e2c6c8630aab | 46 | return Y0_ - x; |
MikamiUitOpen | 0:e2c6c8630aab | 47 | } |
MikamiUitOpen | 0:e2c6c8630aab | 48 | |
MikamiUitOpen | 0:e2c6c8630aab | 49 | void WaveformDisplay::Axis() |
MikamiUitOpen | 0:e2c6c8630aab | 50 | { |
MikamiUitOpen | 4:bf927b50098b | 51 | lcd_.SetTextColor(BACK_COLOR_); |
MikamiUitOpen | 4:bf927b50098b | 52 | lcd_.FillRect(X0_, Y0_-LIMIT2_, N_DATA_, LIMIT2_*2+1); |
MikamiUitOpen | 0:e2c6c8630aab | 53 | |
MikamiUitOpen | 4:bf927b50098b | 54 | lcd_.SetTextColor(AXIS_COLOR_); |
MikamiUitOpen | 4:bf927b50098b | 55 | lcd_.DrawLine(X0_-5, Y0_, X0_+N_DATA_+5, Y0_); |
MikamiUitOpen | 0:e2c6c8630aab | 56 | } |
MikamiUitOpen | 0:e2c6c8630aab | 57 | } |