summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAtle H. Havsø <atle@havso.net>2014-08-26 17:41:25 +0200
committerAtle H. Havsø <atle@havso.net>2014-08-26 17:41:25 +0200
commit49ca2ac5ad2d2fdfceff94af90c204fe1afe3692 (patch)
tree4d65c0b509c3cd2c6ab7d4490b1ee1e7e9b521f0
parent3962f09c4d5cd81a0b9bbba18a253259aa05e3a6 (diff)
Convert data from sensors.
-rw-r--r--drivers/hmc5983.h2
-rw-r--r--drivers/mpu6000.h18
2 files changed, 10 insertions, 10 deletions
diff --git a/drivers/hmc5983.h b/drivers/hmc5983.h
index 9398f23..597aa57 100644
--- a/drivers/hmc5983.h
+++ b/drivers/hmc5983.h
@@ -50,7 +50,7 @@ class HMC5983 {
}
uint8_t update() {
- uint16_t raw_x, raw_y, raw_z;
+ int16_t raw_x, raw_y, raw_z;
uint8_t status;
spi.reg.CR1 = (1 << 9) | (1 <<8) | (1 << 6) | (2 << 3) | (1 << 2) | (1 << 1) | (1 << 0);
spi.reg.CR2 = (1 << 12) | ( 7 << 8);
diff --git a/drivers/mpu6000.h b/drivers/mpu6000.h
index 1297810..a667b00 100644
--- a/drivers/mpu6000.h
+++ b/drivers/mpu6000.h
@@ -45,9 +45,9 @@ class MPU6000 {
Time::sleep(1);
write_register(0x1A, (3 << 0)); // CONFIG - DLPF_CFG 42hz
Time::sleep(1);
- write_register(0x1B, 0); // GYRO_CFG
+ write_register(0x1B, (3 << 3)); // GYRO_CFG, 2000 deg/s
Time::sleep(1);
- write_register(0x1C, 0); // ACCEL_CFG
+ write_register(0x1C, (3 << 3)); // ACCEL_CFG, +-16g
Time::sleep(1);
write_register(0x6A, (1 << 4)); // USER_CTRL - I2C Off
Time::sleep(1);
@@ -59,7 +59,7 @@ class MPU6000 {
void update() {
- uint16_t temp;
+ int16_t temp;
spi.reg.CR1 = (1 << 9) | (1 << 8) | (1 << 6) | (2 << 3) | (1 << 2) | (1 << 1) | (1 << 0); // SSM On | SSI 1 | SPE On | BR /8 | CPOL CK 1 Idle | CPHA Second clock data capture
spi.reg.CR2 = (1 << 12) | ( 7 << 8); // FRXTH RXNE if FIFO >= 8bit | DS 8-bit
@@ -67,23 +67,23 @@ class MPU6000 {
temp = raw_data[0] << 8;
temp |= raw_data[1];
- accel[0] = float(temp);
+ accel[0] = float(temp) * 2 / 32768.0f;
temp = raw_data[2] << 8;
temp |= raw_data[3];
- accel[1] = float(temp);
+ accel[1] = float(temp) * 2 / 32768.0f;
temp = raw_data[4] << 8;
temp |= raw_data[5];
- accel[2] = float(temp);
+ accel[2] = float(temp) * 2 / 32768.0f;
temp = raw_data[8] << 8;
temp |= raw_data[9];
- gyro[0] = float(temp);
+ gyro[0] = float(temp) * 2000 / 32768.0f;
temp = raw_data[10] << 8;
temp |= raw_data[11];
- gyro[1] = float(temp);
+ gyro[1] = float(temp) * 2000 / 32768.0f;
temp = raw_data[12] << 8;
temp |= raw_data[13];
- gyro[2] = float(temp);
+ gyro[2] = float(temp) * 2000 / 32768.0f;
}
};