Loading sensors/2.0/default/Sensor.cpp +20 −0 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ namespace sensors { namespace V2_0 { namespace implementation { using ::android::hardware::sensors::V1_0::MetaDataEventType; using ::android::hardware::sensors::V1_0::SensorFlagBits; using ::android::hardware::sensors::V1_0::SensorStatus; Loading Loading @@ -64,6 +65,25 @@ void Sensor::activate(bool enable) { } } Result Sensor::flush() { // Only generate a flush complete event if the sensor is enabled and if the sensor is not a // one-shot sensor. if (!mIsEnabled || (mSensorInfo.flags & static_cast<uint32_t>(SensorFlagBits::ONE_SHOT_MODE))) { return Result::BAD_VALUE; } // Note: If a sensor supports batching, write all of the currently batched events for the sensor // to the Event FMQ prior to writing the flush complete event. Event ev; ev.sensorHandle = mSensorInfo.sensorHandle; ev.sensorType = SensorType::ADDITIONAL_INFO; ev.u.meta.what = MetaDataEventType::META_DATA_FLUSH_COMPLETE; std::vector<Event> evs{ev}; mCallback->postEvents(evs); return Result::OK; } void Sensor::startThread(Sensor* sensor) { sensor->run(); } Loading sensors/2.0/default/Sensor.h +2 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ #include <vector> using ::android::hardware::sensors::V1_0::Event; using ::android::hardware::sensors::V1_0::Result; using ::android::hardware::sensors::V1_0::SensorInfo; using ::android::hardware::sensors::V1_0::SensorType; Loading @@ -48,6 +49,7 @@ class Sensor { const SensorInfo& getSensorInfo() const; void batch(int32_t samplingPeriodNs); void activate(bool enable); Result flush(); protected: void run(); Loading sensors/2.0/default/Sensors.cpp +6 −3 Original line number Diff line number Diff line Loading @@ -112,9 +112,12 @@ Return<Result> Sensors::batch(int32_t sensorHandle, int64_t samplingPeriodNs, return Result::BAD_VALUE; } Return<Result> Sensors::flush(int32_t /* sensorHandle */) { // TODO implement return Result{}; Return<Result> Sensors::flush(int32_t sensorHandle) { auto sensor = mSensors.find(sensorHandle); if (sensor != mSensors.end()) { return sensor->second->flush(); } return Result::BAD_VALUE; } Return<Result> Sensors::injectSensorData(const Event& /* event */) { Loading Loading
sensors/2.0/default/Sensor.cpp +20 −0 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ namespace sensors { namespace V2_0 { namespace implementation { using ::android::hardware::sensors::V1_0::MetaDataEventType; using ::android::hardware::sensors::V1_0::SensorFlagBits; using ::android::hardware::sensors::V1_0::SensorStatus; Loading Loading @@ -64,6 +65,25 @@ void Sensor::activate(bool enable) { } } Result Sensor::flush() { // Only generate a flush complete event if the sensor is enabled and if the sensor is not a // one-shot sensor. if (!mIsEnabled || (mSensorInfo.flags & static_cast<uint32_t>(SensorFlagBits::ONE_SHOT_MODE))) { return Result::BAD_VALUE; } // Note: If a sensor supports batching, write all of the currently batched events for the sensor // to the Event FMQ prior to writing the flush complete event. Event ev; ev.sensorHandle = mSensorInfo.sensorHandle; ev.sensorType = SensorType::ADDITIONAL_INFO; ev.u.meta.what = MetaDataEventType::META_DATA_FLUSH_COMPLETE; std::vector<Event> evs{ev}; mCallback->postEvents(evs); return Result::OK; } void Sensor::startThread(Sensor* sensor) { sensor->run(); } Loading
sensors/2.0/default/Sensor.h +2 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ #include <vector> using ::android::hardware::sensors::V1_0::Event; using ::android::hardware::sensors::V1_0::Result; using ::android::hardware::sensors::V1_0::SensorInfo; using ::android::hardware::sensors::V1_0::SensorType; Loading @@ -48,6 +49,7 @@ class Sensor { const SensorInfo& getSensorInfo() const; void batch(int32_t samplingPeriodNs); void activate(bool enable); Result flush(); protected: void run(); Loading
sensors/2.0/default/Sensors.cpp +6 −3 Original line number Diff line number Diff line Loading @@ -112,9 +112,12 @@ Return<Result> Sensors::batch(int32_t sensorHandle, int64_t samplingPeriodNs, return Result::BAD_VALUE; } Return<Result> Sensors::flush(int32_t /* sensorHandle */) { // TODO implement return Result{}; Return<Result> Sensors::flush(int32_t sensorHandle) { auto sensor = mSensors.find(sensorHandle); if (sensor != mSensors.end()) { return sensor->second->flush(); } return Result::BAD_VALUE; } Return<Result> Sensors::injectSensorData(const Event& /* event */) { Loading