1 /***************************************************************************** 2 * 3 * mtdev - Multitouch Protocol Translation Library (MIT license) 4 * 5 * Copyright (C) 2010 Henrik Rydberg <rydberg@euromail.se> 6 * Copyright (C) 2010 Canonical Ltd. 7 * 8 * Permission is hereby granted, free of charge, to any person obtaining a 9 * copy of this software and associated documentation files (the "Software"), 10 * to deal in the Software without restriction, including without limitation 11 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 12 * and/or sell copies of the Software, and to permit persons to whom the 13 * Software is furnished to do so, subject to the following conditions: 14 * 15 * The above copyright notice and this permission notice (including the next 16 * paragraph) shall be included in all copies or substantial portions of the 17 * Software. 18 * 19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 22 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 * DEALINGS IN THE SOFTWARE. 26 * 27 ****************************************************************************/ 28 29 #ifndef _MTDEV_PLUMBING_H 30 #define _MTDEV_PLUMBING_H 31 32 #ifdef __cplusplus 33 extern "C" { 34 #endif 35 36 #include <mtdev.h> 37 38 /** 39 * mtdev_new - allocate a new mtdev 40 * 41 * Allocate a new mtdev. 42 * 43 * Returns zero in case of memory allocation failure. 44 */ 45 struct mtdev *mtdev_new(void); 46 47 /** 48 * mtdev_init - initialize mtdev converter 49 * @dev: the mtdev to initialize 50 * 51 * Sets up the internal data structures. 52 * 53 * Returns zero on success, negative error number otherwise. 54 */ 55 int mtdev_init(struct mtdev *dev); 56 57 /** 58 * mtdev_set_mt_event - set event type 59 * @dev: the mtdev in use 60 * @code: the ABS_MT code to set 61 * @value: boolean value 62 * 63 * Returns true if the given event code is present. 64 */ 65 void mtdev_set_mt_event(struct mtdev *dev, int code, int value); 66 67 /** 68 * mtdev_set_abs_<property> - set abs event property 69 * @dev: the mtdev in use 70 * @code: the ABS_MT code to set 71 */ 72 void mtdev_set_abs_minimum(struct mtdev *dev, int code, int value); 73 void mtdev_set_abs_maximum(struct mtdev *dev, int code, int value); 74 void mtdev_set_abs_fuzz(struct mtdev *dev, int code, int value); 75 void mtdev_set_abs_resolution(struct mtdev *dev, int code, int value); 76 77 /** 78 * mtdev_configure - configure the mtdev converter 79 * @dev: the mtdev to configure 80 * @fd: file descriptor of the kernel device 81 * 82 * Reads the device properties to set up the protocol capabilities. 83 * If preferred, this can be done by hand, omitting this call. 84 * 85 * Returns zero on success, negative error number otherwise. 86 */ 87 int mtdev_configure(struct mtdev *dev, int fd); 88 89 /** 90 * mtdev_fetch_event - fetch an event from the kernel device 91 * @dev: the mtdev in use 92 * @fd: file descriptor of the kernel device 93 * @ev: the kernel input event to fill 94 * 95 * Fetch a kernel event from the kernel device. The read operation 96 * behaves as dictated by the file descriptor; if O_NONBLOCK is not 97 * set, the read will block until an event is available. 98 * 99 * On success, returns the number of events read (0 or 1). Otherwise, 100 * a standard negative error number is returned. 101 */ 102 int mtdev_fetch_event(struct mtdev *dev, int fd, struct input_event *ev); 103 104 /** 105 * mtdev_put_event - put an event into the converter 106 * @dev: the mtdev in use 107 * @ev: the kernel input event to put 108 * 109 * Put a kernel event into the mtdev converter. The event should 110 * come straight from the device. 111 * 112 * This call does not block; if the buffer becomes full, older events 113 * are dropped. The buffer is guaranteed to handle several complete MT 114 * packets. 115 */ 116 void mtdev_put_event(struct mtdev *dev, const struct input_event *ev); 117 118 /** 119 * mtdev_empty - check if there are events to get 120 * @dev: the mtdev in use 121 * 122 * Returns true if the processed event queue is empty, false otherwise. 123 */ 124 int mtdev_empty(struct mtdev *dev); 125 126 /** 127 * mtdev_get_event - get processed events from mtdev 128 * @dev: the mtdev in use 129 * @ev: the input event to fill 130 * 131 * Get a processed event from mtdev. The events appear as if they came 132 * from a type B device emitting MT slot events. 133 * 134 * The queue must be non-empty before calling this function. 135 */ 136 void mtdev_get_event(struct mtdev *dev, struct input_event* ev); 137 138 /** 139 * mtdev_delete - free a previously allocated mtdev 140 * 141 * Frees the memory associated with the mtdev and invalidates the 142 * mtdev pointer. 143 */ 144 void mtdev_delete(struct mtdev *dev); 145 146 #ifdef __cplusplus 147 } 148 #endif 149 150 #endif 151