Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions common/freespace_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -493,3 +493,36 @@ LIBFREESPACE_API int freespace_util_getActClass(struct freespace_MotionEngineOut
return 0;
}

/******************************************************************************
* freespace_util_getMouseAndButtons
*/
LIBFREESPACE_API int freespace_util_getMouseAndButtons(struct freespace_MotionEngineOutput const * meOutPkt,
struct MultiAxisSensor * sensor) {

switch (meOutPkt->formatSelect) {
case 0:
if (meOutPkt->ff0 == 0) {
return -1; // Mouse flag not set
}
break;
case 1:
case 2:
return -2; // No mouse data in this format
case 3:
if (meOutPkt->ff0 == 0) {
return -1; // Mouse flag not set
}
break;
default:
return -3; // The format number was unrecognized
}

// Extract and convert the mouse data
sensor->x = meOutPkt->meData[1]; // Delta X
sensor->y = meOutPkt->meData[3]; // Delta Y
sensor->z = meOutPkt->meData[5]; // Delta Wheel
sensor->w = meOutPkt->meData[0]; // Button bits

return 0;
}

16 changes: 16 additions & 0 deletions include/freespace/freespace_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,22 @@ LIBFREESPACE_API int freespace_util_getAngPos(struct freespace_MotionEngineOutpu
LIBFREESPACE_API int freespace_util_getActClass(struct freespace_MotionEngineOutput const * meOutPkt,
struct MultiAxisSensor * sensor);

/** @ingroup util
*
* Get the mouse and button values from a MEOut packet.
*
* For MEOut Format 0 and 3, X and Y units are mickeys, Z is detents and W is bitmask (0 - not pressed, 1 - pressed).
*
* @param meOutPkt A pointer to the MEOut packet to extract the mouse and buttons from.
* @param sensor A pointer to where to store the extracted 8-bit values. Uses X - Delta X, Y - Delta Y, Z - Delta Wheel, W - Button bits.
* @return 0 if successful
* -1 if the format flag was not set for the mouse and buttons field
* -2 if the meOutPkt does not contain mouse or buttons at all
* -3 if the format select number is unrecognized
*/
LIBFREESPACE_API int freespace_util_getMouseAndButtons(struct freespace_MotionEngineOutput const * meOutPkt,
struct MultiAxisSensor * sensor);

#ifdef __cplusplus
}
#endif
Expand Down