Пример #1
0
int main(int argc, char **argv) {
    int i2c_file;
    int8_t x, y, z;  /* The readings are 8 bits and signed */

    /* Open a connection to the I2C userspace control file */
    if ((i2c_file = open(I2C_FILE_NAME, O_RDWR)) < 0) {
        /* Error Indication */
        perror("Unable to open i2c control file");
        exit(1);
    }
    /* Success Indication */
 //   printf("Initialized\n");

    /* Set control register */
    if( set_i2c_register(i2c_file, MMA7455_I2CADDR, MMA7455_CTRLADDR, 0x45) ) {
        /* Error Indication */
        printf("Unable to set control register!\n");
        return -1;
    }
    /* Success Indication */
   // printf("Set control register successfully\n");

// MOje






  //  while (1) {
     /*    Read X, Y, and Z from the register */
        if( get_i2c_register(i2c_file, MMA7455_I2CADDR, MMA7455_XOUT8, &x) ||
            get_i2c_register(i2c_file, MMA7455_I2CADDR, MMA7455_YOUT8, &y) ||
            get_i2c_register(i2c_file, MMA7455_I2CADDR, MMA7455_ZOUT8, &z) ) {

            /* Error Indication */
            printf("Unable to read register\n");
            return -1;
        }
        /* Success Indication */

        /* Debug line that prints out registers */
        printf("%d\t|%d\t|%d\n", x, y, z);
	
   // }
   /* Cleanup and Exit */
    close(i2c_file);
    return 0;
}
Пример #2
0
void main()
{
	int i2c_file;
	int i;
	unsigned char val;
	short accel[3]={0};
	short gyro[3]={0};
	if ((i2c_file = open(I2C_FILE_NAME, O_RDWR)) < 0) {
        	perror("Unable to open i2c control file");
        	exit(1);
    	}

	mpu6050_init(i2c_file);
	initkalman();
	while(1)
	{
		getmotion6(i2c_file,&accel[0],&accel[1],&accel[2],&gyro[0],&gyro[1],&gyro[2]);
		kalman((float)gyro[0],(float)gyro[1],(float)gyro[2],(float)accel[0],(float)accel[1],(float)accel[2]);		
		IMUupdate((float)predictdata[3],(float)predictdata[4],(float)predictdata[5],(float)predictdata[0],(float)predictdata[1],(float)predictdata[2]);
		//printf("accel = %d ,%d ,%d ,gyro = %d ,%d ,%d\n",accel[0],accel[1],accel[2],gyro[0],gyro[1],gyro[2]);
		//printf("q0 = %f,q1 = %f,q2 = %f,q3 = %f\n",q0,q1,q2,q3);
		printf("Pitch = %f,Roll = %f,Yaw = %f\n",Pitch,Roll,Yaw);	
	}
	for(i=0;i<=0x75;i++)
	{
		get_i2c_register(i2c_file,0x68,i,&val);
		printf("addr %x= %x\n",i,val);
		
	}
	
	
	
}
Пример #3
0
int main(int argc, char **argv) {
    int i2c_file;

    // Open a connection to the I2C userspace control file.
    if ((i2c_file = open(I2C_FILE_NAME, O_RDWR)) < 0) {
        perror("Unable to open i2c control file");
        exit(1);
    }


    if(argc > 3 && !strcmp(argv[1], "r")) {
        int addr = strtol(argv[2], NULL, 0);
        int reg = strtol(argv[3], NULL, 0);
        unsigned char value;
        if(get_i2c_register(i2c_file, addr, reg, &value)) {
            printf("Unable to get register!\n");
        }
        else {
            printf("Register %d: %d (%x)\n", reg, (int)value, (int)value);
        }
    }
    else if(argc > 4 && !strcmp(argv[1], "w")) {
        int addr = strtol(argv[2], NULL, 0);
        int reg = strtol(argv[3], NULL, 0);
        int value = strtol(argv[4], NULL, 0);
        if(set_i2c_register(i2c_file, addr, reg, value)) {
            printf("Unable to get register!\n");
        }
        else {
            printf("Set register %x: %d (%x)\n", reg, value, value);
        }
    }
    else {
        fprintf(stderr, USAGE_MESSAGE, argv[0], argv[0]);
    }


    close(i2c_file);


    return 0;
}