EK Code cleanup
This commit is contained in:
parent
b35474d711
commit
5458692192
4 changed files with 47 additions and 40 deletions
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
#include "EKController.h"
|
||||
|
||||
static unsigned char colour_mode_data[][16] =
|
||||
static unsigned char ek_colour_mode_data[][16] =
|
||||
{
|
||||
{ 0x10, 0x12, 0x29, 0xAA, 0x01, 0x10, 0xA2, 0x60,
|
||||
0x00, 0x10, 0x20, 0x01, 0x01, 0x00, 0xFF, 0x64}, // Static
|
||||
|
|
@ -31,7 +31,7 @@ static unsigned char colour_mode_data[][16] =
|
|||
0x00, 0x10, 0x20, 0x01, 0x09, 0x00, 0xFF, 0x64}, // Candle
|
||||
};
|
||||
|
||||
static unsigned char speed_mode_data[][9] =
|
||||
static unsigned char ek_speed_mode_data[][9] =
|
||||
{
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // Static
|
||||
{ 0x00, 0x0C, 0x19, 0x25, 0x32, 0x3E, 0x4B, 0x57, 0x64 }, // Breathing
|
||||
|
|
@ -44,21 +44,24 @@ static unsigned char speed_mode_data[][9] =
|
|||
{ 0x00, 0x0C, 0x19, 0x25, 0x32, 0x3E, 0x4B, 0x57, 0x64 } // Candle
|
||||
};
|
||||
|
||||
EKController::EKController(hid_device* dev_handle, wchar_t *_vendor, wchar_t *_device_name, char *_path)
|
||||
EKController::EKController(hid_device* dev_handle, char *_path)
|
||||
{
|
||||
std::size_t tmp_size = wcslen(_vendor);
|
||||
const int szTemp = 256;
|
||||
wchar_t tmpName[szTemp];
|
||||
|
||||
dev = dev_handle;
|
||||
|
||||
for(std::size_t i = 0; (i < tmp_size) && (i < EK_DEVICE_NAME_SIZE); i++)
|
||||
{
|
||||
device_name[i] = (char)_vendor[i];
|
||||
}
|
||||
hid_get_manufacturer_string(dev, tmpName, szTemp);
|
||||
std::wstring wName = std::wstring(tmpName);
|
||||
device_name = std::string(wName.begin(), wName.end());
|
||||
|
||||
for(std::size_t j = 0; (j < wcslen(_vendor)) && ((tmp_size + j) < EK_DEVICE_NAME_SIZE); j++)
|
||||
{
|
||||
device_name[tmp_size + j] = (char)_device_name[j];
|
||||
}
|
||||
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;
|
||||
|
||||
|
|
@ -68,18 +71,15 @@ EKController::EKController(hid_device* dev_handle, wchar_t *_vendor, wchar_t *_d
|
|||
|
||||
EKController::~EKController()
|
||||
{
|
||||
if(dev)
|
||||
{
|
||||
hid_close(dev);
|
||||
}
|
||||
hid_close(dev);
|
||||
}
|
||||
|
||||
char* EKController::GetDeviceName()
|
||||
std::string EKController::GetDeviceName()
|
||||
{
|
||||
return device_name;
|
||||
}
|
||||
|
||||
char* EKController::GetSerial()
|
||||
std::string EKController::GetSerial()
|
||||
{
|
||||
return serial;
|
||||
}
|
||||
|
|
@ -113,14 +113,14 @@ void EKController::SendUpdate()
|
|||
|
||||
for(std::size_t i = 0; i < EK_COLOUR_MODE_DATA_SIZE; i++)
|
||||
{
|
||||
buffer[i] = colour_mode_data[current_mode][i];
|
||||
buffer[i] = ek_colour_mode_data[current_mode][i];
|
||||
}
|
||||
|
||||
//Set the relevant colour info
|
||||
buffer[EK_RED_BYTE] = current_red;
|
||||
buffer[EK_GREEN_BYTE] = current_green;
|
||||
buffer[EK_BLUE_BYTE] = current_blue;
|
||||
buffer[EK_SPEED_BYTE] = speed_mode_data[current_mode][current_speed];
|
||||
buffer[EK_SPEED_BYTE] = ek_speed_mode_data[current_mode][current_speed];
|
||||
|
||||
buffer[10] = 0x10;
|
||||
buffer[47] = 0xFF;
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
#include <string>
|
||||
#include <hidapi/hidapi.h>
|
||||
|
||||
#define EK_COLOUR_MODE_DATA_SIZE (sizeof(colour_mode_data[0]) / sizeof(colour_mode_data[0][0]))
|
||||
#define EK_COLOUR_MODE_DATA_SIZE (sizeof(ek_colour_mode_data[0]) / sizeof(ek_colour_mode_data[0][0]))
|
||||
#define EK_DEVICE_NAME_SIZE (sizeof(device_name) / sizeof(device_name[ 0 ]))
|
||||
#define EK_PACKET_LENGTH 0x3F
|
||||
|
||||
|
|
@ -55,19 +55,19 @@ enum
|
|||
class EKController
|
||||
{
|
||||
public:
|
||||
EKController(hid_device* dev_handle, wchar_t *_vendor, wchar_t *_device_name, char *_path);
|
||||
EKController(hid_device* dev_handle, char *_path);
|
||||
~EKController();
|
||||
|
||||
char* GetDeviceName();
|
||||
char* GetSerial();
|
||||
std::string GetDeviceName();
|
||||
std::string GetSerial();
|
||||
std::string GetLocation();
|
||||
|
||||
void SetMode(unsigned char mode, unsigned char speed);
|
||||
void SetColor(unsigned char red, unsigned char green, unsigned char blue);
|
||||
|
||||
private:
|
||||
char device_name[32];
|
||||
char serial[32];
|
||||
std::string device_name;
|
||||
std::string serial;
|
||||
std::string location;
|
||||
hid_device* dev;
|
||||
|
||||
|
|
|
|||
|
|
@ -4,21 +4,24 @@
|
|||
#include "RGBController_EKController.h"
|
||||
#include <hidapi/hidapi.h>
|
||||
|
||||
#define EK_VID 0x0483
|
||||
#define EK_VID 0x0483
|
||||
|
||||
#define EK_LOOP_CONNECT 0x5750
|
||||
#define EK_LOOP_CONNECT_PID 0x5750
|
||||
|
||||
#define EK_NUM_DEVICES (sizeof(ek_pids) / sizeof(ek_pids[ 0 ]))
|
||||
|
||||
enum
|
||||
struct ek_device
|
||||
{
|
||||
EK_PID = 0,
|
||||
EK_INTERFACE = 1
|
||||
unsigned int product_id;
|
||||
unsigned short interface;
|
||||
unsigned int usage_page;
|
||||
unsigned int usage;
|
||||
device_type type;
|
||||
};
|
||||
|
||||
static const unsigned int ek_pids[][2] =
|
||||
{ // PID, Interface
|
||||
{ EK_LOOP_CONNECT, 0x00 } //EK Loop Connect
|
||||
static const ek_device ek_pids[] =
|
||||
{ // PID, Interface, Usage_Page, Usage, Device_Type
|
||||
{ EK_LOOP_CONNECT_PID, 0x00, 0xFFA0, 0x01, DEVICE_TYPE_LEDSTRIP } //EK Loop Connect
|
||||
};
|
||||
|
||||
/******************************************************************************************\
|
||||
|
|
@ -33,9 +36,9 @@ void DetectEKControllers(std::vector<RGBController*>& rgb_controllers)
|
|||
{
|
||||
hid_device_info* info = NULL;
|
||||
|
||||
//Look for the passed in cm_pids
|
||||
//Look for the passed in ek_pids
|
||||
hid_init();
|
||||
info = hid_enumerate(EK_VID, 0x0);
|
||||
info = hid_enumerate(0, 0x0);
|
||||
|
||||
while(info)
|
||||
{
|
||||
|
|
@ -44,8 +47,13 @@ void DetectEKControllers(std::vector<RGBController*>& rgb_controllers)
|
|||
{
|
||||
for(unsigned int ek_pid_idx = 0; ek_pid_idx < EK_NUM_DEVICES; ek_pid_idx++)
|
||||
{
|
||||
if((info->product_id == ek_pids[ek_pid_idx][EK_PID])
|
||||
&&(info->interface_number == ek_pids[ek_pid_idx][EK_INTERFACE]))
|
||||
if((info->product_id == ek_pids[ek_pid_idx].product_id)
|
||||
#ifdef USE_HID_USAGE
|
||||
&&(info->usage == ek_pids[ek_pid_idx].usage) //Usage and usage page required to get the correct interface
|
||||
&&(info->usage_page == ek_pids[ek_pid_idx].usage_page))
|
||||
#else
|
||||
&&(info->interface_number == ek_pids[ek_pid_idx].interface))
|
||||
#endif //USE_HID_USAGE
|
||||
{
|
||||
dev = hid_open_path(info->path);
|
||||
break;
|
||||
|
|
@ -55,7 +63,7 @@ void DetectEKControllers(std::vector<RGBController*>& rgb_controllers)
|
|||
|
||||
if(dev)
|
||||
{
|
||||
EKController* controller = new EKController(dev, info->manufacturer_string, info->product_string, info->path);
|
||||
EKController* controller = new EKController(dev, info->path);
|
||||
RGBController_EKController* rgb_controller = new RGBController_EKController(controller);
|
||||
rgb_controllers.push_back(rgb_controller);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@
|
|||
| |
|
||||
\*-------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#include "RGBController_EKController.h"
|
||||
|
||||
RGBController_EKController::RGBController_EKController(EKController* _dev)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue