--(id) findSubActionForValue: (IOHIDValueRef) value {
- int parsed = IOHIDValueGetIntegerValue(value);
- if(IOHIDElementGetLogicalMax(IOHIDValueGetElement(value)) == 7) {
- // 8-way
- switch(parsed) {
- case 0: return [subActions objectAtIndex: 0];
- case 4: return [subActions objectAtIndex: 1];
- case 6: return [subActions objectAtIndex: 2];
- case 2: return [subActions objectAtIndex: 3];
- }
- } else if(IOHIDElementGetLogicalMax(IOHIDValueGetElement(value)) == 8) {
- // 8-way
- switch(parsed) {
- case 1: return [subActions objectAtIndex: 0];
- case 5: return [subActions objectAtIndex: 1];
- case 7: return [subActions objectAtIndex: 2];
- case 3: return [subActions objectAtIndex: 3];
- }
- } else if(IOHIDElementGetLogicalMax(IOHIDValueGetElement(value)) == 3) {
- // 4-way
- switch(parsed) {
- case 0: return [subActions objectAtIndex: 0];
- case 2: return [subActions objectAtIndex: 1];
- case 3: return [subActions objectAtIndex: 2];
- case 1: return [subActions objectAtIndex: 3];
- }
- } else if(IOHIDElementGetLogicalMax(IOHIDValueGetElement(value)) == 4) {
- // 4-way
- switch(parsed) {
- case 1: return [subActions objectAtIndex: 0];
- case 3: return [subActions objectAtIndex: 1];
- case 4: return [subActions objectAtIndex: 2];
- case 2: return [subActions objectAtIndex: 3];
- }
- }
- return NULL;
+- (id)findSubActionForValue:(IOHIDValueRef)value {
+ int parsed = IOHIDValueGetIntegerValue(value);
+ switch (IOHIDElementGetLogicalMax(IOHIDValueGetElement(value))) {
+ case 7: // 8-way switch, 0-7.
+ switch (parsed) {
+ case 0: return self.children[0];
+ case 4: return self.children[1];
+ case 6: return self.children[2];
+ case 2: return self.children[3];
+ default: return nil;
+ }
+ case 8: // 8-way switch, 1-8 (neutral 0).
+ switch (parsed) {
+ case 1: return self.children[0];
+ case 5: return self.children[1];
+ case 7: return self.children[2];
+ case 3: return self.children[3];
+ default: return nil;
+ }
+ case 3: // 4-way switch, 0-3.
+ switch (parsed) {
+ case 0: return self.children[0];
+ case 2: return self.children[1];
+ case 3: return self.children[2];
+ case 1: return self.children[3];
+ default: return nil;
+ }
+ case 4: // 4-way switch, 1-4 (neutral 0).
+ switch (parsed) {
+ case 1: return self.children[0];
+ case 3: return self.children[1];
+ case 4: return self.children[2];
+ case 2: return self.children[3];
+ default: return nil;
+ }
+ default:
+ return nil;
+ }