sun visor control?

One of the world's most popular trainer aircraft
burns
Airman First Class
Posts: 69
Joined: 14 Jun 2013, 17:39

sun visor control?

Post by burns »

Is there a way to assign it to a button or axis? It would be convenient while in VR

User avatar
Nick - A2A
A2A Captain
Posts: 13734
Joined: 06 Jun 2014, 13:06
Location: UK

Re: sun visor control?

Post by Nick - A2A »

Do you own a registered copy of FSUIPC? If so, you should be able to use the "L:VisorLeftPercent" and "L:VisorRightPercent" L:Vars.

Nick

burns
Airman First Class
Posts: 69
Joined: 14 Jun 2013, 17:39

Re: sun visor control?

Post by burns »

I do own a registered version of FSUIPC. Would that mean they would be on/off so to speak? Or can I assign an axis to them?

User avatar
Nick - A2A
A2A Captain
Posts: 13734
Joined: 06 Jun 2014, 13:06
Location: UK

Re: sun visor control?

Post by Nick - A2A »

Just about anything is possible in theory with FSUIPC. Assigning the visors to an axis would be a little more complex as I guess you'd need to find a way to scale the axis input range (e.g. -16384 to +16384) to match the range of 0 to 100 which is valid for the visors. I'm not sure, but it's possible that the free Linda software already offers a preset for this.

Nick

Tomas Linnet
Senior Master Sergeant
Posts: 2286
Joined: 05 Nov 2013, 10:48
Location: Oksboel, Denmark

Re: sun visor control?

Post by Tomas Linnet »

LINDA can't do anything with axis, but I'm pretty sure our good friend, Gypsy Baron is able to help out here.
Kind Regards
Tomas

Sim: FSX SE
Accu-Sim aircraft in my hangar:
C172, C182, P51 Civ, P51 Mil, B17, Spitfire, P47, B377 COTS,
J3 Cub, T6, Connie, P-40, V35B
A2A Accu-Sim Avro Lancaster Loading:............0.000003% complete, please wait.

burns
Airman First Class
Posts: 69
Joined: 14 Jun 2013, 17:39

Re: sun visor control?

Post by burns »

Linda doesn't do axis, only buttons

Tomas Linnet
Senior Master Sergeant
Posts: 2286
Joined: 05 Nov 2013, 10:48
Location: Oksboel, Denmark

Re: sun visor control?

Post by Tomas Linnet »

I just sent Gypsy a heads up on a PM.
Kind Regards
Tomas

Sim: FSX SE
Accu-Sim aircraft in my hangar:
C172, C182, P51 Civ, P51 Mil, B17, Spitfire, P47, B377 COTS,
J3 Cub, T6, Connie, P-40, V35B
A2A Accu-Sim Avro Lancaster Loading:............0.000003% complete, please wait.

Gypsy Baron
A2A Master Mechanic
Posts: 3396
Joined: 02 Aug 2008, 17:04
Location: San Francisco

Re: sun visor control?

Post by Gypsy Baron »

I am currently on another trip, sitting in Cape Breton, Nova Scotia but I do have my gaming laptop with me. I have several examples of scaling axis inputs to 0 - 100% for writing to a L:Variable so it should be a simple matter of editing one of them. They are contained in Lua scripts and can be activated by in a number of ways.

I'll have a look at this in the next few days when I have some time, as I am currently 'engaged' in completing some mission files for the 91st Bombardment Group.

Paul

Image
Last edited by Gypsy Baron on 01 Sep 2017, 23:07, edited 1 time in total.

User avatar
Nick - A2A
A2A Captain
Posts: 13734
Joined: 06 Jun 2014, 13:06
Location: UK

Re: sun visor control?

Post by Nick - A2A »

Thanks Paul. I'll be interested to see what you come up with too as I've never tried assigning an L:Var to an axis. (I don't have enough spare axes to make it worthwhile I'm afraid! :P )

Nick

Gypsy Baron
A2A Master Mechanic
Posts: 3396
Joined: 02 Aug 2008, 17:04
Location: San Francisco

Re: sun visor control?

Post by Gypsy Baron »

OK, I have come up with some Lua code to handle setting the sun visors in the A2A C172.

I don't have the C172 on my traveling laptop here but I do have the C182 which uses the
same L:Variables as the C172 so I was able to test this.

