Initial controller for Tecknet mice

This commit is contained in:
Chris 2020-08-05 21:31:58 -05:00 committed by Adam Honse
parent c15ceaa26c
commit 8168e1cadb
6 changed files with 436 additions and 0 deletions

View 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);
}

View 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

View 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);