#include <stdio.h>#include <string.h>#include "XPLMPlugin.h"#include "XPLMProcessing.h"#include "XPLMDataAccess.h"enum boolean {false = 0, true =1}; //Constants for custom DataRef registration on DataRef Editor pluginlong const MSG_ADD_DATAREF = 0x01000000; //Message to DataRef Editor to add a custom DataRef referencelong const NO_PLUGIN_ID = -1; //Return value when a plugin is not found by ID//Global varsboolean acf_first_three_gears_down_DatarefEditor_Published = false; //Is our custom DataRef yet published on DataRef Editor?long first_three_gears_down = 0; //Internal variable to keep the value of our custom DataRefXPLMDataRef acf_gear_deploy_dataref = NULL; //X-Plane DataRef reference IDXPLMDataRef Accesor1 = NULL; //Handle to the Data Accessor for our custom DataRef//Prototyping//Main flight loop call backfloat MyFlightLoopCallback( float inElapsedSinceLastCall, float inElapsedTimeSinceLastFlightLoop, int inCounter, void * inRefcon);int fn_first_three_gears_down(void * inRefcon);PLUGIN_API int XPluginStart( char * outName, char * outSig, char * outDesc){ strcpy(outName, "Test3"); strcpy(outSig, "Kha29096335.examples.test3"); strcpy(outDesc, "The plugin creates a custom dataref"); //Flag for custom DataRef published in DatarefEditor - We need to publish our custom DataRef only one time, this flag is used to check if the DataRef is yet registered to avoid more than one registration at each loopback call acf_first_three_gears_down_DatarefEditor_Published = false; //Internal variable default value - This variable will keep the value for our custom DataRef - The default value is defined at variable declaration too first_three_gears_down = 0; acf_gear_deploy_dataref = XPLMFindDataRef("sim/aircraft/parts/acf_gear_deploy"); XPLMRegisterFlightLoopCallback(MyFlightLoopCallback, 1, 0); return 1;}PLUGIN_API int XPluginEnable(void){ //Registration of the custom DataRef functions for curso04/aircraft/parts/acf_first_three_gears_down //When our plugin is loaded, it needs register all custom DataRefs in X-Plane (one accessor for each custom DataRef) Accesor1 = XPLMRegisterDataAccessor("curso04/aircraft/parts/acf_first_three_gears_down", xplmType_Int, 0, fn_first_three_gears_down, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 0); return 1;}PLUGIN_API void XPluginDisable(void){ //Unregistration of the custom DataRef //When our plugin is unloaded, we need unregister all customs DataRefs because they will be unavailable XPLMUnregisterDataAccessor(Accesor1);}PLUGIN_API void XPluginStop(void){ // The Callback function is unregistered and the window destroyed XPLMUnregisterFlightLoopCallback(MyFlightLoopCallback,NULL);}float MyFlightLoopCallback( float inElapsedSinceLastCall, float inElapsedTimeSinceLastFlightLoop, int inCounter, void * inRefcon){ long PluginID = XPLM_NO_PLUGIN_ID; float acf_gear_deploy_values[]={-1,-1,-1}; boolean all_down_flag = false; int i = 0; //Publication on the DatarefEditor plugin for testing purposes //We will register our custom DataRef in DatarefEditor if it is not register yet (checking the flag) if(acf_first_three_gears_down_DatarefEditor_Published == false) { //We look for the DatarefEditor's internal id to send the 'register DataRef' message to him PluginID = XPLMFindPluginBySignature("xplanesdk.examples.DataRefEditor"); //If the id for DatarefEditor is found, we send the message if (PluginID != XPLM_NO_PLUGIN_ID) { XPLMSendMessageToPlugin(PluginID, MSG_ADD_DATAREF, "curso04/aircraft/parts/acf_first_three_gears_down"); //We set the status of the DataRef to 'published in DatarefEditor' acf_first_three_gears_down_DatarefEditor_Published = true; } } //Sets the custom DataRef based on first tree gears status XPLMGetDatavf(acf_gear_deploy_dataref, acf_gear_deploy_values, 0, 3); all_down_flag = true; //if(sizeof(acf_gear_deploy_values) / sizeof(*acf_gear_deploy_values) > 3) if(acf_gear_deploy_values[0] != -1) { for (i=0;i<3;i++) { if (acf_gear_deploy_values[i] < 1.0) { all_down_flag = false; } } if (all_down_flag == true) first_three_gears_down = 1; else first_three_gears_down = 0; } return 1.0;}int fn_first_three_gears_down(void * inRefcon){ return first_three_gears_down;}