不韋 呂 / F746_MySoundMachine

Dependencies:   F746_GUI F746_SAI_IO FrequencyResponseDrawer SD_PlayerSkeleton UIT_FFT_Real

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers TouchPanelDetectorX.hpp Source File

TouchPanelDetectorX.hpp

00001 //------------------------------------------------------
00002 //  Touch panel detector for x axis class
00003 //
00004 //  2016/03/31, Copyright (c) 2016 MIKAMI, Naoki
00005 //------------------------------------------------------
00006 
00007 #ifndef F746_TOUCH_PANELDETECTORX_HPP
00008 #define F746_TOUCH_PANELDETECTORX_HPP
00009 
00010 #include "GuiBase.hpp"
00011 
00012 namespace Mikami
00013 {
00014     class TouchPanelDetectorX : public GuiBase
00015     {
00016     public:
00017         // Constructor
00018         TouchPanelDetectorX(uint16_t x1, uint16_t x2,
00019                             uint16_t y1, uint16_t y2)
00020             : X1_(x1), X2_(x2), Y1_(y1), Y2_(y2) {}
00021 
00022         bool IsTouched(uint16_t xIn, uint16_t &xOut)
00023         {
00024             GetTsState();
00025             
00026             if (!state_.touchDetected) return false;
00027             
00028             uint16_t x = state_.touchX[0];
00029             uint16_t y = state_.touchY[0];
00030 
00031             if ( (x < X1_) || (x > X2_) || (y < Y1_) || (y > Y2_) )
00032                 return false;
00033 
00034             const int WD = 8;
00035             if ( (x < xIn-WD) || (x > xIn+WD) ) return false;
00036             
00037             xOut = (x >= X1_) ? x : X1_;
00038             xOut = (x <= X2_) ? x : X2_;
00039             return true;
00040         }
00041 
00042     private:
00043         const uint16_t X1_, X2_, Y1_, Y2_;
00044     };
00045 }   
00046 #endif  // F746_TOUCH_PANELDETECTORX_HPP