Added support for setting speed brakes to Python client
This commit is contained in:
@@ -174,10 +174,11 @@ class XPlaneConnect(object):
|
||||
* Throttle [-1, 1]
|
||||
* Gear (0=up, 1=down)
|
||||
* Flaps [0, 1]
|
||||
* Speedbrakes [-0.5, 1.5]
|
||||
ac: The aircraft to set the control surfaces of. 0 is the main/player aircraft.
|
||||
'''
|
||||
# Preconditions
|
||||
if len(values) < 1 or len(values) > 6:
|
||||
if len(values) < 1 or len(values) > 7:
|
||||
raise ValueError("Must have between 0 and 6 items in values.")
|
||||
if ac < 0 or ac > 20:
|
||||
raise ValueError("Aircraft number must be between 0 and 20.")
|
||||
@@ -189,11 +190,13 @@ class XPlaneConnect(object):
|
||||
if i < len(values):
|
||||
val = values[i]
|
||||
if i == 4:
|
||||
val = -1 if val == -998 else val
|
||||
buffer += struct.pack("B", val)
|
||||
val = -1 if (abs(val + 998) < 1e-4) else val
|
||||
buffer += struct.pack("b", val)
|
||||
else:
|
||||
buffer += struct.pack("<f", val)
|
||||
buffer += struct.pack("B", ac)
|
||||
if len(values) == 7:
|
||||
buffer += struct.pack("<f", values[6])
|
||||
|
||||
# Send
|
||||
self.sendUDP(buffer)
|
||||
|
||||
@@ -171,7 +171,7 @@ class XPCTests(unittest.TestCase):
|
||||
expected = 0.0
|
||||
do_test()
|
||||
|
||||
|
||||
|
||||
def test_sendCTRL(self):
|
||||
# Setup
|
||||
drefs = ["sim/cockpit2/controls/yoke_pitch_ratio",\
|
||||
@@ -209,6 +209,36 @@ class XPCTests(unittest.TestCase):
|
||||
ctrl = [ 0.0, 0.0, 0.0, 0.8, 1.0, 0.0 ]
|
||||
do_test()
|
||||
|
||||
def test_sendCTRL_speedbrake(self):
|
||||
# Setup
|
||||
dref = "sim/flightmodel/controls/sbrkrqst"
|
||||
ctrl = []
|
||||
|
||||
def do_test():
|
||||
client = xpc.XPlaneConnect()
|
||||
|
||||
# Execute
|
||||
client.sendCTRL(ctrl)
|
||||
result = client.getDREF(dref)
|
||||
|
||||
# Cleanup
|
||||
client.close()
|
||||
|
||||
# Tests
|
||||
self.assertAlmostEqual(result[0], ctrl[6])
|
||||
|
||||
# Test 1
|
||||
ctrl = [-998, -998, -998, -998, -998, -998, -0.5]
|
||||
do_test()
|
||||
|
||||
# Test 2
|
||||
ctrl[6] = 1.0
|
||||
do_test()
|
||||
|
||||
# Test 2
|
||||
ctrl[6] = 0.0
|
||||
do_test()
|
||||
|
||||
def test_sendPOSI(self):
|
||||
# Setup
|
||||
drefs = ["sim/flightmodel/position/latitude",\
|
||||
|
||||
Reference in New Issue
Block a user