Skip to content

Commit

Permalink
everything seems to work
Browse files Browse the repository at this point in the history
  • Loading branch information
raleighlittles committed Jul 25, 2022
1 parent 1838709 commit 0582ddd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 38 deletions.
19 changes: 9 additions & 10 deletions cpp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ int main(int /* argc */, char** /* argv[] */ )
/// ---------- ///
/// Setup the virtual driver

const int uinputFileDescriptor = setupKeyboardUinput();
const int uinputFileDescriptorForMouse = setupMouseUinput();
const int uinputFileDescriptor = setupUinput();

sleep (1);

Expand Down Expand Up @@ -117,26 +116,26 @@ int main(int /* argc */, char** /* argv[] */ )

case 0x90:
std::cout << "D-Pad up pressed" << std::endl;
emit(uinputFileDescriptorForMouse, EV_REL, REL_Y, +5);
emit(uinputFileDescriptorForMouse, EV_SYN, SYN_REPORT, 0);
emit(uinputFileDescriptor, EV_REL, REL_Y, -5);
emit(uinputFileDescriptor, EV_SYN, SYN_REPORT, 0);
break;

case 0x91:
std::cout << "D-pad down pressed" << std::endl;
emit(uinputFileDescriptorForMouse, EV_REL, REL_Y, -5);
emit(uinputFileDescriptorForMouse, EV_SYN, SYN_REPORT, 0);
emit(uinputFileDescriptor, EV_REL, REL_Y, +5);
emit(uinputFileDescriptor, EV_SYN, SYN_REPORT, 0);
break;

case 0x92:
std::cout << "D-pad left pressed" << std::endl;
emit(uinputFileDescriptorForMouse, EV_REL, REL_X, -5);
emit(uinputFileDescriptorForMouse, EV_SYN, SYN_REPORT, 0);
emit(uinputFileDescriptor, EV_REL, REL_X, -5);
emit(uinputFileDescriptor, EV_SYN, SYN_REPORT, 0);
break;

case 0x93:
std::cout << "D-Pad right pressed" << std::endl;
emit(uinputFileDescriptorForMouse, EV_REL, REL_X, +5);
emit(uinputFileDescriptorForMouse, EV_SYN, SYN_REPORT, 0);
emit(uinputFileDescriptor, EV_REL, REL_X, +5);
emit(uinputFileDescriptor, EV_SYN, SYN_REPORT, 0);
break;

case 0x0A:
Expand Down
32 changes: 4 additions & 28 deletions cpp/uinput_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ std::map<KeyType, int> keyMap = { std::make_pair(KeyType::SIDE_BUTTON, KEY_MUTE)
std::make_pair(KeyType::SCROLL_WHEEL_DOWN, KEY_SCROLLDOWN),
std::make_pair(KeyType::SCROLL_WHEEL_CLICK, KEY_PAUSE),
std::make_pair(KeyType::BUTTON_3, KEY_ENTER),
std::make_pair(KeyType::BUTTON_A, KEY_A),
std::make_pair(KeyType::BUTTON_B, KEY_B),
std::make_pair(KeyType::BUTTON_A, BTN_LEFT),
std::make_pair(KeyType::BUTTON_B, BTN_RIGHT),
std::make_pair(KeyType::BUTTON_6, KEY_DOT),
std::make_pair(KeyType::BUTTON_7, KEY_MENU),
std::make_pair(KeyType::IPOD_WHEEL_CLOCKWISE, KEY_VOLUMEUP),
Expand Down Expand Up @@ -105,13 +105,14 @@ void registerMouseEvents(int fileDescriptor)
}


int setupKeyboardUinput(void)
int setupUinput(void)
{
struct uinput_setup usetup;

int fd = open("/dev/uinput", O_WRONLY | O_NONBLOCK);

registerKeyboardEvents(fd);
registerMouseEvents(fd);

usleep(1000);

Expand All @@ -128,31 +129,6 @@ int setupKeyboardUinput(void)
return fd;
}


int setupMouseUinput(void)
{
struct uinput_setup usetup;

int fd = open("/dev/uinput", O_WRONLY | O_NONBLOCK);

registerMouseEvents(fd);

usleep(1000);

memset(&usetup, 0, sizeof(usetup));
usetup.id.bustype = BUS_USB;
usetup.id.vendor = 0x0483; /* Same vendor as default device */

usetup.id.product = 0xDEAD; /* Bogus product ID */

strcpy(usetup.name,"Custom Tourbox TBG_H Driver (Mouse)");

ioctl(fd, UI_DEV_SETUP, &usetup);
ioctl(fd, UI_DEV_CREATE);

return fd;
}

void destroyUinput(int fileDescriptor)
{
ioctl(fileDescriptor, UI_DEV_DESTROY);
Expand Down

0 comments on commit 0582ddd

Please sign in to comment.