Permalink
Browse files

Changing to cookies for HID tracking

  • Loading branch information...
1 parent 55b1bc3 commit d9da8dd5e16e537390e8312a615017190e8506a5 @jweinberg jweinberg committed Dec 29, 2010
Showing with 40 additions and 13 deletions.
  1. +3 −3 OpenEmu/GameCore.m
  2. +4 −2 OpenEmu/OEGameCoreController.m
  3. +9 −5 OpenEmu/OEHIDEvent.h
  4. +24 −3 OpenEmu/OEHIDEvent.m
View
@@ -445,7 +445,7 @@ - (void)HIDEventWasSet:(id)theEvent forKey:(NSString *)keyName
break;
case OEHIDButton :
if([anEvent state] == NSOffState) return;
- appKey |= [anEvent buttonNumber];
+ appKey |= [anEvent cookie];
break;
case OEHIDHatSwitch :
if([anEvent position] == 0) return;
@@ -523,14 +523,14 @@ - (void)axisMoved:(OEHIDEvent *)anEvent
- (void)buttonDown:(OEHIDEvent *)anEvent
{
OEEmulatorKey key;
- if(OEMapGetValue(keyMap, HID_MASK | PAD_NUMBER | [anEvent buttonNumber], &key))
+ if(OEMapGetValue(keyMap, HID_MASK | PAD_NUMBER | [anEvent cookie], &key))
[self pressEmulatorKey:key];
}
- (void)buttonUp:(OEHIDEvent *)anEvent
{
OEEmulatorKey key;
- if(OEMapGetValue(keyMap, HID_MASK | PAD_NUMBER | [anEvent buttonNumber], &key))
+ if(OEMapGetValue(keyMap, HID_MASK | PAD_NUMBER | [anEvent cookie], &key))
[self releaseEmulatorKey:key];
}
@@ -115,7 +115,8 @@ - (void)updateOldKeyboardControls;
{
OEHIDEvent *theEvent = [OEHIDEvent keyEventWithTimestamp:0
keyCode:[OEHIDEvent keyCodeForVK:[event unsignedIntValue]]
- state:NSOnState];
+ state:NSOnState
+ cookie:NSNotFound];
[udc setValue:[self registarableValueWithObject:theEvent] forKeyPath:keyPath];
}
}];
@@ -132,7 +133,8 @@ - (void)registerDefaultControls;
{
OEHIDEvent *theEvent = [OEHIDEvent keyEventWithTimestamp:0
keyCode:[obj unsignedIntValue]
- state:NSOnState];
+ state:NSOnState
+ cookie:NSNotFound];
id value = [self registarableValueWithObject:theEvent];
NSString *keyPath = [self keyPathForKey:key withValueType:OEKeyboardEventValueKey];
View
@@ -73,14 +73,17 @@ typedef NSInteger OEHIDDirection;
NSInteger maximum;
} axis;
struct {
+ NSUInteger cookie;
NSUInteger buttonNumber;
NSInteger state;
} button;
struct {
+ NSUInteger cookie;
NSUInteger position;
NSUInteger count;
} hatSwitch;
struct {
+ NSUInteger cookie;
NSUInteger keycode;
NSInteger state;
} keypress;
@@ -92,9 +95,9 @@ typedef NSInteger OEHIDDirection;
+ (NSUInteger)keyCodeForVK:(CGCharCode)charCode;
+ (id)axisEventWithPadNumber:(NSUInteger)padNumber timestamp:(NSTimeInterval)timestamp axis:(OEHIDEventAxis)axis scaledValue:(CGFloat)value;
-+ (id)buttonEventWithPadNumber:(NSUInteger)padNumber timestamp:(NSTimeInterval)timestamp buttonNumber:(NSUInteger)number state:(NSUInteger)state;
-+ (id)hatSwitchEventWithPadNumber:(NSUInteger)padNumber timestamp:(NSTimeInterval)timestamp position:(NSUInteger)position positionCount:(NSUInteger)count;
-+ (id)keyEventWithTimestamp:(NSTimeInterval)timestamp keyCode:(NSUInteger)keyCode state:(NSUInteger)state;
++ (id)buttonEventWithPadNumber:(NSUInteger)padNumber timestamp:(NSTimeInterval)timestamp buttonNumber:(NSUInteger)number state:(NSUInteger)state cookie:(NSUInteger)cookie;
++ (id)hatSwitchEventWithPadNumber:(NSUInteger)padNumber timestamp:(NSTimeInterval)timestamp position:(NSUInteger)position positionCount:(NSUInteger)count cookie:(NSUInteger)cookie;
++ (id)keyEventWithTimestamp:(NSTimeInterval)timestamp keyCode:(NSUInteger)keyCode state:(NSUInteger)state cookie:(NSUInteger)cookie;
+ (id)eventWithDeviceHandler:(OEHIDDeviceHandler *)aDeviceHandler value:(IOHIDValueRef)aValue;
@property(readonly) NSUInteger padNumber;
@@ -112,14 +115,15 @@ typedef NSInteger OEHIDDirection;
// Button event
@property(readonly) NSUInteger buttonNumber;
@property(readonly) NSInteger state;
-
+@property(readonly) NSUInteger cookie;
// Key event
@property(readonly) NSUInteger keycode;
//@property(readonly) NSInteger state;
-
+//@property(readonly) NSUInteger cookie;
// HatSwitch event
@property(readonly) NSUInteger position;
@property(readonly) NSUInteger count;
+//@property(readonly) NSUInteger cookie;
@end
@interface NSEvent (OEEventConversion)
View
@@ -170,37 +170,40 @@ + (id)axisEventWithPadNumber:(NSUInteger)padNumber timestamp:(NSTimeInterval)tim
return ret;
}
-+ (id)buttonEventWithPadNumber:(NSUInteger)padNumber timestamp:(NSTimeInterval)timestamp buttonNumber:(NSUInteger)number state:(NSUInteger)state
++ (id)buttonEventWithPadNumber:(NSUInteger)padNumber timestamp:(NSTimeInterval)timestamp buttonNumber:(NSUInteger)number state:(NSUInteger)state cookie:(NSUInteger)cookie
{
OEHIDEvent *ret = [[[self alloc] initWithPadNumber:padNumber timestamp:timestamp] autorelease];
ret->_type = OEHIDButton;
ret->_data.button.buttonNumber = number;
ret->_data.button.state = state;
+ ret->_data.button.cookie = cookie;
ret->_isPushed = ret->_data.button.state != NSOffState;
return ret;
}
-+ (id)hatSwitchEventWithPadNumber:(NSUInteger)padNumber timestamp:(NSTimeInterval)timestamp position:(NSUInteger)position positionCount:(NSUInteger)count
++ (id)hatSwitchEventWithPadNumber:(NSUInteger)padNumber timestamp:(NSTimeInterval)timestamp position:(NSUInteger)position positionCount:(NSUInteger)count cookie:(NSUInteger)cookie
{
OEHIDEvent *ret = [[[self alloc] initWithPadNumber:padNumber timestamp:timestamp] autorelease];
ret->_type = OEHIDHatSwitch;
ret->_data.hatSwitch.position = position;
ret->_data.hatSwitch.count = count;
+
ret->_isPushed = ret->_data.hatSwitch.position != 0;
return ret;
}
-+ (id)keyEventWithTimestamp:(NSTimeInterval)timestamp keyCode:(NSUInteger)keyCode state:(NSUInteger)state
++ (id)keyEventWithTimestamp:(NSTimeInterval)timestamp keyCode:(NSUInteger)keyCode state:(NSUInteger)state cookie:(NSUInteger)cookie
{
OEHIDEvent *ret = [[[self alloc] initWithPadNumber:0 timestamp:timestamp] autorelease];
ret->_type = OEHIDKeypress;
ret->_data.keypress.keycode = keyCode;
ret->_data.keypress.state = state;
+ ret->_data.keypress.cookie = cookie;
ret->_isPushed = ret->_data.keypress.state != NSOffState;
return ret;
@@ -219,6 +222,8 @@ - (id)initWithDeviceHandler:(OEHIDDeviceHandler *)aDeviceHandler value:(IOHIDVa
IOHIDElementRef elem = IOHIDValueGetElement(aValue);
const uint32_t page = IOHIDElementGetUsagePage(elem);
const uint32_t usage = IOHIDElementGetUsage(elem);
+ const uint32_t cookie = (uint32_t)IOHIDElementGetCookie(elem);
+
if(IOHIDValueGetLength(aValue) != 1)
{
[self release];
@@ -268,6 +273,7 @@ - (id)initWithDeviceHandler:(OEHIDDeviceHandler *)aDeviceHandler value:(IOHIDVa
_type = OEHIDHatSwitch;
_data.hatSwitch.position = value;
_data.hatSwitch.count = IOHIDElementGetLogicalMax(elem);
+ _data.hatSwitch.cookie = cookie;
_isPushed = _data.hatSwitch.position != 0;
break;
}
@@ -277,6 +283,7 @@ - (id)initWithDeviceHandler:(OEHIDDeviceHandler *)aDeviceHandler value:(IOHIDVa
_type = OEHIDButton;
_data.button.buttonNumber = usage;
_data.button.state = value;
+ _data.button.cookie = cookie;
_isPushed = _data.button.state != NSOffState;
break;
case kHIDPage_KeyboardOrKeypad :
@@ -289,6 +296,7 @@ - (id)initWithDeviceHandler:(OEHIDDeviceHandler *)aDeviceHandler value:(IOHIDVa
_type = OEHIDKeypress;
_data.keypress.keycode = usage;
_data.keypress.state = value;
+ _data.keypress.cookie = cookie;
_isPushed = _data.keypress.state != NSOffState;
break;
}
@@ -358,6 +366,12 @@ - (NSUInteger)keycode
return _data.keypress.keycode;
}
+- (NSUInteger)cookie
+{
+ NSAssert1([self type] == OEHIDButton || [self type] == OEHIDKeypress || [self type] == OEHIDHatSwitch, @"Invalid message sent to event \"%@\"", self);
+ return _data.button.cookie;
+}
+
- (NSString *)description
{
NSString *subs = @"UNKNOWN TYPE";
@@ -412,6 +426,7 @@ - (NSString *)description
NSString *OEHIDEventPositionKey = @"OEHIDEventPositionKey";
NSString *OEHIDEventCountKey = @"OEHIDEventCountKey";
NSString *OEHIDEventKeycodeKey = @"OEHIDEventKeycodeKey";
+NSString *OEHIDEventCookieKey = @"OEHIDEventCookieKey";
- (id)initWithCoder:(NSCoder *)decoder
{
@@ -426,14 +441,17 @@ - (id)initWithCoder:(NSCoder *)decoder
case OEHIDButton :
_data.button.buttonNumber = [decoder decodeIntegerForKey:OEHIDEventButtonNumberKey];
_data.button.state = [decoder decodeIntegerForKey:OEHIDEventStateKey];
+ _data.button.cookie = [decoder decodeIntegerForKey:OEHIDEventCookieKey];
break;
case OEHIDHatSwitch :
_data.hatSwitch.position = [decoder decodeIntegerForKey:OEHIDEventPositionKey];
_data.hatSwitch.count = [decoder decodeIntegerForKey:OEHIDEventCountKey];
+ _data.hatSwitch.cookie = [decoder decodeIntegerForKey:OEHIDEventCookieKey];
break;
case OEHIDKeypress :
_data.keypress.keycode = [decoder decodeIntegerForKey:OEHIDEventKeycodeKey];
_data.keypress.state = [decoder decodeIntegerForKey:OEHIDEventStateKey];
+ _data.keypress.cookie = [decoder decodeIntegerForKey:OEHIDEventCookieKey];
break;
}
@@ -453,14 +471,17 @@ - (void)encodeWithCoder:(NSCoder *)encoder
case OEHIDButton :
[encoder encodeInteger:self.buttonNumber forKey:OEHIDEventButtonNumberKey];
[encoder encodeInteger:self.state forKey:OEHIDEventStateKey];
+ [encoder encodeInteger:self.cookie forKey:OEHIDEventCookieKey];
break;
case OEHIDHatSwitch :
[encoder encodeInteger:self.position forKey:OEHIDEventPositionKey];
[encoder encodeInteger:self.count forKey:OEHIDEventCountKey];
+ [encoder encodeInteger:self.cookie forKey:OEHIDEventCookieKey];
break;
case OEHIDKeypress :
[encoder encodeInteger:self.keycode forKey:OEHIDEventKeycodeKey];
[encoder encodeInteger:self.state forKey:OEHIDEventStateKey];
+ [encoder encodeInteger:self.cookie forKey:OEHIDEventCookieKey];
break;
}
}

0 comments on commit d9da8dd

Please sign in to comment.