There are 4 elements to consider here. First the L:Variables must be defined for FSUIPC4
to add them to the controls menus. This is done by creating a text file and saving it to
the FSX Modules folder with the extention .MCRO. If you do not already have an MCRO file
for the A2A C172 then just copy and paste the following lines with notepad to a new file
and do a 'Save as....' A2A_C172.MCRO to your modules folder.

[MACROS]
1=L:VisorLeftPercent=SET
2=L:VisorRightPercent=SET

Next we need to assign the axis you want to use in the FSUIPC4 Axis Assignments tab.
The Axis input is sent to a 'user defined' offset in FSUIPC4 that is used to pass
the axis data to the Lua script. I used offset 0x66D0 and the data type is Signed Word.

To be able to set the left and right sun visors independantly I use another offset,
0x66D2, an Unsigned Byte, to hold a number from 0 to 2. The number will be cycled
from 0 to 1 to 2 to 0, etc and enable either the left or right visor to be set by
the single axis assigned above. A vale of '1' will enable setting the left visor.
A value of '2' will enable setting the right visor, and a value of '0' will disable
the axis from changing eiter visor.

To cycle the value in 0x66D2 I assigned the Key Combo of 'Shift + 0' in the FSUIPC4
'Key Presses' menu.

Each press of Shift + 0 will cycle the data to the next value. Also a small Lua
Display will appear for 2 seconds in the upper right of your display showing the
current visor selection each time the key combo is pressed.

The Lua script contains 3 'functions'. The main visor setting function, the
visor selection and a small utiliy function to round the axis data after it is scaled
from range of -16384 to +16383 to 0 to 100% for writing to the L:Vars.

To install, create the MCRO file and place it in your Modules folder.

Start FSX and load the C172 then select FSUIPC from the Add-ons menu.

Select the Axis Assignment tab and select 'Aircraft specific?' in the menu. Add
the additional information as shown in the JPG below:
NOTE that I use Auto Assign letters for my controllers so the Joy# is F and Axis# is S
You will of course see a different pair of data when you move the axis you wish
to assign here.

Image

Next open the FSUIPC 'Key presses' tab and again select 'Aircraft specific?'.
The set the Key Combo of Shift + 0 as shown in the JPG below.

Image

In addition to the Key Combo cycling the data in 0x66D2, each release of the
key combo will cause the Lua script to run, thus no need for any additional
key/button assignments to c ause the script to run.

Here is the Lua script. Copy and paste it in Notepad and 'Save as...' A2A_C172.lua
into your modules folder. Then exit the C172 and FSX and restart.

----------------------------- Lua Script Below --------------------

Code: Select all

 ipc.setdisplay(870, 50, 500, 100)

  function Sun_Visor(control, Visor_in)

  if VisorR_Out_Last == nil then VisorR_Out_Last = 0 end

  if VisorL_Out_Last == nil then VisorL_Out_Last = 0 end

  Visor_In = (round((Visor_in + 16383)/327.67))

    if Visor_In < 0 then Visor_In = 0 end

-- The key combo Shift + 0 selects left or right or no visor by setting offset ox66D2
-- to '1' for LEFT,'2' for RIGHT or '0' for None
-- Each press of Shift + 0 cycles the select from 0, 1 and 2

--  ipc.display("Visor = "..Visor_In, 1)  -- Test display, comment out if not needed

	V_Sel = ipc.readUB(0x66D2) -- Read None\Left\Right select

	if V_Sel == 2 then

      if Visor_In > VisorR_Out_Last + 1.5 or Visor_In < VisorR_Out_Last - 1.5 then

	  ipc.writeLvar("L:VisorRightPercent", Visor_In)

	    VisorR_Out_Last = Visor_In

	  end

	end

	if V_Sel == 1 then

      if Visor_In > VisorL_Out_Last + 1.5 or Visor_In < VisorL_Out_Last - 1.5 then

      ipc.writeLvar("L:VisorLeftPercent", Visor_In)

	    VisorL_Out_Last = Visor_In

	  end

	end

  end

  function Visor_Select(control, Visor_sel)  -- Display the current Visor Selected

    x = "No Visor Selected"

    if Visor_sel == 1 then x = "Left" end

    if Visor_sel == 2 then x = "Right" end

    ipc.display("Visor Selected = "..x, 2)

  end

