const int ID_ACCELERATION = (SENSORS_HANDLE_BASE + 0);
template <typename T> struct SensorFd : T {
- int ufd;
-
SensorFd(const struct hw_module_t *module, struct hw_device_t **device);
- ~SensorFd();
};
-template <typename T> SensorFd<T>::SensorFd(const struct hw_module_t *module, struct hw_device_t **device) : ufd(-1)
+template <typename T> SensorFd<T>::SensorFd(const struct hw_module_t *module, struct hw_device_t **device)
{
this->common.tag = HARDWARE_DEVICE_TAG;
this->common.version = 0;
LOGD("%s: module=%p dev=%p", __FUNCTION__, module, *device);
}
-template <typename T> SensorFd<T>::~SensorFd()
-{
- close(ufd);
-}
-
struct SensorPollContext : SensorFd<sensors_poll_device_t> {
public:
SensorPollContext(const struct hw_module_t *module, struct hw_device_t **device);
closedir(dir);
}
- ufd = open("/dev/uinput", O_WRONLY | O_NDELAY);
- if (ufd >= 0) {
- struct uinput_user_dev ud;
- memset(&ud, 0, sizeof(ud));
- strcpy(ud.name, "Tega V2 Buttons");
- write(ufd, &ud, sizeof(ud));
- ioctl(ufd, UI_SET_EVBIT, EV_KEY);
- ioctl(ufd, UI_SET_EVBIT, EV_REP);
- ioctl(ufd, UI_SET_KEYBIT, KEY_ESC);
- ioctl(ufd, UI_SET_KEYBIT, KEY_COMPOSE);
- ioctl(ufd, UI_SET_KEYBIT, KEY_LEFTMETA);
- ioctl(ufd, UI_DEV_CREATE, 0);
- } else {
- LOGE("could not open uinput device: %s", strerror(errno));
- }
-
pfd.events = POLLIN;
orients[ROT_0].version = sizeof(sensors_event_t);
orients[ROT_0].sensor = ID_ACCELERATION;
orients[ROT_270].acceleration.z = -sin_angle;
delay.tv_sec = 0;
- delay.tv_nsec = 300000000L;
+ delay.tv_nsec = 200000000L;
- LOGD("%s: dev=%p ufd=%d fd=%d", __FUNCTION__, this, ufd, fd);
+ LOGV("%s: dev=%p fd=%d", __FUNCTION__, this, fd);
}
SensorPollContext::~SensorPollContext()
{
LOGD("%s: dev=%p data=%p count=%d", __FUNCTION__, dev, data, count);
SensorPollContext *ctx = reinterpret_cast<SensorPollContext *>(dev);
+ struct timespec t;
struct pollfd &pfd = ctx->pfd;
+ nanosleep(&ctx->delay, 0);
while (int pollres = ::poll(&pfd, 1, -1)) {
if (pollres < 0) {
LOGE("%s: poll %d error: %s", __FUNCTION__, pfd.fd, strerror(errno));
break;
}
}
-
- if (ctx->ufd >= 0)
- write(ctx->ufd, &iev, sizeof(iev));
}
- LOGD("%s: dev=%p ufd=%d fd=%d rotation=%d", __FUNCTION__, dev, ctx->ufd, pfd.fd, ctx->rotation * 90);
- nanosleep(&ctx->delay, 0);
+ LOGV("%s: dev=%p fd=%d rotation=%d", __FUNCTION__, dev, pfd.fd, ctx->rotation * 90);
data[0] = ctx->orients[ctx->rotation];
- data[0].timestamp = time(0) * 1000000000L;
+ t.tv_sec = t.tv_nsec = 0;
+ clock_gettime(CLOCK_MONOTONIC, &t);
+ data[0].timestamp = int64_t(t.tv_sec) * 1000000000LL + t.tv_nsec;
return 1;
}