def buttonHandler():
    # Reads memB for which buttons are pressed, then sends
    # calls to telemachus as needed.
    global memB
    global memBOLD
    if memB[1] == '1' and memB[1] != memBOLD[1]:
        if (memB[7] == '1'):  # Check the safety
            tele.stage()

    if memB[0] == '1' and memB[0] != memBOLD[0]:
        if memB[7] == '1':  # Check the safety
            tele.abort()

    if int(memB[2]) == 1 and memB[2] != memBOLD[2]:
        # Toggle gear based on what we did last time
        if ps['Gear Status'] is True:
            # Telemachus does not yet read gear status
            tele.gear(0)
            ps['Gear Status'] = False
        elif ps['Gear Status'] is False:
            tele.gear(1)
            ps['Gear Status'] = True

    if int(memB[3]) == 1 and memB[3] != memBOLD[3]:
        # Toggle Light based on the Telemachus reading
        if fd['Light Status'] is True:
            tele.light(0)
        elif fd['Light Status'] is False:
            tele.light(1)

    if int(memB[4]) == 1 and memB[4] != memBOLD[4]:
        # Toggle brake based on what we did last time
        if ps['Brake Status'] is True:
            # Telemachus does not yet read brake status
            tele.brake(0)
            ps['Brake Status'] = False
        elif ps['Brake Status'] is False:
            tele.brake(1)
            ps['Brake Status'] = True

    if int(memB[5]) == 1 and memB[5] != memBOLD[5]:
        # Toggle RCS based on the Telemachus reading
        if fd['RCS Status'] is True:
            tele.rcs(0)
        elif fd['RCS Status'] is False:
            tele.rcs(1)

    if int(memB[6]) == 1 and memB[6] != memBOLD[6]:
        # Toggle SAS based on the Telemachus reading
        if fd['SAS Status'] is True:
            tele.sas(0)
        elif fd['SAS Status'] is False:
            tele.sas(1)
Exemple #2
0
def buttonHandler():
    global gearStatus
    global brakeStatus
    global memB
    global memBOLD
    if memB[1] == '1' and memB[1] != memBOLD[1]:
        if (memB[7] == '1'):  # Check the safety
            tele.stage()

    if memB[0] == '1' and memB[0] != memBOLD[0]:
        if memB[7] == '1':  # Check the safety
            tele.abort()

    if int(memB[2]) == 1 and memB[2] != memBOLD[2]:
        # Toggle gear based on what we did last time
        if gearStatus == 1:  # Telemachus does not yet read gear status
            tele.gear(0)
            gearStatus = 0
        elif gearStatus == 0:
            tele.gear(1)
            gearStatus = 1

    if int(memB[3]) == 1 and memB[3] != memBOLD[3]:
        # Toggle Light based on the Telemachus reading
        if tele.light(2) == 1:
            tele.light(0)
        elif tele.light(2) == 0:
            tele.light(1)

    if int(memB[4]) == 1 and memB[4] != memBOLD[4]:
        # Toggle brake based on what we did last time
        if brakeStatus == 1:  # Telemachus does not yet read brake status
            tele.brake(0)
            brakeStatus = 0
        elif brakeStatus == 0:
            tele.brake(1)
            brakeStatus = 1

    if int(memB[5]) == 1 and memB[5] != memBOLD[5]:
        # Toggle RCS based on the Telemachus reading
        if tele.rcs(2) == 1:
            tele.rcs(0)
        elif tele.rcs(2) == 0:
            tele.rcs(1)

    if int(memB[6]) == 1 and memB[6] != memBOLD[6]:
        # Toggle SAS based on the Telemachus reading
        if tele.sas(2) == 1:
            tele.sas(0)
        elif tele.sas(2) == 0:
            tele.sas(1)
def buttonHandler():
    global gearStatus
    global brakeStatus
    global memB
    global memBOLD
    if memB[1] == '1' and memB[1] != memBOLD[1]:
        if (memB[7] == '1'):  # Check the safety
            tele.stage()

    if memB[0] == '1' and memB[0] != memBOLD[0]:
        if memB[7] == '1':  # Check the safety
            tele.abort()

    if int(memB[2]) == 1 and memB[2] != memBOLD[2]:
        # Toggle gear based on what we did last time
        if gearStatus == 1:  # Telemachus does not yet read gear status
            tele.gear(0)
            gearStatus = 0
        elif gearStatus == 0:
            tele.gear(1)
            gearStatus = 1

    if int(memB[3]) == 1 and memB[3] != memBOLD[3]:
        # Toggle Light based on the Telemachus reading
        if tele.light(2) == 1:
            tele.light(0)
        elif tele.light(2) == 0:
            tele.light(1)

    if int(memB[4]) == 1 and memB[4] != memBOLD[4]:
        # Toggle brake based on what we did last time
        if brakeStatus == 1:  # Telemachus does not yet read brake status
            tele.brake(0)
            brakeStatus = 0
        elif brakeStatus == 0:
            tele.brake(1)
            brakeStatus = 1

    if int(memB[5]) == 1 and memB[5] != memBOLD[5]:
        # Toggle RCS based on the Telemachus reading
        if tele.rcs(2) == 1:
            tele.rcs(0)
        elif tele.rcs(2) == 0:
            tele.rcs(1)

    if int(memB[6]) == 1 and memB[6] != memBOLD[6]:
        # Toggle SAS based on the Telemachus reading
        if tele.sas(2) == 1:
            tele.sas(0)
        elif tele.sas(2) == 0:
            tele.sas(1)
