Skip to content

Commit

Permalink
Add serial implementation of HYTE CNVS mousemat controller for Window…
Browse files Browse the repository at this point in the history
…s and leave libusb implementation for Linux
  • Loading branch information
CalcProgrammer1 committed Oct 6, 2023
1 parent 1b7cff7 commit 0b787eb
Show file tree
Hide file tree
Showing 7 changed files with 198 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*---------------------------------------------------------*\
| HYTEMousematController.cpp |
| |
| Driver for HYTE CNVS RGB mousemat controller |
| |
| Adam Honse ([email protected]), 7/18/2023 |
\*---------------------------------------------------------*/

#include "HYTEMousematController.h"

HYTEMousematController::HYTEMousematController(char* port)
{
port_name = port;

/*-----------------------------------------------------*\
| Open the port |
| Baud rate doesn't matter for ACM device |
\*-----------------------------------------------------*/
serialport = new serial_port(port_name.c_str(), 2000000);
}

HYTEMousematController::~HYTEMousematController()
{

}

std::string HYTEMousematController::GetLocation()
{
return(port_name);
}

void HYTEMousematController::FirmwareAnimationControl(bool enabled)
{
unsigned char serial_buf[4];

/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(serial_buf, 0, sizeof(serial_buf));

/*-----------------------------------------------------*\
| Set up Firmware Animation Control packet |
\*-----------------------------------------------------*/
serial_buf[0] = 0xFF;
serial_buf[1] = 0xDC;
serial_buf[2] = 0x05;
serial_buf[3] = enabled;

/*-----------------------------------------------------*\
| Send packet |
\*-----------------------------------------------------*/
serialport->serial_write((char *)serial_buf, sizeof(serial_buf));
}

