2022-08-30 17:54:56 -05:00
|
|
|
// vi:ft=c
|
2022-08-31 11:54:14 -05:00
|
|
|
#ifndef HID_H_
|
|
|
|
#define HID_H_
|
2022-08-30 08:37:34 -05:00
|
|
|
#include "net.h"
|
2022-10-07 18:36:53 -05:00
|
|
|
#include "server.h"
|
2022-08-30 17:56:56 -05:00
|
|
|
|
2022-08-31 11:59:06 -05:00
|
|
|
#include <linux/input-event-codes.h>
|
2022-08-30 08:37:34 -05:00
|
|
|
#include <stdint.h>
|
2022-08-27 19:29:43 -05:00
|
|
|
|
2022-08-31 16:24:26 -05:00
|
|
|
// Unique identifier for devices (provided by linux), May be the mac address
|
2022-08-29 17:27:03 -05:00
|
|
|
typedef uint64_t uniq_t;
|
2022-08-27 19:29:43 -05:00
|
|
|
|
2022-08-31 16:24:26 -05:00
|
|
|
// Mapping to go from index to id of events
|
|
|
|
// the id of an event is the code field of a input_event struct
|
|
|
|
// the index is given (somewhat arbitrarily) by hid.c::setup_device, this is done because ids are sparse
|
|
|
|
// and innefficient to transfer over network (especially for keys that can range from 0 to 700).
|
2022-08-29 17:27:03 -05:00
|
|
|
typedef struct {
|
2022-08-30 17:54:56 -05:00
|
|
|
uint16_t abs_indices[ABS_CNT];
|
|
|
|
uint16_t rel_indices[REL_CNT];
|
|
|
|
uint16_t key_indices[KEY_CNT];
|
2022-08-30 08:37:34 -05:00
|
|
|
} DeviceMap;
|
|
|
|
|
2022-08-31 16:24:26 -05:00
|
|
|
// A struct representing a connected device
|
2022-08-30 08:37:34 -05:00
|
|
|
typedef struct {
|
|
|
|
int event;
|
|
|
|
int hidraw;
|
|
|
|
uniq_t uniq;
|
|
|
|
char *name;
|
|
|
|
DeviceMap mapping;
|
|
|
|
MessageDeviceInfo device_info;
|
2022-08-29 17:27:03 -05:00
|
|
|
} PhysicalDevice;
|
|
|
|
|
2022-10-07 18:36:53 -05:00
|
|
|
typedef struct {
|
|
|
|
PhysicalDevice dev;
|
|
|
|
ServerConfigController ctr;
|
|
|
|
} Controller;
|
|
|
|
|
|
|
|
void *hid_thread(void *arg);
|
|
|
|
void return_device(Controller *c);
|
|
|
|
void forget_device(Controller *c);
|
|
|
|
Controller *get_device(char *tag);
|
|
|
|
void apply_controller_state(Controller *c, MessageControllerState *state);
|
2022-08-27 19:29:43 -05:00
|
|
|
|
|
|
|
#endif
|