from time import sleep

from SimConnect import *

# Create SimConnect link
sm = SimConnect()
# Note the default _time is 2000 to be refreshed every 2 seconds
aq = AircraftRequests(sm, _time=2000)
# Use _time=ms where ms is the time in milliseconds to cache the data.
# Setting ms to 0 will disable data caching and always pull new data from the sim.
# There is still a timeout of 4 tries with a 10ms delay between checks.
# If no data is received in 40ms the value will be set to None
# Each request can be fine tuned by setting the time param.

# To find and set timeout of cached data to 200ms:
altitude = aq.find("PLANE_ALTITUDE")
altitude.time = 200
kohl = aq.find("AIRSPEED_TRUE")
print(kohl)
#altitude.time = 200
a=9
bleed = aq.list
for i in aq.list:
    print(i)
while a<10:
    altitude = aq.get("PLANE_ALTITUDE")
    speed = aq.get("AIRSPEED_TRUE")
    kompass = aq.get("MAGNETIC_COMPASS")
    fuel = aq.get('FUEL_TOTAL_QUANTITY_WEIGHT')
    gps_speed = aq.get('GPS_GROUND_SPEED')
    baro = aq.get('SEA_LEVEL_PRESSURE')
    altitude = round(altitude + 1000)
    alt_fuss = round(altitude * 3.28 / 1000)
    print('Höhe',altitude, alt_fuss)
    print('TAS', round(speed))
    print('Kurs', round(kompass))
    print('Fuel', round(fuel*0.4536/1000,1))
    print('gps_speed', gps_speed)
    print('baro',baro)

    sleep(3)