94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
-
+
+
|
}
return nil;
}
@implementation OFGameController
@synthesize name = _name, buttons = _buttons;
@synthesize numAnalogSticks = _numAnalogSticks;
@synthesize hasLeftAnalogStick = _hasLeftAnalogStick;
@synthesize hasRightAnalogStick = _hasRightAnalogStick;
+ (OFArray OF_GENERIC(OFGameController *) *)controllers
{
OFMutableArray *controllers = [OFMutableArray array];
void *pool = objc_autoreleasePoolPush();
for (OFString *device in [[OFFileManager defaultManager]
|
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
-
-
+
+
-
-
-
+
+
+
-
|
if (OFBitSetIsSet(evBits, EV_ABS)) {
if (ioctl(_fd, EVIOCGBIT(EV_ABS, sizeof(absBits)),
absBits) == -1)
@throw [OFInitializationFailedException
exception];
if (OFBitSetIsSet(absBits, ABS_X) &&
OFBitSetIsSet(absBits, ABS_Y)) {
_numAnalogSticks++;
OFBitSetIsSet(absBits, ABS_Y))
_hasLeftAnalogStick = true;
if (OFBitSetIsSet(absBits, ABS_RX) &&
OFBitSetIsSet(absBits, ABS_RY))
_numAnalogSticks++;
if (OFBitSetIsSet(absBits, ABS_RX) &&
OFBitSetIsSet(absBits, ABS_RY))
_hasRightAnalogStick = true;
}
if (OFBitSetIsSet(absBits, ABS_HAT0X) &&
OFBitSetIsSet(absBits, ABS_HAT0Y)) {
[_buttons addObject: @"D-Pad Left"];
[_buttons addObject: @"D-Pad Right"];
[_buttons addObject: @"D-Pad Up"];
[_buttons addObject: @"D-Pad Down"];
|
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
|
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
|
-
+
-
+
-
+
-
+
|
else
[_pressedButtons removeObject:
buttonToName(event.code)];
break;
case EV_ABS:
switch (event.code) {
case ABS_X:
_analogStickPositions[0].x =
_leftAnalogStickPosition.x =
(float)event.value /
(event.value < 0 ? -INT16_MIN : INT16_MAX);
break;
case ABS_Y:
_analogStickPositions[0].y =
_leftAnalogStickPosition.y =
(float)event.value /
(event.value < 0 ? -INT16_MIN : INT16_MAX);
break;
case ABS_RX:
_analogStickPositions[1].x =
_rightAnalogStickPosition.x =
(float)event.value /
(event.value < 0 ? -INT16_MIN : INT16_MAX);
break;
case ABS_RY:
_analogStickPositions[1].y =
_rightAnalogStickPosition.y =
(float)event.value /
(event.value < 0 ? -INT16_MIN : INT16_MAX);
break;
case ABS_HAT0X:
if (event.value < 0) {
[_pressedButtons addObject:
@"D-Pad Left"];
|
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
|
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
|
-
-
+
+
-
+
-
-
-
-
-
+
+
+
+
+
+
|
return OFOrderedSame;
}
- (OFSet *)pressedButtons
{
[self of_processEvents];
return [[_pressedButtons copy] autorelease];
}
- (OFPoint)positionOfAnalogStickWithIndex: (size_t)index
- (OFPoint)leftAnalogStickPosition
{
[self of_processEvents];
if (index + 1 > _numAnalogSticks)
return _leftAnalogStickPosition;
@throw [OFOutOfRangeException exception];
[self of_processEvents];
return _analogStickPositions[index];
}
- (OFPoint)rightAnalogStickPosition
{
[self of_processEvents];
return _rightAnalogStickPosition;
}
- (OFString *)description
{
return [OFString stringWithFormat: @"<%@: %@>", self.class, self.name];
}
@end
|