Jump to content
The simFlight Network Forums

Returning developer


Recommended Posts

Hi all,

After a "short" break of 20 years, my interest in flight siming has gotten re-sparked. My ancient (2011) laptop is not up to running the latest and greatest, but it was a powerful machine when new and is more than capable of running FSX at max settings.ย  I've even bought a copy of the excellent Aerosoft A320 add-on.

As a developer, and original author of the Java FSUIPC sdk, I decided to have a look at what has been going on since 2003 ๐Ÿ™‚

I'm now mainly a Python developer having dropped Java behind many moons ago. I was pleased to see a python SDK for FSUIPC so I bought myself a license to have a poke about.

I quickly realised I wanted to try and build some real hardware as I tried this in the past - I even have the rotary encoders.

I got a Raspberry Pi Pico reading an encoder and pretending to be a joystick. USB was out of my league in 2003.

This all works nicely, except when setting a rotary control (SPD or HDG). My option seems to be to call a lua script to increment or decrement the appropriate control based on an emulated button push. The response from the panel is quite slow - I've found a few other forum posts from the past where people have had similar issues.

I have now modified my Pico code to send delta's (as a Dial control) based on the speed of rotation and I'm using Python to set the HDG bug via one L:VAR. It responds really nicely.

My question is: Is this the way to go - i.e create python app to react to the joystick dial events and write to LVARS ? or am I over thinking things

I haven't yet looked at the comms event handling in lua

Cheers

Mark

ย 

Link to comment
Share on other sites

14 minutes ago, markB139 said:

My question is: Is this the way to go - i.e create python app to react to the joystick dial events and write to LVARS ? or am I over thinking things

I haven't yet looked at the comms event handling in lua

If the joystick is recognised as a HID joystick type device by FSUIPC, you can use FSUIPCs assignment facilities. Otherwise, it would need a lua script using the com library.

But if its working using Python and you are happy with this then probably no reason to switch to Lua.

Cheers,

John

Link to comment
Share on other sites

Hi,

Yes, my Pico is being recognised as a HID device.

In case anybody in the future reads this:

I've just tried an experiment that seems to work quite well.ย 

I open my HID device (please ignore the ID's they aren't official - just for my testing) and can watch for data coming in

handle, rd, rdf, wr, initreport = com.openhid(0xcafe, 0x4004)
event.com(handle, 100, 0, "test_com")

I then use a lua struct library (not sure I actually need to do this) and call one of two functions (taken and modified from the Linda aerosoft a320 code) depending on the sign of the delta

function test_com(hand, datastr, len)
  local a,b,c,d,e,f,g,h,i,j,k,l, delta = struct.unpack('bbbbbbbbbbbbb', datastr)
  if delta > 0 then
    AB_HDG_plus(delta)
  end
  if delta < 0 then
    AB_HDG_minus(-delta)
  end
end

ย This works reasonably well in that the heading changes quite quickly to my rotation of the encoder with very little lag.

I like this solution as it requires fewer bits of code to maintain.

cheers

Mark

Link to comment
Share on other sites

15 hours ago, markB139 said:

Yes, my Pico is being recognised as a HID device.

Yes, I know - but I was wondering if it was a joystick type HID device. If so, it would be registered in the FSUIPC4.log file under the joysticl scan section, and would be available for direct assignment via the UI as that is always the easiest methpd to assign. But I guess it isn't.

15 hours ago, markB139 said:

I like this solution as it requires fewer bits of code to maintain.

๐Ÿ‘

Cheers,

John

Link to comment
Share on other sites

2 hours ago, John Dowson said:

Yes, I know - but I was wondering if it was a joystick type HID device. If so, it would be registered in the FSUIPC4.log file under the joysticl scan section, and would be available for direct assignment via the UI as that is always the easiest methpd to assign. But I guess it isn't.

๐Ÿ‘

Cheers,

John

