Ejemplo n.º 1
0
void IntArrayDataRef::setValue(QString &newValue) {
    // Check that value starts with [ and ends with ]
    if(!newValue.startsWith('[') || !newValue.endsWith(']')) {
        INFO << "Invalid array value";
        return;
    }

    // Remove [] and split values
    QString arrayString = newValue.mid(1, newValue.length() - 2);
    QStringList values = arrayString.split(',');

    // Limit number of values to write to ref length or number of given values
    int numberOfValuesToWrite = qMin(_length, values.size());

    // Convert values to int and copy to _valueArray
    for(int i=0;i<numberOfValuesToWrite;i++) {
        bool ok = true;
        int value = values[i].toInt(&ok);
        if(!ok) {
            INFO << "Invalid value " << values[i] << "in array";
            return;
        }
        _valueArray[i]=value;
    }
    XPLMSetDatavi(_ref, _valueArray, 0, numberOfValuesToWrite);
    emit changed(this);
}
Ejemplo n.º 2
0
int sp_process(uint32_t msg) {
    //sprintf(tmp, "-> CP: sp_controller.sp_process: msg: %d\n", msg);
	//XPLMDebugString(tmp);
	int res = 0;
    gEngineKnob = msg & SP_READ_ENGINES_KNOB_MASK;
    uint32_t landingGearUp = msg & SP_READ_GEARLEVER_UP_MASK;
    uint32_t landingGearDown = msg & SP_READ_GEARLEVER_DOWN_MASK;
    uint32_t lightsLanding = msg & SP_READ_LIGHTS_LANDING_MASK;
    uint32_t lightsTaxi = msg & SP_READ_LIGHTS_TAXI_MASK;
    uint32_t lightsStrobe = msg & SP_READ_LIGHTS_STROBE_MASK;
    uint32_t lightsNav = msg & SP_READ_LIGHTS_NAV_MASK;
    uint32_t lightsBeacon = msg & SP_READ_LIGHTS_BEACON_MASK;
    uint32_t lightsPanel = msg & SP_READ_LIGHTS_PANEL_MASK;
    uint32_t cowl = msg & SP_READ_COWL_MASK;
    uint32_t pitot = msg & SP_READ_PITOT_HEAT_MASK;
    uint32_t deice = msg & SP_READ_DE_ICE_MASK;
    uint32_t fuelPump = msg & SP_READ_FUEL_PUMP_MASK;
    uint32_t avionicsMaster = msg & SP_READ_AVIONICS_MASTER_MASK;
    uint32_t masterBattery = msg & SP_READ_MASTER_BAT_MASK;
    uint32_t masterAltBattery = msg & SP_READ_MASTER_ALT_MASK;

    if (gEngineKnob) {
    	gEngineKnobState = gEngineKnob;
    	sp_process_knob(gEngineKnob);
    }
    if (landingGearUp) {
    	gSpGearSwitchUp = 1;
    	XPLMCommandOnce(gSpLandingGearUpCmdRef);
    } else if (landingGearDown) {
    	gSpGearSwitchUp = 0;
    	XPLMCommandOnce(gSpLandingGearDownCmdRef);
    }

    if (lightsLanding) {
    	XPLMCommandOnce(gSpLightsLandingOnCmdRef);
    } else {
    	XPLMCommandOnce(gSpLightsLandingOffCmdRef);
    }
    if (lightsTaxi) {
    	XPLMCommandOnce(gSpLightsTaxiOnCmdRef);
    } else {
    	XPLMCommandOnce(gSpLightsTaxiOffCmdRef);
    }
    if (lightsPanel) {
    	XPLMSetDataf(gSpCockpitLightsDataRef, 1);
    } else {
    	XPLMSetDataf(gSpCockpitLightsDataRef, 0);
    }
    if (lightsBeacon) {
    	XPLMCommandOnce(gSpLightsBeaconOnCmdRef);
    } else {
    	XPLMCommandOnce(gSpLightsBeaconOffCmdRef);
    }
    if (lightsNav) {
    	XPLMCommandOnce(gSpLightsNavOnCmdRef);
    } else {
    	XPLMCommandOnce(gSpLightsNavOffCmdRef);
    }
    if (lightsStrobe) {
    	XPLMCommandOnce(gSpLightsStrobeOnCmdRef);
    } else {
    	XPLMCommandOnce(gSpLightsStrobeOffCmdRef);
    }
    if (masterBattery) {
    	if (gSpNumberOfBatteries == 1) {
    		gSpBatArrayOn[0] = 1;
    	} else if (gSpNumberOfBatteries == 2) {
    		gSpBatArrayOn[0] = 1;
    		gSpBatArrayOn[1] = 1;
    	} else if (gSpNumberOfBatteries == 3) {
    		gSpBatArrayOn[0] = 1;
    		gSpBatArrayOn[1] = 1;
    		gSpBatArrayOn[2] = 1;
    	} else if (gSpNumberOfBatteries == 4) {
    		gSpBatArrayOn[0] = 1;
    		gSpBatArrayOn[1] = 1;
    		gSpBatArrayOn[2] = 1;
    		gSpBatArrayOn[3] = 1;
    	} else if (gSpNumberOfBatteries == 5) {
    		gSpBatArrayOn[0] = 1;
    		gSpBatArrayOn[1] = 1;
    		gSpBatArrayOn[2] = 1;
    		gSpBatArrayOn[3] = 1;
    		gSpBatArrayOn[4] = 1;
    	} else if (gSpNumberOfBatteries == 6) {
    		gSpBatArrayOn[0] = 1;
    		gSpBatArrayOn[1] = 1;
    		gSpBatArrayOn[2] = 1;
    		gSpBatArrayOn[3] = 1;
    		gSpBatArrayOn[4] = 1;
    		gSpBatArrayOn[5] = 1;
    	} else if (gSpNumberOfBatteries == 7) {
    		gSpBatArrayOn[0] = 1;
    		gSpBatArrayOn[1] = 1;
    		gSpBatArrayOn[2] = 1;
    		gSpBatArrayOn[3] = 1;
    		gSpBatArrayOn[4] = 1;
    		gSpBatArrayOn[5] = 1;
    		gSpBatArrayOn[6] = 1;
    	} else if (gSpNumberOfBatteries == 8) {
    		gSpBatArrayOn[0] = 1;
    		gSpBatArrayOn[1] = 1;
    		gSpBatArrayOn[2] = 1;
    		gSpBatArrayOn[3] = 1;
    		gSpBatArrayOn[4] = 1;
    		gSpBatArrayOn[5] = 1;
    		gSpBatArrayOn[6] = 1;
    		gSpBatArrayOn[7] = 1;
    	}
    	XPLMSetDatavi(gSpBatteryArrayOnDataRef, gSpBatArrayOn, 0, 8);
    } else {
    	if (gSpNumberOfBatteries == 1) {
    		gSpBatArrayOn[0] = 0;
    	} else if (gSpNumberOfBatteries == 2) {
    		gSpBatArrayOn[0] = 0;
    		gSpBatArrayOn[1] = 0;
    	} else if (gSpNumberOfBatteries == 3) {
    		gSpBatArrayOn[0] = 0;
    		gSpBatArrayOn[1] = 0;
    		gSpBatArrayOn[2] = 0;
    	} else if (gSpNumberOfBatteries == 4) {
    		gSpBatArrayOn[0] = 0;
    		gSpBatArrayOn[1] = 0;
    		gSpBatArrayOn[2] = 0;
    		gSpBatArrayOn[3] = 0;
    	} else if (gSpNumberOfBatteries == 5) {
    		gSpBatArrayOn[0] = 0;
    		gSpBatArrayOn[1] = 0;
    		gSpBatArrayOn[2] = 0;
    		gSpBatArrayOn[3] = 0;
    		gSpBatArrayOn[4] = 0;
    	} else if (gSpNumberOfBatteries == 6) {
    		gSpBatArrayOn[0] = 0;
    		gSpBatArrayOn[1] = 0;
    		gSpBatArrayOn[2] = 0;
    		gSpBatArrayOn[3] = 0;
    		gSpBatArrayOn[4] = 0;
    		gSpBatArrayOn[5] = 0;
    	} else if (gSpNumberOfBatteries == 7) {
    		gSpBatArrayOn[0] = 0;
    		gSpBatArrayOn[1] = 0;
    		gSpBatArrayOn[2] = 0;
    		gSpBatArrayOn[3] = 0;
    		gSpBatArrayOn[4] = 0;
    		gSpBatArrayOn[5] = 0;
    		gSpBatArrayOn[6] = 0;
    	} else if (gSpNumberOfBatteries == 8) {
    		gSpBatArrayOn[0] = 0;
    		gSpBatArrayOn[1] = 0;
    		gSpBatArrayOn[2] = 0;
    		gSpBatArrayOn[3] = 0;
    		gSpBatArrayOn[4] = 0;
    		gSpBatArrayOn[5] = 0;
    		gSpBatArrayOn[6] = 0;
    		gSpBatArrayOn[7] = 0;
    	}
    	XPLMSetDatavi(gSpBatteryArrayOnDataRef, gSpBatArrayOn, 0, 8);
    }
    if (masterAltBattery) {
    	XPLMCommandOnce(gSpMasterAltBatteryOnCmdRef);
    	if (gSpNumberOfGenerators == 1) {
        	XPLMCommandOnce(gSpGeneratorOn1CmdRef);
    	} else if (gSpNumberOfGenerators == 2) {
        	XPLMCommandOnce(gSpGeneratorOn1CmdRef);
        	XPLMCommandOnce(gSpGeneratorOn2CmdRef);
    	} else if (gSpNumberOfGenerators == 3) {
        	XPLMCommandOnce(gSpGeneratorOn1CmdRef);
        	XPLMCommandOnce(gSpGeneratorOn2CmdRef);
        	XPLMCommandOnce(gSpGeneratorOn3CmdRef);
    	} else if (gSpNumberOfGenerators == 4) {
        	XPLMCommandOnce(gSpGeneratorOn1CmdRef);
        	XPLMCommandOnce(gSpGeneratorOn2CmdRef);
        	XPLMCommandOnce(gSpGeneratorOn3CmdRef);
        	XPLMCommandOnce(gSpGeneratorOn4CmdRef);
    	}
    } else {
    	XPLMCommandOnce(gSpMasterAltBatteryOffCmdRef);
    	if (gSpNumberOfGenerators == 1) {
        	XPLMCommandOnce(gSpGeneratorOff1CmdRef);
    	} else if (gSpNumberOfGenerators == 2) {
        	XPLMCommandOnce(gSpGeneratorOff1CmdRef);
        	XPLMCommandOnce(gSpGeneratorOff2CmdRef);
    	} else if (gSpNumberOfGenerators == 3) {
        	XPLMCommandOnce(gSpGeneratorOff1CmdRef);
        	XPLMCommandOnce(gSpGeneratorOff2CmdRef);
        	XPLMCommandOnce(gSpGeneratorOff3CmdRef);
    	} else if (gSpNumberOfGenerators == 4) {
        	XPLMCommandOnce(gSpGeneratorOff1CmdRef);
        	XPLMCommandOnce(gSpGeneratorOff2CmdRef);
        	XPLMCommandOnce(gSpGeneratorOff3CmdRef);
        	XPLMCommandOnce(gSpGeneratorOff4CmdRef);
    	}
    }
    if (avionicsMaster) {
    	XPLMCommandOnce(gSpMasterAvionicsOnCmdRef);
    } else {
    	XPLMCommandOnce(gSpMasterAvionicsOffCmdRef);
    }
    if (fuelPump) {
    	if (gSpNumberOfEngines == 1) {
        	XPLMCommandOnce(gSpFuelPumpOn1CmdRef);
    	} else if (gSpNumberOfEngines == 2) {
        	XPLMCommandOnce(gSpFuelPumpOn1CmdRef);
        	XPLMCommandOnce(gSpFuelPumpOn2CmdRef);
    	} else if (gSpNumberOfEngines == 3) {
        	XPLMCommandOnce(gSpFuelPumpOn1CmdRef);
        	XPLMCommandOnce(gSpFuelPumpOn2CmdRef);
        	XPLMCommandOnce(gSpFuelPumpOn3CmdRef);
    	} else if (gSpNumberOfEngines == 4) {
        	XPLMCommandOnce(gSpFuelPumpOn1CmdRef);
        	XPLMCommandOnce(gSpFuelPumpOn2CmdRef);
        	XPLMCommandOnce(gSpFuelPumpOn3CmdRef);
        	XPLMCommandOnce(gSpFuelPumpOn4CmdRef);
    	}
    } else {
    	if (gSpNumberOfEngines == 1) {
        	XPLMCommandOnce(gSpFuelPumpOff1CmdRef);
    	} else if (gSpNumberOfEngines == 2) {
        	XPLMCommandOnce(gSpFuelPumpOff1CmdRef);
        	XPLMCommandOnce(gSpFuelPumpOff2CmdRef);
    	} else if (gSpNumberOfEngines == 3) {
        	XPLMCommandOnce(gSpFuelPumpOff1CmdRef);
        	XPLMCommandOnce(gSpFuelPumpOff2CmdRef);
        	XPLMCommandOnce(gSpFuelPumpOff3CmdRef);
    	} else if (gSpNumberOfEngines == 4) {
        	XPLMCommandOnce(gSpFuelPumpOff1CmdRef);
        	XPLMCommandOnce(gSpFuelPumpOff2CmdRef);
        	XPLMCommandOnce(gSpFuelPumpOff3CmdRef);
        	XPLMCommandOnce(gSpFuelPumpOff4CmdRef);
    	}
    }
    if (deice) {
    	XPLMSetDatai(gSpAntiIceDataRef, 1);
    } else {
    	XPLMSetDatai(gSpAntiIceDataRef, 0);
    }
    if (pitot) {
    	XPLMCommandOnce(gSpPitotHeatOnCmdRef);
    } else {
    	XPLMCommandOnce(gSpPitotHeatOffCmdRef);
    }
    if (cowl) {
    	if (gSpNumberOfEngines == 1) {
    		gSpOpencowl[0] = 1;
    	} else if (gSpNumberOfEngines == 2) {
    		gSpOpencowl[0] = 1;
    		gSpOpencowl[1] = 1;
    	} else if (gSpNumberOfEngines == 3) {
    		gSpOpencowl[0] = 1;
    		gSpOpencowl[1] = 1;
    		gSpOpencowl[2] = 1;
    	} else if (gSpNumberOfEngines == 4) {
    		gSpOpencowl[0] = 1;
    		gSpOpencowl[1] = 1;
    		gSpOpencowl[2] = 1;
    		gSpOpencowl[3] = 1;
    	}
    	XPLMSetDatavf(gSpCowlFlapsDataRef, gSpOpencowl, 0, 8);
    } else {
    	if (gSpNumberOfEngines == 1) {
    		gSpClosecowl[0] = 1;
    	} else if (gSpNumberOfEngines == 2) {
    		gSpClosecowl[0] = 1;
    		gSpClosecowl[1] = 1;
    	} else if (gSpNumberOfEngines == 3) {
    		gSpClosecowl[0] = 1;
    		gSpClosecowl[1] = 1;
    		gSpClosecowl[2] = 1;
    	} else if (gSpNumberOfEngines == 4) {
    		gSpClosecowl[0] = 1;
    		gSpClosecowl[1] = 1;
    		gSpClosecowl[2] = 1;
    		gSpClosecowl[3] = 1;
    	}
    	XPLMSetDatavf(gSpCowlFlapsDataRef, gSpClosecowl, 0, 8);
    }

    return res;
}