Write each analog stick a short at a time. Fix analog stick value endianness.

This commit is contained in:
Cameron Gutman 2013-09-21 23:30:12 -04:00
parent 8c8e6c0008
commit fbbf572c9d
5 changed files with 54 additions and 39 deletions

View File

@ -112,7 +112,7 @@ or to a theme attribute in the form "<code>?[<i>package</i>:][<i>type</i>:]<i>na
<p>Must be a reference to another resource, in the form "<code>@[+][<i>package</i>:]<i>type</i>:<i>name</i></code>" <p>Must be a reference to another resource, in the form "<code>@[+][<i>package</i>:]<i>type</i>:<i>name</i></code>"
or to a theme attribute in the form "<code>?[<i>package</i>:][<i>type</i>:]<i>name</i></code>". or to a theme attribute in the form "<code>?[<i>package</i>:][<i>type</i>:]<i>name</i></code>".
@attr name com.limelight:buttonBarButtonStyle @attr name android:buttonBarButtonStyle
*/ */
public static final int ButtonBarContainerTheme_buttonBarButtonStyle = 1; public static final int ButtonBarContainerTheme_buttonBarButtonStyle = 1;
/** /**
@ -122,7 +122,7 @@ or to a theme attribute in the form "<code>?[<i>package</i>:][<i>type</i>:]<i>na
<p>Must be a reference to another resource, in the form "<code>@[+][<i>package</i>:]<i>type</i>:<i>name</i></code>" <p>Must be a reference to another resource, in the form "<code>@[+][<i>package</i>:]<i>type</i>:<i>name</i></code>"
or to a theme attribute in the form "<code>?[<i>package</i>:][<i>type</i>:]<i>name</i></code>". or to a theme attribute in the form "<code>?[<i>package</i>:][<i>type</i>:]<i>name</i></code>".
@attr name com.limelight:buttonBarStyle @attr name android:buttonBarStyle
*/ */
public static final int ButtonBarContainerTheme_buttonBarStyle = 0; public static final int ButtonBarContainerTheme_buttonBarStyle = 0;
}; };

View File

@ -23,10 +23,12 @@ import android.widget.VideoView;
public class Game extends Activity { public class Game extends Activity {
private short inputMap = 0x0000; private short inputMap = 0x0000;
private byte leftTrigger = 0x0000; private byte leftTrigger = 0x00;
private byte rightTrigger = 0x0000; private byte rightTrigger = 0x00;
private int rightStick = 0x00000000; private short rightStickX = 0x0000;
private int leftStick = 0x00000000; private short rightStickY = 0x0000;
private short leftStickX = 0x0000;
private short leftStickY = 0x0000;
private NvConnection conn; private NvConnection conn;
@ -191,14 +193,13 @@ public class Game extends Activity {
"RS_X: " + RS_X + "\t" + "RS_X: " + RS_X + "\t" +
"RS_Y: " + RS_Y + "\t"); "RS_Y: " + RS_Y + "\t");
leftStick = ((int)Math.round(LS_X * 0x7FFF) << 16) & 0xFFFF0000; leftStickX = (short)Math.round(LS_X * 0x7FFF);
leftStick |= (int)Math.round(-LS_Y * 0x7FFF) & 0xFFFF; leftStickY = (short)Math.round(-LS_Y * 0x7FFF);
rightStick = ((int)Math.round(RS_X * 0x7FFF) << 16) & 0xFFFF0000; rightStickX = (short)Math.round(RS_X * 0x7FFF);
rightStick |= (int)Math.round(-RS_Y * 0x7FFF) & 0xFFFF; rightStickY = (short)Math.round(-RS_Y * 0x7FFF);
System.out.printf("(0x%x 0x%x) (0x%x 0x%x)\n", leftStickX, leftStickY, rightStickX, rightStickY);
System.out.printf("0x%x 0x%x\n", leftStick, rightStick);
} }
float L2 = event.getAxisValue(OuyaController.AXIS_L2); float L2 = event.getAxisValue(OuyaController.AXIS_L2);
@ -216,7 +217,8 @@ public class Game extends Activity {
private void sendInputPacket() { private void sendInputPacket() {
conn.sendControllerInput(inputMap, leftTrigger, rightTrigger, leftStick, rightStick); conn.sendControllerInput(inputMap, leftTrigger, rightTrigger,
leftStickX, leftStickY, rightStickX, rightStickY);
} }
} }

View File

