ThomasAH Posted November 20, 2011 Report Posted November 20, 2011 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"endspeed = 115200 -- is this the same for all VRI devices?handshake = 0 -- No handshakeminsize = 8maxsize = 8 -- VRI seems to use fixed length blocks of 8 bytesdev = com.open(VRIdevice, speed, handshake)if dev == 0 then ipc.log("Could not open VRIdevice port") ipc.exit()endfunction 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)endfunction 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) endendfunction unitchanged(off, val) setbarodisplay(0x330, ipc.readUW(0x330))endunitchanged(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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now