Scan for input
This commit is contained in:
parent
37a0eb51df
commit
ae0892eec6
4 changed files with 73 additions and 4 deletions
64
input_dev.c
64
input_dev.c
|
|
@ -9,15 +9,73 @@
|
|||
|
||||
#include "input_dev.h"
|
||||
|
||||
#include <dirent.h>
|
||||
#include <stdio.h>
|
||||
|
||||
pthread_mutex_t input_acquire_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
void *input_dev_thread_func(void *ptr) {
|
||||
input_dev_t *out_dev = (input_dev_t*)ptr;
|
||||
|
||||
for (;;) {
|
||||
uint32_t flags = out_dev->crtl_flags;
|
||||
if (flags & INPUT_DEV_CTRL_FLAG_EXIT) {
|
||||
out_dev->crtl_flags &= ~INPUT_DEV_CTRL_FLAG_EXIT;
|
||||
const uint32_t flags = out_dev->crtl_flags;
|
||||
if (flags & INPUT_DEV_CTRL_FLAG_EXIT) {
|
||||
out_dev->crtl_flags &= ~INPUT_DEV_CTRL_FLAG_EXIT;
|
||||
break;
|
||||
}
|
||||
|
||||
const int input_acquire_lock_result = pthread_mutex_lock(&input_acquire_mutex);
|
||||
if (input_acquire_lock_result != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
char path[512] = "\0";
|
||||
const char *input_path = "/sys/class/input/";
|
||||
|
||||
DIR *d;
|
||||
struct dirent *dir;
|
||||
d = opendir(input_path);
|
||||
if (d) {
|
||||
while ((dir = readdir(d)) != NULL) {
|
||||
if (dir->d_name[0] == '.') {
|
||||
continue;
|
||||
}
|
||||
|
||||
sprintf(path, "%s%s", input_path, dir->d_name);
|
||||
|
||||
printf("device: %s\n", path);
|
||||
|
||||
char name[510] = "\0";
|
||||
|
||||
char name_path[512] = "\0";
|
||||
sprintf(name_path, "%s/device/name", path);
|
||||
|
||||
FILE* n = fopen(name_path, "r");
|
||||
if (n == NULL) {
|
||||
fprintf(stderr, " name: [ERROR]: %s\n", name_path);
|
||||
continue;
|
||||
}
|
||||
|
||||
fseek(n, 0L, SEEK_END);
|
||||
const size_t name_length = ftell(n);
|
||||
fseek(n, 0L, SEEK_SET);
|
||||
fread(name, 1, name_length, n);
|
||||
fclose(n);
|
||||
printf(" name: %s\n", name);
|
||||
}
|
||||
closedir(d);
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&input_acquire_mutex);
|
||||
|
||||
for (;;) {
|
||||
// TODO: do the required
|
||||
|
||||
const uint32_t flags = out_dev->crtl_flags;
|
||||
if (flags & INPUT_DEV_CTRL_FLAG_EXIT) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
|
|
|||
|
|
@ -4,7 +4,14 @@
|
|||
|
||||
#define INPUT_DEV_CTRL_FLAG_EXIT 0x00000001U
|
||||
|
||||
typedef enum input_dev_type {
|
||||
input_dev_type_uinput,
|
||||
input_dev_type_iio,
|
||||
} input_dev_type_t;
|
||||
|
||||
typedef struct input_dev {
|
||||
input_dev_type_t dev_type;
|
||||
|
||||
volatile uint32_t crtl_flags;
|
||||
} input_dev_t;
|
||||
|
||||
|
|
|
|||
4
main.c
4
main.c
|
|
@ -19,18 +19,22 @@ output_dev_t out_gamepadd_dev = {
|
|||
};
|
||||
|
||||
input_dev_t in_asus_kb_1_dev = {
|
||||
.dev_type = input_dev_type_uinput,
|
||||
.crtl_flags = 0x00000000U,
|
||||
};
|
||||
|
||||
input_dev_t in_asus_kb_2_dev = {
|
||||
.dev_type = input_dev_type_uinput,
|
||||
.crtl_flags = 0x00000000U,
|
||||
};
|
||||
|
||||
input_dev_t in_asus_kb_3_dev = {
|
||||
.dev_type = input_dev_type_uinput,
|
||||
.crtl_flags = 0x00000000U,
|
||||
};
|
||||
|
||||
input_dev_t in_xbox_dev = {
|
||||
.dev_type = input_dev_type_uinput,
|
||||
.crtl_flags = 0x00000000U,
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -150,7 +150,7 @@ void *output_dev_thread_func(void *ptr) {
|
|||
output_dev_t *out_dev = (output_dev_t*)ptr;
|
||||
|
||||
for (;;) {
|
||||
uint32_t flags = out_dev->crtl_flags;
|
||||
const uint32_t flags = out_dev->crtl_flags;
|
||||
if (flags & OUTPUT_DEV_CTRL_FLAG_EXIT) {
|
||||
out_dev->crtl_flags &= ~OUTPUT_DEV_CTRL_FLAG_EXIT;
|
||||
break;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue