#include <stdio.h>
#include <getopt.h>
#include <signal.h>
#include <stdlib.h>
#define I2C_BUS 2
#define GPIO_INT_PIN_CHIP 3
#define GPIO_INT_PIN_PIN 21
static int running = 0;
static int silent_mode = 0;
static int show_accel = 0;
static int show_gyro = 0;
static int enable_mag = 0;
static int show_compass = 0;
static int show_temp = 0;
static int show_quat = 0;
static int show_tb = 0;
static int orientation_menu = 0;
static void __print_usage(void);
static void __print_data(void);
static void __print_header(void);
static void __print_usage(void)
{
printf("\n Options\n");
printf("-r {rate} Set sample rate in HZ (default 100)\n");
printf(" Sample rate must be a divisor of 200\n");
printf("-m Enable Magnetometer\n");
printf("-b Enable Reading Magnetometer before ISR (default after)\n");
printf("-c Show raw compass angle\n");
printf("-a Print Accelerometer Data\n");
printf("-g Print Gyro Data\n");
printf("-T Print Temperature\n");
printf("-t Print TaitBryan Angles\n");
printf("-q Print Quaternion Vector\n");
printf("-p {prio} Set Interrupt Priority and FIFO scheduling policy (requires root)\n");
printf("-w Print I2C bus warnings\n");
printf("-o Show a menu to select IMU orientation\n");
printf("-h Print this help message\n\n");
return;
}
static void __print_data(void)
{
printf("\r");
printf(" ");
if(show_compass){
}
if(show_quat && enable_mag){
}
else if(show_quat){
}
if(show_tb && enable_mag){
}
else if(show_tb){
}
if(show_accel){
printf(
" %5.2f %5.2f %5.2f |", data.
accel[0],\
}
if(show_gyro){
printf(
" %5.1f %5.1f %5.1f |", data.
gyro[0],\
}
if(show_temp){
printf(
" %6.2f |", data.
temp);
}
fflush(stdout);
return;
}
static void __print_header(void)
{
printf(" ");
if(show_compass){
printf("Raw Compass |");
printf("FilteredComp|");
}
if(enable_mag){
if(show_quat) printf(" Fused Quaternion |");
if(show_tb) printf(" FusedTaitBryan(deg) |");
} else{
if(show_quat) printf(" DMP Quaternion |");
if(show_tb) printf(" DMP TaitBryan (deg) |");
}
if(show_accel) printf(" Accel XYZ (m/s^2) |");
if(show_gyro) printf(" Gyro XYZ (deg/s) |");
if(show_temp) printf(" Temp(C)|");
printf("\n");
}
static void __signal_handler(__attribute__ ((unused)) int dummy)
{
running=0;
return;
}
int c;
printf("\n");
printf("Please select a number 1-6 corresponding to the\n");
printf("orientation you wish to use. Press 'q' to exit.\n\n");
printf(" 1: ORIENTATION_Z_UP\n");
printf(" 2: ORIENTATION_Z_DOWN\n");
printf(" 3: ORIENTATION_X_UP\n");
printf(" 4: ORIENTATION_X_DOWN\n");
printf(" 5: ORIENTATION_Y_UP\n");
printf(" 6: ORIENTATION_Y_DOWN\n");
printf(" 7: ORIENTATION_X_FORWARD\n");
printf(" 8: ORIENTATION_X_BACK\n");
while ((c = getchar()) != EOF){
switch(c){
case '1':
break;
case '2':
break;
case '3':
break;
case '4':
break;
case '5':
break;
case '6':
break;
case '7':
break;
case '8':
break;
case 'q':
printf("Quitting\n");
exit(0);
case '\n':
break;
default:
printf("invalid input\n");
break;
}
}
return 0;
}
int main(int argc, char *argv[])
{
int c, sample_rate, priority;
int show_something = 0;
opterr = 0;
while ((c=getopt(argc, argv, "sr:mbagrqTtcp:hwo"))!=-1 && argc>1){
switch (c){
case 's':
silent_mode = 1;
show_something = 1;
break;
case 'r':
sample_rate = atoi(optarg);
if(sample_rate>200 || sample_rate<4){
printf("sample_rate must be between 4 & 200");
return -1;
}
break;
case 'p':
priority = atoi(optarg);
break;
case 'm':
show_something = 1;
enable_mag = 1;
break;
case 'b':
break;
case 'c':
show_something = 1;
enable_mag = 1;
show_compass = 1;
break;
case 'a':
show_something = 1;
show_accel = 1;
break;
case 'g':
show_something = 1;
show_gyro = 1;
break;
case 'q':
show_something = 1;
show_quat = 1;
break;
case 't':
show_something = 1;
show_tb = 1;
break;
case 'T':
show_something = 1;
show_temp = 1;
break;
case 'w':
break;
case 'o':
orientation_menu=1;
break;
case 'h':
__print_usage();
return -1;
break;
default:
printf("opt: %c\n",c);
printf("invalid argument\n");
__print_usage();
return -1;
break;
}
}
if(show_something==0){
__print_usage();
printf("please enable an option to print some data\n");
return -1;
}
if(orientation_menu){
conf.
orient=__orientation_prompt();
}
signal(SIGINT, __signal_handler);
running = 1;
printf("rc_mpu_initialize_failed\n");
return -1;
}
__print_header();
printf("\n");
fflush(stdout);
return 0;
}