Add first user ffb handler

This commit is contained in:
Patrick Moessler 2020-10-31 00:48:33 +01:00
parent b1618a8956
commit c2f3ab053d

72
test.py
View file

@ -11,11 +11,15 @@ def send_pkt(port, command, data):
pkt = bytes(ifr.tx_packet(command, data))
port.write(pkt)
def hex_print(d):
print(' '.join('%02x'%x for x in d))
print(' '.join('%02x' % x for x in d))
def query_print(d):
print('QUERY[%02x]:%s'%(d['query'],' '.join('%02x'%x for x in d['data'])))
print('QUERY[%02x]:%s' %
(d['query'], ' '.join('%02x' % x for x in d['data'])))
def setup_wheel(port):
ifr.set_handler(ifr.Packet.QUERY, query_print)
@ -51,6 +55,70 @@ with serial.Serial(port=PORT, baudrate=BAUD) as port:
j = pyvjoy.VJoyDevice(1)
ffb.add_ffb(j)
device_state = 0
def handle_ffb(ffb_type, value, packet):
global device_state
if ffb_type == ffb.FFBPType.PT_EFFREP:
print('not implemented: %02x' % ffb_type)
elif ffb_type == ffb.FFBPType.PT_ENVREP:
print('not implemented: %02x' % ffb_type)
elif ffb_type == ffb.FFBPType.PT_CONDREP:
print('not implemented: %02x' % ffb_type)
elif ffb_type == ffb.FFBPType.PT_PRIDREP:
print('not implemented: %02x' % ffb_type)
elif ffb_type == ffb.FFBPType.PT_CONSTREP:
print('not implemented: %02x' % ffb_type)
elif ffb_type == ffb.FFBPType.PT_RAMPREP:
print('not implemented: %02x' % ffb_type)
elif ffb_type == ffb.FFBPType.PT_CSTMREP:
print('not implemented: %02x' % ffb_type)
elif ffb_type == ffb.FFBPType.PT_SMPLREP:
print('not implemented: %02x' % ffb_type)
elif ffb_type == ffb.FFBPType.PT_EFOPREP:
print('not implemented: %02x' % ffb_type)
elif ffb_type == ffb.FFBPType.PT_BLKFRREP:
print('not implemented: %02x' % ffb_type)
elif ffb_type == ffb.FFBPType.PT_CTRLREP:
if value == ffb.FFB_CTRL.CTRL_ENACT:
device_state |= ifr.DeviceState.ENABLE_FFB
elif value == ffb.FFB_CTRL.CTRL_DISACT:
device_state &= ~ifr.DeviceState.ENABLE_FFB
elif value == ffb.FFB_CTRL.CTRL_STOPALL:
device_state |= ifr.DeviceState.STOP_ALL
elif value == ffb.FFB_CTRL.CTRL_DEVRST:
device_state = 0
elif value == ffb.FFB_CTRL.CTRL_DEVPAUSE:
device_state |= ifr.DeviceState.PAUSE_FFB
elif value == ffb.FFB_CTRL.CTRL_DEVCONT:
device_state &= ~ifr.DeviceState.PAUSE_FFB
send_pkt(port, ifr.Packet.SET_DEVICE_STATE, [device_state])
elif ffb_type == ffb.FFBPType.PT_GAINREP:
print('not implemented: %02x' % ffb_type)
elif ffb_type == ffb.FFBPType.PT_SETCREP:
print('not implemented: %02x' % ffb_type)
elif ffb_type == ffb.FFBPType.PT_NEWEFREP:
print('not implemented: %02x' % ffb_type)
elif ffb_type == ffb.FFBPType.PT_BLKLDREP:
print('not implemented: %02x' % ffb_type)
elif ffb_type == ffb.FFBPType.PT_POOLREP:
print('not implemented: %02x' % ffb_type)
# FFB_CTRL
# FFB_DATA
# FFB_EFF_COND
# FFB_EFF_CONSTANT
# FFB_EFF_ENVLP
# FFB_EFF_OP
# FFB_EFF_PERIOD
# FFB_EFF_RAMP
# FFB_EFF_REPORT_Dir
# FFB_EFF_REPORT
# FFB_EFFECTS
# FFBEType
# FFBOP
# FfbPacket
# FfbPacketHelper
# FFBPType
# def handle_wheel(w):
# j.data.wAxisX = int(0x4000 * (w['axis']['wheel'] + 1))