Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Implementing FFB support #27

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft

Conversation

Ultrawipf
Copy link

@Ultrawipf Ultrawipf commented Oct 24, 2024

This change adds full FFB packet parsing into python dicts using callback functions and the missing FFB related functions from the vJoy sdk.

Solves issue #17

A helper class for receiving and translating C style structs to python dicts using integrated vJoy functions was added in sdk.py.
If preferred it may be possible to split some functionality into sdk and vjoydevice as it did require some higher level processing.

Using different or the same callbacks per device is possible. The callbacks are stored by rID and called based on the source.
Parsed FFB data is passed as a python dict to the callback allowing the use of if "ctrl" in packet for example to check if the packet is a control packet.

Info: This has not yet been extensively used yet but all reports have been tested and verified and should contain valid data.

Note: _wrapper.py was not touched. It seems like this file is not in use anymore. Possibly delete the whole file?
The duplicated SetBtn function was also deleted.

Example usage:

j = pyvjoy.VJoyDevice(1)
j2 = pyvjoy.VJoyDevice(2)

effects = [{} for _ in range(1)]  # Effect storage. Only one is currently valid in vjoy
def ffbCb(data,reptype):
    packetdict,ebi = j.ffb_packet_to_dict(data,reptype)
    if reptype == pyvjoy.PT_BLKFRREP: # Delete block
        effects[packetdict["blkfree"]-1].clear()

    if reptype == pyvjoy.PT_EFFREP:
        print(packetdict)

    if ebi:
        effects[ebi-1].update(packetdict)

    print("Effects:",effects)

def ffbCb2(d,pt):
    print("got data2",pt)
    print(d)

if j.ffb_supported():
    print("J1 support")
    j.ffb_register_callback(ffbCb)

if j2.ffb_supported():
    print("J2 support")
    j2.ffb_register_callback(ffbCb2)

time.sleep(100)
print("End")

For testing "fedit.exe" or the iracing wheelcheck tool can be used.
The sdk callback returns parsed structs and a packet type (previously directly as a dict but that might be too restrictive).

A dict of the packet can be generated using a static helper function ffb_packet_to_dict(packet,packettype) which can then directly update an effect dict if a block index is present and returns the dict and an effect block index.

An effect block index of 0 means that this packet does not address a specific effect and must be treated as a global control report.

Note: vjoy only seems to return block index 1 for all effects even if multiple effects are in use. This is problematic as it would only work well with a single effect.

Type is one of the newly added "PT_" constants.

Valid packet names generated by the ffb_packet_to_dict to function are:

  • ctrl : device control report. Enable or disable actuators.
  • effect: Set effect report. Changes effect parameters.
  • ramp: Ramp report. Changes parameters of a ramp effect.
  • effop: Effect operation. Enables or disables a specific effect.
  • period: Period effect report. Changes periodic effects.
  • cond: Conditional effect report. Changes conditional effects.
  • envelope: Envelope report.
  • neweff: New effect report. Called when a new effect is created at EffectBlockIndex.
  • const: Constant force report. Changes magnitude of constant force effects.
  • gain: Changes total gain of device.
  • blkfree: Block free report. Deletes an effect from EffectBlockIndex.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant