Register default accelerometer sensor

Registers a default accelerometer with the Sensors HAL.

Bug: 111070257
Test: Builds, a_sns_test receives accel events
Change-Id: I2f016eb74b9b729854e771264f4c2f1adf025c09
This commit is contained in:
Brian Stack 2018-10-23 11:22:55 -07:00
parent 237abc6cf8
commit 2927ab7ed7
3 changed files with 29 additions and 1 deletions

View file

@ -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<Event> 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<uint32_t>(SensorFlagBits::WAKE_UP);
};
} // namespace implementation
} // namespace V2_0
} // namespace sensors

View file

@ -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

View file

@ -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<AccelSensor> accel =
std::make_shared<AccelSensor>(1 /* sensorHandle */, this /* callback */);
mSensors[accel->getSensorInfo().sensorHandle] = accel;
}
Sensors::~Sensors() {
deleteEventFlag();