オシロスコープ. このプログラムの説明は,CQ出版社「トランジスタ技術」の2021年10月号から開始された連載記事「STM32マイコンではじめるPC計測」の中にあります.このプログラムといっしょに使うPC側のプログラムについても同誌を参照してください.
Dependencies: Array_Matrix mbed SerialTxRxIntr DSP_ADDA_Dual
Diff: InputBuffer.hpp
- Revision:
- 0:4440ad009afe
diff -r 000000000000 -r 4440ad009afe InputBuffer.hpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/InputBuffer.hpp Thu Sep 09 08:47:03 2021 +0000 @@ -0,0 +1,58 @@ +//-------------------------------------------------------- +// バッファの template クラス +// +// 2021/07/19, Copyright (c) 2021 MIKAMI, Naoki +//------------------------------------------------------- + +#ifndef INPUT_BUFFER_HPP +#define INPUT_BUFFER_HPP + +#include "Array.hpp" +using namespace Mikami; + +class InputBuffer +{ +public: + // コンストラクタ + explicit InputBuffer(int size, float initValue = 0) + : N_(size), buf_(2*size, initValue), index_(0), full_(false) {} + + // データを格納 + void Store(float data1, float data2) + { + buf_[index_] = data1; + buf_[N_+index_++] = data2; + } + + // バッファからデータの取り出し + Array<float> Get() const { return buf_; } + + // バッファが満杯で次の準備を行う + bool IsFullNext() + { + if (index_ < N_) return false; + + index_ = 0; + full_ = true; + return true; + } + + // バッファが満杯で,true を返す + bool IsFull() + { + bool temp = full_; + if (full_) full_ = false; + return temp; + } + +private: + const int N_; // バッファのサイズに対応する値 + Array<float> buf_; // バッファ + int index_; // 入力データのカウンタ + bool full_; // 満杯の場合 true + + // コピー・コンストラクタおよび代入演算子の禁止のため + InputBuffer(const InputBuffer&); + InputBuffer& operator=(const InputBuffer&); +}; +#endif // INPUT_BUFFER_HPP \ No newline at end of file