In the FSUIPC.log I get

      453 Product= Pico Controller
      453    Manufacturer= MarkB
      453    Serial Number= 888888
      453    Vendor=CAFE, Product=4004 (Version 1.0)
      453    GUIDs returned for product: VID_CAFE&PID_4004:
      453       GUID= {4026DA40-CB00-11ED-8001-444553540000}
      453       Details: Btns=32, POVs=(0, 0, 0, 0), Cal=x00000000, Max=R127,U127,V127,X127,Y127,Z127
      453 -------------------------------------------------------------------
      500 Device acquired for use:
      500    Joystick ID = 0 (Registry okay)
      500    0=TinyUSB Device HID
      500    0.GUID={4026DA40-CB00-11ED-8001-444553540000}

I'm still learning about how USB HID report descriptors work. I think I set mine up as a desktop gamepad (type 0x04)

Today I've wired up a couple of buttons to my breadboard. I can assign the buttons using the FSUIPC UI. I now need to buy more buttons ๐Ÿ™‚

ย 

Cheers

Mark

Link to comment
Share on other sites

Ok, then you can assign to it directly and don't need to use the lua com library, which is always the easy path...

8 minutes ago, markB139 said:

Today I've wired up a couple of buttons to my breadboard. I can assign the buttons using the FSUIPC UI. I now need to buy more buttons ๐Ÿ™‚

๐Ÿ‘

Cheers,

John

Link to comment
Share on other sites

On 3/30/2023 at 11:53 AM, markB139 said:

In the FSUIPC.log I get

      453 Product= Pico Controller
      453    Manufacturer= MarkB
      453    Serial Number= 888888
      453    Vendor=CAFE, Product=4004 (Version 1.0)
      453    GUIDs returned for product: VID_CAFE&PID_4004:
      453       GUID= {4026DA40-CB00-11ED-8001-444553540000}
      453       Details: Btns=32, POVs=(0, 0, 0, 0), Cal=x00000000, Max=R127,U127,V127,X127,Y127,Z127
      453 -------------------------------------------------------------------
      500 Device acquired for use:
      500    Joystick ID = 0 (Registry okay)
      500    0=TinyUSB Device HID
      500    0.GUID={4026DA40-CB00-11ED-8001-444553540000}

I'm still learning about how USB HID report descriptors work. I think I set mine up as a desktop gamepad (type 0x04)

Today I've wired up a couple of buttons to my breadboard. I can assign the buttons using the FSUIPC UI. I now need to buy more buttons ๐Ÿ™‚

ย 

Cheers

Mark

As an update. Reading and reacting to button pushes and the change in rotary encoder are working nicely. I'm now trying to send data back to the HID device. I'm using

-- send 51 (ascii 3) to report 1
written = com.writefeature(handle, {1,51}, 2)
ipc.log("written="..written)

However, I get 0 bytes written and I see no activity in wireshark. I do see the data in wireshark for readreport and readfeature.

I can send the feature report in a Python script using the pywinusb hid library and I can see the traffic.

Is there anyway to get any Windows API error codes logged ?

ย 

cheers

Mark

ย 

ย 

Link to comment
Share on other sites

1 hour ago, markB139 said:

As an update. Reading and reacting to button pushes and the change in rotary encoder are working nicely. I'm now trying to send data back to the HID device. I'm using

-- send 51 (ascii 3) to report 1
written = com.writefeature(handle, {1,51}, 2)
ipc.log("written="..written)

However, I get 0 bytes written and I see no activity in wireshark. I do see the data in wireshark for readreport and readfeature.

I can send the feature report in a Python script using the pywinusb hid library and I can see the traffic.

Is there anyway to get any Windows API error codes logged ?

ย 

cheers

Mark

ย 

ย 

Ah ha, think my understanding of lua needs work ๐Ÿ™‚

This has just worked

-- send ascii for 3 to feature 1
binstr = string.char(0x01, 0x33)
ipc.log("binstr "..binstr)
written = com.writefeature(handle, binstr, 2)

ย 

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.