From 039c92b2f15ec5e94ec391aa68bcd7b454f260f3 Mon Sep 17 00:00:00 2001 From: Jason Watkins Date: Fri, 8 May 2015 13:34:32 -0700 Subject: [PATCH] Added support for VIEW command to Python client. --- Python/src/xpc.py | 32 +++++++++++++++++++++++++++++++ TestScripts/Python Tests/Tests.py | 16 ++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/Python/src/xpc.py b/Python/src/xpc.py index 32b4d3c..c19bbdb 100644 --- a/Python/src/xpc.py +++ b/Python/src/xpc.py @@ -326,6 +326,23 @@ class XPlaneConnect(object): buffer = struct.pack("<4sxiiB" + str(msgLen) + "s", "TEXT", x, y, msgLen, msg) self.sendUDP(buffer) + def sendVIEW(self, view): + '''Sets the camera view in X-Plane + + Args: + view: The view to use. The ViewType class provides named constants + for known views. + ''' + # Preconditions + if view < ViewType.Forwards or view > ViewType.FullscreenNoHud: + raise ValueError("Unknown view command.") + + # Pack buffer + buffer = struct.pack("<4sxi", "VIEW", view) + + # Send message + self.sendUDP(buffer) + def sendWYPT(self, op, points): '''Adds, removes, or clears waypoints. Waypoints are three dimensional points on or above the Earth's surface that are represented visually in the simulator. Each @@ -350,3 +367,18 @@ class XPlaneConnect(object): else: buffer = struct.pack("<4sxBB" + str(len(points)) + "f", "WYPT", op, len(points), *points) self.sendUDP(buffer) + +class ViewType(object): + Forwards = 73 + Down = 74 + Left = 75 + Right = 76 + Back = 77 + Tower = 78 + Runway = 79 + Chase = 80 + Follow = 81 + FollowWithPanel = 82 + Spot = 83 + FullscreenWithHud = 84 + FullscreenNoHud = 85 diff --git a/TestScripts/Python Tests/Tests.py b/TestScripts/Python Tests/Tests.py index 558aa7c..2cdc825 100644 --- a/TestScripts/Python Tests/Tests.py +++ b/TestScripts/Python Tests/Tests.py @@ -319,6 +319,22 @@ class XPCTests(unittest.TestCase): # Cleanup client.close() + def test_sendView(self): + # Setup + dref = "sim/graphics/view/view_type" + fwd = 1000 + chase = 1017 + + #Execution + with xpc.XPlaneConnect() as client: + client.sendVIEW(xpc.ViewType.Forwards) + result = client.getDREF(dref) + self.assertAlmostEqual(fwd, result[0], 1e-4) + client.sendVIEW(xpc.ViewType.Chase) + result = client.getDREF(dref) + self.assertAlmostEqual(chase, result[0], 1e-4) + + def test_sendWYPT(self): # Setup client = xpc.XPlaneConnect()