Last active
July 15, 2017 08:20
-
-
Save ddemidov/b5aedd94ba86648f63377c09257f0b38 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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