mirror of
https://github.com/Evolution-X-Devices/device_motorola_rtwo
synced 2026-01-27 07:50:05 +00:00
eqs: sensors: implement and enable UDFPS sensor
This commit is contained in:
@@ -278,4 +278,7 @@
|
||||
|
||||
<!-- Type of the double tap sensor. Empty if double tap is not supported. -->
|
||||
<string name="config_dozeDoubleTapSensorType" translatable="false">org.lineageos.sensor.dt2w</string>
|
||||
|
||||
<!-- Type of the udfps long press sensor. Empty if long press is not supported. -->
|
||||
<string name="config_dozeUdfpsLongPressSensorType" translatable="false">org.lineageos.sensor.udfps</string>
|
||||
</resources>
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
|
||||
#include <chrono>
|
||||
#include <cmath>
|
||||
#include <linux/input.h>
|
||||
|
||||
static bool readEvent(int fd, struct input_event *event) {
|
||||
int rc;
|
||||
@@ -227,24 +226,21 @@ OneShotSensor::OneShotSensor(int32_t sensorHandle, ISensorsEventCallback* callba
|
||||
mSensorInfo.flags |= SensorFlagBits::ONE_SHOT_MODE;
|
||||
}
|
||||
|
||||
#define INPUT_DT2W_SENSOR_PATH "/dev/input/event10"
|
||||
#define INPUT_TOUCHSCREEN_PATH "/dev/input/event11"
|
||||
|
||||
#define GESTURE_PATH "/sys/class/touchscreen/primary/gesture"
|
||||
|
||||
InputEventDT2WSensor::InputEventDT2WSensor(
|
||||
int32_t sensorHandle, ISensorsEventCallback* callback)
|
||||
InputEventOneShotSensor::InputEventOneShotSensor(
|
||||
int32_t sensorHandle, ISensorsEventCallback* callback, const std::string& pollPath,
|
||||
const std::string& enablePath, int enableValue, short keyValue, const std::string& name,
|
||||
const std::string& typeAsString, SensorType type)
|
||||
: OneShotSensor(sensorHandle, callback) {
|
||||
mSensorInfo.name = "DT2W sensor";
|
||||
mSensorInfo.type = static_cast<SensorType>(static_cast<int32_t>(SensorType::DEVICE_PRIVATE_BASE) + 1);
|
||||
mSensorInfo.typeAsString = "org.lineageos.sensor.dt2w";
|
||||
mSensorInfo.name = name;
|
||||
mSensorInfo.type = type;
|
||||
mSensorInfo.typeAsString = typeAsString;
|
||||
mSensorInfo.maxRange = 2048.0f;
|
||||
mSensorInfo.resolution = 1.0f;
|
||||
mSensorInfo.power = 0;
|
||||
mSensorInfo.flags |= SensorFlagBits::WAKE_UP;
|
||||
|
||||
std::ofstream mGestureEnable;
|
||||
mGestureEnable.open(GESTURE_PATH);
|
||||
mGestureEnable.open(enablePath);
|
||||
|
||||
if(!mGestureEnable) {
|
||||
ALOGE("could not open gesture path");
|
||||
@@ -252,7 +248,7 @@ InputEventDT2WSensor::InputEventDT2WSensor(
|
||||
return;
|
||||
}
|
||||
|
||||
mGestureEnable << "49" << std::flush;
|
||||
mGestureEnable << enableValue << std::flush;
|
||||
|
||||
int rc;
|
||||
|
||||
@@ -263,7 +259,7 @@ InputEventDT2WSensor::InputEventDT2WSensor(
|
||||
ALOGE("failed to open wait pipe: %d", rc);
|
||||
}
|
||||
|
||||
mPollFds[0] = open(INPUT_DT2W_SENSOR_PATH, O_RDONLY | O_NONBLOCK);
|
||||
mPollFds[0] = open(pollPath.c_str(), O_RDONLY | O_NONBLOCK);
|
||||
if (mPollFds[0] < 0) {
|
||||
ALOGE("failed to open poll fd: %d", mPollFds[0]);
|
||||
}
|
||||
@@ -282,15 +278,17 @@ InputEventDT2WSensor::InputEventDT2WSensor(
|
||||
.fd = mPollFds[0],
|
||||
.events = POLLIN,
|
||||
};
|
||||
|
||||
mKeyValue = keyValue;
|
||||
}
|
||||
|
||||
InputEventDT2WSensor::~InputEventDT2WSensor() {
|
||||
InputEventOneShotSensor::~InputEventOneShotSensor() {
|
||||
interruptPoll();
|
||||
}
|
||||
|
||||
void InputEventDT2WSensor::activate(bool enable) {
|
||||
void InputEventOneShotSensor::activate(bool enable) {
|
||||
std::lock_guard<std::mutex> lock(mRunMutex);
|
||||
|
||||
ALOGE("Activated for key %d", mKeyValue);
|
||||
if (mIsEnabled != enable) {
|
||||
mIsEnabled = enable;
|
||||
interruptPoll();
|
||||
@@ -298,12 +296,12 @@ void InputEventDT2WSensor::activate(bool enable) {
|
||||
}
|
||||
}
|
||||
|
||||
void InputEventDT2WSensor::setOperationMode(OperationMode mode) {
|
||||
void InputEventOneShotSensor::setOperationMode(OperationMode mode) {
|
||||
Sensor::setOperationMode(mode);
|
||||
interruptPoll();
|
||||
}
|
||||
|
||||
void InputEventDT2WSensor::run() {
|
||||
void InputEventOneShotSensor::run() {
|
||||
std::unique_lock<std::mutex> runLock(mRunMutex);
|
||||
|
||||
while (!mStopThread) {
|
||||
@@ -326,7 +324,7 @@ void InputEventDT2WSensor::run() {
|
||||
}
|
||||
|
||||
if((mPolls[1].revents == mPolls[1].events) && readEvent(mPolls[1].fd, &event)) {
|
||||
if(event.type == EV_KEY && event.value == 1 && event.code == KEY_F4) {
|
||||
if(event.type == EV_KEY && event.value == 1 && event.code == mKeyValue) {
|
||||
mIsEnabled = false;
|
||||
mCallback->postEvents(readEvents(), isWakeUpSensor());
|
||||
}
|
||||
@@ -337,21 +335,25 @@ void InputEventDT2WSensor::run() {
|
||||
}
|
||||
}
|
||||
|
||||
void InputEventDT2WSensor::interruptPoll() {
|
||||
void InputEventOneShotSensor::interruptPoll() {
|
||||
if (mWaitPipeFd[1] < 0) return;
|
||||
|
||||
char c = '1';
|
||||
write(mWaitPipeFd[1], &c, sizeof(c));
|
||||
}
|
||||
|
||||
std::vector<Event> InputEventDT2WSensor::readEvents() {
|
||||
void InputEventOneShotSensor::fillEventData(Event& event) {
|
||||
event.u.data[0] = 0;
|
||||
event.u.data[1] = 0;
|
||||
}
|
||||
|
||||
std::vector<Event> InputEventOneShotSensor::readEvents() {
|
||||
std::vector<Event> events;
|
||||
Event event;
|
||||
event.sensorHandle = mSensorInfo.sensorHandle;
|
||||
event.sensorType = mSensorInfo.type;
|
||||
event.timestamp = ::android::elapsedRealtimeNano();
|
||||
event.u.data[0] = 0;
|
||||
event.u.data[1] = 0;
|
||||
fillEventData(event);
|
||||
events.push_back(event);
|
||||
return events;
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
#include <linux/input.h>
|
||||
|
||||
using ::android::hardware::sensors::V1_0::OperationMode;
|
||||
using ::android::hardware::sensors::V1_0::Result;
|
||||
@@ -92,14 +93,18 @@ class OneShotSensor : public Sensor {
|
||||
virtual Result flush() override { return Result::BAD_VALUE; }
|
||||
};
|
||||
|
||||
class InputEventDT2WSensor : public OneShotSensor {
|
||||
class InputEventOneShotSensor : public OneShotSensor {
|
||||
public:
|
||||
InputEventDT2WSensor(int32_t sensorHandle, ISensorsEventCallback* callback);
|
||||
virtual ~InputEventDT2WSensor() override;
|
||||
InputEventOneShotSensor(int32_t sensorHandle, ISensorsEventCallback* callback,
|
||||
const std::string& pollPath, const std::string& enablePath,
|
||||
int enableValue, short keyValue, const std::string& name,
|
||||
const std::string& typeAsString, SensorType type);
|
||||
virtual ~InputEventOneShotSensor() override;
|
||||
|
||||
virtual void activate(bool enable) override;
|
||||
virtual void setOperationMode(OperationMode mode) override;
|
||||
virtual std::vector<Event> readEvents() override;
|
||||
virtual void fillEventData(Event& event);
|
||||
|
||||
protected:
|
||||
virtual void run() override;
|
||||
@@ -112,6 +117,31 @@ class InputEventDT2WSensor : public OneShotSensor {
|
||||
struct pollfd mPolls[2];
|
||||
int mWaitPipeFd[2];
|
||||
int mPollFds[1];
|
||||
short mKeyValue;
|
||||
};
|
||||
|
||||
const std::string kDoubleTapInputEventPath = "/dev/input/event10";
|
||||
const std::string kGestureEnablePath = "/sys/class/touchscreen/primary/gesture";
|
||||
|
||||
const int kEnableDt2w = 49;
|
||||
const int kEnableFodPressed = 17;
|
||||
|
||||
class InputEventDT2WSensor : public InputEventOneShotSensor {
|
||||
public:
|
||||
InputEventDT2WSensor(int32_t sensorHandle, ISensorsEventCallback* callback)
|
||||
: InputEventOneShotSensor(
|
||||
sensorHandle, callback, kDoubleTapInputEventPath,
|
||||
kGestureEnablePath, kEnableDt2w, KEY_F4, "DT2W sensor",
|
||||
"org.lineageos.sensor.dt2w", static_cast<SensorType>(static_cast<int32_t>(SensorType::DEVICE_PRIVATE_BASE) + 1)) {}
|
||||
};
|
||||
|
||||
class InputEventUdfpsSensor : public InputEventOneShotSensor {
|
||||
public:
|
||||
InputEventUdfpsSensor(int32_t sensorHandle, ISensorsEventCallback* callback)
|
||||
: InputEventOneShotSensor(
|
||||
sensorHandle, callback, kDoubleTapInputEventPath,
|
||||
kGestureEnablePath, kEnableFodPressed, KEY_F2, "UDFPS sensor",
|
||||
"org.lineageos.sensor.udfps", static_cast<SensorType>(static_cast<int32_t>(SensorType::DEVICE_PRIVATE_BASE) + 2)) {}
|
||||
};
|
||||
|
||||
} // namespace implementation
|
||||
|
||||
@@ -34,6 +34,7 @@ using ::android::hardware::sensors::V2_0::implementation::ScopedWakelock;
|
||||
|
||||
SensorsSubHal::SensorsSubHal() : mCallback(nullptr), mNextHandle(1) {
|
||||
AddSensor<InputEventDT2WSensor>();
|
||||
AddSensor<InputEventUdfpsSensor>();
|
||||
}
|
||||
|
||||
Return<void> SensorsSubHal::getSensorsList_2_1(ISensors::getSensorsList_2_1_cb _hidl_cb) {
|
||||
|
||||
Reference in New Issue
Block a user