Permalink
Browse files

Testing out alternative flightstick Joypad layout using accelerometer…

… (it doesn't work very well.) Made Boxer only connect to one Joypad device at a time.
  • Loading branch information...
1 parent b54bb8e commit 40483e382f4037824b551a5a1710206dbdeab9fa @alunbestor committed Jul 4, 2011
@@ -237,6 +237,7 @@
9F7721EB12B38C4400072AE8 /* shell_misc.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9F77217512B38C4400072AE8 /* shell_misc.cpp */; };
9F7FC94C139EB38300D60320 /* RacingWheel.png in Resources */ = {isa = PBXBuildFile; fileRef = 9F7FC94B139EB38300D60320 /* RacingWheel.png */; };
9F843FE11226EB1100FD37F1 /* import.png in Resources */ = {isa = PBXBuildFile; fileRef = 9F843FE01226EB1100FD37F1 /* import.png */; };
+ 9F87EF7313C1B18900326608 /* BXFlightstickAccelerometerLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = 9F87EF7213C1B18900326608 /* BXFlightstickAccelerometerLayout.m */; };
9F8A974A10E7DEF500A4B72A /* RegexKitLite.m in Sources */ = {isa = PBXBuildFile; fileRef = 9F8A974910E7DEF500A4B72A /* RegexKitLite.m */; };
9F8A976010E7EDDE00A4B72A /* libicucore.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 9F8A975F10E7EDDE00A4B72A /* libicucore.dylib */; };
9F8BFE9F12C0EF7B0059030F /* BXDisplayLinkRenderingView.m in Sources */ = {isa = PBXBuildFile; fileRef = 9F8BFE9E12C0EF7B0059030F /* BXDisplayLinkRenderingView.m */; };
@@ -312,7 +313,6 @@
9FC6382213C0D54C004478A3 /* BX2ButtonJoystickLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = 9FC6382113C0D54C004478A3 /* BX2ButtonJoystickLayout.m */; };
9FC6382513C0D637004478A3 /* BXJoypadLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = 9FC6382413C0D637004478A3 /* BXJoypadLayout.m */; };
9FC6382913C0DB4F004478A3 /* BX4ButtonJoystickLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = 9FC6382813C0DB4F004478A3 /* BX4ButtonJoystickLayout.m */; };
- 9FC6382C13C0DC49004478A3 /* BXFlightstickLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = 9FC6382B13C0DC48004478A3 /* BXFlightstickLayout.m */; };
9FC6382F13C0E01C004478A3 /* BX4ButtonWheelLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = 9FC6382E13C0E01B004478A3 /* BX4ButtonWheelLayout.m */; };
9FC6383213C0E245004478A3 /* BX2ButtonWheelLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = 9FC6383113C0E244004478A3 /* BX2ButtonWheelLayout.m */; };
9FC74821122A7C8B00E86E6A /* BXPathEnumerator.m in Sources */ = {isa = PBXBuildFile; fileRef = 9FC74820122A7C8B00E86E6A /* BXPathEnumerator.m */; };
@@ -849,6 +849,8 @@
9F7FC94B139EB38300D60320 /* RacingWheel.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = RacingWheel.png; sourceTree = "<group>"; };
9F80BC81123556AD00EBAB23 /* Finder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Finder.h; sourceTree = "<group>"; };
9F843FE01226EB1100FD37F1 /* import.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = import.png; sourceTree = "<group>"; };
+ 9F87EF7113C1B18900326608 /* BXFlightstickAccelerometerLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BXFlightstickAccelerometerLayout.h; sourceTree = "<group>"; };
+ 9F87EF7213C1B18900326608 /* BXFlightstickAccelerometerLayout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BXFlightstickAccelerometerLayout.m; sourceTree = "<group>"; };
9F8A974810E7DEF500A4B72A /* RegexKitLite.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RegexKitLite.h; sourceTree = "<group>"; };
9F8A974910E7DEF500A4B72A /* RegexKitLite.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RegexKitLite.m; sourceTree = "<group>"; };
9F8A975F10E7EDDE00A4B72A /* libicucore.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libicucore.dylib; path = usr/lib/libicucore.dylib; sourceTree = SDKROOT; };
@@ -2197,6 +2199,8 @@
9FC6382813C0DB4F004478A3 /* BX4ButtonJoystickLayout.m */,
9FC6382A13C0DC48004478A3 /* BXFlightstickLayout.h */,
9FC6382B13C0DC48004478A3 /* BXFlightstickLayout.m */,
+ 9F87EF7113C1B18900326608 /* BXFlightstickAccelerometerLayout.h */,
+ 9F87EF7213C1B18900326608 /* BXFlightstickAccelerometerLayout.m */,
9FC6383013C0E244004478A3 /* BX2ButtonWheelLayout.h */,
9FC6383113C0E244004478A3 /* BX2ButtonWheelLayout.m */,
9FC6382D13C0E01A004478A3 /* BX4ButtonWheelLayout.h */,
@@ -2788,9 +2792,9 @@
9FC6382213C0D54C004478A3 /* BX2ButtonJoystickLayout.m in Sources */,
9FC6382513C0D637004478A3 /* BXJoypadLayout.m in Sources */,
9FC6382913C0DB4F004478A3 /* BX4ButtonJoystickLayout.m in Sources */,
- 9FC6382C13C0DC49004478A3 /* BXFlightstickLayout.m in Sources */,
9FC6382F13C0E01C004478A3 /* BX4ButtonWheelLayout.m in Sources */,
9FC6383213C0E245004478A3 /* BX2ButtonWheelLayout.m in Sources */,
+ 9F87EF7313C1B18900326608 /* BXFlightstickAccelerometerLayout.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -23,7 +23,7 @@ + (JoypadControllerLayout *)layout
{
layout = [[JoypadControllerLayout alloc] init];
- [layout setName: @"2-axis, 2-button joystick"];
+ [layout setName: @"Boxer: 2-axis, 2-button joystick"];
[layout addAnalogStickWithFrame: CGRectMake(0, 70, 240, 240)
identifier: kJoyInputAnalogStick1];
@@ -23,7 +23,7 @@ + (JoypadControllerLayout *)layout
{
layout = [[JoypadControllerLayout alloc] init];
- [layout setName: @"2-button racing wheel"];
+ [layout setName: @"Boxer: 2-button racing wheel"];
//We use the accelerometer in lieu of onscreen steering controls
[layout addAccelerometer];
@@ -24,14 +24,13 @@ + (JoypadControllerLayout *)layout
layout = [[JoypadControllerLayout alloc] init];
//NOTE: we omit the additional 2 axes for lack of space
- [layout setName: @"2-axis, 4-button joystick"];
+ [layout setName: @"Boxer: 2-axis, 4-button joystick"];
[layout addAnalogStickWithFrame: CGRectMake(0, 70, 240, 240)
identifier: kJoyInputAnalogStick1];
/*
[layout addDpadWithFrame: CGRectMake(0, 70, 240, 240)
- dpadOrigin: CGPointMake(120, 190)
identifier: kJoyInputDpad1];
*/
@@ -23,7 +23,7 @@ + (JoypadControllerLayout *)layout
{
layout = [[JoypadControllerLayout alloc] init];
- [layout setName: @"4-button racing wheel"];
+ [layout setName: @"Boxer: 4-button racing wheel"];
//We use the accelerometer in lieu of onscreen steering controls
[layout addAccelerometer];
@@ -0,0 +1,16 @@
+/*
+ Boxer is copyright 2011 Alun Bestor and contributors.
+ Boxer is released under the GNU General Public License 2.0. A full copy of this license can be
+ found in this XCode project at Resources/English.lproj/BoxerHelp/pages/legalese.html, or read
+ online at [http://www.gnu.org/licenses/gpl-2.0.txt].
+ */
+
+//Provides a suitable layout for BXCHFlightstick and BXThrustmasterFCS:
+//Flightsticks with 4 buttons and a hat-switch. Unlike BXFlightstickLayout,
+//this uses tilt control for pitch and roll.
+
+#import "BXJoypadLayout.h"
+
+
+@interface BXFlightstickAccelerometerLayout : BXJoypadLayout
+@end
@@ -0,0 +1,83 @@
+/*
+ Boxer is copyright 2011 Alun Bestor and contributors.
+ Boxer is released under the GNU General Public License 2.0. A full copy of this license can be
+ found in this XCode project at Resources/English.lproj/BoxerHelp/pages/legalese.html, or read
+ online at [http://www.gnu.org/licenses/gpl-2.0.txt].
+ */
+
+#import "BXFlightstickAccelerometerLayout.h"
+#import "BXEmulatedJoystick.h"
+
+
+@implementation BXFlightstickAccelerometerLayout
+
++ (void) load
+{
+ [BXJoypadLayout registerLayout: self forJoystickType: [BXCHFlightStickPro class]];
+ [BXJoypadLayout registerLayout: self forJoystickType: [BXThrustmasterFCS class]];
+}
+
++ (JoypadControllerLayout *)layout
+{
+ static JoypadControllerLayout *layout = nil;
+ if (!layout)
+ {
+ layout = [[JoypadControllerLayout alloc] init];
+
+ [layout setName: @"Boxer: 4-button flightstick with POV switch"];
+
+ //We use the accelerometer in lieu of an onscreen analog stick
+ [layout addAccelerometer];
+
+ //POV hat switch: bottom center of screen
+ [layout addDpadWithFrame: CGRectMake(140, 70, 200, 200)
+ identifier: kJoyInputDpad1];
+
+ //Primary buttons: blue, rectangular and tall, located along each side of the screen
+ [layout addButtonWithFrame: CGRectMake(380,100,100,220)
+ label: @"1"
+ fontSize: 36
+ shape: kJoyButtonShapeSquare
+ color: kJoyButtonColorBlue
+ identifier: kJoyInputAButton];
+
+ [layout addButtonWithFrame: CGRectMake(0,100,100,220)
+ label: @"2"
+ fontSize: 36
+ shape: kJoyButtonShapeSquare
+ color: kJoyButtonColorBlue
+ identifier: kJoyInputBButton];
+
+ //Secondary buttons: square, located at the top corners of each side of the screen
+ [layout addButtonWithFrame: CGRectMake(380,0,100,100)
+ label: @"3"
+ fontSize: 36
+ shape: kJoyButtonShapeSquare
+ color: kJoyButtonColorBlack
+ identifier: kJoyInputXButton];
+
+ [layout addButtonWithFrame: CGRectMake(0,0,100,100)
+ label: @"4"
+ fontSize: 36
+ shape: kJoyButtonShapeSquare
+ color: kJoyButtonColorBlack
+ identifier: kJoyInputYButton];
+
+ //Meta buttons: pill-shaped, located at the top center
+ [layout addButtonWithFrame: CGRectMake(120,10,110,30)
+ label: @"Esc"
+ fontSize: 16
+ shape: kJoyButtonShapePill
+ color: kJoyButtonColorBlack
+ identifier: kJoyInputStartButton];
+
+ [layout addButtonWithFrame: CGRectMake(250,10,110,30)
+ label: @"Pause"
+ fontSize: 16
+ shape: kJoyButtonShapePill
+ color: kJoyButtonColorBlack
+ identifier: kJoyInputSelectButton];
+ }
+ return layout;
+}
+@end
@@ -24,8 +24,7 @@ + (JoypadControllerLayout *)layout
{
layout = [[JoypadControllerLayout alloc] init];
-
- [layout setName: @"4-button flightstick with POV switch"];
+ [layout setName: @"Boxer: 4-button flightstick with POV switch"];
[layout addAnalogStickWithFrame: CGRectMake(0, 70, 240, 240)
identifier: kJoyInputAnalogStick1];
@@ -71,9 +71,9 @@ - (BOOL) joypadControllersAvailable
- (void) joypadDevice: (JoypadDevice *)device
didAccelerate: (JoypadAcceleration)accel
{
- //Map phone rotation to steering
id joystick = [self _emulatedJoystick];
+ //Map phone rotation to steering
if ([joystick respondsToSelector: @selector(wheelMovedTo:)])
{
float rotation = accel.y;
@@ -88,7 +88,39 @@ - (void) joypadDevice: (JoypadDevice *)device
//Values returned by the Joypad SDK are reversed from what emulated joysticks expect
[joystick wheelMovedTo: -rotation];
- //NSLog(@"%f", -rotation);
+ NSLog(@"%f", -rotation);
+ }
+ else if ([joystick respondsToSelector: @selector(xAxisMovedTo:)] &&
+ [joystick respondsToSelector: @selector(yAxisMovedTo:)])
+ {
+ float x, y;
+
+ //'Release' input if the device appears to be lying flat
+ //Disabled for now as this doesn't work terribly well
+ if (NO && ABS(accel.z) > BXJoypadRestingThreshold &&
+ ABS(accel.x) > BXJoypadRestingThreshold)
+ {
+ x = 0.0f;
+ y = 0.0f;
+ }
+ else
+ {
+ NSLog(@"roll: %f, pitch: %f, yaw: %f", accel.y, accel.x, accel.z);
+ //Confusing, yes?
+ //The accelerometer's Y is the angle around an axis going straight through
+ //the screen and out the other side. We want this to be our roll axis.
+ //The accelerometer's X is the angle around an axis parallel to the longest
+ //sides of the device. We want this to be our pitch axis.
+ x = -accel.y;
+ y = accel.x;
+
+ //Apply a deadzone to the center of each axis
+ if (ABS(x) < BXJoypadRotationDeadzone) x = 0.0f;
+ if (ABS(y) < BXJoypadRotationDeadzone) y = 0.0f;
+ }
+
+ [joystick xAxisMovedTo: x];
+ [joystick yAxisMovedTo: y];
}
}
@@ -124,9 +156,11 @@ - (void) joypadDevice: (JoypadDevice *)device
id joystick = [self _emulatedJoystick];
- //TODO: POV input mapping
- if ([joystick respondsToSelector: @selector(xAxisMovedTo:)] &&
- [joystick respondsToSelector: @selector(yAxisMovedTo:)])
+ if ([joystick respondsToSelector: @selector(POVChangedTo:)])
+ {
+ }
+ else if ([joystick respondsToSelector: @selector(xAxisMovedTo:)] &&
+ [joystick respondsToSelector: @selector(yAxisMovedTo:)])
{
switch (dpadButton)
{
@@ -168,7 +202,7 @@ - (void) joypadDevice: (JoypadDevice *)device
case kJoyInputSelectButton:
//Pause button
- //Do nothing: this is a toggle
+ //Do nothing on button up: this is a toggle
break;
case kJoyInputStartButton:
@@ -50,8 +50,9 @@ - (void) setCurrentLayout: (JoypadControllerLayout *)layout
suppressReconnectionNotifications = YES;
for (JoypadDevice *device in [joypadManager connectedDevices])
{
+ NSUInteger playerNum = [device playerNumber];
[device disconnect];
- [joypadManager connectToDevice: device asPlayer: 1];
+ [joypadManager connectToDevice: device asPlayer: playerNum];
}
suppressReconnectionNotifications = NO;
}
@@ -128,8 +129,12 @@ - (void) joypadManager: (JoypadManager *)manager
didFindDevice: (JoypadDevice *)device
previouslyConnected: (BOOL)wasConnected
{
- [self setHasJoypadDevices: YES];
- [joypadManager connectToDevice: device asPlayer: 1];
+ //Don't connect more than one device
+ if (![self hasJoypadDevices])
+ {
+ [joypadManager connectToDevice: device asPlayer: 1];
+ [self setHasJoypadDevices: YES];
+ }
}
- (void) joypadManager: (JoypadManager *)manager

0 comments on commit 40483e3

Please sign in to comment.