Skip to content

Commit

Permalink
Fixed joystick X/Y range
Browse files Browse the repository at this point in the history
  • Loading branch information
0xe1f committed Jun 12, 2015
1 parent d67b935 commit e51ecc6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
12 changes: 8 additions & 4 deletions Cocoa/CMGamepad.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@

#import <IOKit/hid/IOHIDLib.h>

#define AXIS_CENTER 127

#pragma mark - CMGamepad

static void gamepadInputValueCallback(void *context, IOReturn result, void *sender, IOHIDValueRef value);
Expand Down Expand Up @@ -201,9 +199,12 @@ - (void)didReceiveInputValue:(IOHIDValueRef)valueRef
CMGamepadEventData *eventData = [[[CMGamepadEventData alloc] init] autorelease];
[eventData setSourceId:IOHIDElementGetCookie(element)];

NSInteger min = IOHIDElementGetLogicalMin(element);
NSInteger max = IOHIDElementGetLogicalMax(element);

[_delegate gamepad:self
xChanged:value
center:AXIS_CENTER
center:(max - min) / 2
eventData:eventData];
}
}
Expand All @@ -214,9 +215,12 @@ - (void)didReceiveInputValue:(IOHIDValueRef)valueRef
CMGamepadEventData *eventData = [[[CMGamepadEventData alloc] init] autorelease];
[eventData setSourceId:IOHIDElementGetCookie(element)];

NSInteger min = IOHIDElementGetLogicalMin(element);
NSInteger max = IOHIDElementGetLogicalMax(element);

[_delegate gamepad:self
yChanged:value
center:AXIS_CENTER
center:(max - min) / 2
eventData:eventData];
}
}
Expand Down
12 changes: 7 additions & 5 deletions Src/Cocoa/CMCocoaInput.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "InputEvent.h"

//#define DEBUG_KEY_STATE
//#define DEBUG_JOY_STATE

NSString *const CMKeyPasteStarted = @"com.akop.CocoaMSX.KeyPasteStarted";
NSString *const CMKeyPasteEnded = @"com.akop.CocoaMSX.KeyPasteEnded";
Expand Down Expand Up @@ -533,7 +534,7 @@ - (void)gamepad:(CMGamepad *)gamepad
preferredDevice = [[NSUserDefaults standardUserDefaults] integerForKey:@"joystickPreferredMacDevicePort2"];
}

#ifdef DEBUG_KEY_STATE
#ifdef DEBUG_JOY_STATE
NSLog(@"Joystick X: %ld (center: %ld) on gamepad %@",
newValue, center, gamepad);
#endif
Expand Down Expand Up @@ -579,7 +580,7 @@ - (void)gamepad:(CMGamepad *)gamepad
preferredDevice = [[NSUserDefaults standardUserDefaults] integerForKey:@"joystickPreferredMacDevicePort2"];
}

#ifdef DEBUG_KEY_STATE
#ifdef DEBUG_JOY_STATE
NSLog(@"Joystick Y: %ld (center: %ld) on gamepad %@",
newValue, center, gamepad);
#endif
Expand Down Expand Up @@ -622,8 +623,9 @@ - (void)gamepad:(CMGamepad *)gamepad
preferredDevice = [[NSUserDefaults standardUserDefaults] integerForKey:@"joystickPreferredMacDevicePort2"];
}

#ifdef DEBUG_KEY_STATE
NSLog(@"Pressed button %ld on gamepad %@", index, gamepad);
#ifdef DEBUG_JOY_STATE
NSLog(@"Pressed button %ld on gamepad %@",
index, gamepad);
#endif

if (preferredDevice == CMPreferredMacDeviceJoystick ||
Expand Down Expand Up @@ -663,7 +665,7 @@ - (void)gamepad:(CMGamepad *)gamepad
preferredDevice = [[NSUserDefaults standardUserDefaults] integerForKey:@"joystickPreferredMacDevicePort2"];
}

#ifdef DEBUG_KEY_STATE
#ifdef DEBUG_JOY_STATE
NSLog(@"Released button %ld on gamepad %@", index, gamepad);
#endif

Expand Down

0 comments on commit e51ecc6

Please sign in to comment.