Initial commit for NZXT Mouse Controller (NZXT Lift), implements only Direct mode

This commit is contained in:
Adam Honse 2024-04-16 17:22:43 -05:00
parent fe87c25c16
commit 2f80548303
5 changed files with 359 additions and 0 deletions

View file

@ -0,0 +1,138 @@
/*---------------------------------------------------------*\
| NZXTMouseController.cpp |
| |
| Driver for NZXT Mouse |
| |
| Adam Honse (calcprogrammer1@gmail.com), 12/13/2023 |
\*---------------------------------------------------------*/
#include "NZXTMouseController.h"
#include <cstring>
NZXTMouseController::NZXTMouseController(hid_device* dev_handle, const char* path)
{
dev = dev_handle;
location = path;
/*-----------------------------------------------------*\
| Request firmware version |
\*-----------------------------------------------------*/
SendFirmwareRequest();
}
NZXTMouseController::~NZXTMouseController()
{
hid_close(dev);
}
std::string NZXTMouseController::GetFirmwareVersion()
{
return(firmware_version);
}
std::string NZXTMouseController::GetLocation()
{
return("HID: " + location);
}
std::string NZXTMouseController::GetSerialString()
{
wchar_t serial_string[128];
int ret = hid_get_serial_number_string(dev, serial_string, 128);
if(ret != 0)
{
return("");
}
std::wstring return_wstring = serial_string;
std::string return_string(return_wstring.begin(), return_wstring.end());
return(return_string);
}
void NZXTMouseController::SetLEDs
(
RGBColor * colors
)
{
unsigned char usb_buf[64];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, sizeof(usb_buf));
/*-----------------------------------------------------*\
| Set up Direct packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x43;
usb_buf[0x01] = 0xAE;
usb_buf[0x03] = 0x10;
usb_buf[0x04] = 0x02;
usb_buf[0x05] = 0x3F;
usb_buf[24] = 0x06;
usb_buf[25] = RGBGetRValue(colors[2]);
usb_buf[26] = RGBGetGValue(colors[2]);
usb_buf[27] = RGBGetBValue(colors[2]);
usb_buf[29] = RGBGetRValue(colors[1]);
usb_buf[30] = RGBGetGValue(colors[1]);
usb_buf[31] = RGBGetBValue(colors[1]);
usb_buf[33] = RGBGetRValue(colors[0]);
usb_buf[34] = RGBGetGValue(colors[0]);
usb_buf[35] = RGBGetBValue(colors[0]);
usb_buf[37] = RGBGetRValue(colors[3]);
usb_buf[38] = RGBGetGValue(colors[3]);
usb_buf[39] = RGBGetBValue(colors[3]);
usb_buf[41] = RGBGetRValue(colors[4]);
usb_buf[42] = RGBGetGValue(colors[4]);
usb_buf[43] = RGBGetBValue(colors[4]);
usb_buf[45] = RGBGetRValue(colors[5]);
usb_buf[46] = RGBGetGValue(colors[5]);
usb_buf[47] = RGBGetBValue(colors[5]);
/*-----------------------------------------------------*\
| Send packet |
\*-----------------------------------------------------*/
hid_write(dev, usb_buf, sizeof(usb_buf));
}
void NZXTMouseController::SendFirmwareRequest()
{
unsigned char usb_buf[64];
int ret_val = 0;
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, sizeof(usb_buf));
/*-----------------------------------------------------*\
| Set up Firmware Request packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x43;
usb_buf[0x01] = 0x81;
usb_buf[0x03] = 0x01;
hid_write(dev, usb_buf, sizeof(usb_buf));
/*-----------------------------------------------------*\
| Receive packets until 0x43 0x86 is received |
\*-----------------------------------------------------*/
do
{
ret_val = hid_read(dev, usb_buf, sizeof(usb_buf));
} while( (usb_buf[0] != 0x43) || (usb_buf[1] != 0x86) );
/*-----------------------------------------------------*\
| Format firmware version string |
\*-----------------------------------------------------*/
snprintf(firmware_version, 16, "%u.%u.%u", usb_buf[0x03], usb_buf[0x04], usb_buf[0x05]);
}

View file

@ -0,0 +1,38 @@
/*---------------------------------------------------------*\
| NZXTMouseController.h |
| |
| Definitions for NZXT Mouse |
| |
| Adam Honse (calcprogrammer1@gmail.com), 12/13/2023 |
\*---------------------------------------------------------*/
#pragma once
#include "RGBController.h"
#include <string>
#include <vector>
#include <hidapi/hidapi.h>
class NZXTMouseController
{
public:
NZXTMouseController(hid_device* dev_handle, const char* path);
~NZXTMouseController();
std::string GetFirmwareVersion();
std::string GetLocation();
std::string GetSerialString();
void SetLEDs
(
RGBColor * colors
);
private:
hid_device* dev;
char firmware_version[16];
std::string location;
void SendFirmwareRequest();
};

