Jump to content
The simFlight Network Forums

Recommended Posts

Posted

Hello,

I'm using LUA to control the LEDs of several GoFlight modules and everything works great except for one offset: APU!

I have tried 0B51, 0B52, 0B53, 0B54, 0B58 and 0B5C!

event.offset("0B5C", "UB", "APU")

The function APU should set one of the LEDs on.

For whatever reason I can't turn any LED on when the APU is on.

Any idea?

Thanks!

Posted

I'm using LUA to control the LEDs of several GoFlight modules and everything works great except for one offset: APU!

I have tried 0B51, 0B52, 0B53, 0B54, 0B58 and 0B5C!

What version of FS? What version of FSUIPC?

Those offsets certainly work with FSUIPC4 in FSX with the default 737-800. I don't know if they work with anything else. They are just the values SimConnect supplies for the FSX APU.

If you are using an add-on aircraft which doesn't use the inbuilt FSX APU then you'll probably need to look elsewhere.

BTW

event.offset("0B5C", "UB", "APU")

Offset 0B5C is a 32-bit float. Checking only its lowest 8 bits ("UB" == Unsigned Byte) is wrong. If could be zero or anything. Always use the correct type designation for the variable being read. Of the ones you mention only 0B51, 0B52 and 0B53 are "UB".

Regards

Pete

Posted

Pete thanks for the reply. I have the latest version of FSUIPC with FSX.

I will test changing "UB" to "FLT". I'm trying to turn the LED "1" ON of a GoFlight module (GFP8) when the APU is ACTIVE.

I tried 0B52 with no luck. The Push Back works great. I assign the button function using FSUIPC offset-ready-list and turn the LED on using LUA. I wanted to do the same with the APU...

Posted

I will test changing "UB" to "FLT". I'm trying to turn the LED "1" ON of a GoFlight module (GFP8) when the APU is ACTIVE.

I tried 0B52 with no luck. The Push Back works great. I assign the button function using FSUIPC offset-ready-list and turn the LED on using LUA.

Is this with the default 738?

0B5C is not really the correct offset for "APU active". That'll only go non-zero when you atart the APU generator AFTER the APU is running. To detect APU running okay check for 0B54 (FLT) being above 99 (it never quite reaches 100% exactly, 99.99933 is the highest I see here). All the other offsets will then be zero until you switch on the APU generator, after which you'll get both Generator bytes set to 1 and the voltage non-zero.

Here are two pictures showing the relevant offsets displayed by FSInterrogate. The first is with the APU started but the generator off, the second with the generator on as well.

APU_started.jpg

APU_Generating.jpg

It does work (with the 738), so you are doing something wrong.

Regards

Pete

Posted

Hi Pete,

I tested it and I'm still having problems. My code is below. Any suggestions? When I push the button I can see the 0B54 offset changing value using FSInterrogate and the light on the cockpit works, so the button is ok.

As always, thanks for your help.

---------------------------------------------

-- monitor APU status and turn LED on if ON

function APU(offset, value)

model = GFP8

unit = 0

id = 1

gfd.SetBright(model, unit, 15)

if value > 99 then

gfd.SetLight(model, unit, id)

else

gfd.ClearLight(model, unit, id)

end

end

event.offset("0B54", "FLT", "APU")

---------------------------------------------

The Pushback works properly, here is my code:

-- Pushback button GFP8 UNIT 0

function PushBack(offset, value)

model = GFP8

unit = 0

id = 7

gfd.SetBright(model, unit, 15)

if value == 0 then

gfd.SetLight(model, unit, id)

else

gfd.ClearLight(model, unit, id)

end

end

function SetPushBack(model, unit)

gfd.GetValues(model, unit)

if gfd.TestButton(7) then

ipc.writeUB("31F4",0)

else

ipc.writeUB("31F4",3)

end

end

event.offset("31F0", "UB", "PushBack")

event.gfd(GFP8, 0, "SetPushBack")

Posted

I tested it and I'm still having problems. My code is below.

Tried it here. Works fine with the default FSX 738. Here are extracts from a log using FSUIPC 4.82 with 0B54 monitored to the log and Lua tracing enabled before loading your Lua:

This is the loading of the aircraft and starting the Lua, up until the cold/dark aircraft is ready to have the APU started:

