#include <stdio.h>#include <string.h>#include "XPLMPlugin.h"#include "XPLMDisplay.h"#include "XPLMGraphics.h"#include "XPLMProcessing.h"#include "XPLMDataAccess.h"#include "XPLMUtilities.h"//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 IDint Mydataref_DatarefEditor_Published = 0; //Is our custom DataRef yet published on DataRef Editor?long Mydataref = 0; //Internal variable to keep the value of our custom DataRefXPLMDataRef Accesor1 = NULL; //Handle to the Data Accessor for our custom DataRefstatic float MyFlightLoopCallback( float inElapsedSinceLastCall, float inElapsedTimeSinceLastFlightLoop, int inCounter, void * inRefcon); int fn_Mydataref_Status(void * inRefcon);void fn_Mydataref_Write(void * inRefcon, int Invalue);/* * XPluginStart * * Our start routine registers our window and does any other initialization we * must do. * */PLUGIN_API int XPluginStart( char * outName, char * outSig, char * outDesc){ strcpy(outName, "Prueba"); strcpy(outSig, "AlcalaSim.Plugins.Prueba"); strcpy(outDesc, "Prueba Publicacion Dataref"); XPLMRegisterFlightLoopCallback( MyFlightLoopCallback, /* Callback */ 1.0, /* Interval */ NULL); /* refcon not used. */ return 1;}/* * XPluginStop * * Our cleanup routine deallocates our window. * */PLUGIN_API void XPluginStop(void){ XPLMUnregisterFlightLoopCallback(MyFlightLoopCallback, NULL);}/* * XPluginDisable * * We do not need to do anything when we are disabled, but we must provide the handler. * */PLUGIN_API void XPluginDisable(void){}/* * XPluginEnable. * * We don't do any enable-specific initialization, but we must return 1 to indicate * that we may be enabled at this time. * */PLUGIN_API int XPluginEnable(void){ //Registration of the custom DataRef functions for C130/aircraft/parts/Mydataref //When our plugin is loaded, it needs register all custom DataRefs in X-Plane (one accessor for each custom DataRef) Accesor1 = XPLMRegisterDataAccessor("C130/aircraft/parts/Mydataref", xplmType_Int, 1, fn_Mydataref_Status, fn_Mydataref_Write, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 0); return 1;}/* * XPluginReceiveMessage * * We don't have to do anything in our receive message handler, but we must provide one. * */PLUGIN_API void XPluginReceiveMessage( XPLMPluginID inFromWho, long inMessage, void * inParam){}float MyFlightLoopCallback( float inElapsedSinceLastCall, float inElapsedTimeSinceLastFlightLoop, int inCounter, void * inRefcon){ long PluginID = XPLM_NO_PLUGIN_ID; //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(Mydataref_DatarefEditor_Published == 0) { //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,(void*)"C130/aircraft/parts/Mydataref"); //We set the status of the DataRef to 'published in DatarefEditor' Mydataref_DatarefEditor_Published = 1; } } /* Return 1.0 to indicate that we want to be called again in 1 second. */ return -1.0;} int fn_Mydataref_Status(void * inRefcon){ return Mydataref;}void fn_Mydataref_Write(void * inRefcon, int InValue){ Mydataref = InValue;}
init.luadofile("main.lua")main.luadofile("draw.lua")dofile("manipulation.lua")dofile("dataref.lua")function main()OnDraw_Windows()takeoff_stuff()endmanipulation.luafunction takeoff_stuff() --1 On, 0 Offxp.setInt(dref_nav_lights,1) --Luces de Navegacion xp.setInt(dref_land_lights,1) --Luces de Aterrizajexp.setInt(dref_taxi_lights,1) --Luces de Taxixp.setInt(dref_strobe_lights,1) --Luces de Strobexp.setInt(dref_smoking,1) --Luces de No fumarxp.setInt(dref_TransP,2) --Luces de Transponder Modo Stand Byxp.setInt(dref_belts,1) --Cinturon de seguridadxp.setInt(dref_beacon_lights,1) --Luces de Faros enddataref.luaVSI = xp.getDataref("sim/cockpit2/gauges/indicators/vvi_fpm_pilot") --displayed, not actual !!!IAS = xp.getDataref("sim/cockpit2/gauges/indicators/airspeed_kts_pilot") --displayed, not actual !!!ALT = xp.getDataref("sim/flightmodel/position/elevation") --actual meters, MSLALTG = xp.getDataref("sim/flightmodel/position/y_agl") --actual meters, AGLdref_nav_lights = xp.getDataref("sim/cockpit/electrical/nav_lights_on")dref_land_lights = xp.getDataref("sim/cockpit/electrical/landing_lights_on")dref_taxi_lights = xp.getDataref("sim/cockpit/electrical/taxi_light_on") dref_strobe_lights = xp.getDataref("sim/cockpit/electrical/strobe_lights_on") dref_beacon_lights = xp.getDataref("sim/cockpit/electrical/beacon_lights_on")dref_belts = xp.getDataref("sim/cockpit/switches/fasten_seat_belts") dref_smoking = xp.getDataref("sim/cockpit/switches/no_smoking") dref_APU = xp.getDataref("sim/cockpit2/electrical/APU_generator_on") dref_Pheat = xp.getDataref("sim/cockpit/switches/pitot_heat_on") dref_PAice = xp.getDataref("sim/cockpit/switches/anti_ice_on") dref_PWh = xp.getDataref("sim/cockpit/switches/anti_ice_window_heat") dref_PSh = xp.getDataref("sim/cockpit/switches/anti_ice_surf_heat") dref_PIh = xp.getDataref("sim/cockpit/switches/anti_ice_inlet_heat") dref_TransP = xp.getDataref("sim/cockpit/radios/transponder_mode") dref_Gear_up = xp.getDataref("sim/multiplayer/controls/gear_request") -- 0 UP, 1 Downdr_sim_flap_request = xp.getDataref("sim/flightmodel/controls/flaprqst")TEMP = xp.getDataref("sim/weather/temperature_ambient_c") get_TEMP = xp.getFloat(TEMP)SPEED = xp.getDataref("sim/cockpit/autopilot/airspeed") ALTITUDE = xp.getDataref(" sim/cockpit2/gauges/indicators/altitude_ft_pilot")draw.lua function OnDraw_Windows()ALTG= xp.getDataref("sim/flightmodel/position/y_agl") get_ALTG=xp.getFloat(ALTG) --actual meters, AGLget_ALTG_ft = get_ALTG*3.28 --I use the float value returned by xp.getFloat() to work onIAS = xp.getDataref("sim/cockpit2/gauges/indicators/airspeed_kts_pilot") --displayed, not actual !!!get_IAS=xp.getFloat(IAS)VSI = xp.getDataref("sim/cockpit2/gauges/indicators/vvi_fpm_pilot") --displayed, not actual !!!get_VSI=xp.getFloat(VSI)thro=xp.getDataref("sim/flightmodel/engine/ENGN_thro") get_thro=xp.getFloatV(thro,1,4)appr=xp.getDataref("sim/cockpit2/autopilot/approach_status")get_appr=xp.getInt(appr)dr_sim_total_weight = xp.getDataref("sim/flightmodel/weight/m_total")g_total_weight = xp.getFloat(dr_sim_total_weight) * 2.20462262width,height = gfx.getScreenSize()gfx.setColor(0,0,0,0)-- Condicional para que muestre en que fase del vuelo esta el avionif (PhaseOfFlight == 0) then Phase = "Park"elseif (PhaseOfFlight == 1) then Phase = "Take Off"elseif (PhaseOfFlight == 2) then Phase = "Fly"elseif (PhaseOfFlight == 3) then Phase = "Landing"end-- Fin del Condicional de Fase de Vuelo-- Condicional para ver si el avion captura el LOC y GSif (get_appr == 0 ) then apprn = "Off"elseif (get_appr == 1 ) then apprn = "Armed"elseif (get_appr == 2 ) then apprn = "Captured"end-- Hasta Aqui el condiconal del LOC y GS-- Aqui que escriba en la pantallagfx.drawString(string.format("Peso Total Lbs: %0.0f",g_total_weight),10, height-100 )gfx.drawString(string.format("IAS Knots: %0.0f",get_IAS),10, height-90 ) gfx.drawString(string.format("Acelerador: %0.2f",get_thro),10, height-80 )gfx.drawString(string.format("Altura Ft: %0.0f",get_ALTG_ft),10, height-70 ) gfx.drawString(string.format("Velocidad Vertical Ft/min: %0.0f",get_VSI),10, height-60 )gfx.drawString(string.format("Fase del Vuelo: "..Phase),10, height-50 )gfx.drawString(string.format("Approach: "..apprn),10, height-40 )end --end on OnDraw