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 = [NSArray arrayWithObjects:
32 [[SubAction alloc] initWithIndex: 0 name: @"Up" base: self],
33 [[SubAction alloc] initWithIndex: 1 name: @"Down" base: self],
34 [[SubAction alloc] initWithIndex: 2 name: @"Left" base: self],
35 [[SubAction alloc] initWithIndex: 3 name: @"Right" base: self],
44 -(id) findSubActionForValue: (IOHIDValueRef) value {
45 int parsed = IOHIDValueGetIntegerValue(value);
46 if(IOHIDElementGetLogicalMax(IOHIDValueGetElement(value)) == 7) {
49 case 0: return [subActions objectAtIndex: 0];
50 case 4: return [subActions objectAtIndex: 1];
51 case 6: return [subActions objectAtIndex: 2];
52 case 2: return [subActions objectAtIndex: 3];
54 } else if(IOHIDElementGetLogicalMax(IOHIDValueGetElement(value)) == 8) {
57 case 1: return [subActions objectAtIndex: 0];
58 case 5: return [subActions objectAtIndex: 1];
59 case 7: return [subActions objectAtIndex: 2];
60 case 3: return [subActions objectAtIndex: 3];
62 } else if(IOHIDElementGetLogicalMax(IOHIDValueGetElement(value)) == 3) {
65 case 0: return [subActions objectAtIndex: 0];
66 case 2: return [subActions objectAtIndex: 1];
67 case 3: return [subActions objectAtIndex: 2];
68 case 1: return [subActions objectAtIndex: 3];
70 } else if(IOHIDElementGetLogicalMax(IOHIDValueGetElement(value)) == 4) {
73 case 1: return [subActions objectAtIndex: 0];
74 case 3: return [subActions objectAtIndex: 1];
75 case 4: return [subActions objectAtIndex: 2];
76 case 2: return [subActions objectAtIndex: 3];
82 -(void) notifyEvent: (IOHIDValueRef) value {
83 int parsed = IOHIDValueGetIntegerValue(value);
84 int size = IOHIDElementGetLogicalMax(IOHIDValueGetElement(value));
85 if(size == 7 || size == 3) {
89 BOOL* activeSubactions = (size == 8) ? active_eightway : active_fourway;
90 for(int i=0; i<4; i++)
91 [[subActions objectAtIndex: i] setActive: activeSubactions[parsed * 4 + i]];