********* FSUIPC4, Version 4.82 by Pete Dowson *********
...
7969 E:\FSX\SimObjects\Airplanes\B737_800\Boeing737-800.AIR
...
119485 LUA.0: beginning "E:\FSX\Modules\apu.lua"
119485 LUA.0: E:\FSX\Modules\apu.lua:12
119500 LUA.0: Global: ipcPARAM = 0
119500 LUA.0: E:\FSX\Modules\apu.lua:2
119516 LUA.0: E:\FSX\Modules\apu.lua:14
119532 LUA.0: Waiting for an event in "E:\FSX\Modules\apu.lua"
119532 LUA.0: Offset Change event: calling "APU" in "E:\FSX\Modules\apu.lua"
119532 LUA.0: E:\FSX\Modules\apu.lua:3
119532 LUA.0: Local: offset = 2900
119547 LUA.0: Local: value = 0
119547 LUA.0: E:\FSX\Modules\apu.lua:4
119563 LUA.0: Global: model = 2
119563 LUA.0: E:\FSX\Modules\apu.lua:5
119578 LUA.0: Global: unit = 0
119578 LUA.0: E:\FSX\Modules\apu.lua:6
119594 LUA.0: Global: id = 1
119594 KEYUP: VK=9, Waiting=0
119610 LUA.0: E:\FSX\Modules\apu.lua:7
119610 LUA.0: E:\FSX\Modules\apu.lua:10
119625 LUA.0: E:\FSX\Modules\apu.lua:12
119641 LUA.0: Waiting for an event in "E:\FSX\Modules\apu.lua"
[/CODE]

