#include <stdio.h>
#include <signal.h>
#include <getopt.h>
#define I2C_BUS 2
typedef enum g_mode_t{
G_MODE_RAD,
G_MODE_DEG,
G_MODE_RAW
} g_mode_t;
typedef enum a_mode_t{
A_MODE_MS2,
A_MODE_G,
A_MODE_RAW
} a_mode_t;
static int enable_magnetometer = 0;
static int enable_thermometer = 0;
static int enable_warnings = 0;
static int running = 0;
static void __print_usage(void)
{
printf("\n");
printf("-a print raw adc values instead of radians\n");
printf("-r print gyro in radians/s instead of degrees/s\n");
printf("-g print acceleration in G instead of m/s^2\n");
printf("-m print magnetometer data as well as accel/gyro\n");
printf("-t print thermometer data as well as accel/gyro\n");
printf("-w print i2c warnings\n");
printf("-h print this help message\n");
printf("\n");
}
static void __signal_handler(__attribute__ ((unused)) int dummy)
{
running=0;
return;
}
int main(int argc, char *argv[])
{
int c;
g_mode_t g_mode = G_MODE_DEG;
a_mode_t a_mode = A_MODE_MS2;
opterr = 0;
while ((c = getopt(argc, argv, "argmtwh")) != -1){
switch (c){
case 'a':
g_mode = G_MODE_RAW;
a_mode = A_MODE_RAW;
printf("\nRaw values are from 16-bit ADC\n");
break;
case 'r':
g_mode = G_MODE_RAD;
break;
case 'g':
a_mode = A_MODE_G;
break;
case 'm':
enable_magnetometer = 1;
break;
case 't':
enable_thermometer = 1;
break;
case 'w':
enable_warnings = 1;
break;
case 'h':
__print_usage();
return 0;
default:
__print_usage();
return -1;
}
}
signal(SIGINT, __signal_handler);
running = 1;
fprintf(stderr,"rc_mpu_initialize_failed\n");
return -1;
}
printf("\ntry 'rc_test_mpu -h' to see other options\n\n");
switch(a_mode){
case A_MODE_MS2:
printf(" Accel XYZ(m/s^2) |");
break;
case A_MODE_G:
printf(" Accel XYZ(G) |");
break;
case A_MODE_RAW:
printf(" Accel XYZ(raw ADC) |");
break;
default:
printf("ERROR: invalid mode\n");
return -1;
}
switch(g_mode){
case G_MODE_RAD:
printf(" Gyro XYZ (rad/s) |");
break;
case G_MODE_DEG:
printf(" Gyro XYZ (deg/s) |");
break;
case G_MODE_RAW:
printf(" Gyro XYZ (raw ADC) |");
break;
default:
printf("ERROR: invalid mode\n");
return -1;
}
if(enable_magnetometer) printf(" Mag Field XYZ(uT) |");
if(enable_thermometer) printf(" Temp (C)");
printf("\n");
while (running) {
printf("\r");
printf("read accel data failed\n");
}
printf("read gyro data failed\n");
}
printf("read mag data failed\n");
}
printf("read imu thermometer failed\n");
}
switch(a_mode){
case A_MODE_MS2:
printf(
"%6.2f %6.2f %6.2f |", data.
accel[0],\
break;
case A_MODE_G:
break;
case A_MODE_RAW:
}
switch(g_mode){
case G_MODE_RAD:
break;
case G_MODE_DEG:
printf(
"%6.1f %6.1f %6.1f |", data.
gyro[0],\
break;
case G_MODE_RAW:
printf(
"%6d %6d %6d |", data.
raw_gyro[0],\
}
if(enable_magnetometer){
printf(
"%6.1f %6.1f %6.1f |", data.
mag[0],\
}
if(enable_thermometer){
printf(
" %4.1f ", data.
temp);
}
fflush(stdout);
}
printf("\n");
return 0;
}