Jump to content
The simFlight Network Forums

VRI_SetBaro.lua for M-Panel that respects FSX unit setting


ThomasAH

Recommended Posts

Hi!

I just modified VRI_SetBaro.lua from "Example LUA plugins.zip" to use the unit setting in the general options of FSX instead of Lua flag 0 and thought it would be nice to share it.

Unrelated changes (yes, I know that one should not mix changes, but maybe you want them, too :)) are:

- replaced tabs with 2 spaces (otherwise existing indentation would be wrong)

- set my VRIdriver/VRIdevice ports when testing

Regards,

Thomas


-- VRInsight example: displays Inches or Millibars, by Pete Dowson, March 2010
-- adjusted to respect unit setting at offset 0C18, by Thomas Arendsen Hein, November 2011
-- Needs these filters:
-- WrFilter.1=BAR?
-- RdFilter.1=BAR?+

if VRImodel == nil then
-- Set known ports if testing with Lua not loaded automatically
VRIdriver = "COM6"
VRIdevice = "COM5"
end

speed = 115200 -- is this the same for all VRI devices?
handshake = 0 -- No handshake
minsize = 8
maxsize = 8 -- VRI seems to use fixed length blocks of 8 bytes

dev = com.open(VRIdevice, speed, handshake)

if dev == 0 then
ipc.log("Could not open VRIdevice port")
ipc.exit()
end

function setbarodisplay(off, val)
-- val is BARO setting in 16ths of millibar
if ipc.readUW(0xC18) > 0 then
-- need whole number of millibars
val = (val + 8) / 16 -- Note rounding by addition of 8
else
-- need to convert to 100ths of inch
val = ((val * 2992) / (1013.2 * 16)) + 0.5 -- note rounding
end
str = string.format("BAR%04d", val)
com.write(dev, str, 8)
end

function setbarovalue(handle, str)
-- need to check only for BARnnnn+/- and send correct millibars x 16 to FS
baro = tonumber(string.match(str, "BAR(%d%d%d%d)"))
if baro ~= nil then
if ipc.readUW(0xC18) > 0 then
-- metric, using millibars
baro = baro * 16 -- FS units are 16ths
else
-- using inches
baro = ((baro * 1013.2 * 16) / 2992) + 0.5 -- note rounding
end
ipc.writeUW(0x330, baro)
end

end

function unitchanged(off, val)
setbarodisplay(0x330, ipc.readUW(0x330))
end

unitchanged(nil, nil)

event.offset(0x330, "UW", "setbarodisplay")
event.offset(0xC18, "UW", "unitchanged")
event.VRIread(dev, "setbarovalue")
[/CODE]

Same file as attachment for your convenience: VRI_SetBaro.lua.txt

Link to comment
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
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.