GUI parts for DISCO-F746NG. GuiBase, Button, ButtonGroup, ResetButton, Label, BlinkLabel, NumericLabel, SeekBar, SeekbarGroup, NumericUpDown

Dependencies:   Array_Matrix BSP_DISCO_F746NG LCD_DISCO_F746NG TS_DISCO_F746NG

Dependents:   F746_AudioOutQSPI F746_AudioPlayerSD DISCO-F746NG_test001 F746_SD_WavPlayer ... more

Files at this revision

API Documentation at this revision

Comitter:
MikamiUitOpen
Date:
Mon Mar 12 04:22:48 2018 +0000
Parent:
32:e6648167e8d3
Commit message:
34; Added: NumericUpDown

Changed in this revision

BSP_DISCO_F746NG.lib Show annotated file Show diff for this revision Revisions of this file
DelayedEnabler.hpp Show annotated file Show diff for this revision Revisions of this file
F746_GUI.hpp Show annotated file Show diff for this revision Revisions of this file
GuiBase.hpp Show annotated file Show diff for this revision Revisions of this file
NumericUpDown.cpp Show annotated file Show diff for this revision Revisions of this file
NumericUpDown.hpp Show annotated file Show diff for this revision Revisions of this file
ResetButton.hpp Show annotated file Show diff for this revision Revisions of this file
diff -r e6648167e8d3 -r 50b8f7654c36 BSP_DISCO_F746NG.lib
--- a/BSP_DISCO_F746NG.lib	Sun Apr 02 06:59:09 2017 +0000
+++ b/BSP_DISCO_F746NG.lib	Mon Mar 12 04:22:48 2018 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/teams/ST/code/BSP_DISCO_F746NG/#5a395e126678
+http://mbed.org/teams/ST/code/BSP_DISCO_F746NG/#df2ea349c37a
diff -r e6648167e8d3 -r 50b8f7654c36 DelayedEnabler.hpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DelayedEnabler.hpp	Mon Mar 12 04:22:48 2018 +0000
@@ -0,0 +1,46 @@
+//-----------------------------------------------------------
+//  ある機能を一定の時間が経過するまでは無効にし,その後有効に
+//  するためのクラス
+//
+//  2018/03/12, Copyright (c) 2018 MIKAMI, Naoki
+//-----------------------------------------------------------
+
+#ifndef DELAYED_ENABLER_HPP
+#define DELAYED_ENABLER_HPP
+
+#include "mbed.h"
+
+namespace Mikami
+{
+    class DelayedEnabler
+    {
+    public:
+        DelayedEnabler(float delayTime = 0.3f)
+            : DELAY_TIME_(delayTime), enable_(true) {}
+
+        // このメンバ関数の実行直後から指定された時間,IsEnabled() は false を
+        // 返し,その後 InEnabled() は true を返す
+        void Disable()
+        {
+            enable_ = false;
+            Enabler_.attach(callback(this, &DelayedEnabler::TimeoutIsr),
+                            DELAY_TIME_);
+        }
+
+        bool IsEnabled() { return enable_; }
+
+    private:
+        const float DELAY_TIME_;    // 無効になっている時間
+
+        __IO bool enable_;
+        Timeout Enabler_;
+
+        // 有効にする(Timeout 割り込みに対応する ISR)
+        void TimeoutIsr() { enable_ = true; }
+
+        // disallow copy constructor and assignment operator
+        DelayedEnabler(const DelayedEnabler&);
+        DelayedEnabler& operator=(const DelayedEnabler&);      
+    };
+}
+#endif  // DELAYED_ENABLER_HPP
diff -r e6648167e8d3 -r 50b8f7654c36 F746_GUI.hpp
--- a/F746_GUI.hpp	Sun Apr 02 06:59:09 2017 +0000
+++ b/F746_GUI.hpp	Mon Mar 12 04:22:48 2018 +0000
@@ -3,7 +3,7 @@
 //  using 宣言をまとめたもの
 //  Include statements for F746-DISCO GUI and using directive
 //
-//  2016/08/15, Copyright (c) 2016 MIKAMI, Naoki
+//  2018/03/12, Copyright (c) 2018 MIKAMI, Naoki
 //--------------------------------------------------------------
 
 #include "mbed.h"
@@ -16,5 +16,6 @@
 #include "NumericLabel.hpp"
 #include "ResetButton.hpp"
 #include "SeekbarGroup.hpp"
+#include "NumericUpDown.hpp"
 
 using namespace Mikami;
