Jump to content
The simFlight Network Forums

If -> then in FSUIPC.ini possible?


Recommended Posts

Hello,

I' m a new owner of FSUIPC and very inexperienced in programming.

Is it possible to program in the FSUIPC.INI like following?

If offset 078C = 1 then offset 6DF1 = 0 else offset 6DF2 = 0

How must the code look like.

Thanks for help in advance.

regrads Fritz

Link to comment
Share on other sites

Is it possible to program in the FSUIPC.INI like following?

If offset 078C = 1 then offset 6DF1 = 0 else offset 6DF2 = 0

No, not in the INI file. That's the file where your settings (normally made in the FSUIPC options dialogue, in FS flight mode) are saved. True, there are some conditional facilities for button actions which can be performed by INI editing, but in general it is what it says, a configuration or INItialisation file.

To program things like you are asking you use the Lua plug-in facilities. Please see the package about this which is installed with FSUIPC. For full information about Lua you would need to refer to its own website.

Regards

Pete

Link to comment
Share on other sites

...To program things like you are asking you use the Lua plug-in facilities. Please see the package about this which is installed with FSUIPC. For full information about Lua you would need to refer to its own website.

I was looking at their website (http://www.lua.org/). Load an editor and was looking for examples of programm code that does this.

Found nothing suitable. It doesen't makes it easier for me. I would be pleased if you have an example for me.

Regards

Fritz

Link to comment
Share on other sites

Load an editor and was looking for examples of programm code that does this.

Found nothing suitable. It doesen't makes it easier for me. I would be pleased if you have an example for me.

Have you looked at any of the many examples I provide with FSUIPC? (In the "example Lua plugins" ZIP).

Anyway, what you want isn't exactly complex as it only uses two of the FSUIPC library functions -- reading and writing offsets. There are examples of that, and of using "ifelse" statements. Did you not find any of them?

If offset 078C = 1 then offset 6DF1 = 0 else offset 6DF2 = 0

You don't say what size of offsets these are, but 078C is a DWORD (4 bytes, or 32 bits). Assuming your other two are single bytes then you do something like

if ipc.readUD(0x078C) == 1 then
   ipc.writeUB(0x6DF1, 0)
else
   ipc.writeUB(0x6DF2, 0)
end

If you want this running all the time rather than being executed by pressing a button or key then the easiest way is to make it loop:

while 1 do
   if ipc.readUD(0x078C) == 1 then
      ipc.writeUB(0x6DF1, 0)
   else
      ipc.writeUB(0x6DF2, 0)
   end
   ipc.sleep(250)
end

and save this into the FS modules folder as "ipcReady.lua" so that FSUIPC starts it running as soon as FS is "ready to fly".

The "ipc.sleep(250)" is there to stop the program hogging more of the processor than it needs. The delay is in milliseconds, so that makes it check 4 times a second. You can of course adjust that as needed.

Regards

Pete

Link to comment
Share on other sites

Thanks for the LUA code - my FS accepted it right away. However, it's not completely working yet. What I want to do is simulate Side Stick Priority in the A320.

This is my FSUIPC.ini:

ButtonRepeat=20,00
0=P0,2,Cx010007C8,x00		P0 = Cpt. side Autopilot Master off
1=P0,2,Cx010007BC,x00		Autopilot heading lock off is required to switch off the autopilot light (my FCU is from CP Flight, with Wilco Airbus module)
2=P0,2,Cx01006DF1,x01		Offset for Cpt. priority + FO red arrow
3=P1,2,Cx010007C8,x00		P1 = FO side Autopilot Master off
4=P1,2,Cx010007BC,x00		Autopilot heading lock off is required to switch off the autopilot light
5=P1,2,Cx01006DF2,x01		Offset for FO priority + Cpt. red arrow

Unfortunately I can't assing an offset to the autopilot button in the CP Flight FCU. Therefore I need to query offset 07BC. It already works on the Cpt. side but on the FO side, offset 6DF2 is not set to value '1'.

Another problem occurs when FO priority is turned on with Cpt. priority already being active. In that case, 6DF1 should be set to value '0' and 6DF2 value '1' and vice versa.

I'd be really greatful if you could help me once more!

Regards,

Fritz

Link to comment
Share on other sites

Thanks for the LUA code - my FS accepted it right away. However, it's not completely working yet. What I want to do is simulate Side Stick Priority in the A320.

Sorry, i don't really know what that means.

This is my FSUIPC.ini:

Offsets 07C8 and 07BC are more easily set to zero by the normal FS controls "Autopilot off" and "AP hdg hold off". Offsets 6DF1 and 6DF2 are assigned to FS Communicator. I don't know what it or you are using them for, so the INI file coding makes little sense to me I'm afraif.

Unfortunately I can't assing an offset to the autopilot button in the CP Flight FCU. Therefore I need to query offset 07BC.

But 07BC is the standard FS autopilot master switch and is operated equally by standard FS controls.

It already works on the Cpt. side but on the FO side, offset 6DF2 is not set to value '1'.

Another problem occurs when FO priority is turned on with Cpt. priority already being active. In that case, 6DF1 should be set to value '0' and 6DF2 value '1' and vice versa.

I'd be really greatful if you could help me once more!

Sorry, but I don't understand any of that. If you can set down the logic of what you want to do, then converting it into a Lua program would be easy. Programming is merely logic. but you need to know what to do first.

Regards

Pete

Link to comment
Share on other sites

Offset 6DF1 and 6DF2 I got from here http://pd-datentechnik.de/A320/pdf/Dualontrol.pdf.

I had assumed that they are free Offsets. I modified the fsuipc.ini and ipcReady.lua once again.

I think I'm very close to the solution but I produce an endless lop when I turn the autopilot on again.

fsuipc.ini

[Buttons.Feelthere Airbus A320-210]
ButtonRepeat=20,00
0=P0,2,Cx01006DF1,x01
1=P1,2,Cx01006DF2,x01

ipcReady.lua

-- Sidestick Prioritiy Airbus A320
 while 1 do 
 -- Sidestick Prioritiy FO
  if ipc.readUB(0x6DF2) == 1 then
      ipc.writeUD(0x07BC, 0)
      ipc.writeUD(0x07C8, 0)
      ipc.writeUB(0x6DF1, 0)  
   end
    -- Sidestick Prioritiy CPT
    if ipc.readUB(0x6DF1) == 1 then
      ipc.writeUD(0x07BC, 0)
      ipc.writeUD(0x07C8, 0)
      ipc.writeUB(0x6DF2, 0)  
   end
      -- Sidestick Prioritiy light CPT/FO off when Autopilot heading lock is on
    if ipc.readUD(0x07C8) == 1 then
      ipc.writeUB(0x6DF1, 0)
      ipc.writeUB(0x6DF2, 0)
   end
   ipc.sleep(250)
end

I use my own Airbus Homecockpit and I have the FCU and EFIS from CP Flight. I also use the Wilco Airbus in FSX. For usinge the FCU with the Wilco Airbus, I had to buy an extra module, because the Wilco Airbus works with many internal variables for which there is no standard offsets compatible. With FSInterrogate I found out which offstes I have to set that the autopilot (07BC) is turned off and the AP controllight in the FCU (07C8) extinguish. I hope it was a bit understandable why it is not so easy.

Regards

Fritz

Link to comment
Share on other sites

Offset 6DF1 and 6DF2 I got from here http://pd-datentechnik.de/A320/pdf/Dualontrol.pdf.

I had assumed that they are free Offsets.

No, they are assigned to FS Communicator, but I suppose it doesn't matter if you don't use that and don't intend to distribute your Lua programs. The area reserved for general use by anyone is 66C0 to 66FF.

I think I'm very close to the solution but I produce an endless lop when I turn the autopilot on again.

What is this "endless loop" doing?

Why don't you use the FSUIPC logging facilities to see what is going on? You can log Button activity and its results, you can monitor offset 6DF1 and 6DF2 as type "UB" on the right-hand side of the Logging tab, and you can add "ipc.log" entries to your Lua file, temporarily, to log what they are doing.

Debugging using logging is always going to be easier and less error prone than trying to follow someone's logic by looking at lines of code. I look at what you are doing and I still don't understand it at all.

For usinge the FCU with the Wilco Airbus, I had to buy an extra module, because the Wilco Airbus works with many internal variables for which there is no standard offsets compatible. With FSInterrogate I found out which offstes I have to set that the autopilot (07BC) is turned off and the AP controllight in the FCU (07C8) extinguish.

Offsets 07C8 and 07BC are standard FS offsets operated by standard FS controls, as I already pointed out. I don't see why you had to use FSInterrogate for those when they are so well known and easily handled.

I hope it was a bit understandable why it is not so easy.

It is far from easy for me, I'm afraid, because I still don't understand what you are trying to do. Sorry.

Regards

Pete

Link to comment
Share on other sites

I'm trying to solve the problem all day. I'm sorry but I don't know how I could explain it better.

Here is an excerpt of the FSUIPC4.log. It seems that the loop runs endlessly when I press the Joy button.

221037 WRITElua 6DF1,   1 bytes: 00                                               .
   221069 WRITElua 6DF2,   1 bytes: 00                                               .
   221147 WRITElua 6DF1,   1 bytes: 00                                               .
   221178 WRITElua 6DF2,   1 bytes: 00                                               .
   221256 WRITElua 6DF1,   1 bytes: 00                                               .
   221287 WRITElua 6DF2,   1 bytes: 00                                               .
   221349 WRITElua 6DF1,   1 bytes: 00                                               .
   221381 WRITElua 6DF2,   1 bytes: 00                                               .
   221443 WRITElua 6DF1,   1 bytes: 00                                               .
   221474 WRITElua 6DF2,   1 bytes: 00                                               .
   221537 WRITElua 6DF1,   1 bytes: 00                                               .
   221583 WRITElua 6DF2,   1 bytes: 00                                               .
   221646 WRITElua 6DF1,   1 bytes: 00                                               .
   221693 WRITElua 6DF2,   1 bytes: 00                                               .
   221771 WRITElua 6DF1,   1 bytes: 00                                               .
   221802 WRITElua 6DF2,   1 bytes: 00                                               .
   221880 WRITElua 6DF1,   1 bytes: 00                                               .
   221911 WRITElua 6DF2,   1 bytes: 00                                               .
   221989 WRITElua 07BC,   4 bytes: 00 00 00 00                                      ....  <== after pushed Joy Button P0,2
   222036 WRITElua 07C8,   4 bytes: 00 00 00 00                                      ....
   222067 WRITElua 6DF2,   1 bytes: 00                                               .
   222145 WRITElua 07BC,   4 bytes: 00 00 00 00                                      ....
   222176 WRITElua 07C8,   4 bytes: 00 00 00 00                                      ....
   222207 WRITElua 6DF2,   1 bytes: 00                                               .
   222270 WRITElua 07BC,   4 bytes: 00 00 00 00                                      ....
   222317 WRITElua 07C8,   4 bytes: 00 00 00 00                                      ....
   222348 WRITElua 6DF2,   1 bytes: 00                                               .
   222441 WRITElua 07BC,   4 bytes: 00 00 00 00                                      ....
   222473 WRITElua 07C8,   4 bytes: 00 00 00 00                                      ....
   222519 WRITElua 6DF2,   1 bytes: 00                                               .
   222566 WRITElua 07BC,   4 bytes: 00 00 00 00                                      ....
   222613 WRITElua 07C8,   4 bytes: 00 00 00 00                                      ....
   222660 WRITElua 6DF2,   1 bytes: 00                                               .
   222738 WRITElua 07BC,   4 bytes: 00 00 00 00                                      ....
   222769 WRITElua 07C8,   4 bytes: 00 00 00 00                                      ....
   222785 WRITElua 6DF2,   1 bytes: 00                                               .
   222878 WRITElua 07BC,   4 bytes: 00 00 00 00                                      ....
   222909 WRITElua 07C8,   4 bytes: 00 00 00 00        

How can I achieve that the loop runs only once when the condition is met? I guess the solution would be a short LUA command that I'm not aware of yet due to my very limited LUA knowledge.

Link to comment
Share on other sites

I'm trying to solve the problem all day. I'm sorry but I don't know how I could explain it better.

Here is an except of the FSUIPC4.log. It seems that the loop runs endlessly when I press the Joy button.

The Lua program was designed to run in its loop all of the time. That's why we put in the 250 millisecond delay. You wanted to write to some offset(s) all the time some offsets were set to 1. Is this not what you wanted?

How can I achieve that the loop runs only once when the condition is met?

What condition? You have three conditions:

if ipc.readUB(0x6DF2) == 1 then

if ipc.readUB(0x6DF1) == 1 then

and

if ipc.readUD(0x07C8) == 1 then

While any of those condtiions are met, the associated code is executed. Isn't that obvious at all?

I guess the solution would be a short LUA command that I'm not aware of yet due to my very limited LUA knowledge.

I don't think so. I think the solution is for you to work out the logic of what you want to do, which you have so far not manasged to explain to me. If you cannot explain the logic to someone you cannot really successfully program it in any language, as all a programming language does is formalise the logic.

If you only want some action to occur when something CHANGES, rather than when is simply "IS" in a certain state, you have to save its state and only act when you read it again and find it is different. You can use the FSUIPC Lua "event" library facilities for that, which is efficient, but I fear that might be too advanced for you to consider. So try simply doing something like:

MemoryOfX = -1 -- Make sure seems to change first time

while 1 do
   x = 
   if x ~= MemoryOfX then

       MemoryOfX = x -- store new value of x
   end
...

If you want to try Events there are examples in the package supplied with FSUIPC.

Pete

Link to comment
Share on other sites

Thank you for your example. As I said with my very limited LUA knowledge i do not get this to working.

I hope that I do not overstrain your patience. I want to try to explain the logic.

Autopilot is on. If Cpt Sidestick priority button pressed then

1. the Autopilot should set off (07BC = 0)

2. the Autopilot light should set off (078C = 0)

3. the Priority light at the Cpt Side and the red arrow on the FO side illuminates (6DF1 = 1).

4. the Priority light at the FO Side and the red arrow on the Cpt side set off (6DF2 = 0).

If then the Autopilot turned on again (with the button at the FCU)

1. the Autopilot should set on (07BC = 1)

2. the Autopilot light should set on (078C = 1)

3. the Priority light at the Cpt Side and the red arrow on the FO side set off (6DF1 = 0).

4. the Priority light at the FO Side and the red arrow on the Cpt side set off (6DF2 = 0).

Autopilot is on. If FO Sidestick priority button pressed then

1. the Autopilot should set off (07BC = 0)

2. the Autopilot light should set off (078C = 0)

3. the Priority light at the FO Side and the red arrow on the Cpt side illuminates (6DF2 = 1).

4. the Priority light at the Cpt Side and the red arrow on the FO side set off (6DF1 = 0).

Cpt has the priority and if FO Sidestick priority button pressed then

1. the Autopilot is still set off (07BC = 0)

2. the Autopilot light is still set off (078C = 0)

3. the Priority light at the Cpt Side and the red arrow on the FO side set off (6DF1 = 0).

4. the Priority light at the FO Side and the red arrow on the Cpt side illuminates (6DF2 = 1).

FO has the priority and if Cpt Sidestick priority button pressed then

1. the Autopilot is still set off (07BC = 0)

2. the Autopilot light is still set off (078C = 0)

3. the Priority light at the Cpt Side and the red arrow on the FO side illuminates (6DF1 = 1).

4. the Priority light at the FO Side and the red arrow on the Cpt side set off (6DF2 = 0).

Does this makes it more clear what I want to do .

regards

Fritz

Link to comment
Share on other sites

I want to try to explain the logic.

Autopilot is on. If Cpt Sidestick priority button pressed then

1. the Autopilot should set off (07BC = 0)

2. the Autopilot light should set off (078C = 0)

The autopilot master light goes on and off with the autopilot (07BC), which offset is controlled by normal FS controls. Offset 078C is merely a flag which is "true" (1) if a spoiler is available on this aircraft. You probably meant 07c8 as in previous messages, which isn't the A/P light but the heading lock. Again there are standard FS controls for this.

3. the Priority light at the Cpt Side and the red arrow on the FO side illuminates (6DF1 = 1).

4. the Priority light at the FO Side and the red arrow on the Cpt side set off (6DF2 = 0).

If then the Autopilot turned on again (with the button at the FCU)

1. the Autopilot should set on (07BC = 1)

2. the Autopilot light should set on (078C = 1)

3. the Priority light at the Cpt Side and the red arrow on the FO side set off (6DF1 = 0).

4. the Priority light at the FO Side and the red arrow on the Cpt side set off (6DF2 = 0).

Autopilot is on. If FO Sidestick priority button pressed then

1. the Autopilot should set off (07BC = 0)

2. the Autopilot light should set off (078C = 0)

3. the Priority light at the FO Side and the red arrow on the Cpt side illuminates (6DF2 = 1).

4. the Priority light at the Cpt Side and the red arrow on the FO side set off (6DF1 = 0).

Cpt has the priority and if FO Sidestick priority button pressed then

1. the Autopilot is still set off (07BC = 0)

2. the Autopilot light is still set off (078C = 0)

3. the Priority light at the Cpt Side and the red arrow on the FO side set off (6DF1 = 0).

4. the Priority light at the FO Side and the red arrow on the Cpt side illuminates (6DF2 = 1).

FO has the priority and if Cpt Sidestick priority button pressed then

1. the Autopilot is still set off (07BC = 0)

2. the Autopilot light is still set off (078C = 0)

3. the Priority light at the Cpt Side and the red arrow on the FO side illuminates (6DF1 = 1).

4. the Priority light at the FO Side and the red arrow on the Cpt side set off (6DF2 = 0).

Does this makes it more clear what I want to do .

Well, change 078C to 07C8 (when programming silly little errors like that will make it fail and be a devil to spot. Always take care, whether planning or executing) and then just convert all of the conditions to "ifthen" statements and the actions to "ipc.write ..." statements, and you are home and dry. However:

I suspect all of those sections EXCEPT the one where the A/P is turned on directly by the FCU and not via assignment in FSUIPC can easily be done using your original multiple assignments in the FSUIPC.INI file. The only reason the A/P one might need to bve Lua is because there's nothing going through FSUIPC when the FCU sets the A/P on.

However, there are other conditions you need to state actions for, if any:

Autopilot is off. Cpt Sidestick priority button pressed ...

Autopilot is off. FO Sidestick priority button pressed ...

Cpt has the priority and Capt Sidestick priority button pressed ...

FO has the priority and FO Sidestick priority button pressed ...

No one has the priority and Capt Sidestick priority button pressed ...

No one has the priority and FO Sidestick priority button pressed ...

Now these might be trivial cases where nothing needs doing, or they might merge with one of the other cases. For instance, if these two

Cpt has the priority and Capt Sidestick priority button pressed ...

FO has the priority and Capt Sidestick priority button pressed ...

can both result in the same actions without problems (even though some of those actions might be unnecessary) then things simplify -- you don't need to test the "priority" setting when the button is pressed, so it is easy then to program in the INI file instead of Lua.

Incidentally, what didn't you understand about my previous message showing you how to detect changes rather than repetitively do the same thing whilst a condition remains true? I am not going to write your program for you. I just want to help you understand what to do. It isn't helpful ignoring my suggestions.

Regards

Pete

Link to comment
Share on other sites

You probably meant 07C8 as in previous messages...
Yes.
The only reason the A/P one might need to bve Lua is because there's nothing going through FSUIPC when the FCU sets the A/P on.

That could be, yes. But I found out, that Offset 07C8 is changing, therefore I check the status of this offset.

I am not going to write your program for you.

This would be the easiest way for me but I do not have expected.

Incidentally, what didn't you understand about my previous message showing you how to detect changes rather than repetitively do the same thing whilst a condition remains true?

I have not yet understood where must I include this into program. Do I have add my query for like

 if x ~= MemoryOfX then
       if ipc.readUB(0x6DF1) == 1 then
       ipc.writeUD(0x07BC, 0)
       ipc.writeUB(0x6DF2, 0)
       end
end 

or do I have to put the query (MemoryOfX) at first an then the other querys?

regards

Fritz

Link to comment
Share on other sites

I have not yet understood where must I include this into program. Do I have add my query for like

 if x ~= MemoryOfX then
       if ipc.readUB(0x6DF1) == 1 then
       ipc.writeUD(0x07BC, 0)
       ipc.writeUB(0x6DF2, 0)
       end
end 

or do I have to put the query (MemoryOfX) at first an then the other querys?

I don't really understand your question, but why not think it through logically? So:

1. You only want to do something when "X" changes. Correct?

2. When it changes you only want to do something if Y = 1 (where Y is some other value of interest).

If you do it the other way around, then you will miss changes in X and may miss important changes subsequently.

So, the logic has got to be

if x ~= MemoryOfX then  -- Only do something if x changes
    if Y == 1 then             -- Only do something if Y = 1
         DO SOMETHING
    end
    MemoryOfX = x    -- update our memory of the state of x
end

See? If you state the logic of your problem, the program is identical, it follows the logic part for part. That is all programming is, logic written down in a form the computer can read!

However, in your solution above, which is nearly correct, you are not checking whether the autopilot, which has changed, is now ONit might have changed to OFF. So it should surely be:

 if x ~= MemoryOfX then
     if x == 1 then
         if ipc.readUB(0x6DF1) == 1 then
            ipc.writeUD(0x07BC, 0)
            ipc.writeUB(0x6DF2, 0)
        end
    end
    MemoryOfX = x
end 

You can, incidentally, combine conditions, so it could be shortened to:

 if x ~= MemoryOfX then
     if x == 1 and ipc.readUB(0x6DF1) == 1 then
         ipc.writeUD(0x07BC, 0)
         ipc.writeUB(0x6DF2, 0)
    end
    MemoryOfX = x
end 

However you might find the longer forms easier to read and understand until you get used to logic.

Unfortunately, this time, you've not answered my questions about missing possibilities. You seem to be rather selective in what you read and what you ignore. If the answers to that question are what I suspect they might be (that the initial condition of the priority switches are irrelevant) then I think you can do all you want by FSUIPC INI assignment lines, except for the one simply loop in Lua for the autopilot going on. Let me suggest a revised set of logics for your complete need, derived from your list. Is there anything wrong with this:

First, possibly the only one needing a Lua program:

If the Autopilot is turned on (with the button at the FCU)

1. the Autopilot should set on (07BC = 1)

2. the Autopilot heading hold should set on (07C8 = 1)

3. the Priority light at the Cpt Side and the red arrow on the FO side set off (6DF1 = 0).

4. the Priority light at the FO Side and the red arrow on the Cpt side set off (6DF2 = 0).

Then all the others with no conditions collapse into only two, one for each button, and therefore easily dealt with in FSUIPC INI button assignments

If Cpt Sidestick priority button pressed then (i.e. doesn't matter if A/P is on or off, or FO priority on or off?)

1. the Autopilot should set off (07BC = 0)

2. the Autopilot heading hold should set off (07C8 = 0)

3. the Priority light at the Cpt Side and the red arrow on the FO side illuminates (6DF1 = 1).

4. the Priority light at the FO Side and the red arrow on the Cpt side set off (6DF2 = 0).

If FO Sidestick priority button pressed then (i.e. doesn't matter if A/P is on or off, or Cpt priority on or off?)

1. the Autopilot should set off (07BC = 0)

2. the Autopilot heading hold should set off (07C8 = 0)

3. the Priority light at the FO Side and the red arrow on the Cpt side illuminates (6DF2 = 1).

4. the Priority light at the Cpt Side and the red arrow on the FO side set off (6DF1 = 0).

Regards

Pete

Link to comment
Share on other sites

I'm not ignore your suggestions, I could not managed it. Sorry.

I have tried many variants but could not solve the problem.

As you have suggested, I reduced the complexity.

I use the simply loop in Lua and have assigned two offsets to each button .

It worked well so far with exception to switch over from Cpt priority to FO priority

and vice versa. Is it possible to assign more than two offsets to a button in the FSUIPC INI?

That would be the easiest solution for me.

Regards

Fritz

Link to comment
Share on other sites

Is it possible to assign more than two offsets to a button in the FSUIPC INI?

That would be the easiest solution for me.

You don't "assign offsets" to a button. But you can have any number of lines detailing actions for the one button -- as in fact you already did, way back. Just remember that the actions are executed in line number order (i.e. the number before the "-" sign).

Remember this, from your own message?

0=P0,2,Cx010007C8,x00 P0 = Cpt. side Autopilot Master off

1=P0,2,Cx010007BC,x00 Autopilot heading lock off is required to switch off the autopilot light (my FCU is from CP Flight, with Wilco Airbus module)

2=P0,2,Cx01006DF1,x01 Offset for Cpt. priority + FO red arrow

This showed that you understood how to do multiple actions with one button press. However, you seem to have the order wrong here. Shouldn't it be:

0=P0,2,Cx010007BC,x00 P0 = Cpt. side Autopilot Master off

1=P0,2,Cx010007C8,x00 Autopilot heading lock off is required to switch off the autopilot light (my FCU is from CP Flight, with Wilco Airbus module)

2=P0,2,Cx01006DF1,x01 Offset for Cpt. priority + FO red arrow

3=P0,2,Cx01006DF2,x00 Offset for FO. priority off

You want another set like that for the FO priority button, and you should be done.

If you'd like to show me your working Lua code for the A/P switch going on, I'll show you how to midify it to use "events", which will make it much more efficient.

Regards

Pete

Link to comment
Share on other sites

I 've tried to assign 3 actions to button 2 but it seems that the third action is not executed.

Thats why Im asking you if this is generally possible.

What I do not even understand that it is not possible to executed two consecutive queries in a loop

like you did in your examples.

-- Sidestick Prioritiy Airbus A320
 while 1 do
   -- Sidestick Prioritiy light CPT/FO off when Autopilot is on
      if ipc.readUD(0x07BC) == 1 then
        ipc.writeUD(0x07C8, 1)
        ipc.writeUB(0x6DF1, 0)
        ipc.writeUB(0x6DF2, 0)
      end
    -- Sidestick Prioritiy CPT
      if ipc.readUD(0x07BC) == 0 and ipc.readUB(0x6DF1) == 1 then
        ipc.writeUD(0x07C8, 0)
        ipc.writeUB(0x6DF2, 0)  
     end 
   ipc.sleep(50)
end

If the autopilot is on than first loop is working. If I pushed the button than the loop stops and when I turn the autopilot on again than the first loop is working again.

Now back to my current configuration.

[Buttons.Feelthere Airbus A320-210 Lufthansa]
ButtonRepeat=20,00
0=P0,2,Cx01006DF1,x01
1=P0,2,Cx010007BC,x00
2=P1,2,Cx01006DF2,x01
3=P1,2,Cx010007BC,x00

-- Sidestick Prioritiy Airbus A320
  while 1 do
 -- Sidestick Prioritiy FO
      if ipc.readUD(0x07BC) == 1 then
      ipc.writeUD(0x07C8, 1)
      ipc.writeUB(0x6DF1, 0)
      ipc.writeUB(0x6DF2, 0)
      end
     ipc.sleep(250)
   end

I'm curious how we can solve this by 'events'

Regards

Fritz

Link to comment
Share on other sites

I 've tried to assign 3 actions to button 2 but it seems that the third action is not executed.

Thats why Im asking you if this is generally possible.

Any number of actions are executed for a button press. The only limit is on the overall size of the [buttons] section, which is certainly several hundreds (I don't recall without looking it up).

If you think one of them is not doing its job it is probably because it is being overridden by some other action immediately afterwards. Since I've no idea what 6FD1 and 6FD2 are used for I can't really help directly, but you can help yourself. Just enable button logging, and also monitor 6FD1 and 6FD2 as "U8" types on the right-hand side of the Logging tab. Check the "normal log" option below, and you will get a log of both button operations and the changes in your 6FD1 and 6FD2 offsets.

What I do not even understand that it is not possible to executed two consecutive queries in a loop

like you did in your examples.

Sorry, what do you mean "not possible"? You can execute as many queries as you like. Lua is an extremely flexible programming language.

      if ipc.readUD(0x07BC) == 0 and ipc.readUB(0x6DF1) == 1 then
        ipc.writeUD(0x07C8, 0)
        ipc.writeUB(0x6DF2, 0)  
     end 
   ipc.sleep(50)
end

If the autopilot is on than first loop is working. If I pushed the button than the loop stops and when I turn the autopilot on again than the first loop is working again.

First off, a sleep of only 50 means you are repeating everything 20 times a second. That is a waste of time. Please put it back to at least 250. Probably 500 would be better. When you write to 07BC or 07C8, it effectively schedules the request in FSUIPC to send the FS controls to turn on/off the Autopilot/Heading hold. The effect will NOT be immediate so you must give it time. It would be faster if you used the FS controls directly instead of writing to the offsets, but I keep suggesting that you use those to no avail.

Second, if the second part of the code never executes it must be because 6DF1 is never equal to 1. That is what you have to investigate. Try the logging and monitoring as I suggested! One possibility I can see is this:

This loop:

      if ipc.readUD(0x07BC) == 1 then
        ipc.writeUD(0x07C8, 1)
        ipc.writeUB(0x6DF1, 0)
        ipc.writeUB(0x6DF2, 0)
      end

sets 6DF1 and 6DF2 to zero all the time that the A/P is signalled 'on'. Right? But this:

0=P0,2,Cx01006DF1,x01
1=P0,2,Cx010007BC,x00

first sets 6DF1 to 1 then tries to turn the A/P off. Because the Lua program is operating ALL THE TIME the A/P is on, 6DF1 will be set to zero again immediately (or at least within the nexct 50 or 250 mSecs). The A/P being switched off takes time and FSUIPC has to interpret the write to 07BC and THEN send the request to FS as a control. That goes through SimConnect on FSX or via the message queue on FS9.

If your Lua loop only acted on a change in the A/P then this problem would not arise.

Now back to my current configuration.

[Buttons.Feelthere Airbus A320-210 Lufthansa]
ButtonRepeat=20,00
0=P0,2,Cx01006DF1,x01
1=P0,2,Cx010007BC,x00
2=P1,2,Cx01006DF2,x01
3=P1,2,Cx010007BC,x00

Why are you omitting the other two controls for each button?

while 1 do
 -- Sidestick Prioritiy FO
      if ipc.readUD(0x07BC) == 1 then
      ipc.writeUD(0x07C8, 1)
      ipc.writeUB(0x6DF1, 0)
      ipc.writeUB(0x6DF2, 0)
      end
     ipc.sleep(250)
   end

Why have you reverted to code which executes continually whilst the A/P is on? You are ignoring everything we discussed to do this only when it changes. Why?

I'm curious how we can solve this by 'events'

If it isn't working now it won't be "solved" by using events. Using events is just a much tidier and more efficient way of doing things only when something changes. A change in an offset is detected for you by FSUIPC and that instigates some Lua code.

What is and is not working? You don't actually say. Please try to use the Logging.

You are making very heavy weather of something which appears on the surface to be such a simple thing. I get the feeling you aren't telling me everything, so I have to keep guessing. Are you sure you really want to continue for another n days? ;-)

Pete

Link to comment
Share on other sites

You will not believe it but it runs now. :D

I think the key note was ipc.sleep (500).

I've changed it from 250 to 500 and now it seems that the third command is also running well.

Many thanks for your help and especially for your patience.

Regards

Fritz

P.S.: I hope that now the sun comes out again. :wink:

Link to comment
Share on other sites

You will not believe it but it runs now. :D

I think the key note was ipc.sleep (500).

I've changed it from 250 to 500 and now it seems that the third command is also running well.

This is because it takes time for the A/P to be switched off. You'd still be far better off only doing the "AP on" action when the AP changes.

Now it works, here's the event-driven version of the Lua plug-in:

function autopilotonoff(offset, val)
     if val == 1 then
         ipc.writeUD(0x07C8, 1)
         ipc.writeUB(0x6DF1, 0)
         ipc.writeUB(0x6DF2, 0)
    end
end

event.offset(0x07BC, "UD", "autopilotonoff")

That's it. There's no "while" loop nor delay needed. Just save it as ipcReady.lua and you are away.

What happens is that FSUIPC reads the file and actions not the "function", but just the "event" command. This lodges a request for that function, here named "autopilotonoff" to be called whenever offset 07BC changes. Then that function does its job, after checking that the change has been to turn the A/P on. If it is turned off it does nothing.

Regard

sPete

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • 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.