Jump to content
The simFlight Network Forums

Level-D B767 MCP with Lekseecon_f, FSUIPC4, Pokeys 56U and Arduino Mega


Recommended Posts

Hi Pete and Nico,

I have built a (hardware) B767-300ER MCP to interface with the FSX Level-D B767, using Pokeys 56U for the rotaries and switch inputs and an Arduino Mega 2560 for the annunciators and numeric outputs.

I am having a problem with the lower limit of the IAS/MACH input....(the upper limit is working fine).

The lekseecon_f manual states:

lekseecon var 296: range is 4 bytes (32 bit) -> (FSUIPC offset 0x8b18) read/write -> MCP IAS/Mach, range 100 to 950

Note: Mach values are given x 1000, so .802=802

lekseecon var 296 has been duly activated in my lekseecon.ini file.

So, for the rotary encoder controlling IAS/MACH these are the entries in my FSUIPC4.ini file:

195=PM,16,C1005,3840

196=CP(F-15,0)M,14,Cx23008B18,x00640001

197=CP(F+15,0)M,14,Cx23008B18,x0064000A

198=CP(F-15,0)M,15,Cx13008B18,x03B60001

199=CP(F+15,0)M,15,Cx13008B18,x03B6000A

Joystick M is my Pokeys card.

(195) Button 16 is the pushbutton integrated with the rotary encoder which enables toggling between increments/decrements of 1 knot and 10 knots (or .001 mach and .010 mach).

(196) Button 14 (rotary encoder) turned anticlockwise

Cx2300 = Offset UDword Decrement, 8B18 = fsuipc offset for ias/mach, x0064 = lower limit of 100 in hex, 0001 = decrement of 1

(197) Button 14 (rotary encoder) turned anticlockwise

Cx2300 = Offset UDword Decrement, 8B18 = fsuipc offset for ias/mach, x0064 = lower limit of 100 in hex, 000A = decrement of 10

(198) Button 15 (rotary encoder) turned clockwise

Cx1300 = Offset UDword Increment, 8B18 = fsuipc offset for ias/mach, x03B6 = upper limit of 950 in hex, 0001 = increment of 1

(199) Button 15 (rotary encoder) turned clockwise

Cx1300 = Offset UDword Increment, 8B18 = fsuipc offset for ias/mach, x03B6 = upper limit of 950 in hex, 000A = increment of 10

Now, this works perfectly on the upper limit....i.e. I can keep turning the rotary encoder cw, but the display will not register anything beyond 950.

But, the problem is that it does not work on the lower limit.....i.e. if I keep turning the rotary encoder acw, the display WILL go below 100, in steps of 1 or 10, until it reaches 0. So the lower limit of 100 that I have imposed via the code is not being respected.

So, would you please be able to tell me whether I have done something wrong, and how I could set this right?

Thanks and Regards,

Chakko.

post-17243-0-54965300-1435501793_thumb.j

Link to comment
Share on other sites

Hello Chakko,

 

I'm sorry, but I'm not familiar with Pokeys, Arduino and your advanced use of FSUIPC (wrt rotary encoders)... I only know Opencockpits hard- and software very well ;-)

But it is unlikely that there is something wrong with lekseecon_f.

 

Regards,

Nico Kaan

Link to comment
Share on other sites

Now, this works perfectly on the upper limit....i.e. I can keep turning the rotary encoder cw, but the display will not register anything beyond 950.

But, the problem is that it does not work on the lower limit.....i.e. if I keep turning the rotary encoder acw, the display WILL go below 100, in steps of 1 or 10, until it reaches 0. So the lower limit of 100 that I have imposed via the code is not being respected.

 

I'll take a look tomorrow, but first can you please tell me the version number of the FSUIPC you are using? If it isn't the latest (4.939u) please try that first.

 

Pete

Link to comment
Share on other sites

I confirm that I am using registered FSUIPC4 version 4.939u.

 

Okay. Bug verified! It's a very good catch -- thanks for reporting it. The code is explicitly checking for 0 as the lower limit, not the limit you give! This is an original bug, dating back many many years, probably to when the controls were added!

 

I'm amazed no one has reported it before. The signed versions work fine -- maybe folks have always used those -- they'd do the same job when the range of values never use the top bit of the byte/word or DWORD.

 

Please download version 4.939v which is now available in the Download Links subforum..

 

Pete

Link to comment
Share on other sites

Hi Pete,

I've been putting the finishing touches to my B767 MCP, and had to make a compromise with the heading selector.

The real-world B767 MCP has a Heading knob, integrated with a heading Select button, and a Bank-limit rotary switch selector. I guess 'acceleration' for the heading input is built into the device.
post-17243-0-76244300-1435732568.jpg
But, at present, all I have installed is a single rotary encoder with an integrated push-button switch. So to emulate all the functions of the r-w knob, I decided on the following scheme:

(1) Single short press of the push-button toggles between higher and lower value increments/decrements for rotation of the heading knob.
(2) Two short presses in quick succession selects the bank-limit control, for which a mouse macro is available to increment or decrement the setting by rotation of the knob.
(3) Long press of the push-button is the heading select function, or the equivalent of pressing the pushbutton (marked 'SEL') integrated with real-world knob.

I copied the framework of your TripleUse.lua, and modified it, and ran the code, and it works! I am reproducing it here in case it can be of use to anyone else. One little wrinkle still to be ironed out is that while applying a long press (3), the script also seems to apply a short press (1), and toggles the associated bit.

    joy = "M"
    btn = 19
    interval = 500 -- 1/2 second press, gap, press limits

---------------heading button-----------------

local function timebutton(test)
  while true do
        time2 = ipc.elapsedtime()
        if (time2 - time1) > interval then
            return false
        end
         if ipc.testbutton(joy, btn) == test then
            time1 = time2
            return true
        end
         ipc.sleep(20)
    end
end

function buttonpress(j, b, du)
    -- Cancel event so we don't get called again for double press
    event.cancel("buttonpress")
    
    -- Note time button was pressed
    time1 = ipc.elapsedtime()

    if timebutton(false) then
        -- First press / release counts: see if there's another
        if timebutton(true) then
            -- got another press in time, look for release
            if timebutton(false) then
                -- this was a double press, select bank-limit by writing button parameter 2 to offset 66C0
                ipc.writeUB(0x66C0, 2)
            end
      else    
            -- This was a single press, toggle flag for large/small increment by toggling the bit at offset 66C1 and copy the flag back to offset 66C0
            if ipc.readUB(0x66C1) == 0 then
                ipc.writeUB(0x66C1, 1)
            else ipc.writeUB(0x66C1, 0)
            end
            ipc.writeUB(0x66C0, ipc.readUB(0x66C1))

        end
    else
        -- This was a longer press, select heading select by writing button parameter 3 to offset 66C0
        ipc.writeUB(0x66C0, 3)
        ipc.sleep(20)
        ipc.writeUB(0x66C0, ipc.readUB(0x66C1))
    end
    -- Restore cancelled event
    event.button(joy, btn, 1, "buttonpress")
end

-----------------events--------------------

event.button(joy, btn, 1, "buttonpress")

and the relevant FSUIPC4.ini extract:

; button 17 is encoder turned acw, button 18 is encoder turned cw
; button 19 is integrated push-button

200=B66C0=0 PM,17,Cx63008B1C,x01670001   ;hdg cyclic decrement 1 deg, range 1/359
201=B66C0=1 PM,17,Cx63008B1C,x0167000A   ;hdg cyclic decrement 10 deg, range 10/359
202=B66C0=0 PM,18,Cx53008B1C,x01670001   ;hdg cyclic increment 1 deg, range 1/359
203=B66C0=1 PM,18,Cx53008B1C,x0167000A   ;hdg cyclic increment 10 deg, range 10/359
204=B66C0=2 PM,17,CM5:100,0    ;mouse macro to decrement bank-limit
205=B66C0=2 PM,18,CM5:101,0    ;mouse macro to increment bank-limit
206=B66C0=3 PM,19,Cx0D00911C,x01        ;pressing hdg SEL knob toggles bit at the lekseecon offset

What a fantastic tool you have created in FSUIPC, and what a powerful addition you have brought in with the lua library! I am just scratching the surface of possibilities, I know, but I am constantly amazed at what can be achieved!

I was wondering whether the same objectives could have been achieved by direct button programming in the FSUIPC4.ini file. I felt it might not be possible in this case because (i) I wasn't clear about whether one could implement a 'timer-based choice' there, and (ii) a button flag can only toggle between two states, but here we have to choose between three. You will note that I used the free offsets at 66C0 and 66C1 to store the chosen button mode, and that the behaviour of the knob is then conditional on the value of this parameter.

Warm regards,

Chakko.

Link to comment
Share on other sites

I was wondering whether the same objectives could have been achieved by direct button programming in the FSUIPC4.ini file. I felt it might not be possible in this case because (i) I wasn't clear about whether one could implement a 'timer-based choice' there, and (ii) a button flag can only toggle between two states, but here we have to choose between three.

 

No, there's no time-dependent or timing facilities available with mere parameters in the INI file, even using macros. Lua was added to avoid having to make all that stuff even more complex and arcane than it got to, as it is! ;-)

 

Pete

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.