Added support for setting speed brakes to Java client.
This commit is contained in:
@@ -422,9 +422,9 @@ public class XPlaneConnect implements AutoCloseable
|
||||
{
|
||||
throw new IllegalArgumentException("ctrl must no be null.");
|
||||
}
|
||||
if(values.length > 6)
|
||||
if(values.length > 7)
|
||||
{
|
||||
throw new IllegalArgumentException("ctrl must have 6 or fewer elements.");
|
||||
throw new IllegalArgumentException("ctrl must have 7 or fewer elements.");
|
||||
}
|
||||
if(ac < 0 || ac > 9)
|
||||
{
|
||||
@@ -434,35 +434,28 @@ public class XPlaneConnect implements AutoCloseable
|
||||
//Pad command values and convert to bytes
|
||||
int i;
|
||||
int cur = 0;
|
||||
ByteBuffer bb = ByteBuffer.allocate(22);
|
||||
ByteBuffer bb = ByteBuffer.allocate(26);
|
||||
bb.order(ByteOrder.LITTLE_ENDIAN);
|
||||
for(i = 0; i < values.length; ++i)
|
||||
for(i = 0; i < 6; ++i)
|
||||
{
|
||||
if(i == 4)
|
||||
{
|
||||
bb.put(cur, (byte) values[i]);
|
||||
cur += 1;
|
||||
}
|
||||
else if (i >= values.length)
|
||||
{
|
||||
bb.putFloat(cur, -998);
|
||||
cur+= 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
bb.putFloat(cur, values[i]);
|
||||
cur += 4;
|
||||
}
|
||||
}
|
||||
for(; i < 6; ++i)
|
||||
{
|
||||
if(i == 4)
|
||||
{
|
||||
bb.put(cur, (byte) 0);
|
||||
cur += 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
bb.putFloat(cur, -998);
|
||||
cur += 4;
|
||||
}
|
||||
}
|
||||
bb.put(cur, (byte) ac);
|
||||
bb.put(cur++, (byte) ac);
|
||||
bb.putFloat(cur, values.length == 7 ? values[6] : -998);
|
||||
|
||||
//Build and send message
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
|
||||
@@ -463,6 +463,34 @@ public class XPlaneConnectTest
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSendCTRL_Speedbrakes() throws IOException
|
||||
{
|
||||
String dref = "sim/flightmodel/controls/sbrkrqst";
|
||||
float[] ctrl = new float[] { -998.0F, -998.0F, -998.0F, -998.0F, -998.0F, -998.0F, -0.5F };
|
||||
try(XPlaneConnect xpc = new XPlaneConnect())
|
||||
{
|
||||
// Speedbrakes armed
|
||||
xpc.sendCTRL(ctrl);
|
||||
float[] result = xpc.getDREF(dref);
|
||||
|
||||
assertEquals(-0.5F, result[0], 1e-4);
|
||||
|
||||
ctrl[6] = 1.0F; // Deploy speedbrakes
|
||||
xpc.sendCTRL(ctrl);
|
||||
result = xpc.getDREF(dref);
|
||||
|
||||
assertEquals(1.0F, result[0], 1e-4);
|
||||
|
||||
ctrl[6] = 0.0F; // Retract speedbrakes
|
||||
xpc.sendCTRL(ctrl);
|
||||
result = xpc.getDREF(dref);
|
||||
|
||||
assertEquals(0.0F, result[0], 1e-4);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testSendCTRL_NullCtrl() throws IOException
|
||||
{
|
||||
@@ -475,7 +503,7 @@ public class XPlaneConnectTest
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testSendCTRL_LongCtrl() throws IOException
|
||||
{
|
||||
float[] ctrl = new float[] {0, 0, 1, 0.8F, 0, 1, -998};
|
||||
float[] ctrl = new float[] {0, 0, 1, 0.8F, 0, 1, 0, -998};
|
||||
try(XPlaneConnect xpc = new XPlaneConnect())
|
||||
{
|
||||
xpc.sendCTRL(ctrl);
|
||||
|
||||
Reference in New Issue
Block a user