18#if defined(VRPN_USE_HID)
21static const vrpn_uint16 LAPUTA_VENDOR = 0x2633;
22static const vrpn_uint16 LAPUTA_PRODUCT = 0x0006;
23static const vrpn_int32 NUM_CHANNELS = 11;
42 fprintf(stderr,
"vrpn_Laputa::~vrpn_Laputa(): delete failed\n");
65 vector[0] = s.si = (p.i >> 3) & 0x001fffff;
72 vector[1] = s.si = (p.i >> 6) & 0x001fffff;
79 vector[2] = s.si = (p.i >> 1) & 0x001fffff;
84 size_t num_reports = buffer[1];
85 if (num_reports > 3) {
91 vrpn_uint8 *bufptr = &buffer[2];
95 vrpn_uint16 report_index =
96 vrpn_unbuffer_from_little_endian<vrpn_uint16, vrpn_uint8>(bufptr);
101 vrpn_unbuffer_from_little_endian<vrpn_uint16, vrpn_uint8>(bufptr);
104 const double temperature_scale = 0.01;
105 vrpn_uint16 temperature =
106 vrpn_unbuffer_from_little_endian<vrpn_uint16, vrpn_uint8>(bufptr);
107 channel[0] = temperature * temperature_scale;
111 vrpn_uint8 *magnetometer_ptr = &buffer[56];
112 vrpn_int16 magnetometer_raw[3];
113 for (
size_t i = 0; i < 3; i++) {
114 magnetometer_raw[i] =
115 vrpn_unbuffer_from_little_endian<vrpn_int16, vrpn_uint8>(
120 const double magnetometer_scale = 0.0001;
121 channel[8] = -magnetometer_raw[0] * magnetometer_scale;
122 channel[9] = -magnetometer_raw[1] * magnetometer_scale;
123 channel[10] = -magnetometer_raw[2] * magnetometer_scale;
127 for (
size_t i = 0; i < num_reports; i++) {
128 vrpn_int32 accelerometer_raw[3];
129 vrpn_int32 gyroscope_raw[3];
139 const double accelerometer_scale = 0.0001;
140 const double gyroscope_scale = 0.0001;
142 static_cast<double>(accelerometer_raw[0]) * accelerometer_scale;
144 static_cast<double>(accelerometer_raw[1]) * accelerometer_scale;
146 static_cast<double>(accelerometer_raw[2]) * accelerometer_scale;
148 channel[5] =
static_cast<double>(gyroscope_raw[0]) * gyroscope_scale;
149 channel[6] =
static_cast<double>(gyroscope_raw[1]) * gyroscope_scale;
150 channel[7] =
static_cast<double>(gyroscope_raw[2]) * gyroscope_scale;
181 if ((bytes != 62) && (bytes != 64)) {
182 fprintf(stderr,
"vrpn_Laputa::on_data_received(): Unexpected message "
183 "length %d, ignoring\n",
184 static_cast<int>(bytes));
195 fprintf(stderr,
"vrpn_Laputa::on_data_received(): Unexpected "
196 "message type %d, ignoring\n",
vrpn_float64 last[vrpn_CHANNEL_MAX]
vrpn_float64 channel[vrpn_CHANNEL_MAX]
virtual void report_changes(vrpn_uint32 class_of_service=vrpn_CONNECTION_LOW_LATENCY, const struct timeval time=vrpn_ANALOG_NOW)
Send a report only if something has changed (for servers) Optionally, tell what time to stamp the val...
void server_mainloop(void)
Handles functions that all servers should provide in their mainloop() (ping/pong, for example) Should...
Generic connection class not specific to the transport mechanism.
vrpn_HidAcceptor * m_acceptor
This is the HidAcceptor we use when reconnecting.
virtual void update()
Polls the device buffers and causes on_data_received callbacks if appropriate You NEED to call this f...
Accepts any device with the given vendor and product IDs.
vrpn_Laputa(const char *name, vrpn_Connection *c=NULL)
virtual bool parse_message(std::size_t bytes, vrpn_uint8 *buffer)
struct timeval d_timestamp
Timestamp updated during mainloop()
virtual ~vrpn_Laputa()
Destructor.
void on_data_received(std::size_t bytes, vrpn_uint8 *buffer)
Extracts the sensor values from each report and calls the appropriate parser.
void parse_message_type_1(std::size_t bytes, vrpn_uint8 *buffer)
Parse and send reports for type-1 message.
virtual void mainloop()
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
All types of client/server/peer objects in VRPN should be derived from the vrpn_BaseClass type descri...
void unpackVector(const vrpn_uint8 raw[8], int vector[3])
Header for Laputa VR devices.
#define vrpn_gettimeofday