-- rounds the integer
  function round(num)
	num = tonumber(num)
	if num == nil then return 0 end
    if num >= 0 then return math.floor(num+.5)
    else return math.ceil(num-.5) end
  end

event.offset(0x66D0,"SW","Sun_Visor")

event.offset(0x66D2,"UB","Visor_Select")

------------- End of Lua Script -------------------------

Paul

Image
Last edited by Gypsy Baron on 02 Sep 2017, 10:46, edited 3 times in total.

burns
Airman First Class
Posts: 69
Joined: 14 Jun 2013, 17:39

Re: sun visor control?

Post by burns »

Magnificent!
Wow!
Thanks!

burns
Airman First Class
Posts: 69
Joined: 14 Jun 2013, 17:39

Re: sun visor control?

Post by burns »

How would one go about making each visor a separate control?
I have two pots available and could use one for the left and one for the right.

Gypsy Baron
A2A Master Mechanic
Posts: 3396
Joined: 02 Aug 2008, 17:04
Location: San Francisco

Re: sun visor control?

Post by Gypsy Baron »

burns wrote:How would one go about making each visor a separate control?
I have two pots available and could use one for the left and one for the right.
Hello burns,

I just read this thread again after not looking here since my last post.

It will be quite easy to have your two pots control the two visors. I'll post the changes to my first post in the next day or two. Essentially you would assign the 2nd pot to send data to offset 0x66D4 with the first pot still sending it's data to offset 0x66D0 as shown in the first JPG.

The Lua script will be changed to separate the code for the two L:Variables. The KEY assignment will be maintained but will only function to insure that the Lua script is loaded initially. After that, any change in either of your pots will trigger the script to run.

Paul

Image

burns
Airman First Class
Posts: 69
Joined: 14 Jun 2013, 17:39

Re: sun visor control?

Post by burns »

Fantastic. Looking forward to the script.

Gypsy Baron
A2A Master Mechanic
Posts: 3396
Joined: 02 Aug 2008, 17:04
Location: San Francisco

Re: sun visor control?

Post by Gypsy Baron »

OK, here is the new info. You will just need to make 2 axis assignments in FSUIPC.

The axis for the LEFT visor will send data to offset 0x66D0 (used in the previous version)
The axis for the RIGHT visor sends data to offset 0x66D4
The KEY assignment (Shift+0) remains the same and is just used to initially load the Lua script.

Here are the JPGs for the assignment procedure:

Left visor pot assignment

Image

Right visor pot assignment

Image

Key combo assignment

Image

And the new, modified Lua code. Copy and paste it in Notepad and 'Save as...'C172_Visor.lua
into your modules folder. Then exit the C172 and FSX and restart.

Code: Select all

  ipc.setdisplay(870, 50, 500, 100)


  function Sun_Visor(control, Visor_in)

  if VisorR_Out_Last == nil then VisorR_Out_Last = 0 end

  if VisorL_Out_Last == nil then VisorL_Out_Last = 0 end

  VisorL_in = ipc.readSW(0x66D0)

  VisorR_in = ipc.readSW(0x66D4)

  VisorL_In = (round((VisorL_in + 16383)/327.67))

  VisorR_In = (round((VisorR_in + 16383)/327.67))

    if VisorL_In < 0 then VisorL_In = 0 end

	if VisorR_In < 0 then VisorR_In = 0 end

      if VisorL_In > VisorL_Out_Last + 1.5 or VisorL_In < VisorL_Out_Last - 1.5 then

      ipc.writeLvar("L:VisorLeftPercent", VisorL_In)

	    VisorL_Out_Last = VisorL_In

	  end

      if VisorR_In > VisorR_Out_Last + 1.5 or VisorR_In < VisorR_Out_Last - 1.5 then

	  ipc.writeLvar("L:VisorRightPercent", VisorR_In)

	    VisorR_Out_Last = VisorR_In

	  end

  end

-- rounds the integer
  function round(num)
	num = tonumber(num)
	if num == nil then return 0 end
    if num >= 0 then return math.floor(num+.5)
    else return math.ceil(num-.5) end
  end

event.offset(0x66D0,"SW","Sun_Visor")

event.offset(0x66D4,"SW","Sun_Visor")

The MCRO file entries remain the same.

Paul

Image

new reply

Return to “C172 Trainer”

Who is online

Users browsing this forum: Majestic-12 [Bot] and 12 guests