necroware / gameport-adapter

GamePort adapter to connect old DB15 joysticks to USB port

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Sidewinder.h: size of "bits" array in "Packet" struct

git-moritz opened this issue · comments

I might be getting this completely wrong, but:

when we are reading a data packet from the Sidewinder using "readPacket", the "while"-loop

while(packet.length < sizeof(packet.bits))

runs as often as 256 times, because the "Packet"-Struct is defined as

/// Internal bit structure which is filled by reading from the joystick. struct Packet { byte bits[256]; uint16_t length{0u}; };

...is that really necessary? The SW 3DPro transmits 64 bits, the SW FFP transmits 66 bits, the SW Gamepad only 15 bits...

Reducing it to "byte bits[70]" would save some time, wouldn't it?

You could set the actual payload size to some variable during joystick detection and initialization and use that in the loop instead of the "sizeof()".

I already reduced the array size to 64, since this is the max possible packet size so far. But it actually doesn't matter if it's 256 or less the loop runs until a clock timeout comes. So eventually, it never runs up to 256..... Hm, just realized, that the buffer should be larger, than the possible biggest packet, since if joystick sends more bits, than expected, it can be used as additional error detection. Rose to 128 again.

Btw. performance is currently not a problem at all, so don't waste too much of your time on it. The latency for Sidwinder 3D Pro is below 4ms and can be easily reduced by lowering the cooldown time. Currently it is more important to add and test further joysticks support.

Hi Moritz, do you think, this can be closed?

Yes, I think so :)