flybird141

Encoder Speed Input, Leo Bodnar BU0836X

Recommended Posts

Posted (edited)

I just built a MCP and have everything working.  

I would like to know if there is a solution to speed up the increase in Altitude and/or similar with a code in LUA or some other way.

 

If I turn the dial faster it will increase the numbers faster?

 

Any help would be highly appreciated! 

Edited by flybird141

Share this post


Link to post
Share on other sites
Help AVSIM continue to serve you!
Please donate today!

It's a very good question. Been looking for a way for years. I know it's been done in Xplane with lua scripts but I've not found anything for FS.

Share this post


Link to post
Share on other sites

LINDA relies on single pulses (button presses) + or - to action the various rotates (knobs) on the VRi MCPs. The panels send a single ++ or - - pulse when the knob is moved faster than normal. This is 'hardwired' into the MCPs firmware and handled in the LINDA GUI .exe and only the slow/fast instruction sent to LUA to be actioned.

If your MCP only outputs a single pulse then LINDA will not offer you a faster reaction. All device inputs are actioned in a queue in sequence as a series of pushes and releases. If the 'button' remains pressed (not released) the command is repeated. However, it is not possible for LINDA to determine how fast the knob is being turned.

  • Like 1

Share this post


Link to post
Share on other sites

Thanks for your explanation. Just curious how its accomplished in X Plane using lua? Because of Xplanes dataRef?

 

dataref("TIME", "sim/time/total_running_time_sec")

--How many degrees should the OBS jump each time if your spinning fast?
local OBSFastDegrees = 12
local OBSStandardDegrees=1
--How many spins per second (or button presses per second) is considered FAST?
local OBSFastTurnsPerSecond = 3
local TresholdTime=0.4

--You shouldnt need to change anything below-----------------------------------

--OBS1TurnTimes is used for both OBS1 and OBS2 to store times since each turn
OBS1TurnTimes = {}
OBS1NumberUpTurns = 1
OBS1NumberDownTurns = 1


local i = 1

for i = 1, OBSFastTurnsPerSecond do
    OBS1TurnTimes=1
end


function OBS1Increment()
local obs
obs=get("sim/cockpit2/radios/actuators/nav1_obs_deg_mag_pilot")
OBS1NumberDownTurns = 1
local TimeNow = TIME
OBS1TurnTimes[OBS1NumberUpTurns] = TimeNow

local i = 1
local ItsFast = 1

for i = 1, OBSFastTurnsPerSecond do

    if (OBS1TurnTimes + TresholdTime >= TimeNow) and (ItsFast == 1) then
        ItsFast = 1
    else
        ItsFast = 0
    end
end

OBS1NumberUpTurns = OBS1NumberUpTurns + 1
if OBS1NumberUpTurns  > OBSFastTurnsPerSecond then
    OBS1NumberUpTurns = 1
end

if ItsFast == 1 then
obs = obs  + OBSFastDegrees
else
obs  = obs  + OBSStandardDegrees
end
set("sim/cockpit2/radios/actuators/nav1_obs_deg_mag_pilot", obs%360)
end

function OBS1Decrement()
local obs
obs=get("sim/cockpit2/radios/actuators/nav1_obs_deg_mag_pilot")
OBS1NumberUpTurns = 1
local TimeNow = TIME
OBS1TurnTimes[OBS1NumberDownTurns] = TimeNow

local i = 1
local ItsFast = 1

for i = 1, OBSFastTurnsPerSecond do

    if (OBS1TurnTimes + TresholdTime >= TimeNow) and (ItsFast == 1) then
        ItsFast = 1
    else
        ItsFast = 0
    end
end

OBS1NumberDownTurns = OBS1NumberDownTurns + 1
if OBS1NumberDownTurns  > OBSFastTurnsPerSecond then
    OBS1NumberDownTurns = 1
end

if ItsFast == 1 then
obs = obs  - OBSFastDegrees
else
obs  = obs  - OBSStandardDegrees
end
set("sim/cockpit2/radios/actuators/nav1_obs_deg_mag_pilot", obs%360)


end

create_command("FlyWithLua/testing/increase_OBS1","This command increases the OBS1 value.","OBS1Increment()", " ", " ")
create_command("FlyWithLua/testing/decrease_OBS1","This command decreases the OBS1 value.","OBS1Decrement()", " ", " ")

Share this post


Link to post
Share on other sites

Thank you Adrian. That will give you and others a good starting point for your programming. I shall not be taking this any further. 

  • Like 1

Share this post


Link to post
Share on other sites
Posted (edited)

 

Here is the code that got it working thanks to my son:)

Open up the PMDG 777 in the Linda airplane editor. This should work with all planes though.

 

Enter this starting with line 27... or near the top of your file.

lastUsed = 0
----------------------------------------------------------------
----------------------------------------------------------------

function incrementFastOrSlow ()
    local inc = 1
    local now = ipc.elapsedtime()

    if now <= lastUsed + 1000 then
        inc = 5
    end
    lastUsed = ipc.elapsedtime()
    return inc
end

 

And then set Linda to Incfast or decfast with the encoder functions you you want to use this with.

Update both incfast and decfast lines of code to call incrementFastOrSlow()

 

example before: 

function PMDG_AP_ALT_incfast ()
    local i
    for i = 1, 5 do ipc.control(71882, 256) end
    PMDG_AP_ALT_show ()
end

Example after:

function PMDG_AP_ALT_incfast ()
    local i
    for i = 1, incrementFastOrSlow() do ipc.control(71882, 256) end
    PMDG_AP_ALT_show ()
end

Edited by flybird141

Share this post


Link to post
Share on other sites
Posted (edited)

Thanks to you and your son. It works. Ive notice the time to switch from increments  of 5 to 1 is a little long and jumps around alot, not bad but not knowing linda scripts that well, what does the number 1000 in (if now <= lastUsed + 1000 then) correspond to? Thx

Edited by Adrian123

Share this post


Link to post
Share on other sites
Posted (edited)

It's (1000) milliseconds...= one second. You can change it. 500 is a half second 250 quarter and so on.  You can adjust to your needs can also be based on the encoder you are using so may need to be played with.

 

 

Edited by flybird141

Share this post


Link to post
Share on other sites

Thanks been looking for years. Works remarkably well!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now