Skip to content

Commit

Permalink
Merge pull request #30 from ANDR0ID-DCS/main
Browse files Browse the repository at this point in the history
General Profile
  • Loading branch information
llamaXc authored Jun 9, 2023
2 parents 883ca55 + 28c4078 commit 0139c21
Show file tree
Hide file tree
Showing 3 changed files with 319 additions and 0 deletions.
47 changes: 47 additions & 0 deletions wwt/ufcPatch/aircraft/ufcPatchGeneral.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
local ufcUtils = require("ufcPatch\\utilities\\ufcPatchUtils")

ufcPatchGeneral = {}

function ufcPatchGeneral.generateUFCData()

local MainPanel = GetDevice(0)

local FC3RadarAltitudeString = ufcPatchUtils.GenaricRadarAltitudeFeet()
local HeadingString = ufcPatchUtils.MagHeading()
local AirspeedString = ufcPatchUtils.AirspeedKnots()
local FuelString = ufcPatchUtils.TotalFuel()
local Vertical = ufcPatchUtils.VerticalV_FPM()
local FlareCount = ufcPatchUtils.flares()
local ChaffCount = ufcPatchUtils.chaff()

--Send info to UFC components
return ufcUtils.buildSimAppProUFCPayload({
scratchPadNumbers=Vertical,
option1=FC3RadarAltitudeString,
option2=HeadingString,
option3=FuelString, --May be significantly incorrect depending on module, should be % but could be kg or other
option4=AirspeedString,
option5="GNRL",
com1=FlareCount,
com2=ChaffCount,
scratchPadString1="",
scratchPadString2="V"
})
end

return ufcPatchGeneral --v2.0 by ANDR0ID

--[[ Other avaliable functions
ufcPatchUtils.GenaricRadarAltitudeFeet()
ufcPatchUtils.GenaricRadarAltitudeMeters()
ufcPatchUtils.GenaricBaroAltitudeFeet()
ufcPatchUtils.GenaricBaroAltitudeMeters()
ufcPatchUtils.AirspeedKnots()
ufcPatchUtils.AirspeedMPS()
ufcPatchUtils.MagHeading()
ufcPatchUtils.TotalFuel()
ufcPatchUtils.VerticalV_FPM()
ufcPatchUtils.VerticalV_MPS()
ufcPatchUtils.flares()
ufcPatchUtils.chaff()
]]
6 changes: 6 additions & 0 deletions wwt/ufcPatch/ufcPatch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ local ufcPatchTF51D = require("ufcPatch\\aircraft\\ufcPatchTF51D")
local ufcPatchA4 = require("ufcPatch\\aircraft\\ufcPatchA4")
local ufcPatchAH64 = require("ufcPatch\\aircraft\\ufcPatchAH64")
local ufcPatchF16 = require("ufcPatch\\aircraft\\ufcPatchF16")
local ufcPatchGeneral = require("ufcPatch\\aircraft\\ufcPatchGeneral")

-- 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 @@ -130,6 +131,11 @@ function ufcPatch.generateUFCExport(deltaTime, moduleName)
elseif moduleName == "Hercules" then
if ufcExportClock.canTransmitLatestPayload then
return ufcPatchHerc.generateUFCData()
end
--General Profile sends throttled data (THIS MUST ALWAYS BE LAST IN THE LIST)
elseif moduleName ~= "FA-18C_hornet" then
if ufcExportClock.canTransmitLatestPayload then
return ufcPatchGeneral.generateUFCData()
end
end
end
Expand Down
266 changes: 266 additions & 0 deletions wwt/ufcPatch/utilities/ufcPatchUtils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,270 @@ function ufcPatchUtils.buildSimAppProUFCPayload(simAppProUFCDataMap)
return option1..option2..option3..option4..option5..com1..com2..scratchDigits..scratchLeftString..scrathRightString..cuedWindowsPayload
end

--ANDR0ID Added
--Genaric Functions Which Can Be Called Accross Multiple Profiles

