Challenger 300 Unofficial Patch by JackZero

Very important note: This is an unofficial patch for Ddenn's Challenger 300 by JackZero. This patch is for the CL300 version 10.36 only and requires at least X-Plane 10.36! To see if you have the correct version, check if there's a file "10_36_changes.txt" in the aircraft folder. If yes, you should be good.

If you encounter any problems with the plane while the patch is applied, please try to reproduce the issue with the official version before filing a bug report. If the problem only exists with the patched version, please don't contact Ddenn for support but instead send a PM to me! 

Also, don't apply any further patches from Ddenn on top of this patch because it is likely that something will break. If Ddenn has released a new patch that I missed, just send me a PM and I'll build a patch for the new version if it should still be necessary. 

In case that the file link in this post is broken, all releases of the patch can be found here:
https://www.dropbox.com/sh/t7og8c0pomitykb/AABT-HiBBXi9adh-BcJLA8l1a?dl=0
Note that you'll only need the latest version of the patch. The old versions are only there as reference or in case you encounter a bug that renders the lastest version unusable.

==[ INSTALLATION INSTRUCTIONS ]=============================
Unzip or copy the official release 10.36 in a new aircraft directory. Unzip the latest patch into that directory. That's all.

==[ TROUBLESHOOTING ]=============================
The most common sign of trouble is that no switch in the 3D cockpit works and the popup menu is gone. In this case something has gone terribly wrong and caused SASL (the plugin that runs all the custom logic) to crash. In that case, just send me the Log.txt from your X-Plane directory as PM and I’ll look into the issue.

==[ ALTERNATE ACF FILES ]=============================
This patch contains two ZIP files with optional ACF file from Ddenn for X-Plane 10.42 (Ddenn_ACF_10_42_FDM_201215.zip and Ddenn_ADF_10_42_FDM_020116.zip) that contain changes to the flight model that might solve the crosswind landing issues posted at here:
 http://forums.x-plane.org/index.php?showtopic=53029&page=37#entry977571
The files each contain in two versions of the ACF file, Bombardier_Cl_300.acf contains my patches while Bombardier_Cl_300.acf_bak is the original file released by Ddenn). Note that these require at least X-Plane version 10.42.
Note that these flight models are a development state from Ddenn and might contain several bugs and issues. They are not intended for regular use. I’ve only included them because due to the changes in the hydraulic logic the original development files from Ddenn will not work well with my current patch so in case you want to try these patches you can use the versions contained in this patch that include the changes in the hydraulic logic and will therefor work with my patch.

==[ VERSION 10.36 JZ 1.13 – CHANGE LOG ]=============================

MCP:
•	Fixed a bug introduced by the patch that NAV SRC would cycle through the values 1 to 3 instead of 0 to 2.

==[ VERSION 10.36 JZ 1.12 – CHANGE LOG ]=============================

RADIOS:
•	Deactivation of the 8.33 kHz COM spacing via the REFS menu now works correctly.
•	Fixed a bug in the REFS menu that when selecting M/ALT (3rd row) on the fourth page the box would instead highlight 8 KHZ (2nd row).

==[ VERSION 10.36 JZ 1.11 – CHANGE LOG ]=============================

RADIOS:
•	Fixed a bug introduced by version 1.9 that the BRG SRC menu would blink instead of disappearing when the cursor was left at OBS2.

==[ VERSION 10.36 JZ 1.10 – CHANGE LOG ]=============================

RADIOS:
•	The support for 8.33 kHz channel spacing for the COMs can now be enabled and disabled via the REFS menu.

CLOCK:
•	There was a bug in the fix in version 1.9 so FLT would only reset the flight time when on ground. Now FLT will also reset the time when airborne.

SETTINGS:
•	The settings for 8.33 kHz radios, metric alt display, barometer mode (InHg/hPa), GPU mode (manual or automatic) as well as the map range, mode and declutter will now be automatically saved and restored independently of the more complex “position” saving setting.

==[ VERSION 10.36 JZ 1.9 – CHANGE LOG ]=============================

RADIOS:
•	Added support for 8.33 kHz channel spacing for the COMs.
•	NAVSRC will now “remember” the last position: Pressing NAVSRC once will show the current nav source and any subsequent presses will cycle through the options. Previously the first press of NAVSRC would always set FMS1.
•	BRGSRC will now “remember” the last position: Pressing BRGSRC once will now have the previously selected OBS selected again instead of always jumping to OBS1. In addition, any subsequent presses to BRGSRC will toggle the current OBS between VOR and ADF mode. Note that you’ll still be able to also toggle the mode via the DATA knob but for time critical situations you’ll now be able to quickly toggle the (preselected) OBS by pressing BRGSRC twice.
•	Added a command “cl300/DCP/brgsrc_toggle” for the extended functionality of the BRGSRC button.

