-
Notifications
You must be signed in to change notification settings - Fork 27
/
multitouch.h
145 lines (123 loc) · 4.73 KB
/
multitouch.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// Copyright (C) 2009 Fajran Iman Rusadi <[email protected]>
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#ifndef MULTITOUCH_H
#define MULTITOUCH_H
#ifdef __OBJC__
#include <Cocoa/Cocoa.h>
#endif
#include <CoreFoundation/CoreFoundation.h>
#include <IOKit/IOKitLib.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
float x;
float y;
} MTPoint;
typedef struct {
MTPoint position;
MTPoint velocity;
} MTVector;
enum {
MTTouchStateNotTracking = 0,
MTTouchStateStartInRange = 1,
MTTouchStateHoverInRange = 2,
MTTouchStateMakeTouch = 3,
MTTouchStateTouching = 4,
MTTouchStateBreakTouch = 5,
MTTouchStateLingerInRange = 6,
MTTouchStateOutOfRange = 7
};
typedef uint32_t MTTouchState;
typedef struct {
int32_t frame;
double timestamp;
int32_t pathIndex; // "P" (~transducerIndex)
MTTouchState state;
int32_t fingerID; // "F" (~identity)
int32_t handID; // "H" (always 1)
MTVector normalizedVector;
float zTotal; // "ZTot" (~quality, multiple of 1/8 between 0 and 1)
int32_t field9; // always 0
float angle;
float majorAxis;
float minorAxis;
MTVector absoluteVector; // "mm"
int32_t field14; // always 0
int32_t field15; // always 0
float zDensity; // "ZDen" (~density)
} MTTouch;
typedef void* MTDeviceRef;
double MTAbsoluteTimeGetCurrent(void);
bool MTDeviceIsAvailable(void); // true if can create default device
CFArrayRef MTDeviceCreateList(void); // creates for driver types 0, 1, 4, 2, 3
MTDeviceRef MTDeviceCreateDefault(void);
MTDeviceRef MTDeviceCreateFromDeviceID(int64_t);
MTDeviceRef MTDeviceCreateFromService(io_service_t);
MTDeviceRef MTDeviceCreateFromGUID(uuid_t); // GUID's compared by pointer, not value!
void MTDeviceRelease(MTDeviceRef);
CFRunLoopSourceRef MTDeviceCreateMultitouchRunLoopSource(MTDeviceRef);
OSStatus MTDeviceScheduleOnRunLoop(MTDeviceRef, CFRunLoopRef, CFStringRef);
OSStatus MTDeviceStart(MTDeviceRef, int);
OSStatus MTDeviceStop(MTDeviceRef);
bool MTDeviceIsRunning(MTDeviceRef);
bool MTDeviceIsValid(MTDeviceRef);
bool MTDeviceIsBuiltIn(MTDeviceRef) __attribute__ ((weak_import)); // no 10.5
bool MTDeviceIsOpaqueSurface(MTDeviceRef);
io_service_t MTDeviceGetService(MTDeviceRef);
OSStatus MTDeviceGetSensorSurfaceDimensions(MTDeviceRef, int*, int*);
OSStatus MTDeviceGetFamilyID(MTDeviceRef, int*);
OSStatus MTDeviceGetDeviceID(MTDeviceRef, uint64_t*) __attribute__ ((weak_import)); // no 10.5
OSStatus MTDeviceGetDriverType(MTDeviceRef, int*);
OSStatus MTDeviceGetActualType(MTDeviceRef, int*);
OSStatus MTDeviceGetGUID(MTDeviceRef, uuid_t*);
typedef void (*MTFrameCallbackFunction)(MTDeviceRef device,
MTTouch touches[], size_t numTouches,
double timestamp, size_t frame);
void MTRegisterContactFrameCallback(MTDeviceRef, MTFrameCallbackFunction);
void MTUnregisterContactFrameCallback(MTDeviceRef, MTFrameCallbackFunction);
typedef void (*MTPathCallbackFunction)(MTDeviceRef device, long pathID, long state, MTTouch* touch);
//MTPathCallbackFunction MTPathPrintCallback;
void MTRegisterPathCallback(MTDeviceRef, MTPathCallbackFunction);
void MTUnregisterPathCallback(MTDeviceRef, MTPathCallbackFunction);
/*
// callbacks never called (need different flags?)
typedef void (*MTImageCallbackFunction)(MTDeviceRef, void*, void*);
MTImageCallbackFunction MTImagePrintCallback;
void MTRegisterMultitouchImageCallback(MTDeviceRef, MTImageCallbackFunction);
*/
/*
// these log error
void MTVibratorRunForDuration(MTDeviceRef,long);
void MTVibratorStop(MTDeviceRef);
*/
inline const char*
MTTouchStateName(MTTouchState ps) {
switch (ps) {
case MTTouchStateNotTracking: return "NotTracking" ;
case MTTouchStateStartInRange: return "StartInRange" ;
case MTTouchStateHoverInRange: return "HoverInRange" ;
case MTTouchStateMakeTouch: return "MakeTouch" ;
case MTTouchStateTouching: return "Touching" ;
case MTTouchStateBreakTouch: return "BreakTouch" ;
case MTTouchStateLingerInRange: return "LingerInRange" ;
case MTTouchStateOutOfRange: return "OutOfRange" ;
default: return "Unknown" ;
}
}
#ifdef __cplusplus
}
#endif
#endif