2019-10-19 16:26:04 +00:00
|
|
|
#import "JOYMultiplayerController.h"
|
|
|
|
|
|
|
|
@interface JOYController ()
|
|
|
|
- (instancetype)initWithDevice:(IOHIDDeviceRef)device reportIDFilter:(NSArray <NSNumber *> *) filter serialSuffix:(NSString *)suffix;
|
|
|
|
- (void)elementChanged:(IOHIDElementRef) element toValue:(IOHIDValueRef) value;
|
|
|
|
- (void)disconnected;
|
2020-04-29 20:47:18 +00:00
|
|
|
- (void)sendReport:(NSData *)report;
|
2019-10-19 16:26:04 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation JOYMultiplayerController
|
|
|
|
{
|
|
|
|
NSMutableArray <JOYController *> *_children;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (instancetype)initWithDevice:(IOHIDDeviceRef) device reportIDFilters:(NSArray <NSArray <NSNumber *> *>*) reportIDFilters
|
|
|
|
{
|
|
|
|
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]];
|
|
|
|
[_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];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-29 20:47:18 +00:00
|
|
|
- (void)sendReport:(NSData *)report
|
|
|
|
{
|
|
|
|
[[_children firstObject] sendReport:report];
|
|
|
|
}
|
|
|
|
|
2019-10-19 16:26:04 +00:00
|
|
|
@end
|