Skip to content

Instantly share code, notes, and snippets.

@ddemidov
Last active July 15, 2017 08:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ddemidov/b5aedd94ba86648f63377c09257f0b38 to your computer and use it in GitHub Desktop.
Save ddemidov/b5aedd94ba86648f63377c09257f0b38 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <ev3dev.h>
struct __attribute__((__packed__)) gyro_data {
struct {
signed char x, y, z;
} tilt;
struct {
short x, y, z;
} accel;
short compass;
struct {
short x, y, z;
} mag;
struct {
short x, y, z;
} gyro;
};
int main() {
ev3dev::sensor s("", { "ms-absolute-imu" });
std::cout << "connected: " << s.connected() << std::endl;
if (s.connected()) {
std::cout << "address: " << s.address() << std::endl;
std::cout << "driver_name: " << s.driver_name() << std::endl;
s.set_mode("ALL");
gyro_data data;
s.bin_data(&data);
#define SHOW(field) std::cout << #field << ": " << (int)data.field << std::endl
SHOW(tilt.x);
SHOW(tilt.y);
SHOW(tilt.z);
SHOW(accel.x);
SHOW(accel.y);
SHOW(accel.z);
SHOW(compass);
SHOW(mag.x);
SHOW(mag.y);
SHOW(mag.z);
SHOW(gyro.x);
SHOW(gyro.y);
SHOW(gyro.z);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment