mirror of
https://github.com/moonlight-stream/moonlight-embedded.git
synced 2026-02-16 02:20:42 +00:00
Autoload input devices
This commit is contained in:
@@ -22,6 +22,7 @@ find_package(Freescale)
|
||||
find_package(PkgConfig REQUIRED)
|
||||
pkg_check_modules(EVDEV REQUIRED libevdev)
|
||||
pkg_check_modules(AVAHI REQUIRED avahi-client)
|
||||
pkg_check_modules(UDEV REQUIRED libudev)
|
||||
|
||||
if(BROADCOM_FOUND)
|
||||
aux_source_directory(./ilclient SRC_LIST)
|
||||
@@ -45,5 +46,5 @@ elseif(FREESCALE_FOUND)
|
||||
target_link_libraries (moonlight PUBLIC ${FREESCALE_LIBRARIES})
|
||||
endif()
|
||||
|
||||
include_directories(./moonlight-common-c ${OPUS_INCLUDE_DIRS} ${EVDEV_INCLUDE_DIRS} ${AVAHI_INCLUDE_DIRS})
|
||||
target_link_libraries (moonlight PUBLIC ${CMAKE_THREAD_LIBS_INIT} ${CURL_LIBRARIES} ${OPENSSL_LIBRARIES} ${EXPAT_LIBRARIES} ${EVDEV_LIBRARIES} ${ALSA_LIBRARY} ${OPUS_LIBRARY} ${AVAHI_LIBRARIES})
|
||||
include_directories(./moonlight-common-c ${OPUS_INCLUDE_DIRS} ${EVDEV_INCLUDE_DIRS} ${AVAHI_INCLUDE_DIRS} ${UDEV_INCLUDE_DIRS})
|
||||
target_link_libraries (moonlight PUBLIC ${CMAKE_THREAD_LIBS_INIT} ${CURL_LIBRARIES} ${OPENSSL_LIBRARIES} ${EXPAT_LIBRARIES} ${EVDEV_LIBRARIES} ${ALSA_LIBRARY} ${OPUS_LIBRARY} ${AVAHI_LIBRARIES} ${UDEV_LIBRARIES})
|
||||
|
||||
34
src/input.c
34
src/input.c
@@ -23,6 +23,7 @@
|
||||
#include "libevdev/libevdev.h"
|
||||
#include "limelight-common/Limelight.h"
|
||||
|
||||
#include <libudev.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
@@ -93,8 +94,8 @@ void input_create(char* device, char* mapFile) {
|
||||
|
||||
devices[dev].fd = open(device, O_RDONLY|O_NONBLOCK);
|
||||
if (devices[dev].fd <= 0) {
|
||||
fprintf(stderr, "Failed to open device\n");
|
||||
exit(EXIT_FAILURE);
|
||||
fprintf(stderr, "Failed to open device %s\n", device);
|
||||
return;
|
||||
}
|
||||
|
||||
devices[dev].dev = libevdev_new();
|
||||
@@ -116,6 +117,35 @@ void input_create(char* device, char* mapFile) {
|
||||
input_init_parms(&devices[dev], &(devices[dev].dpadyParms), devices[dev].map.abs_dpad_y);
|
||||
}
|
||||
|
||||
void input_autoload(char* mapfile) {
|
||||
struct udev *udev = udev_new();
|
||||
if (!udev) {
|
||||
fprintf(stderr, "Can't create udev\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
struct udev_enumerate *enumerate = udev_enumerate_new(udev);
|
||||
udev_enumerate_add_match_subsystem(enumerate, "input");
|
||||
udev_enumerate_scan_devices(enumerate);
|
||||
struct udev_list_entry *devices = udev_enumerate_get_list_entry(enumerate);
|
||||
|
||||
struct udev_list_entry *dev_list_entry;
|
||||
udev_list_entry_foreach(dev_list_entry, devices) {
|
||||
const char *path = udev_list_entry_get_name(dev_list_entry);
|
||||
struct udev_device *dev = udev_device_new_from_syspath(udev, path);
|
||||
const char *devnode = udev_device_get_devnode(dev);
|
||||
int id;
|
||||
if (devnode != NULL && sscanf(devnode, "/dev/input/event%d", &id) == 1) {
|
||||
input_create(devnode, mapfile);
|
||||
}
|
||||
udev_device_unref(dev);
|
||||
}
|
||||
|
||||
udev_enumerate_unref(enumerate);
|
||||
|
||||
udev_unref(udev);
|
||||
}
|
||||
|
||||
static short input_convert_value(struct input_event *ev, struct input_device *dev, struct input_abs_parms *parms, bool reverse) {
|
||||
if (abs(ev->value - parms->avg) < parms->flat)
|
||||
return 0;
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
* along with Moonlight; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
void input_autoload(char* mapfile);
|
||||
void input_create(char* device, char* mapFile);
|
||||
void input_loop();
|
||||
void input_map(char* fileName);
|
||||
|
||||
@@ -122,6 +122,7 @@ int main(int argc, char* argv[]) {
|
||||
char* action = NULL;
|
||||
char* address = NULL;
|
||||
char* mapping = NULL;
|
||||
bool inputs = false;
|
||||
int option_index = 0;
|
||||
bool sops = true;
|
||||
bool localaudio = false;
|
||||
@@ -159,6 +160,7 @@ int main(int argc, char* argv[]) {
|
||||
break;
|
||||
case 'j':
|
||||
input_create(optarg, mapping);
|
||||
inputs = true;
|
||||
break;
|
||||
case 'k':
|
||||
mapping = optarg;
|
||||
@@ -209,6 +211,10 @@ int main(int argc, char* argv[]) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!inputs) {
|
||||
input_autoload(mapping);
|
||||
}
|
||||
|
||||
client_init(address);
|
||||
|
||||
if (strcmp("applist", action) == 0)
|
||||
|
||||
Reference in New Issue
Block a user