j3d.org Code

org.j3d.device.input.spaceball
Class SpaceballPacket

java.lang.Object
  extended byorg.j3d.device.input.spaceball.SpaceballPacket
Direct Known Subclasses:
Spaceball3003Packet, Spaceball4000Packet

public class SpaceballPacket
extends java.lang.Object

Generates and decodes data packets for a Labtec's Spaceball device which formats are independant of the type.

NOTE: Some data packets will contain an additional "special character" ('^' - 0x5e) inserted within the data stream. This escape character notifies the system to modify the following byte. If the following byte is 'Q', (0x51), 'S' (0x53), or an 'M' (0x4d) the seventh bit should be cleared. (Which should result in 0x11, 0x13, 0x0d respectively.) If the following character is a second '^' (0x5e) then no modification should be made. (Do not forget to remove the '^' character from the packet buffer.). This is currently not implemented. Therefore certain data packets may be ignored, specially if buttons 3 and 4 are pressed at the same time.

NOTE: The Ignore Packet is not implemented.

Spaceball, Spaceball 2003, Spaceball 3003 and Spaceball 4000 are Trademarks of Labtec Inc.

Version:
20. Aug. 2001 Copyright (c) Dipl. Ing. Paul Szawlowski

Author:
Dipl. Ing. Paul Szawlowski - University of Vienna, Dept. of Medical Computer Sciences

Field Summary
static byte BALL_DATA
           
static byte BUTTON_DATA
           
static int BUTTON_DATA_PACKET_LENGTH
           
static int[] BUTTON_MASK
           
static byte ECHO
           
static byte ERROR
           
static byte PACKET_TERMINATOR
           
static byte PATTERNED_BEEP
           
static int POSITION_DATA_PACKET_LENGTH
           
static byte RESET_DEVICE
          This command causes the Spaceball to RESET.
 
Constructor Summary
SpaceballPacket()
           
 
Method Summary
static int createEchoPacket(byte[] data, int offset, byte[] packetData)
          Echo this packet.
static int createPatternedBeepPacket(byte[] data, int offset, char[] pattern)
          This command causes the firmware to emit a beep.
static int createSimpleRequestPacket(byte[] data, int offset, byte request)
          Creates a simple request packet (packet which consists only of a header).
static void decodeBallData(byte[] readBuffer, int[] ballData, int packetStart)
           
protected static void decodeButtonData(int data, int[] buttonData, int[] buttonMask)
           
protected static int makeWord(byte firstByte, byte secondByte)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

POSITION_DATA_PACKET_LENGTH

public static final int POSITION_DATA_PACKET_LENGTH
See Also:
Constant Field Values

BUTTON_DATA_PACKET_LENGTH

public static final int BUTTON_DATA_PACKET_LENGTH
See Also:
Constant Field Values

BALL_DATA

public static final byte BALL_DATA
See Also:
Constant Field Values

BUTTON_DATA

public static final byte BUTTON_DATA
See Also:
Constant Field Values

PATTERNED_BEEP

public static final byte PATTERNED_BEEP
See Also:
Constant Field Values

ERROR

public static final byte ERROR
See Also:
Constant Field Values

ECHO

public static final byte ECHO
See Also:
Constant Field Values

RESET_DEVICE

public static final byte RESET_DEVICE
This command causes the Spaceball to RESET. This is a simple request packet (packet which consists only of a header).Packet size = 2 bytes.

See Also:
Constant Field Values

BUTTON_MASK

public static final int[] BUTTON_MASK

PACKET_TERMINATOR

public static final byte PACKET_TERMINATOR
See Also:
Constant Field Values
Constructor Detail

SpaceballPacket

public SpaceballPacket()
Method Detail

createPatternedBeepPacket

public static int createPatternedBeepPacket(byte[] data,
                                            int offset,
                                            char[] pattern)
This command causes the firmware to emit a beep. The beep pattern is determined by the data packets within the beep string.

Parameters:
data - buffer into which the packet will be copied; packet size = 2 byte + length of "pattern"
offset - first byte of packet will be copied at data[offset]
pattern - Up to 16 upper and lower case letters. Letters that are sooner in the alphabet stand for shorter beeps or pauses. Lower case letters mean beep on, upper cae letters mean beep off. The last character must be beep off.
Returns:
packet size

createSimpleRequestPacket

public static int createSimpleRequestPacket(byte[] data,
                                            int offset,
                                            byte request)
Creates a simple request packet (packet which consists only of a header).

Parameters:
data - buffer into which the packet will be copied; Packet size = 2 bytes.
offset - first byte of packet will be copied at data[offset]
request - header for the packet
Returns:
packet size

createEchoPacket

public static int createEchoPacket(byte[] data,
                                   int offset,
                                   byte[] packetData)
Echo this packet. The device responds by returning the same packet received.

Parameters:
data - buffer into which the packet will be copied; packet size = 2 byte + length of packetData.
offset - first byte of packet will be copied at data[offset]
packetData - Content of packet or null. NOTE: The length of the array + 2 must be smaller than the length of data - offset and the buffer used for receiving packets. The value 0x0D must not be contained.
Returns:
packet size

decodeBallData

public static void decodeBallData(byte[] readBuffer,
                                  int[] ballData,
                                  int packetStart)
Parameters:
ballData - Current position Data; size of array = 7. index 0: period of data (1/16th milliseconds), index 1 xTranslationForce x-axis translation force, index 2 yTranslationForce y-axis translation force, index 3 zTranslationForce z-axis translation force, index 4 xRotationalForce x-axis rotation force (positive values: counter clockwise rotation), index 5 yRotationalForce y-axis rotation force (positive values: counter clockwise rotation), index 6 zRotationalForce z-axis rotation force (positive values: counter clockwise rotation)

decodeButtonData

protected static void decodeButtonData(int data,
                                       int[] buttonData,
                                       int[] buttonMask)

makeWord

protected static int makeWord(byte firstByte,
                              byte secondByte)

j3d.org Code

Latest Info from http://code.j3d.org/
Copyright © 2001 - j3d.org