PFD/MFD:
•	Changed order in which the NAV info above the map on the MFD is displayed. Previously the order was always FMS, NAV1, NAV2. Now this is only the case if the active NAV SRC is FMS. If the NAV SRC is NAV1, the order is NAV1, NAV2, FMS and if it’s NAV2 the order is NAV2, NAV1, FMS. The order was changed because the leftmost item will also be displayed on the MAP on the PFD, so now the active NAV SRC will be visible there.

FUEL:
•	Fixed a bug that could lead to the FUEL IMBALANCED message not extinguishing once the balance is restored.
•	Changed the logic for determining the FUEL USED again. The previous logic to determine fueling/defueling operations and resetting the fuel used counter tended to reset the counter when using the pause function in flight. Now the counter is reset every time the first engine is started while being on ground.

ECIAS:
•	Fixed a bug where the aural CONFIG WARNING would sound when the thrust reverser are deployed during landing.

CLOCK:
•	Fixed a bug that would lead to the FLT TIME being reset on touchdown if not all wheels stay on the ground. Now the FLT TIME will not be automatically reset on takeoff. Instead, the clock ticks while being in air, stops when on ground and restarts ticking when being airborne again. So if you do a multi leg flight, you’ll have to follow the correct procedure and manually reset the clock. In addition, the clock will automatically reset on a complete loss of power.
•	The FLT TIME RST button now works again.

MISC/XHSI:
•	The Dataref for the planes Vno will now be dynamically set to the correct values: 320 KIAS or 0.83 Mach (whichever is lower) above 8000 ft, 300 KIAS at or below 8000 ft, 250 KIAS with gear extended, 210/195 KIAS with flaps extended. While this has no influence on the flight model or native X-Plane displays, external displays like XHSI will now display the correct speed limits.

==[ VERSION 10.36 JZ 1.8 – CHANGE LOG ]=============================

SPOILERS:
•	Changed the implementation on when the ground spoilers are deployed: The technical documents state that they can deploy when two of the following three criteria are met: Radio altitude less than 7 feet, weight on wheels and/or wheel speed greater than 15 knots. The previous implementation required weight on all wheels for the second criteria to be met and only considered wheel speed of the nose wheel. Therefor the ground spoilers would only deploy once the nose wheel touched down and not as soon as the rear wheels touched down. Now the wheel speed as well as weight on wheels is considered for any wheel. So if (e.g. during a crosswind landing) only one of the rear wheels touches the ground the spoilers should deploy and therefore create downward pressure to get the other wheels on the ground as well. 

PFD:
•	Fixed a bug for the V-speeds limits introduced in V1.6, there was a mix up between Vref and Vga, Vref is now limited to 113-134 while Vga is limited to 119-141.

PREFLIGHT:
•	Added an option to use “2D cockpit with nothing” instead of the “3D cockpit with command view” for position 1 during the preflight check. In order to activate this, edit the file “preflight.lua” in the directory “Custom Avionics”, locate the line “USE_3D_COCKPIT = true” and replace the “true” with a “false”.

==[ VERSION 10.36 JZ 1.7 – CHANGE LOG ]=============================

SPOILERS:
•	Fixed a bug introduced by V1.4 that would automatically deploy the FLT SPOILERS if moving the throttle to IDLE.

MFD:
•	Added the commands “cl300/mfd_lr_toggle”, “cl300/mfd_lr_left” and “cl300/mfd_lr_right” to control the side selector switch of the MFD panel.

==[ VERSION 10.36 JZ 1.6 – CHANGE LOG ]=============================

AUTOPILOT:
•	Fixed a bug introduced by V 1.1 that half bank wasn’t working.

FUEL:
•	Fixed a bug introduced by V 1.2 where fuel used was always “0” if the engines where running with more than idle thrust. Reason for this bugs is that in X-Plane, the fuel consumption isn’t applied “per Frame” and therefore the threshold for a defueling operation (instead of engine use) was too low. For this, the threshold had to be increased from 2.77 lbs/s (10000 lbs/h) to 100 lbs/s.

PFD:
•	The V-speeds set via the REFS menu are now limited to valid values (taken from the POH): V1: 116-140, Vr: 116-140, V2: 126-141, Vt: 140-200, Vga: 113-134, Vref: 119-141.

==[ VERSION 10.36 JZ 1.5 – CHANGE LOG ]=============================

PFD:
•	Added an optional display of the metric altitude (both current and autopilot). This is controlled by the REFS menu.
•	The setting for the barometer (InHg/hPa) and metric alt is now also saved if position saving is enabled.

==[ VERSION 10.36 JZ 1.4 – CHANGE LOG ]=============================

SPOILERS:
•	If GROUND SPOILERS is set to AUTO, the spoilers will now also arm when airborne (radio alt > 200 ft). That way the spoilers will also deploy if you start a flight in air. Previously one had to manually arm the spoilers by setting the switch to ON when loading a flight in air.
•	Deploying the thrust reversers will not instantly stow the ground spoilers anymore.
•	NOTE: If you notice that the ground spoilers don’t fully deploy but instead permanently go up and down, this is due to the speedbrake axis of the joystick interfering with the ground spoiler logic. However, this only seems to happen sometimes and not always. While it is possible to completely solve the problem by changing the code to enable it to override joystick inputs this adds to incompatibilities with other plugins (e.g. TugMaster). Another (better) solution is not to assign the speedbrake axis directly but instead use a FlyWithLua script to read the joystick axis and write to the speedbrake dataref. If you need help or a code example, just send me a PM.

==[ VERSION 10.36 JZ 1.3 – CHANGE LOG ]=============================

THROTTLE:
•	Moving the right throttle will now also cancel MACH HOLD. (V 1.3)
•	Changed calculation for throttle movement during MACH HOLD. Previously the system tended to make too large changes of throttle in order to reach/maintain the target speed, resulting in N1 constantly jumping up and down! The change rate has been reduced to a more reasonable level.
•	N1 in CRZ is now limited to the CLB N1. Previously it was possible that (depending on temperature situations) the CRZ N1 could be higher than the CLB N1 (or even APR N1).

RADIOS:
•	Fixed a bug where quickly tuning the transponder code (triggering multiple tune up/down commands per frame) would reset the transponder code to 0000 or 7777.

==[ VERSION 10.36 JZ 1.2 – CHANGE LOG ]=============================

FUEL:
•	Changed the calculation logic for "fuel used". In reality the FADEC knows how much fuel the engines used so that the calculation is independent of any refueling operations. In X-Plane we can only calculate the used fuel by comparing how much fuel we have left to what we started with. Previously, the amount we started with would reset to the current fuel amount on takeoff (therefore loosing track of the fuel used while taxiing) and every time an engine starts or stops (which might happen in air!). The amount should only be reset if a fueling operation takes place. So now the counter will be reset if the amount of fuel increases or if it decreases at a rate larger than 10000 lbs/h.
•	The APU will no longer use fuel while the simulation is paused.

HYDRAULICS:
•	Changed the hydraulic pressure and system linkage in the ACF-File. Previously the electrical and engine pumps would only generate a maximum pressure of 2500 psi, with the engine pumps only supplying 1900 psi if the engines where on idle thrust. In addition, all pumps where linked to all systems, therefore as soon as one electrical or engine pump was running, both hydraulic systems had pressure. Now the left/right engine pump is linked to the left/right system while the elec pump (PlaneMaker supports only one elec pump) is linked to both systems.
•	Decreased the minimum hydraulic pressure on which the control surfaces operate normally from 2100 to 1600 psi. Since the CAS warning "LOW HYDR PRESSURE" shows up at 1800 psi there should be a little reserve on which the control surfaces should still work normal.
•	Fixed the logic for the electrical hydraulic pumps. Previously, the pumps turned on either if that sides engine is running and the pump is set to ON or it is set to AUTO and flaps are set or (if the engine is not running) if the pump is set to at least AUTO and the AUX pump is set to AUTO. However, the pumps state doesn't depend on the AUX pump but instead on the state of the engine driven pumps and electrical power. When set to ON, they turn on if the power demands (see below) are met. On AUTO they turn on if the power demands are met and the engine driven pump is turned off or flaps are set to non-zero. The left electrical pump is powered by the right electrical (main) bus while the right pump is powered by the left (essential) bus. So the left pump can only be powered if a generator is running (main bus) while the right pump can also be powered by the battery (essential bus) although only for a short time (due to the large power consumption and limited battery power). Therefore, when set to AUTO, the pumps will turn on while on battery power if flaps are set to non-zero (last phase of flight) and due to the engine pump not running. Also, if only one generator is online only one pump will be powered, with the right pump having priority, so if no (or just the left or both) engine pumps are running, the right pump will be powered and if only the right engine pump is running then the left pump will be powered.
•	Fixed the logic for the PTU. In AUTO it will turn on if there is right hydraulic pressure, the left engine pump is turned off, the aircraft is in the air and the gear is not in the commanded position.
•	Fixed the logic for the AUX pump. It requires power to work.
•	The different states (e.g. engine driven pump running) are now stored in datarefs instead of local variables.
•	Moved logic code from mfd.lua to aircraft_logic.lua.

