00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #define IPCON_EXPOSE_INTERNALS
00013
00014 #include "brick_imu_v2.h"
00015
00016 #include <string.h>
00017
00018 #ifdef __cplusplus
00019 extern "C" {
00020 #endif
00021
00022
00023
00024 typedef void (*AccelerationCallbackFunction)(int16_t, int16_t, int16_t, void *);
00025
00026 typedef void (*MagneticFieldCallbackFunction)(int16_t, int16_t, int16_t, void *);
00027
00028 typedef void (*AngularVelocityCallbackFunction)(int16_t, int16_t, int16_t, void *);
00029
00030 typedef void (*TemperatureCallbackFunction)(int8_t, void *);
00031
00032 typedef void (*LinearAccelerationCallbackFunction)(int16_t, int16_t, int16_t, void *);
00033
00034 typedef void (*GravityVectorCallbackFunction)(int16_t, int16_t, int16_t, void *);
00035
00036 typedef void (*OrientationCallbackFunction)(int16_t, int16_t, int16_t, void *);
00037
00038 typedef void (*QuaternionCallbackFunction)(int16_t, int16_t, int16_t, int16_t, void *);
00039
00040 typedef void (*AllDataCallbackFunction)(int16_t[3], int16_t[3], int16_t[3], int16_t[3], int16_t[4], int16_t[3], int16_t[3], int8_t, uint8_t, void *);
00041
00042 #if defined _MSC_VER || defined __BORLANDC__
00043 #pragma pack(push)
00044 #pragma pack(1)
00045 #define ATTRIBUTE_PACKED
00046 #elif defined __GNUC__
00047 #ifdef _WIN32
00048
00049
00050 #define ATTRIBUTE_PACKED __attribute__((gcc_struct, packed))
00051 #else
00052 #define ATTRIBUTE_PACKED __attribute__((packed))
00053 #endif
00054 #else
00055 #error unknown compiler, do not know how to enable struct packing
00056 #endif
00057
00058 typedef struct {
00059 PacketHeader header;
00060 } ATTRIBUTE_PACKED GetAcceleration_;
00061
00062 typedef struct {
00063 PacketHeader header;
00064 int16_t x;
00065 int16_t y;
00066 int16_t z;
00067 } ATTRIBUTE_PACKED GetAccelerationResponse_;
00068
00069 typedef struct {
00070 PacketHeader header;
00071 } ATTRIBUTE_PACKED GetMagneticField_;
00072
00073 typedef struct {
00074 PacketHeader header;
00075 int16_t x;
00076 int16_t y;
00077 int16_t z;
00078 } ATTRIBUTE_PACKED GetMagneticFieldResponse_;
00079
00080 typedef struct {
00081 PacketHeader header;
00082 } ATTRIBUTE_PACKED GetAngularVelocity_;
00083
00084 typedef struct {
00085 PacketHeader header;
00086 int16_t x;
00087 int16_t y;
00088 int16_t z;
00089 } ATTRIBUTE_PACKED GetAngularVelocityResponse_;
00090
00091 typedef struct {
00092 PacketHeader header;
00093 } ATTRIBUTE_PACKED GetTemperature_;
00094
00095 typedef struct {
00096 PacketHeader header;
00097 int8_t temperature;
00098 } ATTRIBUTE_PACKED GetTemperatureResponse_;
00099
00100 typedef struct {
00101 PacketHeader header;
00102 } ATTRIBUTE_PACKED GetOrientation_;
00103
00104 typedef struct {
00105 PacketHeader header;
00106 int16_t heading;
00107 int16_t roll;
00108 int16_t pitch;
00109 } ATTRIBUTE_PACKED GetOrientationResponse_;
00110
00111 typedef struct {
00112 PacketHeader header;
00113 } ATTRIBUTE_PACKED GetLinearAcceleration_;
00114
00115 typedef struct {
00116 PacketHeader header;
00117 int16_t x;
00118 int16_t y;
00119 int16_t z;
00120 } ATTRIBUTE_PACKED GetLinearAccelerationResponse_;
00121
00122 typedef struct {
00123 PacketHeader header;
00124 } ATTRIBUTE_PACKED GetGravityVector_;
00125
00126 typedef struct {
00127 PacketHeader header;
00128 int16_t x;
00129 int16_t y;
00130 int16_t z;
00131 } ATTRIBUTE_PACKED GetGravityVectorResponse_;
00132
00133 typedef struct {
00134 PacketHeader header;
00135 } ATTRIBUTE_PACKED GetQuaternion_;
00136
00137 typedef struct {
00138 PacketHeader header;
00139 int16_t w;
00140 int16_t x;
00141 int16_t y;
00142 int16_t z;
00143 } ATTRIBUTE_PACKED GetQuaternionResponse_;
00144
00145 typedef struct {
00146 PacketHeader header;
00147 } ATTRIBUTE_PACKED GetAllData_;
00148
00149 typedef struct {
00150 PacketHeader header;
00151 int16_t acceleration[3];
00152 int16_t magnetic_field[3];
00153 int16_t angular_velocity[3];
00154 int16_t euler_angle[3];
00155 int16_t quaternion[4];
00156 int16_t linear_acceleration[3];
00157 int16_t gravity_vector[3];
00158 int8_t temperature;
00159 uint8_t calibration_status;
00160 } ATTRIBUTE_PACKED GetAllDataResponse_;
00161
00162 typedef struct {
00163 PacketHeader header;
00164 } ATTRIBUTE_PACKED LedsOn_;
00165
00166 typedef struct {
00167 PacketHeader header;
00168 } ATTRIBUTE_PACKED LedsOff_;
00169
00170 typedef struct {
00171 PacketHeader header;
00172 } ATTRIBUTE_PACKED AreLedsOn_;
00173
00174 typedef struct {
00175 PacketHeader header;
00176 bool leds;
00177 } ATTRIBUTE_PACKED AreLedsOnResponse_;
00178
00179 typedef struct {
00180 PacketHeader header;
00181 } ATTRIBUTE_PACKED SaveCalibration_;
00182
00183 typedef struct {
00184 PacketHeader header;
00185 bool calibration_done;
00186 } ATTRIBUTE_PACKED SaveCalibrationResponse_;
00187
00188 typedef struct {
00189 PacketHeader header;
00190 uint32_t period;
00191 } ATTRIBUTE_PACKED SetAccelerationPeriod_;
00192
00193 typedef struct {
00194 PacketHeader header;
00195 } ATTRIBUTE_PACKED GetAccelerationPeriod_;
00196
00197 typedef struct {
00198 PacketHeader header;
00199 uint32_t period;
00200 } ATTRIBUTE_PACKED GetAccelerationPeriodResponse_;
00201
00202 typedef struct {
00203 PacketHeader header;
00204 uint32_t period;
00205 } ATTRIBUTE_PACKED SetMagneticFieldPeriod_;
00206
00207 typedef struct {
00208 PacketHeader header;
00209 } ATTRIBUTE_PACKED GetMagneticFieldPeriod_;
00210
00211 typedef struct {
00212 PacketHeader header;
00213 uint32_t period;
00214 } ATTRIBUTE_PACKED GetMagneticFieldPeriodResponse_;
00215
00216 typedef struct {
00217 PacketHeader header;
00218 uint32_t period;
00219 } ATTRIBUTE_PACKED SetAngularVelocityPeriod_;
00220
00221 typedef struct {
00222 PacketHeader header;
00223 } ATTRIBUTE_PACKED GetAngularVelocityPeriod_;
00224
00225 typedef struct {
00226 PacketHeader header;
00227 uint32_t period;
00228 } ATTRIBUTE_PACKED GetAngularVelocityPeriodResponse_;
00229
00230 typedef struct {
00231 PacketHeader header;
00232 uint32_t period;
00233 } ATTRIBUTE_PACKED SetTemperaturePeriod_;
00234
00235 typedef struct {
00236 PacketHeader header;
00237 } ATTRIBUTE_PACKED GetTemperaturePeriod_;
00238
00239 typedef struct {
00240 PacketHeader header;
00241 uint32_t period;
00242 } ATTRIBUTE_PACKED GetTemperaturePeriodResponse_;
00243
00244 typedef struct {
00245 PacketHeader header;
00246 uint32_t period;
00247 } ATTRIBUTE_PACKED SetOrientationPeriod_;
00248
00249 typedef struct {
00250 PacketHeader header;
00251 } ATTRIBUTE_PACKED GetOrientationPeriod_;
00252
00253 typedef struct {
00254 PacketHeader header;
00255 uint32_t period;
00256 } ATTRIBUTE_PACKED GetOrientationPeriodResponse_;
00257
00258 typedef struct {
00259 PacketHeader header;
00260 uint32_t period;
00261 } ATTRIBUTE_PACKED SetLinearAccelerationPeriod_;
00262
00263 typedef struct {
00264 PacketHeader header;
00265 } ATTRIBUTE_PACKED GetLinearAccelerationPeriod_;
00266
00267 typedef struct {
00268 PacketHeader header;
00269 uint32_t period;
00270 } ATTRIBUTE_PACKED GetLinearAccelerationPeriodResponse_;
00271
00272 typedef struct {
00273 PacketHeader header;
00274 uint32_t period;
00275 } ATTRIBUTE_PACKED SetGravityVectorPeriod_;
00276
00277 typedef struct {
00278 PacketHeader header;
00279 } ATTRIBUTE_PACKED GetGravityVectorPeriod_;
00280
00281 typedef struct {
00282 PacketHeader header;
00283 uint32_t period;
00284 } ATTRIBUTE_PACKED GetGravityVectorPeriodResponse_;
00285
00286 typedef struct {
00287 PacketHeader header;
00288 uint32_t period;
00289 } ATTRIBUTE_PACKED SetQuaternionPeriod_;
00290
00291 typedef struct {
00292 PacketHeader header;
00293 } ATTRIBUTE_PACKED GetQuaternionPeriod_;
00294
00295 typedef struct {
00296 PacketHeader header;
00297 uint32_t period;
00298 } ATTRIBUTE_PACKED GetQuaternionPeriodResponse_;
00299
00300 typedef struct {
00301 PacketHeader header;
00302 uint32_t period;
00303 } ATTRIBUTE_PACKED SetAllDataPeriod_;
00304
00305 typedef struct {
00306 PacketHeader header;
00307 } ATTRIBUTE_PACKED GetAllDataPeriod_;
00308
00309 typedef struct {
00310 PacketHeader header;
00311 uint32_t period;
00312 } ATTRIBUTE_PACKED GetAllDataPeriodResponse_;
00313
00314 typedef struct {
00315 PacketHeader header;
00316 int16_t x;
00317 int16_t y;
00318 int16_t z;
00319 } ATTRIBUTE_PACKED AccelerationCallback_;
00320
00321 typedef struct {
00322 PacketHeader header;
00323 int16_t x;
00324 int16_t y;
00325 int16_t z;
00326 } ATTRIBUTE_PACKED MagneticFieldCallback_;
00327
00328 typedef struct {
00329 PacketHeader header;
00330 int16_t x;
00331 int16_t y;
00332 int16_t z;
00333 } ATTRIBUTE_PACKED AngularVelocityCallback_;
00334
00335 typedef struct {
00336 PacketHeader header;
00337 int8_t temperature;
00338 } ATTRIBUTE_PACKED TemperatureCallback_;
00339
00340 typedef struct {
00341 PacketHeader header;
00342 int16_t x;
00343 int16_t y;
00344 int16_t z;
00345 } ATTRIBUTE_PACKED LinearAccelerationCallback_;
00346
00347 typedef struct {
00348 PacketHeader header;
00349 int16_t x;
00350 int16_t y;
00351 int16_t z;
00352 } ATTRIBUTE_PACKED GravityVectorCallback_;
00353
00354 typedef struct {
00355 PacketHeader header;
00356 int16_t heading;
00357 int16_t roll;
00358 int16_t pitch;
00359 } ATTRIBUTE_PACKED OrientationCallback_;
00360
00361 typedef struct {
00362 PacketHeader header;
00363 int16_t w;
00364 int16_t x;
00365 int16_t y;
00366 int16_t z;
00367 } ATTRIBUTE_PACKED QuaternionCallback_;
00368
00369 typedef struct {
00370 PacketHeader header;
00371 int16_t acceleration[3];
00372 int16_t magnetic_field[3];
00373 int16_t angular_velocity[3];
00374 int16_t euler_angle[3];
00375 int16_t quaternion[4];
00376 int16_t linear_acceleration[3];
00377 int16_t gravity_vector[3];
00378 int8_t temperature;
00379 uint8_t calibration_status;
00380 } ATTRIBUTE_PACKED AllDataCallback_;
00381
00382 typedef struct {
00383 PacketHeader header;
00384 } ATTRIBUTE_PACKED EnableStatusLED_;
00385
00386 typedef struct {
00387 PacketHeader header;
00388 } ATTRIBUTE_PACKED DisableStatusLED_;
00389
00390 typedef struct {
00391 PacketHeader header;
00392 } ATTRIBUTE_PACKED IsStatusLEDEnabled_;
00393
00394 typedef struct {
00395 PacketHeader header;
00396 bool enabled;
00397 } ATTRIBUTE_PACKED IsStatusLEDEnabledResponse_;
00398
00399 typedef struct {
00400 PacketHeader header;
00401 char port;
00402 } ATTRIBUTE_PACKED GetProtocol1BrickletName_;
00403
00404 typedef struct {
00405 PacketHeader header;
00406 uint8_t protocol_version;
00407 uint8_t firmware_version[3];
00408 char name[40];
00409 } ATTRIBUTE_PACKED GetProtocol1BrickletNameResponse_;
00410
00411 typedef struct {
00412 PacketHeader header;
00413 } ATTRIBUTE_PACKED GetChipTemperature_;
00414
00415 typedef struct {
00416 PacketHeader header;
00417 int16_t temperature;
00418 } ATTRIBUTE_PACKED GetChipTemperatureResponse_;
00419
00420 typedef struct {
00421 PacketHeader header;
00422 } ATTRIBUTE_PACKED Reset_;
00423
00424 typedef struct {
00425 PacketHeader header;
00426 } ATTRIBUTE_PACKED GetIdentity_;
00427
00428 typedef struct {
00429 PacketHeader header;
00430 char uid[8];
00431 char connected_uid[8];
00432 char position;
00433 uint8_t hardware_version[3];
00434 uint8_t firmware_version[3];
00435 uint16_t device_identifier;
00436 } ATTRIBUTE_PACKED GetIdentityResponse_;
00437
00438 #if defined _MSC_VER || defined __BORLANDC__
00439 #pragma pack(pop)
00440 #endif
00441 #undef ATTRIBUTE_PACKED
00442
00443 static void imu_v2_callback_wrapper_acceleration(DevicePrivate *device_p, Packet *packet) {
00444 AccelerationCallbackFunction callback_function;
00445 void *user_data = device_p->registered_callback_user_data[IMU_V2_CALLBACK_ACCELERATION];
00446 AccelerationCallback_ *callback = (AccelerationCallback_ *)packet;
00447 *(void **)(&callback_function) = device_p->registered_callbacks[IMU_V2_CALLBACK_ACCELERATION];
00448
00449 if (callback_function == NULL) {
00450 return;
00451 }
00452
00453 callback->x = leconvert_int16_from(callback->x);
00454 callback->y = leconvert_int16_from(callback->y);
00455 callback->z = leconvert_int16_from(callback->z);
00456
00457 callback_function(callback->x, callback->y, callback->z, user_data);
00458 }
00459
00460 static void imu_v2_callback_wrapper_magnetic_field(DevicePrivate *device_p, Packet *packet) {
00461 MagneticFieldCallbackFunction callback_function;
00462 void *user_data = device_p->registered_callback_user_data[IMU_V2_CALLBACK_MAGNETIC_FIELD];
00463 MagneticFieldCallback_ *callback = (MagneticFieldCallback_ *)packet;
00464 *(void **)(&callback_function) = device_p->registered_callbacks[IMU_V2_CALLBACK_MAGNETIC_FIELD];
00465
00466 if (callback_function == NULL) {
00467 return;
00468 }
00469
00470 callback->x = leconvert_int16_from(callback->x);
00471 callback->y = leconvert_int16_from(callback->y);
00472 callback->z = leconvert_int16_from(callback->z);
00473
00474 callback_function(callback->x, callback->y, callback->z, user_data);
00475 }
00476
00477 static void imu_v2_callback_wrapper_angular_velocity(DevicePrivate *device_p, Packet *packet) {
00478 AngularVelocityCallbackFunction callback_function;
00479 void *user_data = device_p->registered_callback_user_data[IMU_V2_CALLBACK_ANGULAR_VELOCITY];
00480 AngularVelocityCallback_ *callback = (AngularVelocityCallback_ *)packet;
00481 *(void **)(&callback_function) = device_p->registered_callbacks[IMU_V2_CALLBACK_ANGULAR_VELOCITY];
00482
00483 if (callback_function == NULL) {
00484 return;
00485 }
00486
00487 callback->x = leconvert_int16_from(callback->x);
00488 callback->y = leconvert_int16_from(callback->y);
00489 callback->z = leconvert_int16_from(callback->z);
00490
00491 callback_function(callback->x, callback->y, callback->z, user_data);
00492 }
00493
00494 static void imu_v2_callback_wrapper_temperature(DevicePrivate *device_p, Packet *packet) {
00495 TemperatureCallbackFunction callback_function;
00496 void *user_data = device_p->registered_callback_user_data[IMU_V2_CALLBACK_TEMPERATURE];
00497 TemperatureCallback_ *callback = (TemperatureCallback_ *)packet;
00498 *(void **)(&callback_function) = device_p->registered_callbacks[IMU_V2_CALLBACK_TEMPERATURE];
00499
00500 if (callback_function == NULL) {
00501 return;
00502 }
00503
00504 callback_function(callback->temperature, user_data);
00505 }
00506
00507 static void imu_v2_callback_wrapper_linear_acceleration(DevicePrivate *device_p, Packet *packet) {
00508 LinearAccelerationCallbackFunction callback_function;
00509 void *user_data = device_p->registered_callback_user_data[IMU_V2_CALLBACK_LINEAR_ACCELERATION];
00510 LinearAccelerationCallback_ *callback = (LinearAccelerationCallback_ *)packet;
00511 *(void **)(&callback_function) = device_p->registered_callbacks[IMU_V2_CALLBACK_LINEAR_ACCELERATION];
00512
00513 if (callback_function == NULL) {
00514 return;
00515 }
00516
00517 callback->x = leconvert_int16_from(callback->x);
00518 callback->y = leconvert_int16_from(callback->y);
00519 callback->z = leconvert_int16_from(callback->z);
00520
00521 callback_function(callback->x, callback->y, callback->z, user_data);
00522 }
00523
00524 static void imu_v2_callback_wrapper_gravity_vector(DevicePrivate *device_p, Packet *packet) {
00525 GravityVectorCallbackFunction callback_function;
00526 void *user_data = device_p->registered_callback_user_data[IMU_V2_CALLBACK_GRAVITY_VECTOR];
00527 GravityVectorCallback_ *callback = (GravityVectorCallback_ *)packet;
00528 *(void **)(&callback_function) = device_p->registered_callbacks[IMU_V2_CALLBACK_GRAVITY_VECTOR];
00529
00530 if (callback_function == NULL) {
00531 return;
00532 }
00533
00534 callback->x = leconvert_int16_from(callback->x);
00535 callback->y = leconvert_int16_from(callback->y);
00536 callback->z = leconvert_int16_from(callback->z);
00537
00538 callback_function(callback->x, callback->y, callback->z, user_data);
00539 }
00540
00541 static void imu_v2_callback_wrapper_orientation(DevicePrivate *device_p, Packet *packet) {
00542 OrientationCallbackFunction callback_function;
00543 void *user_data = device_p->registered_callback_user_data[IMU_V2_CALLBACK_ORIENTATION];
00544 OrientationCallback_ *callback = (OrientationCallback_ *)packet;
00545 *(void **)(&callback_function) = device_p->registered_callbacks[IMU_V2_CALLBACK_ORIENTATION];
00546
00547 if (callback_function == NULL) {
00548 return;
00549 }
00550
00551 callback->heading = leconvert_int16_from(callback->heading);
00552 callback->roll = leconvert_int16_from(callback->roll);
00553 callback->pitch = leconvert_int16_from(callback->pitch);
00554
00555 callback_function(callback->heading, callback->roll, callback->pitch, user_data);
00556 }
00557
00558 static void imu_v2_callback_wrapper_quaternion(DevicePrivate *device_p, Packet *packet) {
00559 QuaternionCallbackFunction callback_function;
00560 void *user_data = device_p->registered_callback_user_data[IMU_V2_CALLBACK_QUATERNION];
00561 QuaternionCallback_ *callback = (QuaternionCallback_ *)packet;
00562 *(void **)(&callback_function) = device_p->registered_callbacks[IMU_V2_CALLBACK_QUATERNION];
00563
00564 if (callback_function == NULL) {
00565 return;
00566 }
00567
00568 callback->w = leconvert_int16_from(callback->w);
00569 callback->x = leconvert_int16_from(callback->x);
00570 callback->y = leconvert_int16_from(callback->y);
00571 callback->z = leconvert_int16_from(callback->z);
00572
00573 callback_function(callback->w, callback->x, callback->y, callback->z, user_data);
00574 }
00575
00576 static void imu_v2_callback_wrapper_all_data(DevicePrivate *device_p, Packet *packet) {
00577 AllDataCallbackFunction callback_function;
00578 void *user_data = device_p->registered_callback_user_data[IMU_V2_CALLBACK_ALL_DATA];
00579 int i;
00580 AllDataCallback_ *callback = (AllDataCallback_ *)packet;
00581 *(void **)(&callback_function) = device_p->registered_callbacks[IMU_V2_CALLBACK_ALL_DATA];
00582
00583 if (callback_function == NULL) {
00584 return;
00585 }
00586
00587 for (i = 0; i < 3; i++) callback->acceleration[i] = leconvert_int16_from(callback->acceleration[i]);
00588 for (i = 0; i < 3; i++) callback->magnetic_field[i] = leconvert_int16_from(callback->magnetic_field[i]);
00589 for (i = 0; i < 3; i++) callback->angular_velocity[i] = leconvert_int16_from(callback->angular_velocity[i]);
00590 for (i = 0; i < 3; i++) callback->euler_angle[i] = leconvert_int16_from(callback->euler_angle[i]);
00591 for (i = 0; i < 4; i++) callback->quaternion[i] = leconvert_int16_from(callback->quaternion[i]);
00592 for (i = 0; i < 3; i++) callback->linear_acceleration[i] = leconvert_int16_from(callback->linear_acceleration[i]);
00593 for (i = 0; i < 3; i++) callback->gravity_vector[i] = leconvert_int16_from(callback->gravity_vector[i]);
00594
00595 callback_function(callback->acceleration, callback->magnetic_field, callback->angular_velocity, callback->euler_angle, callback->quaternion, callback->linear_acceleration, callback->gravity_vector, callback->temperature, callback->calibration_status, user_data);
00596 }
00597
00598 void imu_v2_create(IMUV2 *imu_v2, const char *uid, IPConnection *ipcon) {
00599 DevicePrivate *device_p;
00600
00601 device_create(imu_v2, uid, ipcon->p, 2, 0, 0);
00602
00603 device_p = imu_v2->p;
00604
00605 device_p->response_expected[IMU_V2_FUNCTION_GET_ACCELERATION] = DEVICE_RESPONSE_EXPECTED_ALWAYS_TRUE;
00606 device_p->response_expected[IMU_V2_FUNCTION_GET_MAGNETIC_FIELD] = DEVICE_RESPONSE_EXPECTED_ALWAYS_TRUE;
00607 device_p->response_expected[IMU_V2_FUNCTION_GET_ANGULAR_VELOCITY] = DEVICE_RESPONSE_EXPECTED_ALWAYS_TRUE;
00608 device_p->response_expected[IMU_V2_FUNCTION_GET_TEMPERATURE] = DEVICE_RESPONSE_EXPECTED_ALWAYS_TRUE;
00609 device_p->response_expected[IMU_V2_FUNCTION_GET_ORIENTATION] = DEVICE_RESPONSE_EXPECTED_ALWAYS_TRUE;
00610 device_p->response_expected[IMU_V2_FUNCTION_GET_LINEAR_ACCELERATION] = DEVICE_RESPONSE_EXPECTED_ALWAYS_TRUE;
00611 device_p->response_expected[IMU_V2_FUNCTION_GET_GRAVITY_VECTOR] = DEVICE_RESPONSE_EXPECTED_ALWAYS_TRUE;
00612 device_p->response_expected[IMU_V2_FUNCTION_GET_QUATERNION] = DEVICE_RESPONSE_EXPECTED_ALWAYS_TRUE;
00613 device_p->response_expected[IMU_V2_FUNCTION_GET_ALL_DATA] = DEVICE_RESPONSE_EXPECTED_ALWAYS_TRUE;
00614 device_p->response_expected[IMU_V2_FUNCTION_LEDS_ON] = DEVICE_RESPONSE_EXPECTED_FALSE;
00615 device_p->response_expected[IMU_V2_FUNCTION_LEDS_OFF] = DEVICE_RESPONSE_EXPECTED_FALSE;
00616 device_p->response_expected[IMU_V2_FUNCTION_ARE_LEDS_ON] = DEVICE_RESPONSE_EXPECTED_ALWAYS_TRUE;
00617 device_p->response_expected[IMU_V2_FUNCTION_SAVE_CALIBRATION] = DEVICE_RESPONSE_EXPECTED_ALWAYS_TRUE;
00618 device_p->response_expected[IMU_V2_FUNCTION_SET_ACCELERATION_PERIOD] = DEVICE_RESPONSE_EXPECTED_TRUE;
00619 device_p->response_expected[IMU_V2_FUNCTION_GET_ACCELERATION_PERIOD] = DEVICE_RESPONSE_EXPECTED_ALWAYS_TRUE;
00620 device_p->response_expected[IMU_V2_FUNCTION_SET_MAGNETIC_FIELD_PERIOD] = DEVICE_RESPONSE_EXPECTED_TRUE;
00621 device_p->response_expected[IMU_V2_FUNCTION_GET_MAGNETIC_FIELD_PERIOD] = DEVICE_RESPONSE_EXPECTED_ALWAYS_TRUE;
00622 device_p->response_expected[IMU_V2_FUNCTION_SET_ANGULAR_VELOCITY_PERIOD] = DEVICE_RESPONSE_EXPECTED_TRUE;
00623 device_p->response_expected[IMU_V2_FUNCTION_GET_ANGULAR_VELOCITY_PERIOD] = DEVICE_RESPONSE_EXPECTED_ALWAYS_TRUE;
00624 device_p->response_expected[IMU_V2_FUNCTION_SET_TEMPERATURE_PERIOD] = DEVICE_RESPONSE_EXPECTED_TRUE;
00625 device_p->response_expected[IMU_V2_FUNCTION_GET_TEMPERATURE_PERIOD] = DEVICE_RESPONSE_EXPECTED_ALWAYS_TRUE;
00626 device_p->response_expected[IMU_V2_FUNCTION_SET_ORIENTATION_PERIOD] = DEVICE_RESPONSE_EXPECTED_TRUE;
00627 device_p->response_expected[IMU_V2_FUNCTION_GET_ORIENTATION_PERIOD] = DEVICE_RESPONSE_EXPECTED_ALWAYS_TRUE;
00628 device_p->response_expected[IMU_V2_FUNCTION_SET_LINEAR_ACCELERATION_PERIOD] = DEVICE_RESPONSE_EXPECTED_TRUE;
00629 device_p->response_expected[IMU_V2_FUNCTION_GET_LINEAR_ACCELERATION_PERIOD] = DEVICE_RESPONSE_EXPECTED_ALWAYS_TRUE;
00630 device_p->response_expected[IMU_V2_FUNCTION_SET_GRAVITY_VECTOR_PERIOD] = DEVICE_RESPONSE_EXPECTED_TRUE;
00631 device_p->response_expected[IMU_V2_FUNCTION_GET_GRAVITY_VECTOR_PERIOD] = DEVICE_RESPONSE_EXPECTED_ALWAYS_TRUE;
00632 device_p->response_expected[IMU_V2_FUNCTION_SET_QUATERNION_PERIOD] = DEVICE_RESPONSE_EXPECTED_TRUE;
00633 device_p->response_expected[IMU_V2_FUNCTION_GET_QUATERNION_PERIOD] = DEVICE_RESPONSE_EXPECTED_ALWAYS_TRUE;
00634 device_p->response_expected[IMU_V2_FUNCTION_SET_ALL_DATA_PERIOD] = DEVICE_RESPONSE_EXPECTED_TRUE;
00635 device_p->response_expected[IMU_V2_FUNCTION_GET_ALL_DATA_PERIOD] = DEVICE_RESPONSE_EXPECTED_ALWAYS_TRUE;
00636 device_p->response_expected[IMU_V2_CALLBACK_ACCELERATION] = DEVICE_RESPONSE_EXPECTED_ALWAYS_FALSE;
00637 device_p->response_expected[IMU_V2_CALLBACK_MAGNETIC_FIELD] = DEVICE_RESPONSE_EXPECTED_ALWAYS_FALSE;
00638 device_p->response_expected[IMU_V2_CALLBACK_ANGULAR_VELOCITY] = DEVICE_RESPONSE_EXPECTED_ALWAYS_FALSE;
00639 device_p->response_expected[IMU_V2_CALLBACK_TEMPERATURE] = DEVICE_RESPONSE_EXPECTED_ALWAYS_FALSE;
00640 device_p->response_expected[IMU_V2_CALLBACK_LINEAR_ACCELERATION] = DEVICE_RESPONSE_EXPECTED_ALWAYS_FALSE;
00641 device_p->response_expected[IMU_V2_CALLBACK_GRAVITY_VECTOR] = DEVICE_RESPONSE_EXPECTED_ALWAYS_FALSE;
00642 device_p->response_expected[IMU_V2_CALLBACK_ORIENTATION] = DEVICE_RESPONSE_EXPECTED_ALWAYS_FALSE;
00643 device_p->response_expected[IMU_V2_CALLBACK_QUATERNION] = DEVICE_RESPONSE_EXPECTED_ALWAYS_FALSE;
00644 device_p->response_expected[IMU_V2_CALLBACK_ALL_DATA] = DEVICE_RESPONSE_EXPECTED_ALWAYS_FALSE;
00645 device_p->response_expected[IMU_V2_FUNCTION_ENABLE_STATUS_LED] = DEVICE_RESPONSE_EXPECTED_FALSE;
00646 device_p->response_expected[IMU_V2_FUNCTION_DISABLE_STATUS_LED] = DEVICE_RESPONSE_EXPECTED_FALSE;
00647 device_p->response_expected[IMU_V2_FUNCTION_IS_STATUS_LED_ENABLED] = DEVICE_RESPONSE_EXPECTED_ALWAYS_TRUE;
00648 device_p->response_expected[IMU_V2_FUNCTION_GET_PROTOCOL1_BRICKLET_NAME] = DEVICE_RESPONSE_EXPECTED_ALWAYS_TRUE;
00649 device_p->response_expected[IMU_V2_FUNCTION_GET_CHIP_TEMPERATURE] = DEVICE_RESPONSE_EXPECTED_ALWAYS_TRUE;
00650 device_p->response_expected[IMU_V2_FUNCTION_RESET] = DEVICE_RESPONSE_EXPECTED_FALSE;
00651 device_p->response_expected[IMU_V2_FUNCTION_GET_IDENTITY] = DEVICE_RESPONSE_EXPECTED_ALWAYS_TRUE;
00652
00653 device_p->callback_wrappers[IMU_V2_CALLBACK_ACCELERATION] = imu_v2_callback_wrapper_acceleration;
00654 device_p->callback_wrappers[IMU_V2_CALLBACK_MAGNETIC_FIELD] = imu_v2_callback_wrapper_magnetic_field;
00655 device_p->callback_wrappers[IMU_V2_CALLBACK_ANGULAR_VELOCITY] = imu_v2_callback_wrapper_angular_velocity;
00656 device_p->callback_wrappers[IMU_V2_CALLBACK_TEMPERATURE] = imu_v2_callback_wrapper_temperature;
00657 device_p->callback_wrappers[IMU_V2_CALLBACK_LINEAR_ACCELERATION] = imu_v2_callback_wrapper_linear_acceleration;
00658 device_p->callback_wrappers[IMU_V2_CALLBACK_GRAVITY_VECTOR] = imu_v2_callback_wrapper_gravity_vector;
00659 device_p->callback_wrappers[IMU_V2_CALLBACK_ORIENTATION] = imu_v2_callback_wrapper_orientation;
00660 device_p->callback_wrappers[IMU_V2_CALLBACK_QUATERNION] = imu_v2_callback_wrapper_quaternion;
00661 device_p->callback_wrappers[IMU_V2_CALLBACK_ALL_DATA] = imu_v2_callback_wrapper_all_data;
00662 }
00663
00664 void imu_v2_destroy(IMUV2 *imu_v2) {
00665 device_release(imu_v2->p);
00666 }
00667
00668 int imu_v2_get_response_expected(IMUV2 *imu_v2, uint8_t function_id, bool *ret_response_expected) {
00669 return device_get_response_expected(imu_v2->p, function_id, ret_response_expected);
00670 }
00671
00672 int imu_v2_set_response_expected(IMUV2 *imu_v2, uint8_t function_id, bool response_expected) {
00673 return device_set_response_expected(imu_v2->p, function_id, response_expected);
00674 }
00675
00676 int imu_v2_set_response_expected_all(IMUV2 *imu_v2, bool response_expected) {
00677 return device_set_response_expected_all(imu_v2->p, response_expected);
00678 }
00679
00680 void imu_v2_register_callback(IMUV2 *imu_v2, uint8_t id, void *callback, void *user_data) {
00681 device_register_callback(imu_v2->p, id, callback, user_data);
00682 }
00683
00684 int imu_v2_get_api_version(IMUV2 *imu_v2, uint8_t ret_api_version[3]) {
00685 return device_get_api_version(imu_v2->p, ret_api_version);
00686 }
00687
00688 int imu_v2_get_acceleration(IMUV2 *imu_v2, int16_t *ret_x, int16_t *ret_y, int16_t *ret_z) {
00689 DevicePrivate *device_p = imu_v2->p;
00690 GetAcceleration_ request;
00691 GetAccelerationResponse_ response;
00692 int ret;
00693
00694 ret = packet_header_create(&request.header, sizeof(request), IMU_V2_FUNCTION_GET_ACCELERATION, device_p->ipcon_p, device_p);
00695
00696 if (ret < 0) {
00697 return ret;
00698 }
00699
00700
00701 ret = device_send_request(device_p, (Packet *)&request, (Packet *)&response);
00702
00703 if (ret < 0) {
00704 return ret;
00705 }
00706 *ret_x = leconvert_int16_from(response.x);
00707 *ret_y = leconvert_int16_from(response.y);
00708 *ret_z = leconvert_int16_from(response.z);
00709
00710
00711
00712 return ret;
00713 }
00714
00715 int imu_v2_get_magnetic_field(IMUV2 *imu_v2, int16_t *ret_x, int16_t *ret_y, int16_t *ret_z) {
00716 DevicePrivate *device_p = imu_v2->p;
00717 GetMagneticField_ request;
00718 GetMagneticFieldResponse_ response;
00719 int ret;
00720
00721 ret = packet_header_create(&request.header, sizeof(request), IMU_V2_FUNCTION_GET_MAGNETIC_FIELD, device_p->ipcon_p, device_p);
00722
00723 if (ret < 0) {
00724 return ret;
00725 }
00726
00727
00728 ret = device_send_request(device_p, (Packet *)&request, (Packet *)&response);
00729
00730 if (ret < 0) {
00731 return ret;
00732 }
00733 *ret_x = leconvert_int16_from(response.x);
00734 *ret_y = leconvert_int16_from(response.y);
00735 *ret_z = leconvert_int16_from(response.z);
00736
00737
00738
00739 return ret;
00740 }
00741
00742 int imu_v2_get_angular_velocity(IMUV2 *imu_v2, int16_t *ret_x, int16_t *ret_y, int16_t *ret_z) {
00743 DevicePrivate *device_p = imu_v2->p;
00744 GetAngularVelocity_ request;
00745 GetAngularVelocityResponse_ response;
00746 int ret;
00747
00748 ret = packet_header_create(&request.header, sizeof(request), IMU_V2_FUNCTION_GET_ANGULAR_VELOCITY, device_p->ipcon_p, device_p);
00749
00750 if (ret < 0) {
00751 return ret;
00752 }
00753
00754
00755 ret = device_send_request(device_p, (Packet *)&request, (Packet *)&response);
00756
00757 if (ret < 0) {
00758 return ret;
00759 }
00760 *ret_x = leconvert_int16_from(response.x);
00761 *ret_y = leconvert_int16_from(response.y);
00762 *ret_z = leconvert_int16_from(response.z);
00763
00764
00765
00766 return ret;
00767 }
00768
00769 int imu_v2_get_temperature(IMUV2 *imu_v2, int8_t *ret_temperature) {
00770 DevicePrivate *device_p = imu_v2->p;
00771 GetTemperature_ request;
00772 GetTemperatureResponse_ response;
00773 int ret;
00774
00775 ret = packet_header_create(&request.header, sizeof(request), IMU_V2_FUNCTION_GET_TEMPERATURE, device_p->ipcon_p, device_p);
00776
00777 if (ret < 0) {
00778 return ret;
00779 }
00780
00781
00782 ret = device_send_request(device_p, (Packet *)&request, (Packet *)&response);
00783
00784 if (ret < 0) {
00785 return ret;
00786 }
00787 *ret_temperature = response.temperature;
00788
00789
00790
00791 return ret;
00792 }
00793
00794 int imu_v2_get_orientation(IMUV2 *imu_v2, int16_t *ret_heading, int16_t *ret_roll, int16_t *ret_pitch) {
00795 DevicePrivate *device_p = imu_v2->p;
00796 GetOrientation_ request;
00797 GetOrientationResponse_ response;
00798 int ret;
00799
00800 ret = packet_header_create(&request.header, sizeof(request), IMU_V2_FUNCTION_GET_ORIENTATION, device_p->ipcon_p, device_p);
00801
00802 if (ret < 0) {
00803 return ret;
00804 }
00805
00806
00807 ret = device_send_request(device_p, (Packet *)&request, (Packet *)&response);
00808
00809 if (ret < 0) {
00810 return ret;
00811 }
00812 *ret_heading = leconvert_int16_from(response.heading);
00813 *ret_roll = leconvert_int16_from(response.roll);
00814 *ret_pitch = leconvert_int16_from(response.pitch);
00815
00816
00817
00818 return ret;
00819 }
00820
00821 int imu_v2_get_linear_acceleration(IMUV2 *imu_v2, int16_t *ret_x, int16_t *ret_y, int16_t *ret_z) {
00822 DevicePrivate *device_p = imu_v2->p;
00823 GetLinearAcceleration_ request;
00824 GetLinearAccelerationResponse_ response;
00825 int ret;
00826
00827 ret = packet_header_create(&request.header, sizeof(request), IMU_V2_FUNCTION_GET_LINEAR_ACCELERATION, device_p->ipcon_p, device_p);
00828
00829 if (ret < 0) {
00830 return ret;
00831 }
00832
00833
00834 ret = device_send_request(device_p, (Packet *)&request, (Packet *)&response);
00835
00836 if (ret < 0) {
00837 return ret;
00838 }
00839 *ret_x = leconvert_int16_from(response.x);
00840 *ret_y = leconvert_int16_from(response.y);
00841 *ret_z = leconvert_int16_from(response.z);
00842
00843
00844
00845 return ret;
00846 }
00847
00848 int imu_v2_get_gravity_vector(IMUV2 *imu_v2, int16_t *ret_x, int16_t *ret_y, int16_t *ret_z) {
00849 DevicePrivate *device_p = imu_v2->p;
00850 GetGravityVector_ request;
00851 GetGravityVectorResponse_ response;
00852 int ret;
00853
00854 ret = packet_header_create(&request.header, sizeof(request), IMU_V2_FUNCTION_GET_GRAVITY_VECTOR, device_p->ipcon_p, device_p);
00855
00856 if (ret < 0) {
00857 return ret;
00858 }
00859
00860
00861 ret = device_send_request(device_p, (Packet *)&request, (Packet *)&response);
00862
00863 if (ret < 0) {
00864 return ret;
00865 }
00866 *ret_x = leconvert_int16_from(response.x);
00867 *ret_y = leconvert_int16_from(response.y);
00868 *ret_z = leconvert_int16_from(response.z);
00869
00870
00871
00872 return ret;
00873 }
00874
00875 int imu_v2_get_quaternion(IMUV2 *imu_v2, int16_t *ret_w, int16_t *ret_x, int16_t *ret_y, int16_t *ret_z) {
00876 DevicePrivate *device_p = imu_v2->p;
00877 GetQuaternion_ request;
00878 GetQuaternionResponse_ response;
00879 int ret;
00880
00881 ret = packet_header_create(&request.header, sizeof(request), IMU_V2_FUNCTION_GET_QUATERNION, device_p->ipcon_p, device_p);
00882
00883 if (ret < 0) {
00884 return ret;
00885 }
00886
00887
00888 ret = device_send_request(device_p, (Packet *)&request, (Packet *)&response);
00889
00890 if (ret < 0) {
00891 return ret;
00892 }
00893 *ret_w = leconvert_int16_from(response.w);
00894 *ret_x = leconvert_int16_from(response.x);
00895 *ret_y = leconvert_int16_from(response.y);
00896 *ret_z = leconvert_int16_from(response.z);
00897
00898
00899
00900 return ret;
00901 }
00902
00903 int imu_v2_get_all_data(IMUV2 *imu_v2, int16_t ret_acceleration[3], int16_t ret_magnetic_field[3], int16_t ret_angular_velocity[3], int16_t ret_euler_angle[3], int16_t ret_quaternion[4], int16_t ret_linear_acceleration[3], int16_t ret_gravity_vector[3], int8_t *ret_temperature, uint8_t *ret_calibration_status) {
00904 DevicePrivate *device_p = imu_v2->p;
00905 GetAllData_ request;
00906 GetAllDataResponse_ response;
00907 int ret;
00908 int i;
00909
00910 ret = packet_header_create(&request.header, sizeof(request), IMU_V2_FUNCTION_GET_ALL_DATA, device_p->ipcon_p, device_p);
00911
00912 if (ret < 0) {
00913 return ret;
00914 }
00915
00916
00917 ret = device_send_request(device_p, (Packet *)&request, (Packet *)&response);
00918
00919 if (ret < 0) {
00920 return ret;
00921 }
00922 for (i = 0; i < 3; i++) ret_acceleration[i] = leconvert_int16_from(response.acceleration[i]);
00923 for (i = 0; i < 3; i++) ret_magnetic_field[i] = leconvert_int16_from(response.magnetic_field[i]);
00924 for (i = 0; i < 3; i++) ret_angular_velocity[i] = leconvert_int16_from(response.angular_velocity[i]);
00925 for (i = 0; i < 3; i++) ret_euler_angle[i] = leconvert_int16_from(response.euler_angle[i]);
00926 for (i = 0; i < 4; i++) ret_quaternion[i] = leconvert_int16_from(response.quaternion[i]);
00927 for (i = 0; i < 3; i++) ret_linear_acceleration[i] = leconvert_int16_from(response.linear_acceleration[i]);
00928 for (i = 0; i < 3; i++) ret_gravity_vector[i] = leconvert_int16_from(response.gravity_vector[i]);
00929 *ret_temperature = response.temperature;
00930 *ret_calibration_status = response.calibration_status;
00931
00932
00933
00934 return ret;
00935 }
00936
00937 int imu_v2_leds_on(IMUV2 *imu_v2) {
00938 DevicePrivate *device_p = imu_v2->p;
00939 LedsOn_ request;
00940 int ret;
00941
00942 ret = packet_header_create(&request.header, sizeof(request), IMU_V2_FUNCTION_LEDS_ON, device_p->ipcon_p, device_p);
00943
00944 if (ret < 0) {
00945 return ret;
00946 }
00947
00948
00949 ret = device_send_request(device_p, (Packet *)&request, NULL);
00950
00951
00952 return ret;
00953 }
00954
00955 int imu_v2_leds_off(IMUV2 *imu_v2) {
00956 DevicePrivate *device_p = imu_v2->p;
00957 LedsOff_ request;
00958 int ret;
00959
00960 ret = packet_header_create(&request.header, sizeof(request), IMU_V2_FUNCTION_LEDS_OFF, device_p->ipcon_p, device_p);
00961
00962 if (ret < 0) {
00963 return ret;
00964 }
00965
00966
00967 ret = device_send_request(device_p, (Packet *)&request, NULL);
00968
00969
00970 return ret;
00971 }
00972
00973 int imu_v2_are_leds_on(IMUV2 *imu_v2, bool *ret_leds) {
00974 DevicePrivate *device_p = imu_v2->p;
00975 AreLedsOn_ request;
00976 AreLedsOnResponse_ response;
00977 int ret;
00978
00979 ret = packet_header_create(&request.header, sizeof(request), IMU_V2_FUNCTION_ARE_LEDS_ON, device_p->ipcon_p, device_p);
00980
00981 if (ret < 0) {
00982 return ret;
00983 }
00984
00985
00986 ret = device_send_request(device_p, (Packet *)&request, (Packet *)&response);
00987
00988 if (ret < 0) {
00989 return ret;
00990 }
00991 *ret_leds = response.leds;
00992
00993
00994
00995 return ret;
00996 }
00997
00998 int imu_v2_save_calibration(IMUV2 *imu_v2, bool *ret_calibration_done) {
00999 DevicePrivate *device_p = imu_v2->p;
01000 SaveCalibration_ request;
01001 SaveCalibrationResponse_ response;
01002 int ret;
01003
01004 ret = packet_header_create(&request.header, sizeof(request), IMU_V2_FUNCTION_SAVE_CALIBRATION, device_p->ipcon_p, device_p);
01005
01006 if (ret < 0) {
01007 return ret;
01008 }
01009
01010
01011 ret = device_send_request(device_p, (Packet *)&request, (Packet *)&response);
01012
01013 if (ret < 0) {
01014 return ret;
01015 }
01016 *ret_calibration_done = response.calibration_done;
01017
01018
01019
01020 return ret;
01021 }
01022
01023 int imu_v2_set_acceleration_period(IMUV2 *imu_v2, uint32_t period) {
01024 DevicePrivate *device_p = imu_v2->p;
01025 SetAccelerationPeriod_ request;
01026 int ret;
01027
01028 ret = packet_header_create(&request.header, sizeof(request), IMU_V2_FUNCTION_SET_ACCELERATION_PERIOD, device_p->ipcon_p, device_p);
01029
01030 if (ret < 0) {
01031 return ret;
01032 }
01033
01034 request.period = leconvert_uint32_to(period);
01035
01036 ret = device_send_request(device_p, (Packet *)&request, NULL);
01037
01038
01039 return ret;
01040 }
01041
01042 int imu_v2_get_acceleration_period(IMUV2 *imu_v2, uint32_t *ret_period) {
01043 DevicePrivate *device_p = imu_v2->p;
01044 GetAccelerationPeriod_ request;
01045 GetAccelerationPeriodResponse_ response;
01046 int ret;
01047
01048 ret = packet_header_create(&request.header, sizeof(request), IMU_V2_FUNCTION_GET_ACCELERATION_PERIOD, device_p->ipcon_p, device_p);
01049
01050 if (ret < 0) {
01051 return ret;
01052 }
01053
01054
01055 ret = device_send_request(device_p, (Packet *)&request, (Packet *)&response);
01056
01057 if (ret < 0) {
01058 return ret;
01059 }
01060 *ret_period = leconvert_uint32_from(response.period);
01061
01062
01063
01064 return ret;
01065 }
01066
01067 int imu_v2_set_magnetic_field_period(IMUV2 *imu_v2, uint32_t period) {
01068 DevicePrivate *device_p = imu_v2->p;
01069 SetMagneticFieldPeriod_ request;
01070 int ret;
01071
01072 ret = packet_header_create(&request.header, sizeof(request), IMU_V2_FUNCTION_SET_MAGNETIC_FIELD_PERIOD, device_p->ipcon_p, device_p);
01073
01074 if (ret < 0) {
01075 return ret;
01076 }
01077
01078 request.period = leconvert_uint32_to(period);
01079
01080 ret = device_send_request(device_p, (Packet *)&request, NULL);
01081
01082
01083 return ret;
01084 }
01085
01086 int imu_v2_get_magnetic_field_period(IMUV2 *imu_v2, uint32_t *ret_period) {
01087 DevicePrivate *device_p = imu_v2->p;
01088 GetMagneticFieldPeriod_ request;
01089 GetMagneticFieldPeriodResponse_ response;
01090 int ret;
01091
01092 ret = packet_header_create(&request.header, sizeof(request), IMU_V2_FUNCTION_GET_MAGNETIC_FIELD_PERIOD, device_p->ipcon_p, device_p);
01093
01094 if (ret < 0) {
01095 return ret;
01096 }
01097
01098
01099 ret = device_send_request(device_p, (Packet *)&request, (Packet *)&response);
01100
01101 if (ret < 0) {
01102 return ret;
01103 }
01104 *ret_period = leconvert_uint32_from(response.period);
01105
01106
01107
01108 return ret;
01109 }
01110
01111 int imu_v2_set_angular_velocity_period(IMUV2 *imu_v2, uint32_t period) {
01112 DevicePrivate *device_p = imu_v2->p;
01113 SetAngularVelocityPeriod_ request;
01114 int ret;
01115
01116 ret = packet_header_create(&request.header, sizeof(request), IMU_V2_FUNCTION_SET_ANGULAR_VELOCITY_PERIOD, device_p->ipcon_p, device_p);
01117
01118 if (ret < 0) {
01119 return ret;
01120 }
01121
01122 request.period = leconvert_uint32_to(period);
01123
01124 ret = device_send_request(device_p, (Packet *)&request, NULL);
01125
01126
01127 return ret;
01128 }
01129
01130 int imu_v2_get_angular_velocity_period(IMUV2 *imu_v2, uint32_t *ret_period) {
01131 DevicePrivate *device_p = imu_v2->p;
01132 GetAngularVelocityPeriod_ request;
01133 GetAngularVelocityPeriodResponse_ response;
01134 int ret;
01135
01136 ret = packet_header_create(&request.header, sizeof(request), IMU_V2_FUNCTION_GET_ANGULAR_VELOCITY_PERIOD, device_p->ipcon_p, device_p);
01137
01138 if (ret < 0) {
01139 return ret;
01140 }
01141
01142
01143 ret = device_send_request(device_p, (Packet *)&request, (Packet *)&response);
01144
01145 if (ret < 0) {
01146 return ret;
01147 }
01148 *ret_period = leconvert_uint32_from(response.period);
01149
01150
01151
01152 return ret;
01153 }
01154
01155 int imu_v2_set_temperature_period(IMUV2 *imu_v2, uint32_t period) {
01156 DevicePrivate *device_p = imu_v2->p;
01157 SetTemperaturePeriod_ request;
01158 int ret;
01159
01160 ret = packet_header_create(&request.header, sizeof(request), IMU_V2_FUNCTION_SET_TEMPERATURE_PERIOD, device_p->ipcon_p, device_p);
01161
01162 if (ret < 0) {
01163 return ret;
01164 }
01165
01166 request.period = leconvert_uint32_to(period);
01167
01168 ret = device_send_request(device_p, (Packet *)&request, NULL);
01169
01170
01171 return ret;
01172 }
01173
01174 int imu_v2_get_temperature_period(IMUV2 *imu_v2, uint32_t *ret_period) {
01175 DevicePrivate *device_p = imu_v2->p;
01176 GetTemperaturePeriod_ request;
01177 GetTemperaturePeriodResponse_ response;
01178 int ret;
01179
01180 ret = packet_header_create(&request.header, sizeof(request), IMU_V2_FUNCTION_GET_TEMPERATURE_PERIOD, device_p->ipcon_p, device_p);
01181
01182 if (ret < 0) {
01183 return ret;
01184 }
01185
01186
01187 ret = device_send_request(device_p, (Packet *)&request, (Packet *)&response);
01188
01189 if (ret < 0) {
01190 return ret;
01191 }
01192 *ret_period = leconvert_uint32_from(response.period);
01193
01194
01195
01196 return ret;
01197 }
01198
01199 int imu_v2_set_orientation_period(IMUV2 *imu_v2, uint32_t period) {
01200 DevicePrivate *device_p = imu_v2->p;
01201 SetOrientationPeriod_ request;
01202 int ret;
01203
01204 ret = packet_header_create(&request.header, sizeof(request), IMU_V2_FUNCTION_SET_ORIENTATION_PERIOD, device_p->ipcon_p, device_p);
01205
01206 if (ret < 0) {
01207 return ret;
01208 }
01209
01210 request.period = leconvert_uint32_to(period);
01211
01212 ret = device_send_request(device_p, (Packet *)&request, NULL);
01213
01214
01215 return ret;
01216 }
01217
01218 int imu_v2_get_orientation_period(IMUV2 *imu_v2, uint32_t *ret_period) {
01219 DevicePrivate *device_p = imu_v2->p;
01220 GetOrientationPeriod_ request;
01221 GetOrientationPeriodResponse_ response;
01222 int ret;
01223
01224 ret = packet_header_create(&request.header, sizeof(request), IMU_V2_FUNCTION_GET_ORIENTATION_PERIOD, device_p->ipcon_p, device_p);
01225
01226 if (ret < 0) {
01227 return ret;
01228 }
01229
01230
01231 ret = device_send_request(device_p, (Packet *)&request, (Packet *)&response);
01232
01233 if (ret < 0) {
01234 return ret;
01235 }
01236 *ret_period = leconvert_uint32_from(response.period);
01237
01238
01239
01240 return ret;
01241 }
01242
01243 int imu_v2_set_linear_acceleration_period(IMUV2 *imu_v2, uint32_t period) {
01244 DevicePrivate *device_p = imu_v2->p;
01245 SetLinearAccelerationPeriod_ request;
01246 int ret;
01247
01248 ret = packet_header_create(&request.header, sizeof(request), IMU_V2_FUNCTION_SET_LINEAR_ACCELERATION_PERIOD, device_p->ipcon_p, device_p);
01249
01250 if (ret < 0) {
01251 return ret;
01252 }
01253
01254 request.period = leconvert_uint32_to(period);
01255
01256 ret = device_send_request(device_p, (Packet *)&request, NULL);
01257
01258
01259 return ret;
01260 }
01261
01262 int imu_v2_get_linear_acceleration_period(IMUV2 *imu_v2, uint32_t *ret_period) {
01263 DevicePrivate *device_p = imu_v2->p;
01264 GetLinearAccelerationPeriod_ request;
01265 GetLinearAccelerationPeriodResponse_ response;
01266 int ret;
01267
01268 ret = packet_header_create(&request.header, sizeof(request), IMU_V2_FUNCTION_GET_LINEAR_ACCELERATION_PERIOD, device_p->ipcon_p, device_p);
01269
01270 if (ret < 0) {
01271 return ret;
01272 }
01273
01274
01275 ret = device_send_request(device_p, (Packet *)&request, (Packet *)&response);
01276
01277 if (ret < 0) {
01278 return ret;
01279 }
01280 *ret_period = leconvert_uint32_from(response.period);
01281
01282
01283
01284 return ret;
01285 }
01286
01287 int imu_v2_set_gravity_vector_period(IMUV2 *imu_v2, uint32_t period) {
01288 DevicePrivate *device_p = imu_v2->p;
01289 SetGravityVectorPeriod_ request;
01290 int ret;
01291
01292 ret = packet_header_create(&request.header, sizeof(request), IMU_V2_FUNCTION_SET_GRAVITY_VECTOR_PERIOD, device_p->ipcon_p, device_p);
01293
01294 if (ret < 0) {
01295 return ret;
01296 }
01297
01298 request.period = leconvert_uint32_to(period);
01299
01300 ret = device_send_request(device_p, (Packet *)&request, NULL);
01301
01302
01303 return ret;
01304 }
01305
01306 int imu_v2_get_gravity_vector_period(IMUV2 *imu_v2, uint32_t *ret_period) {
01307 DevicePrivate *device_p = imu_v2->p;
01308 GetGravityVectorPeriod_ request;
01309 GetGravityVectorPeriodResponse_ response;
01310 int ret;
01311
01312 ret = packet_header_create(&request.header, sizeof(request), IMU_V2_FUNCTION_GET_GRAVITY_VECTOR_PERIOD, device_p->ipcon_p, device_p);
01313
01314 if (ret < 0) {
01315 return ret;
01316 }
01317
01318
01319 ret = device_send_request(device_p, (Packet *)&request, (Packet *)&response);
01320
01321 if (ret < 0) {
01322 return ret;
01323 }
01324 *ret_period = leconvert_uint32_from(response.period);
01325
01326
01327
01328 return ret;
01329 }
01330
01331 int imu_v2_set_quaternion_period(IMUV2 *imu_v2, uint32_t period) {
01332 DevicePrivate *device_p = imu_v2->p;
01333 SetQuaternionPeriod_ request;
01334 int ret;
01335
01336 ret = packet_header_create(&request.header, sizeof(request), IMU_V2_FUNCTION_SET_QUATERNION_PERIOD, device_p->ipcon_p, device_p);
01337
01338 if (ret < 0) {
01339 return ret;
01340 }
01341
01342 request.period = leconvert_uint32_to(period);
01343
01344 ret = device_send_request(device_p, (Packet *)&request, NULL);
01345
01346
01347 return ret;
01348 }
01349
01350 int imu_v2_get_quaternion_period(IMUV2 *imu_v2, uint32_t *ret_period) {
01351 DevicePrivate *device_p = imu_v2->p;
01352 GetQuaternionPeriod_ request;
01353 GetQuaternionPeriodResponse_ response;
01354 int ret;
01355
01356 ret = packet_header_create(&request.header, sizeof(request), IMU_V2_FUNCTION_GET_QUATERNION_PERIOD, device_p->ipcon_p, device_p);
01357
01358 if (ret < 0) {
01359 return ret;
01360 }
01361
01362
01363 ret = device_send_request(device_p, (Packet *)&request, (Packet *)&response);
01364
01365 if (ret < 0) {
01366 return ret;
01367 }
01368 *ret_period = leconvert_uint32_from(response.period);
01369
01370
01371
01372 return ret;
01373 }
01374
01375 int imu_v2_set_all_data_period(IMUV2 *imu_v2, uint32_t period) {
01376 DevicePrivate *device_p = imu_v2->p;
01377 SetAllDataPeriod_ request;
01378 int ret;
01379
01380 ret = packet_header_create(&request.header, sizeof(request), IMU_V2_FUNCTION_SET_ALL_DATA_PERIOD, device_p->ipcon_p, device_p);
01381
01382 if (ret < 0) {
01383 return ret;
01384 }
01385
01386 request.period = leconvert_uint32_to(period);
01387
01388 ret = device_send_request(device_p, (Packet *)&request, NULL);
01389
01390
01391 return ret;
01392 }
01393
01394 int imu_v2_get_all_data_period(IMUV2 *imu_v2, uint32_t *ret_period) {
01395 DevicePrivate *device_p = imu_v2->p;
01396 GetAllDataPeriod_ request;
01397 GetAllDataPeriodResponse_ response;
01398 int ret;
01399
01400 ret = packet_header_create(&request.header, sizeof(request), IMU_V2_FUNCTION_GET_ALL_DATA_PERIOD, device_p->ipcon_p, device_p);
01401
01402 if (ret < 0) {
01403 return ret;
01404 }
01405
01406
01407 ret = device_send_request(device_p, (Packet *)&request, (Packet *)&response);
01408
01409 if (ret < 0) {
01410 return ret;
01411 }
01412 *ret_period = leconvert_uint32_from(response.period);
01413
01414
01415
01416 return ret;
01417 }
01418
01419 int imu_v2_enable_status_led(IMUV2 *imu_v2) {
01420 DevicePrivate *device_p = imu_v2->p;
01421 EnableStatusLED_ request;
01422 int ret;
01423
01424 ret = packet_header_create(&request.header, sizeof(request), IMU_V2_FUNCTION_ENABLE_STATUS_LED, device_p->ipcon_p, device_p);
01425
01426 if (ret < 0) {
01427 return ret;
01428 }
01429
01430
01431 ret = device_send_request(device_p, (Packet *)&request, NULL);
01432
01433
01434 return ret;
01435 }
01436
01437 int imu_v2_disable_status_led(IMUV2 *imu_v2) {
01438 DevicePrivate *device_p = imu_v2->p;
01439 DisableStatusLED_ request;
01440 int ret;
01441
01442 ret = packet_header_create(&request.header, sizeof(request), IMU_V2_FUNCTION_DISABLE_STATUS_LED, device_p->ipcon_p, device_p);
01443
01444 if (ret < 0) {
01445 return ret;
01446 }
01447
01448
01449 ret = device_send_request(device_p, (Packet *)&request, NULL);
01450
01451
01452 return ret;
01453 }
01454
01455 int imu_v2_is_status_led_enabled(IMUV2 *imu_v2, bool *ret_enabled) {
01456 DevicePrivate *device_p = imu_v2->p;
01457 IsStatusLEDEnabled_ request;
01458 IsStatusLEDEnabledResponse_ response;
01459 int ret;
01460
01461 ret = packet_header_create(&request.header, sizeof(request), IMU_V2_FUNCTION_IS_STATUS_LED_ENABLED, device_p->ipcon_p, device_p);
01462
01463 if (ret < 0) {
01464 return ret;
01465 }
01466
01467
01468 ret = device_send_request(device_p, (Packet *)&request, (Packet *)&response);
01469
01470 if (ret < 0) {
01471 return ret;
01472 }
01473 *ret_enabled = response.enabled;
01474
01475
01476
01477 return ret;
01478 }
01479
01480 int imu_v2_get_protocol1_bricklet_name(IMUV2 *imu_v2, char port, uint8_t *ret_protocol_version, uint8_t ret_firmware_version[3], char ret_name[40]) {
01481 DevicePrivate *device_p = imu_v2->p;
01482 GetProtocol1BrickletName_ request;
01483 GetProtocol1BrickletNameResponse_ response;
01484 int ret;
01485
01486 ret = packet_header_create(&request.header, sizeof(request), IMU_V2_FUNCTION_GET_PROTOCOL1_BRICKLET_NAME, device_p->ipcon_p, device_p);
01487
01488 if (ret < 0) {
01489 return ret;
01490 }
01491
01492 request.port = port;
01493
01494 ret = device_send_request(device_p, (Packet *)&request, (Packet *)&response);
01495
01496 if (ret < 0) {
01497 return ret;
01498 }
01499 *ret_protocol_version = response.protocol_version;
01500 memcpy(ret_firmware_version, response.firmware_version, 3 * sizeof(uint8_t));
01501 strncpy(ret_name, response.name, 40);
01502
01503
01504
01505 return ret;
01506 }
01507
01508 int imu_v2_get_chip_temperature(IMUV2 *imu_v2, int16_t *ret_temperature) {
01509 DevicePrivate *device_p = imu_v2->p;
01510 GetChipTemperature_ request;
01511 GetChipTemperatureResponse_ response;
01512 int ret;
01513
01514 ret = packet_header_create(&request.header, sizeof(request), IMU_V2_FUNCTION_GET_CHIP_TEMPERATURE, device_p->ipcon_p, device_p);
01515
01516 if (ret < 0) {
01517 return ret;
01518 }
01519
01520
01521 ret = device_send_request(device_p, (Packet *)&request, (Packet *)&response);
01522
01523 if (ret < 0) {
01524 return ret;
01525 }
01526 *ret_temperature = leconvert_int16_from(response.temperature);
01527
01528
01529
01530 return ret;
01531 }
01532
01533 int imu_v2_reset(IMUV2 *imu_v2) {
01534 DevicePrivate *device_p = imu_v2->p;
01535 Reset_ request;
01536 int ret;
01537
01538 ret = packet_header_create(&request.header, sizeof(request), IMU_V2_FUNCTION_RESET, device_p->ipcon_p, device_p);
01539
01540 if (ret < 0) {
01541 return ret;
01542 }
01543
01544
01545 ret = device_send_request(device_p, (Packet *)&request, NULL);
01546
01547
01548 return ret;
01549 }
01550
01551 int imu_v2_get_identity(IMUV2 *imu_v2, char ret_uid[8], char ret_connected_uid[8], char *ret_position, uint8_t ret_hardware_version[3], uint8_t ret_firmware_version[3], uint16_t *ret_device_identifier) {
01552 DevicePrivate *device_p = imu_v2->p;
01553 GetIdentity_ request;
01554 GetIdentityResponse_ response;
01555 int ret;
01556
01557 ret = packet_header_create(&request.header, sizeof(request), IMU_V2_FUNCTION_GET_IDENTITY, device_p->ipcon_p, device_p);
01558
01559 if (ret < 0) {
01560 return ret;
01561 }
01562
01563
01564 ret = device_send_request(device_p, (Packet *)&request, (Packet *)&response);
01565
01566 if (ret < 0) {
01567 return ret;
01568 }
01569 strncpy(ret_uid, response.uid, 8);
01570 strncpy(ret_connected_uid, response.connected_uid, 8);
01571 *ret_position = response.position;
01572 memcpy(ret_hardware_version, response.hardware_version, 3 * sizeof(uint8_t));
01573 memcpy(ret_firmware_version, response.firmware_version, 3 * sizeof(uint8_t));
01574 *ret_device_identifier = leconvert_uint16_from(response.device_identifier);
01575
01576
01577
01578 return ret;
01579 }
01580
01581 #ifdef __cplusplus
01582 }
01583 #endif