void HYTEMousematController::StreamingCommand(RGBColor* colors)
{
unsigned char serial_buf[157];
unsigned int max_brightness = 72;

/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(serial_buf, 0, sizeof(serial_buf));

/*-----------------------------------------------------*\
| Set up Streaming packet |
\*-----------------------------------------------------*/
serial_buf[0] = 0xFF;
serial_buf[1] = 0xEE;
serial_buf[2] = 0x02;
serial_buf[3] = 0x01;
serial_buf[4] = 0x00;
serial_buf[5] = 0x32;
serial_buf[6] = 0x00;

/*-----------------------------------------------------*\
| Copy in colors |
\*-----------------------------------------------------*/
for(unsigned int color_idx = 0; color_idx < 50; color_idx++)
{
serial_buf[7 + (color_idx * 3)] = ( max_brightness * RGBGetGValue(colors[color_idx]) ) / 100;
serial_buf[8 + (color_idx * 3)] = ( max_brightness * RGBGetRValue(colors[color_idx]) ) / 100;
serial_buf[9 + (color_idx * 3)] = ( max_brightness * RGBGetBValue(colors[color_idx]) ) / 100;
}

/*-----------------------------------------------------*\
| Send packet |
\*-----------------------------------------------------*/
serialport->serial_write((char *)serial_buf, sizeof(serial_buf));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*---------------------------------------------------------*\
| HYTEMousematController.h |
| |
| Definitions for HYTE CNVS RGB mousemat controller |
| |
| Adam Honse ([email protected]), 7/18/2023 |
\*---------------------------------------------------------*/

#pragma once

#include "RGBController.h"
#include "serial_port.h"
#include <vector>

class HYTEMousematController
{
public:
HYTEMousematController(char* port);
~HYTEMousematController();

std::string GetLocation();

void FirmwareAnimationControl(bool enabled);
void StreamingCommand(RGBColor* colors);

private:
std::string port_name;
serial_port * serialport = nullptr;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#include "Detector.h"
#include "HYTEMousematController.h"
#include "RGBController.h"
#include "RGBController_HYTEMousemat.h"
#include "find_usb_serial_port.h"
#include <vector>

#define HYTE_VID 0x3402

#define HYTE_CNVS_HW_VER_1_PID 0x0B00
#define HYTE_CNVS_HW_VER_2_PID 0x0B01

struct hyte_mousemat_type
{
unsigned short vid;
unsigned short pid;
const char * name;
};

#define HYTE_MOUSEMAT_NUM_DEVICES 2

static const hyte_mousemat_type hyte_mousemat_devices[] =
{
{ HYTE_VID, HYTE_CNVS_HW_VER_1_PID, "HYTE CNVS" },
{ HYTE_VID, HYTE_CNVS_HW_VER_2_PID, "HYTE CNVS" },
};

/******************************************************************************************\
* *
* DetectHYTEMousematControllers *
* *
* Detect devices supported by the HyteMousemat driver *
* *
\******************************************************************************************/

void DetectHYTEMousematControllers()
{
for(unsigned int device_id = 0; device_id < HYTE_MOUSEMAT_NUM_DEVICES; device_id++)
{
std::vector<std::string *> ports = find_usb_serial_port(hyte_mousemat_devices[device_id].vid, hyte_mousemat_devices[device_id].pid);

for(unsigned int i = 0; i < ports.size(); i++)
{
if(*ports[i] != "")
{
HYTEMousematController * controller = new HYTEMousematController((char *)ports[i]->c_str());
RGBController_HYTEMousemat * rgb_controller = new RGBController_HYTEMousemat(controller);
rgb_controller->name = hyte_mousemat_devices[device_id].name;

ResourceManager::get()->RegisterRGBController(rgb_controller);
}
}
}
} /* DetectHYTEMousematControllers() */

REGISTER_DETECTOR("HYTE Mousemat", DetectHYTEMousematControllers);
/*---------------------------------------------------------------------------------------------------------*\
| Entries for dynamic UDEV rules |
| |
| DUMMY_DEVICE_DETECTOR("HYTE Mousemat", DetectHYTEMousematControllers, 0x3402, 0x0B00 ) |
| DUMMY_DEVICE_DETECTOR("HYTE Mousemat", DetectHYTEMousematControllers, 0x3402, 0x0B01 ) |
\*---------------------------------------------------------------------------------------------------------*/
27 changes: 17 additions & 10 deletions OpenRGB.pro
Original file line number Diff line number Diff line change
Expand Up @@ -564,8 +564,6 @@ HEADERS +=
Controllers/HyperXMouseController/RGBController_HyperXPulsefireRaid.h \
Controllers/HyperXMousematController/HyperXMousematController.h \
Controllers/HyperXMousematController/RGBController_HyperXMousemat.h \
Controllers/HYTEMousematController/HYTEMousematController.h \
Controllers/HYTEMousematController/RGBController_HYTEMousemat.h \
Controllers/IntelArcA770LEController/IntelArcA770LEController.h \
Controllers/IntelArcA770LEController/RGBController_IntelArcA770LE.h \
Controllers/IonicoController/IonicoController.h \
Expand Down Expand Up @@ -1239,9 +1237,6 @@ SOURCES +=
Controllers/HyperXMousematController/HyperXMousematController.cpp \
Controllers/HyperXMousematController/HyperXMousematControllerDetect.cpp \
Controllers/HyperXMousematController/RGBController_HyperXMousemat.cpp \
Controllers/HYTEMousematController/HYTEMousematController.cpp \
Controllers/HYTEMousematController/HYTEMousematControllerDetect.cpp \
Controllers/HYTEMousematController/RGBController_HYTEMousemat.cpp \
Controllers/IntelArcA770LEController/IntelArcA770LEController.cpp \
Controllers/IntelArcA770LEController/IntelArcA770LEControllerDetect.cpp \
Controllers/IonicoController/IonicoController.cpp \
Expand Down Expand Up @@ -1630,6 +1625,7 @@ win32:INCLUDEPATH +=
dependencies/openrazer-win32 \
wmi/ \
Controllers/AsusTUFLaptopController \
Controllers/HYTEMousematController/HYTEMousematController_serial \
Controllers/NVIDIAIlluminationController \

win32:SOURCES += \
Expand Down Expand Up @@ -1734,6 +1730,9 @@ win32:SOURCES +=
Controllers/AsusTUFLaptopController/RGBController_AsusTUFLaptopWMI.cpp \
Controllers/ENESMBusController/XPGSpectrixS40GDetect_Windows.cpp \
Controllers/ENESMBusController/ENESMBusInterface/ENESMBusInterface_SpectrixS40G_Windows.cpp \
Controllers/HYTEMousematController/HYTEMousematController_serial/HYTEMousematController.cpp \
Controllers/HYTEMousematController/HYTEMousematController_serial/HYTEMousematControllerDetect.cpp \
Controllers/HYTEMousematController/RGBController_HYTEMousemat.cpp \
Controllers/NVIDIAIlluminationController/nvapi_accessor.cpp \
Controllers/NVIDIAIlluminationController/NVIDIAIlluminationV1Controller.cpp \
Controllers/NVIDIAIlluminationController/NVIDIAIlluminationControllerDetect.cpp \
Expand All @@ -1756,6 +1755,8 @@ win32:HEADERS +=
Controllers/AsusTUFLaptopController/AsusTUFLaptopController.h \
Controllers/AsusTUFLaptopController/RGBController_AsusTUFLaptopWMI.h \
Controllers/ENESMBusController/ENESMBusInterface/ENESMBusInterface_SpectrixS40G_Windows.h \
Controllers/HYTEMousematController/HYTEMousematController_serial/HYTEMousematController.h \
Controllers/HYTEMousematController/RGBController_HYTEMousemat.h \
Controllers/NVIDIAIlluminationController/nvapi_accessor.h \
Controllers/NVIDIAIlluminationController/NVIDIAIlluminationV1Controller.h \
Controllers/NVIDIAIlluminationController/RGBController_NVIDIAIllumination.h \
Expand Down Expand Up @@ -1847,15 +1848,18 @@ contains(QMAKE_PLATFORM, linux) {

INCLUDEPATH += \
Controllers/FaustusController \
Controllers/HYTEMousematController/HYTEMousematController_libusb \
Controllers/LinuxLEDController \

HEADERS += \
i2c_smbus/i2c_smbus_linux.h \
AutoStart/AutoStart-Linux.h \
Controllers/AsusTUFLaptopController/AsusTUFLaptopLinuxController.h \
Controllers/AsusTUFLaptopController/RGBController_AsusTUFLaptopLinux.h \
Controllers/AsusTUFLaptopController/AsusTUFLaptopLinuxController.h \
Controllers/AsusTUFLaptopController/RGBController_AsusTUFLaptopLinux.h \
Controllers/ENESMBusController/ENESMBusInterface/ENESMBusInterface_SpectrixS40G.h \
Controllers/FaustusController/RGBController_Faustus.h \
Controllers/HYTEMousematController/HYTEMousematController_libusb/HYTEMousematController.h \
Controllers/HYTEMousematController/RGBController_HYTEMousemat.h \
Controllers/LinuxLEDController/LinuxLEDController.h \
Controllers/LinuxLEDController/RGBController_LinuxLED.h \
Controllers/OpenRazerController/RGBController_OpenRazer.h \
Expand Down Expand Up @@ -1903,12 +1907,15 @@ contains(QMAKE_PLATFORM, linux) {
scsiapi/scsiapi_linux.c \
serial_port/find_usb_serial_port_linux.cpp \
AutoStart/AutoStart-Linux.cpp \
Controllers/AsusTUFLaptopController/AsusTUFLaptopLinuxController.cpp \
Controllers/AsusTUFLaptopController/AsusTUFLaptopLinuxDetect.cpp \
Controllers/AsusTUFLaptopController/RGBController_AsusTUFLaptopLinux.cpp \
Controllers/AsusTUFLaptopController/AsusTUFLaptopLinuxController.cpp \
Controllers/AsusTUFLaptopController/AsusTUFLaptopLinuxDetect.cpp \
Controllers/AsusTUFLaptopController/RGBController_AsusTUFLaptopLinux.cpp \
Controllers/ENESMBusController/XPGSpectrixS40GDetect.cpp \
Controllers/ENESMBusController/ENESMBusInterface/ENESMBusInterface_SpectrixS40G.cpp \
Controllers/FaustusController/RGBController_Faustus.cpp \
Controllers/HYTEMousematController/HYTEMousematController_libusb/HYTEMousematController.cpp \
Controllers/HYTEMousematController/HYTEMousematController_libusb/HYTEMousematControllerDetect.cpp \
Controllers/HYTEMousematController/RGBController_HYTEMousemat.cpp \
Controllers/LinuxLEDController/LinuxLEDController.cpp \
Controllers/LinuxLEDController/LinuxLEDControllerDetect.cpp \
Controllers/LinuxLEDController/RGBController_LinuxLED.cpp \
Expand Down

0 comments on commit 0b787eb

Please sign in to comment.