35 #include <libphidget22/phidget22.h>
43 bool is_hub_port_device,
44 std::function<
void(
const double[3],
double)> data_handler)
45 : data_handler_(data_handler)
47 PhidgetReturnCode ret = PhidgetGyroscope_create(&
gyro_handle_);
48 if (ret != EPHIDGET_OK)
54 reinterpret_cast<PhidgetHandle
>(
gyro_handle_), serial_number, hub_port,
55 is_hub_port_device, 0);
57 ret = PhidgetGyroscope_setOnAngularRateUpdateHandler(
gyro_handle_,
59 if (ret != EPHIDGET_OK)
61 throw Phidget22Error(
"Failed to set Gyroscope update handler", ret);
67 PhidgetHandle handle =
reinterpret_cast<PhidgetHandle
>(
gyro_handle_);
73 PhidgetReturnCode ret = PhidgetGyroscope_zero(
gyro_handle_);
74 if (ret != EPHIDGET_OK)
81 double ×tamp)
const
83 double angular_rate[3];
84 PhidgetReturnCode ret =
85 PhidgetGyroscope_getAngularRate(
gyro_handle_, &angular_rate);
86 if (ret != EPHIDGET_OK)
88 throw Phidget22Error(
"Failed to get angular rate from gyroscope", ret);
97 if (ret != EPHIDGET_OK)
99 throw Phidget22Error(
"Failed to get timestamp from gyroscope", ret);
107 PhidgetReturnCode ret =
108 PhidgetGyroscope_setDataInterval(
gyro_handle_, interval_ms);
109 if (ret != EPHIDGET_OK)
116 double timestamp)
const
122 void *ctx,
const double angular_rate[3],
125 ((
Gyroscope *)ctx)->dataHandler(angular_rate, timestamp);