From 9e6fa203ac93cf75992521cdd1b8e42447f320ea Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Wed, 16 Mar 2022 16:21:46 +0200 Subject: [PATCH] device type enumeration and queries --- proto.h | 34 +++++++++++++++++++++++++++++++++- spnav.c | 18 ++++++++++++++++++ spnav.h | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+), 1 deletion(-) diff --git a/proto.h b/proto.h index f95e4ff..0f3e927 100644 --- a/proto.h +++ b/proto.h @@ -28,8 +28,10 @@ enum { REQ_DEV_NAME = 0x2000, /* get device name: R[0] length R[6] status followed by bytes */ REQ_DEV_PATH, /* get device path: same as above */ - REQ_DEV_NAXES, /* get number of axes: R[0] num axes R[6] status */ + REQ_DEV_NAXES, /* get number of axes: R[0] num axes R[6] status */ REQ_DEV_NBUTTONS, /* get number of buttons: same as above */ + REQ_DEV_USBID, /* get USB id: R[0] vend R[1] prod R[6] status */ + REQ_DEV_TYPE, /* get device type: R[0] type enum R[6] status */ /* TODO: features like LCD, LEDs ... */ /* configuration settings */ @@ -62,4 +64,34 @@ enum { REQ_CHANGE_PROTO = 0x5500 }; +/* XXX keep in sync with SPNAV_DEV_* in spnav.h (libspnav) */ +enum { + DEV_UNKNOWN, + /* serial devices */ + DEV_SB2003 = 0x100, /* Spaceball 1003/2003/2003C */ + DEV_SB3003, /* Spaceball 3003/3003C */ + DEV_SB4000, /* Spaceball 4000FLX/5000FLX */ + DEV_SM, /* Magellan SpaceMouse */ + DEV_SM5000, /* Spaceball 5000 (spacemouse protocol) */ + DEV_SMCADMAN, /* 3Dconnexion CadMan (spacemouse protocol) */ + /* USB devices */ + DEV_PLUSXT = 0x200, /* SpaceMouse Plus XT */ + DEV_CADMAN, /* 3Dconnexion CadMan (USB version) */ + DEV_SMCLASSIC, /* SpaceMouse Classic */ + DEV_SB5000, /* Spaceball 5000 (USB version) */ + DEV_STRAVEL, /* Space Traveller */ + DEV_SPILOT, /* Space Pilot */ + DEV_SNAV, /* Space Navigator */ + DEV_SEXP, /* Space Explorer */ + DEV_SNAVNB, /* Space Navigator for Notebooks */ + DEV_SPILOTPRO, /* Space Pilot pro */ + DEV_SMPRO, /* SpaceMouse Pro */ + DEV_NULOOQ, /* Nulooq */ + DEV_SMW, /* SpaceMouse Wireless */ + DEV_SMPROW, /* SpaceMouse Pro Wireless */ + DEV_SMENT, /* SpaceMouse Enterprise */ + DEV_SMCOMP, /* SpaceMouse Compact */ + DEV_SMMOD /* SpaceMouse Module */ +}; + #endif /* PROTO_H_ */ diff --git a/spnav.c b/spnav.c index 45e4b11..0992c4c 100644 --- a/spnav.c +++ b/spnav.c @@ -769,7 +769,25 @@ int spnav_dev_axes(void) return rr.data[0]; } +int spnav_dev_usbid(unsigned int *vend, unsigned int *prod) +{ + struct reqresp rr = {0}; + if(request(REQ_DEV_USBID, &rr, TIMEOUT) == -1) { + return -1; + } + if(vend) *vend = rr.data[0]; + if(prod) *prod = rr.data[1]; + return 0; +} +int spnav_dev_type(void) +{ + struct reqresp rr = {0}; + if(request(REQ_DEV_TYPE, &rr, TIMEOUT) == -1) { + return -1; + } + return rr.data[0]; +} int spnav_cfg_set_sens(float s) { diff --git a/spnav.h b/spnav.h index 7f97255..9620537 100644 --- a/spnav.h +++ b/spnav.h @@ -168,6 +168,43 @@ int spnav_dev_buttons(void); /* returns the number of axes (defaults to 6 if unable to query) */ int spnav_dev_axes(void); +/* Writes the USB vendor:device ID through the vend/prod pointers. + * Returns 0 for success, or -1 on failure (for instance if there is no open + * device, or if it's not a USB device). + */ +int spnav_dev_usbid(unsigned int *vend, unsigned int *prod); + +enum { + SPNAV_DEV_UNKNOWN, + /* serial devices */ + SPNAV_DEV_SB2003 = 0x100, /* Spaceball 1003/2003/2003C */ + SPNAV_DEV_SB3003, /* Spaceball 3003/3003C */ + SPNAV_DEV_SB4000, /* Spaceball 4000FLX/5000FLX */ + SPNAV_DEV_SM, /* Magellan SpaceMouse */ + SPNAV_DEV_SM5000, /* Spaceball 5000 (spacemouse protocol) */ + SPNAV_DEV_SMCADMAN, /* 3Dconnexion CadMan (spacemouse protocol) */ + /* USB devices */ + SPNAV_DEV_PLUSXT = 0x200, /* SpaceMouse Plus XT */ + SPNAV_DEV_CADMAN, /* 3Dconnexion CadMan (USB version) */ + SPNAV_DEV_SMCLASSIC, /* SpaceMouse Classic */ + SPNAV_DEV_SB5000, /* Spaceball 5000 (USB version) */ + SPNAV_DEV_STRAVEL, /* Space Traveller */ + SPNAV_DEV_SPILOT, /* Space Pilot */ + SPNAV_DEV_SNAV, /* Space Navigator */ + SPNAV_DEV_SEXP, /* Space Explorer */ + SPNAV_DEV_SNAVNB, /* Space Navigator for Notebooks */ + SPNAV_DEV_SPILOTPRO, /* Space Pilot pro */ + SPNAV_DEV_SMPRO, /* SpaceMouse Pro */ + SPNAV_DEV_NULOOQ, /* NuLOOQ */ + SPNAV_DEV_SMW, /* SpaceMouse Wireless */ + SPNAV_DEV_SMPROW, /* SpaceMouse Pro Wireless */ + SPNAV_DEV_SMENT, /* SpaceMouse Enterprise */ + SPNAV_DEV_SMCOMP, /* SpaceMouse Compact */ + SPNAV_DEV_SMMOD /* SpaceMouse Module */ +}; + +/* Returns the device type (see enumeration above) or -1 on failure */ +int spnav_dev_type(void); /* configuration API * -----------------