diff --git a/Controllers/MSI3ZoneController/MSI3ZoneController.cpp b/Controllers/MSI3ZoneController/MSI3ZoneController.cpp new file mode 100644 index 000000000..ccac60ef4 --- /dev/null +++ b/Controllers/MSI3ZoneController/MSI3ZoneController.cpp @@ -0,0 +1,78 @@ +/*-----------------------------------------*\ +| MSI3ZoneController.cpp | +| | +| Driver for MSI/Steelseries 3-Zone | +| Keyboard lighting controller | +| | +| Adam Honse (CalcProgrammer1) 12/25/2019 | +\*-----------------------------------------*/ + +#include "MSI3ZoneController.h" + +MSI3ZoneController::MSI3ZoneController(libusb_device_handle* dev_handle) +{ + dev = dev_handle; + + strcpy(device_name, "MSI 3-Zone Keyboard"); +} + +MSI3ZoneController::~MSI3ZoneController() +{ + +} + +char* MSI3ZoneController::GetDeviceName() +{ + return device_name; +} + +void MSI3ZoneController::SetLEDs(std::vector colors) +{ + //Shout out to bparker06 for reverse engineering the MSI keyboard USB protocol! + // https://github.com/bparker06/msi-keyboard/blob/master/keyboard.cpp for original implementation + unsigned char buf[8] = { 0 }; + + buf[0] = 1; + buf[1] = 2; + buf[2] = 64; + buf[3] = 1; + buf[4] = RGBGetRValue(colors[0]); + buf[5] = RGBGetGValue(colors[0]); + buf[6] = RGBGetBValue(colors[0]); + buf[7] = 236; + + libusb_control_transfer(dev, LIBUSB_DT_HID, LIBUSB_REQUEST_SET_CONFIGURATION, 0x0300, 0x03, buf, 8, 0); + + buf[3] = 2; + buf[4] = RGBGetRValue(colors[1]); + buf[5] = RGBGetGValue(colors[1]); + buf[6] = RGBGetBValue(colors[1]); + + libusb_control_transfer(dev, LIBUSB_DT_HID, LIBUSB_REQUEST_SET_CONFIGURATION, 0x0300, 0x03, buf, 8, 0); + + buf[3] = 3; + buf[4] = RGBGetRValue(colors[2]); + buf[5] = RGBGetGValue(colors[2]); + buf[6] = RGBGetBValue(colors[2]); + + libusb_control_transfer(dev, LIBUSB_DT_HID, LIBUSB_REQUEST_SET_CONFIGURATION, 0x0300, 0x03, buf, 8, 0); + + buf[3] = 4; + buf[4] = RGBGetRValue(colors[3]); + buf[5] = RGBGetGValue(colors[3]); + buf[6] = RGBGetBValue(colors[3]); + + libusb_control_transfer(dev, LIBUSB_DT_HID, LIBUSB_REQUEST_SET_CONFIGURATION, 0x0300, 0x03, buf, 8, 0); + + buf[3] = 5; + + libusb_control_transfer(dev, LIBUSB_DT_HID, LIBUSB_REQUEST_SET_CONFIGURATION, 0x0300, 0x03, buf, 8, 0); + + buf[3] = 6; + + libusb_control_transfer(dev, LIBUSB_DT_HID, LIBUSB_REQUEST_SET_CONFIGURATION, 0x0300, 0x03, buf, 8, 0); + + buf[3] = 7; + + libusb_control_transfer(dev, LIBUSB_DT_HID, LIBUSB_REQUEST_SET_CONFIGURATION, 0x0300, 0x03, buf, 8, 0); +} \ No newline at end of file diff --git a/Controllers/MSI3ZoneController/MSI3ZoneController.h b/Controllers/MSI3ZoneController/MSI3ZoneController.h new file mode 100644 index 000000000..e20b74da7 --- /dev/null +++ b/Controllers/MSI3ZoneController/MSI3ZoneController.h @@ -0,0 +1,30 @@ +/*-----------------------------------------*\ +| MSI3ZoneController.h | +| | +| Definitions and types for MSI/Steelseries| +| 3-Zone Keyboard lighting controller | +| | +| Adam Honse (CalcProgrammer1) 12/25/2019 | +\*-----------------------------------------*/ + +#include "RGBController.h" + +#include +#include + +#pragma once + +class MSI3ZoneController +{ +public: + MSI3ZoneController(libusb_device_handle* dev_handle); + ~MSI3ZoneController(); + + char* GetDeviceName(); + + void SetLEDs(std::vector colors); + +private: + char device_name[32]; + libusb_device_handle* dev; +}; diff --git a/Controllers/MSI3ZoneController/MSI3ZoneControllerDetect.cpp b/Controllers/MSI3ZoneController/MSI3ZoneControllerDetect.cpp new file mode 100644 index 000000000..e02f33ac2 --- /dev/null +++ b/Controllers/MSI3ZoneController/MSI3ZoneControllerDetect.cpp @@ -0,0 +1,38 @@ +#include "MSI3ZoneController.h" +#include "RGBController.h" +#include "RGBController_MSI3Zone.h" +#include +#include + +#define MSI_3_ZONE_KEYBOARD_VID 0x1770 +#define MSI_3_ZONE_KEYBOARD_PID 0xFF00 + +/******************************************************************************************\ +* * +* DetectMSI3ZoneControllers * +* * +* Tests the USB address to see if an MSI/SteelSeries 3-zone Keyboard controller * +* exists there. * +* * +\******************************************************************************************/ + +void DetectMSI3ZoneControllers(std::vector& rgb_controllers) +{ + libusb_context * ctx; + libusb_init(&ctx); + + //Look for MSI/Steelseries 3-zone Keyboard + libusb_device_handle * dev = libusb_open_device_with_vid_pid(ctx, MSI_3_ZONE_KEYBOARD_VID, MSI_3_ZONE_KEYBOARD_PID); + + if( dev ) + { + libusb_detach_kernel_driver(dev, 1); + libusb_claim_interface(dev, 1); + + MSI3ZoneController* controller = new MSI3ZoneController(dev); + + RGBController_MSI3Zone* rgb_controller = new RGBController_MSI3Zone(controller); + + rgb_controllers.push_back(rgb_controller); + } +} diff --git a/OpenAuraSDK.cpp b/OpenAuraSDK.cpp index 9e9481320..9eb6391e3 100644 --- a/OpenAuraSDK.cpp +++ b/OpenAuraSDK.cpp @@ -364,6 +364,7 @@ void DetectOpenRazerControllers(std::vector &rgb_controllers); void DetectRazerChromaSDKControllers(std::vector& rgb_controllers); void DetectE131Controllers(std::vector &rgb_controllers); void DetectAMDWraithPrismControllers(std::vector& rgb_controllers); +void DetectMSI3ZoneControllers(std::vector& rgb_controllers); /******************************************************************************************\ * * @@ -387,6 +388,7 @@ void DetectRGBControllers(void) DetectHuePlusControllers(rgb_controllers); DetectAMDWraithPrismControllers(rgb_controllers); + DetectMSI3ZoneControllers(rgb_controllers); #ifdef WIN32 DetectRazerChromaSDKControllers(rgb_controllers); diff --git a/OpenRGB.pro b/OpenRGB.pro index 5242b220d..36841e488 100644 --- a/OpenRGB.pro +++ b/OpenRGB.pro @@ -17,6 +17,7 @@ INCLUDEPATH += \ Controllers/HuePlusController/ \ Controllers/HyperXController/ \ Controllers/LEDStripController/ \ + Controllers/MSI3ZoneController/ \ Controllers/PolychromeController/ \ Controllers/RGBFusionController/ \ RGBController/ \ @@ -49,6 +50,8 @@ SOURCES += \ Controllers/HyperXController/HyperXControllerDetect.cpp \ Controllers/LEDStripController/LEDStripController.cpp \ Controllers/LEDStripController/LEDStripControllerDetect.cpp \ + Controllers/MSI3ZoneController/MSI3ZoneController.cpp \ + Controllers/MSI3ZoneController/MSI3ZoneControllerDetect.cpp \ Controllers/PolychromeController/PolychromeController.cpp \ Controllers/RGBFusionController/RGBFusionController.cpp \ Controllers/RGBFusionController/RGBFusionControllerDetect.cpp \ @@ -59,6 +62,8 @@ SOURCES += \ RGBController/RGBController_HuePlus.cpp \ RGBController/RGBController_HyperX.cpp \ RGBController/RGBController_LEDStrip.cpp \ + RGBController/RGBController_MSI3Zone.cpp \ + RGBController/RGBController_Polychrome.cpp \ RGBController/RGBController_RGBFusion.cpp HEADERS += \ @@ -79,6 +84,9 @@ HEADERS += \ Controllers/HuePlusController/HuePlusController.h \ Controllers/HyperXController/HyperXController.h \ Controllers/LEDStripController/LEDStripController.h \ + Controllers/MSI3ZoneController/MSI3ZoneController.h \ + Controllers/PolychromeController/PolychromeController.h \ + Controllers/RGBFusionController/RGBFusionController.h \ RGBController/RGBController.h \ RGBController/RGBController_AMDWraithPrism.h \ RGBController/RGBController_Aura.h \ @@ -86,6 +94,8 @@ HEADERS += \ RGBController/RGBController_CorsairPro.h \ RGBController/RGBController_HuePlus.h \ RGBController/RGBController_HyperX.h \ + RGBController/RGBController_LEDStrip.h \ + RGBController/RGBController_MSI3Zone.h \ RGBController/RGBController_Polychrome.h \ RGBController/RGBController_RGBFusion.h diff --git a/RGBController/RGBController_MSI3Zone.cpp b/RGBController/RGBController_MSI3Zone.cpp new file mode 100644 index 000000000..477029f23 --- /dev/null +++ b/RGBController/RGBController_MSI3Zone.cpp @@ -0,0 +1,96 @@ +/*-----------------------------------------*\ +| RGBController_MSI3Zone.cpp | +| | +| Generic RGB Interface for MSI/Steelseries| +| 3-Zone Keyboard | +| | +| Adam Honse (CalcProgrammer1) 12/25/2019 | +\*-----------------------------------------*/ + +#include "RGBController_MSI3Zone.h" + +RGBController_MSI3Zone::RGBController_MSI3Zone(MSI3ZoneController* msi_ptr) +{ + msi = msi_ptr; + + name = "MSI 3-Zone Keyboard"; + type = DEVICE_TYPE_KEYBOARD; + + mode led_mode; + led_mode.name = "Custom"; + modes.push_back(led_mode); + + led left_led; + left_led.name = "Keyboard Left"; + leds.push_back(left_led); + + led mid_led; + mid_led.name = "Keyboard Middle"; + leds.push_back(mid_led); + + led right_led; + right_led.name = "Keyboard Right"; + leds.push_back(right_led); + + zone keyboard_zone; + keyboard_zone.name = "Keyboard"; + keyboard_zone.type = ZONE_TYPE_LINEAR; + std::vector keyboard_zone_map; + keyboard_zone_map.push_back(0); + keyboard_zone_map.push_back(1); + keyboard_zone_map.push_back(2); + keyboard_zone.map.push_back(keyboard_zone_map); + zones.push_back(keyboard_zone); + + led aux_led; + aux_led.name = "Aux"; + leds.push_back(aux_led); + + zone aux_zone; + aux_zone.name = "Aux"; + aux_zone.type = ZONE_TYPE_SINGLE; + std::vector aux_zone_map; + aux_zone_map.push_back(3); + aux_zone.map.push_back(aux_zone_map); + zones.push_back(aux_zone); +} + +RGBController_MSI3Zone::~RGBController_MSI3Zone() +{ + +} + +int RGBController_MSI3Zone::GetMode() +{ + return 0; +} + +void RGBController_MSI3Zone::SetMode(int mode) +{ + +} + +void RGBController_MSI3Zone::SetCustomMode() +{ + +} + +void RGBController_MSI3Zone::SetAllLEDs(RGBColor color) +{ + +} + +void RGBController_MSI3Zone::SetAllZoneLEDs(int zone, RGBColor color) +{ + +} + +void RGBController_MSI3Zone::SetLED(int led, RGBColor color) +{ + +} + +void RGBController_MSI3Zone::UpdateLEDs() +{ + +} \ No newline at end of file diff --git a/RGBController/RGBController_MSI3Zone.h b/RGBController/RGBController_MSI3Zone.h new file mode 100644 index 000000000..90728028c --- /dev/null +++ b/RGBController/RGBController_MSI3Zone.h @@ -0,0 +1,29 @@ +/*-----------------------------------------*\ +| RGBController_MSI3Zone.h | +| | +| Generic RGB Interface for MSI/Steelseries| +| 3-Zone Keyboard | +| | +| Adam Honse (CalcProgrammer1) 12/25/2019 | +\*-----------------------------------------*/ + +#pragma once +#include "RGBController.h" +#include "MSI3ZoneController.h" + +class RGBController_MSI3Zone : public RGBController +{ +public: + RGBController_MSI3Zone(MSI3ZoneController* msi_ptr); + ~RGBController_MSI3Zone(); + int GetMode(); + void SetMode(int mode); + void SetCustomMode(); + void SetAllLEDs(RGBColor color); + void SetAllZoneLEDs(int zone, RGBColor color); + void SetLED(int led, RGBColor color); + void UpdateLEDs(); + +private: + MSI3ZoneController* msi; +}; \ No newline at end of file diff --git a/RGBController/RGBController_Polychrome.cpp b/RGBController/RGBController_Polychrome.cpp index a817965ca..d2ac0490e 100644 --- a/RGBController/RGBController_Polychrome.cpp +++ b/RGBController/RGBController_Polychrome.cpp @@ -11,7 +11,7 @@ int RGBController_Polychrome::GetMode() { - return(polychrome->GetMode()); + return(0); } void RGBController_Polychrome::SetMode(int mode)