#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <string.h>
#include <arpa/inet.h>
#include <errno.h>
#include <signal.h>
#include <sys/poll.h>
#include <sys/epoll.h>
#include <sys/timerfd.h>
#include <fcntl.h>
#include <unistd.h>
#include <getopt.h>
#include <linux/i2c.h>
#include <linux/i2c-dev.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
/**
* @brief timer handler
*
* @param[in] fd timer file descriptor
*/
static int timer_process_fd(int fd)
{
uint64_t nb_expired = 0;
int status = -1;
ssize_t count;
do
{
count = read(fd, &nb_expired, sizeof(nb_expired));
}
while (count < 0 && errno == EINTR);
if (count < 0)
{
ULOGE("timer read (fd=%d): err=%d(%s)", fd, errno, strerror(errno));
}
else if (sizeof(nb_expired) != count)
{
ULOGE("timer unexpected read return: %zd != %zd", count, sizeof(nb_expired));
}
else
{
// status = gmsl2_check_ready();
status = touch_input_check_ready();
}
return status;
}
int main(int argv,char *argc[])
{
struct pollfd poll_fd;
struct itimerspec nval;
int fd_timer = -1;
int ret;
fd_timer = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK | TFD_CLOEXEC);
nval.it_value.tv_sec = 0;
nval.it_value.tv_nsec = 100000000; //100ms
nval.it_interval.tv_sec = nval.it_value.tv_sec;
nval.it_interval.tv_nsec = nval.it_value.tv_nsec;
ret = timerfd_settime(fd_timer, 0, &nval, NULL);
poll_fd.fd = fd_timer;
poll_fd.events = POLLIN;
printf("timer fd: %d", poll_fd.fd);
for (;;)
{
do
{
ret = poll(&poll_fd, 1, -1);
}
while (ret < 0 && errno == EINTR);
printf("timer enter...");
if (ret < 0)
{
printf("poll error=%d(%s)", errno, strerror(errno));
printf("poll fd, revents %i", poll_fd.revents);
}
// timer fd
if (poll_fd.revents != 0)
{
printf("timer enter, poll_fd.revents");
ret =1;
// ret = timer_process_fd(poll_fd.fd);
if (ret == 0)
{
printf("timer all ready, stop timer");
close(fd_timer);
poll_fd.fd = -1;
fd_timer = -1;
break;
}
}
}
if (fd_timer != -1) close(fd_timer);
printf("screenInfoMgr exiting");
}