git.y1.nz

SameBoy

Accurate GB/GBC emulator
download: https://git.y1.nz/archives/sameboy.tar.gz
README | Files | Log | Refs | LICENSE

JoyKit/JOYFullReportElement.m

      1 #import "JOYFullReportElement.h"
      2 #import <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:(JOYFullReportElement *)object
     65 {
     66     if ([object isKindOfClass:self.class]) return false;
     67     return self.uniqueID == object.uniqueID;
     68 }
     69 
     70 - (id)copyWithZone:(NSZone *)zone;
     71 {
     72     return self;
     73 }
     74 @end

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.