Basic driver name/image interaction
This commit is contained in:
		
							
								
								
									
										1
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								Makefile
									
									
									
									
									
								
							@@ -30,6 +30,7 @@ $(BUILD_DIR)/glib-2.0/schemas/gschemas.compiled: v.ginput.gschema.xml | $(BUILD_
 | 
			
		||||
	glib-compile-schemas . --targetdir=$(BUILD_DIR)/glib-2.0/schemas
 | 
			
		||||
 | 
			
		||||
# Drivers
 | 
			
		||||
.PHONY: $(BUILD_DIR)/drivers
 | 
			
		||||
$(BUILD_DIR)/drivers:
 | 
			
		||||
	cd drivers && make
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -4,14 +4,19 @@
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
 | 
			
		||||
#define DEVICE_NAME "HTX 4K"
 | 
			
		||||
#define DEVICE_VENDOR_ID 0x33e4
 | 
			
		||||
#define DEVICE_PRODUCT_ID_WIRELESS 0x5707
 | 
			
		||||
 | 
			
		||||
void driver_init(void)
 | 
			
		||||
{
 | 
			
		||||
    printf("Hello from G-Wolves HTX driver !\n");
 | 
			
		||||
}
 | 
			
		||||
void driver_init(void) {}
 | 
			
		||||
 | 
			
		||||
uint32_t driver_getkey(void)
 | 
			
		||||
{
 | 
			
		||||
    static int count = 0;
 | 
			
		||||
    count++;
 | 
			
		||||
 | 
			
		||||
    if(count == 1)
 | 
			
		||||
        return (DEVICE_VENDOR_ID << 16) | DEVICE_PRODUCT_ID_WIRELESS;
 | 
			
		||||
    
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,10 +1,15 @@
 | 
			
		||||
#include "device.h"
 | 
			
		||||
#include "utils/array.h"
 | 
			
		||||
#include "usb/usb.h"
 | 
			
		||||
#include <dlfcn.h>
 | 
			
		||||
 | 
			
		||||
struct DEVICE
 | 
			
		||||
{
 | 
			
		||||
    // Device driver
 | 
			
		||||
    void* driver;
 | 
			
		||||
 | 
			
		||||
    // Physical device handle
 | 
			
		||||
    void* handle;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
array_t* device_array;
 | 
			
		||||
@@ -20,12 +25,25 @@ array_t* device_get_array()
 | 
			
		||||
    return device_array;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
device_t* device_register(void* driver, void* handle)
 | 
			
		||||
{
 | 
			
		||||
    device_t* tr = malloc(sizeof(device_t));
 | 
			
		||||
    tr->driver = driver;
 | 
			
		||||
    tr->handle = handle;
 | 
			
		||||
 | 
			
		||||
    array_add(device_array, tr);
 | 
			
		||||
 | 
			
		||||
    return tr;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
char* device_get_image(device_t* device)
 | 
			
		||||
{
 | 
			
		||||
    return "/home/valentin/Documents/prjs/ginput/drivers/g-wolves/htx/htx_0.png";
 | 
			
		||||
    char* (*getimage_fn)(void) = dlsym(device->driver, "driver_get_image");
 | 
			
		||||
    return getimage_fn();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
char* device_get_name(device_t* device)
 | 
			
		||||
{
 | 
			
		||||
    return "G-Wolves HTX 4K";
 | 
			
		||||
    char* (*getname_fn)(void) = dlsym(device->driver, "driver_get_name");
 | 
			
		||||
    return getname_fn();
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -11,6 +11,7 @@ void device_init();
 | 
			
		||||
array_t* device_get_array();
 | 
			
		||||
 | 
			
		||||
// Handling a single device
 | 
			
		||||
device_t* device_register(void* driver, void* handle);
 | 
			
		||||
char* device_get_image(device_t* device);
 | 
			
		||||
char* device_get_name(device_t* device);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -89,16 +89,12 @@ void usb_init()
 | 
			
		||||
        struct libusb_device_descriptor desc;
 | 
			
		||||
        libusb_get_device_descriptor(current, &desc);
 | 
			
		||||
 | 
			
		||||
        // printf("Found usb device %04x:%04x\n", desc.idVendor, desc.idProduct);
 | 
			
		||||
        // array_t* array = device_get_array();
 | 
			
		||||
        // array_add(array, 0);
 | 
			
		||||
        uint32_t key = (desc.idVendor << 16) | desc.idProduct;
 | 
			
		||||
        void* driver = hashmap_get(usb_drivers, key);
 | 
			
		||||
        if(!driver) continue;
 | 
			
		||||
 | 
			
		||||
        // libusb_device_handle* handle;
 | 
			
		||||
        // libusb_open(current, &handle);
 | 
			
		||||
        // char buf[4096] = {0};
 | 
			
		||||
        // libusb_get_string_descriptor_ascii(handle, 1, buf, 4096);
 | 
			
		||||
        // printf("Device desc (1): %s\n", buf);
 | 
			
		||||
        // libusb_get_string_descriptor_ascii(handle, 2, buf, 4096);
 | 
			
		||||
        // printf("Device desc (2): %s\n", buf);
 | 
			
		||||
        printf("Found driver for usb device %04x:%04x\n", desc.idVendor, desc.idProduct);
 | 
			
		||||
 | 
			
		||||
        device_register(driver, current);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user