Continued the work started by !62 with respect to adding support for Cooler Master keyboards using the libcmmk library.

Commits squashed and amended for code style by Adam Honse <calcprogrammer1@gmail.com>
This commit is contained in:
Tam Do 2021-04-23 05:59:05 -05:00 committed by Adam Honse
parent 7e4b9c0cb0
commit 7952a035b5
22 changed files with 2403 additions and 440 deletions

View file

@ -4,34 +4,33 @@
| Driver for Coolermaster MasterKeys Keyboards |
| |
| Lukas N (chmod222) 28th Jun 2020 |
| Tam D (too.manyhobbies) 25th Apr 2021 |
| |
\*-------------------------------------------------------------------*/
#include "CMMKController.h"
#include <locale>
#include <codecvt>
CMMKController::CMMKController(hid_device_info* _dev_info, wchar_t *_vendor, wchar_t *_device_name, char *_path)
CMMKController::CMMKController(hid_device* dev, hid_device_info* dev_info)
{
std::wstring tmp_vendor_str = _vendor;
std::wstring tmp_device_str = _device_name;
location = dev_info->path;
std::wstring full_name = _vendor + std::wstring{L" "} + _device_name;
const int szTemp = 256;
wchar_t tmpName[szTemp];
std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> converter;
hid_get_manufacturer_string(dev, tmpName, szTemp);
std::wstring wName = std::wstring(tmpName);
device_name = std::string(wName.begin(), wName.end());
device_name = converter.to_bytes(full_name);
hid_get_product_string(dev, tmpName, szTemp);
wName = std::wstring(tmpName);
device_name.append(" ").append(std::string(wName.begin(), wName.end()));
cmmk_attach_path(&cmmk_handle, _dev_info->path, _dev_info->product_id, -1);
cmmk_attach_path(&cmmk_handle, dev_info->path, dev_info->product_id, -1);
char buf[32] = {0};
cmmk_get_firmware_version(&cmmk_handle, buf, 32);
firmware_version = buf;
location = _path;
}
CMMKController::~CMMKController()
@ -39,17 +38,17 @@ CMMKController::~CMMKController()
cmmk_detach(&cmmk_handle);
}
std::string CMMKController::GetDeviceName() const
std::string CMMKController::GetDeviceName()
{
return device_name;
}
std::string CMMKController::GetLocation() const
std::string CMMKController::GetLocation()
{
return location;
}
std::string CMMKController::GetFirmwareVersion() const
std::string CMMKController::GetFirmwareVersion()
{
return firmware_version;
}
@ -133,14 +132,21 @@ void CMMKController::SetMode(cmmk_effect_stars eff)
cmmk_set_effect_stars(&cmmk_handle, &eff);
}
bool CMMKController::PositionValid(int y, int x) const
void CMMKController::SetMode(cmmk_effect_snake eff)
{
return cmmk_lookup_key_id(&cmmk_handle, y, x) >= 0;
ActivateEffect(CMMK_EFFECT_SNAKE);
cmmk_set_effect_snake(&cmmk_handle, &eff);
}
bool CMMKController::PositionValid(int y, int x)
{
return(cmmk_lookup_key_id(&cmmk_handle, y, x) >= 0);
}
void CMMKController::ActivateMode(int mode)
{
if (current_mode != mode) {
if (current_mode != mode)
{
cmmk_set_control_mode(&cmmk_handle, mode);
current_mode = mode;
@ -152,9 +158,10 @@ void CMMKController::ActivateEffect(int effect)
{
ActivateMode(CMMK_EFFECT);
if (current_effect != effect) {
if (current_effect != effect)
{
cmmk_set_active_effect(&cmmk_handle, (enum cmmk_effect_id)effect);
current_effect = effect;
}
}
}