diff --git a/services/hdi_connection/adapter/include/sensor_event_callback.h b/services/hdi_connection/adapter/include/sensor_event_callback.h index c8e92ddd23420a2e255cd07d0688256ce5af6a6d..f1c62ff6733f7e42c441f660c70a824c516a8edd 100644 --- a/services/hdi_connection/adapter/include/sensor_event_callback.h +++ b/services/hdi_connection/adapter/include/sensor_event_callback.h @@ -36,6 +36,7 @@ private: int32_t GetDataDimension(int32_t sensorId); int64_t postureLastTs_ = 0; int64_t ambientLightLastTs_ = 0; + int64_t magneticFieldLastTs_ = 0; }; } // namespace Sensors } // namespace OHOS diff --git a/services/hdi_connection/adapter/src/sensor_event_callback.cpp b/services/hdi_connection/adapter/src/sensor_event_callback.cpp index 5eb665c7b1adf4f510ecb7f4076e94f2383f0e63..85b8a466f5c155968da8a6f4a5185d35d8d943bc 100644 --- a/services/hdi_connection/adapter/src/sensor_event_callback.cpp +++ b/services/hdi_connection/adapter/src/sensor_event_callback.cpp @@ -102,6 +102,11 @@ void SensorEventCallback::ControlSensorPrint(const SensorData &sensorData) PrintSensorData(sensorData); ambientLightLastTs_ = sensorData.timestamp; } + if ((sensorData.sensorTypeId == SENSOR_TYPE_ID_MAGNETIC_FIELD) + && ((magneticFieldLastTs_ == 0) || (sensorData.timestamp - magneticFieldLastTs_ >= LOG_INTERVAL))) { + PrintSensorData(sensorData); + magneticFieldLastTs_ = sensorData.timestamp; + } } void SensorEventCallback::PrintSensorData(const SensorData &sensorData) @@ -133,6 +138,7 @@ int32_t SensorEventCallback::GetDataDimension(int32_t sensorId) case SENSOR_TYPE_ID_POSTURE: return SEVEN_DIMENSION; case SENSOR_TYPE_ID_AMBIENT_LIGHT: + case SENSOR_TYPE_ID_MAGNETIC_FIELD: return THREE_DIMENSION; default: SEN_HILOGW("Unknown sensorId:%{public}d, size:%{public}d", sensorId, DEFAULT_DIMENSION);