diff -r e6648167e8d3 -r 50b8f7654c36 GuiBase.hpp
--- a/GuiBase.hpp	Sun Apr 02 06:59:09 2017 +0000
+++ b/GuiBase.hpp	Mon Mar 12 04:22:48 2018 +0000
@@ -1,7 +1,13 @@
 //-----------------------------------------------------------
 //  GuiBase class (abstract base class) ---- Header
+//
+//      <インポートしたライブラリのリビジョン>
+//          Array_Matrix        2
+//          BSP_DISCO_F746NG    9
+//          LCD_DISCO_F746NG    0
+//          TS_DISCO_F746NG     0
 //      
-//  2017/03/17, Copyright (c) 2017 MIKAMI, Naoki
+//  2018/03/12, Copyright (c) 2018 MIKAMI, Naoki
 //-----------------------------------------------------------
 
 #ifndef F746_GUI_BASE_HPP
@@ -24,6 +30,10 @@
         static bool PanelTouched();
         // Get touch panel state
         static TS_StateTypeDef GetTsState() { return state_; }
+        
+        // Clear the whole LCD
+        static void Clear(uint32_t backColor = ENUM_BACK)
+        { lcd_.Clear(backColor); }
 
         enum { ENUM_TEXT = 0xFFFFFFFF, ENUM_BACK = 0xFF003538,
                ENUM_CREATED = 0xFF0068B7, ENUM_TOUCHED = 0xFF7F7FFF,
diff -r e6648167e8d3 -r 50b8f7654c36 NumericUpDown.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/NumericUpDown.cpp	Mon Mar 12 04:22:48 2018 +0000
@@ -0,0 +1,94 @@
+//-----------------------------------------------------------
+//  NumericUpDown class
+//      指定された桁を up/down する GUI 部品
+//      6 桁まで可能
+//
+//  2017/08/21, Copyright (c) 2017 MIKAMI, Naoki
+//-----------------------------------------------------------
+
+#include "NumericUpDown.hpp"
+
+namespace Mikami
+{
+    // digit    表示する桁数
+    // initVal  最初に表示する数値
+    NumericUpDown::NumericUpDown(uint16_t digit, uint16_t x0, uint16_t y0,
+                                 uint32_t initVal, uint32_t max, uint32_t min,
+                                 string unit, float delay)
+        : DIGIT_(digit), X0_(x0), Y0_(y0), MAX_(max), MIN_(min),
+          POW10_(6, (uint32_t []){1, 10, 100, 1000, 10000, 10000}),
+          numUd_(-1), value_(initVal),
+          delay_(delay), labels_(digit), lcd_(GuiBase::GetLcd())
+    {
+        MBED_ASSERT(DIGIT_ <= 6);   // 6 桁まで
+        sprintf(fmt_, "%%""0%1dd", DIGIT_);
+        for (int n=0; n<DIGIT_; n++)
+            labels_[n] = new Label(
+                X0_+10+n*XW_, Y0_-46, "", Label::LEFT, Font16);
+        Set(initVal);       // 初期値として表示
+        Label lbUnit(X0_+0+DIGIT_*XW_, Y0_-46, unit, Label::LEFT, Font16);
+        Array<string> nonString(DIGIT_*2, "");
+        ud_ = new ButtonGroup(X0_, Y0_-81, 30, 30, DIGIT_*2, nonString,
+                              XW_-30, 22, DIGIT_);
+        for (int n=0; n<DIGIT_*2; n++) UpDownSymbol(X0_, Y0_, n);
+    }
+
+    // Up, Down をタッチした場合は対応する数値を +1 または -1 する
+    bool NumericUpDown::Touched()
+    {
+        if (!delay_.IsEnabled()) return false;
+        int num;
+        if (!ud_->GetTouchedNumber(num)) return false;
+
+        // タッチ後一定の時間が経過してから,再びタッチの検出を有効にするため
+        delay_.Disable();
+
+        // 三角を再描画
+        UpDownSymbol(X0_, Y0_, num);
+        if (numUd_ != -1) UpDownSymbol(X0_, Y0_, numUd_);
+        numUd_ = num;
+
+        int index = num % DIGIT_;
+        if (num < DIGIT_) value_ += POW10_[DIGIT_-index-1];
+        else
+            if (index != 0)
+                value_ -= POW10_[DIGIT_-index-1];
+            else
+                if (value_ >= POW10_[DIGIT_-1])
+                    value_ -= POW10_[DIGIT_-index-1];
+        Set(value_);
+        return true;
+    }
+
+    // 引数の数値を Label に表示する
+    void NumericUpDown::Set(uint32_t frq)
+    {
+        if (frq > MAX_) frq = MAX_;
+        if (frq < MIN_) frq = MIN_;
+        char frqCh[7];
+        sprintf(frqCh, fmt_, frq);
+
+        for (int n=0; n<DIGIT_; n++)
+            labels_[n]->Draw((string)""+frqCh[n]);
+        value_ = frq;
+    }
+
+    // 数値の up, down に使う三角形の描画
+    void NumericUpDown::UpDownSymbol(uint16_t x, uint16_t y, int k)
+    {
+        lcd_.SetTextColor(GuiBase::ENUM_TEXT);
+        Point *pt = k < DIGIT_ ? ptU_ : ptD_;
+        int16_t y0 = k < DIGIT_ ? y - 25 : y + 31;
+
+        Point tri[3];
+        for (int n=0; n<3; n++)
+        {
+            tri[n].X = pt[n].X + x + XW_*(k % DIGIT_) + 15;
+            tri[n].Y = pt[n].Y + y0 - 46;
+        }
+        lcd_.FillPolygon(tri, 3);
+    }
+    
+    Point NumericUpDown::ptU_[] = {{0, 0}, {-SIZE_, SIZE_}, {SIZE_, SIZE_}};
+    Point NumericUpDown::ptD_[] = {{0, SIZE_}, {SIZE_, 0}, {-SIZE_, 0}};
+}
diff -r e6648167e8d3 -r 50b8f7654c36 NumericUpDown.hpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/NumericUpDown.hpp	Mon Mar 12 04:22:48 2018 +0000
@@ -0,0 +1,63 @@
+//-----------------------------------------------------------
+//  NumericUpDown class
+//      指定された桁を up/down する GUI 部品
+//      6 桁まで可能
+//
+//  2018/03/12, Copyright (c) 2018 MIKAMI, Naoki
+//-----------------------------------------------------------
+
+#ifndef NUMERIC_UPDOWN_HPP
+#define NUMERIC_UPDOWN_HPP
+
+#include "F746_GUI.hpp"
+#include "DelayedEnabler.hpp"
+
+namespace Mikami
+{
+    class NumericUpDown
+    {
+    public:
+        // digit    表示する桁数
+        // initVal  最初に表示する数値
+        NumericUpDown(uint16_t digit, uint16_t x0, uint16_t y0,
+                      uint32_t initVal, uint32_t max, uint32_t min,
+                      string unit = "", float delay = 0.2f);
+
+        // Up, Down をタッチした場合は対応する数値を +1 または -1 する
+        bool Touched();
+
+        // 引数の数値を Label に表示する
+        void Set(uint32_t frq);
+
+        // Label に表示されている値を数値データとして取り出す
+        uint32_t Get() { return value_; }
+
+    private:
+        const int DIGIT_;       // 桁数
+        const int X0_, Y0_;
+        const uint32_t MAX_;    // 最大値
+        const uint32_t MIN_;    // 最小値
+        const Array<uint32_t> POW10_;
+        const static uint16_t XW_ = 45;
+        const static int16_t SIZE_ = 6;
+
+        static Point ptU_[3], ptD_[3];
+     
+        char fmt_[5];
+        int numUd_;     // 一つ前にタッチしたボタンの番号
+        uint32_t value_;
+
+        DelayedEnabler delay_;
+        Array<Label *> labels_;
+        ButtonGroup *ud_;
+        LCD_DISCO_F746NG &lcd_;
+
+        // 数値の up, down に使う三角形の描画
+        void UpDownSymbol(uint16_t x, uint16_t y, int k);
+
+        // disallow copy constructor and assignment operator
+        NumericUpDown(const NumericUpDown&);
+        NumericUpDown& operator=(const NumericUpDown&);      
+    };
+}
+#endif  // NUMERIC_UPDOWN_HPP
diff -r e6648167e8d3 -r 50b8f7654c36 ResetButton.hpp
--- a/ResetButton.hpp	Sun Apr 02 06:59:09 2017 +0000
+++ b/ResetButton.hpp	Mon Mar 12 04:22:48 2018 +0000
@@ -41,6 +41,10 @@
 
     private:
         Point pt_[3];
+
+        // disallow copy constructor and assignment operator
+        ResetButton(const ResetButton&);
+        ResetButton& operator=(const ResetButton&);
     };
 }
 #endif  // F746_RESET_BUTTON_HPP