The A2A Simulations Community

"Come share your passion for flight"
It is currently Tue Dec 12, 2017 2:52 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 19 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: sun visor control?
PostPosted: Mon Aug 07, 2017 12:44 pm 
Offline
Airman First Class

Joined: Fri Jun 14, 2013 5:39 pm
Posts: 52
Is there a way to assign it to a button or axis? It would be convenient while in VR


Top
 Profile  
 
 Post subject: Re: sun visor control?
PostPosted: Tue Aug 08, 2017 4:44 am 
Offline
Chief Master Sergeant
User avatar

Joined: Fri Jun 06, 2014 1:06 pm
Posts: 5194
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


Top
 Profile  
 
 Post subject: Re: sun visor control?
PostPosted: Tue Aug 08, 2017 8:46 am 
Offline
Airman First Class

Joined: Fri Jun 14, 2013 5:39 pm
Posts: 52
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?


Top
 Profile  
 
 Post subject: Re: sun visor control?
PostPosted: Tue Aug 08, 2017 3:06 pm 
Offline
Chief Master Sergeant
User avatar

Joined: Fri Jun 06, 2014 1:06 pm
Posts: 5194
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


Top
 Profile  
 
 Post subject: Re: sun visor control?
PostPosted: Tue Aug 08, 2017 3:14 pm 
Online
Master Sergeant

Joined: Tue Nov 05, 2013 10:48 am
Posts: 1160
Location: Oksbøl, Denmark
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

Accu-Sim aircraft in my hangar:
C172, C182, P51 Civ, P51 Mil, B17, Spitfire, P47, B377 COTS, J3 Cub, T6, Connie


Top
 Profile  
 
 Post subject: Re: sun visor control?
PostPosted: Tue Aug 08, 2017 3:15 pm 
Offline
Airman First Class

Joined: Fri Jun 14, 2013 5:39 pm
Posts: 52
Linda doesn't do axis, only buttons


Top
 Profile  
 
 Post subject: Re: sun visor control?
PostPosted: Tue Aug 08, 2017 3:17 pm 
Online
Master Sergeant

Joined: Tue Nov 05, 2013 10:48 am
Posts: 1160
Location: Oksbøl, Denmark
I just sent Gypsy a heads up on a PM.

_________________
Kind Regards
Tomas

Accu-Sim aircraft in my hangar:
C172, C182, P51 Civ, P51 Mil, B17, Spitfire, P47, B377 COTS, J3 Cub, T6, Connie


Top
 Profile  
 
 Post subject: Re: sun visor control?
PostPosted: Tue Aug 08, 2017 3:35 pm 
Offline
A2A Master Mechanic
User avatar

Joined: Sat Aug 02, 2008 5:04 pm
Posts: 3135
Location: San Francisco
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 Fri Sep 01, 2017 11:07 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: sun visor control?
PostPosted: Tue Aug 08, 2017 3:49 pm 
Offline
Chief Master Sergeant
User avatar

Joined: Fri Jun 06, 2014 1:06 pm
Posts: 5194
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


Top
 Profile  
 
 Post subject: Re: sun visor control?
PostPosted: Thu Aug 10, 2017 1:36 pm 
Offline
A2A Master Mechanic
User avatar

Joined: Sat Aug 02, 2008 5:04 pm
Posts: 3135
Location: San Francisco
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:
 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 Sat Sep 02, 2017 10:46 am, edited 3 times in total.

Top
 Profile  
 
 Post subject: Re: sun visor control?
PostPosted: Thu Aug 10, 2017 4:01 pm 
Offline
Airman First Class

Joined: Fri Jun 14, 2013 5:39 pm
Posts: 52
Magnificent!
Wow!
Thanks!


Top
 Profile  
 
 Post subject: Re: sun visor control?
PostPosted: Fri Aug 25, 2017 1:58 pm 
Offline
Airman First Class

Joined: Fri Jun 14, 2013 5:39 pm
Posts: 52
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.


Top
 Profile  
 
 Post subject: Re: sun visor control?
PostPosted: Fri Sep 01, 2017 11:17 pm 
Offline
A2A Master Mechanic
User avatar

Joined: Sat Aug 02, 2008 5:04 pm
Posts: 3135
Location: San Francisco
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


Top
 Profile  
 
 Post subject: Re: sun visor control?
PostPosted: Sat Sep 02, 2017 8:43 am 
Offline
Airman First Class

Joined: Fri Jun 14, 2013 5:39 pm
Posts: 52
Fantastic. Looking forward to the script.


Top
 Profile  
 
 Post subject: Re: sun visor control?
PostPosted: Sat Sep 02, 2017 10:41 am 
Offline
A2A Master Mechanic
User avatar

Joined: Sat Aug 02, 2008 5:04 pm
Posts: 3135
Location: San Francisco
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:
  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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 19 posts ]  Go to page 1, 2  Next

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group