@ -62,7 +62,8 @@ public class NvConnection {
public void sendControllerInput(final short buttonFlags, public void sendControllerInput(final short buttonFlags,
final byte leftTrigger, final byte rightTrigger, final byte leftTrigger, final byte rightTrigger,
final int leftStick, final int rightStick) final short leftStickX, final short leftStickY,
final short rightStickX, final short rightStickY)
{ {
if (inputStream == null) if (inputStream == null)
return; return;
@ -71,7 +72,9 @@ public class NvConnection {
@Override @Override
public void run() { public void run() {
try { try {
inputStream.sendControllerInput(buttonFlags, leftTrigger, rightTrigger, leftStick, rightStick); inputStream.sendControllerInput(buttonFlags, leftTrigger,
rightTrigger, leftStickX, leftStickY,
rightStickX, rightStickY);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
displayToast(e.getMessage()); displayToast(e.getMessage());

View File

@ -19,9 +19,12 @@ public class NvController {
out = s.getOutputStream(); out = s.getOutputStream();
} }
public void sendControllerInput(short buttonFlags, byte leftTrigger, byte rightTrigger, int leftStick, int rightStick) throws IOException public void sendControllerInput(short buttonFlags, byte leftTrigger, byte rightTrigger,
short leftStickX, short leftStickY, short rightStickX, short rightStickY) throws IOException
{ {
out.write(new NvInputPacket(buttonFlags, leftTrigger, rightTrigger, leftStick, rightStick).toWire()); out.write(new NvInputPacket(buttonFlags, leftTrigger,
rightTrigger, leftStickX, leftStickY,
rightStickX, rightStickY).toWire());
out.flush(); out.flush();
} }
} }

View File

@ -28,49 +28,56 @@ public class NvInputPacket {
0x00 0x00
}; };
public static final short A_FLAG = 0x0010; public static final short A_FLAG = 0x1000;
public static final short B_FLAG = 0x0020; public static final short B_FLAG = 0x2000;
public static final short X_FLAG = 0x0040; public static final short X_FLAG = 0x4000;
public static final short Y_FLAG = 0x0080; public static final short Y_FLAG = (short)0x8000;
public static final short UP_FLAG = 0x0100; public static final short UP_FLAG = 0x0001;
public static final short DOWN_FLAG = 0x0200; public static final short DOWN_FLAG = 0x0002;
public static final short LEFT_FLAG = 0x0400; public static final short LEFT_FLAG = 0x0004;
public static final short RIGHT_FLAG = 0x0800; public static final short RIGHT_FLAG = 0x0008;
public static final short RB_FLAG = 0x0001; public static final short RB_FLAG = 0x0100;
public static final short LB_FLAG = 0x0002; public static final short LB_FLAG = 0x0200;
public static final short LS_CLK_FLAG = 0x0400; public static final short LS_CLK_FLAG = 0x0004;
public static final short RS_CLK_FLAG = 0x0800; public static final short RS_CLK_FLAG = 0x0008;
public static final short PLAY_FLAG = 0x0100; public static final short PLAY_FLAG = 0x0001;
public static final short BACK_FLAG = 0x0200; public static final short BACK_FLAG = 0x0002;
public static final short PACKET_LENGTH = 28; public static final short PACKET_LENGTH = 28;
private short buttonFlags; private short buttonFlags;
private byte leftTrigger; private byte leftTrigger;
private byte rightTrigger; private byte rightTrigger;
private int leftStick; private short leftStickX;
private int rightStick; private short leftStickY;
private short rightStickX;
private short rightStickY;
public NvInputPacket(short buttonFlags, byte leftTrigger, byte rightTrigger, public NvInputPacket(short buttonFlags, byte leftTrigger, byte rightTrigger,
int leftStick, int rightStick) short leftStickX, short leftStickY,
short rightStickX, short rightStickY)
{ {
this.buttonFlags = buttonFlags; this.buttonFlags = buttonFlags;
this.leftTrigger = leftTrigger; this.leftTrigger = leftTrigger;
this.rightTrigger = rightTrigger; this.rightTrigger = rightTrigger;
this.leftStick = leftStick; this.leftStickX = leftStickX;
this.rightStick = rightStick; this.leftStickY = leftStickY;
this.rightStickX = rightStickX;
this.rightStickY = rightStickY;
} }
public byte[] toWire() public byte[] toWire()
{ {
ByteBuffer bb = ByteBuffer.allocate(PACKET_LENGTH); ByteBuffer bb = ByteBuffer.allocate(PACKET_LENGTH).order(ByteOrder.LITTLE_ENDIAN);
bb.put(HEADER); bb.put(HEADER);
bb.putShort(buttonFlags); bb.putShort(buttonFlags);
bb.put(leftTrigger); bb.put(leftTrigger);
bb.put(rightTrigger); bb.put(rightTrigger);
bb.putInt(leftStick); bb.putShort(leftStickX);
bb.putInt(rightStick); bb.putShort(leftStickY);
bb.putShort(rightStickX);
bb.putShort(rightStickY);
bb.put(TAIL); bb.put(TAIL);
return bb.array(); return bb.array();