using ::android::hardware::sensors::V1_0::AdditionalInfoType; using ::android::hardware::sensors::V1_0::MetaDataEventType; using ::android::hardware::sensors::V1_0::SensorFlagBits; using ::android::hardware::sensors::V1_0::SensorStatus; using ::sensor::hal::configuration::V1_0::Location; using ::sensor::hal::configuration::V1_0::Orientation;
void HWSensorBase::batch(int32_t samplingPeriodNs) {
samplingPeriodNs =
std::clamp(samplingPeriodNs, mSensorInfo.minDelay * 1000, mSensorInfo.maxDelay * 1000); if (mSamplingPeriodNs != samplingPeriodNs) { unsignedint sampling_frequency = ns_to_frequency(samplingPeriodNs); int i = 0;
mSamplingPeriodNs = samplingPeriodNs;
std::vector<double>::iterator low =
std::lower_bound(mIioData.sampling_freq_avl.begin(),
mIioData.sampling_freq_avl.end(), sampling_frequency);
i = low - mIioData.sampling_freq_avl.begin();
set_sampling_frequency(mIioData.sysfspath, mIioData.sampling_freq_avl[i]); // Wake up the 'run' thread to check if a new event should be generated now
mSensorThread.notifyAll();
}
}
Result SensorBase::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::META_DATA;
ev.u.meta.what = MetaDataEventType::META_DATA_FLUSH_COMPLETE;
std::vector<Event> evs{ev};
mCallback->postEvents(evs, mCallback->createScopedWakelock(isWakeUpSensor())); return Result::OK;
}
Result HWSensorBase::flush() {
Result result = Result::OK;
result = SensorBase::flush(); if (result == Result::OK) sendAdditionalInfoReport(); return result;
}
void HWSensorBase::processScanData(uint8_t* data, Event* evt) {
std::array<float, NUM_OF_DATA_CHANNELS> channelData; unsignedint chanIdx;
evt->sensorHandle = mSensorInfo.sensorHandle;
evt->sensorType = mSensorInfo.type; for (auto i = 0u; i < mIioData.channelInfo.size(); i++) {
chanIdx = mIioData.channelInfo[i].index;
const int64_t val =
*reinterpret_cast<int64_t*>(data + chanIdx * mIioData.channelInfo[i].storage_bytes); // If the channel index is the last, it is timestamp // else it is sensor data if (chanIdx == mIioData.channelInfo.size() - 1) {
evt->timestamp = val;
} else {
channelData[chanIdx] = static_cast<float>(val) * mIioData.scale;
}
}
void HWSensorBase::pollForEvents() { int err = poll(&mPollFdIio, 1, mSamplingPeriodNs * 1000); if (err <= 0) {
ALOGE("Sensor %s poll returned %d", mIioData.name.c_str(), err); return;
}
if (mPollFdIio.revents & POLLIN) { int read_size = read(mPollFdIio.fd, &mSensorRawData[0], mScanSize); if (read_size <= 0) {
ALOGE("%s: Failed to read data from iio char device.", mIioData.name.c_str()); return;
}
Result SensorBase::injectEvent(const Event& event) {
Result result = Result::OK; if (event.sensorType == SensorType::ADDITIONAL_INFO) { // When in OperationMode::NORMAL, SensorType::ADDITIONAL_INFO is used to push operation // environment data into the device.
} elseif (!supportsDataInjection()) {
result = Result::INVALID_OPERATION;
} elseif (mMode == OperationMode::DATA_INJECTION) {
mCallback->postEvents({event}, mCallback->createScopedWakelock(isWakeUpSensor()));
} else {
result = Result::BAD_VALUE;
} return result;
}
ssize_t HWSensorBase::calculateScanSize() {
ssize_t numBytes = 0; for (auto i = 0u; i < mIioData.channelInfo.size(); i++) {
numBytes += mIioData.channelInfo[i].storage_bytes;
} return numBytes;
}
auto sensorLocationList = getLocation(config); if (!sensorLocationList) return BAD_VALUE; if (sensorLocationList->empty()) return BAD_VALUE;
auto sensorOrientationList = getOrientation(config); if (!sensorOrientationList) return BAD_VALUE; if (sensorOrientationList->empty()) return BAD_VALUE;
Location& sensorLocation = (*sensorLocationList)[0]; // SensorPlacementData is given as a 3x4 matrix consisting of a 3x3 rotation matrix (R) // concatenated with a 3x1 location vector (t) in row major order. Example: This raw buffer: // {x1,y1,z1,l1,x2,y2,z2,l2,x3,y3,z3,l3} corresponds to the following 3x4 matrix: // x1 y1 z1 l1 // x2 y2 z2 l2 // x3 y3 z3 l3 // LOCATION_X_IDX,LOCATION_Y_IDX,LOCATION_Z_IDX corresponds to the indexes of the location // vector (l1,l2,l3) in the raw buffer.
status_t ret = setSensorPlacementData(sensorPlacement, HWSensorBase::LOCATION_X_IDX,
sensorLocation.getX()); if (ret != OK) return ret;
ret = setSensorPlacementData(sensorPlacement, HWSensorBase::LOCATION_Y_IDX,
sensorLocation.getY()); if (ret != OK) return ret;
ret = setSensorPlacementData(sensorPlacement, HWSensorBase::LOCATION_Z_IDX,
sensorLocation.getZ()); if (ret != OK) return ret;
Orientation& sensorOrientation = (*sensorOrientationList)[0]; if (sensorOrientation.getRotate()) { // If the HAL is already rotating the sensor orientation to align with the Android // Coordinate system, then the sensor rotation matrix will be an identity matrix // ROTATION_X_IDX, ROTATION_Y_IDX, ROTATION_Z_IDX corresponds to indexes of the // (x1,y1,z1) in the raw buffer.
ret = setSensorPlacementData(sensorPlacement, HWSensorBase::ROTATION_X_IDX + 0, 1); if (ret != OK) return ret;
ret = setSensorPlacementData(sensorPlacement, HWSensorBase::ROTATION_Y_IDX + 4, 1); if (ret != OK) return ret;
ret = setSensorPlacementData(sensorPlacement, HWSensorBase::ROTATION_Z_IDX + 8, 1); if (ret != OK) return ret;
} else {
ret = setSensorPlacementData(
sensorPlacement,
HWSensorBase::ROTATION_X_IDX + 4 * sensorOrientation.getFirstX()->getMap(),
sensorOrientation.getFirstX()->getNegate() ? -1 : 1); if (ret != OK) return ret;
ret = setSensorPlacementData(
sensorPlacement,
HWSensorBase::ROTATION_Y_IDX + 4 * sensorOrientation.getFirstY()->getMap(),
sensorOrientation.getFirstY()->getNegate() ? -1 : 1); if (ret != OK) return ret;
ret = setSensorPlacementData(
sensorPlacement,
HWSensorBase::ROTATION_Z_IDX + 4 * sensorOrientation.getFirstZ()->getMap(),
sensorOrientation.getFirstZ()->getNegate() ? -1 : 1); if (ret != OK) return ret;
} return OK;
}
status_t HWSensorBase::setAdditionalInfoFrames( const std::optional<std::vector<Configuration>>& config) {
AdditionalInfo additionalInfoSensorPlacement;
status_t ret = getSensorPlacement(&additionalInfoSensorPlacement, config); if (ret != OK) return ret;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.