Skip to content

Commit

Permalink
Added FA-18C Hornet support: backlight
Browse files Browse the repository at this point in the history
  • Loading branch information
iknowkungfutoo committed Dec 2, 2023
1 parent f60bd77 commit 83a87f5
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 5 deletions.
24 changes: 19 additions & 5 deletions Hooks/dcs2arget.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,17 @@
-- Speed brake position
-- Console light control level
--
-- F/A-18C Hornet:
-- Speed brake position
-- Console light control level
--
--
-- Author: slughead
-- Date: 28/11/2023
-- Date: 2/12/2023
--
-- Version 1.0.5 - Added F/A-18C Hornet console light control.
-- Version 1.0.4 - Converted from export.lua to "hooks" file.
-- Version 1.0.3 - Added A-10C console light control
-- Version 1.0.3 - Added A-10C console light control.
--
------------------------------------------------------------------------------

Expand All @@ -38,7 +42,7 @@ local generic_aircraft_utils

local dcs2target = {}

dcs2target.VERSION = "DCS2TARGET v1.0.4"
dcs2target.VERSION = "DCS2TARGET v1.0.5"

dcs2target.lastUpdateTime = DCS.getModelTime()

Expand Down Expand Up @@ -118,14 +122,15 @@ function dcs2target.onSimulationFrame()
dcs2target.aircraft_lamp_utils = require("a-10c_lamps")
elseif (dcs2target.aircraft.Name == "F-16C_50") then
dcs2target.aircraft_lamp_utils = require("f-16c_50_lamps")
elseif (dcs2target.aircraft.Name == "FA-18C_hornet") then
dcs2target.aircraft_lamp_utils = require("fa-18c_hornet_lamps")
end
end

local send_update = false
local payload

if ( dcs2target.aircraft.Name == "FA-18C_hornet" or
dcs2target.aircraft.Name == "Su-25T" or
if ( dcs2target.aircraft.Name == "Su-25T" or
dcs2target.aircraft.Name == "Su-33" ) then

local speedbrake_status_payload
Expand Down Expand Up @@ -159,6 +164,15 @@ function dcs2target.onSimulationFrame()
send_update = send_update or updated
end

if (dcs2target.aircraft.Name == "FA-18C_hornet") then
local lamp_status_payload
local updated = false

updated, lamp_status_payload = dcs2target.aircraft_lamp_utils:create_lamp_status_payload()
payload = lamp_status_payload
send_update = updated
end

if send_update then
if target_socket then
payload = tm_target_utils.UPDATE..payload
Expand Down
96 changes: 96 additions & 0 deletions dcs2target/fa-18c_hornet_lamps.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
-------------------------------------------------------------------------------
--
-- fa-18c_hornet_lamps.lua
--
-- Use at own risk without warranty.
--
-- Utility functions for retrieving DCS F/A-18C Hornet simulation data
-- and packaging for TCP packet transmission to Thrustmaster Target
-- TMHotasLEDSync.tmc script.
--
-- Author: slughead
-- Date: 2/12/2023
--
------------------------------------------------------------------------------

local P = {}
fa_18c_hornet_lamps = P

P.CONSOLE_LIGHT_DIAL = 413

P.speedbrakes_value = nil
P.console_light_value = nil


local function get_console_light_value( current_value )
local updated = false
local value = 0

local device = Export.GetDevice(0)
if type(device) ~= "number" and device ~= nil then
local aircraft_lamp_utils = require("fa-18c_hornet_lamps")

-- get engine info
local lEngInfo = Export.LoGetEngineInfo()

if (lEngInfo.RPM.left > 60) then
value = device:get_argument_value(aircraft_lamp_utils.CONSOLE_LIGHT_DIAL)
value = math.floor(value * 5)
end

if current_value ~= value then
updated = true
end
end

return updated, value
end

local function get_speedbrake_value( current_value )

local updated = false
local value = 0

local lMechInfo = Export.LoGetMechInfo() -- mechanical components, e.g. Flaps, Wheelbrakes,...
if (lMechInfo ~= nil) then
value = lMechInfo.speedbrakes.value

-- ensure full range is used for aircraft that almost reach 1.0
if (value >= 0.9) then value = 1.0 end

value = math.floor(value * 5)

if (current_value ~= value) then
updated = true;
end
end

return updated, value
end

function P.create_lamp_status_payload( self )

local updated = false
local status_changed = false
local payload

local device = Export.GetDevice(0)
if type(device) ~= "number" and device ~= nil then
status_changed, self.speedbrakes_value = get_speedbrake_value( self.speedbrakes_value )
updated = updated or status_changed

status_changed, self.console_light_value = get_console_light_value( self.console_light_value )
updated = updated or status_changed

payload = string.format( "%d%d",
self.speedbrakes_value,
self.console_light_value )
else
payload = "00"
end

return updated, payload

end

return fa_18c_hornet_lamps

0 comments on commit 83a87f5

Please sign in to comment.