5 // Created by Sam McCall on 5/05/09.
8 static BOOL active_eightway[36] = {
9 NO, NO, NO, NO , // center
10 YES, NO, NO, NO , // N
11 YES, NO, NO, YES, // NE
13 NO, YES, NO, YES, // SE
14 NO, YES, NO, NO , // S
15 NO, YES, YES, NO , // SW
16 NO, NO, YES, NO , // W
17 YES, NO, YES, NO , // NW
19 static BOOL active_fourway[20] = {
20 NO, NO, NO, NO , // center
21 YES, NO, NO, NO , // N
23 NO, YES, NO, NO , // S
24 NO, NO, YES, NO , // W
27 @implementation JSActionHat
30 if(self = [super init]) {
31 subActions = @[[[SubAction alloc] initWithIndex: 0 name: @"Up" base: self],
32 [[SubAction alloc] initWithIndex: 1 name: @"Down" base: self],
33 [[SubAction alloc] initWithIndex: 2 name: @"Left" base: self],
34 [[SubAction alloc] initWithIndex: 3 name: @"Right" base: self]];
40 -(id) findSubActionForValue: (IOHIDValueRef) value {
41 int parsed = IOHIDValueGetIntegerValue(value);
42 if(IOHIDElementGetLogicalMax(IOHIDValueGetElement(value)) == 7) {
45 case 0: return subActions[0];
46 case 4: return subActions[1];
47 case 6: return subActions[2];
48 case 2: return subActions[3];
50 } else if(IOHIDElementGetLogicalMax(IOHIDValueGetElement(value)) == 8) {
53 case 1: return subActions[0];
54 case 5: return subActions[1];
55 case 7: return subActions[2];
56 case 3: return subActions[3];
58 } else if(IOHIDElementGetLogicalMax(IOHIDValueGetElement(value)) == 3) {
61 case 0: return subActions[0];
62 case 2: return subActions[1];
63 case 3: return subActions[2];
64 case 1: return subActions[3];
66 } else if(IOHIDElementGetLogicalMax(IOHIDValueGetElement(value)) == 4) {
69 case 1: return subActions[0];
70 case 3: return subActions[1];
71 case 4: return subActions[2];
72 case 2: return subActions[3];
78 -(void) notifyEvent: (IOHIDValueRef) value {
79 int parsed = IOHIDValueGetIntegerValue(value);
80 int size = IOHIDElementGetLogicalMax(IOHIDValueGetElement(value));
81 if(size == 7 || size == 3) {
85 BOOL* activeSubactions = (size == 8) ? active_eightway : active_fourway;
86 for(int i=0; i<4; i++)
87 [subActions[i] setActive: activeSubactions[parsed * 4 + i]];