Cocoa Port:
- Fix bug where HID analog inputs would fail to off-state in the upper value range.
This commit is contained in:
parent
01756f15f4
commit
1b5d34dedb
|
@ -123,7 +123,7 @@ typedef std::tr1::unordered_map<std::string, AudioSampleBlockGenerator> AudioFil
|
||||||
@end
|
@end
|
||||||
|
|
||||||
BOOL GetOnStateFromHIDValueRef(IOHIDValueRef hidValueRef);
|
BOOL GetOnStateFromHIDValueRef(IOHIDValueRef hidValueRef);
|
||||||
InputAttributes InputAttributesOfHIDValue(IOHIDValueRef hidValueRef, const char *altElementCode, const char *altElementName, NSNumber *altOnState);
|
InputAttributes InputAttributesOfHIDValue(IOHIDValueRef hidValueRef, const char *altElementCode, const char *altElementName, bool *altOnState);
|
||||||
InputAttributesList InputListFromHIDValue(IOHIDValueRef hidValueRef);
|
InputAttributesList InputListFromHIDValue(IOHIDValueRef hidValueRef);
|
||||||
InputAttributesList InputListFromHatSwitchValue(IOHIDValueRef hidValueRef, bool useEightDirection);
|
InputAttributesList InputListFromHatSwitchValue(IOHIDValueRef hidValueRef, bool useEightDirection);
|
||||||
|
|
||||||
|
|
|
@ -201,9 +201,9 @@ static NSDictionary *hidUsageTable = nil;
|
||||||
|
|
||||||
Takes:
|
Takes:
|
||||||
hidValueRef - The IOHIDValueRef to parse.
|
hidValueRef - The IOHIDValueRef to parse.
|
||||||
altElementCode - An NSString that overrides the default element code.
|
altElementCode - A char buffer that overrides the default element code.
|
||||||
altElementName - An NSString that overrides the default element name.
|
altElementName - A char buffer that overrides the default element name.
|
||||||
altOnState - An NSNumber that overrides the default on state.
|
altOnState - A pointer to a bool value that overrides the default on state.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
An InputAttributes struct with the parsed input attributes.
|
An InputAttributes struct with the parsed input attributes.
|
||||||
|
@ -211,7 +211,7 @@ static NSDictionary *hidUsageTable = nil;
|
||||||
Details:
|
Details:
|
||||||
None.
|
None.
|
||||||
********************************************************************************************/
|
********************************************************************************************/
|
||||||
InputAttributes InputAttributesOfHIDValue(IOHIDValueRef hidValueRef, const char *altElementCode, const char *altElementName, NSNumber *altOnState)
|
InputAttributes InputAttributesOfHIDValue(IOHIDValueRef hidValueRef, const char *altElementCode, const char *altElementName, bool *altOnState)
|
||||||
{
|
{
|
||||||
InputAttributes inputAttr;
|
InputAttributes inputAttr;
|
||||||
|
|
||||||
|
@ -303,7 +303,7 @@ InputAttributes InputAttributesOfHIDValue(IOHIDValueRef hidValueRef, const char
|
||||||
CFStringGetCString(cfDeviceName, inputAttr.deviceName, INPUT_HANDLER_STRING_LENGTH, kCFStringEncodingUTF8);
|
CFStringGetCString(cfDeviceName, inputAttr.deviceName, INPUT_HANDLER_STRING_LENGTH, kCFStringEncodingUTF8);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL onState = (altOnState == nil) ? GetOnStateFromHIDValueRef(hidValueRef) : [altOnState boolValue];
|
bool onState = (altOnState == NULL) ? GetOnStateFromHIDValueRef(hidValueRef) : *altOnState;
|
||||||
CFIndex logicalValue = IOHIDValueGetIntegerValue(hidValueRef);
|
CFIndex logicalValue = IOHIDValueGetIntegerValue(hidValueRef);
|
||||||
NSInteger logicalMin = IOHIDElementGetLogicalMin(hidElementRef);
|
NSInteger logicalMin = IOHIDElementGetLogicalMin(hidElementRef);
|
||||||
NSInteger logicalMax = IOHIDElementGetLogicalMax(hidElementRef);
|
NSInteger logicalMax = IOHIDElementGetLogicalMax(hidElementRef);
|
||||||
|
@ -348,14 +348,14 @@ InputAttributesList InputListFromHIDValue(IOHIDValueRef hidValueRef)
|
||||||
|
|
||||||
if (logicalMin == 0 && logicalMax == 1)
|
if (logicalMin == 0 && logicalMax == 1)
|
||||||
{
|
{
|
||||||
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, NULL, NULL, nil));
|
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, NULL, NULL, NULL));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
NSInteger lowerThreshold = ((logicalMax - logicalMin) / 3) + logicalMin;
|
NSInteger lowerThreshold = ((logicalMax - logicalMin) / 3) + logicalMin;
|
||||||
NSInteger upperThreshold = (((logicalMax - logicalMin) * 2) / 3) + logicalMin;
|
NSInteger upperThreshold = (((logicalMax - logicalMin) * 2) / 3) + logicalMin;
|
||||||
NSNumber *onState = [NSNumber numberWithBool:YES];
|
bool onState = true;
|
||||||
NSNumber *offState = [NSNumber numberWithBool:NO];
|
bool offState = false;
|
||||||
|
|
||||||
char elementCodeLowerThresholdBuf[256] = {0};
|
char elementCodeLowerThresholdBuf[256] = {0};
|
||||||
char elementCodeUpperThresholdBuf[256] = {0};
|
char elementCodeUpperThresholdBuf[256] = {0};
|
||||||
|
@ -364,18 +364,18 @@ InputAttributesList InputListFromHIDValue(IOHIDValueRef hidValueRef)
|
||||||
|
|
||||||
if (logicalValue <= lowerThreshold)
|
if (logicalValue <= lowerThreshold)
|
||||||
{
|
{
|
||||||
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeLowerThresholdBuf, NULL, onState));
|
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeLowerThresholdBuf, NULL, &onState));
|
||||||
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeUpperThresholdBuf, NULL, offState));
|
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeUpperThresholdBuf, NULL, &offState));
|
||||||
}
|
}
|
||||||
else if (logicalValue >= upperThreshold)
|
else if (logicalValue >= upperThreshold)
|
||||||
{
|
{
|
||||||
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeLowerThresholdBuf, NULL, offState));
|
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeLowerThresholdBuf, NULL, &offState));
|
||||||
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeUpperThresholdBuf, NULL, onState));
|
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeUpperThresholdBuf, NULL, &onState));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeLowerThresholdBuf, NULL, offState));
|
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeLowerThresholdBuf, NULL, &offState));
|
||||||
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeUpperThresholdBuf, NULL, onState));
|
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeUpperThresholdBuf, NULL, &offState));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -403,9 +403,8 @@ InputAttributesList InputListFromHatSwitchValue(IOHIDValueRef hidValueRef, bool
|
||||||
inputList.resize(8);
|
inputList.resize(8);
|
||||||
NSInteger logicalMax = IOHIDElementGetLogicalMax(hidElementRef);
|
NSInteger logicalMax = IOHIDElementGetLogicalMax(hidElementRef);
|
||||||
NSInteger logicalValue = IOHIDValueGetIntegerValue(hidValueRef);
|
NSInteger logicalValue = IOHIDValueGetIntegerValue(hidValueRef);
|
||||||
|
bool onState = true;
|
||||||
NSNumber *onState = [NSNumber numberWithBool:YES];
|
bool offState = false;
|
||||||
NSNumber *offState = [NSNumber numberWithBool:NO];
|
|
||||||
|
|
||||||
char elementCodeFourWay[4][256];
|
char elementCodeFourWay[4][256];
|
||||||
for (unsigned int i = 0; i < 4; i++)
|
for (unsigned int i = 0; i < 4; i++)
|
||||||
|
@ -439,7 +438,7 @@ InputAttributesList InputListFromHatSwitchValue(IOHIDValueRef hidValueRef, bool
|
||||||
{
|
{
|
||||||
for (unsigned int i = 0; i <= (unsigned int)logicalMax; i++)
|
for (unsigned int i = 0; i <= (unsigned int)logicalMax; i++)
|
||||||
{
|
{
|
||||||
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeFourWay[i], elementNameFourWay[i], (i == (unsigned int)logicalValue) ? onState : offState));
|
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeFourWay[i], elementNameFourWay[i], (i == (unsigned int)logicalValue) ? &onState : &offState));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (logicalMax == 7)
|
else if (logicalMax == 7)
|
||||||
|
@ -448,7 +447,7 @@ InputAttributesList InputListFromHatSwitchValue(IOHIDValueRef hidValueRef, bool
|
||||||
{
|
{
|
||||||
for (unsigned int i = 0; i <= (unsigned int)logicalMax; i++)
|
for (unsigned int i = 0; i <= (unsigned int)logicalMax; i++)
|
||||||
{
|
{
|
||||||
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[i], elementNameEightWay[i], (i == (unsigned int)logicalValue) ? onState : offState));
|
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[i], elementNameEightWay[i], (i == (unsigned int)logicalValue) ? &onState : &offState));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -456,66 +455,66 @@ InputAttributesList InputListFromHatSwitchValue(IOHIDValueRef hidValueRef, bool
|
||||||
switch (logicalValue)
|
switch (logicalValue)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[0], elementNameEightWay[0], onState));
|
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[0], elementNameEightWay[0], &onState));
|
||||||
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[2], elementNameEightWay[2], offState));
|
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[2], elementNameEightWay[2], &offState));
|
||||||
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[4], elementNameEightWay[4], offState));
|
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[4], elementNameEightWay[4], &offState));
|
||||||
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[6], elementNameEightWay[6], offState));
|
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[6], elementNameEightWay[6], &offState));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[0], elementNameEightWay[0], onState));
|
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[0], elementNameEightWay[0], &onState));
|
||||||
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[2], elementNameEightWay[2], onState));
|
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[2], elementNameEightWay[2], &onState));
|
||||||
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[4], elementNameEightWay[4], offState));
|
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[4], elementNameEightWay[4], &offState));
|
||||||
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[6], elementNameEightWay[6], offState));
|
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[6], elementNameEightWay[6], &offState));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[0], elementNameEightWay[0], offState));
|
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[0], elementNameEightWay[0], &offState));
|
||||||
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[2], elementNameEightWay[2], onState));
|
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[2], elementNameEightWay[2], &onState));
|
||||||
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[4], elementNameEightWay[4], offState));
|
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[4], elementNameEightWay[4], &offState));
|
||||||
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[6], elementNameEightWay[6], offState));
|
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[6], elementNameEightWay[6], &offState));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[0], elementNameEightWay[0], offState));
|
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[0], elementNameEightWay[0], &offState));
|
||||||
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[2], elementNameEightWay[2], onState));
|
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[2], elementNameEightWay[2], &onState));
|
||||||
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[4], elementNameEightWay[4], onState));
|
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[4], elementNameEightWay[4], &onState));
|
||||||
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[6], elementNameEightWay[6], offState));
|
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[6], elementNameEightWay[6], &offState));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 4:
|
case 4:
|
||||||
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[0], elementNameEightWay[0], offState));
|
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[0], elementNameEightWay[0], &offState));
|
||||||
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[2], elementNameEightWay[2], offState));
|
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[2], elementNameEightWay[2], &offState));
|
||||||
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[4], elementNameEightWay[4], onState));
|
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[4], elementNameEightWay[4], &onState));
|
||||||
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[6], elementNameEightWay[6], offState));
|
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[6], elementNameEightWay[6], &offState));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 5:
|
case 5:
|
||||||
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[0], elementNameEightWay[0], offState));
|
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[0], elementNameEightWay[0], &offState));
|
||||||
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[2], elementNameEightWay[2], offState));
|
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[2], elementNameEightWay[2], &offState));
|
||||||
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[4], elementNameEightWay[4], onState));
|
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[4], elementNameEightWay[4], &onState));
|
||||||
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[6], elementNameEightWay[6], onState));
|
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[6], elementNameEightWay[6], &onState));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 6:
|
case 6:
|
||||||
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[0], elementNameEightWay[0], offState));
|
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[0], elementNameEightWay[0], &offState));
|
||||||
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[2], elementNameEightWay[2], offState));
|
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[2], elementNameEightWay[2], &offState));
|
||||||
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[4], elementNameEightWay[4], offState));
|
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[4], elementNameEightWay[4], &offState));
|
||||||
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[6], elementNameEightWay[6], onState));
|
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[6], elementNameEightWay[6], &onState));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 7:
|
case 7:
|
||||||
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[0], elementNameEightWay[0], onState));
|
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[0], elementNameEightWay[0], &onState));
|
||||||
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[2], elementNameEightWay[2], offState));
|
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[2], elementNameEightWay[2], &offState));
|
||||||
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[4], elementNameEightWay[4], offState));
|
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[4], elementNameEightWay[4], &offState));
|
||||||
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[6], elementNameEightWay[6], onState));
|
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[6], elementNameEightWay[6], &onState));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[0], elementNameEightWay[0], offState));
|
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[0], elementNameEightWay[0], &offState));
|
||||||
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[2], elementNameEightWay[2], offState));
|
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[2], elementNameEightWay[2], &offState));
|
||||||
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[4], elementNameEightWay[4], offState));
|
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[4], elementNameEightWay[4], &offState));
|
||||||
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[6], elementNameEightWay[6], offState));
|
inputList.push_back(InputAttributesOfHIDValue(hidValueRef, elementCodeEightWay[6], elementNameEightWay[6], &offState));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue