コード例 #1
0
ファイル: HMC6343.c プロジェクト: kenzanin/webbotavrclib-1x
			// Datasheet says to wait for 1ms before reading response
			delay_ms(1);

			// receive the response
			if(i2cMasterReceive(i2c, sizeof(HEADING_REPLY), (uint8_t*)(&reply))){
				// Get heading in 10ths of a degree 0->3600 and round to degrees
				uint16_t heading10ths = reply.heading_msb;
				heading10ths <<= 8;
				heading10ths |= reply.heading_lsb;
				compass->compass.bearingDegrees = (heading10ths + 5)/10;

				// Get roll +- 900 tenths of a degree
				int16_t roll10ths = reply.roll_msb;
				roll10ths <<= 8;
				roll10ths |= reply.roll_lsb;
				compass->compass.rollDegrees = (roll10ths + 5)/10;

				// Get pitch +- 900 tenths of a degree
				int16_t pitch10ths = reply.pitch_msb;
				pitch10ths <<= 8;
				pitch10ths |= reply.pitch_lsb;
				compass->compass.pitchDegrees = (pitch10ths + 5)/10;
			}
		}
	}
}

// Requires a 500ms delay before being read for the first time
// The fastest it can go is 10Hz ie every 100ms
COMPASS_CLASS const c_HMC6343 = MAKE_COMPASS_CLASS(null,&__HMC6343_read, 500 , 100 );
コード例 #2
0
ファイル: HMC6343.c プロジェクト: bechu/hexapod
			// Datasheet says to wait for 1ms before reading response
			delay_ms(1);

			// receive the response
			if(i2cMasterReceive(i2c, sizeof(HEADING_REPLY), (uint8_t*)(&reply))){
				// Get heading in 10ths of a degree 0->3600 and round to degrees
				uint16_t heading10ths = reply.heading_msb;
				heading10ths <<= 8;
				heading10ths |= reply.heading_lsb;
				compass->compass.bearingDegrees = (heading10ths + 5)/10;

				// Get roll +- 900 tenths of a degree
				int16_t roll10ths = reply.roll_msb;
				roll10ths <<= 8;
				roll10ths |= reply.roll_lsb;
				compass->compass.rollDegrees = (roll10ths + 5)/10;

				// Get pitch +- 900 tenths of a degree
				int16_t pitch10ths = reply.pitch_msb;
				pitch10ths <<= 8;
				pitch10ths |= reply.pitch_lsb;
				compass->compass.pitchDegrees = (pitch10ths + 5)/10;
			}
		}
	}
}

// Requires a 500ms delay before being read for the first time
// The fastest it can go is 10Hz ie every 100ms
const COMPASS_CLASS PROGMEM c_HMC6343 = MAKE_COMPASS_CLASS(null,&__HMC6343_read, 500 , 100 );
コード例 #3
0
ファイル: HMC5883L.c プロジェクト: bechu/hexapod
			// Initialise
			_init(&compass->compass.sensor);
		}
	}
}

void HMC5883L_1_5Hz(HMC5883L* compass){
	_speed(compass,1);
}
void HMC5883L_3Hz(HMC5883L* compass){
	_speed(compass,2);
}
void HMC5883L_7_5Hz(HMC5883L* compass){
	_speed(compass,3);
}
void HMC5883L_15Hz(HMC5883L* compass){
	_speed(compass,4);
}
void HMC5883L_30Hz(HMC5883L* compass){
	_speed(compass,5);
}
void HMC5883L_75Hz(HMC5883L* compass){
	_speed(compass,6);
}


// Requires a 100ms delay before being read for the first time
// The fastest speed is 75Hz ie every 13.33ms
COMPASS_CLASS c_HMC5883L = MAKE_COMPASS_CLASS(&_init,&_read, 100 , 14 );

コード例 #4
0
ファイル: HMC6352.c プロジェクト: bechu/hexapod
static void __HMC6352_init(SENSOR* sensor){
	HMC6352* compass = (HMC6352*)sensor;
	HMC6352_20Hz(compass);
}

static void __HMC6352_read(SENSOR* sensor){
	HMC6352* compass = (HMC6352*)sensor;
	const I2C_DEVICE* i2c = &(compass->i2cInfo);
	HEADING_REPLY reply;

	// Post heading data
// Not need in continuous mode
//	uint8_t  cmd = CMD_GET_HEADING;			// post heading and pitch
//	i2cMasterSend(compass->i2cAddress,1,&cmd);
//	delay_ms(6);							// Datasheet says to wait for 6ms before reading response

	// receive the response
	if(i2cMasterReceive(i2c, sizeof(HEADING_REPLY), (uint8_t*)(&reply))){
		// Get heading in 10ths of a degree 0->3600 and round to degrees
		uint16_t heading10ths = reply.heading_msb;
		heading10ths <<= 8;
		heading10ths |= reply.heading_lsb;
		compass->compass.bearingDegrees = (heading10ths + 5)/10;
	}
}

// Requires a 500ms delay before being read for the first time
// The fastest it can go is 20Hz ie every 50ms
COMPASS_CLASS c_HMC6352 = MAKE_COMPASS_CLASS(&__HMC6352_init,&__HMC6352_read, 500 , 50 );