mirror of
https://github.com/moonlight-stream/moonlight-embedded.git
synced 2026-06-17 06:11:36 +00:00
Autoload input devices
This commit is contained in:
+3
-2
@@ -22,6 +22,7 @@ find_package(Freescale)
|
|||||||
find_package(PkgConfig REQUIRED)
|
find_package(PkgConfig REQUIRED)
|
||||||
pkg_check_modules(EVDEV REQUIRED libevdev)
|
pkg_check_modules(EVDEV REQUIRED libevdev)
|
||||||
pkg_check_modules(AVAHI REQUIRED avahi-client)
|
pkg_check_modules(AVAHI REQUIRED avahi-client)
|
||||||
|
pkg_check_modules(UDEV REQUIRED libudev)
|
||||||
|
|
||||||
if(BROADCOM_FOUND)
|
if(BROADCOM_FOUND)
|
||||||
aux_source_directory(./ilclient SRC_LIST)
|
aux_source_directory(./ilclient SRC_LIST)
|
||||||
@@ -45,5 +46,5 @@ elseif(FREESCALE_FOUND)
|
|||||||
target_link_libraries (moonlight PUBLIC ${FREESCALE_LIBRARIES})
|
target_link_libraries (moonlight PUBLIC ${FREESCALE_LIBRARIES})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
include_directories(./moonlight-common-c ${OPUS_INCLUDE_DIRS} ${EVDEV_INCLUDE_DIRS} ${AVAHI_INCLUDE_DIRS})
|
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})
|
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})
|
||||||
|
|||||||
+32
-2
@@ -23,6 +23,7 @@
|
|||||||
#include "libevdev/libevdev.h"
|
#include "libevdev/libevdev.h"
|
||||||
#include "limelight-common/Limelight.h"
|
#include "limelight-common/Limelight.h"
|
||||||
|
|
||||||
|
#include <libudev.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
@@ -93,8 +94,8 @@ void input_create(char* device, char* mapFile) {
|
|||||||
|
|
||||||
devices[dev].fd = open(device, O_RDONLY|O_NONBLOCK);
|
devices[dev].fd = open(device, O_RDONLY|O_NONBLOCK);
|
||||||
if (devices[dev].fd <= 0) {
|
if (devices[dev].fd <= 0) {
|
||||||
fprintf(stderr, "Failed to open device\n");
|
fprintf(stderr, "Failed to open device %s\n", device);
|
||||||
exit(EXIT_FAILURE);
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
devices[dev].dev = libevdev_new();
|
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);
|
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) {
|
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)
|
if (abs(ev->value - parms->avg) < parms->flat)
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
* along with Moonlight; if not, see <http://www.gnu.org/licenses/>.
|
* 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_create(char* device, char* mapFile);
|
||||||
void input_loop();
|
void input_loop();
|
||||||
void input_map(char* fileName);
|
void input_map(char* fileName);
|
||||||
|
|||||||
@@ -122,6 +122,7 @@ int main(int argc, char* argv[]) {
|
|||||||
char* action = NULL;
|
char* action = NULL;
|
||||||
char* address = NULL;
|
char* address = NULL;
|
||||||
char* mapping = NULL;
|
char* mapping = NULL;
|
||||||
|
bool inputs = false;
|
||||||
int option_index = 0;
|
int option_index = 0;
|
||||||
bool sops = true;
|
bool sops = true;
|
||||||
bool localaudio = false;
|
bool localaudio = false;
|
||||||
@@ -159,6 +160,7 @@ int main(int argc, char* argv[]) {
|
|||||||
break;
|
break;
|
||||||
case 'j':
|
case 'j':
|
||||||
input_create(optarg, mapping);
|
input_create(optarg, mapping);
|
||||||
|
inputs = true;
|
||||||
break;
|
break;
|
||||||
case 'k':
|
case 'k':
|
||||||
mapping = optarg;
|
mapping = optarg;
|
||||||
@@ -209,6 +211,10 @@ int main(int argc, char* argv[]) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!inputs) {
|
||||||
|
input_autoload(mapping);
|
||||||
|
}
|
||||||
|
|
||||||
client_init(address);
|
client_init(address);
|
||||||
|
|
||||||
if (strcmp("applist", action) == 0)
|
if (strcmp("applist", action) == 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user