timer timeout to evdev

This commit is contained in:
Denis 2023-12-17 17:37:58 +01:00
parent 6eb6847444
commit ea5f026e04
No known key found for this signature in database
GPG key ID: DD9B63F805CF5C03
3 changed files with 68 additions and 2 deletions

View file

@ -56,6 +56,8 @@ typedef struct dev_in_timer {
dev_timer_t* timer;
const char* name;
timer_callbacks_t callbacks;
void* user_data;
@ -384,6 +386,25 @@ static void handle_leds(const dev_in_settings_t *const conf, dev_in_t *const in_
}
}
static void handle_timeout(
const dev_in_settings_t *const conf,
dev_in_t *const in_devs,
size_t in_devs_count,
const char* name,
uint64_t expirations
) {
for (size_t i = 0; i < in_devs_count; ++i) {
if (in_devs[i].type == DEV_IN_TYPE_EV) {
in_devs[i].dev.hidraw.callbacks.timeout_callback(
conf,
name,
expirations,
in_devs[i].dev.evdev.user_data
);
}
}
}
static int open_socket(struct sockaddr_un *serveraddr) {
int res = -ENODEV;
@ -531,6 +552,7 @@ void* dev_in_thread_func(void *ptr) {
if (open_res == 0) {
devices[i].dev.timer.callbacks = dev_in_data->input_dev_decl->dev[i]->map.timer_callbacks;
devices[i].dev.timer.user_data = dev_in_data->input_dev_decl->dev[i]->user_data;
devices[i].dev.timer.name = dev_in_data->input_dev_decl->dev[i]->filters.timer.name;
devices[i].type = DEV_IN_TYPE_TIMER;
// device is now connected, query it in select
@ -686,6 +708,14 @@ void* dev_in_thread_func(void *ptr) {
devices[i].type = DEV_IN_TYPE_NONE;
continue;
}
handle_timeout(
&dev_in_data->settings,
devices,
max_devices,
devices[i].dev.timer.name,
expirations
);
}
// send messages (if any)

View file

@ -18,7 +18,19 @@ typedef struct evdev_collected {
* A function with this signature grapbs input_event data and sends to the pipe messages
* constructed from that data.
*/
typedef int (*ev_map)(const dev_in_settings_t *const conf, const evdev_collected_t *const e, in_message_t *const messages, size_t messages_len, void* user_data);
typedef int (*ev_map)(
const dev_in_settings_t *const conf,
const evdev_collected_t *const e,
in_message_t *const messages,
size_t messages_len,
void* user_data
);
typedef void (*ev_timer)(
const dev_in_settings_t *const conf,
const char* const timer_name,
uint64_t expired,
void* user_data
);
typedef enum input_dev_type {
input_dev_type_uinput,
@ -49,6 +61,7 @@ typedef struct hidraw_callbacks {
hidraw_set_leds leds_callback;
hidraw_rumble rumble_callback;
hidraw_map map_callback;
ev_timer timeout_callback;
} hidraw_callbacks_t;
typedef struct iio_settings {
@ -64,6 +77,7 @@ typedef struct timer_callbacks {
typedef struct ev_callbacks {
ev_map input_map_fn;
ev_timer timeout_callback;
} ev_callbacks_t;
typedef struct timer_filters {

View file

@ -844,6 +844,15 @@ static input_dev_t in_iio_dev = {
//.input_filter_fn = input_filter_imu_identity,
};
static void rc71l_timer_asus_kbd(
const dev_in_settings_t *const conf,
const char* const timer_name,
uint64_t expired,
void* user_data
) {
}
static input_dev_t in_asus_kb_1_dev = {
.dev_type = input_dev_type_uinput,
.filters = {
@ -855,6 +864,7 @@ static input_dev_t in_asus_kb_1_dev = {
.map = {
.ev_callbacks = {
.input_map_fn = asus_kbd_ev_map,
.timeout_callback = rc71l_timer_asus_kbd,
},
}
};
@ -870,6 +880,7 @@ static input_dev_t in_asus_kb_2_dev = {
.map = {
.ev_callbacks = {
.input_map_fn = asus_kbd_ev_map,
.timeout_callback = rc71l_timer_asus_kbd,
},
}
};
@ -885,10 +896,20 @@ static input_dev_t in_asus_kb_3_dev = {
.map = {
.ev_callbacks = {
.input_map_fn = asus_kbd_ev_map,
.timeout_callback = rc71l_timer_asus_kbd,
},
}
};
static void rc71l_timer_xbox360(
const dev_in_settings_t *const conf,
const char* const timer_name,
uint64_t expired,
void* user_data
) {
}
static input_dev_t in_xbox_dev = {
.dev_type = input_dev_type_uinput,
.filters = {
@ -899,6 +920,7 @@ static input_dev_t in_xbox_dev = {
.map = {
.ev_callbacks = {
.input_map_fn = xbox360_ev_map,
.timeout_callback = rc71l_timer_xbox360,
},
}
};
@ -1006,7 +1028,7 @@ input_dev_t timer_dev = {
.filters = {
.timer = {
.name = "RC71L_timer",
.ticktime_ms = 650,
.ticktime_ms = 150,
}
},
.user_data = NULL,