Skip to content

Commit

Permalink
Merge pull request #28 from llamaXc/feature-add-f16-ah64
Browse files Browse the repository at this point in the history
Add F16 + AH64
  • Loading branch information
llamaXc authored Jun 5, 2023
2 parents 38b6585 + 864bc36 commit aaa0915
Show file tree
Hide file tree
Showing 3 changed files with 295 additions and 0 deletions.
191 changes: 191 additions & 0 deletions wwt/ufcPatch/aircraft/ufcPatchAH64.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
local ufcUtils = require("ufcPatch\\utilities\\ufcPatchUtils")
ufcPatchAH64 = {}

-- Timestamp for last KU data update
local lastKUDataTimestamp = nil

local function getKU(indication)
local success, KU = pcall(ufcUtils.getDCSListIndication, indication)
if not success then
return nil
end
return KU
end

local function replace(key, value)
local replacedValue = string.gsub(value, "#", "*")
return replacedValue
end

local function defaultDisplay()

--ANDR0ID Added
local MainPanel = GetDevice(0) --Electical Interface for AH64

local MasterArmInfo = MainPanel:get_argument_value(413) --AH-64 Master Arm light
local MasterWarnInfo = MainPanel:get_argument_value(424) --AH-64 Master Arm Warning Light
local MasterCautInfo = MainPanel:get_argument_value(425) --AH-64 Master Arm Caution Light

--Radar Altitude FC3

local FC3RadarAlt = {
math.floor(((LoGetAltitudeAboveGroundLevel())-1.5)*3.28) --Covert meters to feet & account for airframe offset
}

local FC3RadarAltitudeString = ""
for index, value in ipairs(FC3RadarAlt) do
local FC3RadarAltitudeStringToAppend = value
if value <= 0.9 then
FC3RadarAltitudeStringToAppend = 0
elseif value >= 9999 then
FC3RadarAltitudeStringToAppend = 9999
end
FC3RadarAltitudeString = tostring(value)
if value < 10 then
FC3RadarAltitudeString = "000"..value
elseif value >= 1000 then
FC3RadarAltitudeString = ""..value
elseif (value >= 100 and value <= 999) then
FC3RadarAltitudeString = "0"..value
elseif (value >= 10 and value <= 99) then
FC3RadarAltitudeString = "00"..value
end
end

--Heading (Magnetic)
local Headingdigits = {math.floor(LoGetMagneticYaw()* (180/math.pi))}

local HeadingString = ""
for index, value in ipairs(Headingdigits) do
local HeadingdigitToAppend = value
if value >= 360 then
HeadingdigitToAppend = 0
end
HeadingString = tostring(value)
if value < 10 then
HeadingString = "00"..value.."M"
elseif value >= 100 then
HeadingString = ""..value.."M"
elseif value >= 10 then
HeadingString = "0"..value.."M"
end
end

--Fuel (Total)
local Fueldigits = {math.floor((LoGetEngineInfo().fuel_internal)*376*6.692)} --Coverts % fuel to pounds (Uses 376 gallons. as 100% per Chuck's Guide), works for internal, internal and aux, and interal and external

local FuelString = ""
for index, value in ipairs(Fueldigits) do
local FueldigitToAppend = value
if value >= 9999 then
FueldigitToAppend = 9999
end
FuelString = FuelString..FueldigitToAppend
end

--Countermeassures
local Flaredigits = LoGetSnares().flare
local Chaffdigits = LoGetSnares().chaff

--Master Arm
local MasterArmDigit = {math.floor(MasterArmInfo)}

local MasterArmDisplay = ""
for index, value in ipairs(MasterArmDigit) do
local MasterArmDisplayToAppend = value
if value >= 0.2 then
MasterArmDisplayToAppend = 1
end
MasterArmDisplay = MasterArmDisplay..MasterArmDisplayToAppend
if value == 1 then
MasterArmDisplay1 = "ARMD"
elseif value == 0 then
MasterArmDisplay1 = "SAFE"
end
end

--Master Warning / Caution

if MasterWarnInfo == 1 then
StatusDisplay = "WARN"
elseif MasterCautInfo == 1 then
StatusDisplay = "CAUT"
elseif ((MasterWarnInfo == 0) and (MasterCautInfo == 0)) then
StatusDisplay = MasterArmDisplay1
end

--End ANDR0ID Added
return ufcUtils.buildSimAppProUFCPayload({
option1 = FC3RadarAltitudeString, --Radar Altitude --
option2 = HeadingString, --Magnetic Heading
option3 = FuelString, --Fuel (Internal) in Gallons
option4 = "T" .. string.format('%.0f', LoGetTrueAirSpeed()*1.943), --True Airspeed (Knots) --1.852
option5 = StatusDisplay,
--"B" .. string.format('%.0f', math.floor((LoGetAltitudeAboveSeaLevel() * 3.281) / 10) * 10), --Barometric Altimeter
scratchPadNumbers = string.format('%.0f', math.floor(LoGetVerticalVelocity() * 196.85)) .. " ", --Vertical Velocity (FPM)* 0.3048 * 10
--"V" .. string.format('%.0f', math.floor(LoGetVerticalVelocity() * 0.3048 * 10)), --Vertical Velocity (FPS)
scratchPadString1 = "",
scratchPadString2 = "V",
com1 = Flaredigits,
com2 = Chaffdigits,
selectedWindows = {}
})
end

function ufcPatchAH64.generateUFCData()
local PLT_KU = getKU(15)
local CPG_KU = getKU(14)

if PLT_KU then
for key, value in pairs(PLT_KU) do replace(key, value) end
end

if CPG_KU then
for key, value in pairs(CPG_KU) do replace(key, value) end
end

local standbyText = ""
if PLT_KU and PLT_KU["Standby_text"] and PLT_KU["Standby_text"] ~= "" then
standbyText = PLT_KU["Standby_text"]
lastKUDataTimestamp = os.time() -- KU data is available, record the time
elseif CPG_KU and CPG_KU["Standby_text"] and CPG_KU["Standby_text"] ~= "" then
standbyText = CPG_KU["Standby_text"]
lastKUDataTimestamp = os.time() -- KU data is available, record the time
else
-- Check if 7 seconds have passed since last KU data was available, if so show default display
if lastKUDataTimestamp == nil or (lastKUDataTimestamp and os.difftime(os.time(), lastKUDataTimestamp) >= 7) then
return defaultDisplay()
end

return nil
end

if string.len(standbyText) > 19 then standbyText = string.sub(standbyText, 5) end

local function getKPU(n)
return string.gsub(string.gsub(standbyText:sub(n, n + 3), "#", "*"), ":", "-")
end
--ANDR0ID Added
--Countermeassures
local Flaredigits = LoGetSnares().flare
local Chaffdigits = LoGetSnares().chaff
--End ANDR0ID Added
return ufcUtils.buildSimAppProUFCPayload({
option1 = getKPU(1),
option2 = getKPU(5),
option3 = getKPU(9),
option4 = getKPU(13),
option5 = getKPU(17),
scratchPadNumbers = "-64 ",
scratchPadString1 = "A",
scratchPadString2 = "H",
com1 = Flaredigits,
com2 = Chaffdigits,
selectedWindows = {}
})
end

return ufcPatchAH64

--v1.0 by Wostg
--v2.0 by ANDR0ID
94 changes: 94 additions & 0 deletions wwt/ufcPatch/aircraft/ufcPatchF16.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
local ufcUtils = require("ufcPatch\\utilities\\ufcPatchUtils")

ufcPatchF16 = {}

ufcPatchF16.startTime = os.time()

function ufcPatchF16.generateUFCData()
if os.time() - ufcPatchF16.startTime < 15 then
return
end

local MainPanel = GetDevice(0)
local HUD = ufcUtils.getDCSListIndication(1)
local expendableReadout = ufcUtils.getDCSListIndication(16)

-- Altimeter AAU-34/A
local HUD_Altitude_num_k = HUD.HUD_Altitude_num_k or 0
local HUD_Altitude_num = HUD.HUD_Altitude_num or 0
local HUD_BARO = (HUD_Altitude_num_k * 1000) + HUD_Altitude_num

local Altimeter_100_footCount = GetDevice(0):get_argument_value(54)
local Altimeter_1000_footCount = GetDevice(0):get_argument_value(53)
local Altimeter_10000_footCount = GetDevice(0):get_argument_value(52)
local BACKUP_BARO = Altimeter_10000_footCount * 10000 + Altimeter_1000_footCount * 1000 + Altimeter_100_footCount * 100

local BARO_ALT = ""
if HUD_BARO ~= 0 then
BARO_ALT = string.format('%02dK%01d%01d', math.floor(HUD_BARO / 1000), math.floor((HUD_BARO % 1000) / 100), 0)
elseif BACKUP_BARO ~= 0 then
BARO_ALT = string.format('%02dK%01d%01d', math.floor(BACKUP_BARO / 100), math.floor((BACKUP_BARO % 1000) / 10), 0)
elseif LoGetAltitudeAboveSeaLevel then
local success, ALT_ASL = pcall(LoGetAltitudeAboveSeaLevel)
if success then
BARO_ALT = string.format('%02dK%01d%01d', math.floor(ALT_ASL / 1000), math.floor((ALT_ASL % 1000) / 100), 0)
else
BARO_ALT = "BALT"
end
else
BARO_ALT = "BALT"
end

-- Velocity Mnemonic and Numerics
local HUD_Window2_VelScaleMnemonic = HUD.HUD_Window2_VelScaleMnemonic or "V"
local HUD_Velocity_num = HUD.HUD_Velocity_num or 0
local TAS = LoGetTrueAirSpeed()

local Velocity = HUD_Window2_VelScaleMnemonic .. string.format('%03d', HUD_Velocity_num)
if Velocity == HUD_Window2_VelScaleMnemonic then
Velocity = string.format('T%.0f', TAS)
end

if Velocity == HUD_Window2_VelScaleMnemonic and TAS == 0 then
Velocity = "VELO"
end

-- Fuel Totaliser
local FuelTotalizer_10k = MainPanel:get_argument_value(730)
local FuelTotalizer_1k = MainPanel:get_argument_value(731)
local FuelTotalizer_100 = MainPanel:get_argument_value(732)
local fuelPercentage = math.floor(FuelTotalizer_10k * 10000 + FuelTotalizer_1k * 1000 + FuelTotalizer_100 * 100)

-- FLARES AND CHAFF, display the final two digits
local flareCount = expendableReadout and expendableReadout.CMDS_FL_Amount or 0
local chaffCount = expendableReadout and expendableReadout.CMDS_CH_Amount or 0

local FLARES, CHAFF = "", ""
if type(flareCount) == "string" then
FLARES = string.sub(flareCount, -2)
elseif type(flareCount) == "number" then
FLARES = string.sub(string.format('%04d', flareCount), 3)
end

if type(chaffCount) == "string" then
CHAFF = string.sub(chaffCount, -2)
elseif type(chaffCount) == "number" then
CHAFF = string.sub(string.format('%04d', chaffCount), 3)
end

return ufcUtils.buildSimAppProUFCPayload({
option1=Velocity,
option2=BARO_ALT,
option3="H" .. string.format('%.0f', ((LoGetMagneticYaw() * 180 / math.pi) + 360) % 360),
option4="V" .. string.format('%.0f', LoGetVerticalVelocity() * 0.3048 * 10),
option5="F" .. string.format('%03d', fuelPercentage),
scratchPadNumbers=HUD.HUD_Window14_StpTgtData_RangeNum,
scratchPadString1="S",
scratchPadString2="P",
com1=CHAFF,
com2=FLARES,
selectedWindows={}
})
end

return ufcPatchF16
10 changes: 10 additions & 0 deletions wwt/ufcPatch/ufcPatch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ local ufcPatchKA50 = require("ufcPatch\\aircraft\\ufcPatchKA50")
local ufcPatchJF17 = require("ufcPatch\\aircraft\\ufcPatchJF17")
local ufcPatchTF51D = require("ufcPatch\\aircraft\\ufcPatchTF51D")
local ufcPatchA4 = require("ufcPatch\\aircraft\\ufcPatchA4")
local ufcPatchAH64 = require("ufcPatch\\aircraft\\ufcPatchAH64")
local ufcPatchF16 = require("ufcPatch\\aircraft\\ufcPatchF16")

-- Add new module names here, then create a supporting lua file for the aircraft
-- See aircraft/ufcPatchCustomModuleExample.lua for an example.
Expand Down Expand Up @@ -53,6 +55,14 @@ function ufcPatch.generateUFCExport(deltaTime, moduleName)
return ufcPatchA10C2.generateUFCData()
end

-- AH-64D_BLK_II sends information when latest is available
elseif moduleName == 'AH-64D_BLK_II' then
return ufcPatchAH64.generateUFCData()

-- F-16C_50 sends information when latest is available
elseif moduleName == 'F-16C_50' then
return ufcPatchF16.generateUFCData()

-- AV8BNA sends ODU information when latest is available
elseif moduleName == 'AV8BNA' then
return ufcPatchAV88.generateUFCData()
Expand Down

0 comments on commit aaa0915

Please sign in to comment.