def getFlightData(dIN):
    # Try to update the dictionary with live data. If any of it fails for any
    # reason, return the original dictionary and set the 'Radio Contact' key
    # to false.
    d = {'Zero': 0}
    try:
        d['MET'] = float(tele.read_missiontime())
        d['ASL'] = int(tele.read_asl())
        d['Height From Terrain'] = int(tele.read_heightFromTerrain())
        d['Body'] = str(tele.read_body())
        d['Ap'] = int(tele.read_apoapsis())
        d['Pe'] = int(tele.read_periapsis())
        d['Time to Ap'] = float(tele.read_time_to_ap())
        d['Time to Pe'] = float(tele.read_time_to_pe())
        d['Eccentricity'] = float(tele.read_eccentricity())
        d['Inclination'] = float(tele.read_inclination())
        d['Orbital Period'] = float(tele.read_orbitalperiod())
        d['Vertical Speed'] = float(tele.read_verticalspeed())
        d['Surface Speed'] = float(tele.read_surfacespeed())
        d['Pitch'] = float(tele.read_facing('pitch'))
        d['Yaw'] = float(tele.read_facing('yaw'))
        d['Roll'] = float(tele.read_facing('roll'))
        d['Throttle'] = float(tele.read_throttle())

        d['Brake Status'] = int(tele.brake(2))
        d['Gear Status'] = int(tele.gear(2))
        d['SAS Status'] = int(tele.sas(2))
        d['RCS Status'] = int(tele.rcs(2))
        d['Light Status'] = int(tele.light(2))

        d['ElectricCharge'] = float(tele.read_resource('ElectricCharge'))
        d['Max ElectricCharge'] = float(tele.read_resource_max(
            'ElectricCharge'))
        d['LiquidFuel'] = float(tele.read_resource('LiquidFuel'))
        d['Max LiquidFuel'] = float(tele.read_resource_max('LiquidFuel'))
        d['Oxidizer'] = float(tele.read_resource('Oxidizer'))
        d['Max Oxidizer'] = float(tele.read_resource_max('Oxidizer'))
        d['SolidFuel'] = float(tele.read_resource('SolidFuel'))
        d['Max SolidFuel'] = float(tele.read_resource_max('SolidFuel'))
        d['MonoPropellant'] = float(tele.read_resource('MonoPropellant'))
        d['Max MonoPropellant'] = float(tele.read_resource_max('MonoPropellant'))
        # If you are playing with realism mods, uncomment these as needed
        d['Oxygen'] = float(tele.read_resource('Oxygen'))
        d['Max Oxygen'] = float(tele.read_resource_max('Oxygen'))
        d['LiquidOxygen'] = float(tele.read_resource('LiquidOxygen'))
        d['Max LiquidOxygen'] = float(tele.read_resource_max('LiquidOxygen'))
        d['LiquidH2'] = float(tele.read_resource('LiquidH2'))
        d['Max LiquidH2'] = float(tele.read_resource_max('LiquidH2'))
        d['MMH'] = float(tele.read_resource('MMH'))
        d['Max MMH'] = float(tele.read_resource_max('MMH'))
        d['N2O4'] = float(tele.read_resource('N2O4'))
        d['Max N2O4'] = float(tele.read_resource_max('N2O4'))

        d['Previous Radio Contact'] = dIN['Radio Contact']
        d['Radio Contact'] = True

        #Clean up the data types
        if d['SAS Status'] == 1:
            d['SAS Status'] = True
        elif d['SAS Status'] == 0:
            d['SAS Status'] = False
        else:
            d['SAS Status'] = 'Error'
        if d['RCS Status'] == 1:
            d['RCS Status'] = True
        else:
            d['RCS Status'] = False
        if d['Light Status'] == 1:
            d['Light Status'] = True
        else:
            d['Light Status'] = False
        if d['Gear Status'] == 1:
            d['Gear Status'] = True
        elif d['Gear Status'] == 0:
            d['Gear Status'] = False
        if d['Brake Status'] == 1:
            d['Brake Status'] = True
        elif d['Brake Status'] == 0:
            d['Brake Status'] = False

        return d

    except:
        dIN['Previous Radio Contact'] = dIN['Radio Contact']
        dIN['Radio Contact'] = False
        del d
        return dIN