Initial controller for Tecknet mice
This commit is contained in:
parent
c15ceaa26c
commit
8168e1cadb
6 changed files with 436 additions and 0 deletions
96
Controllers/TecknetController/TecknetController.cpp
Normal file
96
Controllers/TecknetController/TecknetController.cpp
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
/*-------------------------------------------------------------------*\
|
||||
| TecknetController.cpp |
|
||||
| |
|
||||
| Driver for Technet Devices |
|
||||
| |
|
||||
| Chris M (Dr_No) 29th Jul 2020 |
|
||||
| |
|
||||
\*-------------------------------------------------------------------*/
|
||||
|
||||
#include "TecknetController.h"
|
||||
|
||||
TecknetController::TecknetController(hid_device* dev_handle, char *_path)
|
||||
{
|
||||
const int szTemp = 256;
|
||||
wchar_t tmpName[szTemp];
|
||||
|
||||
dev = dev_handle;
|
||||
|
||||
hid_get_manufacturer_string(dev, tmpName, szTemp);
|
||||
std::wstring wName = std::wstring(tmpName);
|
||||
device_name = std::string(wName.begin(), wName.end());
|
||||
|
||||
hid_get_product_string(dev, tmpName, szTemp);
|
||||
wName = std::wstring(tmpName);
|
||||
device_name.append(" ").append(std::string(wName.begin(), wName.end()));
|
||||
|
||||
hid_get_serial_number_string(dev, tmpName, szTemp);
|
||||
wName = std::wstring(tmpName);
|
||||
serial = std::string(wName.begin(), wName.end());
|
||||
|
||||
location = _path;
|
||||
|
||||
current_mode = TECKNET_MODE_STATIC;
|
||||
current_speed = TECKNET_SPEED_NORMAL;
|
||||
current_brightness = TECKNET_BRIGHTNESS_HIGH;
|
||||
}
|
||||
|
||||
TecknetController::~TecknetController()
|
||||
{
|
||||
hid_close(dev);
|
||||
}
|
||||
|
||||
std::string TecknetController::GetDeviceName()
|
||||
{
|
||||
return device_name;
|
||||
}
|
||||
|
||||
std::string TecknetController::GetSerial()
|
||||
{
|
||||
return serial;
|
||||
}
|
||||
|
||||
std::string TecknetController::GetLocation()
|
||||
{
|
||||
return location;
|
||||
}
|
||||
|
||||
void TecknetController::SetMode(unsigned char mode, unsigned char speed, unsigned char brightness)
|
||||
{
|
||||
current_mode = mode;
|
||||
current_speed = speed;
|
||||
current_brightness = brightness;
|
||||
|
||||
SendUpdate();
|
||||
}
|
||||
|
||||
void TecknetController::SetColor(unsigned char red, unsigned char green, unsigned char blue)
|
||||
{
|
||||
//The Tecknet mouse expects inverted colours in sent packets
|
||||
current_red = 255 - red;
|
||||
current_green = 255 - green;
|
||||
current_blue = 255 - blue;
|
||||
|
||||
SendUpdate();
|
||||
}
|
||||
|
||||
void TecknetController::SendUpdate()
|
||||
{
|
||||
unsigned char buffer[TECKNET_PACKET_LENGTH] = { 0x00 };
|
||||
int buffer_size = (sizeof(buffer) / sizeof(buffer[0]));
|
||||
|
||||
for(int i = 0; i < TECKNET_COLOUR_MODE_DATA_SIZE; i++)
|
||||
{
|
||||
buffer[i] = tecknet_colour_mode_data[current_mode][i];
|
||||
}
|
||||
|
||||
//Set the relevant colour info
|
||||
buffer[TECKNET_RED_BYTE] = current_red;
|
||||
buffer[TECKNET_GREEN_BYTE] = current_green;
|
||||
buffer[TECKNET_BLUE_BYTE] = current_blue;
|
||||
buffer[TECKNET_BRIGHTNESS_BYTE] = current_brightness;
|
||||
buffer[TECKNET_SPEED_BYTE] = tecknet_speed_mode_data[current_mode][current_speed];
|
||||
|
||||
hid_send_feature_report(dev, buffer, buffer_size);
|
||||
}
|
||||
|
||||
94
Controllers/TecknetController/TecknetController.h
Normal file
94
Controllers/TecknetController/TecknetController.h
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
/*-------------------------------------------------------------------*\
|
||||
| TecknetController.h |
|
||||
| |
|
||||
| Driver for Tecknet Devices |
|
||||
| |
|
||||
| Chris M (Dr_No) 29th Jul 2020 |
|
||||
| |
|
||||
\*-------------------------------------------------------------------*/
|
||||
|
||||
#ifndef TECKNETCONTROLLER_H
|
||||
#define TECKNETCONTROLLER_H
|
||||
|
||||
#include <string>
|
||||
#include <hidapi/hidapi.h>
|
||||
|
||||
#define TECKNET_COLOUR_MODE_DATA_SIZE (sizeof(tecknet_colour_mode_data[0]) / sizeof(tecknet_colour_mode_data[0][0]))
|
||||
#define TECKNET_DEVICE_NAME_SIZE (sizeof(device_name) / sizeof(device_name[ 0 ]))
|
||||
#define TECKNET_PACKET_LENGTH 0x10 //16 bytes
|
||||
|
||||
enum
|
||||
{
|
||||
TECKNET_RED_BYTE = 2,
|
||||
TECKNET_GREEN_BYTE = 3,
|
||||
TECKNET_BLUE_BYTE = 4,
|
||||
TECKNET_BRIGHTNESS_BYTE = 5,
|
||||
TECKNET_SPEED_BYTE = 6
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
TECKNET_MODE_OFF = 0xFF, //LEDs Off
|
||||
TECKNET_MODE_STATIC = 0x00, //Static Mode
|
||||
TECKNET_MODE_BREATHING = 0x01, //Breathing Mode
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
TECKNET_BRIGHTNESS_OFF = 0x00,
|
||||
TECKNET_BRIGHTNESS_LOW = 0x01,
|
||||
TECKNET_BRIGHTNESS_MED = 0x02,
|
||||
TECKNET_BRIGHTNESS_HIGH = 0x03
|
||||
};
|
||||
|
||||
static unsigned char tecknet_colour_mode_data[][16] =
|
||||
{
|
||||
{ 0x02, 0x04, 0x00, 0x00, 0x00, 0x03, 0x00 }, // Static
|
||||
{ 0x02, 0x04, 0x00, 0x00, 0x00, 0x03, 0x00 }, // Breathing
|
||||
};
|
||||
|
||||
static unsigned char tecknet_speed_mode_data[][9] =
|
||||
{
|
||||
{ 0x00, 0x00, 0x00, 0x00 }, // Static
|
||||
{ 0x00, 0x06, 0x03, 0x01 }, // Breathing
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
TECKNET_SPEED_OFF = 0x00, // Breathe Off
|
||||
TECKNET_SPEED_SLOW = 0x01, // Breathe Slow speed
|
||||
TECKNET_SPEED_NORMAL = 0x02, // Breathe Normal speed
|
||||
TECKNET_SPEED_FAST = 0x03, // Breathe Fast speed
|
||||
};
|
||||
|
||||
class TecknetController
|
||||
{
|
||||
public:
|
||||
TecknetController(hid_device *dev_handle, char *_path);
|
||||
~TecknetController();
|
||||
|
||||
std::string GetDeviceName();
|
||||
std::string GetSerial();
|
||||
std::string GetLocation();
|
||||
|
||||
void SetMode(unsigned char mode, unsigned char speed, unsigned char brightness);
|
||||
void SetColor(unsigned char red, unsigned char green, unsigned char blue);
|
||||
|
||||
private:
|
||||
std::string device_name;
|
||||
std::string serial;
|
||||
std::string location;
|
||||
hid_device* dev;
|
||||
|
||||
unsigned char current_mode;
|
||||
unsigned char current_speed;
|
||||
unsigned char current_brightness;
|
||||
|
||||
unsigned char current_red;
|
||||
unsigned char current_green;
|
||||
unsigned char current_blue;
|
||||
|
||||
void SendUpdate();
|
||||
};
|
||||
|
||||
#endif // TECKNETCONTROLLER_H
|
||||
87
Controllers/TecknetController/TecknetControllerDetect.cpp
Normal file
87
Controllers/TecknetController/TecknetControllerDetect.cpp
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
/*-------------------------------------------------------------------*\
|
||||
| TecknetControllerDetect.cpp |
|
||||
| |
|
||||
| Driver for Tecknet Devices |
|
||||
| |
|
||||
| Chris M (Dr_No) 29th Jul 2020 |
|
||||
| |
|
||||
\*-------------------------------------------------------------------*/
|
||||
|
||||
#include "Detector.h"
|
||||
#include "TecknetController.h"
|
||||
#include "RGBController.h"
|
||||
#include "RGBController_Tecknet.h"
|
||||
#include <hidapi/hidapi.h>
|
||||
|
||||
#define TECKNET_VID 0x04D9
|
||||
|
||||
#define TECKNET_M0008_PID 0xFC05
|
||||
#define TECKNET_M0008_U 0x01 //Usage 01
|
||||
#define TECKNET_M0008_UPG 0xFFA0 //Vendor Defined Usage Page
|
||||
|
||||
#define TECKNET_NUM_DEVICES (sizeof(tecknet_pids) / sizeof(tecknet_pids[ 0 ]))
|
||||
|
||||
enum
|
||||
{
|
||||
TECKNET_PID = 0,
|
||||
TECKNET_INTERFACE = 1,
|
||||
TECKNET_USAGE = 2,
|
||||
TECKNET_USAGE_PAGE = 3
|
||||
};
|
||||
|
||||
static const unsigned int tecknet_pids[][4] =
|
||||
{ // PID, Interface, Usage, Usage_Page
|
||||
{ TECKNET_M0008_PID, 0, TECKNET_M0008_U, TECKNET_M0008_UPG } //Tecknet M008 Mouse
|
||||
};
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* DetectTecknetControllers *
|
||||
* *
|
||||
* Tests the USB address to see if any Tecknet Controllers. *
|
||||
* *
|
||||
\******************************************************************************************/
|
||||
|
||||
void DetectTecknetControllers(std::vector<RGBController*>& rgb_controllers)
|
||||
{
|
||||
hid_device_info* info;
|
||||
|
||||
//Look for the passed in tecknet_pids
|
||||
hid_init();
|
||||
info = hid_enumerate(TECKNET_VID, 0x0);
|
||||
|
||||
while(info)
|
||||
{
|
||||
hid_device* dev = NULL;
|
||||
if(info->vendor_id == TECKNET_VID)
|
||||
{
|
||||
for(int pid_idx = 0; pid_idx < TECKNET_NUM_DEVICES; pid_idx++)
|
||||
{
|
||||
if((info->vendor_id == TECKNET_VID)
|
||||
#ifdef USE_HID_USAGE
|
||||
&&(info->usage == tecknet_pids[pid_idx][TECKNET_USAGE])
|
||||
&&(info->usage_page == tecknet_pids[pid_idx][TECKNET_USAGE_PAGE])
|
||||
&&(info->product_id == tecknet_pids[pid_idx][TECKNET_PID]))
|
||||
#else
|
||||
&&(info->interface_number == tecknet_pids[pid_idx][TECKNET_INTERFACE]) //Interface is only valid on Windows where there is > 1 interface
|
||||
&&(info->product_id == tecknet_pids[pid_idx][TECKNET_PID]))
|
||||
#endif
|
||||
{
|
||||
dev = hid_open_path(info->path);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(dev)
|
||||
{
|
||||
TecknetController* controller = new TecknetController(dev, info->path);
|
||||
RGBController_Tecknet* rgb_controller = new RGBController_Tecknet(controller);
|
||||
rgb_controllers.push_back(rgb_controller);
|
||||
}
|
||||
info = info->next;
|
||||
}
|
||||
hid_free_enumeration(info);
|
||||
} /* DetectTecknetControllers) */
|
||||
|
||||
REGISTER_DETECTOR(DetectTecknetControllers);
|
||||
|
|
@ -85,6 +85,7 @@ INCLUDEPATH += \
|
|||
Controllers/RGBFusionGPUController/ \
|
||||
Controllers/SapphireGPUController/ \
|
||||
Controllers/SteelSeriesController/ \
|
||||
Controllers/TecknetController/ \
|
||||
Controllers/ThermaltakeRiingController/ \
|
||||
RGBController/ \
|
||||
qt/
|
||||
|
|
@ -163,6 +164,7 @@ HEADERS += \
|
|||
Controllers/SteelSeriesController/SteelSeriesRivalController.h \
|
||||
Controllers/SteelSeriesController/SteelSeriesSiberiaController.h \
|
||||
Controllers/SteelSeriesController/SteelSeriesApexController.h \
|
||||
Controllers/TecknetController/TecknetController.h \
|
||||
Controllers/ThermaltakeRiingController/ThermaltakeRiingController.h \
|
||||
RGBController/RGBController.h \
|
||||
RGBController/RGBController_AMDWraithPrism.h \
|
||||
|
|
@ -216,6 +218,7 @@ HEADERS += \
|
|||
RGBController/RGBController_SteelSeriesRival.h \
|
||||
RGBController/RGBController_SteelSeriesSiberia.h \
|
||||
RGBController/RGBController_SteelSeriesApex.h \
|
||||
RGBController/RGBController_Tecknet.h \
|
||||
RGBController/RGBController_ThermaltakeRiing.h \
|
||||
|
||||
SOURCES += \
|
||||
|
|
@ -333,6 +336,8 @@ SOURCES += \
|
|||
Controllers/SteelSeriesController/SteelSeriesSiberiaController.cpp \
|
||||
Controllers/SteelSeriesController/SteelSeriesApexController.cpp \
|
||||
Controllers/SteelSeriesController/SteelSeriesControllerDetect.cpp \
|
||||
Controllers/TecknetController/TecknetController.cpp \
|
||||
Controllers/TecknetController/TecknetControllerDetect.cpp \
|
||||
Controllers/ThermaltakeRiingController/ThermaltakeRiingController.cpp \
|
||||
Controllers/ThermaltakeRiingController/ThermaltakeRiingControllerDetect.cpp \
|
||||
RGBController/RGBController.cpp \
|
||||
|
|
@ -387,6 +392,7 @@ SOURCES += \
|
|||
RGBController/RGBController_SteelSeriesRival.cpp \
|
||||
RGBController/RGBController_SteelSeriesSiberia.cpp \
|
||||
RGBController/RGBController_SteelSeriesApex.cpp \
|
||||
RGBController/RGBController_Tecknet.cpp \
|
||||
RGBController/RGBController_ThermaltakeRiing.cpp \
|
||||
|
||||
RESOURCES += \
|
||||
|
|
|
|||
118
RGBController/RGBController_Tecknet.cpp
Normal file
118
RGBController/RGBController_Tecknet.cpp
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
/*-------------------------------------------------------------------*\
|
||||
| RGBController_Tecknet.cpp |
|
||||
| |
|
||||
| Driver for Tecknet Devices |
|
||||
| |
|
||||
| Chris M (Dr_No) 29th Jul 2020 |
|
||||
| |
|
||||
\*-------------------------------------------------------------------*/
|
||||
|
||||
#include "RGBController_Tecknet.h"
|
||||
|
||||
RGBController_Tecknet::RGBController_Tecknet(TecknetController *_dev)
|
||||
{
|
||||
Tecknet_dev = _dev;
|
||||
|
||||
name = Tecknet_dev->GetDeviceName();
|
||||
type = DEVICE_TYPE_MOUSE;
|
||||
description = Tecknet_dev->GetDeviceName();
|
||||
version = "1.0";
|
||||
serial = Tecknet_dev->GetSerial();
|
||||
location = Tecknet_dev->GetLocation();
|
||||
|
||||
mode Off;
|
||||
Off.name = "Off";
|
||||
Off.value = TECKNET_MODE_OFF;
|
||||
Off.color_mode = MODE_COLORS_NONE;
|
||||
Off.speed_min = TECKNET_SPEED_OFF;
|
||||
Off.speed_max = TECKNET_SPEED_OFF;
|
||||
Off.speed = TECKNET_SPEED_OFF;
|
||||
modes.push_back(Off);
|
||||
|
||||
mode Static;
|
||||
Static.name = "Static";
|
||||
Static.value = TECKNET_MODE_STATIC;
|
||||
Static.flags = MODE_FLAG_HAS_PER_LED_COLOR | MODE_FLAG_HAS_BRIGHTNESS;
|
||||
Static.color_mode = MODE_COLORS_PER_LED;
|
||||
Static.speed_min = TECKNET_SPEED_OFF;
|
||||
Static.speed_max = TECKNET_SPEED_OFF;
|
||||
Static.speed = TECKNET_SPEED_OFF;
|
||||
modes.push_back(Static);
|
||||
|
||||
mode Breathing;
|
||||
Breathing.name = "Breathing";
|
||||
Breathing.value = TECKNET_MODE_BREATHING;
|
||||
Breathing.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_PER_LED_COLOR | MODE_FLAG_HAS_BRIGHTNESS;
|
||||
Breathing.speed_min = TECKNET_SPEED_SLOW;
|
||||
Breathing.speed_max = TECKNET_SPEED_FAST;
|
||||
Breathing.color_mode = MODE_COLORS_PER_LED;
|
||||
Breathing.speed = TECKNET_SPEED_NORMAL;
|
||||
modes.push_back(Breathing);
|
||||
|
||||
SetupZones();
|
||||
}
|
||||
|
||||
RGBController_Tecknet::~RGBController_Tecknet()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void RGBController_Tecknet::SetupZones()
|
||||
{
|
||||
zone Tecknet_zone;
|
||||
Tecknet_zone.name = "Tecknet Logo";
|
||||
Tecknet_zone.type = ZONE_TYPE_SINGLE;
|
||||
Tecknet_zone.leds_min = 1;
|
||||
Tecknet_zone.leds_max = 1;
|
||||
Tecknet_zone.leds_count = 1;
|
||||
Tecknet_zone.matrix_map = NULL;
|
||||
zones.push_back(Tecknet_zone);
|
||||
|
||||
led Tecknet_led;
|
||||
Tecknet_led.name = "Logo LED";
|
||||
leds.push_back(Tecknet_led);
|
||||
|
||||
SetupColors();
|
||||
}
|
||||
|
||||
void RGBController_Tecknet::ResizeZone(int /*zone*/, int /*new_size*/)
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| Not implemented for thiis device |
|
||||
\*---------------------------------------------------------*/
|
||||
}
|
||||
|
||||
void RGBController_Tecknet::DeviceUpdateLEDs()
|
||||
{
|
||||
unsigned char red = RGBGetRValue(colors[0]);
|
||||
unsigned char grn = RGBGetGValue(colors[0]);
|
||||
unsigned char blu = RGBGetBValue(colors[0]);
|
||||
Tecknet_dev->SetColor(red, grn, blu);
|
||||
}
|
||||
|
||||
void RGBController_Tecknet::UpdateZoneLEDs(int zone)
|
||||
{
|
||||
RGBColor color = colors[zone];
|
||||
unsigned char red = RGBGetRValue(color);
|
||||
unsigned char grn = RGBGetGValue(color);
|
||||
unsigned char blu = RGBGetBValue(color);
|
||||
Tecknet_dev->SetColor(red, grn, blu);
|
||||
}
|
||||
|
||||
void RGBController_Tecknet::UpdateSingleLED(int led)
|
||||
{
|
||||
UpdateZoneLEDs(led);
|
||||
}
|
||||
|
||||
void RGBController_Tecknet::SetCustomMode()
|
||||
{
|
||||
active_mode = 0;
|
||||
}
|
||||
|
||||
void RGBController_Tecknet::DeviceUpdateMode()
|
||||
{
|
||||
//If active_mode is "Off" then set brightness to off otherwise high
|
||||
unsigned char brightness = (active_mode == TECKNET_MODE_OFF) ? TECKNET_BRIGHTNESS_OFF : TECKNET_BRIGHTNESS_HIGH;
|
||||
|
||||
Tecknet_dev->SetMode(modes[active_mode].value, modes[active_mode].speed, brightness);
|
||||
}
|
||||
35
RGBController/RGBController_Tecknet.h
Normal file
35
RGBController/RGBController_Tecknet.h
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/*-------------------------------------------------------------------*\
|
||||
| RGBController_Tecknet.h |
|
||||
| |
|
||||
| Driver for Tecknet Devices |
|
||||
| |
|
||||
| Chris M (Dr_No) 29th Jul 2020 |
|
||||
| |
|
||||
\*-------------------------------------------------------------------*/
|
||||
|
||||
#ifndef RGBCONTROLLER_TECKNET_H
|
||||
#define RGBCONTROLLER_TECKNET_H
|
||||
|
||||
#include "RGBController.h"
|
||||
#include "TecknetController.h"
|
||||
|
||||
class RGBController_Tecknet : public RGBController
|
||||
{
|
||||
public:
|
||||
RGBController_Tecknet(TecknetController *_dev);
|
||||
~RGBController_Tecknet();
|
||||
|
||||
void SetupZones();
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
void SetCustomMode();
|
||||
void DeviceUpdateMode();
|
||||
private:
|
||||
TecknetController* Tecknet_dev;
|
||||
};
|
||||
|
||||
#endif // RGBCONTROLLER_TECKNET_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue