touch screen handler for the microchip AR1020

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers AreaTouchHandler.h Source File

AreaTouchHandler.h

00001 /*
00002 * mbed AR1020 library
00003 * Copyright (c) 2010 Hendrik Lipka
00004 *
00005 * Permission is hereby granted, free of charge, to any person obtaining a copy
00006 * of this software and associated documentation files (the "Software"), to deal
00007 * in the Software without restriction, including without limitation the rights
00008 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00009 * copies of the Software, and to permit persons to whom the Software is
00010 * furnished to do so, subject to the following conditions:
00011 *
00012 * The above copyright notice and this permission notice shall be included in
00013 * all copies or substantial portions of the Software.
00014 *
00015 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00016 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00017 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00018 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00019 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00020 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00021 * THE SOFTWARE.
00022 */
00023 
00024 #ifndef __AREATOUCHHANDLER_H__
00025 #define __AREATOUCHHANDLER_H__
00026 
00027 #include "mbed.h"
00028 #include "FPointer.h"
00029 #include "touchpanel.h"
00030 #include <list>
00031 
00032 class area;
00033 
00034 /**
00035     this class registers itself with a touch screen controller, and listens for touch events. 
00036     If an event matches a prefined region, the callback function is called with the corresponding command code.
00037 */
00038 class AreaTouchHandler
00039 {
00040     public:
00041         /**
00042             creates the handler, and attaches it to the given touch panel
00043             @params pane the touch panel to listen to
00044         */
00045         AreaTouchHandler(TouchPanel* panel);
00046         /**
00047             set the callback method        
00048             @params item the callback object
00049             @params method the callback method
00050         */
00051         class T;
00052         template<class T> 
00053         void attach(T* item, uint32_t (T::*method)(uint32_t)) { _callback.attach(item, method); }   
00054         /**
00055             set the callback method        
00056             @params function the callback function
00057         */
00058         void attach(uint32_t (*function)(uint32_t)) { _callback.attach(function); }   
00059 
00060         /**
00061             defines the command for a specific region
00062             @params top the top of the region (y)
00063             @params bottom the bottom of the region (y)
00064             @params the left side of the region (x)
00065             @params the right side of the region (x)
00066             @params the command code for this region
00067         */        
00068         void addArea(int top, int bottom, int left, int right, int commandCode);
00069     private:
00070         FPointer      _callback;
00071         std::list<area*> _areas;
00072         uint32_t down(uint32_t arg);
00073         uint32_t move(uint32_t arg);
00074         uint32_t up(uint32_t arg);
00075         
00076         int findCommand();
00077         
00078         float _x, _y;
00079         int _samples;
00080         bool _called;
00081 };
00082 
00083 
00084 #endif