Minor JoyKit improvements
This commit is contained in:
parent
6448a692e2
commit
4c443d51ce
@ -125,23 +125,21 @@
|
||||
|
||||
double old1 = _state1, old2 = _state2;
|
||||
{
|
||||
double min = [self effectiveMinX];
|
||||
double max = [self effectiveMaxX];
|
||||
if (min == max) return false;
|
||||
int32_t value = x;
|
||||
|
||||
|
||||
if (initialX != 0) {
|
||||
minX = MIN(value, minX);
|
||||
maxX = MAX(value, maxX);
|
||||
}
|
||||
|
||||
double min = [self effectiveMinX];
|
||||
double max = [self effectiveMaxX];
|
||||
if (min == max) return false;
|
||||
|
||||
_state1 = (value - min) / (max - min) * 2 - 1;
|
||||
}
|
||||
|
||||
{
|
||||
double min = [self effectiveMinY];
|
||||
double max = [self effectiveMaxY];
|
||||
if (min == max) return false;
|
||||
int32_t value = y;
|
||||
|
||||
if (initialY != 0) {
|
||||
@ -149,8 +147,23 @@
|
||||
maxY = MAX(value, maxY);
|
||||
}
|
||||
|
||||
double min = [self effectiveMinY];
|
||||
double max = [self effectiveMaxY];
|
||||
if (min == max) return false;
|
||||
|
||||
_state2 = (value - min) / (max - min) * 2 - 1;
|
||||
}
|
||||
|
||||
if (_state1 < -1 || _state1 > 1 ||
|
||||
_state2 < -1 || _state2 > 1) {
|
||||
// Makes no sense, recalibrate
|
||||
_state1 = _state2 = 0;
|
||||
initialX = initialY = 0;
|
||||
minX = _element1.max;
|
||||
minY = _element2.max;
|
||||
maxX = _element1.min;
|
||||
maxY = _element2.min;
|
||||
}
|
||||
|
||||
return old1 != _state1 || old2 != _state2;
|
||||
}
|
||||
|
@ -382,11 +382,13 @@ typedef struct __attribute__((packed)) {
|
||||
|
||||
- (NSString *)deviceName
|
||||
{
|
||||
if (!_device) return nil;
|
||||
return IOHIDDeviceGetProperty(_device, CFSTR(kIOHIDProductKey));
|
||||
}
|
||||
|
||||
- (NSString *)uniqueID
|
||||
{
|
||||
if (!_device) return nil;
|
||||
NSString *serial = (__bridge NSString *)IOHIDDeviceGetProperty(_device, CFSTR(kIOHIDSerialNumberKey));
|
||||
if (!serial || [(__bridge NSString *)IOHIDDeviceGetProperty(_device, CFSTR(kIOHIDTransportKey)) isEqualToString:@"USB"]) {
|
||||
serial = [NSString stringWithFormat:@"%04x%04x%08x",
|
||||
@ -581,6 +583,7 @@ typedef struct __attribute__((packed)) {
|
||||
- (void)sendReport:(NSData *)report
|
||||
{
|
||||
if (!report.length) return;
|
||||
if (!_device) return;
|
||||
IOHIDDeviceSetReport(_device, kIOHIDReportTypeOutput, *(uint8_t *)report.bytes, report.bytes, report.length);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user