Jump to content
The simFlight Network Forums

Recommended Posts

Posted

Hi everyone,

I have an add-on that randomly triggers brakes failures in my sim which is really annoying. The only FS controls I found are toggle_left/right_brake_failure which are controls 66311 and 66312. The following simple lua script brakesresetevent.lua  intends to reset the brake-failures when ever they occur randomly. The second script brakesevent.lua (further below) should give me the opportunity to overrule the resetting such that I can sill fail the brakes if I intend to.

brakesresetevent.lua:

ipc.set("leftFailed",1)
ipc.set("rightFailed",1)
local lfail = 0
local rfail = 0

function leftreset()
    lfail = ipc.get("leftFailed")
    if(lfail == 1) then
        ipc.set("leftFailed",0)
        ipc.control(66311)
        ipc.sleep(1000)
        ipc.set("leftFailed",1)
    end
end   

function rightreset()
        rfail = ipc.get("rightFailed")
    if(rfail == 1) then
        ipc.set("rightFailed",0)
        ipc.control(66312)
        ipc.sleep(1000)
        ipc.set("rightFailed",1)
    end
end

event.control(66311, "leftreset")
event.control(66312, "rightreset")

The problem is that although I try to prevent recursive triggering of the event with the global vars leftFailed and rightFailed this seems to happen. In general lua there is the possibility to temporarily unregister and reregister an event. Is this also possible in FSUIPC?

brakesevent.lua:
ipc.set("LeftFailed",0)
ipc.set("RightFailed",0)
ipc.sleep(200)
ipc.control(66311,0)
ipc.sleep(100)
ipc.control(66312, 0)
ipc.sleep(200)
ipc.set("LeftFailed",1)
ipc.set("RightFailed",1)
ipc.runlua("brakesresetevent")

The idea is the following: The first script runs from the beginning of the sim session (Run by FSUIPC.cfg). Whenever I hit the key combo, the first script gets killed by KillLua and the second script is started when releasing the key combo. That's why I restart the continuously running first script at the end of the second script by ipc.runlua. However, whatever I try I get recursive callbacks since the brakes flicker wildly from on to off. I'd appreciate if anybody could help me see my mistake.

regards draci

 

Posted
On 1/26/2024 at 11:42 PM, draci said:

In general lua there is the possibility to temporarily unregister and reregister an event. Is this also possible in FSUIPC?

You can use event.cancel to remove all event tracking on the same function.

On 1/26/2024 at 11:42 PM, draci said:

The idea is the following: The first script runs from the beginning of the sim session (Run by FSUIPC.cfg). Whenever I hit the key combo, the first script gets killed by KillLua and the second script is started when releasing the key combo. That's why I restart the continuously running first script at the end of the second script by ipc.runlua. However, whatever I try I get recursive callbacks since the brakes flicker wildly from on to off. I'd appreciate if anybody could help me see my mistake.

This seems overly complicated. Why not just use one script that has a flag (or two) which determine if the brakes should fail or not. You can then set/clear these flags by using an ipcParam variable, and using an event.param function in your script, and assigning with LuaValue to tell the script when to set and clear the brakes failure flags.

John

  • 2 weeks later...
Posted

Ok, I have tried to reset the P3D brakes failure via .lua scripts for weeks without success. Here's what my main problems are:
 

1. Writing to the offset 0B63 with ipc.setbitsUB and ipc.clearbitsUB doesn't work. The failure in the PMDG->Vehicles->Failure Menu persists for Left and Right Brake.

2. Toggling FS-controls 66310-66312 via ipc.control(6631x) in order to reset randomly occurring failures doesn't work either or seems to end up in infinite recursions since event.control(6631x,"callback") is called everytime the callback-function calls ipc.control(6631x). Cancelling the recursion via event.cancel("callback") does not help.

3. The FSUIPC Fs-controls "Toggle Left/Righ/All Brakes Failure" surprsingly DO work to trigger a failure, however, repeated use doesn't clear the failure.

However, since there are Add-Ons like FS-Flight Control which can both trigger and reset failures, there must be a way to control the failure state somehow. My lua scripts are correct and FSUIPC Debugging/Tracing for them doesn't reveal any issues with my code, the logic runs as intended. What else can I try?

Posted
13 hours ago, draci said:

1. Writing to the offset 0B63 with ipc.setbitsUB and ipc.clearbitsUB doesn't work. The failure in the PMDG->Vehicles->Failure Menu persists for Left and Right Brake.

Try logging offset 0B63 (as U8 in Hex) to see if this offset is being used. Does it update correctly when using the PMDG->Vehicles->Failure Menu? If you also log events, what events do you see? When your lua script sets/clears the bits in this offset, do you see the same values and events? As you are using a PMDG aircraft (which one?), it may not be responding to standard FS controls.

13 hours ago, draci said:

2. Toggling FS-controls 66310-66312 via ipc.control(6631x) in order to reset randomly occurring failures doesn't work either or seems to end up in infinite recursions since event.control(6631x,"callback") is called everytime the callback-function calls ipc.control(6631x). Cancelling the recursion via event.cancel("callback") does not help.

Again, use logging. If you are sending the same control in an event callback that is handling the control, then you will get into an infinite recursive loop. Maybe check the event parameter - is this different between a toggle on and a toggle off (some toggle controls do use a parameter)? If so, you can use that to distinguish between toggle on and toggle off, and only send the control for one parameter. Otherwise, try using event.offset instead, and again only send the required control when needed.

13 hours ago, draci said:

3. The FSUIPC Fs-controls "Toggle Left/Righ/All Brakes Failure" surprsingly DO work to trigger a failure, however, repeated use doesn't clear the failure.

What events do you see when you use the menu to toggle failures on and off? Check if a parameter is needed.

If you need further help, please show me your lua script, and your ini and log files, the latter with logging for Events activated as well as logging for offset 0B63, and maybe also lua plugin logging. One log file should show you toggling and clearing the brake failure via the PMDG menu (without your lua running), and another log file showing what you are trying to achieve with your lua script running.

  • 3 weeks later...
Posted

Wrote a little simconnect client to implement the above functionality. Works without any problems, no recursive calls at all, brakes failures efficiently blocked, me a happy camper. 🙂

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.