View file

@ -0,0 +1,35 @@
#include "Detector.h"
#include "NZXTMouseController.h"
#include "RGBController.h"
#include "RGBController_NZXTMouse.h"
#include <hidapi/hidapi.h>
/*-----------------------------------------------------*\
| NZXT USB IDs |
\*-----------------------------------------------------*/
#define NZXT_VID 0x1E71
#define NZXT_LIFT_PID 0x2100
/******************************************************************************************\
* *
* DetectNZXTMouseControllers *
* *
* Detect devices supported by the NZXTMouse driver *
* *
\******************************************************************************************/
static void DetectNZXTMouseControllers(hid_device_info* info, const std::string& name)
{
hid_device* dev = hid_open_path(info->path);
if(dev)
{
NZXTMouseController* controller = new NZXTMouseController(dev, info->path);
RGBController_NZXTMouse* rgb_controller = new RGBController_NZXTMouse(controller);
rgb_controller->name = name;
ResourceManager::get()->RegisterRGBController(rgb_controller);
}
}
REGISTER_HID_DETECTOR_IPU("NZXT Lift", DetectNZXTMouseControllers, NZXT_VID, NZXT_LIFT_PID, 0, 0xFFCA, 1);

View file

@ -0,0 +1,115 @@
/*-----------------------------------------*\
| RGBController_NZXTMouse.cpp |
| |
| Generic RGB Interface for NZXT Mouse |
| |
| Adam Honse (CalcProgrammer1) 12/16/2023 |
\*-----------------------------------------*/
#include "RGBController_NZXTMouse.h"
/**------------------------------------------------------------------*\
@name NZXT Mouse
@category Mouse
@type USB
@save :x:
@direct :white_check_mark:
@effects :tools:
@detectors DetectNZXTMouseControllers
@comment
\*-------------------------------------------------------------------*/
RGBController_NZXTMouse::RGBController_NZXTMouse(NZXTMouseController* controller_ptr)
{
controller = controller_ptr;
name = "NZXT Mouse";
vendor = "NZXT";
type = DEVICE_TYPE_MOUSE;
description = "NZXT Mouse Device";
version = controller->GetFirmwareVersion();
location = controller->GetLocation();
serial = controller->GetSerialString();
mode Direct;
Direct.name = "Direct";
Direct.value = 0xFFFF;
Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR;
Direct.color_mode = MODE_COLORS_PER_LED;
modes.push_back(Direct);
SetupZones();
}
RGBController_NZXTMouse::~RGBController_NZXTMouse()
{
}
void RGBController_NZXTMouse::SetupZones()
{
zone left;
left.name = "Left";
left.type = ZONE_TYPE_LINEAR;
left.leds_min = 3;
left.leds_max = 3;
left.leds_count = 3;
left.matrix_map = NULL;
zones.push_back( left );
for(unsigned int led_idx = 0; led_idx < left.leds_count; led_idx++)
{
led left_led;
left_led.name = "Left LED " + led_idx;
leds.push_back(left_led);
}
zone right;
right.name = "Right";
right.type = ZONE_TYPE_LINEAR;
right.leds_min = 3;
right.leds_max = 3;
right.leds_count = 3;
right.matrix_map = NULL;
zones.push_back( right );
for(unsigned int led_idx = 0; led_idx < right.leds_count; led_idx++)
{
led right_led;
right_led.name = "Right LED " + led_idx;
leds.push_back(right_led);
}
SetupColors();
}
void RGBController_NZXTMouse::ResizeZone(int /*zone*/, int /*new_size*/)
{
}
void RGBController_NZXTMouse::DeviceUpdateLEDs()
{
controller->SetLEDs(&colors[0]);
}
void RGBController_NZXTMouse::UpdateZoneLEDs(int zone)
{
DeviceUpdateLEDs();
}
void RGBController_NZXTMouse::UpdateSingleLED(int led)
{
DeviceUpdateLEDs();
}
void RGBController_NZXTMouse::DeviceUpdateMode()
{
DeviceUpdateLEDs();
}

View file

@ -0,0 +1,33 @@
/*-----------------------------------------*\
| RGBController_NZXTMouse.h |
| |
| Generic RGB Interface for NZXT Mouse |
| |
| Adam Honse (CalcProgrammer1) 12/16/2023 |
\*-----------------------------------------*/
#pragma once
#include "RGBController.h"
#include "NZXTMouseController.h"
class RGBController_NZXTMouse : public RGBController
{
public:
RGBController_NZXTMouse(NZXTMouseController* controller_ptr);
~RGBController_NZXTMouse();
void SetupZones();
void ResizeZone(int zone, int new_size);
void DeviceUpdateLEDs();
void UpdateZoneLEDs(int zone);
void UpdateSingleLED(int led);
void DeviceUpdateMode();
private:
NZXTMouseController* controller;
std::vector<unsigned int> leds_channel;
std::vector<unsigned int> zones_channel;
};