ELECTRICAL:
•	The generator voltage isn't static anymore but drops with increasing load.

ECS:
•	Fixed a bug in the window heater logic, the heater would only heat the windows up to 1°C.

THROTTLE:
•	Changed how the reversers are stowed. Previously when stowing the reversers, the commanded throttle would stay at 55% until the reverser deploy ratio was less than 10% at which point the throttle would jump up to 75% to then slowly go down to 0%. In addition, as soon as you let go of the "toggle max reverse" button X-Plane would set the thrust direction to forward thrust even though the reversers are still partially deployed. This would result in a large amount of (unexpected) forward thrust bumping the plane ahead. I've changed the logic so that when stowing the reversers (reversers still deployed but prop mode is set to forward thrust) the trust direction is set to reverse thrust and the throttle is set to zero.
•	Detent throttle positions (APR, TO, CLB) are now separated for both levers. Previously the maximum selected detent would automatically be used for both throttles. Previously if you had (for example) both throttles in CLB and then moved one (joystick axis) back to idle, that throttle would still stay in CLB.
•	Changed a part of the FADEC/throttle logic that would previously only work if both throttles where in the same position (e.g. CLB).

CLOCK:
•	Flight time will not be reset to zero on touchdown. Instead, the flight time will still be displayed and only be reset at the next takeoff.

RADIOS:
•	Fixed a bug where tuning the ADFs below 190 would reset the ADF to 530 instead of keeping the value 190.
•	Setting "TUNE" to "CDU ONLY" will now not only prohibit the transponder from being tuned by the DCP tune knob but also the COMs, NAVs and ADFs.

MAP (XHSI):
•	Added extended support for XHSI. If the XHSI plugin is present (installed and not deactivated) then the following changes become active. Note that if you don't have the XHSI plugin installed, the MAP will operate as always.
  - You can use the REFS menu to switch MINS between RA and DA and set set DA. 
  - You can use the REFS menu to also toggle the POS & DATA map display.
  - The plane now optionally supports different maps inside XHSI for the PFD and MFD. The PFD will use the pilot map while the MFD will use the copilot map:
    • The FRMT button on the DCP panel controls the PFD/pilot map mode while the FMRT button on the MFD panel controls the MFD/copilot map mode.
    • Range and declutter for both maps are synced.
    • The PFD map is limited to the VOR mode and FRMT toggles between ARC and CTR mode.
    • The MFD map is limited to VOR, MAP, NAV and PLAN modes without the option to toggle between ARC and CTR.
    • You can enable the reduced map modes by changing the line
        local XHSI_MAP_MODE_LOCK = false
      in the file "Custom Avionics\mfd.lua" to
        local XHSI_MAP_MODE_LOCK = true
  - Added proxy-datarefs for XHSI 2.0 beta 7: With the 10.31 release of the CL300 all custom datarefs where renamed. But since the current XHSI beta is still looking for the old datarefs, the CL300 specific parts of XHSI (e.g. ref-speeds on the speed tape) aren't working. Therefore, proxy-datarefs using the old names where created which map the current values to the old names. These datarefs are only created if the XHSI plugin is found and enabled on the system. Note that XHSI 2.0 beta 8 will include the renamed datarefs so this is only a temporary workaround and will be removed in a later patch.

==[ VERSION 10.36 JZ 1.1 – CHANGE LOG ]=============================

AUTOPILOT:
•	Changed how the datarefs from the 'mode'-buttons trigger the x-plane autopilot commands in order to remove an incompatibility with SmartCopilot. Note that is an internal change only and doesn't have any noticeable effect if you don't use SmartCopilot.
•	Moved the 'half bank' logic from the pfd.lua to the aircraft_logic.lua and made it compatible with SmartCopilot.

ECIAS:
•	Added datarefs to access the text and color of the CAS messages and checklist entries.

