CQエレクトロニクス・セミナ「実習・マイコンを動かしながら学ぶディジタル・フィルタ」で使うプログラムを,入力として STM32F746 の内蔵 ADC を使うように変更したもの. http://seminar.cqpub.co.jp/ccm/ES18-0020

Dependencies:   mbed Array_Matrix BSP_DISCO_F746NG LCD_DISCO_F746NG TS_DISCO_F746NG

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Zoom.hpp Source File

Zoom.hpp

00001 //-----------------------------------------------------------
00002 //  時間軸の Zoom ボタン
00003 //
00004 //  2017/08/21, Copyright (c) 2017 MIKAMI, Naoki
00005 //-----------------------------------------------------------
00006 
00007 #ifndef ZOOM_BUTTON_HPP
00008 #define ZOOM_BUTTON_HPP
00009 
00010 #include "F746_GUI.hpp"
00011 #include "DelayedEnabler.hpp"
00012 
00013 namespace Mikami
00014 {
00015     class ZoomButton
00016     {
00017     public:
00018         // delay: ZoomButton がタッチされた後に再び有効になるまでの時間(単位:秒)
00019         ZoomButton(uint16_t x0, uint16_t y0, uint16_t w0, uint16_t h0,
00020                    uint32_t max, uint32_t min = 1, float delay = 0.2f)
00021             : X0_(x0), Y0_(y0), W0_(w0), H0_(h0), 
00022               MAX_(max), MIN_(min), delay_(delay), factor_(1)
00023         {
00024             zoom_ = new ButtonGroup(x0, y0, w0, h0, 2, (string[]){"-", "+"},
00025                                     5, 0, 2);
00026             zoom_->Inactivate(0);   // ズームアウトボタンは無効にする
00027         }
00028 
00029         // タッチした場合は factor を *2 または /2 する
00030         bool Touched(int &factor)
00031         {
00032             if (!delay_.IsEnabled()) return false;
00033             int num;
00034             if (!zoom_->GetTouchedNumber(num)) return false;
00035 
00036             // タッチ後一定の時間が経過してから,再びタッチの検出を有効にするため
00037             delay_.Disable();
00038 
00039             factor_ = (num == 1) ? factor_*2 : factor_/2;
00040             if (factor_ > MAX_) factor_ = MAX_;
00041             if (factor_ < MIN_) factor_ = MIN_;
00042 
00043             zoom_->ActivateAll();
00044             if (factor_ == MAX_) zoom_->Inactivate(num);
00045             if (factor_ == MIN_) zoom_->Inactivate(num);
00046 
00047             factor = factor_;
00048 
00049             return true;
00050         }
00051 
00052     private:
00053         const int X0_, Y0_, W0_, H0_;
00054         const uint32_t MAX_;    // 最大値
00055         const uint32_t MIN_;    // 最小値
00056 
00057         ButtonGroup *zoom_;
00058         DelayedEnabler delay_;
00059         int factor_;
00060     };
00061 }
00062 #endif  // ZOOM_BUTTON_HPP
00063