forked from LIJI32/SameBoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJOYMultiplayerController.m
50 lines (41 loc) · 1.41 KB
/
JOYMultiplayerController.m
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
#import "JOYMultiplayerController.h"
@interface JOYController ()
- (instancetype)initWithDevice:(IOHIDDeviceRef)device reportIDFilter:(NSArray <NSNumber *> *) filter serialSuffix:(NSString *)suffix hacks:(NSDictionary *)hacks;
- (void)elementChanged:(IOHIDElementRef) element toValue:(IOHIDValueRef) value;
- (void)disconnected;
- (void)sendReport:(NSData *)report;
@end
@implementation JOYMultiplayerController
{
NSMutableArray <JOYController *> *_children;
}
- (instancetype)initWithDevice:(IOHIDDeviceRef) device reportIDFilters:(NSArray <NSArray <NSNumber *> *>*) reportIDFilters hacks:(NSDictionary *)hacks;
{
self = [super init];
if (!self) return self;
_children = [NSMutableArray array];
unsigned index = 1;
for (NSArray *filter in reportIDFilters) {
JOYController *controller = [[JOYController alloc] initWithDevice:device reportIDFilter:filter serialSuffix:[NSString stringWithFormat:@"%d", index] hacks:hacks];
[_children addObject:controller];
index++;
}
return self;
}
- (void)elementChanged:(IOHIDElementRef) element toValue:(IOHIDValueRef) value
{
for (JOYController *child in _children) {
[child elementChanged:element toValue:value];
}
}
- (void)disconnected
{
for (JOYController *child in _children) {
[child disconnected];
}
}
- (void)sendReport:(NSData *)report
{
[[_children firstObject] sendReport:report];
}
@end