diff --git a/sensors/2.0/default/Sensor.cpp b/sensors/2.0/default/Sensor.cpp index 1691b3e7a2..21c1591d01 100644 --- a/sensors/2.0/default/Sensor.cpp +++ b/sensors/2.0/default/Sensor.cpp @@ -24,6 +24,7 @@ namespace sensors { namespace V2_0 { namespace implementation { +using ::android::hardware::sensors::V1_0::SensorFlagBits; using ::android::hardware::sensors::V1_0::SensorStatus; Sensor::Sensor(ISensorsEventCallback* callback) @@ -106,6 +107,24 @@ std::vector Sensor::readEvents() { return events; } +AccelSensor::AccelSensor(int32_t sensorHandle, ISensorsEventCallback* callback) : Sensor(callback) { + mSensorInfo.sensorHandle = sensorHandle; + mSensorInfo.name = "Accel Sensor"; + mSensorInfo.vendor = "Vendor String"; + mSensorInfo.version = 1; + mSensorInfo.type = SensorType::ACCELEROMETER; + mSensorInfo.typeAsString = ""; + mSensorInfo.maxRange = 78.4f; // +/- 8g + mSensorInfo.resolution = 1.52e-5; + mSensorInfo.power = 0.001f; // mA + mSensorInfo.minDelay = 20 * 1000; // microseconds + mSensorInfo.maxDelay = 1000 * 1000; // microseconds + mSensorInfo.fifoReservedEventCount = 0; + mSensorInfo.fifoMaxEventCount = 0; + mSensorInfo.requiredPermission = ""; + mSensorInfo.flags = static_cast(SensorFlagBits::WAKE_UP); +}; + } // namespace implementation } // namespace V2_0 } // namespace sensors diff --git a/sensors/2.0/default/Sensor.h b/sensors/2.0/default/Sensor.h index 21ad10d002..e467b56f78 100644 --- a/sensors/2.0/default/Sensor.h +++ b/sensors/2.0/default/Sensor.h @@ -66,6 +66,11 @@ class Sensor { ISensorsEventCallback* mCallback; }; +class AccelSensor : public Sensor { + public: + AccelSensor(int32_t sensorHandle, ISensorsEventCallback* callback); +}; + } // namespace implementation } // namespace V2_0 } // namespace sensors diff --git a/sensors/2.0/default/Sensors.cpp b/sensors/2.0/default/Sensors.cpp index f0b02c3125..39c1ded356 100644 --- a/sensors/2.0/default/Sensors.cpp +++ b/sensors/2.0/default/Sensors.cpp @@ -31,7 +31,11 @@ using ::android::hardware::sensors::V1_0::RateLevel; using ::android::hardware::sensors::V1_0::Result; using ::android::hardware::sensors::V1_0::SharedMemInfo; -Sensors::Sensors() : mEventQueueFlag(nullptr) {} +Sensors::Sensors() : mEventQueueFlag(nullptr) { + std::shared_ptr accel = + std::make_shared(1 /* sensorHandle */, this /* callback */); + mSensors[accel->getSensorInfo().sensorHandle] = accel; +} Sensors::~Sensors() { deleteEventFlag();