From cc6fbb21c37f12dad8b18a9c6d5baef2bf3aef1f Mon Sep 17 00:00:00 2001 From: BPanther Date: Tue, 28 May 2024 23:19:01 +0200 Subject: [PATCH] yWeb: fix rc (thx TangoCash) --- src/nhttpd/tuxboxapi/controlapi.cpp | 101 +++++++++++++++++++++++++--- src/nhttpd/tuxboxapi/controlapi.h | 1 + 2 files changed, 91 insertions(+), 11 deletions(-) diff --git a/src/nhttpd/tuxboxapi/controlapi.cpp b/src/nhttpd/tuxboxapi/controlapi.cpp index 34606c157..48584b4da 100644 --- a/src/nhttpd/tuxboxapi/controlapi.cpp +++ b/src/nhttpd/tuxboxapi/controlapi.cpp @@ -57,10 +57,27 @@ extern cVideo *videoDecoder; extern CPlugins *g_Plugins;//for relodplugins extern CBouquetManager *g_bouquetManager; -#if HAVE_DUCKBOX_HARDWARE -#define EVENTDEV "/dev/input/event0" + +#if HAVE_SPARK_HARDWARE +#define RC_DEVICE "/dev/input/nevis_ir" +#define RC_DEVICE_FALLBACK "/dev/input/event1" + +#elif HAVE_DUCKBOX_HARDWARE +#define RC_DEVICE "/dev/input/event0" +#define RC_DEVICE_FALLBACK "/dev/input/event1" + +#elif BOXMODEL_H7 || BOXMODEL_DM8000 +#define RC_DEVICE "/dev/input/event2" +#define RC_DEVICE_FALLBACK "/dev/input/event1" + +#elif BOXMODEL_DM820 || BOXMODEL_DM900 +#define RC_DEVICE "/dev/input/event3" +#define RC_DEVICE_FALLBACK "/dev/input/event0" + #else -#define EVENTDEV "/dev/input/input0" +#define RC_DEVICE "/dev/input/event1" +#define RC_DEVICE_FALLBACK "/dev/input/event0" + #endif //----------------------------------------------------------------------------- @@ -929,13 +946,52 @@ void CControlAPI::RebootCGI(CyhookHandler *hh) } //----------------------------------------------------------------------------- -int CControlAPI::rc_send(int ev, unsigned int code, unsigned int value) +unsigned int revert_translate(unsigned int code) +{ + switch(code) + { + case RC_home: + return KEY_EXIT; + case RC_page_up: + return KEY_CHANNELUP; + case RC_page_down: + return KEY_CHANNELDOWN; +#if HAVE_ARM_HARDWARE || HAVE_MIPS_HARDWARE + case RC_mode: + return KEY_SWITCHVIDEOMODE; + case RC_play: + case RC_pause: + return KEY_PLAYPAUSE; + case RC_favorites: + return KEY_VIDEO; + case RC_forward: + return KEY_FASTFORWARD; +#endif + default: + break; + } + return code; +} + +void CControlAPI::rc_sync(int fd) +{ + struct input_event ev; + + gettimeofday(&ev.time, NULL); + ev.type = EV_SYN; + ev.code = SYN_REPORT; + ev.value = 0; + write(fd, &ev, sizeof(ev)); +} + +int CControlAPI::rc_send(int fd, unsigned int code, unsigned int value) { - struct input_event iev; - iev.type = EV_KEY; - iev.code = code; - iev.value = value; - return write(ev, &iev, sizeof(iev)); + struct input_event ev; + + ev.type = EV_KEY; + ev.code = code; + ev.value = value; + return write(fd, &ev, sizeof(ev)); } //----------------------------------------------------------------------------- @@ -963,8 +1019,31 @@ void CControlAPI::RCEmCGI(CyhookHandler *hh) return; } - /* 0 == KEY_PRESSED in rcinput.cpp */ - g_RCInput->postMsg((neutrino_msg_t) sendcode, 0); + int evd = open(RC_DEVICE, O_RDWR); + if (evd < 0) + evd = open(RC_DEVICE_FALLBACK, O_RDWR); + if (evd < 0) { + perror("opening " RC_DEVICE " failed"); + hh->SendError(); + return; + } + sendcode = revert_translate(sendcode); + if (rc_send(evd, sendcode, KEY_PRESSED) < 0) { + perror("writing 'KEY_PRESSED' event failed"); + hh->SendError(); + close(evd); + return; + } + rc_sync(evd); + if (rc_send(evd, sendcode, KEY_RELEASED) < 0) { + perror("writing 'KEY_RELEASED' event failed"); + hh->SendError(); + close(evd); + return; + } + rc_sync(evd); + close(evd); + hh->SendOk(); } //----------------------------------------------------------------------------- diff --git a/src/nhttpd/tuxboxapi/controlapi.h b/src/nhttpd/tuxboxapi/controlapi.h index 059169367..fb0299471 100644 --- a/src/nhttpd/tuxboxapi/controlapi.h +++ b/src/nhttpd/tuxboxapi/controlapi.h @@ -41,6 +41,7 @@ class CControlAPI : public Cyhook } } fsort; + void rc_sync(int fd); int rc_send(int ev, unsigned int code, unsigned int value); // send functions for ExecuteCGI (controld api)