aboutsummaryrefslogtreecommitdiff
path: root/apps/drivers/hmc5883/hmc5883.cpp
diff options
context:
space:
mode:
authorLorenz Meier <lm@inf.ethz.ch>2012-08-26 23:48:16 +0200
committerLorenz Meier <lm@inf.ethz.ch>2012-08-26 23:48:16 +0200
commit2963dc679a63309a7b26da1677208fbdb4aec146 (patch)
tree2cdf3f4968e98f7474bf4e10c3986893ed7dad6d /apps/drivers/hmc5883/hmc5883.cpp
parent56e66a80cdd5f0f09716ee503cdc2810e3e74a69 (diff)
downloadpx4-firmware-2963dc679a63309a7b26da1677208fbdb4aec146.tar.gz
px4-firmware-2963dc679a63309a7b26da1677208fbdb4aec146.tar.bz2
px4-firmware-2963dc679a63309a7b26da1677208fbdb4aec146.zip
Driver debugging (scaling, ranges, endianess) MPU-6000 needs more love
Diffstat (limited to 'apps/drivers/hmc5883/hmc5883.cpp')
-rw-r--r--apps/drivers/hmc5883/hmc5883.cpp19
1 files changed, 12 insertions, 7 deletions
diff --git a/apps/drivers/hmc5883/hmc5883.cpp b/apps/drivers/hmc5883/hmc5883.cpp
index 3a194ee11..99deb5da8 100644
--- a/apps/drivers/hmc5883/hmc5883.cpp
+++ b/apps/drivers/hmc5883/hmc5883.cpp
@@ -649,9 +649,9 @@ HMC5883::collect()
}
/* swap the data we just received */
- report.x = ((int16_t)hmc_report.x[0] << 8) + hmc_report.x[1];
- report.y = ((int16_t)hmc_report.y[0] << 8) + hmc_report.y[1];
- report.z = ((int16_t)hmc_report.z[0] << 8) + hmc_report.z[1];
+ report.x = (((int16_t)hmc_report.x[0]) << 8) + hmc_report.x[1];
+ report.y = (((int16_t)hmc_report.y[0]) << 8) + hmc_report.y[1];
+ report.z = (((int16_t)hmc_report.z[0]) << 8) + hmc_report.z[1];
/*
* If any of the values are -4096, there was an internal math error in the sensor.
@@ -662,10 +662,14 @@ HMC5883::collect()
(abs(report.z) > 2048))
goto out;
- /* raw outputs */
- /* to align the sensor axes with the board, x and y need to be flipped */
+ /*
+ * RAW outputs
+ *
+ * to align the sensor axes with the board, x and y need to be flipped
+ * and y needs to be negated
+ */
_reports[_next_report].x_raw = report.y;
- _reports[_next_report].y_raw = report.x;
+ _reports[_next_report].y_raw = ((report.x == -32768) ? 32767 : -report.x);
/* z remains z */
_reports[_next_report].z_raw = report.z;
@@ -688,7 +692,8 @@ HMC5883::collect()
/* to align the sensor axes with the board, x and y need to be flipped */
_reports[_next_report].x = ((report.y * _range_scale) - _scale.x_offset) * _scale.x_scale;
- _reports[_next_report].y = ((report.x * _range_scale) - _scale.y_offset) * _scale.y_scale;
+ /* flip axes and negate value for y */
+ _reports[_next_report].y = ((((report.x == -32768) ? 32767 : -report.x) * _range_scale) - _scale.y_offset) * _scale.y_scale;
/* z remains z */
_reports[_next_report].z = ((report.z * _range_scale) - _scale.z_offset) * _scale.z_scale;