Exemple #1
0
static void read(SENSOR* sensor){
	ITG3200* device = (ITG3200*)sensor;
	const I2C_DEVICE* i2c = &(device->i2cInfo);
	uint8_t response[8];
	if(i2cMasterReadRegisters(i2c,TMP_H,sizeof(response),response)){
		int16_t tmp;
		// tempC = 35.0 + ((rawVal + 13200)/280.0);
		tmp = (response[0] << 8) | response[1];	// temperature
		device->celsius = 35 + ((tmp + 13200)/280);

		// Divide readings by 14.375 to get degrees per second
		// Same as multiply by 0.069565217391304347826086956521739
		// Fib series: 0, 15, 345
		tmp = (response[2] << 8) | response[3];	// x
		tmp -= device->x_zero;
		device->gyro.x_axis_degrees_per_second = fraction32(tmp, frac);

		tmp = (response[4] << 8) | response[5];	// y
		tmp -= device->y_zero;
		device->gyro.y_axis_degrees_per_second = fraction32(tmp, frac);

		tmp = (response[6] << 8) | response[7];	// z
		tmp -= device->z_zero;
		device->gyro.z_axis_degrees_per_second = fraction32(tmp, frac);
	}
}

// Make the class, 50ms on startup, 0ms between readings
GYRO_CLASS const c_ITG3200 = MAKE_GYRO_CLASS(&init,&read,50,0);
Exemple #2
0
	device->x_zero = 0;
	device->y_zero = 0;
	device->z_zero = 0;

	// Read 8 times
	for(uint8_t i=0; i<8; i++){
		device->x_zero += a2dReadMv(device->x_pin);
		device->y_zero += a2dReadMv(device->y_pin);
		device->z_zero += a2dReadMv(device->z_pin);
	}

	// Get average
	device->x_zero /= 8;
	device->y_zero /= 8;
	device->z_zero /= 8;
}

// Read all the values and store into the device
static void read(SENSOR* sensor){
	LPRY530AL* device = (LPRY530AL*)sensor;
	device->gyro.x_axis_degrees_per_second = __read_channel(device->x_pin, device->slow, device->x_zero);
	device->gyro.y_axis_degrees_per_second = __read_channel(device->y_pin, device->slow, device->y_zero);
	device->gyro.z_axis_degrees_per_second = __read_channel(device->z_pin, device->slow, device->z_zero);
}

// 200ms startup time
const GYRO_CLASS PROGMEM c_LPRY530AL = MAKE_GYRO_CLASS(&init,&read,200,0);



Exemple #3
0
	}
	return rtn;
}

static void __ly530alh_init(SENSOR* sensor){
	LY530ALH* device = (LY530ALH*)sensor;
	// The default is that device should be outputing 1.23v ie ADC10 of 251
	device->z_zero = 0;

	// Read 8 times
	for(uint8_t i=0; i<8; i++){
		device->z_zero += a2dReadMv(device->z_pin);
	}

	// Get average
	device->z_zero /= 8;

}

// Read all the values and store into the device
static void __ly530alh_read(SENSOR* sensor){
	LY530ALH* device = (LY530ALH*)sensor;
	device->gyro.z_axis_degrees_per_second = __read_channel(device->z_pin, device->slow, device->z_zero);
}

// 200ms startup time
GYRO_CLASS c_LY530ALH = MAKE_GYRO_CLASS(&__ly530alh_init,&__ly530alh_read,200,0);



Exemple #4
0
static void __idg300_init(SENSOR* sensor){
	IDG300* device = (IDG300*)sensor;
	// The default is that device should be outputing 1.5v ie ADC10 = 307
	device->x_zero = 0;
	device->y_zero = 0;

	// Read 8 times
	for(uint8_t i=0; i<8; i++){
		device->x_zero += a2dReadMv(device->x_pin);
		device->y_zero += a2dReadMv(device->y_pin);
	}

	// Get average
	device->x_zero /= 8;
	device->y_zero /= 8;

}

// Read all the values and store into the device
static void __idg300_read(SENSOR* sensor){
	IDG300* device = (IDG300*)sensor;
	device->gyro.x_axis_degrees_per_second = __read_channel(device->x_pin, device->x_zero);
	device->gyro.y_axis_degrees_per_second = __read_channel(device->y_pin, device->y_zero);
}

// 200ms startup time, 20ms between readings
const GYRO_CLASS PROGMEM c_IDG300 = MAKE_GYRO_CLASS(&__idg300_init,&__idg300_read,200,20);