motion data should be structured

Bug #391783 reported by yliu0
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
pyfreespace
Invalid
Undecided
JT Burgess

Bug Description

The motion data is returned as a string. For example:

s = device.readMessage(500)

The content of s is:

"UserFrame(button1=0 button2=0 button3=0 button4=0 button5=0 deltaX=0 deltaY=0 deltaWheel=0 sequenceNumber=2192591 linearPosX=0 linearPosY=0 linearPosZ=0 angularPosA=-11493 angularPosB=12130 angularPosC=-20052 angularPosD=-19807)"

This string can be parsed easily. However it would be more convenient to receive:

s = {
    "type": "userframe",
    "buttons": [False, False, False, False, False],
    "delta": [0, 0, 0],
    "sequenceNumber": 2192591,
    "linearPosition": [0, 0, 0],
    "angularPosition": [-11493, 12130, -20052, -19807]
}

An alternative is to return the structure above in JSON format.

Revision history for this message
JT Burgess (jt-burgess) wrote :

Actually, readMessage does not return a string, it returns an object. The type of the object returned depends on the message received, but in this case it's actually of type freespace.UserFrame

If you run

> s = device.readMessage(500)
> dir(s)

you can see that s actually has a number of read-only attributes to it, which are the fields listed in the string representation above.

You can access each field by doing

s.button1 (which is a boolean)
s.linearPosX (which is an integer)
etc.

Changed in pyfreespace:
assignee: nobody → JT Burgess (jt-burgess)
Revision history for this message
JT Burgess (jt-burgess) wrote :

Misunderstanding of pyfreespace. Probably an indication that I need to create documentation for how to use it properly.

Changed in pyfreespace:
status: New → Invalid
Revision history for this message
yliu0 (yliu0) wrote :

You are right. The s is of type UserFrame.

>>> type(s)
<type 'freespace.UserFrame'>

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.