-
-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add serial implementation of HYTE CNVS mousemat controller for Window…
…s and leave libusb implementation for Linux
- Loading branch information
1 parent
1b7cff7
commit 0b787eb
Showing
7 changed files
with
198 additions
and
10 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
90 changes: 90 additions & 0 deletions
90
Controllers/HYTEMousematController/HYTEMousematController_serial/HYTEMousematController.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} |
29 changes: 29 additions & 0 deletions
29
Controllers/HYTEMousematController/HYTEMousematController_serial/HYTEMousematController.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
62 changes: 62 additions & 0 deletions
62
...ers/HYTEMousematController/HYTEMousematController_serial/HYTEMousematControllerDetect.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ) | | ||
\*---------------------------------------------------------------------------------------------------------*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters