Jump to content

OwenM

Lua script to control Taxi and Landing lights

Recommended Posts

I have built an overhead panel for my sim that has some switches for example Taxi Lights and Landing Lights.

Although I have used Lua before I have spent hours on trying to get these switches to work.

I know that the light switch data is held in 0x0D0C  offset but I can not figure out how to extract the individual bits to allow me to modify them and then write them back to the offset. I think it involves some logic.and  command but its all beyond me unfortunately.

Or am I on the wrong track altogether and is there an easier way.

Could anyone please help with a little sample code that reads offset  extracts bit 3 , if its off turn it on and vice versa and write it back to 0x0D0C.

I have read all the stuff that comes with FSUIPC  but to no avail

 

Thanks heaps

 

Owen Moore

 

 

 

 

 

Share this post


Link to post
Share on other sites

See the FSUIPC forum for a possible remedy.


Roman_Full_combo_AVSIM_2.png?dl=1  FS RTWR   SHRS F-111   JoinFS Host/Client 

 

Yamaha CR 1000/JBL 2500, AMD 965 BE OC'd @ 3.88, RipJaw 2x4GB 1600 CL7, Gigabyte GTX-1070 OC 8GB, Asus M4A87TD EVO (AMD 870), Samsung 850 EVO 256GB & 1TB SSDs, WD 1T & 500G Black, 19" & 32" LCD, Win7 Pro 64bit, TMaster T-Flight HOTAS, FSX/FS9, FSUIPC / LUA, FSRealWX Pro, PlanG, JoinFS, LittleNavMap

Copilot - Samantha the "Hound"                EAA Chapter 651
       samantha.jpg?dl=1

 

Share this post


Link to post
Share on other sites
Posted (edited)

Is this for P3D? If so:

1. Create a plain text file called LUACMDS.lua (or whatever you want) and copy and paste the script below into that file. Watch out for a text editor that adds special characters. I use Notepad++ which is excellent freeware for editing.

2. Save that file in your P3D modules folder.

3. In P3D FSUIPC5 (paid version) assign your taxi light switch ON position to "Select for FS control" then in the dropdown select "LUA LUACMDS" and in the Parameter put "1".

4. Repeat for the assignment of the taxi switch OFF and landing switch ON / OFF using parameters "2" "3" "4" as indicated in the script below.

5. Add a section to your FSUIPC5.ini file as follows:

         [LuaFiles]
        1=LUACMDS

The reason it's "8" and "4" in the setbitsUW cmd is because the bit #3 (1000) in binary, is 8 decimal. Remember the bits start at zero on the right.

Try this and see if it works. It can be more complicated if the airplane you're flying has a single light with two intensities. Then we have to clearbits to turn one light off when the other is turned on. And in some airplanes the switch in the VC may not move. If that happens we have to know the LVAR for the switch and read it then set it appropriately. I can help.

Good luck,

Bruce

Spoiler

--------------------------------------------
-- Scripts for special switches and functions
--------------------------------------------

--------------------------------------------
-- Parameters by Number
--------------------------------------------
-- 1    Turn ON taxi light
-- 2    Turn OFF taxi light
-- 3    Turn ON Landing light
-- 4    Turn OFF Landing light

--------------------------------------------
---- Scripts
--------------------------------------------

-- Turn ON taxi light
if ipcPARAM == 1 then
    ipc.setbitsUW(0x0D0C, 8 )    
end

-- Turn OFF taxi light
if ipcPARAM == 2 then
      ipc.clearbitsUW(0x0D0C, 8 )           
end

-- Turn ON landing light
if ipcPARAM == 3 then
    ipc.setbitsUW(0x0D0C, 4) 
end

-- Turn OFF landing light
if ipcPARAM == 4 then
      ipc.clearbitsUW(0x0D0C, 4)            
end

 

Edited by bbuckley
fix spoiler text for some reason the 8 and ) are being converted to a smiley. in your text file make it 8 & ) with no space.

Bruce Buckley | RW Commercial / Instrument / SEL / MEL

I9-9900K @5.0GHz, Maximus XI  Hero, GTX 1080ti, 32GB DDR4 3200 14, 1TB NVMe SSD, 500GB SSD, 1TB HDD, 40" Samsung 4K TV, Saitek/Logitech Pro Yoke, Throttle Q, Rudder Pedals, Switch Panel, WIN10, P3DV4.5, PTA, ASP4, REX TDSC Lots of ORBX stuff and some add on airports / aircraft

Share this post


Link to post
Share on other sites
Posted (edited)

Here is my Lua scriptlet that can control all the lights (bits) of 0x0D0C. In FSUIPC, after putting in the name of the Lua script, put the appropriate parameter number in the "Parameter" field.

Let me know if you have any questions.

 

Spoiler

 

-- List of parameters
--   0 All lights off
--    10    Instrument lights off
--    11    Instrument lights on
--    12    Strobe light off
--    13    Strobe light on
--    14    Landing lights off    
--    15    Landing lights on
--    16    Taxi lights off
--    17    Taxi lights on
--    18    Cockpit flood lights off
--    19    Cockpit flood lights on
--    20    Nav lights off
--    21    Nav lights on
--    22    Beacon light off
--    23    Beacon light on
--    24    Wing lights off
--    25    Wing lights on
--    26    Logo light off
--    27    Logo light on

--   0 All lights off
if ipcPARAM == 0 then 
  ipc.writeUW("0D0C", 0)
end

--    10    Instrument lights off
if ipcPARAM == 10 then
  ipc.control(66057)
end
    
--    11    Instrument lights on
if ipcPARAM == 11 then
  ipc.control(66056)
end
    
--    12    Strobe light off
if ipcPARAM == 12 then
  ipc.control(66053)
end

--    13    Strobe light on
if ipcPARAM == 13 then
  ipc.control(66052)
end

--    14    Landing lights off    
if ipcPARAM == 14 then
  ipc.control(66060)
end
    
--    15    Landing lights on
if ipcPARAM == 15 then
  ipc.control(66059)
end

--    16    Taxi lights off
if ipcPARAM == 16 then
  cstate =  ipc.readUW("0D0C")
  nstate = logic.And(cstate, 1015)
  ipc.writeUW("0D0C", nstate)
end

--    17    Taxi lights on
if ipcPARAM == 17 then
  cstate =  ipc.readUW("0D0C")
  nstate = logic.Or(cstate, 😎
  ipc.writeUW("0D0C", nstate)
end

--    18    Cockpit flood lights off
if ipcPARAM == 18 then
  cstate =  ipc.readUW("0D0C")
  nstate = logic.And(ipc.readUW("0D0C"), 511)
  ipc.writeUW("0D0C", nstate)
end

--    19    Cockpit flood lights on
if ipcPARAM == 19 then
  cstate =  ipc.readUW("0D0C")
  nstate = logic.Or(ipc.readUW("0D0C"), 512)
  ipc.writeUW("0D0C", nstate)
end

--    20    Nav lights off
if ipcPARAM == 20 then
  cstate =  ipc.readUW("0D0C")
  nstate = logic.And(ipc.readUW("0D0C"), 1022)
  ipc.writeUW("0D0C", nstate)
end

--    21    Nav lights on
if ipcPARAM == 21 then
  cstate =  ipc.readUW("0D0C")
  nstate = logic.Or(ipc.readUW("0D0C"), 1)
  ipc.writeUW("0D0C", nstate)
end

--    22    Beacon lights off
if ipcPARAM == 22 then
  cstate =  ipc.readUW("0D0C")
  nstate = logic.And(ipc.readUW("0D0C"), 1021)
  ipc.writeUW("0D0C", nstate)
end

--    23    Beacon lights on
if ipcPARAM == 23 then
  cstate =  ipc.readUW("0D0C")
  nstate = logic.Or(ipc.readUW("0D0C"), 2)
  ipc.writeUW("0D0C", nstate)
end

--    24    Wing lights off
if ipcPARAM == 24 then
  cstate =  ipc.readUW("0D0C")
  nstate = logic.And(ipc.readUW("0D0C"), 895)
  ipc.writeUW("0D0C", nstate)
end

--    25    Wing lights on
if ipcPARAM == 25 then
  cstate =  ipc.readUW("0D0C")
  nstate = logic.Or(ipc.readUW("0D0C"), 128)
  ipc.writeUW("0D0C", nstate)
end

--    26    Logo lights off
if ipcPARAM == 26 then
  cstate =  ipc.readUW("0D0C")
  nstate = logic.And(ipc.readUW("0D0C"), 767)
  ipc.writeUW("0D0C", nstate)
end

--    27    Logo lights on
if ipcPARAM == 27 then
  cstate =  ipc.readUW("0D0C")
  nstate = logic.Or(ipc.readUW("0D0C"), 256)
  ipc.writeUW("0D0C", nstate)
end

 

 

Edited by yurei

Share this post


Link to post
Share on other sites

Thank you for all your help. i have now got my switches all working with ideas from your code examples. Instead off togglebit I used set and clear bit for better control.

 

If I may ask another couple of questions

I now understand how to work with the switches but I also have a park brake switch and can not figure out how to write to offset 0BC8 as it seems to take a value from 0 to 32767 when all I really want is on or off.

I note in the offset pdf there is a field for size but how does that relate to the following

UB unsigned 8-bit byte
UW unsigned 16-bit word
UD unsigned 32-bit dword
SB signed 8-bit byte
SW signed 16-bit word
SD signed 32-bit dword
DD signed 64-bit value
DBL 64-bit double floating point
FLT 32-bit single floating point
STR string of ASCII characters (in this case the preceding number,
n, gives the length not a repeat count)

 

I am sure there is a correlation to these two and I note that 0D0C has a size of 2 and that we used sw in the lights example

 

Again thanks for your help

 

Owen

Share this post


Link to post
Share on other sites

Here is a toggle for parking brake.  If ipcparam is 1, the brake is set. if ipcparam is 0, then the brake is released.

pbstate = ipcPARAM
if pbstate <= 0
then pb = 0
else pb = 32767
end
ipc.writeSW(0x0BC8, pb)

 

 

 

  • Like 1

Share this post


Link to post
Share on other sites

Thanks all. I now have my overhead panel and my throttle panel all working nicely

 

 

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...