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>"
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;
/**
@ -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>"
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;
};

View File

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

View File

@ -19,9 +19,12 @@ public class NvController {
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();
}
}

View File

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