[size=5][font=arial,helvetica,sans-serif]Now here is the APU spooling up (there's a lot of logging here as you can imagine, so I'll just show the beginning, and ending where the value finally goes over 99.0%:[/font][/size]

[CODE]
145953 Monitor IPC:0B54 (FLT32) = 0.71267867
145953 SimRead: 0B54="APU PCT RPM"
FLT64: 0.712678550207
145953 LUA.0: Offset Change event: calling "APU" in "E:\FSX\Modules\apu.lua"
145953 LUA.0: E:\FSX\Modules\apu.lua:3
145969 LUA.0: Local: value = 0.71267867088318
145969 LUA.0: E:\FSX\Modules\apu.lua:4
145969 Monitor IPC:0B54 (FLT32) = 1.37349093
145969 SimRead: 0B54="APU PCT RPM"
FLT64: 1.37349057081
145985 LUA.0: E:\FSX\Modules\apu.lua:5
145985 LUA.0: E:\FSX\Modules\apu.lua:6
146000 Monitor IPC:0B54 (FLT32) = 2.60532713
146000 LUA.0: E:\FSX\Modules\apu.lua:7
146000 SimRead: 0B54="APU PCT RPM"
FLT64: 2.60532617682
146016 LUA.0: E:\FSX\Modules\apu.lua:10
146032 LUA.0: E:\FSX\Modules\apu.lua:12
...
182094 Monitor IPC:0B54 (FLT32) = 98.96405029
182094 SimRead: 0B54="APU PCT RPM"
FLT64: 98.9640051778
182094 LUA.0: E:\FSX\Modules\apu.lua:5
182110 LUA.0: E:\FSX\Modules\apu.lua:6
182125 LUA.0: E:\FSX\Modules\apu.lua:7
182125 Monitor IPC:0B54 (FLT32) = 98.97804260
182125 SimRead: 0B54="APU PCT RPM"
FLT64: 98.9780432637
182125 LUA.0: E:\FSX\Modules\apu.lua:10
182141 LUA.0: E:\FSX\Modules\apu.lua:12
182157 LUA.0: Offset Change event: calling "APU" in "E:\FSX\Modules\apu.lua"
182157 LUA.0: E:\FSX\Modules\apu.lua:3
182157 Monitor IPC:0B54 (FLT32) = 98.99060822
182157 SimRead: 0B54="APU PCT RPM"
FLT64: 98.9906165059
182157 LUA.0: Local: value = 98.978042602539
182172 LUA.0: E:\FSX\Modules\apu.lua:4
182172 LUA.0: E:\FSX\Modules\apu.lua:5
182188 LUA.0: E:\FSX\Modules\apu.lua:6
182203 LUA.0: E:\FSX\Modules\apu.lua:7
182203 Monitor IPC:0B54 (FLT32) = 99.00544739
182203 SimRead: 0B54="APU PCT RPM"
FLT64: 99.0054480489
182203 LUA.0: E:\FSX\Modules\apu.lua:10
182219 LUA.0: E:\FSX\Modules\apu.lua:12
182235 LUA.0: Offset Change event: calling "APU" in "E:\FSX\Modules\apu.lua"
182235 LUA.0: E:\FSX\Modules\apu.lua:3
182235 Monitor IPC:0B54 (FLT32) = 99.02178955
182235 SimRead: 0B54="APU PCT RPM"
FLT64: 99.0218054708
182235 LUA.0: Local: value = 99.005447387695
182250 LUA.0: E:\FSX\Modules\apu.lua:4
182250 LUA.0: E:\FSX\Modules\apu.lua:5
182266 LUA.0: E:\FSX\Modules\apu.lua:6
182266 Monitor IPC:0B54 (FLT32) = 99.03430939
182266 SimRead: 0B54="APU PCT RPM"
FLT64: 99.0343176779
182282 LUA.0: E:\FSX\Modules\apu.lua:7
182282 LUA.0: E:\FSX\Modules\apu.lua:8
182297 Monitor IPC:0B54 (FLT32) = 99.04635620
182297 LUA.0: E:\FSX\Modules\apu.lua:12[/CODE]

Note that the timing of the Monitor and the calling to the Lua thread is a little skewed so it isn't exactly the same value or time -- okay within a few hundred millisecs though.

Perhaps you should do the same sort of thing, monitor the value and trace your Lua code. You'll see, above, that once the value is seen, in the Lua, as being over 99%, your line 8 is executed as shown by

[CODE] 182282 LUA.0: E:\FSX\Modules\apu.lua:8[/CODE]

I did this without a GF unit attached, but what would worry me about your code is this:

The value you are acting on is changing all the time whilst the APU is starting, and even afterwards. Your function is being called at a rate of about 15-20 times per second all that time. So you are sending "SetBright" and either "SetLight" or "ClearLight" to the GoFlight driver that often. Maybe that doesn't cope? Anyway, it is very ineffiicent. Try a slim line version only sending changes when changes are needed. That's good practice in ALL coding. e.g.:

[CODE]
-- monitor APU status and turn LED on if ON
gfd.SetBright(GFP8, 0, 1)
apuon = false

function APU(offset, value)
if value > 99 and not apuon then
apuon = true
gfd.SetLight(GFP8, 0, 1)
else if value <= 99 and apuon then
apuon = false
gfd.ClearLight(GFP8, 0, 1)
end
end

event.offset("0B54", "FLT", "APU")

[/CODE]

Regards

Pete

Posted

Thanks Pete, I will try it tonight. Regarding the debuggg.do I need to launch the "LUA Debug" and turn on the FSUIPC logging?

The Lua Debug method is really redundant now. I shall be removing it. FSUIPC features a much superior Lua debugging feature "Lua tracing", an entry on the Logging tab. This not only logs the line numbers being executed, but also the variable values, when they change. This is in the current version FSUIPC 4.823, and will be in the next release for FSUIPC3.

If you choose the othr Lua logging option, to log separately, then each Lua program will have its own log. Otherwise all the Lua logging goes to the main FSUIPC4 log file. In this case multiple Lua plug-ins have an ID number, like "Lua:N", with N starting at 0. This helps identify which log entries are for which plug-in. This method of logging is very useful when you have several separate plug-ins interacting with each other, as with projects like LINDA, as you then see the precise sequence of events.

Regards

Pete

Posted

Pete,

Is it better to create single LUA programs and assign them to a button? For example APU.LUA then link it to the button I want to program?

What about ipcready.lua? Is it possible to code all the offset/buttons monitoring inside only that file?

My understanding is that ipcready.lua loads automatically after FSUIPC completes the starting phase...

Posted

Is it better to create single LUA programs and assign them to a button? For example APU.LUA then link it to the button I want to program?

If the plug-in is simply doing some one-off action when you press the button, yes. But that APU function is designed to monitor a condition and reflext it on an indicator, isn't it So it isn't button-instigated and needs to be running in the background all the time. Right? So start it either by a "RunLua" call in ipcReady.lua, or use the [Auto] facilities in the FSUIPC INI file to start it like a macro. The latter method allows you to start different plug-ins for different aircraft or profiles.

My understanding is that ipcready.lua loads automatically after FSUIPC completes the starting phase...

Well, when FS is ready to fly to be more exact. But best to just start off your separate pluginns with "RunLua" calls inside ipcReady.lua -- easier for reconfigring, editing, debugging and so on.

Regards

Pete

Posted

Great, thanks.

One more question...I want to edit my LUA code while FSUIPC is running so I can troubleshoot better. Does the "RELOAD ALL BUTTONS" reload/refresh the LUA scripts inside the Modules folder as well? If not how can I do this?

Posted

One more question...I want to edit my LUA code while FSUIPC is running so I can troubleshoot better. Does the "RELOAD ALL BUTTONS" reload/refresh the LUA scripts inside the Modules folder as well? If not how can I do this?

No, the Reload facilities only reload assignments, so you can edit the INI file without closing FS. To re-execute a running Lua you simply need to restart it. What I do is assign some otherwise unusued key combination, like TAB+1, to "Lua <name of lua>". Then when to press that it will Kill the existing one and start the new one with the same name.

Regards

Pete

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.