Stores CHRE accuracy values in SeeCalHelper
Since the accuracy value is not used for anything other than
populating the accuracy field in chreSensorDataHeader when queried,
it makes sense to store the CHRE defined version of sensor accuracy.
Bug: 119269599
Test: Compile only
Change-Id: I124ce74755c32df03d74805cd50dc7843603c1c5
diff --git a/platform/slpi/include/chre/platform/slpi/see/see_cal_helper.h b/platform/slpi/include/chre/platform/slpi/see/see_cal_helper.h
index c7edc86..836d9f0 100644
--- a/platform/slpi/include/chre/platform/slpi/see/see_cal_helper.h
+++ b/platform/slpi/include/chre/platform/slpi/see/see_cal_helper.h
@@ -101,9 +101,11 @@
* @param scale 3-axis scale factor; only valid if hasScale is true
* @param hasMatrix true if matrix was decoded from the proto
* @param matrix 3x3 compensation matrix; only valid if hasMatrix is true
- * @param accuracy Android accuracy rating of the calibration quality (see
- * sns_std_sensor_sample_status)
+ * @param accuracy CHRE accuracy rating of the calibration quality (see
+ * CHRE_SENSOR_ACCURACY)
* @param timestamp The timestamp of the calibration event
+ *
+ * @see CHRE_SENSOR_ACCURACY
*/
void updateCalibration(const sns_std_suid& suid, bool hasBias, float bias[3],
bool hasScale, float scale[3], bool hasMatrix,
diff --git a/platform/slpi/see/see_helper.cc b/platform/slpi/see/see_helper.cc
index 9d35766..0dd9ae7 100644
--- a/platform/slpi/see/see_helper.cc
+++ b/platform/slpi/see/see_helper.cc
@@ -1000,6 +1000,31 @@
return success;
}
+/**
+ * Helper function to convert sns_std_sensor_sample_status to
+ * CHRE_SENSOR_ACCURACY_* values.
+ *
+ * @param status the SEE sensor sample status
+ *
+ * @return the corresponding CHRE_SENSOR_ACCURACY_* value,
+ * CHRE_SENSOR_ACCURACY_UNKNOWN if invalid
+ */
+uint8_t getChreSensorAccuracyFromSeeSampleStatus(
+ sns_std_sensor_sample_status status) {
+ switch (status) {
+ case SNS_STD_SENSOR_SAMPLE_STATUS_UNRELIABLE:
+ return CHRE_SENSOR_ACCURACY_UNRELIABLE;
+ case SNS_STD_SENSOR_SAMPLE_STATUS_ACCURACY_LOW:
+ return CHRE_SENSOR_ACCURACY_LOW;
+ case SNS_STD_SENSOR_SAMPLE_STATUS_ACCURACY_MEDIUM:
+ return CHRE_SENSOR_ACCURACY_MEDIUM;
+ case SNS_STD_SENSOR_SAMPLE_STATUS_ACCURACY_HIGH:
+ return CHRE_SENSOR_ACCURACY_HIGH;
+ default:
+ return CHRE_SENSOR_ACCURACY_UNKNOWN;
+ }
+}
+
bool decodeSnsCalEvent(pb_istream_t *stream, const pb_field_t *field,
void **arg) {
SeeFloatArg offset = {};
@@ -1024,7 +1049,7 @@
bool hasBias = (offset.index == 3);
bool hasScale = (scale.index == 3);
bool hasMatrix = (matrix.index == 9);
- uint8_t accuracy = static_cast<uint8_t>(event.status);
+ uint8_t accuracy = getChreSensorAccuracyFromSeeSampleStatus(event.status);
calHelper->updateCalibration(
info->suid, hasBias, offset.val, hasScale, scale.val,