mirror of
https://github.com/Evolution-X/hardware_interfaces
synced 2026-02-01 11:36:00 +00:00
Merge "Set default value for pressure sensor"
This commit is contained in:
@@ -26,6 +26,7 @@ namespace sensors {
|
|||||||
namespace V2_X {
|
namespace V2_X {
|
||||||
namespace implementation {
|
namespace implementation {
|
||||||
|
|
||||||
|
using ::android::hardware::sensors::V1_0::EventPayload;
|
||||||
using ::android::hardware::sensors::V1_0::MetaDataEventType;
|
using ::android::hardware::sensors::V1_0::MetaDataEventType;
|
||||||
using ::android::hardware::sensors::V1_0::OperationMode;
|
using ::android::hardware::sensors::V1_0::OperationMode;
|
||||||
using ::android::hardware::sensors::V1_0::Result;
|
using ::android::hardware::sensors::V1_0::Result;
|
||||||
@@ -133,20 +134,13 @@ bool Sensor::isWakeUpSensor() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Event> Sensor::readEvents() {
|
std::vector<Event> Sensor::readEvents() {
|
||||||
// For an accelerometer sensor type, default the z-direction
|
|
||||||
// value to -9.8
|
|
||||||
float zValue = (mSensorInfo.type == SensorType::ACCELEROMETER)
|
|
||||||
? -9.8 : 0.0;
|
|
||||||
|
|
||||||
std::vector<Event> events;
|
std::vector<Event> events;
|
||||||
Event event;
|
Event event;
|
||||||
event.sensorHandle = mSensorInfo.sensorHandle;
|
event.sensorHandle = mSensorInfo.sensorHandle;
|
||||||
event.sensorType = mSensorInfo.type;
|
event.sensorType = mSensorInfo.type;
|
||||||
event.timestamp = ::android::elapsedRealtimeNano();
|
event.timestamp = ::android::elapsedRealtimeNano();
|
||||||
event.u.vec3.x = 0;
|
memset(&event.u, 0, sizeof(event.u));
|
||||||
event.u.vec3.y = 0;
|
readEventPayload(event.u);
|
||||||
event.u.vec3.z = zValue;
|
|
||||||
event.u.vec3.status = SensorStatus::ACCURACY_HIGH;
|
|
||||||
events.push_back(event);
|
events.push_back(event);
|
||||||
return events;
|
return events;
|
||||||
}
|
}
|
||||||
@@ -194,7 +188,7 @@ std::vector<Event> OnChangeSensor::readEvents() {
|
|||||||
|
|
||||||
for (auto iter = events.begin(); iter != events.end(); ++iter) {
|
for (auto iter = events.begin(); iter != events.end(); ++iter) {
|
||||||
Event ev = *iter;
|
Event ev = *iter;
|
||||||
if (ev.u.vec3 != mPreviousEvent.u.vec3 || !mPreviousEventSet) {
|
if (!mPreviousEventSet || memcmp(&mPreviousEvent.u, &ev.u, sizeof(ev.u)) != 0) {
|
||||||
outputEvents.push_back(ev);
|
outputEvents.push_back(ev);
|
||||||
mPreviousEvent = ev;
|
mPreviousEvent = ev;
|
||||||
mPreviousEventSet = true;
|
mPreviousEventSet = true;
|
||||||
@@ -221,6 +215,13 @@ AccelSensor::AccelSensor(int32_t sensorHandle, ISensorsEventCallback* callback)
|
|||||||
mSensorInfo.flags = static_cast<uint32_t>(SensorFlagBits::DATA_INJECTION);
|
mSensorInfo.flags = static_cast<uint32_t>(SensorFlagBits::DATA_INJECTION);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void AccelSensor::readEventPayload(EventPayload& payload) {
|
||||||
|
payload.vec3.x = 0;
|
||||||
|
payload.vec3.y = 0;
|
||||||
|
payload.vec3.z = -9.8;
|
||||||
|
payload.vec3.status = SensorStatus::ACCURACY_HIGH;
|
||||||
|
}
|
||||||
|
|
||||||
PressureSensor::PressureSensor(int32_t sensorHandle, ISensorsEventCallback* callback)
|
PressureSensor::PressureSensor(int32_t sensorHandle, ISensorsEventCallback* callback)
|
||||||
: Sensor(callback) {
|
: Sensor(callback) {
|
||||||
mSensorInfo.sensorHandle = sensorHandle;
|
mSensorInfo.sensorHandle = sensorHandle;
|
||||||
@@ -240,6 +241,10 @@ PressureSensor::PressureSensor(int32_t sensorHandle, ISensorsEventCallback* call
|
|||||||
mSensorInfo.flags = 0;
|
mSensorInfo.flags = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void PressureSensor::readEventPayload(EventPayload& payload) {
|
||||||
|
payload.scalar = 1013.25f;
|
||||||
|
}
|
||||||
|
|
||||||
MagnetometerSensor::MagnetometerSensor(int32_t sensorHandle, ISensorsEventCallback* callback)
|
MagnetometerSensor::MagnetometerSensor(int32_t sensorHandle, ISensorsEventCallback* callback)
|
||||||
: Sensor(callback) {
|
: Sensor(callback) {
|
||||||
mSensorInfo.sensorHandle = sensorHandle;
|
mSensorInfo.sensorHandle = sensorHandle;
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ class Sensor {
|
|||||||
using OperationMode = ::android::hardware::sensors::V1_0::OperationMode;
|
using OperationMode = ::android::hardware::sensors::V1_0::OperationMode;
|
||||||
using Result = ::android::hardware::sensors::V1_0::Result;
|
using Result = ::android::hardware::sensors::V1_0::Result;
|
||||||
using Event = ::android::hardware::sensors::V2_1::Event;
|
using Event = ::android::hardware::sensors::V2_1::Event;
|
||||||
|
using EventPayload = ::android::hardware::sensors::V1_0::EventPayload;
|
||||||
using SensorInfo = ::android::hardware::sensors::V2_1::SensorInfo;
|
using SensorInfo = ::android::hardware::sensors::V2_1::SensorInfo;
|
||||||
using SensorType = ::android::hardware::sensors::V2_1::SensorType;
|
using SensorType = ::android::hardware::sensors::V2_1::SensorType;
|
||||||
|
|
||||||
@@ -65,6 +66,7 @@ class Sensor {
|
|||||||
protected:
|
protected:
|
||||||
void run();
|
void run();
|
||||||
virtual std::vector<Event> readEvents();
|
virtual std::vector<Event> readEvents();
|
||||||
|
virtual void readEventPayload(EventPayload&) {}
|
||||||
static void startThread(Sensor* sensor);
|
static void startThread(Sensor* sensor);
|
||||||
|
|
||||||
bool isWakeUpSensor();
|
bool isWakeUpSensor();
|
||||||
@@ -101,6 +103,9 @@ class OnChangeSensor : public Sensor {
|
|||||||
class AccelSensor : public Sensor {
|
class AccelSensor : public Sensor {
|
||||||
public:
|
public:
|
||||||
AccelSensor(int32_t sensorHandle, ISensorsEventCallback* callback);
|
AccelSensor(int32_t sensorHandle, ISensorsEventCallback* callback);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void readEventPayload(EventPayload& payload) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class GyroSensor : public Sensor {
|
class GyroSensor : public Sensor {
|
||||||
@@ -116,6 +121,9 @@ class AmbientTempSensor : public OnChangeSensor {
|
|||||||
class PressureSensor : public Sensor {
|
class PressureSensor : public Sensor {
|
||||||
public:
|
public:
|
||||||
PressureSensor(int32_t sensorHandle, ISensorsEventCallback* callback);
|
PressureSensor(int32_t sensorHandle, ISensorsEventCallback* callback);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void readEventPayload(EventPayload& payload) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class MagnetometerSensor : public Sensor {
|
class MagnetometerSensor : public Sensor {
|
||||||
|
|||||||
Reference in New Issue
Block a user