1#import "JOYFullReportElement.h" 2#include <IOKit/hid/IOHIDLib.h> 3 4@implementation JOYFullReportElement 5{ 6 IOHIDDeviceRef _device; 7 NSData *_data; 8 unsigned _reportID; 9 size_t _capacity; 10} 11 12- (uint32_t)uniqueID 13{ 14 return _reportID ^ 0xFFFF; 15} 16 17- (instancetype)initWithDevice:(IOHIDDeviceRef) device reportID:(unsigned)reportID 18{ 19 if ((self = [super init])) { 20 _data = [[NSMutableData alloc] initWithLength:[(__bridge NSNumber *)IOHIDDeviceGetProperty(device, CFSTR(kIOHIDMaxOutputReportSizeKey)) unsignedIntValue]]; 21 *(uint8_t *)(((NSMutableData *)_data).mutableBytes) = reportID; 22 _reportID = reportID; 23 _device = device; 24 } 25 return self; 26} 27 28- (int32_t)value 29{ 30 [self doesNotRecognizeSelector:_cmd]; 31 return 0; 32} 33 34- (NSData *)dataValue 35{ 36 return _data; 37} 38 39- (IOReturn)setValue:(uint32_t)value 40{ 41 [self doesNotRecognizeSelector:_cmd]; 42 return -1; 43} 44 45- (IOReturn)setDataValue:(NSData *)value 46{ 47 48 [self updateValue:value]; 49 return IOHIDDeviceSetReport(_device, kIOHIDReportTypeOutput, _reportID, [_data bytes], [_data length]);; 50} 51 52- (void)updateValue:(NSData *)value 53{ 54 _data = [value copy]; 55} 56 57/* For use as a dictionary key */ 58 59- (NSUInteger)hash 60{ 61 return self.uniqueID; 62} 63 64- (BOOL)isEqual:(id)object 65{ 66 return self.uniqueID == self.uniqueID; 67} 68 69- (id)copyWithZone:(nullable NSZone *)zone; 70{ 71 return self; 72} 73@end 74