Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: F746_SpectralAnalysis_NoPhoto F746_Fourier_series_of_square_wave_01 F746_ButtonGroup_Demo F746_Mandelbrot ... more
Revision 13:af578b53ff0e, committed 2016-02-22
- Comitter:
- MikamiUitOpen
- Date:
- Mon Feb 22 13:39:32 2016 +0000
- Parent:
- 12:710078d50d9b
- Commit message:
- 14
Changed in this revision
--- a/button.cpp Thu Feb 18 10:04:20 2016 +0000
+++ b/button.cpp Mon Feb 22 13:39:32 2016 +0000
@@ -1,7 +1,8 @@
//-----------------------------------------------------------
-// Button class coping with multi-touch
+// Button class handling multi-touch
+// Multi-touch: Enabled (default)
//
-// 2016/02/18, Copyright (c) 2016 MIKAMI, Naoki
+// 2016/02/22, Copyright (c) 2016 MIKAMI, Naoki
//-----------------------------------------------------------
#include "button.hpp"
@@ -31,20 +32,9 @@
// Check touch detected
bool Button::Touched()
{
- bool rtn = false;
- TS_StateTypeDef state;
- ts_.GetState(&state);
-
- for (int n=0; n<state.touchDetected; n++)
- {
- uint16_t x = state.touchX[n];
- uint16_t y = state.touchY[n];
-
- if ( (X_ <= x) && (x <= X_+W_) &&
- (Y_ <= y) && (y <= Y_+H_) ) rtn = true;
- if (rtn) break;
- }
- return rtn;
+ ts_.GetState(&state_);
+ if (!state_.touchDetected) return false;
+ return IsOnButton();
}
// Check touch detected and redraw button
@@ -54,4 +44,29 @@
if (rtn) Draw(color, textColor);
return rtn;
}
+
+ // If panel touched, return true
+ bool Button::PanelTouched()
+ {
+ ts_.GetState(&state_);
+ return (bool)(state_.touchDetected);
+ }
+
+ // 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;
+ }
+
+ TS_StateTypeDef Button::state_;
+ bool Button::multiTouch = true;
}
--- a/button.hpp Thu Feb 18 10:04:20 2016 +0000
+++ b/button.hpp Mon Feb 22 13:39:32 2016 +0000
@@ -1,7 +1,8 @@
//-----------------------------------------------------------
-// Button class coping with multi-touch -- Header
+// Button class handling multi-touch -- Header
+// Multi-touch: Enabled (default)
//
-// 2016/02/18, Copyright (c) 2016 MIKAMI, Naoki
+// 2016/02/22, Copyright (c) 2016 MIKAMI, Naoki
//-----------------------------------------------------------
#ifndef F746_BUTTON_HPP
@@ -36,7 +37,7 @@
void Redraw(uint32_t textColor = LCD_COLOR_WHITE)
{ Draw(ORIGINAL_COLOR_, textColor); }
- // Erase button with selected color
+ // Erase button
void Erase()
{ Draw(BACK_COLOR_, BACK_COLOR_); }
@@ -48,10 +49,21 @@
// Get original color
uint32_t GetOriginalColor() { return ORIGINAL_COLOR_; }
+
+ bool PanelTouched();
+ bool IsOnButton();
+
+ // Get previously got state
+ static TS_StateTypeDef GottenState()
+ { return state_; }
+
+ // Set or reset multi-touch
+ static void SetMultiTouch(bool tf) { multiTouch = tf; }
private:
LCD_DISCO_F746NG &lcd_;
TS_DISCO_F746NG &ts_;
+
const uint16_t X_, Y_, W_, H_;
const uint32_t ORIGINAL_COLOR_; // original color
const uint32_t BACK_COLOR_; // back color of screen
@@ -60,6 +72,9 @@
const uint16_t FONT_WIDTH_;
const uint16_t FONT_HEIGHT_;
+ static TS_StateTypeDef state_;
+ static bool multiTouch;
+
// disallow copy constructor and assignment operator
Button(const Button&);
Button& operator=(const Button&);
--- a/button_group.cpp Thu Feb 18 10:04:20 2016 +0000
+++ b/button_group.cpp Mon Feb 22 13:39:32 2016 +0000
@@ -1,7 +1,7 @@
//-----------------------------------------------------------
// Button group class
//
-// 2016/02/17, Copyright (c) 2016 MIKAMI, Naoki
+// 2016/02/22, Copyright (c) 2016 MIKAMI, Naoki
//-----------------------------------------------------------
#include "button_group.hpp"
@@ -17,7 +17,7 @@
uint16_t spaceX, uint16_t spaceY,
uint16_t column,
sFONT &fonts, uint32_t textColor)
- : numberOfButtons_(number)
+ : numberOfButtons_(number), touchedNum_(-1)
{
buttons_ = new Button *[number];
for (int n=0; n<number; n++)
@@ -38,6 +38,15 @@
delete[] *buttons_;
}
+ // Draw button
+ bool ButtonGroup::Draw(int num, uint32_t color, uint32_t textColor)
+ {
+ if (!Range(num)) return false;
+ buttons_[num]->Draw(color, textColor);
+ touchedNum_ = num;
+ return true;
+ }
+
// Redraw button with original color
bool ButtonGroup::Redraw(int num, uint32_t textColor)
{
@@ -58,7 +67,9 @@
bool ButtonGroup::Touched(int num)
{
if (!Range(num)) return false;
- return buttons_[num]->Touched();
+ bool touched = buttons_[num]->Touched();
+ if (touched) touchedNum_ = num;
+ return touched;
}
// Check touch detected for specified button and redraw
@@ -66,26 +77,31 @@
uint32_t textColor)
{
if (!Range(num)) return false;
- if (buttons_[num]->Touched(color, textColor))
+ bool touched = buttons_[num]->Touched(color, textColor);
+ if (touched)
{
- for (int n=0; n<numberOfButtons_; n++)
- if (n != num) buttons_[n]->Redraw();
- return true;
+ if (Range(touchedNum_) && (num != touchedNum_))
+ buttons_[touchedNum_]->Redraw();
+ touchedNum_ = num;
}
- else
- return false;
+ return touched;
}
// Get touched number
bool ButtonGroup::GetTouchedNumber(int &num)
{
- for (int n=0; n<numberOfButtons_; n++)
- if (buttons_[n]->Touched())
- {
- num = n;
- return true;
- }
- return false;
+ if (buttons_[0]->PanelTouched())
+ {
+ for (int n=0; n<numberOfButtons_; n++)
+ if (buttons_[n]->IsOnButton())
+ {
+ num = n;
+ return true;
+ }
+ return false;
+ }
+ else
+ return false;
}
// Get touched number and redraw button if touched
@@ -93,23 +109,13 @@
{
if (GetTouchedNumber(num))
{
- for (int n=0; n<numberOfButtons_; n++)
- if (n == num)
- buttons_[n]->Draw(color);
- else
- buttons_[n]->Redraw();
- return true;
+ buttons_[num]->Draw(color);
+ if (Range(touchedNum_) && (num != touchedNum_))
+ buttons_[touchedNum_]->Redraw();
+ touchedNum_ = num;
+ return true;
}
else
return false;
}
-
- // Check range of argument
- bool ButtonGroup::Range(int n)
- {
- if ( (n >= 0) && (n < numberOfButtons_) )
- return true;
- else
- return false;
- }
}
--- a/button_group.hpp Thu Feb 18 10:04:20 2016 +0000
+++ b/button_group.hpp Mon Feb 22 13:39:32 2016 +0000
@@ -1,7 +1,7 @@
//-----------------------------------------------------------
// Button group class -- Header
//
-// 2016/02/17, Copyright (c) 2016 MIKAMI, Naoki
+// 2016/02/22, Copyright (c) 2016 MIKAMI, Naoki
//-----------------------------------------------------------
#ifndef F746_BUTTON_GROUP_HPP
@@ -30,9 +30,8 @@
~ButtonGroup();
// Draw button
- void Draw(int num, uint32_t color,
- uint32_t textColor = LCD_COLOR_WHITE)
- { buttons_[num]->Draw(color, textColor); }
+ bool Draw(int num, uint32_t color,
+ uint32_t textColor = LCD_COLOR_WHITE);
// Draw all buttons
void DrawAll(uint32_t color,
@@ -64,9 +63,11 @@
private:
Button **buttons_;
int numberOfButtons_;
+ int touchedNum_;
// Check range of argument
- bool Range(int n);
+ bool Range(int n)
+ { return ((n >= 0) && (n < numberOfButtons_)); }
// disallow copy constructor and assignment operator
ButtonGroup(const ButtonGroup&);