summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew LeCain <alecain@google.com>2019-02-25 16:34:02 -0800
committerandroid-build-merger <android-build-merger@google.com>2019-02-25 16:34:02 -0800
commita2294ba6ac3eaf346798e3e4985fac16bbf6c958 (patch)
tree5adeb4d08cfa2f45c1f3b76aff897924179aa3d5
parent85db51e1d88452f38f9644049f771bd2cc956156 (diff)
parent4f15b214b8c3d451a6cfe413f592da444506a3b1 (diff)
downloaddevice_google_contexthub-a2294ba6ac3eaf346798e3e4985fac16bbf6c958.tar.gz
device_google_contexthub-a2294ba6ac3eaf346798e3e4985fac16bbf6c958.tar.bz2
device_google_contexthub-a2294ba6ac3eaf346798e3e4985fac16bbf6c958.zip
nanotool: Add support for compressed mag samples am: 9301a0b25e
am: 4f15b214b8 Change-Id: Ia75990ecfc0c72473ee145ee40dad522e9afe32d
-rw-r--r--util/nanotool/contexthub.cpp1
-rw-r--r--util/nanotool/contexthub.h1
-rw-r--r--util/nanotool/sensorevent.cpp25
3 files changed, 23 insertions, 4 deletions
diff --git a/util/nanotool/contexthub.cpp b/util/nanotool/contexthub.cpp
index 7a3df87b..e240d558 100644
--- a/util/nanotool/contexthub.cpp
+++ b/util/nanotool/contexthub.cpp
@@ -83,6 +83,7 @@ struct SensorTypeAlias {
static const SensorTypeAlias sensor_aliases_[] = {
{ SensorType::Accel, SensorType::CompressedAccel, "compressed_accel" },
+ { SensorType::Magnetometer, SensorType::CompressedMag, "compressed_mag" },
};
bool SensorTypeIsAliasOf(SensorType sensor_type, SensorType alias) {
diff --git a/util/nanotool/contexthub.h b/util/nanotool/contexthub.h
index 8dfce260..582dacb0 100644
--- a/util/nanotool/contexthub.h
+++ b/util/nanotool/contexthub.h
@@ -70,6 +70,7 @@ enum class SensorType {
Vsync,
CompressedAccel,
WristTilt = 39,
+ CompressedMag = 59,
Humidity = 61,
Max_
diff --git a/util/nanotool/sensorevent.cpp b/util/nanotool/sensorevent.cpp
index 5f095055..2f84fa77 100644
--- a/util/nanotool/sensorevent.cpp
+++ b/util/nanotool/sensorevent.cpp
@@ -24,7 +24,9 @@
namespace android {
-constexpr float kCompressedSampleRatio(8.0f * 9.81f / 32768.0f);
+constexpr float kCompressedAccelSampleRatio(8.0f * 9.81f / 32768.0f);
+constexpr float kCompressedMagSampleRatio(0.15f); //For AK09915
+//constexpr float kCompressedMagSampleRatio(0.0625f); //For BMM150
/* SensorEvent ****************************************************************/
@@ -81,6 +83,7 @@ std::unique_ptr<SensorEvent> SensorEvent::FromBytes(
break;
case SensorType::CompressedAccel:
+ case SensorType::CompressedMag:
sensor_event = new CompressedTripleAxisSensorEvent();
break;
@@ -259,6 +262,7 @@ uint8_t TripleAxisSensorEvent::GetSampleDataSize() const {
std::string CompressedTripleAxisSensorEvent::StringForSample(
uint8_t index) const {
+ float compressedSampleRatio;
const CompressedTripleAxisDataPoint *sample =
reinterpret_cast<const CompressedTripleAxisDataPoint *>(
GetSampleAtIndex(index));
@@ -269,9 +273,22 @@ std::string CompressedTripleAxisSensorEvent::StringForSample(
bool is_bias_sample = first_sample->biasPresent
&& first_sample->biasSample == index;
- float x = sample->ix * kCompressedSampleRatio;
- float y = sample->iy * kCompressedSampleRatio;
- float z = sample->iz * kCompressedSampleRatio;
+ switch(GetSensorType())
+ {
+ case SensorType::CompressedAccel:
+ compressedSampleRatio = kCompressedAccelSampleRatio;
+ break;
+ case SensorType::CompressedMag:
+ compressedSampleRatio = kCompressedMagSampleRatio;
+ break;
+ default:
+ LOGW("Unsupported compressed sensor type");
+ compressedSampleRatio = 1.0;
+ }
+
+ float x = sample->ix * compressedSampleRatio;
+ float y = sample->iy * compressedSampleRatio;
+ float z = sample->iz * compressedSampleRatio;
char buffer[128];
snprintf(buffer, sizeof(buffer), " X:%f Y:%f Z:%f @ %s%s\n",