File: JOYFullReportElement.m

package info (click to toggle)
sameboy 1.0.2%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 10,632 kB
  • sloc: ansic: 29,954; objc: 22,249; asm: 1,424; pascal: 1,373; makefile: 1,064; xml: 111
file content (74 lines) | stat: -rw-r--r-- 1,467 bytes parent folder | download | duplicates (2)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#import "JOYFullReportElement.h"
#import <IOKit/hid/IOHIDLib.h>

@implementation JOYFullReportElement
{
    IOHIDDeviceRef _device;
    NSData *_data;
    unsigned _reportID;
    size_t _capacity;
}

- (uint32_t)uniqueID
{
    return _reportID ^ 0xFFFF;
}

- (instancetype)initWithDevice:(IOHIDDeviceRef) device reportID:(unsigned)reportID
{
    if ((self = [super init])) {
        _data = [[NSMutableData alloc] initWithLength:[(__bridge NSNumber *)IOHIDDeviceGetProperty(device, CFSTR(kIOHIDMaxOutputReportSizeKey)) unsignedIntValue]];
        *(uint8_t *)(((NSMutableData *)_data).mutableBytes) = reportID;
        _reportID = reportID;
        _device = device;
    }
    return self;
}

- (int32_t)value
{
    [self doesNotRecognizeSelector:_cmd];
    return 0;
}

- (NSData *)dataValue
{
    return _data;
}

- (IOReturn)setValue:(uint32_t)value
{
    [self doesNotRecognizeSelector:_cmd];
    return -1;
}

- (IOReturn)setDataValue:(NSData *)value
{

    [self updateValue:value];
    return IOHIDDeviceSetReport(_device, kIOHIDReportTypeOutput, _reportID, [_data bytes], [_data length]);
}

- (void)updateValue:(NSData *)value
{
    _data = [value copy];
}

/* For use as a dictionary key */

- (NSUInteger)hash
{
    return self.uniqueID;
}

- (BOOL)isEqual:(JOYFullReportElement *)object
{
    if ([object isKindOfClass:self.class]) return false;
    return self.uniqueID == object.uniqueID;
}

- (id)copyWithZone:(NSZone *)zone;
{
    return self;
}
@end