From bfedc6bdc3272d72f691ae1b81dfdc10fad65818 Mon Sep 17 00:00:00 2001 From: Andrey Prokhorov Date: Sun, 14 Apr 2019 23:48:32 +0300 Subject: [PATCH] Initial commit --- inflight.py | 114 +++++++++++++++++++++++++++++++++++++++++++++++++ prox-style.css | 72 +++++++++++++++++++++++++++++++ setup.cmd | 1 + setup.py | 4 ++ 4 files changed, 191 insertions(+) create mode 100644 inflight.py create mode 100644 prox-style.css create mode 100644 setup.cmd create mode 100644 setup.py diff --git a/inflight.py b/inflight.py new file mode 100644 index 0000000..9949ad0 --- /dev/null +++ b/inflight.py @@ -0,0 +1,114 @@ +# This Python file uses the following encoding: utf-8 +from time import sleep +from math import degrees +import sys +import pyuipc + +P3Dv4 = 12 +XPL11 = 0 +VERSIONS = [P3Dv4, XPL11] + +def open_file(): + try: + fh = open("bar.html", "w") + except: + print("Cannot open file for writing!") + else: + return fh + +def write_data(file, hdg, alt, fpm, gs, gf, aoa): + data = "" + data += "" + data += "" + data += "" + data += "" + data += "" + data += "
" + data += "
" + str(hdg) + "
" + data += "
" + str(alt) + "
" + data += "
" + str(fpm) + "
" + data += "
" + str(gs) + "
" + data += "
" + str(aoa) + "
" + data += "
" + str(gf) + "
" + data += "" + try: + file.write(data) + file.close() + except: + print("Error writing to file!") + file.close() + + +while True: + try: + pyuipc.open(XPL11) + while True: + try: + l = list() + t0 = (0x0580, 'u') # heading + t1 = (0x0570, 'l') # alt + t2 = (0x02b4, 'd') # ground speed + t3 = (0x02a0, 'h') # magvar + t4 = (0x1140, 'f') # G-force + t5 = (0x030c, 'd') # vspeed at touchdown + t6 = (0x2ed0, 'f') # AOA + l = [t0, t1, t2, t3, t4, t5, t6] + res = pyuipc.read(l) + + hdg = res[0]*360/(65535*65535) + magvar = int(res[3] * 360 / 65536) + mag = hdg - magvar + if mag < 0: + mag = 360 + mag + if mag == 0: + mag = 360 + mag = str(mag) + if len(mag) == 1: + mag = "00" + mag + elif len(mag) == 2: + mag = "0" + mag + + alt = int(res[1]*3.28084/(65536*65536)) + + gs = res[2]*3600/65536/1852 + + gf = str(res[4]) + if len(gf) > 3: + if gf[0] == "-": + gf = gf[0:5] + else: + gf = gf[0:4] + + tdvspeed = int(res[5]*60*3.28084/256) + + aoa = str(degrees(res[6])) + if aoa[0] == "-": + aoa = aoa[0:5] + else: + aoa = aoa[0:4] + + print("Hdg: " + str(mag)) + print("Alt: " + str(alt) + " ft") + print("Gs: " + str(gs) + " kts") + print("G-force: " + str(gf)) + print("T/D VSpeed: " + str(tdvspeed)) + print("AOA: " + str(aoa)) + print("---") + fh = open_file() + write_data(fh, mag, alt, tdvspeed, gs, gf, aoa) + sleep(2) + except: + print("Error") + print(sys.exc_info()[0]) + try: + pyuipc.close() + except: + pass + break + except pyuipc.FSUIPCException as e: + print("Exception") + print(str(e.errorCode) + " " + e.errorString) + sleep(10) + except: + print("Probably incorrect FSUIPC version or simulator is not started. Timeout 10 sec.") + sleep(10) \ No newline at end of file diff --git a/prox-style.css b/prox-style.css new file mode 100644 index 0000000..c70c78a --- /dev/null +++ b/prox-style.css @@ -0,0 +1,72 @@ +.flexbox { + display: flex ; + flex-direction: row ; + flex-wrap: wrap ; + justify-content: flex-start ; + align-items: center ; + align-content: center ; + margin: 10px +} + +.block { + background: rgba(0, 0, 0, .34); + padding: 10px; + color: #fff; + margin: 3px +} + +.block:before { + font-weight: 700; + #color: #00b5ca; + color: #00ffaa; + text-transform: uppercase +} + +.block:after { + color: hsla(0, 0%, 100%, .6) +} + +.heading:before { + content: 'Hdg: ' +} + +.heading:after { + content: '°' +} + +.altitude:before { + content: 'Alt: ' +} + +.altitude:after { + content: ' ft' +} + +.speed:before { + content: 'G/S: ' +} + +.speed:after { + content: ' kts' +} + +.vs:before { + content: 'V/S: ' +} + +.vs:after { + content: ' fpm' +} + +.gf:before { + content: 'G: ' +} + +.aoa:before { + text-transform: lowercase; + content: 'α: ' +} + +.aoa:after { + content: '°' +} diff --git a/setup.cmd b/setup.cmd new file mode 100644 index 0000000..9519647 --- /dev/null +++ b/setup.cmd @@ -0,0 +1 @@ +python setup.py py2exe \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..4c385e1 --- /dev/null +++ b/setup.py @@ -0,0 +1,4 @@ +from distutils.core import setup +import py2exe + +setup(console=['inflight.py']) \ No newline at end of file