diff --git a/.gitmodules b/.gitmodules index 12be370b..35a99f82 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "dependencies/libe131"] path = dependencies/libe131 url = https://github.com/CalcProgrammer1/libe131 +[submodule "razer-drivers-win32"] + path = razer-drivers-win32 + url = https://github.com/rsandoz/razer-drivers-win32 diff --git a/OpenRGB.cpp b/OpenRGB.cpp index d2808468..6d066d41 100644 --- a/OpenRGB.cpp +++ b/OpenRGB.cpp @@ -317,7 +317,7 @@ void DetectRGBControllers(void) \*-------------------------------------*/ #ifdef WIN32 //DetectAorusGPUControllers(rgb_controllers); - + DetectOpenRazerControllers(rgb_controllers); /*-------------------------------------*\ | Linux-only devices | \*-------------------------------------*/ diff --git a/OpenRGB.pro b/OpenRGB.pro index 99524cbf..02fd9fd6 100644 --- a/OpenRGB.pro +++ b/OpenRGB.pro @@ -185,6 +185,7 @@ win32:INCLUDEPATH += \ dependencies/inpout32_1501/Win32/ \ dependencies/libusb-1.0.22/include \ dependencies/hidapi \ + dependencies/openrazer-win32 \ wmi/ \ win32:SOURCES += \ @@ -194,7 +195,9 @@ win32:SOURCES += \ serial_port/find_usb_serial_port_win.cpp \ wmi/wmi.cpp \ RGBController/AorusGPUDetect.cpp \ + RGBController/OpenRazerWindowsDetect.cpp \ RGBController/RGBController_AorusGPU.cpp \ + RGBController/RGBController_OpenRazerWindows.cpp \ win32:HEADERS += \ dependencies/inpout32_1501/Win32/inpout32.h \ @@ -203,6 +206,7 @@ win32:HEADERS += \ i2c_smbus/i2c_smbus_piix4.h \ wmi/wmi.h \ RGBController/RGBController_AorusGPU.h \ + RGBController/RGBController_OpenRazerWindows.h \ win32:LIBS += \ -lws2_32 \ @@ -220,6 +224,16 @@ win32:DEFINES += \ _WINSOCK_DEPRECATED_NO_WARNINGS \ WIN32_LEAN_AND_MEAN +# Copy OpenRazer.dll to output directory +win32 +{ + copydata.commands = $(COPY_FILE) \"$$shell_path($$PWD\\dependencies\\openrazer-win32\\OpenRazer.dll)\" \"$$shell_path($$OUT_PWD)\" + first.depends = $(first) copydata + export(first.depends) + export(copydata.commands) + QMAKE_EXTRA_TARGETS += first copydata +} + #----------------------------------------------- # Linux specific project configuration #----------------------------------------------- diff --git a/RGBController/OpenRazerWindowsDetect.cpp b/RGBController/OpenRazerWindowsDetect.cpp new file mode 100644 index 00000000..93d2250f --- /dev/null +++ b/RGBController/OpenRazerWindowsDetect.cpp @@ -0,0 +1,316 @@ +#include "RGBController.h" +#include "RGBController_OpenRazerWindows.h" +#include +#include +#include +#include + +#include +#include +#include + +#ifdef _WIN64 +#define OPENRAZERDLL "OpenRazer64.dll" +#elif WIN32 +#define OPENRAZERDLL "OpenRazer.dll" +#endif + +/******************************************************************************************\ +* * +* DetectOpenRazerControllers * +* * +* Detect devices supported by the OpenRazer kernel drivers * +* * +\******************************************************************************************/ + +void DetectOpenRazerControllers(std::vector &rgb_controllers) +{ + static HMODULE module = LoadLibrary(OPENRAZERDLL); + + if(module == nullptr) + { + return; + } + + // map DLL calls + typedef unsigned int(*INITRAZERDRIVER)(struct hid_device** hdev); + + INITRAZERDRIVER init_razer_kbd_driver = reinterpret_cast(GetProcAddress(module, "init_razer_kbd_driver")); + static struct device_attribute devkbd_attr_device_type = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devkbd_attr_device_type")); + static struct device_attribute devkbd_attr_device_serial = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devkbd_attr_device_serial")); + static struct device_attribute devkbd_attr_firmware_version = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devkbd_attr_firmware_version")); + static struct device_attribute devkbd_attr_matrix_effect_custom = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devkbd_attr_matrix_effect_custom")); + static struct device_attribute devkbd_attr_matrix_custom_frame = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devkbd_attr_matrix_custom_frame")); + static struct device_attribute devkbd_attr_matrix_brightness = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devkbd_attr_matrix_brightness")); + static struct device_attribute devkbd_attr_matrix_effect_none = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devkbd_attr_matrix_effect_none")); + static struct device_attribute devkbd_attr_matrix_effect_static = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devkbd_attr_matrix_effect_static")); + static struct device_attribute devkbd_attr_matrix_effect_breath = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devkbd_attr_matrix_effect_breath")); + static struct device_attribute devkbd_attr_matrix_effect_spectrum = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devkbd_attr_matrix_effect_spectrum")); + static struct device_attribute devkbd_attr_matrix_effect_reactive = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devkbd_attr_matrix_effect_reactive")); + static struct device_attribute devkbd_attr_matrix_effect_wave = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devkbd_attr_matrix_effect_wave")); + + INITRAZERDRIVER init_razer_mousemat_driver = reinterpret_cast(GetProcAddress(module, "init_razer_mousemat_driver")); + static struct device_attribute devmousemat_attr_device_type = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devmousemat_attr_device_type")); + static struct device_attribute devmousemat_attr_device_serial = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devmousemat_attr_device_serial")); + static struct device_attribute devmousemat_attr_firmware_version = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devmousemat_attr_firmware_version")); + static struct device_attribute devmousemat_attr_matrix_effect_custom = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devmousemat_attr_matrix_effect_custom")); + static struct device_attribute devmousemat_attr_matrix_custom_frame = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devmousemat_attr_matrix_custom_frame")); + static struct device_attribute devmousemat_attr_matrix_brightness = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devmousemat_attr_matrix_brightness")); + static struct device_attribute devmousemat_attr_matrix_effect_none = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devmousemat_attr_matrix_effect_none")); + static struct device_attribute devmousemat_attr_matrix_effect_static = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devmousemat_attr_matrix_effect_static")); + static struct device_attribute devmousemat_attr_matrix_effect_breath = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devmousemat_attr_matrix_effect_breath")); + static struct device_attribute devmousemat_attr_matrix_effect_spectrum = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devmousemat_attr_matrix_effect_spectrum")); + static struct device_attribute devmousemat_attr_matrix_effect_reactive = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devmousemat_attr_matrix_effect_reactive")); + static struct device_attribute devmousemat_attr_matrix_effect_wave = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devmousemat_attr_matrix_effect_wave")); + + INITRAZERDRIVER init_razer_mouse_driver = reinterpret_cast(GetProcAddress(module, "init_razer_mouse_driver")); + static struct device_attribute devmouse_attr_device_type = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devmouse_attr_device_type")); + static struct device_attribute devmouse_attr_device_serial = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devmouse_attr_device_serial")); + static struct device_attribute devmouse_attr_firmware_version = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devmouse_attr_firmware_version")); + static struct device_attribute devmouse_attr_matrix_effect_custom = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devmouse_attr_matrix_effect_custom")); + static struct device_attribute devmouse_attr_matrix_custom_frame = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devmouse_attr_matrix_custom_frame")); + static struct device_attribute devmouse_attr_matrix_brightness = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devmouse_attr_matrix_brightness")); + static struct device_attribute devmouse_attr_logo_led_brightness = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devmouse_attr_logo_led_brightness")); + static struct device_attribute devmouse_attr_scroll_led_brightness = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devmouse_attr_scroll_led_brightness")); + static struct device_attribute devmouse_attr_matrix_effect_none = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devmouse_attr_matrix_effect_none")); + static struct device_attribute devmouse_attr_logo_matrix_effect_none = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devmouse_attr_logo_matrix_effect_none")); + static struct device_attribute devmouse_attr_scroll_matrix_effect_none = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devmouse_attr_scroll_matrix_effect_none")); + static struct device_attribute devmouse_attr_matrix_effect_static = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devmouse_attr_matrix_effect_static")); + static struct device_attribute devmouse_attr_logo_matrix_effect_static = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devmouse_attr_logo_matrix_effect_static")); + static struct device_attribute devmouse_attr_scroll_matrix_effect_static = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devmouse_attr_scroll_matrix_effect_static")); + static struct device_attribute devmouse_attr_matrix_effect_breath = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devmouse_attr_matrix_effect_breath")); + static struct device_attribute devmouse_attr_matrix_effect_spectrum = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devmouse_attr_matrix_effect_spectrum")); + static struct device_attribute devmouse_attr_logo_matrix_effect_spectrum = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devmouse_attr_logo_matrix_effect_spectrum")); + static struct device_attribute devmouse_attr_scroll_matrix_effect_spectrum = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devmouse_attr_scroll_matrix_effect_spectrum")); + static struct device_attribute devmouse_attr_matrix_effect_reactive = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devmouse_attr_matrix_effect_reactive")); + static struct device_attribute devmouse_attr_logo_matrix_effect_reactive = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devmouse_attr_logo_matrix_effect_reactive")); + static struct device_attribute devmouse_attr_scroll_matrix_effect_reactive = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devmouse_attr_scroll_matrix_effect_reactive")); + static struct device_attribute devmouse_attr_scroll_led_effect = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devmouse_attr_scroll_led_effect")); + static struct device_attribute devmouse_attr_scroll_led_rgb = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devmouse_attr_scroll_led_rgb")); + static struct device_attribute devmouse_attr_scroll_led_state = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devmouse_attr_scroll_led_state")); + static struct device_attribute devmouse_attr_matrix_effect_wave = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devmouse_attr_matrix_effect_wave")); + + INITRAZERDRIVER init_razer_accessory_driver = reinterpret_cast(GetProcAddress(module, "init_razer_accessory_driver")); + static struct device_attribute devaccessory_attr_device_type = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devaccessory_attr_device_type")); + static struct device_attribute devaccessory_attr_device_serial = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devaccessory_attr_device_serial")); + static struct device_attribute devaccessory_attr_firmware_version = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devaccessory_attr_firmware_version")); + static struct device_attribute devaccessory_attr_matrix_effect_custom = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devaccessory_attr_matrix_effect_custom")); + static struct device_attribute devaccessory_attr_matrix_custom_frame = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devaccessory_attr_matrix_custom_frame")); + static struct device_attribute devaccessory_attr_matrix_brightness = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devaccessory_attr_matrix_brightness")); + static struct device_attribute devaccessory_attr_matrix_effect_none = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devaccessory_attr_matrix_effect_none")); + static struct device_attribute devaccessory_attr_matrix_effect_static = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devaccessory_attr_matrix_effect_static")); + static struct device_attribute devaccessory_attr_matrix_effect_breath = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devaccessory_attr_matrix_effect_breath")); + static struct device_attribute devaccessory_attr_matrix_effect_spectrum = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devaccessory_attr_matrix_effect_spectrum")); + //static struct device_attribute devaccessory_attr_matrix_effect_reactive = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devaccessory_attr_matrix_effect_reactive")); + static struct device_attribute devaccessory_attr_matrix_effect_wave = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devaccessory_attr_matrix_effect_wave")); + + INITRAZERDRIVER init_razer_kraken_driver = reinterpret_cast(GetProcAddress(module, "init_razer_kraken_driver")); + static struct device_attribute devkraken_attr_device_type = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devkraken_attr_device_type")); + static struct device_attribute devkraken_attr_device_serial = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devkraken_attr_device_serial")); + static struct device_attribute devkraken_attr_firmware_version = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devkraken_attr_firmware_version")); + static struct device_attribute devkraken_attr_matrix_effect_custom = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devkraken_attr_matrix_effect_custom")); + //static struct device_attribute devkraken_attr_matrix_custom_frame = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devkraken_attr_matrix_custom_frame")); + //static struct device_attribute devkraken_attr_matrix_brightness = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devkraken_attr_matrix_brightness")); + static struct device_attribute devkraken_attr_matrix_effect_none = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devkraken_attr_matrix_effect_none")); + static struct device_attribute devkraken_attr_matrix_effect_static = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devkraken_attr_matrix_effect_static")); + static struct device_attribute devkraken_attr_matrix_effect_breath = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devkraken_attr_matrix_effect_breath")); + static struct device_attribute devkraken_attr_matrix_effect_spectrum = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devkraken_attr_matrix_effect_spectrum")); + + INITRAZERDRIVER init_razer_core_driver = reinterpret_cast(GetProcAddress(module, "init_razer_core_driver")); + static struct device_attribute devcore_attr_device_type = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devcore_attr_device_type")); + static struct device_attribute devcore_attr_device_serial = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devcore_attr_device_serial")); + static struct device_attribute devcore_attr_firmware_version = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devcore_attr_firmware_version")); + static struct device_attribute devcore_attr_matrix_effect_custom = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devcore_attr_matrix_effect_custom")); + static struct device_attribute devcore_attr_matrix_custom_frame = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devcore_attr_matrix_custom_frame")); + static struct device_attribute devcore_attr_matrix_brightness = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devcore_attr_matrix_brightness")); + static struct device_attribute devcore_attr_matrix_effect_none = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devcore_attr_matrix_effect_none")); + static struct device_attribute devcore_attr_matrix_effect_static = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devcore_attr_matrix_effect_static")); + static struct device_attribute devcore_attr_matrix_effect_breath = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devcore_attr_matrix_effect_breath")); + static struct device_attribute devcore_attr_matrix_effect_spectrum = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devcore_attr_matrix_effect_spectrum")); + static struct device_attribute devcore_attr_matrix_effect_reactive = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devcore_attr_matrix_effect_reactive")); + static struct device_attribute devcore_attr_matrix_effect_wave = *(struct device_attribute*)reinterpret_cast(GetProcAddress(module, "devcore_attr_matrix_effect_wave")); + + struct hid_device* hdev; + unsigned int num; + + hdev = NULL; + num = init_razer_kbd_driver(&hdev); + for (unsigned int i = 0; i < num; i++) + { + device_fn_type* device_fn = new device_fn_type; + device_fn->device_type = &devkbd_attr_device_type; + device_fn->device_serial = &devkbd_attr_device_serial; + device_fn->firmware_version = &devkbd_attr_firmware_version; + device_fn->matrix_effect_custom = &devkbd_attr_matrix_effect_custom; + device_fn->matrix_custom_frame = &devkbd_attr_matrix_custom_frame; + device_fn->matrix_brightness = &devkbd_attr_matrix_brightness; + device_fn->matrix_effect_none = &devkbd_attr_matrix_effect_none; + device_fn->matrix_effect_static = &devkbd_attr_matrix_effect_static; + device_fn->matrix_effect_breath = &devkbd_attr_matrix_effect_breath; + device_fn->matrix_effect_spectrum = &devkbd_attr_matrix_effect_spectrum; + device_fn->matrix_effect_reactive = &devkbd_attr_matrix_effect_reactive; + device_fn->matrix_effect_wave = &devkbd_attr_matrix_effect_wave; + + RGBController_OpenRazer * razer_rgb = new RGBController_OpenRazer(&hdev[i].dev, device_fn); + + if(razer_rgb->device_index != -1) + { + rgb_controllers.push_back(razer_rgb); + } + else + { + delete razer_rgb; + } + } + + hdev = NULL; + num = init_razer_mouse_driver(&hdev); + for (unsigned int i = 0; i < num; i++) + { + device_fn_type* device_fn = new device_fn_type; + device_fn->device_type = &devmouse_attr_device_type; + device_fn->device_serial = &devmouse_attr_device_serial; + device_fn->firmware_version = &devmouse_attr_firmware_version; + device_fn->matrix_effect_custom = &devmouse_attr_matrix_effect_custom; + device_fn->matrix_custom_frame = &devmouse_attr_matrix_custom_frame; + device_fn->matrix_brightness = &devmouse_attr_matrix_brightness; + device_fn->matrix_effect_none = &devmouse_attr_matrix_effect_none; + device_fn->matrix_effect_static = &devmouse_attr_matrix_effect_static; + device_fn->matrix_effect_breath = &devmouse_attr_matrix_effect_breath; + device_fn->matrix_effect_spectrum = &devmouse_attr_matrix_effect_spectrum; + device_fn->matrix_effect_reactive = &devmouse_attr_matrix_effect_reactive; + device_fn->matrix_effect_wave = &devmouse_attr_matrix_effect_wave; + + RGBController_OpenRazer * razer_rgb = new RGBController_OpenRazer(&hdev[i].dev, device_fn); + + if(razer_rgb->device_index != -1) + { + rgb_controllers.push_back(razer_rgb); + } + else + { + delete razer_rgb; + } + } + + hdev = NULL; + num = init_razer_mousemat_driver(&hdev); + for (unsigned int i = 0; i < num; i++) + { + device_fn_type* device_fn = new device_fn_type; + device_fn->device_type = &devmousemat_attr_device_type; + device_fn->device_serial = &devmousemat_attr_device_serial; + device_fn->firmware_version = &devmousemat_attr_firmware_version; + device_fn->matrix_effect_custom = &devmousemat_attr_matrix_effect_custom; + device_fn->matrix_custom_frame = &devmousemat_attr_matrix_custom_frame; + device_fn->matrix_brightness = &devmousemat_attr_matrix_brightness; + device_fn->matrix_effect_none = &devmousemat_attr_matrix_effect_none; + device_fn->matrix_effect_static = &devmousemat_attr_matrix_effect_static; + device_fn->matrix_effect_breath = &devmousemat_attr_matrix_effect_breath; + device_fn->matrix_effect_spectrum = &devmousemat_attr_matrix_effect_spectrum; + device_fn->matrix_effect_reactive = &devmousemat_attr_matrix_effect_reactive; + device_fn->matrix_effect_wave = &devmousemat_attr_matrix_effect_wave; + + RGBController_OpenRazer * razer_rgb = new RGBController_OpenRazer(&hdev[i].dev, device_fn); + + if(razer_rgb->device_index != -1) + { + rgb_controllers.push_back(razer_rgb); + } + else + { + delete razer_rgb; + } + } + + hdev = NULL; + num = init_razer_accessory_driver(&hdev); + for (unsigned int i = 0; i < num; i++) + { + device_fn_type* device_fn = new device_fn_type; + device_fn->device_type = &devaccessory_attr_device_type; + device_fn->device_serial = &devaccessory_attr_device_serial; + device_fn->firmware_version = &devaccessory_attr_firmware_version; + device_fn->matrix_effect_custom = &devaccessory_attr_matrix_effect_custom; + device_fn->matrix_custom_frame = &devaccessory_attr_matrix_custom_frame; + device_fn->matrix_brightness = &devaccessory_attr_matrix_brightness; + device_fn->matrix_effect_none = &devaccessory_attr_matrix_effect_none; + device_fn->matrix_effect_static = &devaccessory_attr_matrix_effect_static; + device_fn->matrix_effect_breath = &devaccessory_attr_matrix_effect_breath; + device_fn->matrix_effect_spectrum = &devaccessory_attr_matrix_effect_spectrum; + device_fn->matrix_effect_reactive = NULL;//&devaccessory_attr_matrix_effect_reactive; + device_fn->matrix_effect_wave = &devaccessory_attr_matrix_effect_wave; + + RGBController_OpenRazer * razer_rgb = new RGBController_OpenRazer(&hdev[i].dev, device_fn); + + if(razer_rgb->device_index != -1) + { + rgb_controllers.push_back(razer_rgb); + } + else + { + delete razer_rgb; + } + } + + hdev = NULL; + num = init_razer_kraken_driver(&hdev); + for (unsigned int i = 0; i < num; i++) + { + device_fn_type* device_fn = new device_fn_type; + device_fn->device_type = &devkraken_attr_device_type; + device_fn->device_serial = &devkraken_attr_device_serial; + device_fn->firmware_version = &devkraken_attr_firmware_version; + device_fn->matrix_effect_custom = &devkraken_attr_matrix_effect_custom; + device_fn->matrix_custom_frame = NULL;//&devkraken_attr_matrix_custom_frame; + device_fn->matrix_brightness = NULL;//&devkraken_attr_matrix_brightness; + device_fn->matrix_effect_none = &devkraken_attr_matrix_effect_none; + device_fn->matrix_effect_static = &devkraken_attr_matrix_effect_static; + device_fn->matrix_effect_breath = &devkraken_attr_matrix_effect_breath; + device_fn->matrix_effect_spectrum = &devkraken_attr_matrix_effect_spectrum; + device_fn->matrix_effect_reactive = NULL;//&devkraken_attr_matrix_effect_reactive; + device_fn->matrix_effect_wave = NULL;//&devkraken_attr_matrix_effect_wave; + + RGBController_OpenRazer * razer_rgb = new RGBController_OpenRazer(&hdev[i].dev, device_fn); + + if(razer_rgb->device_index != -1) + { + rgb_controllers.push_back(razer_rgb); + } + else + { + delete razer_rgb; + } + } + + hdev = NULL; + num = init_razer_core_driver(&hdev); + for (unsigned int i = 0; i < num; i++) + { + device_fn_type* device_fn = new device_fn_type; + device_fn->device_type = &devcore_attr_device_type; + device_fn->device_serial = &devcore_attr_device_serial; + device_fn->firmware_version = &devcore_attr_firmware_version; + device_fn->matrix_effect_custom = &devcore_attr_matrix_effect_custom; + device_fn->matrix_custom_frame = &devcore_attr_matrix_custom_frame; + device_fn->matrix_brightness = &devcore_attr_matrix_brightness; + device_fn->matrix_effect_none = &devcore_attr_matrix_effect_none; + device_fn->matrix_effect_static = &devcore_attr_matrix_effect_static; + device_fn->matrix_effect_breath = &devcore_attr_matrix_effect_breath; + device_fn->matrix_effect_spectrum = &devcore_attr_matrix_effect_spectrum; + device_fn->matrix_effect_reactive = &devcore_attr_matrix_effect_reactive; + device_fn->matrix_effect_wave = &devcore_attr_matrix_effect_wave; + + RGBController_OpenRazer * razer_rgb = new RGBController_OpenRazer(&hdev[i].dev, device_fn); + + if(razer_rgb->device_index != -1) + { + rgb_controllers.push_back(razer_rgb); + } + else + { + delete razer_rgb; + } + } + +} /* DetectOpenRazerControllers() */ diff --git a/RGBController/RGBController_OpenRazerWindows.cpp b/RGBController/RGBController_OpenRazerWindows.cpp new file mode 100644 index 00000000..5a5731c9 --- /dev/null +++ b/RGBController/RGBController_OpenRazerWindows.cpp @@ -0,0 +1,419 @@ +/*-----------------------------------------*\ +| RGBController_OpenRazer.cpp | +| | +| Generic RGB Interface for OpenRazer | +| kernel drivers for Chroma peripherals | +| | +| Adam Honse (CalcProgrammer1) 6/15/2019 | +\*-----------------------------------------*/ + +#include "RGBController_OpenRazerWindows.h" +#include +#include +#include +#include +#include +#include + +void RGBController_OpenRazer::UpdateLEDs() +{ + switch(matrix_type) + { + case RAZER_TYPE_MATRIX_FRAME: + case RAZER_TYPE_MATRIX_NOFRAME: + case RAZER_TYPE_MATRIX_STATIC: + { + char update_value = 1; + + for (unsigned int row = 0; row < matrix_rows; row++) + { + unsigned int output_array_size; + unsigned int output_offset; + unsigned int row_offset = (row * matrix_cols); + + if(matrix_type == RAZER_TYPE_MATRIX_FRAME) + { + output_array_size = 3 + (matrix_cols* 3); + output_offset = 3; + } + else + { + output_array_size = 3; + output_offset = 0; + } + + char* output_array = new char[output_array_size]; + + if(matrix_type == RAZER_TYPE_MATRIX_FRAME) + { + output_array[0] = row; + output_array[1] = 0; + output_array[2] = matrix_cols - 1; + } + + for(unsigned int col = 0; col < matrix_cols; col++) + { + unsigned int color_idx = col + row_offset; + output_array[(col * 3) + 0 + output_offset] = (char)RGBGetRValue(colors[color_idx]); + output_array[(col * 3) + 1 + output_offset] = (char)RGBGetGValue(colors[color_idx]); + output_array[(col * 3) + 2 + output_offset] = (char)RGBGetBValue(colors[color_idx]); + } + + if(matrix_type == RAZER_TYPE_MATRIX_FRAME) + { + razer_functions->matrix_custom_frame->store(razer_device, NULL, output_array, output_array_size); + } + else if(matrix_type == RAZER_TYPE_MATRIX_NOFRAME) + { + razer_functions->matrix_effect_custom->store(razer_device, NULL, output_array, output_array_size); + } + else + { + razer_functions->matrix_effect_static->store(razer_device, NULL, output_array, output_array_size); + } + } + + if(matrix_type == RAZER_TYPE_MATRIX_FRAME) + { + razer_functions->matrix_effect_custom->store(razer_device, NULL, &update_value, 1); + } + } + break; + #if 0 + case RAZER_TYPE_NOMATRIX: + { + unsigned int output_array_size = 3; + char output_array[output_array_size]; + char update_value = 0; + + output_array[0] = (char)RGBGetRValue(colors[0]); + output_array[1] = (char)RGBGetGValue(colors[0]); + output_array[2] = (char)RGBGetBValue(colors[0]); + logo_led_rgb.write(output_array, output_array_size); + + output_array[0] = (char)RGBGetRValue(colors[1]); + output_array[1] = (char)RGBGetGValue(colors[1]); + output_array[2] = (char)RGBGetBValue(colors[1]); + scroll_led_rgb.write(output_array, output_array_size); + + logo_led_rgb.flush(); + scroll_led_rgb.flush(); + + logo_led_effect.write(&update_value, 1); + scroll_led_effect.write(&update_value, 1); + logo_led_effect.flush(); + scroll_led_effect.flush(); + } + break; + #endif + } +} + +void RGBController_OpenRazer::UpdateZoneLEDs(int zone) +{ + UpdateLEDs(); +} + +void RGBController_OpenRazer::UpdateSingleLED(int led) +{ + UpdateLEDs(); +} + +void RGBController_OpenRazer::SetupMatrixDevice(device * razer_device, device_fn_type* razer_functions, unsigned int rows, unsigned int cols) +{ + if(razer_functions->matrix_custom_frame == NULL) + { + if(razer_functions->matrix_effect_custom != NULL) + { + matrix_type = RAZER_TYPE_MATRIX_STATIC; + } + else + { + matrix_type = RAZER_TYPE_MATRIX_NOFRAME; + } + + matrix_rows = 1; + matrix_cols = 1; + } + else + { + matrix_type = RAZER_TYPE_MATRIX_FRAME; + + matrix_rows = rows; + matrix_cols = cols; + } +} + +void RGBController_OpenRazer::SetupNonMatrixDevice(device * razer_device, device_fn_type* razer_functions) +{ + matrix_type = RAZER_TYPE_NOMATRIX; +} + +RGBController_OpenRazer::RGBController_OpenRazer(device * razer_device, device_fn_type* razer_functions) +{ + char string_buf[1024]; + + this->razer_device = razer_device; + this->razer_functions = razer_functions; + + unsigned int led_count = 0; + + /*-----------------------------------------------------------------*\ + | Initialize buffer | + \*-----------------------------------------------------------------*/ + memset(string_buf, 0xFF, sizeof(string_buf)); + string_buf[1023] = '\0'; + + /*-----------------------------------------------------------------*\ + | Start device at -1. This indicates the device was not detected | + \*-----------------------------------------------------------------*/ + device_index = -1; + + /*-----------------------------------------------------------------*\ + | Get the device name from the OpenRazer driver | + \*-----------------------------------------------------------------*/ + razer_functions->device_type->show(razer_device, NULL, string_buf); + name = string_buf; + name.erase(std::remove(name.begin(), name.end(), '\n'), name.end()); + name.erase(std::remove(name.begin(), name.end(), '\r'), name.end()); + + /*-----------------------------------------------------------------*\ + | Set the description to indicate this is an OpenRazer device | + \*-----------------------------------------------------------------*/ + description = "OpenRazer Device"; + + /*-----------------------------------------------------------------*\ + | Set the device path as the location | + \*-----------------------------------------------------------------*/ + location = ""; + + /*-----------------------------------------------------------------*\ + | Initialize buffer | + \*-----------------------------------------------------------------*/ + //memset(string_buf, 0xFF, sizeof(string_buf)); + //string_buf[1023] = '\0'; + + /*-----------------------------------------------------------------*\ + | Get the serial number from the dev path | + \*-----------------------------------------------------------------*/ + //razer_functions->device_serial->show(razer_device, NULL, string_buf); + //serial = string_buf; + + /*-----------------------------------------------------------------*\ + | Initialize buffer | + \*-----------------------------------------------------------------*/ + //memset(string_buf, 0xFF, sizeof(string_buf)); + //string_buf[1023] = '\0'; + + /*-----------------------------------------------------------------*\ + | Get the firmware version from the dev path | + \*-----------------------------------------------------------------*/ + //razer_functions->firmware_version->show(razer_device, NULL, string_buf); + //version = string_buf; + + /*-----------------------------------------------------------------*\ + | Loop through all known devices to look for a name match | + \*-----------------------------------------------------------------*/ + for (unsigned int i = 0; i < RAZER_NUM_DEVICES; i++) + { + if (device_list[i]->name == name) + { + /*---------------------------------------------------------*\ + | Set device ID | + \*---------------------------------------------------------*/ + device_index = i; + + /*---------------------------------------------------------*\ + | Set device type | + \*---------------------------------------------------------*/ + type = device_list[i]->type; + + /*---------------------------------------------------------*\ + | Initialize modes | + \*---------------------------------------------------------*/ + if(razer_functions->matrix_effect_custom != NULL) + { + mode Custom; + Custom.name = "Custom"; + Custom.value = RAZER_MODE_CUSTOM; + Custom.flags = MODE_FLAG_HAS_COLOR | MODE_FLAG_PER_LED_COLOR; + modes.push_back(Custom); + } + + if(razer_functions->matrix_effect_none) + { + mode Off; + Off.name = "Off"; + Off.value = RAZER_MODE_OFF; + Off.flags = 0; + modes.push_back(Off); + } + + if(razer_functions->matrix_effect_static) + { + mode Static; + Static.name = "Static"; + Static.value = RAZER_MODE_STATIC; + Static.flags = MODE_FLAG_HAS_COLOR; + modes.push_back(Static); + } + + if(razer_functions->matrix_effect_breath) + { + mode Breathing; + Breathing.name = "Breathing"; + Breathing.value = RAZER_MODE_BREATHING; + Breathing.flags = MODE_FLAG_HAS_COLOR | MODE_FLAG_RANDOM_COLOR; + Breathing.random = false; + modes.push_back(Breathing); + } + + if(razer_functions->matrix_effect_spectrum) + { + mode SpectrumCycle; + SpectrumCycle.name = "Spectrum Cycle"; + SpectrumCycle.value = RAZER_MODE_SPECTRUM_CYCLE; + SpectrumCycle.flags = 0; + modes.push_back(SpectrumCycle); + } + + if(razer_functions->matrix_effect_wave) + { + mode Wave; + Wave.name = "Wave"; + Wave.value = RAZER_MODE_WAVE; + Wave.flags = 0; + modes.push_back(Wave); + } + + if(razer_functions->matrix_effect_reactive) + { + mode Reactive; + Reactive.name = "Reactive"; + Reactive.value = RAZER_MODE_REACTIVE; + Reactive.flags = 0; + modes.push_back(Reactive); + } + + /*---------------------------------------------------------*\ + | Initialize file descriptors | + \*---------------------------------------------------------*/ + if(device_list[i]->matrix_type == true) + { + SetupMatrixDevice(razer_device, razer_functions, device_list[i]->rows, device_list[i]->cols); + } + else + { + SetupNonMatrixDevice(razer_device, razer_functions); + } + + /*---------------------------------------------------------*\ + | Fill in zone information based on device table | + \*---------------------------------------------------------*/ + for (int zone_id = 0; zone_id < RAZER_MAX_ZONES; zone_id++) + { + if (device_list[i]->zones[zone_id] != NULL) + { + zone new_zone; + new_zone.name = device_list[i]->zones[zone_id]->name; + new_zone.type = device_list[i]->zones[zone_id]->type; + + for (unsigned int row_id = 0; row_id < device_list[i]->zones[zone_id]->rows; row_id++) + { + std::vector new_zone_map; + + for (unsigned int col_id = 0; col_id < device_list[i]->zones[zone_id]->cols; col_id++) + { + RGBColor new_color = 0x00000000; + colors.push_back(new_color); + + led* new_led = new led(); + new_led->name = device_list[i]->zones[zone_id]->name; + leds.push_back(*new_led); + + new_zone_map.push_back(led_count); + + led_count++; + } + + new_zone.map.push_back(new_zone_map); + } + zones.push_back(new_zone); + } + } + } + } + +} + +void RGBController_OpenRazer::SetCustomMode() +{ + SetMode(RAZER_MODE_CUSTOM); +} + +void RGBController_OpenRazer::UpdateMode() +{ + char update_value = 1; + + switch(matrix_type) + { + case RAZER_TYPE_MATRIX_FRAME: + case RAZER_TYPE_MATRIX_NOFRAME: + { + switch(modes[active_mode].value) + { + case RAZER_MODE_CUSTOM: + razer_functions->matrix_effect_custom->store(razer_device, NULL, &update_value, 1); + break; + + case RAZER_MODE_OFF: + razer_functions->matrix_effect_none->store(razer_device, NULL, &update_value, 1); + break; + + case RAZER_MODE_STATIC: + razer_functions->matrix_effect_static->store(razer_device, NULL, &update_value, 1); + break; + + case RAZER_MODE_BREATHING: + razer_functions->matrix_effect_breath->store(razer_device, NULL, &update_value, 1); + break; + + case RAZER_MODE_SPECTRUM_CYCLE: + razer_functions->matrix_effect_spectrum->store(razer_device, NULL, &update_value, 1); + break; + + case RAZER_MODE_WAVE: + razer_functions->matrix_effect_wave->store(razer_device, NULL, &update_value, 1); + break; + + case RAZER_MODE_REACTIVE: + razer_functions->matrix_effect_reactive->store(razer_device, NULL, &update_value, 1); + break; + } + } + break; +#if 0 + case RAZER_TYPE_NOMATRIX: + { + switch(modes[active_mode].value) + { + case RAZER_MODE_CUSTOM: + update_value = 0; + logo_led_effect.write(&update_value, 1); + scroll_led_effect.write(&update_value, 1); + logo_led_effect.flush(); + scroll_led_effect.flush(); + break; + + case RAZER_MODE_SPECTRUM_CYCLE: + update_value = '4'; + logo_led_effect.write(&update_value, 1); + scroll_led_effect.write(&update_value, 1); + logo_led_effect.flush(); + scroll_led_effect.flush(); + break; + } + } +#endif + } +} diff --git a/RGBController/RGBController_OpenRazerWindows.h b/RGBController/RGBController_OpenRazerWindows.h new file mode 100644 index 00000000..1721f8bb --- /dev/null +++ b/RGBController/RGBController_OpenRazerWindows.h @@ -0,0 +1,1204 @@ +/*-----------------------------------------*\ +| RGBController_OpenRazerWindows.h | +| | +| Generic RGB Interface for OpenRazer | +| kernel drivers for Chroma peripherals | +| | +| Adam Honse (CalcProgrammer1) 6/15/2019 | +\*-----------------------------------------*/ + +#include "RGBController.h" +#include + +#include +#include +#include + +typedef struct +{ + struct device_attribute * device_type; + struct device_attribute * device_serial; + struct device_attribute * firmware_version; + struct device_attribute * matrix_effect_custom; + struct device_attribute * matrix_custom_frame; + struct device_attribute * matrix_brightness; + struct device_attribute * matrix_effect_none; + struct device_attribute * matrix_effect_static; + struct device_attribute * matrix_effect_breath; + struct device_attribute * matrix_effect_spectrum; + struct device_attribute * matrix_effect_reactive; + struct device_attribute * matrix_effect_wave; +} device_fn_type; + +#define RAZER_MAX_ZONES 6 + +typedef struct +{ + std::string name; + unsigned int type; + unsigned int rows; + unsigned int cols; +} razer_zone; + +typedef struct +{ + std::string name; + device_type type; + bool matrix_type; + unsigned int rows; + unsigned int cols; + const razer_zone* zones[RAZER_MAX_ZONES]; +} razer_device; + +/*-------------------------------------------------------------------------*\ +| KEYBOARDS | +\*-------------------------------------------------------------------------*/ + +/*-------------------------------------------------------------*\ +| Razer BlackWidow Chroma | +| | +| Zone "Keyboard" | +| Matrix | +| 6 Rows, 22 Columns | +\*-------------------------------------------------------------*/ +static const razer_zone blackwidow_chroma_zone = +{ + "Keyboard", + ZONE_TYPE_MATRIX, + 6, + 22 +}; + +static const razer_device blackwidow_chroma_device = +{ + "Razer BlackWidow Chroma", + DEVICE_TYPE_KEYBOARD, + true, + 6, + 22, + { + &blackwidow_chroma_zone, + NULL, + NULL, + NULL, + NULL, + NULL + } +}; + +/*-------------------------------------------------------------*\ +| Razer BlackWidow Chroma Tournament Edition | +| | +| Zone "Keyboard" | +| Matrix | +| 6 Rows, 22 Columns | +\*-------------------------------------------------------------*/ +static const razer_zone blackwidow_chroma_te_zone = +{ + "Keyboard", + ZONE_TYPE_MATRIX, + 6, + 22 +}; + +static const razer_device blackwidow_chroma_te_device = +{ + "Razer BlackWidow Chroma Tournament Edition", + DEVICE_TYPE_KEYBOARD, + true, + 6, + 22, + { + &blackwidow_chroma_te_zone, + NULL, + NULL, + NULL, + NULL, + NULL + } +}; + +/*-------------------------------------------------------------*\ +| Razer Ornata Chroma | +| | +| Zone "Keyboard" | +| Matrix | +| 6 Rows, 22 Columns | +\*-------------------------------------------------------------*/ +static const razer_zone ornata_chroma_zone = +{ + "Keyboard", + ZONE_TYPE_MATRIX, + 6, + 22 +}; + +static const razer_device ornata_chroma_device = +{ + "Razer Ornata Chroma", + DEVICE_TYPE_KEYBOARD, + true, + 6, + 22, + { + &ornata_chroma_zone, + NULL, + NULL, + NULL, + NULL, + NULL + } +}; + +/*-------------------------------------------------------------*\ +| Razer DeathStalker Chroma | +| | +| Zone "Keyboard" | +| Linear | +| 12 LEDs | +\*-------------------------------------------------------------*/ +static const razer_zone deathstalker_chroma_zone = +{ + "Keyboard", + ZONE_TYPE_LINEAR, + 1, + 12 +}; + +static const razer_device deathstalker_chroma_device = +{ + "Razer DeathStalker Chroma", + DEVICE_TYPE_KEYBOARD, + true, + 1, + 12, + { + &deathstalker_chroma_zone, + NULL, + NULL, + NULL, + NULL, + NULL + } +}; + +/*-------------------------------------------------------------*\ +| Razer Huntsman Elite | +| | +| Zone "Keyboard" | +| Matrix | +| 6 Rows, 22 Columns | +\*-------------------------------------------------------------*/ +static const razer_zone huntsman_elite_zone = +{ + "Keyboard", + ZONE_TYPE_MATRIX, + 6, + 22 +}; + +static const razer_device huntsman_elite_device = +{ + "Razer Huntsman Elite", + DEVICE_TYPE_KEYBOARD, + true, + 6, + 22, + { + &huntsman_elite_zone, + NULL, + NULL, + NULL, + NULL, + NULL + } +}; + +/*-------------------------------------------------------------------------*\ +| LAPTOPS | +\*-------------------------------------------------------------------------*/ + +/*-------------------------------------------------------------*\ +| Razer Blade Stealth | +| | +| Zone "Keyboard" | +| Matrix | +| 6 Rows, 16 Columns | +\*-------------------------------------------------------------*/ +static const razer_zone blade_stealth_zone = +{ + "Keyboard", + ZONE_TYPE_MATRIX, + 6, + 16 +}; + +static const razer_device blade_stealth_device = +{ + "Razer Blade Stealth", + DEVICE_TYPE_KEYBOARD, + true, + 6, + 16, + { + &blade_stealth_zone, + NULL, + NULL, + NULL, + NULL, + NULL + } +}; + +/*-------------------------------------------------------------*\ +| Razer Blade Pro (Late 2016) | +| | +| Zone "Keyboard" | +| Matrix | +| 6 Rows, 25 Columns | +\*-------------------------------------------------------------*/ +static const razer_zone blade_pro_late_2016_zone = +{ + "Keyboard", + ZONE_TYPE_MATRIX, + 6, + 25 +}; + +static const razer_device blade_pro_late_2016_device = +{ + "Razer Blade Pro (Late 2016)", + DEVICE_TYPE_KEYBOARD, + true, + 6, + 25, + { + &blade_pro_late_2016_zone, + NULL, + NULL, + NULL, + NULL, + NULL + } +}; + +/*-------------------------------------------------------------*\ +| Razer Blade Pro (2017) | +| | +| Zone "Keyboard" | +| Matrix | +| 6 Rows, 25 Columns | +\*-------------------------------------------------------------*/ +static const razer_zone blade_pro_2017_zone = +{ + "Keyboard", + ZONE_TYPE_MATRIX, + 6, + 25 +}; + +static const razer_device blade_pro_2017_device = +{ + "Razer Blade Pro (2017)", + DEVICE_TYPE_KEYBOARD, + true, + 6, + 25, + { + &blade_pro_2017_zone, + NULL, + NULL, + NULL, + NULL, + NULL + } +}; + +/*-------------------------------------------------------------------------*\ +| MICE | +\*-------------------------------------------------------------------------*/ + +/*-------------------------------------------------------------*\ +| Razer Mamba Tournament Edition | +| | +| Zone "Left" | +| Linear | +| 7 LEDs | +| | +| Zone "Right" | +| Linear | +| 7 LEDs | +| | +| Zone "Logo" | +| Single | +| 1 LED | +| | +| Zone "Scroll Wheel" | +| Single | +| 1 LED | +\*-------------------------------------------------------------*/ +static const razer_zone mamba_te_left_zone = +{ + "Left LED Strip", + ZONE_TYPE_LINEAR, + 1, + 7 +}; + +static const razer_zone mamba_te_right_zone = +{ + "Right LED Strip", + ZONE_TYPE_LINEAR, + 1, + 7 +}; + +static const razer_zone mamba_te_logo_zone = +{ + "Logo", + ZONE_TYPE_SINGLE, + 1, + 1 +}; + +static const razer_zone mamba_te_scroll_wheel_zone = +{ + "Scroll Wheel", + ZONE_TYPE_SINGLE, + 1, + 1 +}; + +static const razer_device mamba_te_device = +{ + "Razer Mamba Tournament Edition", + DEVICE_TYPE_MOUSE, + true, + 1, + 16, + { + &mamba_te_left_zone, + &mamba_te_right_zone, + &mamba_te_logo_zone, + &mamba_te_scroll_wheel_zone, + NULL, + NULL + } +}; + +/*-------------------------------------------------------------*\ +| Razer Mamba Elite | +| | +| Zone "Scroll Wheel" | +| Single | +| 1 LED | +| | +| Zone "Logo" | +| Single | +| 1 LED | +| | +| Zone "Left" | +| Linear | +| 9 LEDs | +| | +| Zone "Right" | +| Linear | +| 9 LEDs | +| | +\*-------------------------------------------------------------*/ +static const razer_zone mamba_elite_scroll_wheel_zone = +{ + "Scroll Wheel", + ZONE_TYPE_SINGLE, + 1, + 1 +}; + +static const razer_zone mamba_elite_logo_zone = +{ + "Logo", + ZONE_TYPE_SINGLE, + 1, + 1 +}; + +static const razer_zone mamba_elite_left_zone = +{ + "Left LED Strip", + ZONE_TYPE_LINEAR, + 1, + 9 +}; + +static const razer_zone mamba_elite_right_zone = +{ + "Right LED Strip", + ZONE_TYPE_LINEAR, + 1, + 9 +}; + +static const razer_device mamba_elite_device = +{ + "Razer Mamba Elite", + DEVICE_TYPE_MOUSE, + true, + 1, + 20, + { + &mamba_elite_scroll_wheel_zone, + &mamba_elite_logo_zone, + &mamba_elite_left_zone, + &mamba_elite_right_zone, + NULL, + NULL + } +}; + +/*-------------------------------------------------------------*\ +| Razer Diamondback Chroma | +| | +| Zone "Right" | +| Linear | +| 7 LEDs | +| | +| Zone "Bottom" | +| Linear | +| 5 LEDs | +| | +| Zone "Left" | +| Linear | +| 7 LEDs | +| | +| Zone "Logo" | +| Single | +| 1 LED | +| | +| Zone "Scroll Wheel" | +| Single | +| 1 LED | +\*-------------------------------------------------------------*/ +static const razer_zone diamondback_chroma_right_zone = +{ + "Right LED Strip", + ZONE_TYPE_LINEAR, + 1, + 7 +}; + +static const razer_zone diamondback_chroma_bottom_zone = +{ + "Bottom LED Strip", + ZONE_TYPE_LINEAR, + 1, + 5 +}; + +static const razer_zone diamondback_chroma_left_zone = +{ + "Left LED Strip", + ZONE_TYPE_LINEAR, + 1, + 7 +}; + +static const razer_zone diamondback_chroma_logo_zone = +{ + "Logo", + ZONE_TYPE_SINGLE, + 1, + 1 +}; + +static const razer_zone diamondback_chroma_scroll_wheel_zone = +{ + "Scroll Wheel", + ZONE_TYPE_SINGLE, + 1, + 1 +}; + +static const razer_device diamondback_chroma_device = +{ + "Razer Diamondback Chroma", + DEVICE_TYPE_MOUSE, + true, + 1, + 21, + { + &diamondback_chroma_right_zone, + &diamondback_chroma_bottom_zone, + &diamondback_chroma_left_zone, + &diamondback_chroma_logo_zone, + &diamondback_chroma_scroll_wheel_zone, + NULL + } +}; + +/*-------------------------------------------------------------*\ +| Razer DeathAdder Chroma | +| | +| Zone "Logo" | +| Single | +| 1 LED | +| | +| Zone "Scroll Wheel" | +| Single | +| 1 LED | +\*-------------------------------------------------------------*/ +static const razer_zone deathadder_chroma_logo_zone = +{ + "Logo", + ZONE_TYPE_SINGLE, + 1, + 1 +}; + +static const razer_zone deathadder_chroma_scroll_wheel_zone = +{ + "Scroll Wheel", + ZONE_TYPE_SINGLE, + 1, + 1 +}; + +static const razer_device deathadder_chroma_device = +{ + "Razer DeathAdder Chroma", + DEVICE_TYPE_MOUSE, + false, + 1, + 2, + { + &deathadder_chroma_logo_zone, + &deathadder_chroma_scroll_wheel_zone, + NULL, + NULL, + NULL, + NULL + } +}; + +/*-------------------------------------------------------------*\ +| Razer Naga Chroma | +| | +| Zone "Logo" | +| Single | +| 1 LED | +| | +| Zone "Scroll Wheel" | +| Single | +| 1 LED | +| | +| Zone "Numpad" | +| Single | +| 1 LED | +\*-------------------------------------------------------------*/ +static const razer_zone naga_chroma_logo_zone = +{ + "Logo", + ZONE_TYPE_SINGLE, + 1, + 1 +}; + +static const razer_zone naga_chroma_scroll_wheel_zone = +{ + "Scroll Wheel", + ZONE_TYPE_SINGLE, + 1, + 1 +}; + +static const razer_zone naga_chroma_numpad_zone = +{ + "Numpad", + ZONE_TYPE_SINGLE, + 1, + 1 +}; + +static const razer_device naga_chroma_device = +{ + "Razer Naga Chroma", + DEVICE_TYPE_MOUSE, + false, + 1, + 3, + { + &naga_chroma_logo_zone, + &naga_chroma_scroll_wheel_zone, + &naga_chroma_numpad_zone, + NULL, + NULL, + NULL + } +}; + +/*-------------------------------------------------------------------------*\ +| KEYPADS | +\*-------------------------------------------------------------------------*/ + +/*-------------------------------------------------------------*\ +| Razer Orbweaver Chroma | +| | +| Zone "Keypad" | +| Matrix | +| 4 Rows, 5 Columns | +\*-------------------------------------------------------------*/ +static const razer_zone orbweaver_chroma_zone = +{ + "Keypad", + ZONE_TYPE_MATRIX, + 4, + 5 +}; + +static const razer_device orbweaver_chroma_device = +{ + "Razer Orbweaver Chroma", + DEVICE_TYPE_KEYBOARD, + true, + 6, + 25, + { + &orbweaver_chroma_zone, + NULL, + NULL, + NULL, + NULL, + NULL + } +}; + +/*-------------------------------------------------------------*\ +| Razer Tartarus Chroma | +| | +| Zone "Keypad" | +| Single | +| 1 LED | +\*-------------------------------------------------------------*/ +static const razer_zone tartarus_chroma_zone = +{ + "Keypad", + ZONE_TYPE_SINGLE, + 1, + 1 +}; + +static const razer_device tartarus_chroma_device = +{ + "Razer Tartarus Chroma", + DEVICE_TYPE_KEYBOARD, + true, + 1, + 1, + { + &tartarus_chroma_zone, + NULL, + NULL, + NULL, + NULL, + NULL + } +}; + +/*-------------------------------------------------------------------------*\ +| MOUSEMATS | +\*-------------------------------------------------------------------------*/ + +/*-------------------------------------------------------------*\ +| Razer Firefly | +| | +| Zone "LED Strip" | +| Linear | +| 15 LEDs | +\*-------------------------------------------------------------*/ +static const razer_zone firefly_zone = +{ + "LED Strip", + ZONE_TYPE_LINEAR, + 1, + 15 +}; + +static const razer_device firefly_device = +{ + "Razer Firefly", + DEVICE_TYPE_MOUSEMAT, + true, + 1, + 15, + { + &firefly_zone, + NULL, + NULL, + NULL, + NULL, + NULL + } +}; + +/*-------------------------------------------------------------*\ +| Razer Goliathus Extended | +| | +| Zone "LED Strip" | +| Single | +| 1 LED | +\*-------------------------------------------------------------*/ +static const razer_zone goliathus_extended_zone = +{ + "LED Strip", + ZONE_TYPE_SINGLE, + 1, + 1 +}; + +static const razer_device goliathus_extended_device = +{ + "Razer Goliathus Extended", + DEVICE_TYPE_MOUSEMAT, + true, + 1, + 1, + { + &goliathus_extended_zone, + NULL, + NULL, + NULL, + NULL, + NULL + } +}; + +/*-------------------------------------------------------------------------*\ +| HEADSETS | +\*-------------------------------------------------------------------------*/ + +/*-------------------------------------------------------------*\ +| Razer Kraken 7.1 Chroma | +| | +| Zone "Headset" | +| Single | +| 1 LED | +\*-------------------------------------------------------------*/ +static const razer_zone kraken_chroma_zone = +{ + "Headset", + ZONE_TYPE_SINGLE, + 1, + 1 +}; + +static const razer_device kraken_chroma_device = +{ + "Razer Kraken 7.1 Chroma", + DEVICE_TYPE_HEADSET, + true, + 1, + 1, + { + &kraken_chroma_zone, + NULL, + NULL, + NULL, + NULL, + NULL + } +}; + +/*-------------------------------------------------------------*\ +| Razer Kraken 7.1 V2 | +| | +| Zone "Headset" | +| Single | +| 1 LED | +\*-------------------------------------------------------------*/ +static const razer_zone kraken_v2_zone = +{ + "Headset", + ZONE_TYPE_SINGLE, + 1, + 1 +}; + +static const razer_device kraken_v2_device = +{ + "Razer Kraken 7.1 V2", + DEVICE_TYPE_HEADSET, + true, + 1, + 1, + { + &kraken_v2_zone, + NULL, + NULL, + NULL, + NULL, + NULL + } +}; + +/*-------------------------------------------------------------------------*\ +| OTHER | +\*-------------------------------------------------------------------------*/ + +/*-------------------------------------------------------------*\ +| Razer Core | +| | +| Zone "Side Window Lights" | +| Single | +| 1 LED | +| | +| Zone "LED Strip" | +| Linear | +| 8 LEDs | +\*-------------------------------------------------------------*/ +static const razer_zone core_side_zone = +{ + "Side Window Lights", + ZONE_TYPE_SINGLE, + 1, + 1 +}; + +static const razer_zone core_led_strip_zone = +{ + "LED Strip", + ZONE_TYPE_LINEAR, + 1, + 8 +}; + +static const razer_device core_device = +{ + "Razer Core", + DEVICE_TYPE_UNKNOWN, + true, + 1, + 9, + { + &core_side_zone, + &core_led_strip_zone, + NULL, + NULL, + NULL, + NULL + } +}; + +/*-------------------------------------------------------------*\ +| Razer Chroma Mug Holder | +| | +| Zone "LED Strip" | +| Linear | +| 15 LEDs | +\*-------------------------------------------------------------*/ +static const razer_zone mug_holder_zone = +{ + "LED Strip", + ZONE_TYPE_LINEAR, + 1, + 15 +}; + +static const razer_device mug_holder_device = +{ + "Razer Chroma Mug Holder", + DEVICE_TYPE_UNKNOWN, + true, + 1, + 15, + { + &mug_holder_zone, + NULL, + NULL, + NULL, + NULL, + NULL + } +}; + +/*-------------------------------------------------------------*\ +| Razer Chroma HDK | +| | +| Zone "LED Strip" | +| Linear | +| 16 LEDs | +| | +| Zone "LED Strip" | +| Linear | +| 16 LEDs | +| | +| Zone "LED Strip" | +| Linear | +| 16 LEDs | +| | +| Zone "LED Strip" | +| Linear | +| 16 LEDs | +\*-------------------------------------------------------------*/ +static const razer_zone chromahdk_zone = +{ + "LED Strip", + ZONE_TYPE_LINEAR, + 1, + 16 +}; + +static const razer_device chromahdk_device = +{ + "Razer Chroma HDK", + DEVICE_TYPE_LEDSTRIP, + true, + 4, + 16, + { + &chromahdk_zone, + &chromahdk_zone, + &chromahdk_zone, + &chromahdk_zone, + NULL, + NULL + } +}; + +/*-------------------------------------------------------------*\ +| Razer Base Station Chroma | +| | +| Zone "LED Strip" | +| Linear | +| 15 LEDs | +\*-------------------------------------------------------------*/ +static const razer_zone base_station_zone = +{ + "LED Strip", + ZONE_TYPE_LINEAR, + 1, + 15 +}; + +static const razer_device base_station_device = +{ + "Razer Base Station Chroma", + DEVICE_TYPE_UNKNOWN, + true, + 1, + 15, + { + &base_station_zone, + NULL, + NULL, + NULL, + NULL, + NULL + } +}; + +/*-------------------------------------------------------------*\ +| Razer Nommo Pro | +| | +| Zone "Left Speaker" | +| Linear | +| 8 LEDs | +| | +| Zone "Right Speaker" | +| Linear | +| 8 LEDs | +| | +\*-------------------------------------------------------------*/ +static const razer_zone nommo_pro_left_zone = +{ + "Left Speaker", + ZONE_TYPE_LINEAR, + 1, + 8 +}; + +static const razer_zone nommo_pro_right_zone = +{ + "Right Speaker", + ZONE_TYPE_LINEAR, + 1, + 8 +}; + +static const razer_device nommo_pro_device = +{ + "Razer Nommo Pro", + DEVICE_TYPE_UNKNOWN, + true, + 2, + 8, + { + &nommo_pro_left_zone, + &nommo_pro_right_zone, + NULL, + NULL, + NULL, + NULL + } +}; + +/*-------------------------------------------------------------*\ +| Razer Nommo Chroma | +| | +| Zone "Right Speaker" | +| Linear | +| 8 LEDs | +| | +| Zone "Left Speaker" | +| Linear | +| 8 LEDs | +| | +\*-------------------------------------------------------------*/ +static const razer_zone nommo_chroma_right_zone = +{ + "Right Speaker", + ZONE_TYPE_LINEAR, + 1, + 24 +}; + +static const razer_zone nommo_chroma_left_zone = +{ + "Left Speaker", + ZONE_TYPE_LINEAR, + 1, + 24 +}; + +static const razer_device nommo_chroma_device = +{ + "Razer Nommo Chroma", + DEVICE_TYPE_UNKNOWN, + true, + 2, + 24, + { + &nommo_chroma_right_zone, + &nommo_chroma_left_zone, + NULL, + NULL, + NULL, + NULL + } +}; + +/*-------------------------------------------------------------------------*\ +| DEVICE MASTER LIST | +\*-------------------------------------------------------------------------*/ +#define RAZER_NUM_DEVICES (sizeof(device_list) / sizeof(device_list[ 0 ])) + +static const razer_device* device_list[] = +{ +/*-----------------------------------------------------------------*\ +| KEYBOARDS | +\*-----------------------------------------------------------------*/ + &blackwidow_chroma_device, + &blackwidow_chroma_te_device, + &ornata_chroma_device, + &deathstalker_chroma_device, + &huntsman_elite_device, +/*-----------------------------------------------------------------*\ +| LAPTOPS | +\*-----------------------------------------------------------------*/ + &blade_stealth_device, + &blade_pro_late_2016_device, + &blade_pro_2017_device, +/*-----------------------------------------------------------------*\ +| MICE | +\*-----------------------------------------------------------------*/ + &mamba_te_device, + &mamba_elite_device, + &diamondback_chroma_device, + &deathadder_chroma_device, +/*-----------------------------------------------------------------*\ +| KEYPADS | +\*-----------------------------------------------------------------*/ + &orbweaver_chroma_device, + &tartarus_chroma_device, +/*-----------------------------------------------------------------*\ +| MOUSEMATS | +\*-----------------------------------------------------------------*/ + &firefly_device, + &goliathus_extended_device, +/*-----------------------------------------------------------------*\ +| HEADSETS | +\*-----------------------------------------------------------------*/ + &kraken_chroma_device, + &kraken_v2_device, +/*-----------------------------------------------------------------*\ +| OTHER | +\*-----------------------------------------------------------------*/ + &core_device, + &mug_holder_device, + &chromahdk_device, + &base_station_device, + &nommo_pro_device, + &nommo_chroma_device +}; + + +class RGBController_OpenRazer : public RGBController +{ +public: + enum + { + RAZER_MODE_CUSTOM, + RAZER_MODE_OFF, + RAZER_MODE_STATIC, + RAZER_MODE_BREATHING, + RAZER_MODE_SPECTRUM_CYCLE, + RAZER_MODE_WAVE, + RAZER_MODE_REACTIVE, + RAZER_NUM_MODES + }; + + enum + { + RAZER_TYPE_MATRIX_FRAME, + RAZER_TYPE_MATRIX_NOFRAME, + RAZER_TYPE_MATRIX_STATIC, + RAZER_TYPE_NOMATRIX, + RAZER_NUM_TYPES + }; + +public: + RGBController_OpenRazer(device * razer_device, device_fn_type* razer_functions); + void UpdateLEDs(); + void UpdateZoneLEDs(int zone); + void UpdateSingleLED(int led); + + void SetCustomMode(); + void UpdateMode(); + + int device_index; + +private: + void SetupMatrixDevice(device * razer_device, device_fn_type* razer_functions, unsigned int rows, unsigned int cols); + void SetupNonMatrixDevice(device * razer_device, device_fn_type* razer_functions); + + unsigned int matrix_type; + unsigned int matrix_rows; + unsigned int matrix_cols; + + device* razer_device; + device_fn_type* razer_functions; + + //OpenRazer Sysfs Entries for Matrix Devices + std::ofstream matrix_custom_frame; + std::ofstream matrix_effect_custom; + std::ofstream matrix_effect_breath; + std::ofstream matrix_effect_none; + std::ofstream matrix_effect_reactive; + std::ofstream matrix_effect_spectrum; + std::ofstream matrix_effect_static; + std::ofstream matrix_effect_wave; + + //OpenRazer Sysfs Entries for Non-Matrix Devices + std::ofstream logo_led_effect; + std::ofstream logo_led_rgb; + std::ofstream scroll_led_effect; + std::ofstream scroll_led_rgb; +}; diff --git a/dependencies/openrazer-win32/OpenRazer.dll b/dependencies/openrazer-win32/OpenRazer.dll new file mode 100644 index 00000000..e97cb015 Binary files /dev/null and b/dependencies/openrazer-win32/OpenRazer.dll differ diff --git a/dependencies/openrazer-win32/linux/dmi.h b/dependencies/openrazer-win32/linux/dmi.h new file mode 100644 index 00000000..2c93e03a --- /dev/null +++ b/dependencies/openrazer-win32/linux/dmi.h @@ -0,0 +1,31 @@ +#ifndef DMI_H_ +#define DMI_H_ + +enum dmi_field { + DMI_NONE, + DMI_BIOS_VENDOR, + DMI_BIOS_VERSION, + DMI_BIOS_DATE, + DMI_SYS_VENDOR, + DMI_PRODUCT_NAME, + DMI_PRODUCT_VERSION, + DMI_PRODUCT_SERIAL, + DMI_PRODUCT_UUID, + DMI_BOARD_VENDOR, + DMI_BOARD_NAME, + DMI_BOARD_VERSION, + DMI_BOARD_SERIAL, + DMI_BOARD_ASSET_TAG, + DMI_CHASSIS_VENDOR, + DMI_CHASSIS_TYPE, + DMI_CHASSIS_VERSION, + DMI_CHASSIS_SERIAL, + DMI_CHASSIS_ASSET_TAG, + DMI_STRING_MAX, +}; + +static inline char* dmi_get_system_info(int x) { + return "BLADESERIAL"; +} + +#endif /* DMI_H_ */ diff --git a/dependencies/openrazer-win32/linux/hid.h b/dependencies/openrazer-win32/linux/hid.h new file mode 100644 index 00000000..8ded55ba --- /dev/null +++ b/dependencies/openrazer-win32/linux/hid.h @@ -0,0 +1,300 @@ +#ifndef HID_H_ +#define HID_H_ + +#include +#include +#include + +#pragma comment(lib, "setupapi.lib") +#pragma comment(lib, "Winusb.lib") + +#define HID_STAT_ADDED 1 +#define HID_STAT_PARSED 2 + +#define HID_CONNECT_HIDINPUT 0x01 +#define HID_CONNECT_HIDRAW 0x04 +#define HID_CONNECT_HIDDEV 0x08 +#define HID_CONNECT_FF 0x20 +#define HID_CONNECT_DEFAULT (HID_CONNECT_HIDINPUT|HID_CONNECT_HIDRAW| HID_CONNECT_HIDDEV|HID_CONNECT_FF) + +#define HID_GD_WHEEL 0x00010038 + +#define HID_REQ_GET_REPORT 0x01 +#define HID_REQ_SET_REPORT 0x09 + +#define USB_INTERFACE_PROTOCOL_KEYBOARD 1 +#define USB_INTERFACE_PROTOCOL_MOUSE 2 + +static const GUID GUID_DEVINTERFACE = { 0xDEE824EF, 0x729B, 0x4A0E, 0x9C, 0x14, 0xB7, 0x11, 0x7D, 0x33, 0xA8, 0x17 }; + +typedef enum +{ +HID_TYPE_OTHER, +HID_TYPE_USBMOUSE, +HID_TYPE_USBNONE +} hid_type; + +struct hid_input { + struct input_dev *input; +}; + +struct hid_field { + struct hid_input *hidinput; /* associated input structure */ +}; + +struct hid_usage { + unsigned hid; + __u16 code; /* input driver code */ + __u8 type; /* input driver type */ +}; + +struct hid_driver { + char *name; + const struct hid_device_id *id_table; + int (*probe)(struct hid_device *dev, const struct hid_device_id *id); + void (*remove)(struct hid_device *dev); + int (*raw_event)(struct hid_device *hdev, struct hid_report *report, u8 *data, int size); + int (*event)(struct hid_device *hdev, struct hid_field *field, struct hid_usage *usage, __s32 value); + int (*input_configured)(struct hid_device *hdev, + struct hid_input *hidinput); + int (*input_mapping)(struct hid_device *hdev, + struct hid_input *hidinput, struct hid_field *field, + struct hid_usage *usage, unsigned long **bit, int *max); +}; + +struct hid_device_id { + __u16 bus; + __u32 vendor; + __u32 product; +}; + +struct hid_device { + __u16 product; + enum hid_type type; + struct device dev; + struct hid_ll_driver *ll_driver; + unsigned int status; + struct hid_driver *driver; +}; + +struct hid_ll_driver { + int (*start)(struct hid_device *hdev); + void (*stop)(struct hid_device *hdev); + int (*parse)(struct hid_device *hdev); +}; + +inline int ll_start(struct hid_device *hdev) { + printf("ll_start\n"); + return 0; +} + +inline void ll_stop(struct hid_device *hdev) { + printf("ll_stop\n"); +} + +inline int ll_parse(struct hid_device *hdev) { + printf("ll_parse\n"); + return 0; +} + +inline void dev_err(struct device** dev, const char* msg) { + printf("dev_err device=%s msg=%s", (*dev)->init_name, msg); +} + +inline void dev_info(struct device** dev, const char* msg) { + printf("dev_err device=%s msg=%s", (*dev)->init_name, msg); +} + +inline void *dev_get_drvdata(const struct device *dev) { + return dev->driver_data; +} + +inline void dev_set_drvdata(struct device *dev, void *data) { + dev->driver_data = data; +} + +inline int hid_connect(struct hid_device *hdev, unsigned int connect_mask) { + printf("hid_connect\n"); + return 0; +} + +inline int hid_parse(struct hid_device *hdev) { + int ret; + + if (hdev->status & HID_STAT_PARSED) + return 0; + + ret = hdev->ll_driver->parse(hdev); + if (!ret) + hdev->status |= HID_STAT_PARSED; + + return ret; +} + +inline void *hid_get_drvdata(struct hid_device *hdev) { + return dev_get_drvdata(&hdev->dev); +} + +inline void hid_set_drvdata(struct hid_device *hdev, void *data) { + dev_set_drvdata(&hdev->dev, data); +} + +inline int hid_hw_start(struct hid_device *hdev, unsigned int connect_mask) { + int ret = hdev->ll_driver->start(hdev); + if (ret || !connect_mask) + return ret; + ret = hid_connect(hdev, connect_mask); + if (ret) + hdev->ll_driver->stop(hdev); + return ret; +} + +inline void hid_hw_stop(struct hid_device *hdev) { + hdev->ll_driver->stop(hdev); +} + +inline void hid_err(struct hid_device *hdev, const char* msg, ...) { + va_list args; + va_start(args, msg); + printf("hid_err device=%s", hdev->dev.init_name); + printf(msg, args); + va_end(args); +} + +inline void hid_map_usage(struct hid_input* hidinput, + struct hid_usage* usage, unsigned long** bit, int* max, + __u8 type, __u16 c) +{ + +}; + +#define container_of(ptr, type, member) (type*)((char*)(ptr)-(char*)&((type *)0)->member) + +inline void close(struct device* dev) { + printf("close %04X\n", (to_usb_device(dev))->descriptor.idProduct); + struct usb_interface *intf = to_usb_interface(dev->parent); + struct usb_device *usb_dev = interface_to_usbdev(intf); + struct hid_device *hdev = container_of(dev, struct hid_device, dev); + free(hdev->ll_driver); + free(usb_dev); + free(intf->cur_altsetting); + free(intf); + free(hdev); + //TODO:cleanup malloc memory, move this function into DLL +} + +inline void openChromaDevice(struct hid_device** hdev, unsigned int* numHdev, struct hid_driver hdr) { + + for (unsigned int i = 0; hdr.id_table[i].vendor != 0; i++) { + HDEVINFO hDevInfo = SetupDiGetClassDevs(&GUID_DEVINTERFACE, 0, 0, DIGCF_DEVICEINTERFACE); + if (hDevInfo == INVALID_HANDLE_VALUE) { + printf("SetupDiGetClassDevs failed\n"); + return; + } + + SP_DEVINFO_DATA deviceData = { 0 }; + deviceData.cbSize = sizeof(SP_DEVINFO_DATA); + + for (unsigned int j = 0; SetupDiEnumDeviceInfo(hDevInfo, j, &deviceData); ++j) { + char deviceID[MAX_DEVICE_ID_LEN]; + if (CM_Get_Device_ID(deviceData.DevInst, deviceID, MAX_DEVICE_ID_LEN, 0)) + continue; + + char* vid = strstr(deviceID, "VID_"); + if (!vid || hdr.id_table[i].vendor != strtoul(vid+4, NULL, 16)) + continue; + + char* pid = strstr(deviceID, "PID_"); + if (!pid || hdr.id_table[i].product != strtoul(pid+4, NULL, 16)) + continue; + + SP_INTERFACE_DEVICE_DATA interfaceData = { 0 }; + interfaceData.cbSize = sizeof(SP_INTERFACE_DEVICE_DATA); + if (!SetupDiEnumDeviceInterfaces(hDevInfo, &deviceData, &GUID_DEVINTERFACE, 0, &interfaceData)) + continue; + + DWORD dwRequiredSize = 0; + SetupDiGetDeviceInterfaceDetail(hDevInfo, &interfaceData, 0, 0, &dwRequiredSize, 0); + SP_INTERFACE_DEVICE_DETAIL_DATA* pData = (SP_INTERFACE_DEVICE_DETAIL_DATA*)malloc(dwRequiredSize); + pData->cbSize = sizeof(SP_INTERFACE_DEVICE_DETAIL_DATA); + if (!SetupDiGetDeviceInterfaceDetail(hDevInfo, &interfaceData, pData, dwRequiredSize, 0, 0)) { + free(pData); + continue; + } + + HANDLE hDevice = CreateFile(pData->DevicePath + , GENERIC_READ | GENERIC_WRITE + , FILE_SHARE_READ | FILE_SHARE_WRITE + , 0 + , OPEN_EXISTING + , FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED + , 0); + if (hDevice == INVALID_HANDLE_VALUE) { + free(pData); + continue; + } + + WINUSB_INTERFACE_HANDLE hWinUSBHandle; + if (!WinUsb_Initialize(hDevice, &hWinUSBHandle)) + continue; + + SetupDiDestroyDeviceInfoList(hDevInfo); + + printf("CM_Get_Device_ID (%s)\n", deviceID); + printf("device %04X:%04X opened!\n", hdr.id_table[i].vendor, hdr.id_table[i].product); + + *hdev = (struct hid_device*)realloc(*hdev, (*numHdev+1) * sizeof(struct hid_device)); + if (!*hdev) { + printf("out of memory\n"); + continue; + } + + if (*numHdev > 0) + { + //Correct all previous pointers to their new locations + for (int old_dev = 0; old_dev < *numHdev; old_dev++) + { + (*hdev)[old_dev].dev.parent = &((*hdev)[old_dev].dev); + (*hdev)[old_dev].dev.parent_usb_interface->dev = &((*hdev)[old_dev].dev); + (*hdev)[old_dev].dev.parent_usb_interface->parent_usb_device->dev = &((*hdev)[old_dev].dev); + } + } + + struct usb_interface* intf = (struct usb_interface*)malloc(sizeof(struct usb_interface)); + intf->cur_altsetting = (struct usb_host_interface*)malloc(sizeof(struct usb_host_interface)); + intf->cur_altsetting->desc.bInterfaceProtocol = 0; + + struct usb_device *usbdevice = (struct usb_device*)malloc(sizeof(struct usb_device)); + usbdevice->descriptor.idVendor = hdr.id_table[i].vendor; + usbdevice->descriptor.idProduct = hdr.id_table[i].product; + + intf->parent_usb_device = usbdevice; + + (*hdev)[*numHdev].product = hdr.id_table[i].product; + (*hdev)[*numHdev].dev.parent = &((*hdev)[*numHdev].dev); + (*hdev)[*numHdev].dev.driver_data; + (*hdev)[*numHdev].dev.p = hWinUSBHandle; + (*hdev)[*numHdev].dev.parent_usb_interface = intf; + (*hdev)[*numHdev].dev.init_name = hdr.name; + + usbdevice->dev = &((*hdev)[*numHdev].dev); + intf->dev = &((*hdev)[*numHdev].dev); + + + (*hdev)[*numHdev].status = 2; + (*hdev)[*numHdev].driver = &hdr; + (*hdev)[*numHdev].ll_driver = (struct hid_ll_driver*)malloc(sizeof(struct hid_ll_driver)); + (*hdev)[*numHdev].ll_driver->parse = ll_parse; + (*hdev)[*numHdev].ll_driver->start = ll_start; + (*hdev)[*numHdev].ll_driver->stop = ll_stop; + + (*hdev)[*numHdev].driver->probe(&((*hdev)[*numHdev]), &(hdr.id_table[i])); + + (*numHdev)++; + } + if (!numHdev) + printf("device %04X:%04X NOT opened!\n", hdr.id_table[i].vendor, hdr.id_table[i].product); + } +} + +#endif /* HID_H_ */ diff --git a/dependencies/openrazer-win32/linux/init.h b/dependencies/openrazer-win32/linux/init.h new file mode 100644 index 00000000..090c4b0f --- /dev/null +++ b/dependencies/openrazer-win32/linux/init.h @@ -0,0 +1,60 @@ +#ifndef INIT_H_ +#define INIT_H_ + +static inline int sprint_f(char* buf, const char* fmt, ...) { + va_list args; + int i; + va_start(args, fmt); + i = sprintf_s(buf, strlen(buf) - 1, fmt, args); + va_end(args); + return i; +} +#define sprintf sprint_f + +static inline int strncpy_f(char* dest, const char* source, const size_t sourceLen) { + return strncpy_s(dest, strlen(dest) - 1, source, sourceLen); +} +#define strncpy strncpy_f + +static inline int strcpy_f(char* dest, const char* source) { + return strcpy_s(dest, strlen(dest) - 1, source); +} +#define strcpy strcpy_f + +#define strdup _strdup + +#define KERN_WARNING +#define KERN_ALERT +#define KERN_CRIT + +#define printk printf + +inline unsigned long simple_strtoul(const char *cp, char **endp, unsigned int base) { + return strtoul(cp, endp, base); +} + +inline void usleep(__int64 usec) { + HANDLE timer; + LARGE_INTEGER ft; + + ft.QuadPart = -(10 * usec); // Convert to 100 nanosecond interval, negative value indicates relative time + + timer = CreateWaitableTimer(NULL, TRUE, NULL); + SetWaitableTimer(timer, &ft, 0, NULL, NULL, 0); + WaitForSingleObject(timer, INFINITE); + CloseHandle(timer); +} + +inline void msleep(__int64 msec) { + usleep(1000 * msec); +} + +inline void usleep_range(__int64 usec1, __int64 usec2) { + usleep((usec1 + usec2) / 2); +} + +inline unsigned short eflip(unsigned short val) { + return (val & 0xff) * 0xFF + (val >> 8); +} + +#endif /* INIT_H_ */ diff --git a/dependencies/openrazer-win32/linux/kernel.h b/dependencies/openrazer-win32/linux/kernel.h new file mode 100644 index 00000000..70b97775 --- /dev/null +++ b/dependencies/openrazer-win32/linux/kernel.h @@ -0,0 +1,98 @@ +#ifndef KERNEL_H_ +#define KERNEL_H_ + +#include + +#define DLL_INTERNAL __declspec( dllexport ) + +#define u8 unsigned char +#define u16 unsigned short +#define u32 unsigned int +#define u64 unsigned long + +#define __u8 unsigned char +#define __u16 unsigned short +#define __u32 unsigned int +#define __u64 unsigned long +#define uint8_t unsigned char +#define uint16_t unsigned short +#define uint32_t unsigned int +#define uint64_t unsigned long +#define __le8 unsigned char +#define __le16 unsigned short +#define __le32 unsigned int +#define __le64 unsigned long +#define __s8 signed char +#define __s16 signed short +#define __s32 signed int +#define __s64 signed long +#define uint unsigned int +#define ulong unsigned long + +#define socklen_t int + +#define bool int +#define true 1 +#define false 0 + +#define size_t SIZE_T +#define ssize_t SSIZE_T + +struct mutex { + CRITICAL_SECTION lock; +}; + +inline void mutex_init(struct mutex* mutex) { + InitializeCriticalSection(&mutex->lock); +} + +inline void mutex_lock(struct mutex* mutex) { + EnterCriticalSection(&mutex->lock); +} + +inline void mutex_unlock(struct mutex* mutex) { + LeaveCriticalSection(&mutex->lock); +} + +inline int mutex_trylock(struct mutex* mutex) { + return TryEnterCriticalSection(&mutex->lock); +} + +inline int mutex_is_locked(struct mutex* mutex) { + if (mutex_trylock(mutex)) { + mutex_unlock(mutex); + return 0; + } + else + return 1; +} + +inline void set_bit(int nr, volatile unsigned long *addr) { + int *a = (int *)addr; + int mask; + + a += nr >> 5; + mask = 1 << (nr & 0x1f); + *a |= mask; +} +#define __set_bit set_bit + +inline void clear_bit(int nr, volatile unsigned long *addr) { + int *a = (int *)addr; + int mask; + + a += nr >> 5; + mask = 1 << (nr & 0x1f); + *a &= ~mask; +} + +inline int test_bit(int nr, const void *addr) { + int *a = (int *)addr; + int mask; + + a += nr >> 5; + mask = 1 << (nr & 0x1f); + return ((mask & *a) != 0); +} + +#endif /* KERNEL_H_ */ diff --git a/dependencies/openrazer-win32/linux/module.h b/dependencies/openrazer-win32/linux/module.h new file mode 100644 index 00000000..96e14156 --- /dev/null +++ b/dependencies/openrazer-win32/linux/module.h @@ -0,0 +1,146 @@ +#ifndef MODULE_H_ +#define MODULE_H_ + +#include +#include + +#define MODULE_AUTHOR( __Declaration__ ) +#define MODULE_DESCRIPTION( __Declaration__ ) +#define MODULE_VERSION( __Declaration__ ) +#define MODULE_LICENSE( __Declaration__ ) + +#define USB_CTRL_SET_TIMEOUT 5000 + +#define USB_DIR_OUT 0 +#define USB_DIR_IN 0x80 + +#define USB_TYPE_CLASS (0x01 << 5) +#define USB_RECIP_INTERFACE 0x01 + +#define usb_sndctrlpipe(u,d) 0 +#define usb_rcvctrlpipe(u,d) 0 + +#define PATH_MAX 512 + +struct usb_interface_descriptor { + unsigned char bInterfaceProtocol; +}; + +struct usb_host_interface { + struct usb_interface_descriptor desc; +}; + +struct device { + struct device *parent; + void *p; + const char *init_name; + void *driver_data; +struct usb_interface *parent_usb_interface; +}; + +struct usb_interface { + struct device* dev; + int num_altsetting; + struct usb_host_interface *cur_altsetting; +struct usb_device *parent_usb_device; +}; + +struct usb_device_descriptor { + unsigned short idVendor; + unsigned short idProduct; +}; + +struct usb_device { + struct device* dev; + struct usb_device_descriptor descriptor; +}; + +inline int usb_control_msg( + struct usb_device *usb_dev + , int usb_pipe + , unsigned int request + , unsigned int request_type + , unsigned int value + , unsigned int report_index + , unsigned char* buf, unsigned int size + , unsigned int timeout) +{ + WINUSB_SETUP_PACKET packet; + packet.RequestType = request_type; + packet.Request = request; + packet.Value = value; + packet.Index = report_index; + packet.Length = size; + ULONG cbSent = 0; + if (!WinUsb_ControlTransfer(usb_dev->dev->p, packet, buf, size, &cbSent, 0)) + printf("WinUsb_ControlTransfer failed\n"); + + return cbSent; +} + + + +inline struct usb_interface *to_usb_interface(struct device *dev) { + return dev->parent_usb_interface; +} + +inline struct usb_device *to_usb_device(struct device *dev) { + return dev->parent_usb_interface->parent_usb_device; +} + +inline struct usb_device *interface_to_usbdev(struct usb_interface *intf) { + return to_usb_device(intf->dev->parent); +} + +inline void usb_disable_autosuspend(struct usb_device *usb_dev) { + printf("usb_disable_autosuspend\n"); +} + +struct device_attribute { + const char* name; + ssize_t(*show)(struct device *dev, struct device_attribute *attr, char *buf); + ssize_t(*store)(struct device *dev, struct device_attribute *attr, const char *buf, size_t count); +}; + +inline int device_create_file(struct device *device, struct device_attribute *entry) { + printf("device_create_file %s\n", entry->name); + return 0; +} + +inline void device_remove_file(struct device *device, struct device_attribute *entry) { + printf("device_remove_file %s\n", entry->name); +} + +#define HID_USB_DEVICE(ven, prod) \ + .vendor = (ven) \ + , .product = (prod) + + +#define __stringify(x) #x + +// Hack to turn Linux device macros into API calls +#define DEVICE_ATTR1(_device,_name, _mode, _show, _store) \ + struct device_attribute dev_attr_##_name; \ + DLL_INTERNAL struct device_attribute dev##_device##_attr_##_name = { \ + .name = __stringify(_name) \ + , .show = _show \ + , .store = _store \ + }; + +#define MODULE_DEVICE_TABLE(type, name) + +/*typedef struct hid_device_array_tag { + unsigned int count; + struct hid_device* hdev[]; +} hid_device_array;*/ + +#define module_hid_driver(hdr) \ +DLL_INTERNAL unsigned int init_##hdr## (struct hid_device** hdevo) { \ + unsigned int numHdevs = 0; \ + struct hid_device* hdev = NULL; \ + openChromaDevice(&hdev, &numHdevs, hdr); \ + *hdevo = hdev; \ + return numHdevs; \ +} + +#endif /* MODULE_H_ */ diff --git a/dependencies/openrazer-win32/linux/random.h b/dependencies/openrazer-win32/linux/random.h new file mode 100644 index 00000000..c32727d9 --- /dev/null +++ b/dependencies/openrazer-win32/linux/random.h @@ -0,0 +1,16 @@ +#ifndef RANDOM_H_ +#define RANDOM_H_ + +static inline void get_random_bytes(void* rand_ptr, unsigned int rand_size) { + char failed = 0; + static HCRYPTPROV prov = 0; + if (prov == 0) { + if (!CryptAcquireContext(&prov, NULL, NULL, PROV_RSA_FULL, 0)) + failed = 1; + } + if (!failed && !CryptGenRandom(prov, rand_size, (unsigned char*)rand_ptr)) + printf("get_random_bytes failed\n"); +} + + +#endif /* RANDOM_H_ */ diff --git a/dependencies/openrazer-win32/linux/slab.h b/dependencies/openrazer-win32/linux/slab.h new file mode 100644 index 00000000..ec07dd0a --- /dev/null +++ b/dependencies/openrazer-win32/linux/slab.h @@ -0,0 +1,31 @@ +#ifndef SLAB_H_ +#define SLAB_H_ + +typedef enum { + GFP_KERNEL, + GFP_ATOMIC, + __GFP_HIGHMEM, + __GFP_HIGH +} gfp_t; + +static inline void *kzalloc(size_t s, gfp_t gfp) { + void *p = malloc(s); + + memset(p, 0, s); + return p; +} + +inline void *kmemdup(const void *src, size_t len, gfp_t gfp) { + void *p; + p = malloc(len); + if (p) + memcpy(p, src, len); + return p; +} + +static inline void kfree(const void* p) { + free((void*)p); +} + + +#endif /* SLAB_H_ */ diff --git a/dependencies/openrazer-win32/linux/usb/input.h b/dependencies/openrazer-win32/linux/usb/input.h new file mode 100644 index 00000000..29bf6eb8 --- /dev/null +++ b/dependencies/openrazer-win32/linux/usb/input.h @@ -0,0 +1,539 @@ +#ifndef INPUT_H_ +#define INPUT_H_ + +#include +#include + +#define uint unsigned int +#define ulong unsigned long +#define u8 unsigned char +#define u16 unsigned short +#define u32 unsigned int +#define u64 unsigned long + +#define ABS_VOLUME 0x20 + +//input-event-codes.h +#define KEY_RESERVED 0 +#define KEY_ESC 1 +#define KEY_1 2 +#define KEY_2 3 +#define KEY_3 4 +#define KEY_4 5 +#define KEY_5 6 +#define KEY_6 7 +#define KEY_7 8 +#define KEY_8 9 +#define KEY_9 10 +#define KEY_0 11 +#define KEY_MINUS 12 +#define KEY_EQUAL 13 +#define KEY_BACKSPACE 14 +#define KEY_TAB 15 +#define KEY_Q 16 +#define KEY_W 17 +#define KEY_E 18 +#define KEY_R 19 +#define KEY_T 20 +#define KEY_Y 21 +#define KEY_U 22 +#define KEY_I 23 +#define KEY_O 24 +#define KEY_P 25 +#define KEY_LEFTBRACE 26 +#define KEY_RIGHTBRACE 27 +#define KEY_ENTER 28 +#define KEY_LEFTCTRL 29 +#define KEY_A 30 +#define KEY_S 31 +#define KEY_D 32 +#define KEY_F 33 +#define KEY_G 34 +#define KEY_H 35 +#define KEY_J 36 +#define KEY_K 37 +#define KEY_L 38 +#define KEY_SEMICOLON 39 +#define KEY_APOSTROPHE 40 +#define KEY_GRAVE 41 +#define KEY_LEFTSHIFT 42 +#define KEY_BACKSLASH 43 +#define KEY_Z 44 +#define KEY_X 45 +#define KEY_C 46 +#define KEY_V 47 +#define KEY_B 48 +#define KEY_N 49 +#define KEY_M 50 +#define KEY_COMMA 51 +#define KEY_DOT 52 +#define KEY_SLASH 53 +#define KEY_RIGHTSHIFT 54 +#define KEY_KPASTERISK 55 +#define KEY_LEFTALT 56 +#define KEY_SPACE 57 +#define KEY_CAPSLOCK 58 +#define KEY_F1 59 +#define KEY_F2 60 +#define KEY_F3 61 +#define KEY_F4 62 +#define KEY_F5 63 +#define KEY_F6 64 +#define KEY_F7 65 +#define KEY_F8 66 +#define KEY_F9 67 +#define KEY_F10 68 +#define KEY_NUMLOCK 69 +#define KEY_SCROLLLOCK 70 +#define KEY_KP7 71 +#define KEY_KP8 72 +#define KEY_KP9 73 +#define KEY_KPMINUS 74 +#define KEY_KP4 75 +#define KEY_KP5 76 +#define KEY_KP6 77 +#define KEY_KPPLUS 78 +#define KEY_KP1 79 +#define KEY_KP2 80 +#define KEY_KP3 81 +#define KEY_KP0 82 +#define KEY_KPDOT 83 + +#define KEY_ZENKAKUHANKAKU 85 +#define KEY_102ND 86 +#define KEY_F11 87 +#define KEY_F12 88 +#define KEY_RO 89 +#define KEY_KATAKANA 90 +#define KEY_HIRAGANA 91 +#define KEY_HENKAN 92 +#define KEY_KATAKANAHIRAGANA 93 +#define KEY_MUHENKAN 94 +#define KEY_KPJPCOMMA 95 +#define KEY_KPENTER 96 +#define KEY_RIGHTCTRL 97 +#define KEY_KPSLASH 98 +#define KEY_SYSRQ 99 +#define KEY_RIGHTALT 100 +#define KEY_LINEFEED 101 +#define KEY_HOME 102 +#define KEY_UP 103 +#define KEY_PAGEUP 104 +#define KEY_LEFT 105 +#define KEY_RIGHT 106 +#define KEY_END 107 +#define KEY_DOWN 108 +#define KEY_PAGEDOWN 109 +#define KEY_INSERT 110 +#define KEY_DELETE 111 +#define KEY_MACRO 112 +#define KEY_MUTE 113 +#define KEY_VOLUMEDOWN 114 +#define KEY_VOLUMEUP 115 +#define KEY_POWER 116 /* SC System Power Down */ +#define KEY_KPEQUAL 117 +#define KEY_KPPLUSMINUS 118 +#define KEY_PAUSE 119 +#define KEY_SCALE 120 /* AL Compiz Scale (Expose) */ + +#define KEY_KPCOMMA 121 +#define KEY_HANGEUL 122 +#define KEY_HANGUEL KEY_HANGEUL +#define KEY_HANJA 123 +#define KEY_YEN 124 +#define KEY_LEFTMETA 125 +#define KEY_RIGHTMETA 126 +#define KEY_COMPOSE 127 + +#define KEY_STOP 128 /* AC Stop */ +#define KEY_AGAIN 129 +#define KEY_PROPS 130 /* AC Properties */ +#define KEY_UNDO 131 /* AC Undo */ +#define KEY_FRONT 132 +#define KEY_COPY 133 /* AC Copy */ +#define KEY_OPEN 134 /* AC Open */ +#define KEY_PASTE 135 /* AC Paste */ +#define KEY_FIND 136 /* AC Search */ +#define KEY_CUT 137 /* AC Cut */ +#define KEY_HELP 138 /* AL Integrated Help Center */ +#define KEY_MENU 139 /* Menu (show menu) */ +#define KEY_CALC 140 /* AL Calculator */ +#define KEY_SETUP 141 +#define KEY_SLEEP 142 /* SC System Sleep */ +#define KEY_WAKEUP 143 /* System Wake Up */ +#define KEY_FILE 144 /* AL Local Machine Browser */ +#define KEY_SENDFILE 145 +#define KEY_DELETEFILE 146 +#define KEY_XFER 147 +#define KEY_PROG1 148 +#define KEY_PROG2 149 +#define KEY_WWW 150 /* AL Internet Browser */ +#define KEY_MSDOS 151 +#define KEY_COFFEE 152 /* AL Terminal Lock/Screensaver */ +#define KEY_SCREENLOCK KEY_COFFEE +#define KEY_DIRECTION 153 +#define KEY_CYCLEWINDOWS 154 +#define KEY_MAIL 155 +#define KEY_BOOKMARKS 156 /* AC Bookmarks */ +#define KEY_COMPUTER 157 +#define KEY_BACK 158 /* AC Back */ +#define KEY_FORWARD 159 /* AC Forward */ +#define KEY_CLOSECD 160 +#define KEY_EJECTCD 161 +#define KEY_EJECTCLOSECD 162 +#define KEY_NEXTSONG 163 +#define KEY_PLAYPAUSE 164 +#define KEY_PREVIOUSSONG 165 +#define KEY_STOPCD 166 +#define KEY_RECORD 167 +#define KEY_REWIND 168 +#define KEY_PHONE 169 /* Media Select Telephone */ +#define KEY_ISO 170 +#define KEY_CONFIG 171 /* AL Consumer Control Configuration */ +#define KEY_HOMEPAGE 172 /* AC Home */ +#define KEY_REFRESH 173 /* AC Refresh */ +#define KEY_EXIT 174 /* AC Exit */ +#define KEY_MOVE 175 +#define KEY_EDIT 176 +#define KEY_SCROLLUP 177 +#define KEY_SCROLLDOWN 178 +#define KEY_KPLEFTPAREN 179 +#define KEY_KPRIGHTPAREN 180 +#define KEY_NEW 181 /* AC New */ +#define KEY_REDO 182 /* AC Redo/Repeat */ + +#define KEY_F13 183 +#define KEY_F14 184 +#define KEY_F15 185 +#define KEY_F16 186 +#define KEY_F17 187 +#define KEY_F18 188 +#define KEY_F19 189 +#define KEY_F20 190 +#define KEY_F21 191 +#define KEY_F22 192 +#define KEY_F23 193 +#define KEY_F24 194 + +#define KEY_PLAYCD 200 +#define KEY_PAUSECD 201 +#define KEY_PROG3 202 +#define KEY_PROG4 203 +#define KEY_DASHBOARD 204 /* AL Dashboard */ +#define KEY_SUSPEND 205 +#define KEY_CLOSE 206 /* AC Close */ +#define KEY_PLAY 207 +#define KEY_FASTFORWARD 208 +#define KEY_BASSBOOST 209 +#define KEY_PRINT 210 /* AC Print */ +#define KEY_HP 211 +#define KEY_CAMERA 212 +#define KEY_SOUND 213 +#define KEY_QUESTION 214 +#define KEY_EMAIL 215 +#define KEY_CHAT 216 +#define KEY_SEARCH 217 +#define KEY_CONNECT 218 +#define KEY_FINANCE 219 /* AL Checkbook/Finance */ +#define KEY_SPORT 220 +#define KEY_SHOP 221 +#define KEY_ALTERASE 222 +#define KEY_CANCEL 223 /* AC Cancel */ +#define KEY_BRIGHTNESSDOWN 224 +#define KEY_BRIGHTNESSUP 225 +#define KEY_MEDIA 226 + +#define KEY_SWITCHVIDEOMODE 227 /* Cycle between available video + outputs (Monitor/LCD/TV-out/etc) */ +#define KEY_KBDILLUMTOGGLE 228 +#define KEY_KBDILLUMDOWN 229 +#define KEY_KBDILLUMUP 230 + +#define KEY_SEND 231 /* AC Send */ +#define KEY_REPLY 232 /* AC Reply */ +#define KEY_FORWARDMAIL 233 /* AC Forward Msg */ +#define KEY_SAVE 234 /* AC Save */ +#define KEY_DOCUMENTS 235 + +#define KEY_BATTERY 236 + +#define KEY_BLUETOOTH 237 +#define KEY_WLAN 238 +#define KEY_UWB 239 + +#define KEY_UNKNOWN 240 + +#define KEY_VIDEO_NEXT 241 /* drive next video source */ +#define KEY_VIDEO_PREV 242 /* drive previous video source */ +#define KEY_BRIGHTNESS_CYCLE 243 /* brightness up, after max is min */ +#define KEY_BRIGHTNESS_ZERO 244 /* brightness off, use ambient */ +#define KEY_DISPLAY_OFF 245 /* display device to off state */ + +#define KEY_WIMAX 246 + +/* Range 248 - 255 is reserved for special needs of AT keyboard driver */ + +#define BTN_MISC 0x100 +#define BTN_0 0x100 +#define BTN_1 0x101 +#define BTN_2 0x102 +#define BTN_3 0x103 +#define BTN_4 0x104 +#define BTN_5 0x105 +#define BTN_6 0x106 +#define BTN_7 0x107 +#define BTN_8 0x108 +#define BTN_9 0x109 + +#define BTN_MOUSE 0x110 +#define BTN_LEFT 0x110 +#define BTN_RIGHT 0x111 +#define BTN_MIDDLE 0x112 +#define BTN_SIDE 0x113 +#define BTN_EXTRA 0x114 +#define BTN_FORWARD 0x115 +#define BTN_BACK 0x116 +#define BTN_TASK 0x117 + +#define BTN_JOYSTICK 0x120 +#define BTN_TRIGGER 0x120 +#define BTN_THUMB 0x121 +#define BTN_THUMB2 0x122 +#define BTN_TOP 0x123 +#define BTN_TOP2 0x124 +#define BTN_PINKIE 0x125 +#define BTN_BASE 0x126 +#define BTN_BASE2 0x127 +#define BTN_BASE3 0x128 +#define BTN_BASE4 0x129 +#define BTN_BASE5 0x12a +#define BTN_BASE6 0x12b +#define BTN_DEAD 0x12f + +#define BTN_GAMEPAD 0x130 +#define BTN_A 0x130 +#define BTN_B 0x131 +#define BTN_C 0x132 +#define BTN_X 0x133 +#define BTN_Y 0x134 +#define BTN_Z 0x135 +#define BTN_TL 0x136 +#define BTN_TR 0x137 +#define BTN_TL2 0x138 +#define BTN_TR2 0x139 +#define BTN_SELECT 0x13a +#define BTN_START 0x13b +#define BTN_MODE 0x13c +#define BTN_THUMBL 0x13d +#define BTN_THUMBR 0x13e + +#define BTN_DIGI 0x140 +#define BTN_TOOL_PEN 0x140 +#define BTN_TOOL_RUBBER 0x141 +#define BTN_TOOL_BRUSH 0x142 +#define BTN_TOOL_PENCIL 0x143 +#define BTN_TOOL_AIRBRUSH 0x144 +#define BTN_TOOL_FINGER 0x145 +#define BTN_TOOL_MOUSE 0x146 +#define BTN_TOOL_LENS 0x147 +#define BTN_TOUCH 0x14a +#define BTN_STYLUS 0x14b +#define BTN_STYLUS2 0x14c +#define BTN_TOOL_DOUBLETAP 0x14d +#define BTN_TOOL_TRIPLETAP 0x14e +#define BTN_TOOL_QUADTAP 0x14f /* Four fingers on trackpad */ + +#define BTN_WHEEL 0x150 +#define BTN_GEAR_DOWN 0x150 +#define BTN_GEAR_UP 0x151 + +#define KEY_OK 0x160 +#define KEY_SELECT 0x161 +#define KEY_GOTO 0x162 +#define KEY_CLEAR 0x163 +#define KEY_POWER2 0x164 +#define KEY_OPTION 0x165 +#define KEY_INFO 0x166 /* AL OEM Features/Tips/Tutorial */ +#define KEY_TIME 0x167 +#define KEY_VENDOR 0x168 +#define KEY_ARCHIVE 0x169 +#define KEY_PROGRAM 0x16a /* Media Select Program Guide */ +#define KEY_CHANNEL 0x16b +#define KEY_FAVORITES 0x16c +#define KEY_EPG 0x16d +#define KEY_PVR 0x16e /* Media Select Home */ +#define KEY_MHP 0x16f +#define KEY_LANGUAGE 0x170 +#define KEY_TITLE 0x171 +#define KEY_SUBTITLE 0x172 +#define KEY_ANGLE 0x173 +#define KEY_ZOOM 0x174 +#define KEY_MODE 0x175 +#define KEY_KEYBOARD 0x176 +#define KEY_SCREEN 0x177 +#define KEY_PC 0x178 /* Media Select Computer */ +#define KEY_TV 0x179 /* Media Select TV */ +#define KEY_TV2 0x17a /* Media Select Cable */ +#define KEY_VCR 0x17b /* Media Select VCR */ +#define KEY_VCR2 0x17c /* VCR Plus */ +#define KEY_SAT 0x17d /* Media Select Satellite */ +#define KEY_SAT2 0x17e +#define KEY_CD 0x17f /* Media Select CD */ +#define KEY_TAPE 0x180 /* Media Select Tape */ +#define KEY_RADIO 0x181 +#define KEY_TUNER 0x182 /* Media Select Tuner */ +#define KEY_PLAYER 0x183 +#define KEY_TEXT 0x184 +#define KEY_DVD 0x185 /* Media Select DVD */ +#define KEY_AUX 0x186 +#define KEY_MP3 0x187 +#define KEY_AUDIO 0x188 +#define KEY_VIDEO 0x189 +#define KEY_DIRECTORY 0x18a +#define KEY_LIST 0x18b +#define KEY_MEMO 0x18c /* Media Select Messages */ +#define KEY_CALENDAR 0x18d +#define KEY_RED 0x18e +#define KEY_GREEN 0x18f +#define KEY_YELLOW 0x190 +#define KEY_BLUE 0x191 +#define KEY_CHANNELUP 0x192 /* Channel Increment */ +#define KEY_CHANNELDOWN 0x193 /* Channel Decrement */ +#define KEY_FIRST 0x194 +#define KEY_LAST 0x195 /* Recall Last */ +#define KEY_AB 0x196 +#define KEY_NEXT 0x197 +#define KEY_RESTART 0x198 +#define KEY_SLOW 0x199 +#define KEY_SHUFFLE 0x19a +#define KEY_BREAK 0x19b +#define KEY_PREVIOUS 0x19c +#define KEY_DIGITS 0x19d +#define KEY_TEEN 0x19e +#define KEY_TWEN 0x19f +#define KEY_VIDEOPHONE 0x1a0 /* Media Select Video Phone */ +#define KEY_GAMES 0x1a1 /* Media Select Games */ +#define KEY_ZOOMIN 0x1a2 /* AC Zoom In */ +#define KEY_ZOOMOUT 0x1a3 /* AC Zoom Out */ +#define KEY_ZOOMRESET 0x1a4 /* AC Zoom */ +#define KEY_WORDPROCESSOR 0x1a5 /* AL Word Processor */ +#define KEY_EDITOR 0x1a6 /* AL Text Editor */ +#define KEY_SPREADSHEET 0x1a7 /* AL Spreadsheet */ +#define KEY_GRAPHICSEDITOR 0x1a8 /* AL Graphics Editor */ +#define KEY_PRESENTATION 0x1a9 /* AL Presentation App */ +#define KEY_DATABASE 0x1aa /* AL Database App */ +#define KEY_NEWS 0x1ab /* AL Newsreader */ +#define KEY_VOICEMAIL 0x1ac /* AL Voicemail */ +#define KEY_ADDRESSBOOK 0x1ad /* AL Contacts/Address Book */ +#define KEY_MESSENGER 0x1ae /* AL Instant Messaging */ +#define KEY_DISPLAYTOGGLE 0x1af /* Turn display (LCD) on and off */ +#define KEY_SPELLCHECK 0x1b0 /* AL Spell Check */ +#define KEY_LOGOFF 0x1b1 /* AL Logoff */ + +#define KEY_DOLLAR 0x1b2 +#define KEY_EURO 0x1b3 + +#define KEY_FRAMEBACK 0x1b4 /* Consumer - transport controls */ +#define KEY_FRAMEFORWARD 0x1b5 +#define KEY_CONTEXT_MENU 0x1b6 /* GenDesc - system context menu */ +#define KEY_MEDIA_REPEAT 0x1b7 /* Consumer - transport control */ + +#define KEY_DEL_EOL 0x1c0 +#define KEY_DEL_EOS 0x1c1 +#define KEY_INS_LINE 0x1c2 +#define KEY_DEL_LINE 0x1c3 + +#define KEY_FN 0x1d0 +#define KEY_FN_ESC 0x1d1 +#define KEY_FN_F1 0x1d2 +#define KEY_FN_F2 0x1d3 +#define KEY_FN_F3 0x1d4 +#define KEY_FN_F4 0x1d5 +#define KEY_FN_F5 0x1d6 +#define KEY_FN_F6 0x1d7 +#define KEY_FN_F7 0x1d8 +#define KEY_FN_F8 0x1d9 +#define KEY_FN_F9 0x1da +#define KEY_FN_F10 0x1db +#define KEY_FN_F11 0x1dc +#define KEY_FN_F12 0x1dd +#define KEY_FN_1 0x1de +#define KEY_FN_2 0x1df +#define KEY_FN_D 0x1e0 +#define KEY_FN_E 0x1e1 +#define KEY_FN_F 0x1e2 +#define KEY_FN_S 0x1e3 +#define KEY_FN_B 0x1e4 + +#define KEY_BRL_DOT1 0x1f1 +#define KEY_BRL_DOT2 0x1f2 +#define KEY_BRL_DOT3 0x1f3 +#define KEY_BRL_DOT4 0x1f4 +#define KEY_BRL_DOT5 0x1f5 +#define KEY_BRL_DOT6 0x1f6 +#define KEY_BRL_DOT7 0x1f7 +#define KEY_BRL_DOT8 0x1f8 +#define KEY_BRL_DOT9 0x1f9 +#define KEY_BRL_DOT10 0x1fa + +#define KEY_NUMERIC_0 0x200 /* used by phones, remote controls, */ +#define KEY_NUMERIC_1 0x201 /* and other keypads */ +#define KEY_NUMERIC_2 0x202 +#define KEY_NUMERIC_3 0x203 +#define KEY_NUMERIC_4 0x204 +#define KEY_NUMERIC_5 0x205 +#define KEY_NUMERIC_6 0x206 +#define KEY_NUMERIC_7 0x207 +#define KEY_NUMERIC_8 0x208 +#define KEY_NUMERIC_9 0x209 +#define KEY_NUMERIC_STAR 0x20a +#define KEY_NUMERIC_POUND 0x20b + +/* We avoid low common keys in module aliases so they don't get huge. */ +#define KEY_MIN_INTERESTING KEY_MUTE +#define KEY_MAX 0x2ff +#define KEY_CNT (KEY_MAX+1) + +#define EV_SYN 0x00 +#define EV_KEY 0x01 +#define EV_REL 0x02 +#define EV_ABS 0x03 +#define EV_MSC 0x04 +#define EV_SW 0x05 +#define EV_LED 0x11 +#define EV_SND 0x12 +#define EV_REP 0x14 +#define EV_FF 0x15 +#define EV_PWR 0x16 +#define EV_FF_STATUS 0x17 +#define EV_MAX 0x1f +#define EV_CNT (EV_MAX+1) + +#define SYN_REPORT 0 + +#define BITS_PER_BYTE 8 +#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) +#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long)) +#define DECLARE_BITMAP(name,bits) unsigned long name[BITS_TO_LONGS(bits)] + +struct input_dev { + const char *name; + const char *phys; + unsigned long evbit[BITS_TO_LONGS(EV_CNT)]; + unsigned long keybit[BITS_TO_LONGS(KEY_CNT)]; +}; + +static inline void input_event(struct input_dev *dev, unsigned int type, unsigned int code, int value) { + printf("input_event\n"); +} + +static inline void input_report_key(struct input_dev *dev, unsigned int code, int value) { + input_event(dev, EV_KEY, code, value); +} + +static inline void input_sync(struct input_dev *dev) { + input_event(dev, EV_SYN, SYN_REPORT, 0); +} + + +#endif /* INPUT_H_ */