Exemplo n.º 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);
	}
}
Exemplo n.º 2
0
static GYRO_TYPE __read_channel(ADC_CHANNEL pin, boolean slow, uint16_t zero){
	int16_t adc = a2dReadMv(pin);
	adc -= zero;

	GYRO_TYPE rtn;
	if(slow){
		rtn = fraction32(adc, ly530alh_slow_frac);
	}else{
		rtn = fraction32(adc, ly530alh_fast_frac);
	}
	return rtn;
}
Exemplo n.º 3
0
static void __Phidget_Humidity_read(SENSOR* sensor){
	Phidget_Humidity* device = (Phidget_Humidity*)sensor;
	uint16_t adc = __phidgetsRead(device->adcPin);
	// scale it:  (0.1946 * adc)-41.98
	adc = fraction32(adc, phidget_humidity_frac);
	adc -= 42;
	device->humidity.percent = adc;
}
Exemplo n.º 4
0
// Read all the values and store into the device
static void _read(SENSOR* sensor){
	Maxbotix_MB7077* sonar = (Maxbotix_MB7077*)sensor;
	uint16_t adc = a2dConvert10bit(sonar->adcPin);
	if(sonar->inWater){
		// Multiply by 4.3
		adc = fraction32(adc,_frac);
	}
	sonar->distance.cm = adc;
}
Exemplo n.º 5
0
static GYRO_TYPE __read_channel(ADC_CHANNEL pin, boolean slow, uint16_t zero){
	// Read the voltage im mV
	int16_t adc = 0;

	for(uint8_t s=0; s<SAMPLES;s++){
		adc += a2dReadMv(pin);
	}
	adc /= SAMPLES;


	// Make zero relative
	adc -= zero;

	GYRO_TYPE rtn;
	if(slow){
		// Divide by 3.33mV = multiply by 0.3
		rtn = fraction32(adc, slow_frac);
	}else{
		// Divide by 0.83mV = multiply by 1.2
		rtn = fraction32(adc, fast_frac);
	}
	return rtn;
}
Exemplo n.º 6
0
// Read all the values and store into the device
static void __ping_read(SENSOR* sensor){
	TICK_COUNT duration;

	PingSonar* device = (PingSonar*)sensor;

	// 5 us Trigger Pulse
	pin_pulseOut(device->ioPin,5,TRUE);

	// Measure the inbound pulse
	duration = pin_pulseIn(device->ioPin,TRUE);

	device->distance.cm = fraction32(duration, ping_frac);
//	device->distance.cm = duration;

}
Exemplo n.º 7
0
// Read all the values and store into the device
static void __srf04_read(SENSOR* sensor){
	TICK_COUNT duration;

	Devantech_SRF04* device = (Devantech_SRF04*)sensor;

	// initialise the pins
	pin_make_output(device->out,FALSE);		// Set low
	pin_make_input(device->in,FALSE);

	// 10us high trigger pulse
	pin_pulseOut(device->out,10,TRUE);

	// Measure the inbound pulse
	duration = pin_pulseIn(device->in,TRUE);

	device->distance.cm = fraction32(duration, srf04_frac);
}