Archived

This topic is now archived and is closed to further replies.

pcxmac

input::SetDataFormat // finding out how big the data packet is

Recommended Posts

hey all just wondering if there is a way to get the size of the data packet or structure used in the GetDeviceState function. i only have a mouse and keyboard attached to the system, and while it would be less headache to use the constants associated with the mouse and keyboard for setting the data format, i am looking for a general purpose how much data does this device lookup when it gets the device state, also is there anything in this line when it comes to buffered data. i can get everything else but the size of the data packet is what the problem is.

Share this post


Link to post
Share on other sites
I am not sure that I understood what you mean, but I''ll give it a go anyway:
If what you want is to know the size of your input device without using the global c_dfDIKeyboard, c_dfDIMouse etc., you
can do it by enumerating the objects on the device.
You can do so by calling IDirectInputDevice8::EnumObjects.
Once you have established the number of object for your input device you use SetDataFormat with a new struct of type DIDATAFORMAT you created, using your knowledge about the input device. Now, since you created the data format yourself, you should be able to know in advance the expected size of input from that device.
...Or maybe you can just stick with the constants

Share this post


Link to post
Share on other sites
no there cannot be any constants, as i am going for one size fits all on this api. and i have enumerated all the device objects. i have offsets to all the applicable data inside the packet but i cant find the actual size of the packet its self. for instance the keyboard, the last offset for object (i believe the home button) is 237, byte 237. However the DX SDK says that the device for keyboard extracts 256 bytes.

so im currently at a loss on how to determine the size of the data extracted from the device. i have looked at the DIDEVCAPS structure, DIDEVICEINSTANCE, and so forth, looking for the size of the data packet extracted on get_device_state().

my only problem here is that i cant determine the data packet size with any of the given structs, or dxDevice::functions.

my api will never use those nasty constants or define#s'' i cant use precompiled data for building dx devices.

Share this post


Link to post
Share on other sites
You know the size of the data returned when you call GetDeviceState() because you are the one deciding that when you call SetDataFormat(). The dwDataSize member of DIDATAFORMAT is the size of your data packet when you call GetDeviceState().

Share this post


Link to post
Share on other sites
so if i wanted to make the packet for the keyboard 32 bytes it would fly? i am currently under the impression that with each device the device packet has a fixed size. if not, all i need is an offset to the data, then i can use the offsets given relative from each object to extract data. but as it is, and from what i can piece togeather from the SDK the packet is of fixed length. and that length needs to be determined inorder to correctly use the Device::SetDataFormat().

ps. im bad at being explicit. all i need to know is, is there a way to determine a devices data packet size in order for correctly setting up the DIDATAFORMAT struct and then setting the correct data format. sorry if i confused anyone. im not going to use constants or numbers, i just need to know if there is a variable or struct that holds that information.

[edited by - pcxmac on July 3, 2003 5:38:06 PM]

Share this post


Link to post
Share on other sites
You can certainly make your packet only 32-bytes long, but every time you call GetDeviceState(), you would only get back state information for 32 keys (in the keyboard case). The way you achieve this is by defining your own data format. For instance, if you are only interested in 3 keys (Escape, Enter, and Space) when you call GetDeviceState(), then you can define your data format as this:


DIOBJECTDATAFORMAT DIodf[] = {
{ &GUID_Key, 0, DIDFT_MAKEINSTANCE(DIK_ESCAPE)|DIDFT_BUTTON, 0 }, // Offset 0

{ &GUID_Key, 1, DIDFT_MAKEINSTANCE(DIK_RETURN)|DIDFT_BUTTON, 0 }, // Offset 1

{ &GUID_Key, 2, DIDFT_MAKEINSTANCE(DIK_SPACE)|DIDFT_BUTTON, 0 } // Offset 2

};


Then later in your code:


DIDATAFORMAT df;
df.dwSize = sizeof(df);
df.dwObjSize = sizeof(DIOBJECTDATAFORMAT);
df.dwFlags = DIDF_RELAXIS;
df.dwDataSize = 4; // 3 bytes used, but must be multiple of 4

df.dwNumObjs = 3;
df.rgodf = DIodf;
pKeyboardDevice->SetDataFormat( &df );


Now your data packet will be 4-byte long, although the last byte is not used. When you call GetDeviceState() to get state information, bytes 0, 1, and 2 will contain the state of the Escape, Enter, and Spacebar keys, respectively.

Share this post


Link to post
Share on other sites
statement 1 : somethings not making sense.

question 1 : im not getting the concept. is there a maximum size for the dwDataSize. does this max, change for different devices. would it be possible to obtain a pointer to the offset in to the data extracted by getDeviceState?

point 1 : my point is, this kind of way of extracting data seems in-effecient i mean give a pointer to said data and use the offsets given in each DIDEVICEOBJECTINSTANCE.

last question : i am trying to use a one size fits all way of doing business and i need some variable or device class member which describes the true size for df.dwDataSize for any given device type (mouse, keyboard, etc...)

DIDATAFORMAT df;
df.dwDataSize = 4; // 3 bytes used, but must be multiple of 4

Share this post


Link to post
Share on other sites
If you wish to find out the size of the buffer needed to hold information for all objects on a device, you can do the following:

1. Call EnumObjects() on the device.
2. In your EnumObjects callback function, check the type of the object enumerated (axis or button) and add the size it requires to a device-sum variable. Each axis requires 4 bytes; each button requires 1 byte.
3. When EnumObjects() returns, the device-sum variable holds the data size needed for that particular device.

Do this for all devices, and the maximum of those sums is the size that works with all devices on the system.

Does that answer your question?

Share this post


Link to post
Share on other sites
well i got it to work i multiplied the number of axes * 4 and the number of buttons * 2. and i got a good size. one thing to not when enumerating the mouse objects, i had to set DIDFT_ALL | DIDFT_~objects that dont receive input inorder to correctly size up the data packet. one thing though i looked on the DEVCAPS struct and theres a field for POVs how many bytes do they take up? or what is the multiplier(see above).

[edited by - pcxmac on July 4, 2003 5:08:28 PM]

Share this post


Link to post
Share on other sites