2018年3月16日に開催されるCQ出版社インターフェース誌オフ会で紹介するプログラム
Dependencies: mbed Array_Matrix BSP_DISCO_F746NG LCD_DISCO_F746NG TS_DISCO_F746NG
Revision 1:c27b3361dbbb, committed 2018-03-12
- Comitter:
- MikamiUitOpen
- Date:
- Mon Mar 12 04:31:12 2018 +0000
- Parent:
- 0:f00cf31ae154
- Commit message:
- 2
Changed in this revision
diff -r f00cf31ae154 -r c27b3361dbbb F746_GUI.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/F746_GUI.lib Mon Mar 12 04:31:12 2018 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/MikamiUitOpen/code/F746_GUI/#50b8f7654c36
diff -r f00cf31ae154 -r c27b3361dbbb F746_Gui_New/Array_Matrix.lib --- a/F746_Gui_New/Array_Matrix.lib Sat Mar 10 11:37:33 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -https://developer.mbed.org/users/MikamiUitOpen/code/Array_Matrix/#a25dba17218c
diff -r f00cf31ae154 -r c27b3361dbbb F746_Gui_New/BSP_DISCO_F746NG.lib --- a/F746_Gui_New/BSP_DISCO_F746NG.lib Sat Mar 10 11:37:33 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/teams/ST/code/BSP_DISCO_F746NG/#df2ea349c37a
diff -r f00cf31ae154 -r c27b3361dbbb F746_Gui_New/BlinkLabel.hpp --- a/F746_Gui_New/BlinkLabel.hpp Sat Mar 10 11:37:33 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,46 +0,0 @@ -//----------------------------------------------------------- -// BlinkLabel class -- derived class of Label class -// For displaying error message -// -// 2017/01/25, Copyright (c) 2017 MIKAMI, Naoki -//----------------------------------------------------------- - -#ifndef F746_BLINK_LABEL_HPP -#define F746_BLINK_LABEL_HPP - -#include "Label.hpp" -#include "ResetButton.hpp" - -namespace Mikami -{ - class BlinkLabel : public Label - { - public: - // Constructor - BlinkLabel(uint16_t x, uint16_t y, const string str, - TextAlignMode mode = LEFT, - sFONT &fonts = Font20, - uint32_t textColor = LCD_COLOR_RED, - uint32_t backColor = GuiBase::ENUM_BACK, - uint32_t on = 500, uint32_t off = 200) - : Label(x, y, str, mode, fonts, textColor, backColor) - { - ResetButton reset; - while (true) // Blinking here - { - wait_ms(on); - Draw(backColor); - wait_ms(off); - Draw(textColor); - reset.DoIfTouched(); - } - } - - private: - // disallow copy constructor and assignment operator - BlinkLabel(const BlinkLabel&); - BlinkLabel& operator=(const BlinkLabel&); - }; -} -#endif // F746_BLINK_LABEL_HPP -
diff -r f00cf31ae154 -r c27b3361dbbb F746_Gui_New/Button.cpp --- a/F746_Gui_New/Button.cpp Sat Mar 10 11:37:33 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,67 +0,0 @@ -//----------------------------------------------------------- -// Button class handling multi-touch -// Multi-touch: Enabled (default) -// -// 2016/04/08, Copyright (c) 2016 MIKAMI, Naoki -//----------------------------------------------------------- - -#include "Button.hpp" - -namespace Mikami -{ - // Draw button - void Button::Draw(uint32_t color, uint32_t textColor) - { - if (color == BACK_COLOR_) active_ = true; - if (!active_) return; - lcd_.SetTextColor(color); - lcd_.FillRect(X_, Y_, W_, H_); - - if (STR_.length() != 0) - { - lcd_.SetFont(FONTS_); - lcd_.SetBackColor(color); - lcd_.SetTextColor(textColor); - uint16_t x0 = X_ + (W_ - FONTS_->Width*(STR_.length()))/2; - uint16_t y0 = Y_ + (H_ - FONTS_->Height)/2 + 1; - DrawString(x0, y0, STR_); - lcd_.SetBackColor(BACK_COLOR_); // recover back color - } - } - - // Check touch detected - bool Button::Touched() - { - if (!active_) return false; - if (!PanelTouched()) return false; - if (!IsOnButton()) return false; - Draw(TOUCHED_COLOR_, TEXT_COLOR_); - return true; - } - - // If touched position is on the button, return true - bool Button::IsOnButton() - { - int nTouch = multiTouch_ ? state_.touchDetected : 1; - for (int n=0; n<nTouch; n++) - { - uint16_t x = state_.touchX[n]; - uint16_t y = state_.touchY[n]; - if ( (X_ <= x) && (x <= X_+W_) && - (Y_ <= y) && (y <= Y_+H_) ) return true; - } - return false; - } - - void Button::Activate() - { - active_ = true; - Draw(); - } - - void Button::Inactivate() - { - Draw(INACTIVE_COLOR_, INACTIVE_TEXT_COLOR_); - active_ = false; - } -}
diff -r f00cf31ae154 -r c27b3361dbbb F746_Gui_New/Button.hpp --- a/F746_Gui_New/Button.hpp Sat Mar 10 11:37:33 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,65 +0,0 @@ -//----------------------------------------------------------- -// Button class handling multi-touch -- Header -// Multi-touch: Enabled (default) -// -// 2016/03/29, Copyright (c) 2016 MIKAMI, Naoki -//----------------------------------------------------------- - -#ifndef F746_BUTTON_HPP -#define F746_BUTTON_HPP - -#include "GuiBase.hpp" - -namespace Mikami -{ - class Button : public GuiBase - { - public: - // Constructor - Button(uint16_t x, uint16_t y, - uint16_t width, uint16_t height, - const string str = "", sFONT &fonts = Font12, - uint32_t textColor = GuiBase::ENUM_TEXT, - uint32_t backColor = GuiBase::ENUM_BACK, - uint32_t createdColor = GuiBase::ENUM_CREATED, - uint32_t touchedColor = GuiBase::ENUM_TOUCHED, - uint32_t inactiveColor = GuiBase::ENUM_INACTIVE, - uint32_t inactiveTextColor = GuiBase::ENUM_INACTIVE_TEXT) - : GuiBase(x, y, fonts, - textColor, backColor, createdColor, - touchedColor, inactiveColor, - inactiveTextColor), - W_(width), H_(height), STR_(str), active_(true) - { Draw(); } - - // Draw button - void Draw(uint32_t color, uint32_t textColor); - void Draw(uint32_t color) { Draw(color, TEXT_COLOR_); } - void Draw() { Draw(CREATED_COLOR_, TEXT_COLOR_); } - - // Erase button - void Erase() { Draw(BACK_COLOR_, BACK_COLOR_); } - - // Check touch detected and redraw button - bool Touched(); - - bool IsOnButton(); - - void Activate(); - void Inactivate(); - bool IsActive() { return active_; } - - // Set or reset multi-touch - static void SetMultiTouch(bool tf) { multiTouch_ = tf; } - - private: - const uint16_t W_, H_; - const string STR_; - bool active_; - - // disallow copy constructor and assignment operator - Button(const Button&); - Button& operator=(const Button&); - }; -} -#endif // F746_BUTTON_HPP
diff -r f00cf31ae154 -r c27b3361dbbb F746_Gui_New/ButtonGroup.cpp --- a/F746_Gui_New/ButtonGroup.cpp Sat Mar 10 11:37:33 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,134 +0,0 @@ -//----------------------------------------------------------- -// ButtonGroup class -// -// 2017/01/25, Copyright (c) 2017 MIKAMI, Naoki -//----------------------------------------------------------- - -#include "ButtonGroup.hpp" - -namespace Mikami -{ - // Constructor - ButtonGroup::ButtonGroup( - uint16_t x0, uint16_t y0, - uint16_t width, uint16_t height, - uint16_t number, const string str[], - uint16_t spaceX, uint16_t spaceY, - uint16_t column, int touched, - sFONT &fonts, - uint32_t textColor, uint32_t backColor, - uint32_t createdColor, uint32_t touchedColor, - uint32_t inactiveColor, uint32_t inactiveTextColor) - : TEXT_COLOR_(textColor), CREATED_COLOR_(createdColor), - TOUCHED_COLOR_(touchedColor), - NUMBER_(number), prevNum_(touched) - { - buttons_.SetSize(number); - for (int n=0; n<number; n++) - { - div_t u1 = div(n, column); - uint16_t x = x0 + u1.rem*(width + spaceX); - uint16_t y = y0 + u1.quot*(height + spaceY); - buttons_[n] = - new Button(x, y, width, height, str[n], fonts, - textColor, backColor, - createdColor, touchedColor, - inactiveColor, inactiveTextColor); - } - // On created, set touched color as needed - if (touched >= 0) TouchedColor(touched); - } - - // Draw button - bool ButtonGroup::Draw(int num, uint32_t color, uint32_t textColor) - { - if (!Range(num)) return false; - buttons_[num]->Draw(color, textColor); - return true; - } - - // Change to touched color - bool ButtonGroup::TouchedColor(int num) - { - if (prevNum_ != num) prevNum_ = num; - return Draw(num, TOUCHED_COLOR_, TEXT_COLOR_); - } - - // Erase button - bool ButtonGroup::Erase(int num) - { - if (!Range(num)) return false; - buttons_[num]->Erase(); - return true; - } - - // Check touch detected for specified button - bool ButtonGroup::Touched(int num) - { - if (!Range(num)) return false; - if (!buttons_[num]->IsActive()) return false; - int touched; - if (!GetTouchedNumber(touched)) return false; - bool rtn = (touched == num) ? true : false; - return rtn; - } - - // Get touched number, return value: true or false - bool ButtonGroup::GetTouchedNumber(int &num) - { - bool rtn = false; - if (GuiBase::PanelTouched()) - { - for (int n=0; n<NUMBER_; n++) - if (buttons_[n]->IsOnButton() && - buttons_[n]->IsActive()) - { - num = n; - rtn = true; - } - - if (!rtn) return false; - } - else - return false; - - buttons_[num]->Draw(TOUCHED_COLOR_); - if ((prevNum_ >= 0) && (prevNum_ != num)) - buttons_[prevNum_]->Draw(); - if (prevNum_ != num) prevNum_ = num; - return true; - } - - // Get touched number, return value: touched number - int ButtonGroup::GetTouchedNumber() - { - int num; - if (GetTouchedNumber(num)) - return num; - else - return -1; - } - - // Wait until touched and get touched number - int ButtonGroup::WaitTouchedAndGet() - { - int num; - while (!GetTouchedNumber(num)) {} - return num; - } - - // Activate and inactivate button(s) - bool ButtonGroup::Activate(int num) - { - if (!Range(num)) return false; - buttons_[num]->Activate(); - return true; - } - bool ButtonGroup::Inactivate(int num) - { - if (!Range(num)) return false; - buttons_[num]->Inactivate(); - return true; - } -} -
diff -r f00cf31ae154 -r c27b3361dbbb F746_Gui_New/ButtonGroup.hpp --- a/F746_Gui_New/ButtonGroup.hpp Sat Mar 10 11:37:33 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,95 +0,0 @@ -//----------------------------------------------------------- -// ButtonGroup class -- Header -// -// 2017/01/25, Copyright (c) 2017 MIKAMI, Naoki -//----------------------------------------------------------- - -#ifndef F746_BUTTON_GROUP_HPP -#define F746_BUTTON_GROUP_HPP - -#include "Button.hpp" -#include "Array.hpp" - -namespace Mikami -{ - class ButtonGroup - { - public: - // Constructor - ButtonGroup(uint16_t x0, uint16_t y0, - uint16_t width, uint16_t height, - uint16_t number, const string str[], - uint16_t spaceX = 0, uint16_t spaceY = 0, - uint16_t column = 1, - int touched = -1, // number for button initially touched-color - sFONT &fonts = Font12, - uint32_t textColor = GuiBase::ENUM_TEXT, - uint32_t backColor = GuiBase::ENUM_BACK, - uint32_t createdColor = GuiBase::ENUM_CREATED, - uint32_t touchedColor = GuiBase::ENUM_TOUCHED, - uint32_t inactiveColor = GuiBase::ENUM_INACTIVE, - uint32_t inactiveTextColor = GuiBase::ENUM_INACTIVE_TEXT); - - // Destructor - virtual ~ButtonGroup() - { for (int n=0; n<NUMBER_; n++) delete buttons_[n]; } - - // Draw button - bool Draw(int num, uint32_t color, uint32_t textColor); - bool Draw(int num) { return Draw(num, CREATED_COLOR_, TEXT_COLOR_); } - - // Change to touched color - bool TouchedColor(int num); - - // Draw all buttons - void DrawAll(uint32_t color, uint32_t textColor) - { for (int n=0; n<NUMBER_; n++) Draw(n, color, textColor); } - void DrawAll() { DrawAll(CREATED_COLOR_, TEXT_COLOR_); } - - // Erase button - bool Erase(int num); - void EraseAll() - { for (int n=0; n<NUMBER_; n++) Erase(n); } - - // Check touch detected for specified button - bool Touched(int num); - - // Get touched number, return value: true or false - bool GetTouchedNumber(int &num); - // Get touched number, return value: touched number - int GetTouchedNumber(); - - // Wait until touched - void WaitTouched(int num) - { while (!Touched(num)) {} } - // Wait until touched and get touched number - int WaitTouchedAndGet(); - - // Activate and inactivate button(s) - bool Activate(int num); - void ActivateAll() - { for (int n=0; n<NUMBER_; n++) Activate(n); } - bool Inactivate(int num); - void InactivateAll() - { for (int n=0; n<NUMBER_; n++) Inactivate(n); } - - private: - const uint32_t TEXT_COLOR_; - const uint32_t CREATED_COLOR_; - const uint32_t TOUCHED_COLOR_; - const int NUMBER_; - - Array<Button *> buttons_; - __IO int prevNum_; - - // Check range of argument - bool Range(int n) - { return ((n >= 0) && (n < NUMBER_)); } - - // disallow copy constructor and assignment operator - ButtonGroup(const ButtonGroup&); - ButtonGroup& operator=(const ButtonGroup&); - }; -} -#endif // F746_BUTTON_GROUP_HPP -
diff -r f00cf31ae154 -r c27b3361dbbb F746_Gui_New/F746_GUI.hpp --- a/F746_Gui_New/F746_GUI.hpp Sat Mar 10 11:37:33 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,20 +0,0 @@ -//-------------------------------------------------------------- -// F746-DISCO の GUI 用のインクルード文とそれらを使うための -// using 宣言をまとめたもの -// Include statements for F746-DISCO GUI and using directive -// -// 2016/08/15, Copyright (c) 2016 MIKAMI, Naoki -//-------------------------------------------------------------- - -#include "mbed.h" -#ifndef __STM32F746xx_H -#error Platform is not F746NG-DISCOVERY -#endif - -#include "BlinkLabel.hpp" -#include "ButtonGroup.hpp" -#include "NumericLabel.hpp" -#include "ResetButton.hpp" -#include "SeekbarGroup.hpp" - -using namespace Mikami;
diff -r f00cf31ae154 -r c27b3361dbbb F746_Gui_New/GuiBase.cpp --- a/F746_Gui_New/GuiBase.cpp Sat Mar 10 11:37:33 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,44 +0,0 @@ -//----------------------------------------------------------- -// GuiBase class (abstract base class) -// -// 2016/03/29, Copyright (c) 2016 MIKAMI, Naoki -//----------------------------------------------------------- - -#include "GuiBase.hpp" - -namespace Mikami -{ - GuiBase::GuiBase( - uint16_t x, uint16_t y, sFONT &fonts, - uint32_t textColor, uint32_t backColor, - uint32_t createdColor, uint32_t touchedColor, - uint32_t inactiveColor, uint32_t inactiveTextColor) - : X_(x), Y_(y), FONTS_(&fonts), - TEXT_COLOR_(textColor), BACK_COLOR_(backColor), - CREATED_COLOR_(createdColor), - TOUCHED_COLOR_(touchedColor), - INACTIVE_COLOR_(inactiveColor), - INACTIVE_TEXT_COLOR_(inactiveTextColor) - { - if (first_) - { - lcd_.Clear(backColor); - first_ = false; - } - } - - // If panel touched, return true - bool GuiBase::PanelTouched() - { - ts_.GetState(&state_); - return (bool)(state_.touchDetected); - } - - LCD_DISCO_F746NG GuiBase::lcd_; - TS_DISCO_F746NG GuiBase::ts_; - - TS_StateTypeDef GuiBase::state_; - - bool GuiBase::multiTouch_ = false; - bool GuiBase::first_ = true; -}
diff -r f00cf31ae154 -r c27b3361dbbb F746_Gui_New/GuiBase.hpp --- a/F746_Gui_New/GuiBase.hpp Sat Mar 10 11:37:33 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,70 +0,0 @@ -//----------------------------------------------------------- -// GuiBase class (abstract base class) ---- Header -// -// 2017/03/17, Copyright (c) 2017 MIKAMI, Naoki -//----------------------------------------------------------- - -#ifndef F746_GUI_BASE_HPP -#define F746_GUI_BASE_HPP - -#include "mbed.h" -#include <string> -#include "TS_DISCO_F746NG.h" -#include "LCD_DISCO_F746NG.h" - -namespace Mikami -{ - class GuiBase - { - public: - static LCD_DISCO_F746NG& GetLcd() { return lcd_; } - static TS_DISCO_F746NG& GetTs() { return ts_; } - - // If panel touched, return true - static bool PanelTouched(); - // Get touch panel state - static TS_StateTypeDef GetTsState() { return state_; } - - enum { ENUM_TEXT = 0xFFFFFFFF, ENUM_BACK = 0xFF003538, - ENUM_CREATED = 0xFF0068B7, ENUM_TOUCHED = 0xFF7F7FFF, - ENUM_INACTIVE = 0xD0003538, ENUM_INACTIVE_TEXT = 0xFF808080}; - - protected: - static LCD_DISCO_F746NG lcd_; // for LCD display - static TS_DISCO_F746NG ts_; // for touch pannel - - static TS_StateTypeDef state_; - static bool multiTouch_; - - const uint16_t X_, Y_; - sFONT *const FONTS_; - - const uint32_t TEXT_COLOR_; - const uint32_t BACK_COLOR_; - const uint32_t CREATED_COLOR_; - const uint32_t TOUCHED_COLOR_; - const uint32_t INACTIVE_COLOR_; - const uint32_t INACTIVE_TEXT_COLOR_; - - // Constructor - GuiBase(uint16_t x =0, uint16_t y =0, - sFONT &fonts = Font12, - uint32_t textColor = ENUM_TEXT, - uint32_t backColor = ENUM_BACK, - uint32_t createdColor = ENUM_CREATED, - uint32_t touchedColor = ENUM_TOUCHED, - uint32_t inactiveColor = ENUM_INACTIVE, - uint32_t inactiveTextColor = ENUM_INACTIVE_TEXT); - - void DrawString(uint16_t x, uint16_t y, const string str) - { lcd_.DisplayStringAt(x, y, (uint8_t *)str.c_str(), LEFT_MODE); } - - private: - static bool first_; - - // disallow copy constructor and assignment operator - GuiBase(const GuiBase&); - GuiBase& operator=(const GuiBase&); - }; -} -#endif // F746_GUI_BASE_HPP
diff -r f00cf31ae154 -r c27b3361dbbb F746_Gui_New/LCD_DISCO_F746NG.lib --- a/F746_Gui_New/LCD_DISCO_F746NG.lib Sat Mar 10 11:37:33 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/teams/ST/code/LCD_DISCO_F746NG/#d44525b1de98
diff -r f00cf31ae154 -r c27b3361dbbb F746_Gui_New/Label.cpp --- a/F746_Gui_New/Label.cpp Sat Mar 10 11:37:33 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,50 +0,0 @@ -//----------------------------------------------------------- -// Label class -// -// 2016/04/24, Copyright (c) 2016 MIKAMI, Naoki -//----------------------------------------------------------- - -#include "Label.hpp" - -namespace Mikami -{ - // Constructor - Label::Label(uint16_t x, uint16_t y, - const string str, TextAlignMode mode, sFONT &fonts, - uint32_t textColor, uint32_t backColor) - : GuiBase(x, y, fonts, textColor, backColor), - MODE_(mode), STR_(str) - { - length_ = str.length(); - lcd_.SetBackColor(backColor); - lcd_.SetTextColor(textColor); - lcd_.SetFont(&fonts); - DrawString(PosX(x), y, str); - } - - void Label::Draw(const string str, uint32_t textColor) - { - // Erase previously-drawn string - lcd_.SetTextColor(BACK_COLOR_); - length_ = (length_ > str.length()) ? length_ : str.length(); - lcd_.FillRect(PosX(X_), Y_, FONTS_->Width*length_+1, FONTS_->Height); - - // Draw new string - length_ = str.length(); - lcd_.SetFont(FONTS_); - lcd_.SetTextColor(textColor); - DrawString(PosX(X_), Y_, str); - } - - uint16_t Label::PosX(uint16_t x) - { - if (MODE_ == LEFT) return x; - else - { - if (MODE_ == CENTER) - return x - length_*FONTS_->Width/2; - else - return x - length_*FONTS_->Width; - } - } -}
diff -r f00cf31ae154 -r c27b3361dbbb F746_Gui_New/Label.hpp --- a/F746_Gui_New/Label.hpp Sat Mar 10 11:37:33 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,58 +0,0 @@ -//----------------------------------------------------------- -// Label class -- Header -// -// 2016/10/02, Copyright (c) 2016 MIKAMI, Naoki -//----------------------------------------------------------- - -#ifndef F746_LABEL_HPP -#define F746_LABEL_HPP - -#include "GuiBase.hpp" - -namespace Mikami -{ - class Label : public GuiBase - { - public: - enum TextAlignMode { LEFT, CENTER, RIGHT }; - // Constructor - Label(uint16_t x, uint16_t y, const string str, - TextAlignMode mode = LEFT, - sFONT &fonts = Font12, - uint32_t textColor = GuiBase::ENUM_TEXT, - uint32_t backColor = GuiBase::ENUM_BACK); - - // Constructor without string - Label(uint16_t x, uint16_t y, - TextAlignMode mode = LEFT, - sFONT &fonts = Font12, - uint32_t textColor = GuiBase::ENUM_TEXT, - uint32_t backColor = GuiBase::ENUM_BACK) - : GuiBase(x, y, fonts, textColor, backColor), - MODE_(mode), STR_(""), length_(0) {} - - void Draw() - { Draw(STR_, TEXT_COLOR_); } - - void Draw(const string str) - { Draw(str, TEXT_COLOR_); } - - void Draw(uint32_t textColor) - { Draw(STR_, textColor); } - - void Draw(const string str, - uint32_t textColor); - - private: - const TextAlignMode MODE_; - const string STR_; - - uint8_t length_; - uint16_t PosX(uint16_t x); - - // disallow copy constructor and assignment operator - Label(const Label&); - Label& operator=(const Label&); - }; -} -#endif // F746_LABEL_HPP
diff -r f00cf31ae154 -r c27b3361dbbb F746_Gui_New/NumericLabel.hpp --- a/F746_Gui_New/NumericLabel.hpp Sat Mar 10 11:37:33 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -//----------------------------------------------------------- -// NumericLabel class -- derived class of Label class -// -// 2016/11/07, Copyright (c) 2016 MIKAMI, Naoki -//----------------------------------------------------------- - -#ifndef F746_NUMERIC_LABEL_HPP -#define F746_NUMERIC_LABEL_HPP - -#include "Label.hpp" - -namespace Mikami -{ - template <typename T> class NumericLabel : public Label - { - public: - // Constructor without drawing value - NumericLabel(uint16_t x, uint16_t y, - const char fmt[], - TextAlignMode mode = LEFT, - sFONT &fonts = Font12, - uint32_t textColor = GuiBase::ENUM_TEXT, - uint32_t backColor = GuiBase::ENUM_BACK) - : Label(x, y, "", mode, fonts, textColor, backColor), FMT_(fmt) {} - - // Constructor with drawing value - NumericLabel(uint16_t x, uint16_t y, - const char fmt[], T val, - TextAlignMode mode = LEFT, - sFONT &fonts = Font12, - uint32_t textColor = GuiBase::ENUM_TEXT, - uint32_t backColor = GuiBase::ENUM_BACK) - : Label(x, y, "", mode, fonts, textColor, backColor), FMT_(fmt) - { Draw(val); } - - // Draw value using format specified in constructor - void Draw(T val) - { - sprintf(str_, FMT_, val); - Label::Draw(str_); - } - - // Draw value - void Draw(const char fmt[], T val) - { - sprintf(str_, fmt, val); - Label::Draw(str_); - } - - // Draw previous value with specified color - void Redraw(uint32_t color) - { Label::Draw(str_, color); } - - private: - const char *const FMT_; - char str_[81]; - - // disallow copy constructor and assignment operator - NumericLabel(const NumericLabel&); - NumericLabel& operator=(const NumericLabel&); - }; -} -#endif // F746_NUMERIC_LABEL_HPP -
diff -r f00cf31ae154 -r c27b3361dbbb F746_Gui_New/ResetButton.hpp --- a/F746_Gui_New/ResetButton.hpp Sat Mar 10 11:37:33 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,46 +0,0 @@ -//----------------------------------------------------------- -// ResetButton class -- derived class of Button class -// -// 2017/01/16, Copyright (c) 2017 MIKAMI, Naoki -//----------------------------------------------------------- - -#ifndef F746_RESET_BUTTON_HPP -#define F746_RESET_BUTTON_HPP - -#include "Button.hpp" - -namespace Mikami -{ - class ResetButton : public Button - { - public: - ResetButton(uint16_t x = 0, uint16_t y = 240, - uint16_t w = 32, uint16_t h = 32) - : Button(x, y, w, h) - { - pt_[0] = (Point){x+0.2f*w, y+h/2}; - pt_[1] = (Point){x+0.75f*w, y+0.175f*h}; - pt_[2] = (Point){x+0.75f*w, y+0.825f*h}; - Draw(); - } - - void DoIfTouched() - { - if (!Touched()) return; - - wait(0.2f); - NVIC_SystemReset(); - } - - void Draw() - { - Activate(); - lcd_.SetTextColor(LCD_COLOR_WHITE); - lcd_.FillPolygon(pt_, 3); - } - - private: - Point pt_[3]; - }; -} -#endif // F746_RESET_BUTTON_HPP
diff -r f00cf31ae154 -r c27b3361dbbb F746_Gui_New/SeekBar.cpp --- a/F746_Gui_New/SeekBar.cpp Sat Mar 10 11:37:33 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,182 +0,0 @@ -//----------------------------------------------------------- -// SeekBar class -// -// 2017/01/25, Copyright (c) 2017 MIKAMI, Naoki -//----------------------------------------------------------- - -#include "SeekBar.hpp" - -namespace Mikami -{ - // Constructor with scale value (only horizontal) - SeekBar::SeekBar(uint16_t x, uint16_t y, uint16_t length, - float min, float max, float initialValue, - string left, string center, string right, - uint32_t thumbColor, - uint16_t thumbSize, uint16_t width, - uint32_t colorL, uint32_t colorH, - uint32_t backColor) - : GuiBase(x, y, Font12, GuiBase::ENUM_TEXT, backColor, thumbColor), - L_(length), W_(width), - SIZE_(thumbSize), COLOR_L_(colorL), COLOR_H_(colorH), - MIN_(min), MAX_(max), ORIENT_(Holizontal), v_(initialValue), - labelOn_(true), slided_(false), active_(true) - { - Draw(initialValue); - uint16_t y0 = y - thumbSize/2 - 13; - labelLCR_[0] = new Label(x, y0, left, Label::CENTER); - labelLCR_[1] = new Label(x+length/2, y0, center, Label::CENTER); - labelLCR_[2] = new Label(x+length, y0, right, Label::CENTER); - } - - // Slide thumb - // If the thumb is not touched, return false - bool SeekBar::Slide() - { - if (!active_) return false; - - if (!PanelTouched()) - { - if (slided_) Draw(v_); - slided_ = false; - return false; - } - - uint16_t x, y; - bool rtn = IsOnThumb(x, y); - if (rtn || slided_) - { - if (rtn) v_ = ToValue(Point(x, y)); - Draw(v_, rtn); - slided_ = rtn; - } - return rtn; - } - - void SeekBar::Activate() - { - active_ = true; - Draw(v_); - if (labelOn_) - for (int n=0; n<3; n++) labelLCR_[n]->Draw(TEXT_COLOR_); - } - - void SeekBar::Inactivate() - { - active_ = false; - Draw(v_); - if (labelOn_) - for (int n=0; n<3; n++) labelLCR_[n]->Draw(INACTIVE_TEXT_COLOR_); - } - - // If touched position is on the thumb, return true - bool SeekBar::IsOnThumb(uint16_t &x, uint16_t &y) - { - x = state_.touchX[0]; - y = state_.touchY[0]; - - uint16_t th = SIZE_/2; - Point pt = ToPoint(v_); - if (ORIENT_ == Holizontal) - { - if ( (pt.x-th <= x) && (x <= pt.x+th) && - (pt.y-th <= y) && (y <= pt.y+th) ) return true; - } - else - { - if ( (pt.x-th <= x) && (x <= pt.x+th) && - (pt.y-th <= y) && (y <= pt.y+th) ) return true; - } - - return false; - } - - // Draw seekbar - void SeekBar::Draw(float value, bool fill) - { - uint16_t sizeS = (uint16_t)(SIZE_*0.6f); - // Erase previous seekbar - lcd_.SetTextColor(BACK_COLOR_); - if (ORIENT_ == Holizontal) - lcd_.FillRect(X_-sizeS/2, Y_-SIZE_/2, L_+sizeS+1, SIZE_+1); - else - lcd_.FillRect(X_-SIZE_/2, Y_-sizeS/2, SIZE_+1, L_+sizeS+1); - - v_ = Saturate(value); // current value - Point pt = ToPoint(v_); // Position of thumb - - // Draw upper line - if (active_) lcd_.SetTextColor(COLOR_H_); - else lcd_.SetTextColor(INACTIVE_TEXT_COLOR_-0x404040); - if ((ORIENT_ == Holizontal) && ((X_+L_-pt.x) > 0)) - lcd_.FillRect(pt.x, Y_-W_/4, X_+L_-pt.x, W_/2); - if ((ORIENT_ == Vertical) && ((pt.y-Y_) > 0)) - lcd_.FillRect(X_-W_/4, Y_, W_/2, pt.y-Y_); - - // Draw lower line - if (active_) lcd_.SetTextColor(COLOR_L_); - else lcd_.SetTextColor(INACTIVE_TEXT_COLOR_-0x202020); - if ((ORIENT_ == Holizontal) && ((pt.x-X_) > 0)) - lcd_.FillRect(X_, Y_-W_/2, pt.x-X_, W_); - if ((ORIENT_ == Vertical) && ((Y_+L_-pt.y) > 0)) - lcd_.FillRect(X_-W_/2, pt.y, W_, Y_+L_-pt.y); - - // Draw thumb - if (active_) lcd_.SetTextColor(CREATED_COLOR_); - else lcd_.SetTextColor(INACTIVE_TEXT_COLOR_); - uint16_t width = SIZE_; - uint16_t height = SIZE_; - if (ORIENT_ == Holizontal) width = sizeS; - else height = sizeS; - uint16_t xPos = pt.x - width/2; - uint16_t yPos = pt.y - height/2; - - if (fill) - lcd_.FillRect(xPos, yPos, width+1, height+1); - else - { - lcd_.DrawRect(xPos, yPos, width, height); - lcd_.DrawHLine(pt.x+width/2, pt.y+height/2, 1); - lcd_.DrawRect(xPos+1, yPos+1, width-2, height-2); - lcd_.DrawHLine(pt.x+width/2-1, pt.y+height/2-1, 1); - if (ORIENT_ == Holizontal) - lcd_.DrawVLine(pt.x, yPos+4, SIZE_-7); - else - lcd_.DrawHLine(xPos+4, pt.y, SIZE_-7); - } - } - - void SeekBar::Redraw(bool fill) - { - Draw(GetValue(), fill); - if (labelOn_) - for (int n=0; n<3; n++) labelLCR_[n]->Draw(TEXT_COLOR_); - } - - SeekBar::Point SeekBar::ToPoint(float value) - { - if (ORIENT_ == Holizontal) - return Point(X_ + Round(L_*(value - MIN_)/(MAX_ - MIN_)), Y_); - else - return Point(X_, Y_ + L_ - Round(L_*(value - MIN_)/(MAX_ - MIN_))); - } - - float SeekBar::ToValue(Point pt) - { - float value; - if (ORIENT_ == Holizontal) - value = (pt.x - X_)*(MAX_ - MIN_)/(float)L_ + MIN_; - else - value = -(pt.y - Y_ - L_)*(MAX_ - MIN_)/(float)L_ + MIN_; - return Saturate(value); - } - - float SeekBar::Saturate(float value) - { - if (value < MIN_) value = MIN_; - if (value > MAX_) value = MAX_; - return value; - } -} - -
diff -r f00cf31ae154 -r c27b3361dbbb F746_Gui_New/SeekBar.hpp --- a/F746_Gui_New/SeekBar.hpp Sat Mar 10 11:37:33 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,95 +0,0 @@ -//----------------------------------------------------------- -// SeekBar class -- Header -// -// 2017/01/25, Copyright (c) 2017 MIKAMI, Naoki -//----------------------------------------------------------- - -#ifndef F746_SEEKBAR_HPP -#define F746_SEEKBAR_HPP - -#include "GuiBase.hpp" -#include "Label.hpp" - -namespace Mikami -{ - class SeekBar : public GuiBase - { - public: - enum Orientation { Holizontal, Vertical }; - - struct Point - { - uint16_t x, y; - Point(uint16_t x0 = 0, uint16_t y0 = 0) : x(x0), y(y0) {} - }; - - // Constructor - SeekBar(uint16_t x, uint16_t y, uint16_t length, - float min, float max, float initialValue, - Orientation hv = Holizontal, - uint32_t thumbColor = 0xFFB0B0FF, - uint16_t thumbSize = 30, uint16_t width = 4, - uint32_t colorL = LCD_COLOR_LIGHTGRAY, - uint32_t colorH = 0xFFB0B0B0, - uint32_t backColor = GuiBase::ENUM_BACK) - : GuiBase(x, y, Font12, 0, backColor, thumbColor), - L_(length), W_(width), - SIZE_(thumbSize), COLOR_L_(colorL), COLOR_H_(colorH), - MIN_(min), MAX_(max), ORIENT_(hv), v_(initialValue), - labelOn_(false), slided_(false), active_(true) - { Draw(initialValue); } - - // Constructor with scale value (only horizontal) - SeekBar(uint16_t x, uint16_t y, uint16_t length, - float min, float max, float initialValue, - string left, string center, string right, - uint32_t thumbColor = 0xFFB0B0FF, - uint16_t thumbSize = 30, uint16_t width = 4, - uint32_t colorL = LCD_COLOR_LIGHTGRAY, - uint32_t colorH = 0xFFB0B0B0, - uint32_t backColor = GuiBase::ENUM_BACK); - - virtual ~SeekBar() - { for (int n=0; n<3; n++) delete labelLCR_[n]; } - - bool Slide(); - float GetValue() { return v_; } - int GetIntValue() { return Round(v_); } - - void Activate(); - void Inactivate(); - bool IsActive() { return active_; } - - bool IsOnThumb(uint16_t &x, uint16_t &y); - void Draw(float value, bool fill = false); - void Redraw(bool fill = false); - float ToValue(Point pt); - - void SetValue(float v) { v_ = v; } - void SetSlided(bool tf) { slided_ = tf; } - bool GetSlided() { return slided_; } - - private: - const uint16_t L_, W_; - const uint16_t SIZE_; // Size of thumb - const uint32_t COLOR_L_, COLOR_H_; - const float MIN_, MAX_; - const Orientation ORIENT_; - - Label *labelLCR_[3]; - float v_; // value of seekbar - bool labelOn_; - bool slided_; - bool active_; - - int Round(float x) { return x + 0.5f - (x < 0); } - Point ToPoint(float value); - float Saturate(float value); - - // disallow copy constructor and assignment operator - SeekBar(const SeekBar&); - SeekBar& operator=(const SeekBar&); - }; -} -#endif // F746_SEEKBAR_HPP -
diff -r f00cf31ae154 -r c27b3361dbbb F746_Gui_New/SeekbarGroup.cpp --- a/F746_Gui_New/SeekbarGroup.cpp Sat Mar 10 11:37:33 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,72 +0,0 @@ -//----------------------------------------------------------- -// SeekbarGroup class -// -// 2017/01/25, Copyright (c) 2017 MIKAMI, Naoki -//----------------------------------------------------------- - -#include "SeekbarGroup.hpp" - -namespace Mikami -{ - SeekbarGroup::SeekbarGroup( - uint16_t x0, uint16_t y0, uint16_t length, - uint16_t number, uint16_t space, - float min, float max, float initialValue, - SeekBar::Orientation hv, - uint32_t thumbColor, uint16_t thumbSize, uint16_t width, - uint32_t colorL, uint32_t colorH, uint32_t backColor) - : NUMBER_(number) - { - seekBars_.SetSize(number); - for (int n=0; n<number; n++) - { - uint16_t x = x0; - uint16_t y = y0; - if (hv == SeekBar::Holizontal) y += space*n; - else x += space*n; - seekBars_[n] = - new SeekBar(x, y, length, min, max, initialValue, hv, - thumbColor, thumbSize, width, - colorL, colorH, backColor); - } - } - - // Get slided number - bool SeekbarGroup::GetSlidedNumber(int &num) - { - bool active = false; - for (int n=0; n<NUMBER_; n++) - if (seekBars_[n]->IsActive()) active = true; - if (!active) return false; - - if (!GuiBase::PanelTouched()) - { - for (int n=0; n<NUMBER_; n++) - { - if (seekBars_[n]->GetSlided()) - seekBars_[n]->Draw(seekBars_[n]->GetValue()); - seekBars_[n]->SetSlided(false); - } - return false; - } - - bool rtn = false; - uint16_t x, y; - for (int n=0; n<NUMBER_; n++) - { - if (seekBars_[n]->IsOnThumb(x, y)) - { - if ((num != n) && Range(num)) - seekBars_[num]->Draw(seekBars_[num]->GetValue()); - num = n; - seekBars_[n]->SetValue(seekBars_[n]->ToValue(SeekBar::Point(x, y))); - seekBars_[n]->Draw(seekBars_[n]->GetValue(), true); - seekBars_[n]->SetSlided(true); - rtn = true; - } - if (rtn) break; - } - return rtn; - } -} -
diff -r f00cf31ae154 -r c27b3361dbbb F746_Gui_New/SeekbarGroup.hpp --- a/F746_Gui_New/SeekbarGroup.hpp Sat Mar 10 11:37:33 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,79 +0,0 @@ -//----------------------------------------------------------- -// SeekbarGroup class -- Header -// -// 2017/01/25, Copyright (c) 2017 MIKAMI, Naoki -//----------------------------------------------------------- - -#ifndef F746_SEEKBAR_GROUP_HPP -#define F746_SEEKBAR_GROUP_HPP - -#include "SeekBar.hpp" -#include "Array.hpp" - -namespace Mikami -{ - class SeekbarGroup - { - public: - SeekbarGroup(uint16_t x0, uint16_t y0, uint16_t length, - uint16_t number, uint16_t space, - float min, float max, float initialValue, - SeekBar::Orientation hv = SeekBar::Holizontal, - uint32_t thumbColor = 0xFFB0B0FF, - uint16_t thumbSize = 30, uint16_t width = 4, - uint32_t colorL = LCD_COLOR_LIGHTGRAY, - uint32_t colorH = 0xFFB0B0B0, - uint32_t backColor = GuiBase::ENUM_BACK); - - virtual ~SeekbarGroup() - { for (int n=0; n<NUMBER_; n++) delete seekBars_[n]; } - - bool Slide(int num) { return seekBars_[num]->Slide(); } - float GetValue(int num) { return seekBars_[num]->GetValue(); } - int GetIntValue(int num) { return seekBars_[num]->GetIntValue(); } - - // Get slided number - bool GetSlidedNumber(int &num); - - void Draw(int num, float value, bool fill = false) - { seekBars_[num]->Draw(value, fill); } - - // Draw all thumbs with same value - void DrawAll(float value, bool fill = false) - { for (int n=0; n<NUMBER_; n++) Draw(n, value, fill); } - - void Redraw(int num, bool fill = false) - { seekBars_[num]->Draw(seekBars_[num]->GetValue(), fill); } - - void RedrawAll(bool fill = false) - { for (int n=0; n<NUMBER_; n++) Redraw(n, fill); } - - // Activate and inactivate - void Activate(int num) { seekBars_[num]->Activate(); } - void Inactivate(int num) { seekBars_[num]->Inactivate(); } - void ActivateAll() - { - for (int n=0; n<NUMBER_; n++) - seekBars_[n]->Activate(); - } - void InactivateAll() - { - for (int n=0; n<NUMBER_; n++) - seekBars_[n]->Inactivate(); - } - - private: - const int NUMBER_; - Array<SeekBar *> seekBars_; - - // Check range of argument - bool Range(int n) - { return ((n >= 0) && (n < NUMBER_)); } - - // disallow copy constructor and assignment operator - SeekbarGroup(const SeekbarGroup&); - SeekbarGroup& operator=(const SeekbarGroup&); - }; -} -#endif // F746_SEEKBAR_GROUP_HPP -
diff -r f00cf31ae154 -r c27b3361dbbb F746_Gui_New/TS_DISCO_F746NG.lib --- a/F746_Gui_New/TS_DISCO_F746NG.lib Sat Mar 10 11:37:33 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -https://developer.mbed.org/teams/ST/code/TS_DISCO_F746NG/#fe0cf5e2960f
diff -r f00cf31ae154 -r c27b3361dbbb main.cpp --- a/main.cpp Sat Mar 10 11:37:33 2018 +0000 +++ b/main.cpp Mon Mar 12 04:31:12 2018 +0000 @@ -5,7 +5,7 @@ // ライブラリ F746_GUI のリビジョンが 32 の場合,中に含まれる // BSP_DISCO_F746NG はリビジョン 9 に更新すること // -// 2018/03/09, Copyright (c) 2018 MIKAMI, Naoki +// 2018/03/12, Copyright (c) 2018 MIKAMI, Naoki //------------------------------------------------------------ #include "F746_GUI.hpp" // GUI 用のライブラリのインクルード文をまとめたもの @@ -13,7 +13,7 @@ // SeekBar と ResetButton を使う例 void Slider() { - GuiBase::GetLcd().Clear(GuiBase::ENUM_BACK); // 画面のクリア + GuiBase::Clear(); // 画面のクリア // リセットボタンのオブジェクト生成 ResetButton myReset;