13#include <linux/version.h>
14#define HAVE_KERNEL_LIRC (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 10, 0))
16#include <netinet/in.h>
17#include <sys/socket.h>
21#include <linux/lirc.h>
25#define RECONNECTDELAY 3000
26#define LIRC_REPEAT_TIMEOUT 250
33 virtual void Action(
void)
override;
41 virtual void Action(
void)
override;
44 bool Connect(
const char *DeviceName);
80 addr.sun_family = AF_UNIX;
88 if ((
f = socket(AF_UNIX, SOCK_STREAM, 0)) >= 0) {
89 if (connect(
f, (
struct sockaddr *)&
addr,
sizeof(
addr)) >= 0)
117 int ret = ready ?
safe_read(
f, buf,
sizeof(buf)) : -1;
119 if (
f < 0 || ready && ret <= 0) {
120 esyslog(
"ERROR: lircd connection broken, trying to reconnect every %.1f seconds",
float(
RECONNECTDELAY) / 1000);
127 isyslog(
"reconnected to lircd");
137 if (sscanf(buf,
"%*x %x %29s", &count, KeyName) != 2) {
138 esyslog(
"ERROR: unparsable lirc command: %s", buf);
143 Put(LastKeyName,
false,
true);
144 strn0cpy(LastKeyName, KeyName,
sizeof(LastKeyName));
158 Put(KeyName, repeat);
162 Put(LastKeyName,
false,
true);
174 unsigned mode = LIRC_MODE_SCANCODE;
175 f = open(DeviceName, O_RDONLY, 0);
186 else if (ioctl(
f, LIRC_SET_REC_MODE, &mode)) {
205 uint64_t FirstTime = 0, LastTime = 0;
206 uint32_t LastKeyCode = 0;
207 uint16_t LastFlags =
false;
208 bool SeenRepeat =
false;
213 ssize_t ret = read(
f, &sc,
sizeof sc);
215 if (ret ==
sizeof sc) {
216 const bool SameKey = sc.keycode == LastKeyCode && !((sc.flags ^ LastFlags) & LIRC_SCANCODE_FLAG_TOGGLE);
218 if ((sc.flags & LIRC_SCANCODE_FLAG_REPEAT) != 0)
222 if (SameKey && uint((sc.timestamp - FirstTime) / 1000000) < uint(
Setup.RcRepeatDelay))
225 if (!SameKey || (SeenRepeat && !(sc.flags & LIRC_SCANCODE_FLAG_REPEAT))) {
228 Put(LastKeyCode,
false,
true);
230 FirstTime = sc.timestamp;
231 LastKeyCode = sc.keycode;
232 LastFlags = sc.flags;
234 else if (uint((sc.timestamp - LastTime) / 1000000) < uint(
Setup.RcRepeatDelta))
239 LastTime = sc.timestamp;
240 Put(sc.keycode, repeat);
244 Put(LastKeyCode,
false,
true);
static void SleepMs(int TimeoutMs)
Creates a cCondWait object and uses it to sleep for TimeoutMs milliseconds, immediately giving up the...
static bool FileReady(int FileDes, int TimeoutMs=1000)
virtual void Action(void) override
A derived cThread class must implement the code it wants to execute as a separate thread in this func...
bool Connect(const char *DeviceName)
virtual ~cLircRemote() override
virtual bool Ready(void) override
static void NewLircRemote(const char *Name)
cLircRemote(const char *Name)
cLircUsrRemote(const char *DeviceName)
virtual void Action(void) override
A derived cThread class must implement the code it wants to execute as a separate thread in this func...
bool Put(uint64_t Code, bool Repeat=false, bool Release=false)
cRemote(const char *Name)
void bool Start(void)
Sets the description of this thread, which will be used when logging starting or stopping of the thre...
bool Running(void)
Returns false if a derived cThread object shall leave its Action() function.
cThread(const char *Description=NULL, bool LowPriority=false)
Creates a new thread.
void Cancel(int WaitSeconds=0)
Cancels the thread by first setting 'running' to false, so that the Action() loop can finish in an or...
uint64_t Elapsed(void) const
Returns the number of milliseconds that have elapsed since the last call to Set().
void Set(int Ms=0)
Sets the timer.
#define LIRC_REPEAT_TIMEOUT