~chasedouglas/frame/ubuntu-upstream-xi

« back to all changes in this revision

Viewing changes to tools/common/device.c

  • Committer: Chase Douglas
  • Date: 2011-12-09 01:36:45 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: chase.douglas@ubuntu.com-20111209013645-n24l4myiumblzsfu
* New upstream release.
  - Version 2 adds a new API built on top of XInput multitouch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*****************************************************************************
 
2
 *
 
3
 * utouch-frame - Touch Frame Library
 
4
 *
 
5
 * Copyright (C) 2010-2011 Canonical Ltd.
 
6
 *
 
7
 * This program is free software: you can redistribute it and/or modify it
 
8
 * under the terms of the GNU General Public License as published by the
 
9
 * Free Software Foundation, either version 3 of the License, or (at your
 
10
 * option) any later version.
 
11
 *
 
12
 * This program is distributed in the hope that it will be useful, but
 
13
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
15
 * General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU General Public License along
 
18
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
 *
 
20
 ****************************************************************************/
 
21
 
 
22
#include "common/device.h"
 
23
 
 
24
#include <stdio.h>
 
25
 
 
26
void get_axis_info(UFAxis axis, UFAxisType *type, const char **name, float *min,
 
27
                   float *max, float *res) {
 
28
  *type = frame_axis_get_type(axis);
 
29
 
 
30
  switch (*type) {
 
31
    case UFAxisTypeX:
 
32
      *name = "X";
 
33
      break;
 
34
 
 
35
    case UFAxisTypeY:
 
36
      *name = "Y";
 
37
      break;
 
38
 
 
39
    case UFAxisTypeTouchMajor:
 
40
      *name = "Touch major";
 
41
      break;
 
42
 
 
43
    case UFAxisTypeTouchMinor:
 
44
      *name = "Touch minor";
 
45
      break;
 
46
 
 
47
    case UFAxisTypeWidthMajor:
 
48
      *name = "Width major";
 
49
      break;
 
50
 
 
51
    case UFAxisTypeWidthMinor:
 
52
      *name = "Width minor";
 
53
      break;
 
54
 
 
55
    case UFAxisTypeOrientation:
 
56
      *name = "Orientation";
 
57
      break;
 
58
 
 
59
    case UFAxisTypeTool:
 
60
      *name = "Tool";
 
61
      break;
 
62
 
 
63
    case UFAxisTypeBlobId:
 
64
      *name = "Blob ID";
 
65
      break;
 
66
 
 
67
    case UFAxisTypeTrackingId:
 
68
      *name = "Tracking ID";
 
69
      break;
 
70
 
 
71
    case UFAxisTypePressure:
 
72
      *name = "Pressure";
 
73
      break;
 
74
 
 
75
    case UFAxisTypeDistance:
 
76
      *name = "Distance";
 
77
      break;
 
78
 
 
79
    default:
 
80
      *name = "Unknown";
 
81
      break;
 
82
  }
 
83
 
 
84
  *min = frame_axis_get_minimum(axis);
 
85
  *max = frame_axis_get_maximum(axis);
 
86
  *res = frame_axis_get_resolution(axis);
 
87
}
 
88
 
 
89
void print_device_added(UFHandle handle, UFEvent event) {
 
90
  UFDevice device;
 
91
  char *string = NULL;
 
92
  UFStatus status;
 
93
  int num_axes = 0;
 
94
  int integer;
 
95
  int i;
 
96
 
 
97
  status = frame_event_get_property(event, UFEventPropertyDevice, &device);
 
98
  if (status != UFStatusSuccess) {
 
99
    fprintf(stderr, "Error: failed to get device from event\n");
 
100
    return;
 
101
  }
 
102
    
 
103
  printf("Device added:\n");
 
104
 
 
105
  printf("  Time: %ju ms\n", frame_event_get_time(event));
 
106
 
 
107
  status = frame_device_get_property(device, UFDevicePropertyName, &string);
 
108
  if (status != UFStatusSuccess)
 
109
    fprintf(stderr, "Error: failed to get name from device\n");
 
110
  else
 
111
    printf("  Name: %s\n", string);
 
112
 
 
113
  status = frame_device_get_property(device, UFDevicePropertyDirect, &integer);
 
114
  if (status != UFStatusSuccess)
 
115
    fprintf(stderr, "Error: failed to get direct property from device\n");
 
116
  else
 
117
    printf("  Direct: %s\n", integer ? "yes" : "no");
 
118
 
 
119
  status = frame_device_get_property(device, UFDevicePropertyIndependent,
 
120
                                     &integer);
 
121
  if (status != UFStatusSuccess)
 
122
    fprintf(stderr, "Error: failed to get independent property from device\n");
 
123
  else
 
124
    printf("  Independent: %s\n", integer ? "yes" : "no");
 
125
 
 
126
  status = frame_device_get_property(device, UFDevicePropertySemiMT, &integer);
 
127
  if (status != UFStatusSuccess)
 
128
    fprintf(stderr, "Error: failed to get semi-MT property from device\n");
 
129
  else
 
130
    printf("  Semi-MT: %s\n", integer ? "yes" : "no");
 
131
 
 
132
  status = frame_device_get_property(device, UFDevicePropertyMaxTouches,
 
133
                                     &integer);
 
134
  if (status != UFStatusSuccess)
 
135
    fprintf(stderr, "Error: failed to get max touches from device\n");
 
136
  else
 
137
    printf("  Maximum touches: %d\n", integer);
 
138
 
 
139
  num_axes = frame_device_get_num_axes(device);
 
140
  printf("  Number of axes: %d\n", num_axes);
 
141
 
 
142
  for (i = 0; i < num_axes; ++i) {
 
143
    UFAxis axis;
 
144
    UFAxisType type;
 
145
    const char *name;
 
146
    float min;
 
147
    float max;
 
148
    float res;
 
149
 
 
150
    printf("  Axis %d:\n", i);
 
151
 
 
152
    status = frame_device_get_axis_by_index(device, i, &axis);
 
153
    if (status != UFStatusSuccess) {
 
154
      fprintf(stderr, "Error: failed to get axis %d from device\n", i);
 
155
      continue;
 
156
    }
 
157
 
 
158
    get_axis_info(axis, &type, &name, &min, &max, &res);
 
159
    printf("    Type: %s\n", name);
 
160
    printf("    Minimum: %f\n", min);
 
161
    printf("    Maximum: %f\n", max);
 
162
    printf("    Resolution: %f\n", res);
 
163
  }
 
164
 
 
165
  printf("\n");
 
166
}
 
167
 
 
168
void print_device_removed(UFHandle handle, UFEvent event) {
 
169
  UFDevice device;
 
170
  char *string = NULL;
 
171
  UFStatus status;
 
172
 
 
173
  status = frame_event_get_property(event, UFEventPropertyDevice, &device);
 
174
  if (status != UFStatusSuccess) {
 
175
    fprintf(stderr, "Error: failed to get device from event\n");
 
176
    return;
 
177
  }
 
178
    
 
179
  printf("Device removed:\n");
 
180
 
 
181
  printf("  Time: %ju ms\n", frame_event_get_time(event));
 
182
 
 
183
  status = frame_device_get_property(device, UFDevicePropertyName, &string);
 
184
  if (status != UFStatusSuccess)
 
185
    fprintf(stderr, "Error: failed to get name from device\n");
 
186
  else
 
187
    printf("  Name: %s\n", string);
 
188
}