Autoload input devices

This commit is contained in:
Iwan Timmer
2015-05-11 21:27:25 +02:00
parent 65a4685c36
commit 25ebfde470
4 changed files with 42 additions and 4 deletions

View File

@@ -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;

View File

@@ -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);

View File

@@ -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)