RADIOS:
•	Increased maximum transponder mode from 2 (OFF, STBY, TA/RA) to 4 (OFF, STBY, ON, TA, TA/RA) for XHSI compatibility.
•	Added a dataref cl300/mfd_sel_column to access the selected column on the radio bar.

MFD:
•	Fixed a bug where the engine shut off valve was shown open if the PUMP was ON but ENGINE was set to OFF (e.g. during fuel transfer).
•	Fixed a bug where the APU shut off valve was shown closed if the APU switch was set to RUN but the APU wasn't started yet.

MAP:
•	Added commands to change the displayed flight plan waypoint on the map (plan-mode) and a dataref to access/sync it via SmartCopilot. Note that these are note accessible via the 3D cockpit since this is usually controlled via the FMS.

MISC:
•	Setting the landing alt source to FMS1 or FMS2 will now set the landing to the alt of the last airport found in the configured flight plan. This is confirmed to work with X-FMC but should also work with any FMS that saves the route in the default FMS flight plan.
•	Added a configuration file for SmartCopilot.
•	Added a modified configuration file for X-FMC (changed the V-speeds and thrust limits according to the POH).
•	Added proxy-datarefs to sync the X-FMC key input via SmartCopilot as well as commands for every key. That way you can link your hardware keyboard to X-FMC (e.g. CTRL+A = A, CTRL+F1 = LSK 1) and have it sync via SmartCopilot. Note that key input to X-FMC will not be synced if you use the native X-FMC popup.

==[ VERSION 10.36 JZ 1.0 – CHANGE LOG ]=============================

IGNITION:
•	The startup sequence would never deactivate the ignition again once activated (neither if the startup was aborted (e.g. when setting ENGINE L/R to OFF during startup) nor if it was successful).
•	IGNITION would only activate the continuous ignition for the left engine and when depressed would not deactivate the ignition again.

FUEL:
•	Fixed a bug that you could start an engine with the fuel pump turned off if you set ENGINE L/R to RUN before setting L/R PUMP to OFF.
•	Fixed several issues with the fuel transfer logic:
  - Pump driven fuel transfer (XFER) should also work if the delivering pump is set to AUTO and the pump is running. Note that in the usual situations where fuel transfer is necessary (engine failure) the pump would not be running when set to AUTO so usually you'll still need to set the pump to ON.
  - Pump driven fuel transfer (XFER) should not work if receiving sides electric pump is running. Previously this was possible if the pump was running while set to AUTO or if it was set to ON after XFER was set ON and the supplying sides pump had been turned on.
  - GRAVITY XFLOW didn't consider slip. However, slip should shift the fuel from the inner tank to the outer tank, which is why you should never taxi with the gravity xflow open. The fuel transfer logic is now:
    • XFER is set to ON and one of the electrical pumps (L/R PUMP) is running (set to ON or AUTO and active) while the other pump is not running (set to OFF or set to AUTO but inactive), in that case the active pumps side is the source and the passive sides pump is the target.
    • GRAVITY XFLOW is ON and the fuel is unbalanced (considering both fill level and slip). As an approximation of the effect that slip has on gravity xflow, the following logic is applied:
    We assume that every 15 deg (which is very extreme) will double the fuel weight on the 'inner' tank and half it on the 'outer' tank, therefore pushing more fuel to the outer tank and resulting in a distribution of 1:4 being balanced (80% fuel in the outer and 20% fuel in the inner tank). For 2000 lbs total fuel this would result in a balance state with the following distribution:
      45 deg slip (are you mad?) = 30 lbs : 1970 lbs
      15 deg slip (extreme) = 400 lbs : 1600 lbs
      5 deg slip (moderate) = 775 lbs : 1225 lbs
      1 deg slip (slight) = 950 lbs : 1050 lbs
      0 deg slip (none) = 1000 lbs : 1000 lbs
    In addition, we assume that at least 10 lbs of difference is needed for the gravity xflow to work.
    • If both XFER and GRAVITY XFLOW are ON and are directed into opposite direction (the pump trying to fill the tank already more full) then the fuel transfers will cancel each other out.
•	Moved the code for determining whether an electrical fuel pump is running while on AUTO from mfd.lua to aircraft_logic.lua to reduce redundant code.

ECIAS:
•	The code for the CAS messages has been completely reworked. This reduced the code from 14.600 lines to 300 lines, greatly improving maintainability and extendibility.
•	Fixed a bug in the previous release of this code, which caused configuration warnings to show up while in flight.
•	Added L/R ENG IGN FAULT messages.
•	The yellow "IGN" message below the ITT gauge should show up if the ignition is active, not on an ignition failure.
