-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathPI_FreeSharedCockpit_pluginMaster.py
More file actions
106 lines (89 loc) · 4.06 KB
/
PI_FreeSharedCockpit_pluginMaster.py
File metadata and controls
106 lines (89 loc) · 4.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
from XPLMDefs import *
from XPLMDataAccess import *
from XPLMDisplay import *
from XPLMGraphics import *
from XPLMUtilities import *
import pickle
import os
DataRx = []
sync = False
filename = 'C:/2.fll'
try:
os.remove(filename)
except OSError:
print('Cant remove file!')
class PythonInterface:
def XPluginStart(self):
self.Name = "Test"
self.Sig = "Ong.Python.Test"
self.Desc = "Datarefs"
self.Clicked = 0
self.DrawWindowCB = self.DrawWindowCallback
self.KeyCB = self.KeyCallback
self.MouseClickCB = self.MouseClickCallback
self.WindowId = XPLMCreateWindow(self, 50, 600, 400, 570, 1, self.DrawWindowCB, self.KeyCB, self.MouseClickCB, 0)
return self.Name, self.Sig, self.Desc
def XPluginStop(self):
XPLMDestroyWindow(self, self.WindowId)
pass
def XPluginEnable(self):
return 1
def XPluginDisable(self):
pass
def XPluginReceiveMessage(self, inFromWho, inMessage, inParam):
pass
def DrawWindowCallback(self, inWindowID, inRefcon):
# First we get the location of the window passed in to us.
lLeft = []; lTop = []; lRight = []; lBottom = []
XPLMGetWindowGeometry(inWindowID, lLeft, lTop, lRight, lBottom)
left = int(lLeft[0]); top = int(lTop[0]); right = int(lRight[0]); bottom = int(lBottom[0])
XPLMDrawTranslucentDarkBox(left, top, right, bottom)
color = 1.0, 1.0, 1.0
# Access in sim variables
AccessorDataRefX = XPLMFindDataRef("sim/flightmodel/position/local_x")
DataX = XPLMGetDataf(AccessorDataRefX)
AccessorDataRefY = XPLMFindDataRef("sim/flightmodel/position/local_y")
DataY = XPLMGetDataf(AccessorDataRefY)
AccessorDataRefZ = XPLMFindDataRef("sim/flightmodel/position/local_z")
DataZ = XPLMGetDataf(AccessorDataRefZ)
AccessorDataRefPsi = XPLMFindDataRef("sim/flightmodel/position/psi")
DataPsi = XPLMGetDataf(AccessorDataRefPsi)
AccessorDataRefTheta = XPLMFindDataRef("sim/flightmodel/position/theta")
DataTheta = XPLMGetDataf(AccessorDataRefTheta)
AccessorDataRefPhi = XPLMFindDataRef("sim/flightmodel/position/phi")
DataPhi = XPLMGetDataf(AccessorDataRefPhi)
AccessorDataRefP = XPLMFindDataRef("sim/flightmodel/position/P")
DataP = XPLMGetDataf(AccessorDataRefP)
AccessorDataRefQ = XPLMFindDataRef("sim/flightmodel/position/Q")
DataQ = XPLMGetDataf(AccessorDataRefQ)
AccessorDataRefR = XPLMFindDataRef("sim/flightmodel/position/R")
DataR = XPLMGetDataf(AccessorDataRefR)
AccessorDataRefVX = XPLMFindDataRef("sim/flightmodel/position/local_vx")
DataVX = XPLMGetDataf(AccessorDataRefVX)
AccessorDataRefVY = XPLMFindDataRef("sim/flightmodel/position/local_vy")
DataVY = XPLMGetDataf(AccessorDataRefVY)
AccessorDataRefVZ = XPLMFindDataRef("sim/flightmodel/position/local_vz")
DataVZ = XPLMGetDataf(AccessorDataRefVZ)
# Export in sim data to other comp
global DataRx
DataTx = [DataX, DataY, DataZ, DataPsi, DataTheta, DataPhi, DataP, DataQ, DataR, DataVX, DataVY, DataVZ]
outfile = open('C:/1.fll', 'w')
pickle.dump(DataTx, outfile)
outfile.close()
try:
infile = open('C:/2.fll', 'r')
DataRx = pickle.load(infile)
except:
print('IOError')
# Common script for both master and slave
DescTx = 'Tx: ' + str(DataTx)
DescRx = 'Rx: ' + str(DataRx)
XPLMDrawString(color, left + 5, top - 10, DescTx, 0, xplmFont_Basic)
XPLMDrawString(color, left + 5, top - 20, DescRx, 0, xplmFont_Basic)
pass
def KeyCallback(self, inWindowID, inKey, inFlags, inVirtualKey, inRefcon, losingFocus):
pass
def MouseClickCallback(self, inWindowID, x, y, inMouse, inRefcon):
if (inMouse == xplm_MouseDown) or (inMouse == xplm_MouseUp):
self.Clicked = 1 - self.Clicked
return 1