![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
CQエレクトロニクス・セミナ「実習・マイコンを動かしながら学ぶディジタル・フィルタ」で使うプログラム.1次IIRフィルタの係数をターミナルから変更できる. http://seminar.cqpub.co.jp/ccm/ES18-0020
Dependencies: mbed Array_Matrix BSP_DISCO_F746NG LCD_DISCO_F746NG TS_DISCO_F746NG
MyFiles/NumericUpDown.cpp@0:47718d3154d9, 2017-10-09 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Mon Oct 09 02:36:11 2017 +0000
- Revision:
- 0:47718d3154d9
1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 0:47718d3154d9 | 1 | //----------------------------------------------------------- |
MikamiUitOpen | 0:47718d3154d9 | 2 | // NumericUpDown class |
MikamiUitOpen | 0:47718d3154d9 | 3 | // 指定された桁を up/down する GUI 部品 |
MikamiUitOpen | 0:47718d3154d9 | 4 | // 6 桁まで可能 |
MikamiUitOpen | 0:47718d3154d9 | 5 | // |
MikamiUitOpen | 0:47718d3154d9 | 6 | // 2017/08/21, Copyright (c) 2017 MIKAMI, Naoki |
MikamiUitOpen | 0:47718d3154d9 | 7 | //----------------------------------------------------------- |
MikamiUitOpen | 0:47718d3154d9 | 8 | |
MikamiUitOpen | 0:47718d3154d9 | 9 | #include "NumericUpDown.hpp" |
MikamiUitOpen | 0:47718d3154d9 | 10 | |
MikamiUitOpen | 0:47718d3154d9 | 11 | namespace Mikami |
MikamiUitOpen | 0:47718d3154d9 | 12 | { |
MikamiUitOpen | 0:47718d3154d9 | 13 | // digit 表示する桁数 |
MikamiUitOpen | 0:47718d3154d9 | 14 | // initVal 最初に表示する数値 |
MikamiUitOpen | 0:47718d3154d9 | 15 | NumericUpDown::NumericUpDown(uint16_t digit, uint16_t x0, uint16_t y0, |
MikamiUitOpen | 0:47718d3154d9 | 16 | uint32_t initVal, uint32_t max, uint32_t min, |
MikamiUitOpen | 0:47718d3154d9 | 17 | string unit, float delay) |
MikamiUitOpen | 0:47718d3154d9 | 18 | : DIGIT_(digit), X0_(x0), Y0_(y0), MAX_(max), MIN_(min), |
MikamiUitOpen | 0:47718d3154d9 | 19 | POW10_(6, (uint32_t []){1, 10, 100, 1000, 10000, 10000}), |
MikamiUitOpen | 0:47718d3154d9 | 20 | numUd_(-1), value_(initVal), |
MikamiUitOpen | 0:47718d3154d9 | 21 | delay_(delay), labels_(digit), lcd_(GuiBase::GetLcd()) |
MikamiUitOpen | 0:47718d3154d9 | 22 | { |
MikamiUitOpen | 0:47718d3154d9 | 23 | MBED_ASSERT(DIGIT_ <= 6); // 6 桁まで |
MikamiUitOpen | 0:47718d3154d9 | 24 | sprintf(fmt_, "%%""0%1dd", DIGIT_); |
MikamiUitOpen | 0:47718d3154d9 | 25 | for (int n=0; n<DIGIT_; n++) |
MikamiUitOpen | 0:47718d3154d9 | 26 | labels_[n] = new Label( |
MikamiUitOpen | 0:47718d3154d9 | 27 | X0_+10+n*XW_, Y0_-46, "", Label::LEFT, Font16); |
MikamiUitOpen | 0:47718d3154d9 | 28 | Set(initVal); // 初期値として表示 |
MikamiUitOpen | 0:47718d3154d9 | 29 | Label lbUnit(X0_+0+DIGIT_*XW_, Y0_-46, unit, Label::LEFT, Font16); |
MikamiUitOpen | 0:47718d3154d9 | 30 | Array<string> nonString(DIGIT_*2, ""); |
MikamiUitOpen | 0:47718d3154d9 | 31 | ud_ = new ButtonGroup(X0_, Y0_-81, 30, 30, DIGIT_*2, nonString, |
MikamiUitOpen | 0:47718d3154d9 | 32 | XW_-30, 22, DIGIT_); |
MikamiUitOpen | 0:47718d3154d9 | 33 | for (int n=0; n<DIGIT_*2; n++) UpDownSymbol(X0_, Y0_, n); |
MikamiUitOpen | 0:47718d3154d9 | 34 | } |
MikamiUitOpen | 0:47718d3154d9 | 35 | |
MikamiUitOpen | 0:47718d3154d9 | 36 | // Up, Down をタッチした場合は対応する数値を +1 または -1 する |
MikamiUitOpen | 0:47718d3154d9 | 37 | bool NumericUpDown::Touched() |
MikamiUitOpen | 0:47718d3154d9 | 38 | { |
MikamiUitOpen | 0:47718d3154d9 | 39 | if (!delay_.IsEnabled()) return false; |
MikamiUitOpen | 0:47718d3154d9 | 40 | int num; |
MikamiUitOpen | 0:47718d3154d9 | 41 | if (!ud_->GetTouchedNumber(num)) return false; |
MikamiUitOpen | 0:47718d3154d9 | 42 | |
MikamiUitOpen | 0:47718d3154d9 | 43 | // タッチ後一定の時間が経過してから,再びタッチの検出を有効にするため |
MikamiUitOpen | 0:47718d3154d9 | 44 | delay_.Disable(); |
MikamiUitOpen | 0:47718d3154d9 | 45 | |
MikamiUitOpen | 0:47718d3154d9 | 46 | // 三角を再描画 |
MikamiUitOpen | 0:47718d3154d9 | 47 | UpDownSymbol(X0_, Y0_, num); |
MikamiUitOpen | 0:47718d3154d9 | 48 | if (numUd_ != -1) UpDownSymbol(X0_, Y0_, numUd_); |
MikamiUitOpen | 0:47718d3154d9 | 49 | numUd_ = num; |
MikamiUitOpen | 0:47718d3154d9 | 50 | |
MikamiUitOpen | 0:47718d3154d9 | 51 | int index = num % DIGIT_; |
MikamiUitOpen | 0:47718d3154d9 | 52 | if (num < DIGIT_) value_ += POW10_[DIGIT_-index-1]; |
MikamiUitOpen | 0:47718d3154d9 | 53 | else |
MikamiUitOpen | 0:47718d3154d9 | 54 | if (index != 0) |
MikamiUitOpen | 0:47718d3154d9 | 55 | value_ -= POW10_[DIGIT_-index-1]; |
MikamiUitOpen | 0:47718d3154d9 | 56 | else |
MikamiUitOpen | 0:47718d3154d9 | 57 | if (value_ >= POW10_[DIGIT_-1]) |
MikamiUitOpen | 0:47718d3154d9 | 58 | value_ -= POW10_[DIGIT_-index-1]; |
MikamiUitOpen | 0:47718d3154d9 | 59 | Set(value_); |
MikamiUitOpen | 0:47718d3154d9 | 60 | return true; |
MikamiUitOpen | 0:47718d3154d9 | 61 | } |
MikamiUitOpen | 0:47718d3154d9 | 62 | |
MikamiUitOpen | 0:47718d3154d9 | 63 | // 引数の数値を Label に表示する |
MikamiUitOpen | 0:47718d3154d9 | 64 | void NumericUpDown::Set(uint32_t frq) |
MikamiUitOpen | 0:47718d3154d9 | 65 | { |
MikamiUitOpen | 0:47718d3154d9 | 66 | if (frq > MAX_) frq = MAX_; |
MikamiUitOpen | 0:47718d3154d9 | 67 | if (frq < MIN_) frq = MIN_; |
MikamiUitOpen | 0:47718d3154d9 | 68 | char frqCh[7]; |
MikamiUitOpen | 0:47718d3154d9 | 69 | sprintf(frqCh, fmt_, frq); |
MikamiUitOpen | 0:47718d3154d9 | 70 | |
MikamiUitOpen | 0:47718d3154d9 | 71 | for (int n=0; n<DIGIT_; n++) |
MikamiUitOpen | 0:47718d3154d9 | 72 | labels_[n]->Draw((string)""+frqCh[n]); |
MikamiUitOpen | 0:47718d3154d9 | 73 | value_ = frq; |
MikamiUitOpen | 0:47718d3154d9 | 74 | } |
MikamiUitOpen | 0:47718d3154d9 | 75 | |
MikamiUitOpen | 0:47718d3154d9 | 76 | // 数値の up, down に使う三角形の描画 |
MikamiUitOpen | 0:47718d3154d9 | 77 | void NumericUpDown::UpDownSymbol(uint16_t x, uint16_t y, int k) |
MikamiUitOpen | 0:47718d3154d9 | 78 | { |
MikamiUitOpen | 0:47718d3154d9 | 79 | lcd_.SetTextColor(GuiBase::ENUM_TEXT); |
MikamiUitOpen | 0:47718d3154d9 | 80 | Point *pt = k < DIGIT_ ? ptU_ : ptD_; |
MikamiUitOpen | 0:47718d3154d9 | 81 | int16_t y0 = k < DIGIT_ ? y - 25 : y + 31; |
MikamiUitOpen | 0:47718d3154d9 | 82 | |
MikamiUitOpen | 0:47718d3154d9 | 83 | Point tri[3]; |
MikamiUitOpen | 0:47718d3154d9 | 84 | for (int n=0; n<3; n++) |
MikamiUitOpen | 0:47718d3154d9 | 85 | { |
MikamiUitOpen | 0:47718d3154d9 | 86 | tri[n].X = pt[n].X + x + XW_*(k % DIGIT_) + 15; |
MikamiUitOpen | 0:47718d3154d9 | 87 | tri[n].Y = pt[n].Y + y0 - 46; |
MikamiUitOpen | 0:47718d3154d9 | 88 | } |
MikamiUitOpen | 0:47718d3154d9 | 89 | lcd_.FillPolygon(tri, 3); |
MikamiUitOpen | 0:47718d3154d9 | 90 | } |
MikamiUitOpen | 0:47718d3154d9 | 91 | |
MikamiUitOpen | 0:47718d3154d9 | 92 | Point NumericUpDown::ptU_[] = {{0, 0}, {-SIZE_, SIZE_}, {SIZE_, SIZE_}}; |
MikamiUitOpen | 0:47718d3154d9 | 93 | Point NumericUpDown::ptD_[] = {{0, SIZE_}, {SIZE_, 0}, {-SIZE_, 0}}; |
MikamiUitOpen | 0:47718d3154d9 | 94 | } |