programming lvar on axis

The jack of all trades and the world's most popular high performance GA aircraft
nathanmalo
Airman
Posts: 10
Joined: 22 Dec 2014, 09:34

programming lvar on axis

Post by nathanmalo »

hi, everybody.

I'm buiding an home cockpit with this fabulous 182.
But i've a question for you.

Since 2 days, i try to programming the lvars "panellightknob" on an axi of my joystick.

In fact i want to have the panel light intensity on a potentiometre on my panel.

Can you help me to write the macro file or LUA file and say me how to setting FSUIPC with it please?

Best regards.
Nathan

lancealotg
Airman Basic
Posts: 7
Joined: 22 Dec 2014, 11:33

Re: programming lvar on axis

Post by lancealotg »

I use "Linda" for interfacing my MCP to P3d.
There is a module for the c182 that has tons of programming for the different functions.
Here is a portion of the programming
Not sure if it will be of any use?
Good luck

-- ## Light knobs ###############

function A182_PanelLight_show ()
local pl = round((ipc.readLvar('PanelLightKnob')/32)*100)
DspShow ("Panl", pl .. "%")
end

function A182_PanelLight_plus ()

local pl = ipc.readLvar('PanelLightKnob')
if pl < 32 then
pl = pl + 1
end
ipc.writeLvar('PanelLightKnob', pl)
if ipc.get("silence") == 0 then
A182_PanelLight_show ()
end
end

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

Re: programming lvar on axis

Post by Gypsy Baron »

I use a simplistic approach via FSUIPC4 just using 2 switches for OFF and 50% .

First, from my C182.MCRO file, the L:Var you want to use is 66=L:PanelLightKnob=SET

That could also be CYCLIC when using a single switch.

To use an axis using SET, you will need to scale the axis input to cover that range.
A simple Lua script would suffice as is the case using LINDA.

The parameter expected is 0 to 100 for off to full on.

I don't use LINDA but instead prefer to ,use my own INI file edits and Lua scripts due to the
way I implement multiple "modes" for all my switches.

Here is a Lua script I use on the A2A 180 for controlling the
Mixture with an axis. This code could be used for the lighting knob
by simply changing the variable names as needed.

First, the axis is sent to an Offset in FSUIPC4. I use 0x66D0 below. It
is one of the user-defined offsets in the range of p0x66C0 to 0x66FF.

A change of the value in that location triggers the Lua function. The
input is read and scaled and sent to the L:variable. I also display the
value sent (0 to 100) for 1 second if the current value changes more than +/- 0.5 from
the previous value to prevent the display from happening when there is a
bit of 'noise' on the axis.

The 'round' function is included and is needed during the scaling process.

So, for this approach you would add the L:Var to yout C182.MCRO file (or whatever you named it)
and use the SET specification. Assign the axis to output to a user-defined offset,
and save the code below a C182.lua or whatever name you wish. Have this load/run when
the C182 is loaded via the FSUIPC4 "Auto" declaration in the INI file.
========================================================

function Mixture_Lever(control, Lever_in)

if Lever_Out_Last == nil then Lever_Out_Last = 0 end

Lever_Out = (round((Lever_in + 16383)/327.67))

if Lever_Out < 0 then Lever_Out = 0 end

ipc.writeLvar("L:Eng1_MixtureManualLever", Lever_Out)

if Lever_Out > Lever_Out_Last + 0.5 or Lever_Out < Lever_Out_Last - 0.5 then

ipc.display("Mixture = "..Lever_Out, 1) end

Lever_Out_Last = Lever_Out

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","Mixture_Lever")

==================================================

Hope this helps.

Paul

Image

nathanmalo
Airman
Posts: 10
Joined: 22 Dec 2014, 09:34

Re: programming lvar on axis

Post by nathanmalo »

Thanks, i think it's what i search, but i'm really a noob in lua and i don't know where goes this file and how to change the fixture for the panel light knob...
Can you explain me please?

Best regards.

Nathan

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

Re: programming lvar on axis

Post by Gypsy Baron »

nathanmalo wrote:Thanks, i think it's what i search, but i'm really a noob in lua and i don't know where goes this file and how to change the fixture for the panel light knob...
Can you explain me please?

Best regards.

Nathan
I'm busy now but will get back to you later. Lua scripts go into the FSX "Modules" folder where all the
FSUIPC4 things 'live'.

Paul

nathanmalo
Airman
Posts: 10
Joined: 22 Dec 2014, 09:34

Re: programming lvar on axis

Post by nathanmalo »

Gypsy Baron wrote:
nathanmalo wrote:Thanks, i think it's what i search, but i'm really a noob in lua and i don't know where goes this file and how to change the fixture for the panel light knob...
Can you explain me please?

Best regards.

Nathan
I'm busy now but will get back to you later. Lua scripts go into the FSX "Modules" folder where all the
FSUIPC4 things 'live'.

Paul

Ok, thanks!

In fact what i want to do is know how to affect a variable but on an axi and not on a switch, via Fsuip (Proportionally)

If ma axis move 0->100% , parameter of radiolightknob will move 0->32.
how can i do this with LUA?

Best regards.
Nathan

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

Re: programming lvar on axis

Post by Gypsy Baron »

nathanmalo wrote:
Gypsy Baron wrote:
nathanmalo wrote:Thanks, i think it's what i search, but i'm really a noob in lua and i don't know where goes this file and how to change the fixture for the panel light knob...
Can you explain me please?

Best regards.

Nathan
I'm busy now but will get back to you later. Lua scripts go into the FSX "Modules" folder where all the
FSUIPC4 things 'live'.

Paul

Ok, thanks!

In fact what i want to do is know how to affect a variable but on an axi and not on a switch, via Fsuip (Proportionally)

If ma axis move 0->100% , parameter of radiolightknob will move 0->32.
how can i do this with LUA?

Best regards.
Nathan
The script I posted will do that assuming that the axis input is -16384 -> +16383 and the output
desired is 0 -> 100 which would be the full range for the light intensity range.

I'll modify the script later, test it on my 182 and then post that here.

Paul

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

Re: programming lvar on axis

Post by Gypsy Baron »

Let me understand this. What is the range of raw data from your axis as seen in the FSUIPC4 Axis Assignment page?

Is it -16384 to + 16383 or 0 to 100?

Why do you want the radio knob to only go 0 to 32? Full range for that function is 0 to 100.

Paul

EDIT:

OK...I see why you want 0-32 instead of 0 to 100 out.


Here is the script that will take -16384 to +16383 and output 0 to 32 to the Panel Light control

Simply copy and paste this in notepad and save it as C182PanelLt.lua (The name can not exceed 16 charaters,
excluding the .lua extension).

Place the file into your FSX Modules folder.

In the FSUIPC4 Axis assignment tab assign the axis as "Send to FSUIPC Axis", "Offset Word Set". Offset "x66D2"

You will need to define the L:Variable in a MCRO file. If you have one already for the C182 then just add

XX=L:PanelLightKnob=SET where XX is the next line number.

If you do NOT have a C182 MCRO file, create this in notepad:

[MACROS]
1=L:PanelLightKnob=SET

Save that file as "C182.MCRO" into your Modules folder.

In both cases be sure that the extentions "lua" and "MCRO" are correct and that notepad did NOT add "txt" to them!!!

The only thing left to do would be to insure that the Lua script is loaded when you start the C182. This can be
done by placing the following lines in your FSUIPC4.ini file:

[Auto.C182]
1=Lua KillAll
2=Lua C182PanelLt

This will load the file "C182PanelLt.lua" when you load the C182. For insurance and during testing
I also assign an unused switch/button via the FSX Buttons + Switches Control drop-down menu
to "LusKillAll" when pressed and "Lua C182PanelLt" when released. This will reload that script each
time you press the assigned button or switch.

OK...here is the script code:

Code: Select all


-- This script takes an input from an axis via offset x66D2 
-- in the range of -16384 to +16383 and outputs the Panel Light
-- control in the range of 0 to 32 

  function Panel_Light(control, Knob_in)

  if Knob_Out_Last == nil then Knob_Out_Last = 0 end

  Knob_Out = (round((Knob_in + 16383)/1024))

    if Knob_Out < 0 then Knob_Out = 0 end

  ipc.writeLvar("L:PanelLightKnob", Knob_Out)

    if Knob_Out > Knob_Out_Last + 0.5 or Knob_Out < Knob_Out_Last - 0.5 then

    ipc.display("Panel Light = "..Knob_Out, 1) end

  Knob_Out_Last = Knob_Out

  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

-- Assign the Axis to "Offser Word Set" "Offset x66D2"

event.offset(0x66D2,"SW","Panel_Light")

Now, IF your axis raw data range is indeed 0 to 100 as shown in the axis assignment page
then you can mosify the line above:

Knob_Out = (round((Knob_in + 16383)/1024))

to this:

Knob_Out = (round((Knob_in)/3.125))


Paul

Image

nathanmalo
Airman
Posts: 10
Joined: 22 Dec 2014, 09:34

Re: programming lvar on axis

Post by nathanmalo »

Thanks for the answerd.

I dont'k know if i've done something wrong or not, but i've a really strange behaviour with this script...

I can see 3 major problems:

1) The command is not proportional: light intensity is off or on, but not linear with the potentiometer.
2) When i push le physical command assign to the light knob command on my yoke (Potentiometre), the cessna clock (Top left oh the panl) change the value.....
3) When i push le physical command assign to the light knob command on my yoke (Potentiometre), the ampmeter fall down at -60A .....



So, i think i've done something wrong, but i don't know why...

