Initial commit for the EK Loop Connect Support

* Implemented Static & Breathing modes
This commit is contained in:
Chris 2020-07-16 10:33:01 +10:00 committed by Adam Honse
parent 607d83b795
commit 95ded7b871
8 changed files with 402 additions and 1 deletions

View file

@ -0,0 +1,88 @@
/*-------------------------------------------------------------------*\
| EKController.cpp |
| |
| Driver for EK Loop Connect |
| |
| Chris M (Dr_No) 16th Jul 2020 |
| |
\*-------------------------------------------------------------------*/
#include "EKController.h"
EKController::EKController(hid_device* dev_handle, wchar_t *_vendor, wchar_t *_device_name, char *_path)
{
int tmp_size = wcslen(_vendor);
dev = dev_handle;
for(int i=0; (i < tmp_size) && (i < EK_DEVICE_NAME_SIZE); i++)
{
device_name[i] = (char)_vendor[i];
}
for(int j=0; (j < wcslen(_vendor)) && ((tmp_size + j) < EK_DEVICE_NAME_SIZE); j++)
{
device_name[tmp_size+j] = (char)_device_name[j];
}
location = _path;
current_mode = EK_MODE_STATIC;
current_speed = EK_SPEED_NORMAL;
}
EKController::~EKController()
{
hid_close(dev);
}
char* EKController::GetDeviceName()
{
return device_name;
}
char* EKController::GetSerial()
{
return serial;
}
std::string EKController::GetLocation()
{
return location;
}
void EKController::SetMode(unsigned char mode, unsigned char speed)
{
current_mode = mode;
current_speed = speed;
SendUpdate();
}
void EKController::SetColor(unsigned char red, unsigned char green, unsigned char blue)
{
current_red = red;
current_green = green;
current_blue = blue;
SendUpdate();
}
void EKController::SendUpdate()
{
unsigned char buffer[EK_PACKET_LENGTH] = { 0x00 };
int buffer_size = (sizeof(buffer) / sizeof(buffer[0]));
for(int i = 0; i < EK_COLOUR_MODE_DATA_SIZE; i++)
{
buffer[i] = 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];
hid_write(dev, buffer, buffer_size);
}

View file

@ -0,0 +1,103 @@
/*-------------------------------------------------------------------*\
| EKController.h |
| |
| Driver for EK Loop Connect |
| |
| Chris M (Dr_No) 16th Jul 2020 |
| |
\*-------------------------------------------------------------------*/
#ifndef EKCONTROLLER_H
#define EKCONTROLLER_H
#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_DEVICE_NAME_SIZE (sizeof(device_name) / sizeof(device_name[ 0 ]))
#define EK_PACKET_LENGTH 0x3F
enum
{
EK_MODE_BYTE = 12,
EK_SPEED_BYTE = 14,
EK_RED_BYTE = 16,
EK_GREEN_BYTE = 17,
EK_BLUE_BYTE = 18
};
enum
{
EK_MODE_STATIC = 0x00, //Static Mode
EK_MODE_BREATHING = 0x01, //Breathing Mode
EK_MODE_FADING = 0x02, //Fading Mode
EK_MODE_MARQUEE = 0x03, //Marquee Mode
EK_MODE_COVERING_MARQUEE = 0x04 //Covering Marquee Mode
};
static unsigned char colour_mode_data[][16] =
{
{ 0x10, 0x12, 0x29, 0xAA, 0x01, 0x10, 0xA2, 0x60,
0x00, 0x10, 0x20, 0x01, 0x01, 0x00, 0xFF, 0x64}, /* Static */
{ 0x10, 0x12, 0x29, 0xAA, 0x01, 0x10, 0xA2, 0x60,
0x00, 0x10, 0x20, 0x01, 0x02, 0x00, 0xFF, 0x64}, /* Breathing */
{ 0x10, 0x12, 0x29, 0xAA, 0x01, 0x10, 0xA2, 0x60,
0x00, 0x10, 0x20, 0x01, 0x03, 0x00, 0xFF, 0x64}, /* Fading */
{ 0x10, 0x12, 0x29, 0xAA, 0x01, 0x10, 0xA2, 0x60,
0x00, 0x10, 0x20, 0x01, 0x04, 0x00, 0xFF, 0x64}, /* Marquee */
{ 0x10, 0x12, 0x29, 0xAA, 0x01, 0x10, 0xA2, 0x60,
0x00, 0x10, 0x20, 0x01, 0x05, 0x00, 0xFF, 0x64}, /* Covering Marquee */
};
static unsigned char speed_mode_data[][9] =
{
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },// Static
{ 0x40, 0x38, 0x30, 0x28, 0x20, 0x18, 0x10, 0x08, 0x00 },// Breathing
{ 0x40, 0x38, 0x30, 0x28, 0x20, 0x18, 0x10, 0x08, 0x00 },// Fading
{ 0x40, 0x38, 0x30, 0x28, 0x20, 0x18, 0x10, 0x08, 0x00 },// Marquee
{ 0x40, 0x38, 0x30, 0x28, 0x20, 0x18, 0x10, 0x08, 0x00 } // Covering Marquee
};
enum
{
EK_SPEED_SLOWEST = 0x00, // Slowest speed
EK_SPEED_SLOWER = 0x01, // Slower speed
EK_SPEED_SLOW = 0x02, // Slow speed
EK_SPEED_SLOWISH = 0x03, // Slowish speed
EK_SPEED_NORMAL = 0x04, // Normal speed
EK_SPEED_FASTISH = 0x05, // Fastish speed
EK_SPEED_FAST = 0x06, // Fast speed
EK_SPEED_FASTER = 0x07, // Faster speed
EK_SPEED_FASTEST = 0x08, // Fastest speed
};
class EKController
{
public:
EKController(hid_device* dev_handle, wchar_t *_vendor, wchar_t *_device_name, char *_path);
~EKController();
char* GetDeviceName();
char* 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 location;
hid_device* dev;
unsigned char current_mode;
unsigned char current_speed;
unsigned char current_red;
unsigned char current_green;
unsigned char current_blue;
void SendUpdate();
};
#endif // EKCONTROLLER_H

View file

@ -0,0 +1,64 @@
#include "EKController.h"
#include "RGBController.h"
#include "RGBController_EKController.h"
#include <hidapi/hidapi.h>
#define EK_VID 0x0483
#define EK_LOOP_CONNECT 0x5750
#define EK_NUM_DEVICES (sizeof(ek_pids) / sizeof(ek_pids[ 0 ]))
enum
{
EK_PID = 0,
EK_INTERFACE = 1
};
static const unsigned int ek_pids[][2] =
{ // PID, Interface
{ EK_LOOP_CONNECT, 0x00 } //EK Loop Connect
};
/******************************************************************************************\
* *
* DetectEKControllers *
* *
* Tests the USB address to see if any EK Controllers exists there. *
* *
\******************************************************************************************/
void DetectEKControllers(std::vector<RGBController*>& rgb_controllers)
{
hid_device_info* info;
//Look for the passed in cm_pids
hid_init();
info = hid_enumerate(0x0, 0x0);
while(info)
{
hid_device* dev = NULL;
if(info->vendor_id == EK_VID)
{
for(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]))
{
dev = hid_open_path(info->path);
break;
}
}
}
if(dev)
{
EKController* controller = new EKController(dev, info->manufacturer_string, info->product_string, info->path);
RGBController_EKController* rgb_controller = new RGBController_EKController(controller);
rgb_controllers.push_back(rgb_controller);
}
info = info->next;
}
hid_free_enumeration(info);
}