![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Chapter003_TRobot
Dependencies: F746_GUI Array_Matrix TS_DISCO_F746NG mbed LCD_DISCO_F746NG BSP_DISCO_F746NG SDFileSystem_Warning_Fixed FrequencyResponseDrawer F746_SAI_IO
MyClasses_Functions/TouchPanelDetectorX.hpp@12:fde5056cec5c, 2019-04-01 (annotated)
- Committer:
- SanYune
- Date:
- Mon Apr 01 06:43:07 2019 +0000
- Revision:
- 12:fde5056cec5c
- Parent:
- 0:04b43b777fae
Chapter003_TRobot
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 0:04b43b777fae | 1 | //------------------------------------------------------ |
MikamiUitOpen | 0:04b43b777fae | 2 | // Touch panel detector for x axis class |
MikamiUitOpen | 0:04b43b777fae | 3 | // |
MikamiUitOpen | 0:04b43b777fae | 4 | // 2016/03/31, Copyright (c) 2016 MIKAMI, Naoki |
MikamiUitOpen | 0:04b43b777fae | 5 | //------------------------------------------------------ |
MikamiUitOpen | 0:04b43b777fae | 6 | |
MikamiUitOpen | 0:04b43b777fae | 7 | #ifndef F746_TOUCH_PANELDETECTORX_HPP |
MikamiUitOpen | 0:04b43b777fae | 8 | #define F746_TOUCH_PANELDETECTORX_HPP |
MikamiUitOpen | 0:04b43b777fae | 9 | |
MikamiUitOpen | 0:04b43b777fae | 10 | #include "GuiBase.hpp" |
MikamiUitOpen | 0:04b43b777fae | 11 | |
MikamiUitOpen | 0:04b43b777fae | 12 | namespace Mikami |
MikamiUitOpen | 0:04b43b777fae | 13 | { |
MikamiUitOpen | 0:04b43b777fae | 14 | class TouchPanelDetectorX : public GuiBase |
MikamiUitOpen | 0:04b43b777fae | 15 | { |
MikamiUitOpen | 0:04b43b777fae | 16 | public: |
MikamiUitOpen | 0:04b43b777fae | 17 | // Constructor |
MikamiUitOpen | 0:04b43b777fae | 18 | TouchPanelDetectorX(uint16_t x1, uint16_t x2, |
MikamiUitOpen | 0:04b43b777fae | 19 | uint16_t y1, uint16_t y2) |
MikamiUitOpen | 0:04b43b777fae | 20 | : X1_(x1), X2_(x2), Y1_(y1), Y2_(y2) {} |
MikamiUitOpen | 0:04b43b777fae | 21 | |
MikamiUitOpen | 0:04b43b777fae | 22 | bool IsTouched(uint16_t xIn, uint16_t &xOut) |
MikamiUitOpen | 0:04b43b777fae | 23 | { |
MikamiUitOpen | 0:04b43b777fae | 24 | GetTsState(); |
MikamiUitOpen | 0:04b43b777fae | 25 | |
MikamiUitOpen | 0:04b43b777fae | 26 | if (!state_.touchDetected) return false; |
MikamiUitOpen | 0:04b43b777fae | 27 | |
MikamiUitOpen | 0:04b43b777fae | 28 | uint16_t x = state_.touchX[0]; |
MikamiUitOpen | 0:04b43b777fae | 29 | uint16_t y = state_.touchY[0]; |
MikamiUitOpen | 0:04b43b777fae | 30 | |
MikamiUitOpen | 0:04b43b777fae | 31 | if ( (x < X1_) || (x > X2_) || (y < Y1_) || (y > Y2_) ) |
MikamiUitOpen | 0:04b43b777fae | 32 | return false; |
MikamiUitOpen | 0:04b43b777fae | 33 | |
MikamiUitOpen | 0:04b43b777fae | 34 | const int WD = 8; |
MikamiUitOpen | 0:04b43b777fae | 35 | if ( (x < xIn-WD) || (x > xIn+WD) ) return false; |
MikamiUitOpen | 0:04b43b777fae | 36 | |
MikamiUitOpen | 0:04b43b777fae | 37 | xOut = (x >= X1_) ? x : X1_; |
MikamiUitOpen | 0:04b43b777fae | 38 | xOut = (x <= X2_) ? x : X2_; |
MikamiUitOpen | 0:04b43b777fae | 39 | return true; |
MikamiUitOpen | 0:04b43b777fae | 40 | } |
MikamiUitOpen | 0:04b43b777fae | 41 | |
MikamiUitOpen | 0:04b43b777fae | 42 | private: |
MikamiUitOpen | 0:04b43b777fae | 43 | const uint16_t X1_, X2_, Y1_, Y2_; |
MikamiUitOpen | 0:04b43b777fae | 44 | }; |
MikamiUitOpen | 0:04b43b777fae | 45 | } |
MikamiUitOpen | 0:04b43b777fae | 46 | #endif // F746_TOUCH_PANELDETECTORX_HPP |