For the 0-32 parameter, i found that on the C182 variables list, above the "panellightknob" var...

Have you the same issue with the code or not?
Your command are they proportional?

Best regards
Nathan

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

Re: programming lvar on axis

Post by Gypsy Baron »

The script works fine for me. As I increase the axis input the panel light increases in intensity.

From your description I can't tell what is happening. Something is not assigned correctly.

When you open the FSUIPC Axis assignment window, what are the values you see
when you increase your your yoke potentiometer from minimum to maximum?
Does it go from -16384 to +16384?? If not, I need to know the minimum and the maximum values.

How are you 'assigning' the hardware potentiometer? It SHOULD be assigned to
send its data to the Offset x66D2 and nowhere else. That offset is what causes
the script to run.

The script sends the scaled data on to the Panel Light Knob via the L:variable.

Paul

nathanmalo
Airman
Posts: 10
Joined: 22 Dec 2014, 09:34

Re: programming lvar on axis

Post by nathanmalo »

I think i switched something....


My potentiometre have the standard range of -16384 to +16384. No problem.

When i assign my potentiometre:

In fsuipc Axis assignment:
i click set ; an move my axis.
I click "sent to FS as normal axis"
and in the list, i select the C182 vars i want to control.


But when i read your post, i think the problem is ir...

" It SHOULD be assigned to
send its data to the Offset x66D2 and nowhere else"


Other question, i can't see the x66D2 on the offset list of fsuipc.
just

Offset: 66C0
Size: 64
Use: Free for general use, for example in button or keys
programming.

It would say 64 offset afet 66C0 are free for general use?

From 66C0 to 66C9
From 66D0 to 66D9
etc until 66i0 to 66i3

Is that?

nathanmalo
Airman
Posts: 10
Joined: 22 Dec 2014, 09:34

Re: programming lvar on axis

Post by nathanmalo »

For free offsets, i've found my answerd on othe post.

Free offsets are:
66C0->66CF (66C0 ;66C1 ; 66C2 ; 66C3 ; 66C4 ; 66c5 ; 66c6 ; 66c7 ; 66c8 ; 66c9 ; 66ca ; 66cb ; 66cc ; 66cd ; 66ce ; 66cf)
66D0->66DF
66E0->66EF
66F0->66FF

They are 16 free by line ; so, 64 offsets for the 4 line.
It's right?

All this offsets can be used freely for our programmations.

Resagrds.

Nathan

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

Re: programming lvar on axis

Post by Gypsy Baron »

nathanmalo wrote:I think i switched something....


My potentiometre have the standard range of -16384 to +16384. No problem.

When i assign my potentiometre:

In fsuipc Axis assignment:
i click set ; an move my axis.
I click "sent to FS as normal axis"
and in the list, i select the C182 vars i want to control.


But when i read your post, i think the problem is ir...

" It SHOULD be assigned to
send its data to the Offset x66D2 and nowhere else"


Other question, i can't see the x66D2 on the offset list of fsuipc.
just

Offset: 66C0
Size: 64
Use: Free for general use, for example in button or keys
programming.

It would say 64 offset afet 66C0 are free for general use?

From 66C0 to 66C9
From 66D0 to 66D9
etc until 66i0 to 66i3

Is that?
Yes, all those offsets from 66C0 to 66FF are free user-defined offsets. I chose 66D2 dor this implementation
as for testing on my system it is not used but I use the offsets below it for other purposes.

You should NOT assign the "Panel Lights" potentiometer the way you did it. Assign it to go to an Offset, x66D4.
You must enter that offset x66D2 in the box labels offset on the left side of the page after you select the
type/size of the data in the boxes above that.

Do NOT assign the potentiometer directly to the L:Variable!!!

On the left side, use "Send to FSUIPC Offset"
In the list below that select "Offset Word Set"
in the box below that enter "x66D2"
Click OK.

Make sure you have entered the INI lines I mentioned to activate the Lua script.

It should work. If you entered the Lua script correctly and it is 'active', when you move the
axis assigned to pasnel lights a Lua Display window should pop up and display the value
of the setting.

I am going to be out for most of the day so I won't be reading the forums until later.

Paul

nathanmalo
Airman
Posts: 10
Joined: 22 Dec 2014, 09:34

Re: programming lvar on axis

Post by nathanmalo »

A big thank to you Paul!

All is done!

Thanks for all


Merry christmas and certainly happy new year!

Nathan

nathanmalo
Airman
Posts: 10
Joined: 22 Dec 2014, 09:34

Re: programming lvar on axis

Post by nathanmalo »

can you just explain me this part of code:

Code: Select all

function Panel_Light(control, Knob_in)
Function: We declare a new function
Panel_Light : function name

but, (control , Knob_in) , what is this and how to find it (with knob_out_last etc)?

new reply

Return to “C182 Skylane”

Who is online

Users browsing this forum: No registered users and 5 guests