touch screen handler for the microchip AR1020

Committer:
hlipka
Date:
Thu Feb 24 22:05:04 2011 +0000
Revision:
6:a6971458d612
Parent:
4:510ea5b28a05
calibration works now

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hlipka 4:510ea5b28a05 1 /*
hlipka 4:510ea5b28a05 2 * mbed AR1020 library
hlipka 4:510ea5b28a05 3 * Copyright (c) 2010 Hendrik Lipka
hlipka 4:510ea5b28a05 4 *
hlipka 4:510ea5b28a05 5 * Permission is hereby granted, free of charge, to any person obtaining a copy
hlipka 4:510ea5b28a05 6 * of this software and associated documentation files (the "Software"), to deal
hlipka 4:510ea5b28a05 7 * in the Software without restriction, including without limitation the rights
hlipka 4:510ea5b28a05 8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
hlipka 4:510ea5b28a05 9 * copies of the Software, and to permit persons to whom the Software is
hlipka 4:510ea5b28a05 10 * furnished to do so, subject to the following conditions:
hlipka 4:510ea5b28a05 11 *
hlipka 4:510ea5b28a05 12 * The above copyright notice and this permission notice shall be included in
hlipka 4:510ea5b28a05 13 * all copies or substantial portions of the Software.
hlipka 4:510ea5b28a05 14 *
hlipka 4:510ea5b28a05 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
hlipka 4:510ea5b28a05 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
hlipka 4:510ea5b28a05 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
hlipka 4:510ea5b28a05 18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
hlipka 4:510ea5b28a05 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
hlipka 4:510ea5b28a05 20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
hlipka 4:510ea5b28a05 21 * THE SOFTWARE.
hlipka 4:510ea5b28a05 22 */
hlipka 4:510ea5b28a05 23
hlipka 4:510ea5b28a05 24 #ifndef __AREATOUCHHANDLER_H__
hlipka 4:510ea5b28a05 25 #define __AREATOUCHHANDLER_H__
hlipka 4:510ea5b28a05 26
hlipka 4:510ea5b28a05 27 #include "mbed.h"
hlipka 4:510ea5b28a05 28 #include "FPointer.h"
hlipka 4:510ea5b28a05 29 #include "touchpanel.h"
hlipka 4:510ea5b28a05 30 #include <list>
hlipka 4:510ea5b28a05 31
hlipka 4:510ea5b28a05 32 class area;
hlipka 4:510ea5b28a05 33
hlipka 4:510ea5b28a05 34 /**
hlipka 4:510ea5b28a05 35 this class registers itself with a touch screen controller, and listens for touch events.
hlipka 4:510ea5b28a05 36 If an event matches a prefined region, the callback function is called with the corresponding command code.
hlipka 4:510ea5b28a05 37 */
hlipka 4:510ea5b28a05 38 class AreaTouchHandler
hlipka 4:510ea5b28a05 39 {
hlipka 4:510ea5b28a05 40 public:
hlipka 4:510ea5b28a05 41 /**
hlipka 4:510ea5b28a05 42 creates the handler, and attaches it to the given touch panel
hlipka 4:510ea5b28a05 43 @params pane the touch panel to listen to
hlipka 4:510ea5b28a05 44 */
hlipka 4:510ea5b28a05 45 AreaTouchHandler(TouchPanel* panel);
hlipka 4:510ea5b28a05 46 /**
hlipka 4:510ea5b28a05 47 set the callback method
hlipka 4:510ea5b28a05 48 @params item the callback object
hlipka 4:510ea5b28a05 49 @params method the callback method
hlipka 4:510ea5b28a05 50 */
hlipka 4:510ea5b28a05 51 class T;
hlipka 4:510ea5b28a05 52 template<class T>
hlipka 4:510ea5b28a05 53 void attach(T* item, uint32_t (T::*method)(uint32_t)) { _callback.attach(item, method); }
hlipka 4:510ea5b28a05 54 /**
hlipka 4:510ea5b28a05 55 set the callback method
hlipka 4:510ea5b28a05 56 @params function the callback function
hlipka 4:510ea5b28a05 57 */
hlipka 4:510ea5b28a05 58 void attach(uint32_t (*function)(uint32_t)) { _callback.attach(function); }
hlipka 4:510ea5b28a05 59
hlipka 4:510ea5b28a05 60 /**
hlipka 4:510ea5b28a05 61 defines the command for a specific region
hlipka 4:510ea5b28a05 62 @params top the top of the region (y)
hlipka 4:510ea5b28a05 63 @params bottom the bottom of the region (y)
hlipka 4:510ea5b28a05 64 @params the left side of the region (x)
hlipka 4:510ea5b28a05 65 @params the right side of the region (x)
hlipka 4:510ea5b28a05 66 @params the command code for this region
hlipka 4:510ea5b28a05 67 */
hlipka 4:510ea5b28a05 68 void addArea(int top, int bottom, int left, int right, int commandCode);
hlipka 4:510ea5b28a05 69 private:
hlipka 4:510ea5b28a05 70 FPointer _callback;
hlipka 4:510ea5b28a05 71 std::list<area*> _areas;
hlipka 4:510ea5b28a05 72 uint32_t down(uint32_t arg);
hlipka 4:510ea5b28a05 73 uint32_t move(uint32_t arg);
hlipka 4:510ea5b28a05 74 uint32_t up(uint32_t arg);
hlipka 4:510ea5b28a05 75
hlipka 4:510ea5b28a05 76 int findCommand();
hlipka 4:510ea5b28a05 77
hlipka 4:510ea5b28a05 78 float _x, _y;
hlipka 4:510ea5b28a05 79 int _samples;
hlipka 4:510ea5b28a05 80 bool _called;
hlipka 4:510ea5b28a05 81 };
hlipka 4:510ea5b28a05 82
hlipka 4:510ea5b28a05 83
hlipka 4:510ea5b28a05 84 #endif