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]];
41 -(id) findSubActionForValue: (IOHIDValueRef) value {
42 int parsed = IOHIDValueGetIntegerValue(value);
43 if(IOHIDElementGetLogicalMax(IOHIDValueGetElement(value)) == 7) {
46 case 0: return subActions[0];
47 case 4: return subActions[1];
48 case 6: return subActions[2];
49 case 2: return subActions[3];
51 } else if(IOHIDElementGetLogicalMax(IOHIDValueGetElement(value)) == 8) {
54 case 1: return subActions[0];
55 case 5: return subActions[1];
56 case 7: return subActions[2];
57 case 3: return subActions[3];
59 } else if(IOHIDElementGetLogicalMax(IOHIDValueGetElement(value)) == 3) {
62 case 0: return subActions[0];
63 case 2: return subActions[1];
64 case 3: return subActions[2];
65 case 1: return subActions[3];
67 } else if(IOHIDElementGetLogicalMax(IOHIDValueGetElement(value)) == 4) {
70 case 1: return subActions[0];
71 case 3: return subActions[1];
72 case 4: return subActions[2];
73 case 2: return subActions[3];
79 -(void) notifyEvent: (IOHIDValueRef) value {
80 int parsed = IOHIDValueGetIntegerValue(value);
81 int size = IOHIDElementGetLogicalMax(IOHIDValueGetElement(value));
82 if(size == 7 || size == 3) {
86 BOOL* activeSubactions = (size == 8) ? active_eightway : active_fourway;
87 for(int i=0; i<4; i++)
88 [subActions[i] setActive: activeSubactions[parsed * 4 + i]];