![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
オシロスコープ
Dependencies: Array_Matrix mbed SerialTxRxIntr DSP_ADDA_Dual
InputBuffer.hpp@0:595c23d6949a, 2020-10-17 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Sat Oct 17 10:14:31 2020 +0000
- Revision:
- 0:595c23d6949a
1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 0:595c23d6949a | 1 | //-------------------------------------------------------- |
MikamiUitOpen | 0:595c23d6949a | 2 | // バッファの template クラス |
MikamiUitOpen | 0:595c23d6949a | 3 | // バッファに2次元配列(Matrix クラス)を使用 |
MikamiUitOpen | 0:595c23d6949a | 4 | // |
MikamiUitOpen | 0:595c23d6949a | 5 | // 2020/10/17, Copyright (c) 2020 MIKAMI, Naoki |
MikamiUitOpen | 0:595c23d6949a | 6 | //-------------------------------------------------------- |
MikamiUitOpen | 0:595c23d6949a | 7 | |
MikamiUitOpen | 0:595c23d6949a | 8 | #ifndef INPUT_BUFFER_HPP |
MikamiUitOpen | 0:595c23d6949a | 9 | #define INPUT_BUFFER_HPP |
MikamiUitOpen | 0:595c23d6949a | 10 | |
MikamiUitOpen | 0:595c23d6949a | 11 | #include "Matrix.hpp" |
MikamiUitOpen | 0:595c23d6949a | 12 | using namespace Mikami; |
MikamiUitOpen | 0:595c23d6949a | 13 | |
MikamiUitOpen | 0:595c23d6949a | 14 | template<class T> class InputBuffer |
MikamiUitOpen | 0:595c23d6949a | 15 | { |
MikamiUitOpen | 0:595c23d6949a | 16 | public: |
MikamiUitOpen | 0:595c23d6949a | 17 | // コンストラクタ |
MikamiUitOpen | 0:595c23d6949a | 18 | explicit InputBuffer(int size, T initialValue = 0) |
MikamiUitOpen | 0:595c23d6949a | 19 | : N_(size), buf_(2, size, initialValue), index_(0), full_(false) {} |
MikamiUitOpen | 0:595c23d6949a | 20 | |
MikamiUitOpen | 0:595c23d6949a | 21 | // データを格納 |
MikamiUitOpen | 0:595c23d6949a | 22 | void Store(T data1, T data2) |
MikamiUitOpen | 0:595c23d6949a | 23 | { |
MikamiUitOpen | 0:595c23d6949a | 24 | buf_[0][index_] = data1; |
MikamiUitOpen | 0:595c23d6949a | 25 | buf_[1][index_++] = data2; |
MikamiUitOpen | 0:595c23d6949a | 26 | } |
MikamiUitOpen | 0:595c23d6949a | 27 | |
MikamiUitOpen | 0:595c23d6949a | 28 | // 出力バッファからデータの取り出し |
MikamiUitOpen | 0:595c23d6949a | 29 | T Get(int ch, int n) const { return buf_[ch][n]; } |
MikamiUitOpen | 0:595c23d6949a | 30 | |
MikamiUitOpen | 0:595c23d6949a | 31 | // バッファが満杯で次の準備を行う |
MikamiUitOpen | 0:595c23d6949a | 32 | bool IsFullNext() |
MikamiUitOpen | 0:595c23d6949a | 33 | { |
MikamiUitOpen | 0:595c23d6949a | 34 | if (index_ < N_) return false; |
MikamiUitOpen | 0:595c23d6949a | 35 | |
MikamiUitOpen | 0:595c23d6949a | 36 | index_ = 0; |
MikamiUitOpen | 0:595c23d6949a | 37 | full_ = true; |
MikamiUitOpen | 0:595c23d6949a | 38 | return true; |
MikamiUitOpen | 0:595c23d6949a | 39 | } |
MikamiUitOpen | 0:595c23d6949a | 40 | |
MikamiUitOpen | 0:595c23d6949a | 41 | // バッファが満杯で,true を返す |
MikamiUitOpen | 0:595c23d6949a | 42 | bool IsFull() |
MikamiUitOpen | 0:595c23d6949a | 43 | { |
MikamiUitOpen | 0:595c23d6949a | 44 | bool temp = full_; |
MikamiUitOpen | 0:595c23d6949a | 45 | if (full_) full_ = false; |
MikamiUitOpen | 0:595c23d6949a | 46 | return temp; |
MikamiUitOpen | 0:595c23d6949a | 47 | } |
MikamiUitOpen | 0:595c23d6949a | 48 | |
MikamiUitOpen | 0:595c23d6949a | 49 | private: |
MikamiUitOpen | 0:595c23d6949a | 50 | const int N_; // バッファのサイズ |
MikamiUitOpen | 0:595c23d6949a | 51 | Matrix<T> buf_; // バッファ |
MikamiUitOpen | 0:595c23d6949a | 52 | int index_; // 入力データのカウンタ |
MikamiUitOpen | 0:595c23d6949a | 53 | bool full_; // 満杯の場合 true |
MikamiUitOpen | 0:595c23d6949a | 54 | |
MikamiUitOpen | 0:595c23d6949a | 55 | // コピー・コンストラクタおよび代入演算子の禁止のため |
MikamiUitOpen | 0:595c23d6949a | 56 | InputBuffer(const InputBuffer&); |
MikamiUitOpen | 0:595c23d6949a | 57 | InputBuffer& operator=(const InputBuffer&); |
MikamiUitOpen | 0:595c23d6949a | 58 | }; |
MikamiUitOpen | 0:595c23d6949a | 59 | #endif // INPUT_BUFFER_HPP |