Skip to content

Commit

Permalink
yWeb: fix rc (thx TangoCash)
Browse files Browse the repository at this point in the history
  • Loading branch information
BPanther committed May 28, 2024
1 parent 45ecd0e commit cc6fbb2
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 11 deletions.
101 changes: 90 additions & 11 deletions src/nhttpd/tuxboxapi/controlapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -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));
}

//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -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();
}
//-----------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions src/nhttpd/tuxboxapi/controlapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit cc6fbb2

Please sign in to comment.