float myFlightLoopCallback(float inElapsedSinceLastCall, float inElapsedTimeSinceLastFlightLoop, int inCounter, void * inRefcon) { if(gPluginEnabled && gnsOpened) { #if 0 //FIXME if(autopilotConnected) { XPLMSetDatai(g_override_autopilot_ref, 1); XPLMSetDatai(g_autopilot_state_ref, 512); //see doc (HNAV engaged) override_gps = 1;//;pIntf->override_gps; XPLMSetDatai(g_override_gps_ref, override_gps); gps_fromto = 1; XPLMSetDatai(g_gps_fromto_ref, gps_fromto); gps_course_degtm = pIntf->dtk; XPLMSetDataf(g_gps_course_degtm_ref, gps_course_degtm); hsi_obs_deg_mag_pilot = pIntf->dtk; XPLMSetDataf(g_hsi_obs_deg_mag_pilot_ref, hsi_obs_deg_mag_pilot); XPLMSetDataf(g_gps_hdef_dot_ref, pIntf->cdi_horizontal_offtrack); } else { XPLMSetDatai(g_override_autopilot_ref, 0); } #endif //Set the COM frequencies XPLMSetDatai(g_com1_active_ref, gGNSx30Proxy.getCOMActiveFrequency()/10); XPLMSetDatai(g_com1_standby_ref, gGNSx30Proxy.getCOMStandbyFrequency()/10); XPLMSetDatai(g_nav1_active_ref, gGNSx30Proxy.getNAVActiveFrequency()/10); XPLMSetDatai(g_nav1_standby_ref, gGNSx30Proxy.getNAVStandbyFrequency()/10); latitude = XPLMGetDatad(g_latitude_ref); longitude = XPLMGetDatad(g_longitude_ref); heading = XPLMGetDataf(g_heading_ref); groundspeed = XPLMGetDataf(g_groundspeed_ref); elevation = (float)XPLMGetDatad(g_elevation_ref); vert_speed = XPLMGetDataf(g_vert_speed_ref); if(heading > 180.0f) // from 0 t pi and from -pi to 0 heading = -360.0f + heading; gGNSx30Proxy.setGPSInfo(latitude * PI / 180.0f, // rad longitude * PI / 180.0f, // rad groundspeed, heading*PI/180.0f, vert_speed, elevation); } return gUpdateInterval; //update every 0.01 sec }
void XPlaneInterface::setSideStickPitchRatio(float ratio) { if (!isYokePitchOverriden) { XPLMSetDatai(findDataRefByCode(OVERRIDE_JOYSTICK_PITCH), true); isYokePitchOverriden = true; } XPLMSetDataf(findDataRefByCode(YOKE_PITCH_RATIO), ratio); }
void XPlaneInterface::setSideStickRollRatio(float ratio) { if (!isYokeRollOverriden) { XPLMSetDatai(findDataRefByCode(OVERRIDE_JOYSTICK_ROLL), true); isYokeRollOverriden = true; } XPLMSetDataf(findDataRefByCode(YOKE_ROLL_RATIO), ratio); }
void setTurbulence( void ) { /* the tailwind just rockets us op to 0.5 turbulence, not okay */ /* i think .01 is the min? */ /* TODO: make this configurable */ if( XPLMGetDataf( ref_wind_turb0 ) > 0.1 ) { XPLMSetDataf( ref_wind_turb0, 0.1 ); } }
void FloatDataRef::setValue(float newValue) { if(!isWritable()) { INFO << "Tried to write read-only dataref" << name(); return; } _value = newValue; XPLMSetDataf(ref(), _value); }
// ***************** HDG Button and light ******************* void process_hdg_button() { if (loaded737 == 1) { if (multires > 0) { if (testbit(multibuf, HDG_BUTTON)) { XPLMCommandOnce(x737mcp_hdg_toggle); lastappos = 1; } } // Always match x737 glareshield LED switch (XPLMGetDatai(x737mcp_hdg_led)) { case 1: btnleds |= (1<<1); break; case 0: btnleds &= ~(1<<1); break; } } else { if (multires > 0) { if(testbit(multibuf,HDG_BUTTON)) { if(xpanelsfnbutton == 1) { rhdgf = XPLMGetDataf(MHdg); XPLMSetDataf(ApHdg, rhdgf); } if(xpanelsfnbutton == 0) { XPLMCommandOnce(ApHdgBtn); lastappos = 1; } } } switch(XPLMGetDatai(ApHdgStat)){ case 2: btnleds |= (1<<1); // * set bit 1 in btnleds to 1 * break; case 1: if (flashon == 1) { btnleds |= (1<<1); // * set bit 1 in btnleds to 1 * }else{ btnleds &= ~(1<<1); // * clear bit 1 in btnleds to 0 * } break; case 0: btnleds &= ~(1<<1); // * clear bit 1 in btnleds to 0 * break; } if (XPLMGetDatai(ApMstrStat) == 0) { btnleds &= ~(1<<1); // * clear bit 1 in btnleds to 0 * } } }
void GyroModel::setEQOff(){ if(XPlaneData->equalizer()==1) { float nav1=XPLMGetDataf(XPLMFindDataRef("sim/cockpit2/radios/actuators/nav1_obs_deg_mag_pilot")); float nav2=XPLMGetDataf(XPLMFindDataRef("sim/cockpit2/radios/actuators/nav2_obs_deg_mag_pilot")); if(nav2<nav1){ XPLMSetDataf(XPLMFindDataRef("sim/cockpit2/radios/actuators/nav2_obs_deg_mag_pilot"),XPLMGetDataf(XPLMFindDataRef("sim/cockpit2/radios/actuators/nav2_obs_deg_mag_pilot"))+0.5); } else { XPLMSetDataf(XPLMFindDataRef("sim/cockpit2/radios/actuators/nav2_obs_deg_mag_pilot"),XPLMGetDataf(XPLMFindDataRef("sim/cockpit2/radios/actuators/nav2_obs_deg_mag_pilot"))-0.5); } if(round(nav2)==round(nav1)) { XPlaneData->setEqualizerOff(); } } }
void setCloudBase( float alt_agl, float alt_msl ) { float cloud_base_msl = XPLMGetDataf( ref_cloud_base0 ); float ground_level = alt_msl - alt_agl; float cloud_base_agl = cloud_base_msl - ground_level; float cloud_tops_msl = XPLMGetDataf( ref_cloud_tops0 ); /* find the difference betwee the lowest cloud layer and what we want, * then apply that difference to all cloud layers */ float delta = config_min_cloud_base - cloud_base_agl; sprintf( debug_string, "min: %f, base %f, detla %f", config_min_cloud_base, cloud_base_agl, delta ); /* only set clouds if they're above the plane */ if( cloud_tops_msl > alt_msl && ( delta > 0 ) ) { XPLMSetDataf( ref_cloud_base0, cloud_base_msl + delta ); XPLMSetDataf( ref_cloud_tops0, XPLMGetDataf( ref_cloud_tops0 ) + delta ); XPLMSetDataf( ref_cloud_base1, XPLMGetDataf( ref_cloud_base1 ) + delta ); XPLMSetDataf( ref_cloud_tops1, XPLMGetDataf( ref_cloud_tops1 ) + delta ); XPLMSetDataf( ref_cloud_base2, XPLMGetDataf( ref_cloud_base2 ) + delta ); XPLMSetDataf( ref_cloud_tops2, XPLMGetDataf( ref_cloud_tops2 ) + delta ); } }
float weather_callback ( float inElapsedSinceLastCall, float inElapsedTimeSinceLastFlightLoop, int inCounter, void * inRefcon) { XPLMDataRef visible_range; visible_range = XPLMFindDataRef("sim/weather/visibility_reported_m"); XPLMSetDataf(visible_range, plugin_weather_visibility); return 1.0; }
void forceWind( float speed, float dir ) { XPLMSetDataf( ref_wind_speed0, speed ); XPLMSetDataf( ref_wind_direction0, dir ); XPLMSetDataf( ref_wind_speed1, speed ); XPLMSetDataf( ref_wind_direction1, dir ); XPLMSetDataf( ref_wind_speed2, speed ); XPLMSetDataf( ref_wind_direction2, dir ); }
// Step through list of controls reading the servo channel, calculating new position // and setting either a surface or engine(s) to the value void ServosToControls(void) { int iIndex = 0; int iSize = ControlSurfaces.size(); int iServoChannel; intbb ServoValue; float ControlSetting; ChannelSetup* pScanSetup; for (iIndex = 0; iIndex < iSize; iIndex++) { pScanSetup = &ControlSurfaces[iIndex]; iServoChannel = pScanSetup->mServoChannel; ServoValue._.B1 = SERVO_IN[2*iServoChannel]; ServoValue._.B0 = SERVO_IN[(2*iServoChannel)+1]; ControlSetting = pScanSetup->GetControlDeflection(ServoValue.BB); if (pScanSetup->mControlType == CONTROL_TYPE_SURFACE) { XPLMSetDataf(pScanSetup->mControlSurfaceRef, ControlSetting); } else if (pScanSetup->mControlType == CONTROL_TYPE_ENGINE) { unsigned int Mask = pScanSetup->mEngineMask; for (int Engine = 0; Engine < 8; Engine++) { if ((Mask & 0x01) != 0) { ThrottleSettings[Engine] = ControlSetting; } Mask >>= 1; } if (ControlSetting > PARKBRAKE_THROTTLE_THRESHOLD) // if engine is throttled-up above threshold.. { BrakeSetting = PARKBRAKE_OFF; // remove parkbrake } else { BrakeSetting = PARKBRAKE_ON; // apply parkbrake } } }
// Step through list of controls reading the servo channel, calculating new position // and setting either a surface or engine(s) to the value void ServosToControls() { int iIndex = 0; int iSize = ControlSurfaces.size(); int iServoChannel; intbb ServoValue; int Value; float ControlSetting; ChannelSetup* pScanSetup; for(iIndex = 0; iIndex < iSize; iIndex++) { pScanSetup = &ControlSurfaces[iIndex]; iServoChannel = pScanSetup->mServoChannel; ServoValue._.B1 = SERVO_IN[2*iServoChannel]; ServoValue._.B0 = SERVO_IN[(2*iServoChannel)+1]; ControlSetting = pScanSetup->GetControlDeflection(ServoValue.BB); if(pScanSetup->mControlType == CONTROL_TYPE_SURFACE) { XPLMSetDataf(pScanSetup->mControlSurfaceRef, ControlSetting); } else if(pScanSetup->mControlType == CONTROL_TYPE_ENGINE) { unsigned int Mask = pScanSetup->mEngineMask; for (int Engine = 0; Engine < 8; Engine++) { if( (Mask & 0x01) != 0 ) { ThrottleSettings[Engine] = ControlSetting; } Mask >>= 1; } } }
float MyFlightLoopCallback( float inElapsedSinceLastCall, float inElapsedTimeSinceLastFlightLoop, int inCounter, void * inRefcon) { /* The actual callback. First we read the sim's time and the data. */ float elapsed = XPLMGetElapsedTime(); float lat = XPLMGetDataf(gPlaneLat); float lon = XPLMGetDataf(gPlaneLon); float el = XPLMGetDataf(gPlaneEl); float vis = XPLMGetDataf(gPlaneVis); /* Write the data to a file. */ fprintf(gOutputFile, "Vis=%f,Time=%f,lat=%f,lon=%f,el=%f.\n",vis,elapsed, lat, lon, el); XPLMSetDataf(gPlaneVis, vis_amount); /* Return 1.0 to indicate that we want to be called again in 1 second. */ return 1.0; }
void resetTime() { float local_time_seconds, new_zulu_seconds; /* in order for the clock to be set right, we need to make sure we're using * system time initially to get local time, then turn off use system time before * changing the time -- using system time is set in the message handler */ local_time_seconds = XPLMGetDataf( ref_local_time ); new_zulu_seconds = XPLMGetDataf( ref_zulu_time ); if( local_time_seconds > config_late_time_seconds ) { new_zulu_seconds -= config_time_rollback_seconds; } else if( local_time_seconds < config_early_time_seconds ) { new_zulu_seconds += config_time_push_forward_seconds; } /* always turn off system time and always change it to make sure the clock gets set correctly */ XPLMSetDatai( ref_use_sys_time, 0 ); XPLMSetDataf( ref_zulu_time, new_zulu_seconds ); reset_time = false; }
// ***************** VS Switch Position ******************* void process_vs_switch() { if(testbit(multibuf,VS_SWITCH)) { multiseldis = 1; upapvsf = XPLMGetDataf(ApVs); upapvs = (int)(upapvsf); if(testbit(multibuf,ADJUSTMENT_UP)) { vsdbncinc++; if (vsdbncinc > multispeed) { n = multimul; if (xpanelsfnbutton == 1) { if (loaded737 == 1) { XPLMCommandOnce(x737mcp_vvi_up_fast); } else { while (n>0) { //XPLMCommandOnce(ApVsUp); upapvs = upapvs + 100; --n; } } vsdbncinc = 0; } if (xpanelsfnbutton == 0) { if (loaded737 == 1) { XPLMCommandOnce(x737mcp_vvi_up); } else if (apvsupremap == 1) { XPLMCommandOnce(ApVsUpRemapableCmd); } else { //XPLMCommandOnce(ApVsUp); upapvs = upapvs + 100; } vsdbncinc = 0; } } } if(testbit(multibuf,ADJUSTMENT_DN)) { vsdbncdec++; if (vsdbncdec > multispeed) { n = multimul; if(xpanelsfnbutton == 1) { if (loaded737 == 1) { XPLMCommandOnce(x737mcp_vvi_down_fast); } else { while (n>0) { //XPLMCommandOnce(ApVsUp); upapvs = upapvs - 100; --n; } } } vsdbncdec = 0; if(xpanelsfnbutton == 0) { if (loaded737 == 1){ XPLMCommandOnce(x737mcp_vvi_down); } else if (apvsdnremap == 1) { XPLMCommandOnce(ApVsDnRemapableCmd); } else { //XPLMCommandOnce(ApVsUp); upapvs = upapvs - 100; } vsdbncdec = 0; } } } upapvsf = upapvs; XPLMSetDataf(ApVs, upapvsf); upapaltf = XPLMGetDataf(ApAlt); upapvsf = XPLMGetDataf(ApVs); upapalt = (int)(upapaltf); upapvs = (int)(upapvsf); if (upapvs < 0){ upapvs = (upapvs * -1); neg = 1; } else { neg = 0; } } }
float GetBodyRates(float elapsedMe, float elapsedSim, int counter, void* refcon) { (void)elapsedSim; (void)counter; (void)refcon; pendingElapsedTime += elapsedMe; ReceiveFromComPort(); if (pendingElapsedTime < 0.025) // Don't run faster than 40Hz { return -1; } union intbb Temp2; float phi, theta, psi; float alpha, beta; float P_flight, Q_flight, R_flight; float ax, ay, az; float gravity_acceleration_x, gravity_acceleration_y, gravity_acceleration_z; // Angular rates in X-Plane are specified relative to the flight path, not to the aircraft, // for reasons unknown. So that means we need to rotate by alpha and beta to get angular rates // in the aircraft body frame, which is what the UDB measures. // Retrieve rates and slip angles, and convert to radians P_flight = XPLMGetDataf(drP) / 180 * PI; Q_flight = XPLMGetDataf(drQ) / 180 * PI; R_flight = XPLMGetDataf(drR) / 180 * PI; alpha = XPLMGetDataf(drAlpha) / 180 * PI; beta = XPLMGetDataf(drBeta) / 180 * PI; // On 25th Jan 2015, Bill Premerlani confirmed with Austin Meyer, author of X-Plane // that P, Q and R are rotations in the body frame. So they do not need to be rotated into // any other frame of reference, other than a small sign correction for the UDB frame conventions. // Austin Meyer said: "now, i CAN say that P is roll, Q is pitch, and R is yaw, all in degrees per second //about the aircraft axis,..... (i just looked at the code to confirm this)" P_plane = P_flight; Q_plane = -Q_flight; // convert from NED to UDB R_plane = R_flight; // Angular rate // multiply by 5632 (constant from UDB code) // Divide by SCALEGYRO(3.0 for red board) // 1 * 5632 / 3.0 = 1877.33 Temp2.BB = (int)(P_plane * 1877.33); Store2LE(&NAV_BODYRATES[6], Temp2); Temp2.BB = (int)(Q_plane * 1877.33); Store2LE(&NAV_BODYRATES[8], Temp2); Temp2.BB = (int)(R_plane * 1877.33); Store2LE(&NAV_BODYRATES[10], Temp2); // Our euler angles: // X-Plane angles are in degrees. // Phi is roll, roll to right is positive // Theta is pitch, pitch up is positive // Psi is yaw, relative to north. North is 0/360. // Convert these angles to radians first. phi = (float)((XPLMGetDataf(drPhi) / 180) * PI); theta = (float)((XPLMGetDataf(drTheta) / 180) * PI); psi = (float)((XPLMGetDataf(drPsi) / 180) * PI); // set up a vertical reference for the plotting computations // vertical in earth frame: ax = 0; ay = -(float)9.8; az = 0; // get the acceleration loading (gravity-acceleration) in the body frame in "g"s, // and convert to meter/sec/sec // x, y, and z are "UDB" coordinates, x is left wing, y is forward, and z is down. gravity_acceleration_x = (float)((XPLMGetDataf(drg_side)) * 9.8); gravity_acceleration_y = (float)((XPLMGetDataf(drg_axil)) * 9.8); gravity_acceleration_z = (float)((XPLMGetDataf(drg_nrml)) * 9.8); // Convert from OGL frame to Aircraft body fixed frame // This produces a vertical reference in body frame OGLtoBCBF(ax, ay, az, phi, theta, psi); ax_plane = ax; ay_plane = -ay; // convert from NED to UDB az_plane = az; // Lastly we need to convert from X-Plane units (m/s^2) to the arbitrary units used by the UDB // Accelerations are in m/s^2 // Divide by 9.8 to get g's // Multiply by 5280 (constant from UDB code) // Divide by SCALEACCEL (2.64 for red board) // 1 / 9.8 * 5280 / 2.64 = 204.8 Temp2.BB = (int)(gravity_acceleration_x * 204.8); Store2LE(&NAV_BODYRATES[12], Temp2); Temp2.BB = (int)(gravity_acceleration_y * 204.8); Store2LE(&NAV_BODYRATES[14], Temp2); Temp2.BB = (int)(gravity_acceleration_z * 204.8); Store2LE(&NAV_BODYRATES[16], Temp2); CalculateChecksum(NAV_BODYRATES); SendToComPort(sizeof(NAV_BODYRATES), NAV_BODYRATES); while (pendingElapsedTime >= 0.025) // Don't run slower than 40Hz { GPSCount++; if (!IsConnected()) { ConnectionCount++; if (ConnectionCount % 160 == 0) // attempt reconnection every 4 seconds when disconnected { AttemptConnection(); ConnectionCount = 0; } } if (GPSCount % 10 == 0) { GetGPSData(); GPSCount = 0; } pendingElapsedTime -= (float)0.025; } ServosToControls(); // float ThrottleSetting = 0; //SurfaceDeflections[CHANNEL_THROTTLE]; // float throttle[8] = {ThrottleSetting, ThrottleSetting, ThrottleSetting, ThrottleSetting, // ThrottleSetting, ThrottleSetting, ThrottleSetting, ThrottleSetting}; XPLMSetDatavf(drThro, ThrottleSettings, 0, 8); static float prevBrakeSetting = PARKBRAKE_ON; if (BrakeSetting != prevBrakeSetting) { prevBrakeSetting = BrakeSetting; XPLMSetDataf(drBrake, BrakeSetting); // LoggingFile.mLogFile << "Set parkbrake to " << BrakeSetting << endl; } return -1; // get called back on every frame }
void GyroModel::addYawDeviation() { cageGyro.yaw = cageGyro.yaw+0.000111111; // 15p alatt 3 fok XPLMSetDataf(XPLMFindDataRef("sim/cockpit2/radios/actuators/nav2_obs_deg_mag_pilot"),XPLMGetDataf(XPLMFindDataRef("sim/cockpit2/radios/actuators/nav2_obs_deg_mag_pilot"))+0.000055555); // 30p alatt 3 fok }
void setWind( float alt_agl, float alt_msl ) { float target_speed; static int transition_steps = 0; static float direction_interval, speed_interval, origin_direction, target_direction, origin_speed; float heading = XPLMGetDataf( ref_heading ), tmp_direction; /* wind alt should always be the plane's alt */ XPLMSetDataf( ref_wind_altitude, alt_msl ); switch( wind_state ) { case WIND_STATE_INITIAL: /* don't change the weather, just check to see if we're reading for a state change */ if( alt_agl > config_wind_transition_altitude ) { TRANSITION_TO_AT } break; case WIND_STATE_AT: /* in the transition state, we want to move direction to 180 degrees from heading, * and move the speed to 20kts */ transition_steps++; target_speed = config_tailwind_speed > origin_speed ? origin_speed + ( speed_interval * transition_steps ) : origin_speed - ( speed_interval * transition_steps ); /* set all three layers so the speed is predictable as you climb */ forceWind( target_speed, origin_direction > target_direction ? origin_direction - ( direction_interval * transition_steps ) : origin_direction + ( direction_interval * transition_steps ) ); if( transition_steps >= WIND_TRANSITION_STEPS ) { wind_state = WIND_STATE_AP; } else if( alt_agl < config_wind_transition_altitude ) { TRANSITION_TO_BT } break; case WIND_STATE_AP: /* persistant state - preserve tailwind */ tmp_direction = floor( OPP_HEADING ); /* transition direction if not within tolerance */ CHECK_DIRECTION forceWind( config_tailwind_speed, target_direction ); if( alt_agl < config_wind_transition_altitude ) { TRANSITION_TO_BT } break; case WIND_STATE_BT: transition_steps++; target_speed = origin_speed > config_headwind_speed ? origin_speed - ( speed_interval * transition_steps ) : origin_speed + ( speed_interval * transition_steps ); /* set all three layers so the speed is predictable as you climb */ forceWind( target_speed, origin_direction > target_direction ? origin_direction - ( direction_interval * transition_steps ) : origin_direction + ( direction_interval * transition_steps ) ); if( alt_agl < 1 ) { wind_state = WIND_STATE_INITIAL; } else if( transition_steps >= WIND_TRANSITION_STEPS ) { wind_state = WIND_STATE_BP; } else if( alt_agl > config_wind_transition_altitude ) { TRANSITION_TO_AT } break; case WIND_STATE_BP: /* persistant state - preserve tailwind */ tmp_direction = floor( heading ); /* transition direction if not within tolerance */ CHECK_DIRECTION forceWind( config_headwind_speed, target_direction ); if( alt_agl < 1 ) { wind_state = WIND_STATE_INITIAL; } else if( alt_agl > config_wind_transition_altitude ) { TRANSITION_TO_AT } break; } }
void setVisibility() { XPLMSetDataf( ref_visibility, config_visibility_setting ); }
// ***************** APR Button and light ******************* void process_apr_button() { if (loaded737 == 1) { if (multires > 0) { if (testbit(multibuf, APR_BUTTON)) { XPLMCommandOnce(x737mcp_app_toggle); lastappos = 1; } } // Always match x737 glareshield LED switch (XPLMGetDatai(x737mcp_app_led)) { case 1: btnleds |= (1<<6); break; case 0: btnleds &= ~(1<<6); break; } } else if (aprbuttonremap == 1){ if (multires > 0) { if(testbit(multibuf,APR_BUTTON)) { XPLMCommandOnce(AprButtonRemapableCmd); lastappos = 1; } } switch(XPLMGetDatai(ApAprStat)){ case 2: btnleds |= (1<<6); // * set bit 6 in btnleds to 1 * break; case 1: if (flashon == 1) { btnleds |= (1<<6); // * set bit 6 in btnleds to 1 * }else{ btnleds &= ~(1<<6); // * clear bit 6 in btnleds to 0 * } break; case 0: btnleds &= ~(1<<6); // * clear bit 6 in btnleds to 0 * break; } } else { if (multires > 0) { if(testbit(multibuf,APR_BUTTON)) { if(xpanelsfnbutton == 1) { rhdgf = XPLMGetDataf(MHdg); XPLMSetDataf(ApCrs, rhdgf); } if(xpanelsfnbutton == 0) { XPLMCommandOnce(ApAprBtn); lastappos = 1; } } } switch(XPLMGetDatai(ApAprStat)){ case 2: btnleds |= (1<<6); // * set bit 6 in btnleds to 1 * break; case 1: if (flashon == 1) { btnleds |= (1<<6); // * set bit 6 in btnleds to 1 * }else{ btnleds &= ~(1<<6); // * clear bit 6 in btnleds to 0 * } break; case 0: btnleds &= ~(1<<6); // * clear bit 6 in btnleds to 0 * break; } } }
// ***************** ALT Switch Position ******************* void process_alt_switch() { if(testbit(multibuf,ALT_SWITCH)) { multiseldis = 1; upapaltf = XPLMGetDataf(ApAlt); upapalt = (int)(upapaltf); if(testbit(multibuf,ADJUSTMENT_UP)) { altdbncinc++; if (altdbncinc > multispeed) { if(xpanelsfnbutton == 1) { upapalt = upapalt + 1000; upapalt = (upapalt / 1000); upapalt = (upapalt * 1000); altdbncinc = 0; } if (xpanelsfnbutton == 0) { upapalt = upapalt + 100; upapalt = (upapalt / 100); upapalt = (upapalt * 100); altdbncinc = 0; } } } if(testbit(multibuf,ADJUSTMENT_DN)) { altdbncdec++; if (altdbncdec > multispeed) { if(xpanelsfnbutton == 1) { if (upapalt >= 1000){ upapalt = upapalt - 1000; } if(upapalt > 100){ upapalt = (upapalt / 100); upapalt = (upapalt * 100); } altdbncdec = 0; } if (xpanelsfnbutton == 0) { if (upapalt >= 100){ upapalt = upapalt - 100; } if(upapalt > 100){ upapalt = (upapalt / 100); upapalt = (upapalt * 100); } altdbncdec = 0; } } } upapaltf = upapalt; if (loaded737 == 1) { XPLMSetDataf(x737mcp_alt, upapaltf); } else { XPLMSetDataf(ApAlt, upapaltf); } upapvsf = XPLMGetDataf(ApVs); upapvs = (int)(upapvsf); if (upapvs < 0){ upapvs = (upapvs * -1); neg = 1; } else { neg = 0; } } }
// ***************** CRS Switch Position ******************* void process_crs_switch() { float cur_apcrsf = 0; int cur_apcrs = 0; // if the toggle is selected, use nav2, otherwise, nav1 XPLMDataRef crs_dataref = !xpanelscrstoggle ? ApCrs : ApCrs2; if(testbit(multibuf,CRS_SWITCH)) { multiseldis = 4; upapcrsf = XPLMGetDataf(ApCrs); upapcrs = (int)(upapcrsf); // get the appropriate course setting depending on if the toggle is down cur_apcrsf = XPLMGetDataf(crs_dataref); cur_apcrs = (int)(cur_apcrsf); if(testbit(multibuf,ADJUSTMENT_UP)) { crsdbncinc++; if (crsdbncinc > multispeed) { if (xpanelsfnbutton == 1) { cur_apcrs = cur_apcrs + multimul; } if(xpanelsfnbutton == 0) { cur_apcrs = cur_apcrs + 1; } crsdbncinc = 0; } } if(testbit(multibuf,ADJUSTMENT_DN)) { crsdbncdec++; if (crsdbncdec > multispeed) { if (xpanelsfnbutton == 1) { cur_apcrs = cur_apcrs - multimul; } if(xpanelsfnbutton == 0) { cur_apcrs = cur_apcrs - 1; } crsdbncdec = 0; } } if(cur_apcrs > 360){ cur_apcrs = 1; } if(cur_apcrs < 0){ cur_apcrs = 359; } cur_apcrsf = cur_apcrs; XPLMSetDataf(crs_dataref, cur_apcrsf); // set the appropriate global based on whether the crs toggle is on if( !xpanelscrstoggle ) { // toggle off - nav1 upapcrsf = cur_apcrsf; upapcrs = cur_apcrs; } else { // toggle on - nav2 upapcrsf2 = cur_apcrsf; upapcrs2 = cur_apcrs; upapcrs = cur_apcrs; } } }
// ***************** HDG Switch Position ******************* void process_hdg_switch() { if(testbit(multibuf,HDG_SWITCH)) { multiseldis = 3; upaphdgf = XPLMGetDataf(ApHdg); upaphdg = (int)(upaphdgf); if(testbit(multibuf,ADJUSTMENT_UP)) { hdgdbncinc++; if (hdgdbncinc > multispeed) { if(xpanelsfnbutton == 1) { if (loaded737 == 1) { XPLMCommandOnce(x737mcp_hdg_up_fast); } else { upaphdg = upaphdg + multimul; } hdgdbncinc = 0; } if(xpanelsfnbutton == 0) { if (loaded737 == 1) { XPLMCommandOnce(x737mcp_hdg_up); } else { upaphdg = upaphdg + 1; } hdgdbncinc = 0; } } } if(testbit(multibuf,ADJUSTMENT_DN)) { hdgdbncdec++; if (hdgdbncdec > multispeed) { if(xpanelsfnbutton == 1) { if (loaded737 == 1) { XPLMCommandOnce(x737mcp_hdg_down_fast); } else { upaphdg = upaphdg - multimul; } hdgdbncdec = 0; } if(xpanelsfnbutton == 0) { if (loaded737 == 1) { XPLMCommandOnce(x737mcp_hdg_down); } else { upaphdg = upaphdg - 1; } hdgdbncdec = 0; } } } if (loaded737 != 1) { if(upaphdg > 360){ upaphdg = 1; } if(upaphdg < 0){ upaphdg = 359; } upaphdgf = upaphdg; XPLMSetDataf(ApHdg, upaphdgf); } } }
int htmlUniSet( char *header, char *html ){ header200OK_HTM( header ); char drefName[1024]; char drefType[4]; char drefValueFormatString[64]; parseQuerystringForString( "dref", drefName, 1024 ); parseQuerystringForString( "type", drefType, 4 ); XPLMDataRef tmpDr = XPLMFindDataRef( drefName ); switch( drefType[0] ){ case 'i': { int tmp = parseQuerystringForInt("val"); XPLMSetDatai( tmpDr, tmp ); sprintf( drefValueFormatString, "Int Value: (%i)<br/>\n", tmp ); } break; case 'f': { float tmp = parseQuerystringForFloat("val"); XPLMSetDataf( tmpDr, tmp ); sprintf( drefValueFormatString, "Float Value: (%f)<br/>\n", tmp ); } break; case 'c': { sprintf( drefValueFormatString, "String Value: (%s)<br/>\n", "foo" ); } break; } sprintf( html, //"Uni Set<br/>\n" "Dataref: (%s)<br/>\n" "Type: (%s)<br/>\n" "%s<br/>" //"<hr/>" //"<form action='/set' method='GET'>" // "dref: <input type='text' name='dref' value='%s'/><br/>" // "type: <input type='text' name='type' value='%s'/><br/>" // "val: <input type='text' name='val'/></br>" // "<input type='submit'/><br/>" //"</form>" , drefName, drefType, drefValueFormatString//, //drefName, //form field 1 //drefType //form field 2 ); return strlen( html ); }
// ***************** IAS Switch Position ******************* void process_ias_switch() { if (testbit(multibuf,IAS_SWITCH)) { multiseldis = 2; upapasf = XPLMGetDataf(ApAs); upapas = (int)(upapasf); if (testbit(multibuf,ADJUSTMENT_UP)) { iasdbncinc++; if (iasdbncinc > multispeed) { n = multimul; if (xpanelsfnbutton == 1) { if (loaded737 == 1) { XPLMCommandOnce(x737mcp_spd_up_fast); } else { while (n>0) { if (XPLMGetDatai(AirspeedIsMach) == 1) { XPLMSetDataf(Airspeed, XPLMGetDataf(Airspeed) + 0.01); } else { //XPLMCommandOnce(ApAsUp); upapas = upapas + 1; } --n; } } iasdbncinc = 0; } if (xpanelsfnbutton == 0) { if (loaded737 == 1) { XPLMCommandOnce(x737mcp_spd_up); } else { if (XPLMGetDatai(AirspeedIsMach) == 1) { XPLMSetDataf(Airspeed, XPLMGetDataf(Airspeed) + 0.01); } else { //XPLMCommandOnce(ApAsUp); upapas = upapas + 1; } } iasdbncinc = 0; } } } if (testbit(multibuf,ADJUSTMENT_DN)) { iasdbncdec++; if (iasdbncdec > multispeed) { n = multimul; if (xpanelsfnbutton == 1) { if (loaded737 == 1) { XPLMCommandOnce(x737mcp_spd_down_fast); } else { while (n>0) { if (XPLMGetDatai(AirspeedIsMach) == 1) { XPLMSetDataf(Airspeed, XPLMGetDataf(Airspeed) - 0.01); } else { //XPLMCommandOnce(ApAsDn); upapas = upapas - 1; } --n; } } iasdbncdec = 0; } if (xpanelsfnbutton == 0) { if (loaded737 == 1) { XPLMCommandOnce(x737mcp_spd_down); } else { if (XPLMGetDatai(AirspeedIsMach) == 1) { XPLMSetDataf(Airspeed, XPLMGetDataf(Airspeed) - 0.01); } else { //XPLMCommandOnce(ApAsDn); upapas = upapas - 1; } } iasdbncdec = 0; } } } upapasf = upapas; XPLMSetDataf(ApAs, upapasf); upapasf = XPLMGetDataf(ApAs); if (XPLMGetDatai(AirspeedIsMach) == 1) { upapasf = (upapasf * 100); } upapas = (int)(upapasf); } }
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; }