--Radar Altitude in Feet (Will be off due to various airframe offsets)
function ufcPatchUtils.GenaricRadarAltitudeFeet()
local FC3RadarAltFeet = {
math.floor(((LoGetAltitudeAboveGroundLevel()))*3.28)-0 --Covert meters to feet & account for airframe offset
}
local FC3RadarAltitudeStringFeet = ""
for index, value in ipairs(FC3RadarAltFeet) do
local FC3RadarAltitudeStringFeetToAppend = value
if value <= 0.9 then
FC3RadarAltitudeStringFeetToAppend = 0
elseif value >= 99999 then
FC3RadarAltitudeStringFeetToAppend = 99999
end
FC3RadarAltitudeStringFeet = tostring(value)
if value >= 10000 then
FC3RadarAltitudeStringFeet = math.floor(value/1000).."K"
elseif value < 10 then
FC3RadarAltitudeStringFeet = "000"..value
elseif value >= 1000 then
FC3RadarAltitudeStringFeet = ""..value
elseif (value >= 100 and value <= 999) then
FC3RadarAltitudeStringFeet = "0"..value
elseif (value >= 10 and value <= 99) then
FC3RadarAltitudeStringFeet = "00"..value
end
end
return FC3RadarAltitudeStringFeet
end

--Radar Altitude in Meters (Will be off due to various airframe offsets)
function ufcPatchUtils.GenaricRadarAltitudeMeters()
local FC3RadarAltMeters = {
math.floor(((LoGetAltitudeAboveGroundLevel())))
}
local FC3RadarAltitudeStringMeters = ""
for index, value in ipairs(FC3RadarAltMeters) do
local FC3RadarAltitudeStringMetersToAppend = value
if value <= 0.9 then
FC3RadarAltitudeStringMetersToAppend = 0
elseif value >= 99999 then
FC3RadarAltitudeStringMetersToAppend = 99999
end
FC3RadarAltitudeStringMeters = tostring(value)
if value >= 10000 then
FC3RadarAltitudeStringMeters = math.floor(value/1000).."K"
elseif value < 10 then
FC3RadarAltitudeStringMeters = "000"..value
elseif value >= 1000 then
FC3RadarAltitudeStringMeters = ""..value
elseif (value >= 100 and value <= 999) then
FC3RadarAltitudeStringMeters = "0"..value
elseif (value >= 10 and value <= 99) then
FC3RadarAltitudeStringMeters = "00"..value
end
end
return FC3RadarAltitudeStringMeters
end

--Barometric Altitude in Feet (Will be off due to various airframe offsets)
function ufcPatchUtils.GenaricBaroAltitudeFeet()
local FC3BaroAltFeet = {
math.floor(((LoGetAltitudeAboveSeaLevel()))*3.28)-0 --Covert meters to feet & account for airframe offset
}
local FC3BaroAltitudeStringFeet = ""
for index, value in ipairs(FC3BaroAltFeet) do
local FC3BaroAltitudeStringFeetToAppend = value
if value <= 0.9 then
FC3BaroAltitudeStringFeetToAppend = 0
elseif value >= 99999 then
FC3BaroAltitudeStringFeetToAppend = 99999
end
FC3BaroAltitudeStringFeet = tostring(value)
if value >= 10000 then
FC3BaroAltitudeStringFeet = math.floor(value/1000).."K"
elseif value < 10 then
FC3BaroAltitudeStringFeet = "000"..value
elseif value >= 1000 then
FC3BaroAltitudeStringFeet = ""..value
elseif (value >= 100 and value <= 999) then
FC3BaroAltitudeStringFeet = "0"..value
elseif (value >= 10 and value <= 99) then
FC3BaroAltitudeStringFeet = "00"..value
end
end
return FC3BaroAltitudeStringFeet
end

--Barometric Altitude in Meters (Will be off due to various airframe offsets)
function ufcPatchUtils.GenaricBaroAltitudeMeters()
local FC3BaroAltMeters = {
math.floor(((LoGetAltitudeAboveSeaLevel())))
}
local FC3BaroAltitudeStringMeters = ""
for index, value in ipairs(FC3BaroAltMeters) do
local FC3BaroAltitudeStringMetersToAppend = value
if value <= 0.9 then
FC3BaroAltitudeStringMetersToAppend = 0
elseif value >= 99999 then
FC3BaroAltitudeStringMetersToAppend = 99999
end
FC3BaroAltitudeStringMeters = tostring(value)
if value >= 10000 then
FC3BaroAltitudeStringMeters = math.floor(value/1000).."K"
elseif value < 10 then
FC3BaroAltitudeStringMeters = "000"..value
elseif value >= 1000 then
FC3BaroAltitudeStringMeters = ""..value
elseif (value >= 100 and value <= 999) then
FC3BaroAltitudeStringMeters = "0"..value
elseif (value >= 10 and value <= 99) then
FC3BaroAltitudeStringMeters = "00"..value
end
end
return FC3BaroAltitudeStringMeters
end

--Airspeed Knots
function ufcPatchUtils.AirspeedKnots()
local AirspeeddigitsKts = {math.floor(LoGetIndicatedAirSpeed()*1.943)} --Convert Meters per Second to Knots

local AirspeedStringKts = ""
for index, value in ipairs(AirspeeddigitsKts) do
local AirspeeddigitKtsToAppend = value
if value >= 9999 then
AirspeeddigitToAppend = 9999
end
AirspeedStringKts = AirspeedStringKts..AirspeeddigitKtsToAppend
end
return AirspeedStringKts
end

--Airspeed MPS
function ufcPatchUtils.AirspeedMPS()
local AirspeeddigitsMPS = {math.floor(LoGetIndicatedAirSpeed())} --Meters per Second

local AirspeedStringMPS = ""
for index, value in ipairs(AirspeeddigitsMPS) do
local AirspeeddigitMPSToAppend = value
if value >= 9999 then
AirspeeddigitToAppend = 9999
end
AirspeedStringMPS = AirspeedStringMPS..AirspeeddigitMPSToAppend
end
return AirspeedStringMPS
end

--Heading (Magnetic)
function ufcPatchUtils.MagHeading()
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 == -7 then
HeadingString = "353M"
elseif value == -6 then
HeadingString = "354M"
elseif value == -5 then
HeadingString = "355M"
elseif value == -4 then
HeadingString = "356M"
elseif value == -3 then
HeadingString = "357M"
elseif value == -2 then
HeadingString = "358M"
elseif value == -1 then
HeadingString = "359M"
elseif value < 10 then
HeadingString = "00"..value.."M"
elseif value >= 100 then
HeadingString = ""..value.."M"
elseif value >= 10 then
HeadingString = "0"..value.."M"
end
end
return HeadingString
end

--Fuel (Total)
function ufcPatchUtils.TotalFuel()
local Fueldigits = {math.floor((LoGetEngineInfo().fuel_internal)*100)} --How this displays varies by airframe... should be percentage, but may be signifincalty wrong (ie kg, etc)

local FuelString = ""
for index, value in ipairs(Fueldigits) do
local FueldigitToAppend = value
if value >= 9999 then --Value may need editing depending on airframe
FueldigitToAppend = 9999
end

FuelSting = tostring(value)
if value >= 10000 then
FuelString = math.floor(value/1000).."K"
elseif value < 10000 then
FuelString = value
end
end
return FuelSting
end

--Vertical Velocity
--Feet per Min
function ufcPatchUtils.VerticalV_FPM()
local VerticalSpeed = {math.floor(LoGetVerticalVelocity()*196.85)} --Feet per Min

local VerticalFPM = ""
for index, value in ipairs(VerticalSpeed) do
local VerticalFPMtoAppend = value
if value >= 9999 then
AirspeeddigitToAppend = 9999
end
VerticalFPM = VerticalFPM..VerticalFPMtoAppend
end
return VerticalFPM
end
--Meters per Second
function ufcPatchUtils.VerticalV_MPS()
local AirspeeddigitsMPS = {math.floor(LoGetVerticalVelocity())} --Meters per Second

local VerticalMPS = ""
for index, value in ipairs(AirspeeddigitsMPS) do
local VerticalMPStoAppend = value
if value >= 9999 then
AirspeeddigitToAppend = 9999
end
VerticalMPS = VerticalMPS..VerticalMPStoAppend
end
return VerticalMPS
end

--Countermeassures (Limited to 99 based of the assumption they will be displayed on Com1/2 which can only display two digits)
function ufcPatchUtils.flares()
local Flaredigits = {math.floor(LoGetSnares().flare)}

local FlareString = ""
for index, value in ipairs(Flaredigits) do
local FlaredigitsToAppend = value
if value >= 99 then
FlaredigitsToAppend = 99
end
FlareString = FlareString..FlaredigitsToAppend
end
return FlareString
end

function ufcPatchUtils.chaff()
local Chaffdigits = {math.floor(LoGetSnares().chaff)}

local ChaffString = ""
for index, value in ipairs(Chaffdigits) do
local ChaffdigitsToAppend = value
if value >= 99 then
ChaffdigitsToAppend = 99
end
ChaffString = ChaffString..ChaffdigitsToAppend
end
return ChaffString
end
--End ANDR0ID Added

return ufcPatchUtils

0 comments on commit 0139c21

Please sign in to comment.