From a35616326cb098d67d966b3eac1171ba8d6bf067 Mon Sep 17 00:00:00 2001 From: Tam D Date: Wed, 13 Dec 2023 02:41:35 +0000 Subject: [PATCH] Cooler Master Keyboard Controller v2 --- .../CMKeyboardAbstractController.cpp | 205 ++++ .../CMKeyboardAbstractController.h | 122 ++ .../CMKeyboardDevices.cpp | 768 ++++++++++++ .../CMKeyboardDevices.h | 120 ++ .../CMKeyboardV1Controller.cpp | 497 ++++++++ .../CMKeyboardV1Controller.h | 39 + .../CMKeyboardV2Controller.cpp | 1046 ++++++++++++++++ .../CMKeyboardV2Controller.h | 54 + .../CoolerMasterController/CMMKController.cpp | 320 ----- .../CoolerMasterController/CMMKController.h | 97 -- .../CoolerMasterControllerDetect.cpp | 102 +- .../RGBController_CMKeyboardController.cpp | 185 +++ .../RGBController_CMKeyboardController.h | 41 + .../RGBController_CMMKController.cpp | 503 -------- .../RGBController_CMMKController.h | 46 - OpenRGB.pro | 28 +- README.md | 4 +- .../libcmmk/include/libcmmk/libcmmk.h | 426 ------- dependencies/libcmmk/src/libcmmk.c | 1080 ----------------- .../libcmmk/src/mappings/ansi/mk750.h | 25 - .../libcmmk/src/mappings/ansi/pro_l.h | 44 - .../libcmmk/src/mappings/ansi/pro_s.h | 43 - .../libcmmk/src/mappings/ansi/sk630.h | 44 - .../libcmmk/src/mappings/ansi/sk650.h | 25 - dependencies/libcmmk/src/mappings/iso/mk750.h | 45 - dependencies/libcmmk/src/mappings/iso/pro_l.h | 44 - dependencies/libcmmk/src/mappings/iso/pro_s.h | 37 - dependencies/libcmmk/src/mappings/iso/sk630.h | 44 - dependencies/libcmmk/src/mappings/iso/sk650.h | 44 - 29 files changed, 3174 insertions(+), 2904 deletions(-) create mode 100644 Controllers/CoolerMasterController/CMKeyboardAbstractController.cpp create mode 100644 Controllers/CoolerMasterController/CMKeyboardAbstractController.h create mode 100644 Controllers/CoolerMasterController/CMKeyboardDevices.cpp create mode 100644 Controllers/CoolerMasterController/CMKeyboardDevices.h create mode 100644 Controllers/CoolerMasterController/CMKeyboardV1Controller.cpp create mode 100644 Controllers/CoolerMasterController/CMKeyboardV1Controller.h create mode 100644 Controllers/CoolerMasterController/CMKeyboardV2Controller.cpp create mode 100644 Controllers/CoolerMasterController/CMKeyboardV2Controller.h delete mode 100644 Controllers/CoolerMasterController/CMMKController.cpp delete mode 100644 Controllers/CoolerMasterController/CMMKController.h create mode 100644 Controllers/CoolerMasterController/RGBController_CMKeyboardController.cpp create mode 100644 Controllers/CoolerMasterController/RGBController_CMKeyboardController.h delete mode 100644 Controllers/CoolerMasterController/RGBController_CMMKController.cpp delete mode 100644 Controllers/CoolerMasterController/RGBController_CMMKController.h delete mode 100644 dependencies/libcmmk/include/libcmmk/libcmmk.h delete mode 100644 dependencies/libcmmk/src/libcmmk.c delete mode 100644 dependencies/libcmmk/src/mappings/ansi/mk750.h delete mode 100644 dependencies/libcmmk/src/mappings/ansi/pro_l.h delete mode 100644 dependencies/libcmmk/src/mappings/ansi/pro_s.h delete mode 100644 dependencies/libcmmk/src/mappings/ansi/sk630.h delete mode 100644 dependencies/libcmmk/src/mappings/ansi/sk650.h delete mode 100644 dependencies/libcmmk/src/mappings/iso/mk750.h delete mode 100644 dependencies/libcmmk/src/mappings/iso/pro_l.h delete mode 100644 dependencies/libcmmk/src/mappings/iso/pro_s.h delete mode 100644 dependencies/libcmmk/src/mappings/iso/sk630.h delete mode 100644 dependencies/libcmmk/src/mappings/iso/sk650.h diff --git a/Controllers/CoolerMasterController/CMKeyboardAbstractController.cpp b/Controllers/CoolerMasterController/CMKeyboardAbstractController.cpp new file mode 100644 index 00000000..9a2401a6 --- /dev/null +++ b/Controllers/CoolerMasterController/CMKeyboardAbstractController.cpp @@ -0,0 +1,205 @@ +/*-------------------------------------------------------------------*\ +| CMKeyboardAbstractController.h | +| | +| Abstract driver for Coolermaster keyboards | +| | +| Tam D (too.manyhobbies) 30th Nov 2023 | +| | +\*-------------------------------------------------------------------*/ +#include "CMKeyboardAbstractController.h" + +CMKeyboardAbstractController::CMKeyboardAbstractController(hid_device* dev_handle, hid_device_info* dev_info) +{ + const uint8_t sz = HID_MAX_STR; + wchar_t tmp[sz]; + + m_pDev = dev_handle; + m_productId = dev_info->product_id; + m_sLocation = dev_info->path; + + hid_get_manufacturer_string(m_pDev, tmp, sz); + std::wstring wName = std::wstring(tmp); + m_vendorName = std::string(wName.begin(), wName.end()); + + hid_get_product_string(m_pDev, tmp, sz); + wName = std::wstring(tmp); + m_deviceName = std::string(wName.begin(), wName.end()); + + m_serialNumber = m_deviceName; + + bool bNotFound = true; + + for(uint16_t i = 0; i < COOLERMASTER_KEYBOARD_DEVICE_COUNT; i++) + { + if(cm_kb_device_list[i]->product_id == m_productId) + { + bNotFound = false; + m_deviceIndex = i; + break; + } + } + + if(bNotFound) + { + LOG_ERROR("[%s] device capabilities not found. Please creata a new device request.", + m_deviceName.c_str()); + } +}; + +CMKeyboardAbstractController::~CMKeyboardAbstractController() +{ + if(m_pDev) + { + hid_close(m_pDev); + } +}; + +std::string CMKeyboardAbstractController::GetDeviceName() +{ + return m_deviceName; +} + +void CMKeyboardAbstractController::SetDeviceName(std::string name) +{ + m_deviceName = name; +} + +std::string CMKeyboardAbstractController::GetDeviceVendor() +{ + return m_vendorName; +} + +std::string CMKeyboardAbstractController::GetDeviceSerial() +{ + return m_serialNumber; +} + +const cm_kb_device* CMKeyboardAbstractController::GetDeviceData() +{ + return cm_kb_device_list[m_deviceIndex]; +} + +std::string CMKeyboardAbstractController::GetLocation() +{ + return m_sLocation; +} + +std::string CMKeyboardAbstractController::GetFirmwareVersion() +{ + return m_sFirmwareVersion; +} + +int CMKeyboardAbstractController::GetProductID() +{ + return m_productId; +} + +std::vector CMKeyboardAbstractController::SendCommand(std::vector buf, uint8_t fill) +{ + int status; + std::vector read; + + uint8_t data[CM_KEYBOARD_WRITE_SIZE]; + memset(data, fill, CM_KEYBOARD_WRITE_SIZE); + + size_t i = 1; + for(uint8_t b : buf) + { + data[i++] = b; + } + + std::lock_guard guard(m_mutexSendCommand); + status = hid_write(m_pDev, data, CM_KEYBOARD_WRITE_SIZE); + + if(status < 0) + { + LOG_ERROR("[%s] SendCommand() failed code %d.", m_deviceName.c_str(), status); + return read; + } + + memset(data, 0, CM_KEYBOARD_WRITE_SIZE); + status = hid_read(m_pDev, data, CM_KEYBOARD_WRITE_SIZE); + + if(status < 0) + { + LOG_ERROR("[%s] SendCommand() failed code %d.", m_deviceName.c_str(), status); + return read; + } + + for(i = 0; i < (size_t)status; i++) + { + read.push_back(data[i]); + } + + return read; +} + +/*---------------------------------------------------------*\ +| Enter/leave direct control mode | +\*---------------------------------------------------------*/ +void CMKeyboardAbstractController::SetControlMode(uint8_t modeId) +{ + SendCommand({0x41, (uint8_t)modeId}); +}; + +/*---------------------------------------------------------*\ +| Sets the currently active profile. | +| byte[0] = 0x51 0x00 0x00 0x00 | +| byte[4] = profileId | +| - corresponds to saved keyboard profile i.e. [1-4] | +| - 0x05 - Used on MK and CK style keyboards? | +\*---------------------------------------------------------*/ +void CMKeyboardAbstractController::SetActiveProfile(uint8_t profileId) +{ + SendCommand({0x51, 0x00, 0x00, 0x00, profileId}); +}; + +uint8_t CMKeyboardAbstractController::GetActiveProfile() +{ + std::vector data = SendCommand({0x52, 0x00}); + + if(data.size() > 4) + { + return (int)data[4]; + } + + return 0xFF; // error +} + +/*---------------------------------------------------------*\ +| Saves changes in currently used profile. | +| byte[1] = 0x52 | +\*---------------------------------------------------------*/ +void CMKeyboardAbstractController::SaveActiveProfile() +{ + SendCommand({0x50, 0x55}); +} + +void CMKeyboardAbstractController::SetActiveEffect(uint8_t effectId) +{ + SendCommand({0x51, 0x28, 0x00, 0x00, effectId}); +}; + +void CMKeyboardAbstractController::SaveProfile() +{ + SendCommand({0x50, 0x55}); +} + + +uint8_t CMKeyboardAbstractController::GetModeStatus() +{ + std::vector data = SendCommand({0x52, 0x28}); + return data[4]; +}; + +std::string CMKeyboardAbstractController::GetHexString(std::vector buf) +{ + std::stringstream hexss; + + for(uint8_t b : buf) + { + hexss << std::hex << b << " "; + } + + return hexss.str(); +} diff --git a/Controllers/CoolerMasterController/CMKeyboardAbstractController.h b/Controllers/CoolerMasterController/CMKeyboardAbstractController.h new file mode 100644 index 00000000..6109a220 --- /dev/null +++ b/Controllers/CoolerMasterController/CMKeyboardAbstractController.h @@ -0,0 +1,122 @@ +/*-------------------------------------------------------------------*\ +| CMKeyboardAbstractController.h | +| | +| Abstract driver for Coolermaster keyboards | +| | +| Tam D (too.manyhobbies) 30th Nov 2023 | +| | +\*-------------------------------------------------------------------*/ + +#pragma once + +#include +#include +#include +#include +#include +#include + +#include + +#include "CMKeyboardDevices.h" +#include "KeyboardLayoutManager.h" +#include "RGBController.h" +#include "LogManager.h" + + +#define HID_MAX_STR 255 +#define CM_KEYBOARD_WRITE_SIZE 65 +#define CM_MAX_LEDS 255 +#define CM_KEYBOARD_TIMEOUT 50 +#define CM_KEYBOARD_TIMEOUT_SHORT 3 + +struct cm_keyboard_effect +{ + uint8_t effectId; + uint8_t p1; + uint8_t p2; + uint8_t p3; + RGBColor color1; + RGBColor color2; +}; + +/*---------------------------------------------------------*\ +| byte[0] = 0x41 | +| byte[1] = modeId | +\*---------------------------------------------------------*/ +enum cm_keyboard_control_mode +{ + MODE_FIRMWARE = 0x00, + MODE_EFFECT = 0x01, + MODE_MANUAL_V2 = 0x02, + MODE_CUSTOM_PROFILE = 0x03, + MODE_CUSTOM_PROFILE_V2 = 0x05, + MODE_DIRECT = 0x80 +}; + +class CMKeyboardAbstractController +{ +public: + CMKeyboardAbstractController(hid_device* dev_handle, hid_device_info* dev_info); + ~CMKeyboardAbstractController(); + + /*---------------------------------------------------------*\ + | Common USB controller fuctions | + \*---------------------------------------------------------*/ + int GetProductID(); + std::string GetDeviceName(); + void SetDeviceName(std::string name); + std::string GetDeviceVendor(); + std::string GetDeviceSerial(); + std::string GetLocation(); + std::string GetFirmwareVersion(); + const cm_kb_device* GetDeviceData(); + + /*---------------------------------------------------------*\ + | Keyboard Layout Manager support funtions | + \*---------------------------------------------------------*/ + + /*---------------------------------------------------------*\ + | Common keyboard driver functions | + \*---------------------------------------------------------*/ + virtual void SetControlMode(uint8_t modeId); + virtual void SetActiveProfile(uint8_t profileId); + virtual uint8_t GetActiveProfile(); + virtual void SaveActiveProfile(); + virtual void SaveProfile(); + virtual void SetActiveEffect(uint8_t effectId); + virtual uint8_t GetModeStatus(); + virtual void InitializeModes(std::vector &modes) = 0; + virtual KEYBOARD_LAYOUT GetKeyboardLayout() = 0; + + /*---------------------------------------------------------*\ + | Protocol specific funtions to be implmented | + \*---------------------------------------------------------*/ + virtual void SetLeds(std::vector leds, std::vector colors) = 0; + virtual void SetSingleLED(uint8_t in_led, RGBColor in_color) = 0; + virtual void Initialize() = 0; + virtual void Shutdown() = 0; + virtual void SetLEDControl(bool bManual) = 0; // FW or SW control + virtual void SetCustomMode() = 0; + virtual void SetMode(mode selectedMode) = 0; + +protected: + /*---------------------------------------------------------*\ + | Utility functions. | + \*---------------------------------------------------------*/ + std::vector SendCommand(std::vector buf, uint8_t fill=0x00); + std::string GetHexString(std::vector buf); + std::string m_sFirmwareVersion; + std::string m_deviceName; + hid_device* m_pDev; + uint16_t m_productId; + uint16_t m_deviceIndex; + std::string m_vendorName; + std::string m_sLocation; + std::string m_serialNumber; + KEYBOARD_LAYOUT m_keyboardLayout; + std::map mapModeValueEffect; + std::mutex m_mutex; + std::mutex m_mutexSendCommand; +}; + diff --git a/Controllers/CoolerMasterController/CMKeyboardDevices.cpp b/Controllers/CoolerMasterController/CMKeyboardDevices.cpp new file mode 100644 index 00000000..c479c987 --- /dev/null +++ b/Controllers/CoolerMasterController/CMKeyboardDevices.cpp @@ -0,0 +1,768 @@ +/*-------------------------------------------------------------------*\ +| CMKeyboardDevices.cpp | +| | +| Keymap definitions for Cooler Master Keyboards | +| | +| Tam D (too.manyhobbies) 30th Nov 2023 | +| | +\*-------------------------------------------------------------------*/ +#include "CMKeyboardDevices.h" + +/*-------------------------------------------------------------------------*\ +| Coolermaster Key Values | +\*-------------------------------------------------------------------------*/ + +const std::vector mk_pro_s_keymap = +{ +/* ESC F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 PRSC SCLK PSBK */ + 96, 97, 98, 99, 104, 105, 106, 112, 113, 114, 67, 68, 69, 102, 103, 107, +/* BKTK 1 2 3 4 5 6 7 8 9 0 - = BPSC INS HOME PGUP */ + 0, 1, 8, 9, 16, 17, 24, 25, 32, 33, 40, 41, 48, 49, 56, 57, 64, +/* TAB Q W E R T Y U I O P [ ] \ DEL END PGDN */ + 2, 3, 10, 11, 18, 19, 26, 27, 34, 35, 42, 43, 50, 51, 58, 59, 66, +/* CPLK A S D F G H J K L ; " # ENTR */ + 4, 5, 12, 13, 20, 21, 28, 29, 36, 37, 44, 45, 89, 52, +/* LSFT ISO\ Z X C V B N M , . / RSFT ARWU */ + 6, 100, 7, 14, 15, 22, 23, 30, 31, 38, 39, 46, 47, 61, +/* LCTL LWIN LALT SPC RALT RFNC RMNU RCTL ARWL ARWD ARWR */ + 91, 90, 92, 93, 94, 60, 95, 54, 63, 62, 70, +}; + +const std::vector mk_pro_l_keymap = +{ +/* ESC F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 PRSC SCLK PSBK P1 P2 P3 P4 */ + 11, 22, 30, 25, 27, 7, 51, 57, 62, 86, 87, 83, 85, 79, 72, 0, +/* BKTK 1 2 3 4 5 6 7 8 9 0 - = BPSC INS HOME PGUP NMLK NMDV NMTM NMMI */ + 14, 15, 23, 31, 39, 38, 46, 47, 55, 63, 71, 70, 54, 81, 3, 1, 2, 100, 108, 116, 118, +/* TAB Q W E R T Y U I O P [ ] \ DEL END PGDN NM7 NM8 NM9 NMPL */ + 9, 8, 16, 24, 32, 33, 41, 40, 48, 56, 64, 65, 49, 82, 94, 92, 88, 96, 104, 112, 110, +/* CPLK A S D F G H J K L ; ' \ ENTR NM4 NM5 NM6 */ + 17, 10, 18, 26, 34, 35, 43, 42, 50, 58, 66, 67, 68, 84, 97, 105, 113, +/* LSFT ISO\ Z X C V B N M , . / RSFT ARWU NM1 NM2 NM3 NMER */ + 73, 19, 12, 20, 28, 36, 37, 45, 44, 52, 60, 69, 74, 80, 98, 106, 114, 111, +/* LCTL LWIN LALT SPACE RALT RWFNC RMNU RCTRL ARWL ARDN ARWR NM0 NMPD */ + 6, 90, 75, 91, 77, 78, 61, 4, 95, 93, 5, 107, 115, +}; + +const std::vector mk850_keymap = +{ +/* ESC F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 PRSC SCLK PSBK AIM AIMU AIMD */ + 6, 27, 34, 41, 48, 62, 69, 76, 83, 90, 97, 104, 111, 118, 125, 132, +/* M1 BKTK 1 2 3 4 5 6 7 8 9 0 - = BPSC INS HOME PGUP NMLK NMDV NMTM NMMI */ + 7, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98, 112, 119, 126, 133, 254, 147, 154, 161, +/* M2 TAB Q W E R T Y U I O P [ ] \ DEL END PGDN NM7 NM8 NM9 NMPL */ + 8, 22, 29, 36, 43, 50, 57, 64, 71, 78, 85, 92, 99, 113, 120, 127, 134, 141, 148, 155, 162, +/* M3 CPLK A S D F G H J K L ; ' # ENTR NM4 NM5 NM6 */ + 9, 23, 30, 37, 44, 51, 58, 65, 72, 79, 86, 93, 0, 114, 142, 149, 156, +/* M4 LSFT ISO\ Z X C V B N M , . / RSFT ARWU NM1 NM2 NM3 NMER */ + 10, 0, 24, 31, 38, 45, 52, 59, 66, 73, 80, 87, 115, 129, 143, 150, 157, 164, +/* M5 LCTL LWIN LALT SPACE RALT RWFNC RMNU RCTRL ARWL ARDN ARWR NM0 NMPD */ + 11, 18, 25, 53, 81, 88, 95, 116, 123, 130, 137, 144, 158, +}; + +/*-------------------------------------------------------------*\ +| CoolerMaster SK (60%) | +\*-------------------------------------------------------------*/ +const std::vector sk622_keymap = +{ +/* T1 T2 T3 T4 T5 T6 T7 T8 T9 T10 T11 T12 T13 T14 T15 */ +/* L1 ESC 1 2 3 4 5 6 7 8 9 0 - = BPSC R1 */ + 8, 15, 22, 29, 36, 43, 50, 57, 64, 71, 78, 85, 92, 106, +/* L2 TAB Q W E R T Y U I O P [ ] R2 */ + 9, 23, 30, 37, 44, 51, 58, 65, 72, 79, 86, 93, 100, +/* L3 CPLK A S D F G H J K L ; " \ ENTR R3 */ + 10, 24, 31, 38, 45, 52, 59, 66, 73, 80, 87, 94, 101, 108, +/* L4 LSFT ISO\ Z X C V B N M , . # RSFT ARWU DEL R$ */ + 11, 18, 25, 32, 39, 46, 53, 60, 67, 74, 81, 88, 95, 102, 109, +/* L5 LCTL LWIN LALT SPACE RALT RWFNC ARWL ARDN ARWR R5 */ + 12, 19, 26, 54, 82, 89, 96, 103, 110, +/* B1 B2 B3 B4 B5 B6 B7 B8 B9 B10 B11 B12 B13 B14 B15 B15 */ +}; + +const std::vector sk630_keymap = +{ +/* ESC F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 PRSC SCLK PSBK */ + 9, 33, 41, 49, 57, 73, 81, 89, 97, 105, 113, 121, 129, 137, 145, 153, +/* BKTK 1 2 3 4 5 6 7 8 9 0 - = BPSC INS HOME PGUP */ + 10, 26, 34, 42, 50, 58, 66, 74, 82, 90, 98, 106, 114, 130, 138, 146, 154, +/* TAB Q W E R T Y U I O P [ ] \ DEL END PGDN */ + 11, 27, 35, 43, 51, 59, 67, 75, 83, 91, 99, 107, 115, 131, 139, 147, 155, +/* CPLK A S D F G H J K L ; " # ENTR */ + 12, 28, 36, 44, 52, 60, 68, 76, 84, 92, 100, 108, 116, 132, +/* LSFT ISO\ Z X C V B N M , . / RSFT ARWU */ + 13, 21, 29, 37, 45, 53, 61, 69, 77, 85, 93, 101, 133, 149, +/* LCTL LWIN LALT SPC RALT RFNC RMNU RCTL ARWL ARWD ARWR */ + 14, 22, 30, 62, 94, 102, 110, 134, 142, 150, 158, +}; + +const std::vector sk650_keymap = +{ +/* ESC F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 PRSC SCLK PSBK */ + 0, 24, 32, 40, 48, 64, 72, 80, 88, 96, 104, 112, 120, 128, 136, 144, +/* BKTK 1 2 3 4 5 6 7 8 9 0 - = BPSC INS HOME PGUP NMLK NMDV NMTM NMMI */ + 1, 17, 25, 33, 41, 49, 57, 65, 73, 81, 89, 97, 105, 121, 129, 137, 145, 153, 161, 169, 177, +/* TAB Q W E R T Y U I O P [ ] \ DEL END PGDN NM7 NM8 NM9 NMPL */ + 2, 18, 26, 34, 42, 50, 58, 66, 74, 82, 90, 98, 106, 122, 130, 138, 146, 154, 162, 170, 178, +/* CPLK A S D F G H J K L ; ' # ENTR NM4 NM5 NM6 */ + 3, 19, 27, 35, 43, 51, 59, 67, 75, 83, 91, 99, 107, 123, 155, 163, 171, +/* LSFT ISO\ Z X C V B N M , . / RSFT ARWU NM1 NM2 NM3 NMER */ + 4, 20, 28, 36, 44, 52, 60, 68, 76, 84, 92, 100, 124, 140, 156, 164, 172, 180, +/* LCTL LWIN LALT SPACE RALT RWFNC RMNU RCTRL ARWL ARDN ARWR NM0 NMPD */ + 5, 13, 21, 53, 85, 93, 101, 125, 133, 141, 149, 165, 173, +}; + +const std::vector sk652_keymap = +{ + +/* ESC F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 PRSC SCLK PSBK */ + 9, 33, 41, 49, 57, 73, 81, 89, 97, 105, 113, 121, 129, 137, 145, 153, +/* BKTK 1 2 3 4 5 6 7 8 9 0 - = BPSC INS HOME PGUP NMLK NMDV NMTM NMMI */ + 10, 26, 34, 42, 50, 58, 66, 74, 82, 90, 98, 106, 114, 130, 138, 146, 154, 162, 170, 178, 186, +/* TAB Q W E R T Y U I O P [ ] \ DEL END PGDN NM7 NM8 NM9 NMPL */ + 11, 27, 35, 43, 51, 59, 67, 75, 83, 91, 99, 107, 115, 131, 139, 147, 155, 163, 171, 179, 187, +/* CPLK A S D F G H J K L ; ' # ENTR NM4 NM5 NM6 */ + 12, 28, 36, 44, 52, 60, 68, 76, 84, 92, 100, 108, 116, 132, 164, 172, 180, +/* LSFT ISO\ Z X C V B N M , . / RSFT ARWU NM1 NM2 NM3 NMER */ + 13, 21, 29, 37, 45, 53, 61, 69, 77, 85, 93, 101, 133, 149, 165, 173, 181, 189, +/* LCTL LWIN LALT SPACE RALT RWFNC RMNU RCTRL ARWL ARDN ARWR NM0 NMPD */ + 14, 22, 30, 62, 94, 102, 110, 134, 142, 150, 158, 174, 182, +}; + +const std::vector sk653_keymap = +{ +/* ESC F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 PRSC SCLK PSBK */ + 0, 24, 32, 40, 48, 64, 72, 80, 88, 96, 104, 112, 120, 128, 136, 144, +/* BKTK 1 2 3 4 5 6 7 8 9 0 - = BPSC INS HOME PGUP NMLK NMDV NMTM NMMI */ + 1, 17, 25, 33, 41, 49, 57, 65, 73, 81, 89, 97, 105, 121, 129, 137, 145, 153, 161, 169, 177, +/* TAB Q W E R T Y U I O P [ ] \ DEL END PGDN NM7 NM8 NM9 NMPL */ + 2, 18, 26, 34, 42, 50, 58, 66, 74, 82, 90, 98, 106, 122, 130, 138, 146, 154, 162, 170, 178, +/* CPLK A S D F G H J K L ; ' # ENTR NM4 NM5 NM6 */ + 3, 19, 27, 35, 43, 51, 59, 67, 75, 83, 91, 99, 107, 123, 155, 163, 171, +/* LSFT ISO\ Z X C V B N M , . / RSFT ARWU NM1 NM2 NM3 NMER */ + 4, 20, 28, 36, 44, 52, 60, 68, 76, 84, 92, 100, 124, 140, 156, 164, 172, 180, +/* LCTL LWIN LALT SPACE RALT RWFNC RMNU RCTRL ARWL ARDN ARWR NM0 NMPD */ + 5, 13, 21, 53, 85, 93, 101, 125, 133, 141, 149, 165, 173, +}; + +const std::vector mk730_keymap = +{ +/* ESC F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 PRSC SCLK PSBK */ + 7, 28, 35, 42, 49, 63, 70, 77, 84, 91, 98, 105, 112, 119, 126, 133, +/* L1 BKTK 1 2 3 4 5 6 7 8 9 0 - = BPSC INS HOME PGUP R1 */ + 8, 22, 29, 36, 43, 50, 57, 64, 71, 78, 85, 92, 99, 113, 120, 127, 134, +/* L2 TAB Q W E R T Y U I O P [ ] \ DEL END PGDN R2 */ + 9, 23, 30, 37, 44, 51, 58, 65, 72, 79, 86, 93, 100, 114, 121, 128, 135, +/* L3 CPLK A S D F G H J K L ; ' # ENTR R3 */ + 10, 24, 31, 38, 45, 52, 59, 66, 73, 80, 87, 94, 108, 115, +/* L4 LSFT ISO\ Z X C V B N M , . / RSFT ARWU R4 */ + 11, 18, 25, 32, 39, 46, 53, 60, 67, 74, 81, 88, 116, 130, +/* LCTL LWIN LALT SPACE RALT RWFNC RMNU RCTRL ARWL ARDN ARWR */ + 12, 19, 26, 54, 82, 89, 96, 117, 124, 131, 138, +/* B1 B2 B3 B4 B5 B6 B7 B8 B9 B10 B11 B12 B12 */ +}; + +const std::vector mk750_keymap = +{ +/* ESC F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 PRSC SCLK PSBK MUT PLA REW FFWD */ + 7, 28, 35, 42, 49, 63, 70, 77, 84, 91, 98, 105, 112, 119, 136, 133, +/* L1 BKTK 1 2 3 4 5 6 7 8 9 0 - = BPSC INS HOME PGUP NMLK NMDV NMTM NMMI R1 */ + 8, 22, 29, 36, 43, 50, 57, 64, 71, 78, 85, 92, 99, 113, 120, 127, 134, 0, 148, 155, 162, +/* L2 TAB Q W E R T Y U I O P [ ] \ DEL END PGDN NM7 NM8 NM9 NMPL R2 */ + 9, 23, 30, 37, 44, 51, 58, 65, 72, 79, 86, 93, 100, 114, 121, 128, 135, 142, 149, 156, 163, +/* L3 CPLK A S D F G H J K L ; ' # ENTR NM4 NM5 NM6 R3 */ + 10, 24, 31, 38, 45, 52, 59, 66, 73, 80, 87, 94, 108, 115, 143, 150, 157, +/* L4 LSFT ISO\ Z X C V B N M , . / RSFT ARWU NM1 NM2 NM3 NMER R4 */ + 11, 18, 25, 32, 39, 46, 53, 60, 67, 74, 81, 88, 116, 130, 144, 151, 158, 165, +/* LCTL LWIN LALT SPACE RALT RWFNC RMNU RCTRL ARWL ARDN ARWR NM0 NMPD */ + 12, 19, 26, 54, 82, 89, 96, 117, 124, 131, 138, 152, 159, +/* B1 B2 B3 B4 B5 B6 B7 B8 B9 B10 B11 B12 B12 B13 B14 B15 B16 B17 B18 */ +}; + + +const std::vector ck530_keymap = +{ +/* ESC F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 PRSC SCLK PSBK */ + 6, 21, 27, 34, 41, 55, 62, 69, 76, 83, 90, 97, 104, 111, 118, 125, +/* BKTK 1 2 3 4 5 6 7 8 9 0 - = BPSC INS HOME PGUP */ + 7, 15, 22, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 105, 112, 119, 126, +/* TAB Q W E R T Y U I O P [ ] \ DEL END PGDN */ + 8, 16, 23, 29, 36, 43, 50, 57, 64, 71, 78, 85, 92, 106, 113, 120, 127, +/* CPLK A S D F G H J K L ; " # ENTR */ + 9, 17, 24, 30, 37, 44, 51, 58, 65, 72, 79, 86, 93, 107, +/* LSFT ISO\ Z X C V B N M , . / RSFT ARWU */ + 10, 18, 25, 31, 38, 45, 52, 59, 66, 73, 80, 87, 108, 122, +/* LCTL LWIN LALT SPC RALT RFNC RMNU RCTL ARWL ARWD ARWR */ + 11, 12, 19, 46, 74, 81, 88, 109, 116, 123, 130, +}; + +const std::vector ck550_v2_keymap = +{ +/* ESC F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 PRSC SCLK PSBK */ + 0, 18, 24, 30, 36, 48, 54, 60, 66, 72, 78, 84, 90, 96, 102, 108, +/* BKTK 1 2 3 4 5 6 7 8 9 0 - = BPSC INS HOME PGUP NMLK NMDV NMTM NMMI */ + 1, 13, 19, 25, 31, 37, 43, 49, 55, 61, 67, 73, 79, 91, 97, 103, 109, 115, 121, 127, 133, +/* TAB Q W E R T Y U I O P [ ] \ DEL END PGDN NM7 NM8 NM9 NMPL */ + 2, 14, 20, 26, 32, 38, 44, 50, 56, 62, 68, 74, 80, 92, 98, 104, 110, 116, 122, 128, 134, +/* CPLK A S D F G H J K L ; ' # ENTR NM4 NM5 NM6 */ + 3, 15, 21, 27, 33, 39, 45, 51, 57, 63, 69, 75, 87, 93, 117, 123, 129, +/* LSFT ISO\ Z X C V B N M , . / RSFT ARWU NM1 NM2 NM3 NMER */ + 4, 10, 16, 22, 28, 34, 40, 46, 52, 58, 64, 70,/*76,*/ 94, 106, 118, 124, 130, 136, +/* LCTL LWIN LALT SPACE RALT RWFNC RMNU RCTRL ARWL ARDN ARWR NM0 NMPD */ + 5, 11, 17, 41, 65, 71, 77, 95, 101, 107, 113, 125, 131, +}; + +const std::vector ck552_keymap = +{ +/* ESC F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 PRSC SCLK PSBK */ + 0, 18, 24, 30, 36, 48, 54, 60, 66, 72, 78, 84, 90, 96, 102, 108, +/* BKTK 1 2 3 4 5 6 7 8 9 0 - = BPSC INS HOME PGUP NMLK NMDV NMTM NMMI */ + 1, 13, 19, 25, 31, 37, 43, 49, 55, 61, 67, 73, 79, 91, 97, 103, 109, 115, 121, 127, 133, +/* TAB Q W E R T Y U I O P [ ] \ DEL END PGDN NM7 NM8 NM9 NMPL */ + 2, 14, 20, 26, 32, 38, 44, 50, 56, 62, 68, 74, 80, 92, 98, 104, 110, 116, 122, 128, 134, +/* CPLK A S D F G H J K L ; ' # ENTR NM4 NM5 NM6 */ + 3, 15, 21, 27, 33, 39, 45, 51, 57, 63, 69, 75, 81, 93, 117, 123, 129, +/* LSFT ISO\ Z X C V B N M , . / RSFT ARWU NM1 NM2 NM3 NMER */ + 4, 10, 16, 22, 28, 34, 40, 46, 52, 58, 64, 70,/*76,*/ 94, 106, 118, 124, 130, 136, +/* LCTL LWIN LALT SPACE RALT RWFNC RMNU RCTRL ARWL ARDN ARWR NM0 NMPD */ + 5, 11, 17, 41, 65, 71, 77, 95, 101, 107, 113, 125, 131, +}; + +/*-------------------------------------------------------------------------*\ +| KEYMAPS | +\*-------------------------------------------------------------------------*/ +keyboard_keymap_overlay_values mk_pro_s_layout +{ + KEYBOARD_SIZE::KEYBOARD_SIZE_TKL, + { + mk_pro_s_keymap, + { + /* Add more regional layout fixes here */ + } + }, + { + /*---------------------------------------------------------------------------------------------------------*\ + | Edit Keys | + | Zone, Row, Column, Value, Key, OpCode, | + \*---------------------------------------------------------------------------------------------------------*/ + }, +}; + +keyboard_keymap_overlay_values mk_pro_l_layout +{ + KEYBOARD_SIZE::KEYBOARD_SIZE_FULL, + { + mk_pro_l_keymap, + { + /* Add more regional layout fixes here */ + } + }, + { + /*---------------------------------------------------------------------------------------------------------*\ + | Edit Keys | + | Zone, Row, Column, Value, Key, OpCode, | + \*---------------------------------------------------------------------------------------------------------*/ + { 0, 0, 17, 101, "Key: P1", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 0, 18, 109, "Key: P2", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 0, 19, 117, "Key: P3", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 0, 20, 119, "Key: P4", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + }, +}; + +/*-------------------------------------------------------------*\ +| CoolerMaster MK85O Keyboard | +| Unknown Keys: ISO\, ISO# set to 0 | +\*-------------------------------------------------------------*/ +keyboard_keymap_overlay_values mk850_layout +{ + KEYBOARD_SIZE::KEYBOARD_SIZE_FULL, + { + mk850_keymap, + { + /* Add more regional layout fixes here */ + } + }, + { + /*---------------------------------------------------------------------------------------------------------*\ + | Edit Keys | + | Zone, Row, Column, Value, Key, OpCode, | + \*---------------------------------------------------------------------------------------------------------*/ + { 0, 0, 17, 146, "Key: Aim <|>", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, // aimpad <|> + { 0, 0, 18, 153, "Key: Aim -", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, // aimpad + + { 0, 0, 19, 160, "Key: Aim +", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, // aimpad - + { 0, 1, 0, 0, "Key: M5", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 2, 0, 1, "Key: M4", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 3, 0, 2, "Key: M3", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 4, 0, 3, "Key: M2", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 5, 0, 4, "Key: M1", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + }, +}; + +keyboard_keymap_overlay_values sk622_layout +{ + KEYBOARD_SIZE::KEYBOARD_SIZE_SIXTY, + { + sk622_keymap, + { + /* Add more regional layout fixes here */ + } + }, + { + /*---------------------------------------------------------------------------------------------------------*\ + | Edit Keys | + | Zone, Row, Column, Value, Key, OpCode, | + \*---------------------------------------------------------------------------------------------------------*/ + { 0, 0, 0, 7, "Light: Top 1", KEYBOARD_OPCODE_INSERT_ROW, }, + { 0, 0, 1, 14, "Light: Top 2", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 0, 2, 21, "Light: Top 3", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 0, 3, 28, "Light: Top 4", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 0, 4, 35, "Light: Top 5", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 0, 5, 42, "Light: Top 6", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 0, 6, 49, "Light: Top 7", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 0, 7, 56, "Light: Top 8", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 0, 8, 63, "Light: Top 9", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 0, 9, 70, "Light: Top 10", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 0, 10, 77, "Light: Top 11", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 0, 11, 84, "Light: Top 12", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 0, 12, 91, "Light: Top 13", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 0, 13, 98, "Light: Top 14", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 0, 14, 105, "Light: Top 14", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 1, 0, 0, "Light: Left 1", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 2, 0, 1, "Light: Left 2", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 3, 0, 2, "Light: Left 3", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 4, 0, 3, "Light: Left 4", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 5, 0, 4, "Light: Left 5", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 1, 16, 112, "Light: Right 1", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 2, 16, 113, "Light: Right 2", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 3, 16, 114, "Light: Right 3", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 4, 16, 115, "Light: Right 4", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 5, 16, 116, "Light: Right 5", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 6, 0, 6, "Light: Bottom 1", KEYBOARD_OPCODE_INSERT_ROW, }, + { 0, 6, 1, 20, "Light: Bottom 2", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 6, 2, 27, "Light: Bottom 3", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 6, 3, 34, "Light: Bottom 4", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 6, 4, 41, "Light: Bottom 5", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 6, 5, 48, "Light: Bottom 6", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 6, 6, 55, "Light: Bottom 7", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 6, 7, 62, "Light: Bottom 8", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 6, 8, 69, "Light: Bottom 9", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 6, 9, 76, "Light: Bottom 10", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 6, 10, 83, "Light: Bottom 11", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 6, 11, 90, "Light: Bottom 12", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 6, 12, 97, "Light: Bottom 13", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 6, 13, 104, "Light: Bottom 14", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 6, 14, 111, "Light: Bottom 15", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 6, 14, 118, "Light: Bottom 16", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + }, +}; + +keyboard_keymap_overlay_values sk630_layout +{ + KEYBOARD_SIZE::KEYBOARD_SIZE_TKL, + { + sk630_keymap, + { + /* Add more regional layout fixes here */ + } + }, + { + /*---------------------------------------------------------------------------------------------------------*\ + | Edit Keys | + | Zone, Row, Column, Value, Key, OpCode, | + \*---------------------------------------------------------------------------------------------------------*/ + } +}; + +keyboard_keymap_overlay_values sk650_layout +{ + KEYBOARD_SIZE::KEYBOARD_SIZE_FULL, + { + sk650_keymap, + { + /* Add more regional layout fixes here */ + } + }, + { + /*---------------------------------------------------------------------------------------------------------*\ + | Edit Keys | + | Zone, Row, Column, Value, Key, OpCode, | + \*---------------------------------------------------------------------------------------------------------*/ + } +}; + +keyboard_keymap_overlay_values sk652_layout +{ + KEYBOARD_SIZE::KEYBOARD_SIZE_FULL, + { + sk652_keymap, + { + /* Add more regional layout fixes here */ + } + }, + { + /*---------------------------------------------------------------------------------------------------------*\ + | Edit Keys | + | Zone, Row, Column, Value, Key, OpCode, | + \*---------------------------------------------------------------------------------------------------------*/ + } +}; + +keyboard_keymap_overlay_values sk653_layout +{ + KEYBOARD_SIZE::KEYBOARD_SIZE_FULL, + { + sk653_keymap, + { + /* Add more regional layout fixes here */ + } + }, + { + /*---------------------------------------------------------------------------------------------------------*\ + | Edit Keys | + | Zone, Row, Column, Value, Key, OpCode, | + \*---------------------------------------------------------------------------------------------------------*/ + } +}; + +/*-------------------------------------------------------------*\ +| CoolerMaster MK730 Keyboard | +\*-------------------------------------------------------------*/ +keyboard_keymap_overlay_values mk730_layout +{ + KEYBOARD_SIZE::KEYBOARD_SIZE_TKL, + { + mk730_keymap, + { + /* Add more regional layout fixes here */ + } + }, + { + /*---------------------------------------------------------------------------------------------------------*\ + | Edit Keys | + | Zone, Row, Column, Value, Key, OpCode, | + \*---------------------------------------------------------------------------------------------------------*/ + { 0, 1, 0, 1, "Light: Left 1", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 2, 0, 2, "Light: Left 2", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 3, 0, 3, "Light: Left 3", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 4, 0, 4, "Light: Left 4", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 1, 18, 141, "Light: Right 1", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 2, 18, 142, "Light: Right 2", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 3, 18, 143, "Light: Right 3", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 4, 18, 144, "Light: Right 4", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 6, 1, 13, "Light: Bottom 1", KEYBOARD_OPCODE_INSERT_ROW, }, + { 0, 6, 2, 20, "Light: Bottom 2", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 6, 3, 27, "Light: Bottom 3", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 6, 4, 34, "Light: Bottom 4", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 6, 5, 41, "Light: Bottom 5", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 6, 6, 55, "Light: Bottom 6", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 6, 7, 62, "Light: Bottom 7", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 6, 8, 69, "Light: Logo", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 6, 10, 76, "Light: Bottom 8", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 6, 11, 90, "Light: Bottom 9", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 6, 12, 104, "Light: Bottom 10", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 6, 13, 111, "Light: Bottom 11", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 6, 14, 118, "Light: Bottom 12", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 6, 15, 125, "Light: Bottom 13", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + } +}; + +/*-------------------------------------------------------------*\ +| CoolerMaster MK750 Keyboard | +| based on keymap defined in Signal. | +| The keymap needs the following adjustments | +| NMLK - Unknown set to 0 | +| SCLK - Unknown set to 0 | +| CAPS - Unknown set to 0 | +| Guesses on ISO\ and # | +\*-------------------------------------------------------------*/ +keyboard_keymap_overlay_values mk750_layout +{ + KEYBOARD_SIZE::KEYBOARD_SIZE_FULL, + { + mk750_keymap, + { + /* Add more regional layout fixes here */ + } + }, + { + /*---------------------------------------------------------------------------------------------------------*\ + | Edit Keys | + | Zone, Row, Column, Value, Key, OpCode, | + \*---------------------------------------------------------------------------------------------------------*/ + { 0, 0, 17, 140, KEY_EN_MEDIA_MUTE, KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 0, 18, 147, KEY_EN_MEDIA_PLAY_PAUSE, KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 0, 19, 154, KEY_EN_MEDIA_PREVIOUS, KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 0, 20, 161, KEY_EN_MEDIA_NEXT, KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 1, 0, 1, "Light: Left 1", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 2, 0, 2, "Light: Left 2", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 3, 0, 3, "Light: Left 3", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 4, 0, 4, "Light: Left 4", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 1, 22, 170, "Light: Right 1", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 2, 22, 171, "Light: Right 2", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 3, 22, 172, "Light: Right 3", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 4, 22, 173, "Light: Right 4", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 6, 1, 20, "Light: Bottom 1", KEYBOARD_OPCODE_INSERT_ROW, }, + { 0, 6, 2, 27, "Light: Bottom 2", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 6, 3, 34, "Light: Bottom 3", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 6, 4, 41, "Light: Bottom 4", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 6, 5, 55, "Light: Bottom 5", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 6, 6, 62, "Light: Bottom 6", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 6, 7, 69, "Light: Bottom 7", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 6, 8, 76, "Light: Bottom 8", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 6, 9, 83, "Light: Bottom 9", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 6, 10, 90, "Light: Bottom 10", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 6, 11, 104, "Light: Bottom 11", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 6, 12, 111, "Light: Bottom 12", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 6, 13, 118, "Light: Bottom 13", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 6, 14, 125, "Light: Bottom 14", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 6, 15, 132, "Light: Bottom 15", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 6, 16, 146, "Light: Bottom 16", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 6, 17, 153, "Light: Bottom 17", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 6, 18, 160, "Light: Bottom 18", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + } +}; + +keyboard_keymap_overlay_values ck530_layout +{ + KEYBOARD_SIZE::KEYBOARD_SIZE_TKL, + { + ck530_keymap, + { + /* Add more regional layout fixes here */ + } + }, + { + /*---------------------------------------------------------------------------------------------------------*\ + | Edit Keys | + | Zone, Row, Column, Value, Key, OpCode, | + \*---------------------------------------------------------------------------------------------------------*/ + } +}; + +keyboard_keymap_overlay_values ck550v2_layout +{ + KEYBOARD_SIZE::KEYBOARD_SIZE_FULL, + { + ck550_v2_keymap, + { + { + /* Add more regional layout fixes here */ + /*---------------------------------------------------------------------------------------------------------*\ + | Edit Keys | + | Zone, Row, Column, Value, Key, OpCode, | + \*---------------------------------------------------------------------------------------------------------*/ + }, + }, + }, + { + /*---------------------------------------------------------------------------------------------------------*\ + | Edit Keys | + | Zone, Row, Column, Value, Key, OpCode, | + \*---------------------------------------------------------------------------------------------------------*/ + { 0, 0, 17, 120, "Indicator: N", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 0, 18, 126, "Indicator: C", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + { 0, 0, 19, 132, "Indicator: S", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, }, + }, +}; + +keyboard_keymap_overlay_values ck552_layout +{ + KEYBOARD_SIZE::KEYBOARD_SIZE_FULL, + { + ck552_keymap, + { + { + /* Add more regional layout fixes here */ + /*---------------------------------------------------------------------------------------------------------*\ + | Edit Keys | + | Zone, Row, Column, Value, Key, OpCode, | + \*---------------------------------------------------------------------------------------------------------*/ + }, + }, + }, + { + /*---------------------------------------------------------------------------------------------------------*\ + | Edit Keys | + | Zone, Row, Column, Value, Key, OpCode, | + \*---------------------------------------------------------------------------------------------------------*/ + }, +}; + +static const cm_kb_zone cm_generic_zone = +{ + ZONE_EN_KEYBOARD, + ZONE_TYPE_MATRIX, +}; + +cm_kb_device mk_pro_s_device +{ + COOLERMASTER_KEYBOARD_PRO_S_PID, + { + &cm_generic_zone, + }, + &mk_pro_s_layout, +}; + +cm_kb_device mk_pro_l_device +{ + COOLERMASTER_KEYBOARD_PRO_L_PID, + { + &cm_generic_zone, + }, + &mk_pro_l_layout, +}; + +cm_kb_device mk850_device +{ + COOLERMASTER_KEYBOARD_MK850_PID, + { + &cm_generic_zone, + }, + &mk850_layout, +}; + +cm_kb_device sk622w_device +{ + COOLERMASTER_KEYBOARD_SK622W_PID, + { + &cm_generic_zone, + }, + &sk622_layout, +}; + +cm_kb_device sk622b_device +{ + COOLERMASTER_KEYBOARD_SK622B_PID, + { + &cm_generic_zone, + }, + &sk622_layout, +}; + +cm_kb_device sk630_device +{ + COOLERMASTER_KEYBOARD_SK630_PID, + { + &cm_generic_zone, + }, + &sk630_layout, +}; + +cm_kb_device sk650_device +{ + COOLERMASTER_KEYBOARD_SK650_PID, + { + &cm_generic_zone, + }, + &sk650_layout, +}; + +cm_kb_device sk652_device +{ + COOLERMASTER_KEYBOARD_SK652_PID, + { + &cm_generic_zone, + }, + &sk652_layout, +}; + +cm_kb_device sk653_device +{ + COOLERMASTER_KEYBOARD_SK653_PID, + { + &cm_generic_zone, + }, + &sk652_layout, +}; + +/*---------------------------------------------------------*\ +| TODO: Keymap is incomplete. Extra keys mode enabled to | +| aid in key discovery. | +\*---------------------------------------------------------*/ +cm_kb_device mk730_device +{ + COOLERMASTER_KEYBOARD_MK730_PID, + { + &cm_generic_zone, + }, + &mk730_layout, +}; + +cm_kb_device mk750_device +{ + COOLERMASTER_KEYBOARD_MK750_PID, + { + &cm_generic_zone, + }, + &mk750_layout, +}; + +cm_kb_device ck530_device +{ + COOLERMASTER_KEYBOARD_CK530_PID, + { + &cm_generic_zone, + }, + &ck530_layout, +}; + +cm_kb_device ck530_v2_device +{ + COOLERMASTER_KEYBOARD_CK530_V2_PID, + { + &cm_generic_zone, + }, + &ck530_layout, +}; + +cm_kb_device ck550_v2_device +{ + COOLERMASTER_KEYBOARD_CK550_V2_PID, + { + &cm_generic_zone, + }, + &ck550v2_layout, +}; + +cm_kb_device ck552_v2_device +{ + COOLERMASTER_KEYBOARD_CK552_V2_PID, + { + &cm_generic_zone, + }, + &ck552_layout, +}; + +cm_kb_device mk_pro_l_white_device +{ + COOLERMASTER_KEYBOARD_PRO_L_WHITE_PID, + { + &cm_generic_zone, + }, + &mk_pro_s_layout, +}; + +/*-----------------------------------------------------------------*\ +| KEYBOARDS | +\*-----------------------------------------------------------------*/ +const cm_kb_device* cm_kb_devices[] = +{ + &mk_pro_s_device, + &mk_pro_l_device, + &mk850_device, + &sk622w_device, + &sk622b_device, + &sk630_device, + &sk650_device, + &sk652_device, + &sk653_device, + &mk730_device, + &mk750_device, + &ck530_device, + &ck530_v2_device, + &ck550_v2_device, + &ck552_v2_device, + &mk_pro_l_white_device, +}; + +const unsigned int COOLERMASTER_KEYBOARD_DEVICE_COUNT = (sizeof(cm_kb_devices) / sizeof(cm_kb_devices[ 0 ])); +const cm_kb_device** cm_kb_device_list = cm_kb_devices; diff --git a/Controllers/CoolerMasterController/CMKeyboardDevices.h b/Controllers/CoolerMasterController/CMKeyboardDevices.h new file mode 100644 index 00000000..4ce21a7c --- /dev/null +++ b/Controllers/CoolerMasterController/CMKeyboardDevices.h @@ -0,0 +1,120 @@ +/*-------------------------------------------------------------------*\ +| CMKeyboardDevices.h | +| | +| Keymap definitions for Cooler Master Keyboards | +| | +| Tam D (too.manyhobbies) 30th Nov 2023 | +| | +\*-------------------------------------------------------------------*/ +#pragma once + +#include "RGBController.h" +#include "KeyboardLayoutManager.h" + +/*-----------------------------------------------------*\ +| List of all supported effects by this controller. | +| All of these effects are firmware controlled, and | +| they types of effects supported will depend on the | +| Keyboard. | +| | +| To enable a command, the SetEffect(effectId) needs | +| to be called. The specific effectId->Effect mapping | +| depends on the keyboard. | +\*-----------------------------------------------------*/ +enum cm_keyboard_effect_type +{ + NONE = 0, + DIRECT, + SINGLE, + FULLY_LIT, + STATIC, + BREATHE, + CYCLE, + WAVE, + RIPPLE, + CROSS, + RAINDROPS, + STARS, + SNAKE, + CUSTOMIZED, + INDICATOR, + MULTILAYER, + REACTIVE_FADE, + REACTIVE_PUNCH, + REACTIVE_TORNADO, + HEARTBEAT, + FIREBALL, + SNOW, + CIRCLE_SPECTRUM, + WATER_RIPPLE, + OFF +}; + +#define CM_KB_ZONES_MAX 1 + +typedef struct +{ + std::string name; + zone_type type; +} cm_kb_zone; + +typedef struct +{ + uint16_t product_id; + const cm_kb_zone * zones[CM_KB_ZONES_MAX]; + keyboard_keymap_overlay_values* layout_new; +} cm_kb_device; + +#define COOLERMASTER_VID 0x2516 + +#define CMKB_MAXKEYS 256 + +/*-----------------------------------------------------------------*\ +| keyboard support status is indicated to the right of | +| the PID definition. Attribution to products is also | +| indicated. | +| | +| libcmmk | +| signal https://gitlab.com/signalrgb/signal-plugins | +| openrgb | +| ck550-macos https://github.com/vookimedlo/ck550-macos/tree/master | +| reversed | +| | +| issue tickets, open merge requests etc are provided | +| for developer references. | +| # denotes issue ticket | +| ! denotes merge/pull request | +\*-----------------------------------------------------------------*/ +#define COOLERMASTER_KEYBOARD_CK351_PID 0x014F // unsupported +#define COOLERMASTER_KEYBOARD_CK530_PID 0x009F // [ck550-macos] +#define COOLERMASTER_KEYBOARD_CK530_V2_PID 0x0147 // [signal] +#define COOLERMASTER_KEYBOARD_CK550_V2_PID 0x0145 // [openrgb #800, #2863, signal] +#define COOLERMASTER_KEYBOARD_CK552_V2_PID 0x007F // [ck550-macos, signal] +#define COOLERMASTER_KEYBOARD_CK570_V2_PID 0x01E8 // unsupported +#define COOLERMASTER_KEYBOARD_CK720_PID 0x016B // unsupported +#define COOLERMASTER_KEYBOARD_CK721_PID 0x016D // unsupported +#define COOLERMASTER_KEYBOARD_CK721LINE_PID 0x01EE // unsupported +#define COOLERMASTER_KEYBOARD_PRO_L_PID 0x003B // [libcmmk !16] +#define COOLERMASTER_KEYBOARD_PRO_L_WHITE_PID 0x0047 // [libcmmk] +#define COOLERMASTER_KEYBOARD_PRO_S_PID 0x003C // [libcmmk #30 !31 !36, !37, !7, #5(closed), #3(closed)] +// MASTERKEYS PRO M [libcmmk #17] +#define COOLERMASTER_KEYBOARD_MK721_PID 0x016F // unsupported +#define COOLERMASTER_KEYBOARD_MK730_PID 0x008F // [openrgb #1630, libcmmk] +#define COOLERMASTER_KEYBOARD_MK750_PID 0x0067 // fw1.2 [libcmmk #25 !9, !14, signal] +#define COOLERMASTER_KEYBOARD_MK770_PID 0x01D5 // unsupported +#define COOLERMASTER_KEYBOARD_MK850_PID 0x0069 // [signal] +#define COOLERMASTER_KEYBOARD_SK620B_PID 0x0157 // unsupported +#define COOLERMASTER_KEYBOARD_SK620W_PID 0x0159 // [signal] +#define COOLERMASTER_KEYBOARD_SK622B_PID 0x0149 // [openrgb #3110, signal #217(closed)] +#define COOLERMASTER_KEYBOARD_SK622W_PID 0x014B // [signal] +#define COOLERMASTER_KEYBOARD_SK630_PID 0x0089 // [openrgb #967, libcmmk !21] +#define COOLERMASTER_KEYBOARD_SK631B_PID 0x008B // unsupported +#define COOLERMASTER_KEYBOARD_SK631W_PID 0x0125 // [libcmmk] +#define COOLERMASTER_KEYBOARD_SK650_PID 0x008D // [openrgb #613, libcmmk #23 !37 !27 !28, signal] +#define COOLERMASTER_KEYBOARD_SK651B_PID 0x0091 // unsupported +#define COOLERMASTER_KEYBOARD_SK651W_PID 0x0127 // [signal] +#define COOLERMASTER_KEYBOARD_SK652_PID 0x015D // [signal] +#define COOLERMASTER_KEYBOARD_SK653_PID 0x01AB // [openrgb #3571, signal] + +extern const unsigned int COOLERMASTER_KEYBOARD_DEVICE_COUNT; +extern const cm_kb_device** cm_kb_device_list; diff --git a/Controllers/CoolerMasterController/CMKeyboardV1Controller.cpp b/Controllers/CoolerMasterController/CMKeyboardV1Controller.cpp new file mode 100644 index 00000000..a7e89b59 --- /dev/null +++ b/Controllers/CoolerMasterController/CMKeyboardV1Controller.cpp @@ -0,0 +1,497 @@ +/*-------------------------------------------------------------------*\ +| CMKeyboardV1Controller.cpp | +| | +| Driver for Coolermaster MasterKeys keyboards (V1) | +| | +| Tam D (too.manyhobbies) 30th Nov 2023 | +| | +\*-------------------------------------------------------------------*/ +#include "CMKeyboardV1Controller.h" +#include "LogManager.h" +#include + +CMKeyboardV1Controller::CMKeyboardV1Controller(hid_device* dev_handle, hid_device_info* dev_info) : CMKeyboardAbstractController(dev_handle, dev_info) +{ + m_sFirmwareVersion = _GetFirmwareVersion(); +} + +CMKeyboardV1Controller::~CMKeyboardV1Controller() +{ +} + +void CMKeyboardV1Controller::Initialize() +{ + SetLEDControl(true); +} + +void CMKeyboardV1Controller::SetActiveEffect(uint8_t effectId) +{ + SendCommand({0x51, 0x28, 0x00, 0x00, effectId}); +} + +uint8_t CMKeyboardV1Controller::GetActiveEffect() +{ + std::vector data = SendCommand({0x52, 0x28}); + + return data[4]; +} + +void CMKeyboardV1Controller::SetEffect(uint8_t effectId, uint8_t p1, uint8_t p2, uint8_t p3, RGBColor color1, RGBColor color2) +{ + std::vector data; + + data.push_back(0x51); + data.push_back(0x2C); + data.push_back(0x00); // multilayer_mode - NOT SUPPORTED + data.push_back(0x00); + data.push_back(effectId); + data.push_back(p1); + data.push_back(p2); + data.push_back(p3); + data.push_back(0xFF); + data.push_back(0xFF); + data.push_back(RGBGetRValue(color1)); + data.push_back(RGBGetGValue(color1)); + data.push_back(RGBGetBValue(color1)); + data.push_back(RGBGetRValue(color2)); + data.push_back(RGBGetGValue(color2)); + data.push_back(RGBGetBValue(color2)); + + /*-------------------------------------------*\ + | Likely a bit mask for each LEDs. | + | 3 bits per LED x 127 possible LEDs ~48 bytes| + \*-------------------------------------------*/ + for(size_t i = 0; i < 48; i++) + { + data.push_back(0xFF); + } + + SetCustomMode(); + SetActiveEffect(effectId); + SendCommand(data); +} + +void CMKeyboardV1Controller::SetCustomMode() +{ + SetControlMode(0x01); +} + +void CMKeyboardV1Controller::SetMode(mode selectedMode) +{ + RGBColor color1 = 0; + RGBColor color2 = 0; + uint8_t cSpeed = 0; + uint8_t cDirection = 0; + uint8_t effectId = selectedMode.value; + bool bModeRandom = false; + + if(selectedMode.colors.size() >= 1) + { + color1 = selectedMode.colors[0]; + } + + if(selectedMode.colors.size() >= 2) + { + color2 = selectedMode.colors[1]; + } + + if(selectedMode.color_mode == MODE_COLORS_RANDOM) + { + bModeRandom = true; + } + + int selectedEffect = mapModeValueEffect[effectId]; + cSpeed = selectedMode.speed; + + switch(selectedMode.direction) + { + case MODE_DIRECTION_LEFT: + case MODE_DIRECTION_HORIZONTAL: + cDirection = 0x00; + break; + + case MODE_DIRECTION_RIGHT: + cDirection = 0x04; + break; + + case MODE_DIRECTION_UP: + case MODE_DIRECTION_VERTICAL: + cDirection = 0x06; + break; + + case MODE_DIRECTION_DOWN: + cDirection = 0x02; + break; + + default: + break; + } + + switch(selectedEffect) + { + case DIRECT: + case STATIC: + { + SetEffect(effectId, 0, 0, 0, color1, color2); + } + break; + + case CROSS: + case BREATHE: + case REACTIVE_PUNCH: + case CIRCLE_SPECTRUM: + case SNAKE: + { + SetEffect(effectId, cSpeed, 0, 0xFF, color1, color2); + } + break; + + case WAVE: + { + SetEffect(effectId, cSpeed, cDirection, 0xFF, color1, color2); + } + break; + + case RIPPLE: + { + SetEffect(effectId, cSpeed, bModeRandom ? 0x80 : 0x00, 0xFF, color1, color2); + } + break; + + case RAINDROPS: + { + SetEffect(effectId, 0x6a, 0x00, cSpeed, color1, color2); + } + break; + + case STARS: + { + SetEffect(effectId, cSpeed, 0x00, 0x10, color1, color2); + } + break; + + default: + break; + } +} + +void CMKeyboardV1Controller::InitializeModes(std::vector &modes) +{ + mode Direct; + Direct.name = "Direct"; + Direct.value = 0x02; + Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR; + Direct.color_mode = MODE_COLORS_PER_LED; + + modes.push_back(Direct); + + mapModeValueEffect[0x02] = DIRECT; + + mode Static; + Static.name = "Static"; + Static.value = 0x00; + Static.flags = MODE_FLAG_HAS_MODE_SPECIFIC_COLOR; + Static.color_mode = MODE_COLORS_MODE_SPECIFIC; + Static.colors_min = 1; + Static.colors_max = 1; + Static.colors.resize(1); + modes.push_back(Static); + mapModeValueEffect[0x00] = STATIC; + + mode Breathing; + Breathing.name = "Breathing"; + Breathing.value = 0x01; + Breathing.flags = MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_SPEED; + Breathing.color_mode = MODE_COLORS_MODE_SPECIFIC; + Breathing.speed_min = 0x46; + Breathing.speed_max = 0x27; + Breathing.speed = 0x36; + Breathing.colors_min = 1; + Breathing.colors_max = 1; + Breathing.colors.resize(1); + modes.push_back(Breathing); + mapModeValueEffect[0x01] = BREATHE; + + mode Cycle; + Cycle.name = "Spectrum Cycle"; + Cycle.value = 0x02; + Cycle.flags = MODE_FLAG_HAS_SPEED; + Cycle.color_mode = MODE_COLORS_NONE; + Cycle.speed_min = 0x96; + Cycle.speed_max = 0x68; + Cycle.speed = 0x7F; + modes.push_back(Cycle); + mapModeValueEffect[0x02] = CIRCLE_SPECTRUM; + + mode Reactive; + Reactive.name = "Reactive"; + Reactive.value = 0x03; + Reactive.flags = MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_SPEED; + Reactive.color_mode = MODE_COLORS_MODE_SPECIFIC; + Reactive.speed_min = 0x3C; + Reactive.speed_max = 0x2F; + Reactive.speed = 0x35; + Reactive.colors_min = 2; + Reactive.colors_max = 2; + Reactive.colors.resize(2); + modes.push_back(Reactive); + mapModeValueEffect[0x03] = REACTIVE_PUNCH; + + mode Wave; + Wave.name = "Rainbow Wave"; + Wave.value = 0x04; + Wave.flags = MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_DIRECTION_LR | MODE_FLAG_HAS_DIRECTION_UD; + Wave.color_mode = MODE_COLORS_MODE_SPECIFIC; + Wave.speed_min = 0x48; + Wave.speed_max = 0x2A; + Wave.speed = 0x29; + Wave.direction = MODE_DIRECTION_LEFT; + Wave.colors_min = 1; + Wave.colors_max = 1; + Wave.colors.resize(1); + modes.push_back(Wave); + mapModeValueEffect[0x04] = WAVE; + + mode Ripple; + Ripple.name = "Ripple Effect"; + Ripple.value = 0x05; + Ripple.flags = MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_RANDOM_COLOR | MODE_FLAG_HAS_SPEED; + Ripple.color_mode = MODE_COLORS_MODE_SPECIFIC; + Ripple.speed_min = 0x96; + Ripple.speed_max = 0x62; + Ripple.speed = 0x7C; + Ripple.colors_min = 2; + Ripple.colors_max = 2; + Ripple.colors.resize(2); + modes.push_back(Ripple); + mapModeValueEffect[0x05] = RIPPLE; + + mode Cross; + Cross.name = "Cross"; + Cross.value = 0x06; + Cross.flags = MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_SPEED; + Cross.color_mode = MODE_COLORS_MODE_SPECIFIC; + Cross.speed_min = 0x2A; + Cross.speed_max = 0x48; + Cross.speed = 0x39; + Cross.colors_min = 2; + Cross.colors_max = 2; + Cross.colors.resize(2); + modes.push_back(Cross); + mapModeValueEffect[0x06] = CROSS; + + mode Raindrops; + Raindrops.name = "Raindrops"; + Raindrops.value = 0x07; + Raindrops.flags = MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_SPEED; + Raindrops.color_mode = MODE_COLORS_MODE_SPECIFIC; + Raindrops.speed_min = 0x40; + Raindrops.speed_max = 0x08; + Raindrops.speed = 0x24; + Raindrops.colors_min = 2; + Raindrops.colors_max = 2; + Raindrops.colors.resize(2); + modes.push_back(Raindrops); + mapModeValueEffect[0x07] = RAINDROPS; + + mode Stars; + Stars.name = "Starfield"; + Stars.value = 0x08; + Stars.flags = MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_SPEED; + Stars.color_mode = MODE_COLORS_MODE_SPECIFIC; + Stars.speed_min = 0x46; + Stars.speed_max = 0x32; + Stars.speed = 0x3C; + Stars.colors_min = 2; + Stars.colors_max = 2; + Stars.colors.resize(2); + modes.push_back(Stars); + mapModeValueEffect[0x08] = STARS; + + mode Snake; + Snake.name = "Snake"; + Snake.value = 0x09; + Snake.flags = MODE_FLAG_HAS_SPEED; + Snake.color_mode = MODE_COLORS_NONE; + Snake.speed_min = 0x48; + Snake.speed_max = 0x2A; + Snake.speed = 0x39; + modes.push_back(Snake); + mapModeValueEffect[0x09] = SNAKE; +} + +struct cm_keyboard_effect CMKeyboardV1Controller::GetEffect(uint8_t effectId) +{ + std::vector data; + data.push_back(0x52); + data.push_back(0x2C); + data.push_back(0x00); + data.push_back(0x00); + data.push_back(effectId); + + data = SendCommand(data); + struct cm_keyboard_effect response; + + response.effectId = effectId; + response.p1 = data[5]; + response.p2 = data[6]; + response.p3 = data[7]; + response.color1 = ToRGBColor(data[10], data[11], data[12]); + response.color2 = ToRGBColor(data[13], data[14], data[15]); + + return response; +} + +std::vector CMKeyboardV1Controller::GetEnabledEffects() +{ + std::vector data; + + data = SendCommand({0x52, 0x29}); + + std::vector effects; + + for(size_t i = 4; data[i] != 0xFF; i++) + { + effects.push_back(data[i]); + } + + return effects; +} + + +void CMKeyboardV1Controller::SetLEDControl(bool bManual) +{ + uint8_t modeId = 0; // firmware + + if(bManual) + { + modeId = 0x02; // manual + } + + SetControlMode(modeId); +}; + +void CMKeyboardV1Controller::SetLeds(std::vector leds, std::vector colors) +{ + SetLEDControl(true); + + RGBColor rgbColorMap[CM_MAX_LEDS]; + memset(rgbColorMap, 0, sizeof(RGBColor)*CM_MAX_LEDS); + + for(size_t i = 0; i < leds.size(); i++) + { + rgbColorMap[leds[i].value] = colors[i]; + } + + RGBColor * pRGBColor = rgbColorMap; + + std::lock_guard guard(m_mutex); + + for(size_t i = 0; i < 8; i++) + { + std::vector data; + data.push_back(0xC0); + data.push_back(0x02); + data.push_back(i*2); + data.push_back(0x00); + + for(size_t j = 0; j < 16; j++) + { + data.push_back(RGBGetRValue(*pRGBColor)); + data.push_back(RGBGetGValue(*pRGBColor)); + data.push_back(RGBGetBValue(*pRGBColor)); + + ++pRGBColor; + } + + SendCommand(data); + } +} + +void CMKeyboardV1Controller::SetSingleLED(uint8_t in_led, RGBColor in_color) +{ + std::vector data; + data.push_back(0xC0); + data.push_back(0x01); + data.push_back(0x01); + data.push_back(0x00); + data.push_back(in_led); + data.push_back(RGBGetRValue(in_color)); + data.push_back(RGBGetGValue(in_color)); + data.push_back(RGBGetBValue(in_color)); + + SendCommand(data); +} + +/*-------------------------------------------------------------------*\ +| Detect the Firmware Version | +| | +| Firmware version string is in the format: | +| .. | +| Where is: | +| UNK = 0, ANSI/US = 1, ISO/EU = 2, JP = 3 | +| Examples: | +| 1.2.1 = ANSI/US Keyboard (PRO S) | +| 2.2.1 = ISO/EU Keyboard (PRO L) | +\*-------------------------------------------------------------------*/ +std::string CMKeyboardV1Controller::_GetFirmwareVersion() +{ + std::vector read; + + SetControlMode(MODE_FIRMWARE); + read = SendCommand({0x01, 0x02}); + + char cVersionStr[CM_KEYBOARD_WRITE_SIZE]; + + for(size_t i = 0; i < read.size(); i++) + { + cVersionStr[i] = read[i]; + } + + cVersionStr[CM_KEYBOARD_WRITE_SIZE - 1] = 0; + + std::string sFirmwareVersion; + + sFirmwareVersion = std::string(cVersionStr+4); + + LOG_VERBOSE("[%s] GetFirmwareVersion(): [%s]", m_deviceName.c_str(), sFirmwareVersion.c_str()); + + return sFirmwareVersion; +} + +void CMKeyboardV1Controller::Shutdown() +{ + +} + +KEYBOARD_LAYOUT CMKeyboardV1Controller::GetKeyboardLayout() +{ + KEYBOARD_LAYOUT layout = KEYBOARD_LAYOUT_DEFAULT; + + if(m_sFirmwareVersion.empty()) + { + LOG_WARNING("[%s] GetKeyboardLayout() empty firmware string detected. Unable to detect firmware layout. Assuming defaults.", m_deviceName.c_str()); + + layout = KEYBOARD_LAYOUT_ANSI_QWERTY; + return layout; + } + + switch(m_sFirmwareVersion.c_str()[0]) + { + case '0': + default: + case '1': + layout = KEYBOARD_LAYOUT_ANSI_QWERTY; + break; + + case '2': + layout = KEYBOARD_LAYOUT_ISO_QWERTY; + break; + + case '3': + layout = KEYBOARD_LAYOUT_JIS; + break; + } + + return layout; +} diff --git a/Controllers/CoolerMasterController/CMKeyboardV1Controller.h b/Controllers/CoolerMasterController/CMKeyboardV1Controller.h new file mode 100644 index 00000000..0b0b7f0d --- /dev/null +++ b/Controllers/CoolerMasterController/CMKeyboardV1Controller.h @@ -0,0 +1,39 @@ +/*-------------------------------------------------------------------*\ +| CMKeyboardV1Controller.h | +| | +| Driver for Coolermaster MasterKeys keyboards (V1) | +| | +| Tam D (too.manyhobbies) 30th Nov 2023 | +| | +\*-------------------------------------------------------------------*/ +#include "CMKeyboardAbstractController.h" + +class CMKeyboardV1Controller : public CMKeyboardAbstractController +{ +public: + CMKeyboardV1Controller(hid_device* dev_handle, hid_device_info* dev_info); + ~CMKeyboardV1Controller(); + + /*---------------------------------------------------------*\ + | Protocol specific funtions to be implmented | + \*---------------------------------------------------------*/ + void SetLeds(std::vector leds, std::vector colors); + void SetSingleLED(uint8_t in_led, RGBColor in_color); + void Initialize(); + void Shutdown(); + void SetLEDControl(bool bManual); + + void SetActiveEffect(uint8_t effectId); + uint8_t GetActiveEffect(); + void SetEffect(uint8_t effectId, uint8_t p1, uint8_t p2, uint8_t p3, RGBColor color1, RGBColor color2); + struct cm_keyboard_effect GetEffect(uint8_t effectId); + void SetCustomMode(); + void SetMode(mode selectedMode); + std::vector GetEnabledEffects(); + void InitializeModes(std::vector &modes); + KEYBOARD_LAYOUT GetKeyboardLayout(); + +private: + std::string _GetFirmwareVersion(); + +}; diff --git a/Controllers/CoolerMasterController/CMKeyboardV2Controller.cpp b/Controllers/CoolerMasterController/CMKeyboardV2Controller.cpp new file mode 100644 index 00000000..32c8c6e4 --- /dev/null +++ b/Controllers/CoolerMasterController/CMKeyboardV2Controller.cpp @@ -0,0 +1,1046 @@ +/*-------------------------------------------------------------------*\ +| CMKeyboardV2Controller.cpp | +| | +| Driver for Coolermaster V2 | +| | +| Tam D (too.manyhobbies) 30th Nov 2023 | +| | +\*-------------------------------------------------------------------*/ +#include +#include +#include +#include "CMKeyboardV2Controller.h" +#include "LogManager.h" + +CMKeyboardV2Controller::CMKeyboardV2Controller(hid_device* dev_handle, hid_device_info* dev_info) : CMKeyboardAbstractController(dev_handle, dev_info) +{ + m_sFirmwareVersion = _GetFirmwareVersion(); + m_bMoreFFs = false; +} + +CMKeyboardV2Controller::~CMKeyboardV2Controller() +{ +} + +/*-----------------------------------------------------------------*\ +| Firmware version string is in the format: | +| V.. | +| Where is: | +| UNK = 0, ANSI/US = 1, ISO/EU = 2, JP = 3 | +\*-----------------------------------------------------------------*/ +KEYBOARD_LAYOUT CMKeyboardV2Controller::GetKeyboardLayout() +{ + KEYBOARD_LAYOUT layout = KEYBOARD_LAYOUT_DEFAULT; + + if(m_sFirmwareVersion.empty()) + { + LOG_WARNING("[%s] _GetKeyboardLayout() empty firmware string detected. Assuming ANSI layout as default..", m_deviceName.c_str()); + + layout = KEYBOARD_LAYOUT_ANSI_QWERTY; + } + else + { + switch(m_sFirmwareVersion.c_str()[1]) + { + case '3': + layout = KEYBOARD_LAYOUT_JIS; + break; + + case '2': + layout = KEYBOARD_LAYOUT_ISO_QWERTY; + break; + + default: + case '1': + layout = KEYBOARD_LAYOUT_ANSI_QWERTY; + break; + } + } + + /*------------------------------------------------------------*\ + | Double check keyboard type per #3592, EU keyboard reported | + | with version ID in serial number. | + \*------------------------------------------------------------*/ + if(m_serialNumber.find("JP") != std::string::npos) + { + layout = KEYBOARD_LAYOUT_JIS; + } + + if(m_serialNumber.find("EU") != std::string::npos) + { + layout = KEYBOARD_LAYOUT_ISO_QWERTY; + } + + return layout; +} + +/*-----------------------------------------------------------------*\ +| Gets the firmware version. | +| Strings are stored as UTF-16 so need to be converted to string | +| Firmware format is VX.YY.ZZ . | +\*-----------------------------------------------------------------*/ +std::string CMKeyboardV2Controller::_GetFirmwareVersion() +{ + std::vector read; + + SetControlMode(MODE_FIRMWARE); + read = SendCommand({0x12, 0x20}); + + uint8_t cVersionStr[CM_KEYBOARD_WRITE_SIZE]; + + size_t i = 0; + for(auto it : read) + { + cVersionStr[i++] = it; + } + + std::u16string usFirmwareVersion(reinterpret_cast(cVersionStr+8)); + std::string sFirmwareVersion(usFirmwareVersion.begin(), usFirmwareVersion.end()); + + LOG_VERBOSE("[%s] GetFirmwareVersion(): [%s]", m_deviceName.c_str(), sFirmwareVersion.c_str()); + + return sFirmwareVersion; +} + +void CMKeyboardV2Controller::Initialize() +{ + switch(m_productId) + { + case COOLERMASTER_KEYBOARD_SK620B_PID: + case COOLERMASTER_KEYBOARD_SK620W_PID: + MagicCommand(0x09); + break; + + case COOLERMASTER_KEYBOARD_SK622B_PID: + case COOLERMASTER_KEYBOARD_SK622W_PID: + MagicStartupPacket(); + MagicCommand(0x09); + break; + + case COOLERMASTER_KEYBOARD_SK630_PID: + case COOLERMASTER_KEYBOARD_SK650_PID: + SetActiveProfile(0x0C); + m_bMoreFFs = true; + break; + + case COOLERMASTER_KEYBOARD_SK652_PID: + case COOLERMASTER_KEYBOARD_SK653_PID: + MagicStartupPacket(); + MagicCommand(0x0C); + m_bMoreFFs = true; + break; + + case COOLERMASTER_KEYBOARD_CK530_PID: + case COOLERMASTER_KEYBOARD_CK530_V2_PID: + SetActiveProfile(0x05); + MagicCommand(0x0A); + break; + + case COOLERMASTER_KEYBOARD_CK550_V2_PID: + SetActiveProfile(0x05); + MagicCommand(0x09); + break; + + case COOLERMASTER_KEYBOARD_MK730_PID: + SetActiveProfile(0x05); + MagicCommand(0x0A); + m_bMoreFFs = true; + break; + + case COOLERMASTER_KEYBOARD_CK552_V2_PID: + SetControlMode(0x80); + MagicCommand(0x01); + break; + + default: + SendCommand({0x56, 0x81, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0A, 0x00, 0x00, 0x00, 0xBB, 0xBB, 0xBB}); + break; + } +} + +void CMKeyboardV2Controller::Shutdown() +{ + +} + +/*---------------------------------------------------------*\ +| Required for some keyboards. No idea what it does. | +\*---------------------------------------------------------*/ +void CMKeyboardV2Controller::MagicStartupPacket() +{ + std::lock_guard guard(m_mutex); + + SendCommand({0x12}); + SendCommand({0x12, 0x20}); + SendCommand({0x12, 0x01}); + SendCommand({0x12, 0x22}); + SendCommand({0x42, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x01}); + SendCommand({0x43, 0x00, 0x00, 0x00, 0x01}); +}; + +void CMKeyboardV2Controller::SetLEDControl(bool bManual) +{ + uint8_t modeId = 0; + + if(bManual) + { + modeId = 0x05; + } + + SetControlMode(modeId); +} + +void CMKeyboardV2Controller::SetLeds(std::vector leds, std::vector colors) +{ + SetLEDControl(true); + Initialize(); + + RGBColor rgbColorMap[CM_MAX_LEDS]; + memset(rgbColorMap, 0, sizeof(RGBColor)*CM_MAX_LEDS); + + for(size_t i = 0; i < leds.size(); i++) + { + rgbColorMap[leds[i].value] = colors[i]; + } + + /*---------------------------------------------------------*\ + | Convert color array to linear map of RGB positions. | + | Map is sequential layout of RGB for each LED. i indicates | + | the position in the map (i*3), | + \*---------------------------------------------------------*/ + uint8_t linearColorMap[CM_MAX_LEDS*3] = {0,}; + + for(size_t i = 0; i < CM_MAX_LEDS; i++) + { + linearColorMap[i*3] = RGBGetRValue(rgbColorMap[i]); + linearColorMap[i*3+1] = RGBGetGValue(rgbColorMap[i]); + linearColorMap[i*3+2] = RGBGetBValue(rgbColorMap[i]); + } + + /*---------------------------------------------------------*\ + | For future reference, some keyboares may designate a | + | different number of max LEDs. | + \*---------------------------------------------------------*/ + const uint8_t nLEDs = 0xC1; + + /*---------------------------------------------------------*\ + | Build initial packet. | + | This specifies some of the initial parameters such as the | + | number of LEDs, and the first grouping of LEDs. | + | The packet structure seems to be fixed for these first 24 | + | bytes. | + \*---------------------------------------------------------*/ + std::vector data = + { + 0x56, 0x83, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x80, 0x01, 0x00, nLEDs, 0x00, 0x00, 0x00, 0x00, + 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00 + }; + + + size_t pktIdx; + for(pktIdx = 0; pktIdx < 40; pktIdx++) + { + data.push_back(linearColorMap[pktIdx]); + } + + std::lock_guard guard(m_mutex); + + SendCommand(data); + + /*---------------------------------------------------------*\ + | Build subsequent packets. | + | Aproximately 9 packets of 60 bytes each. Total may change | + | if we get a keyboard with an insane number of LEDs. | + \*---------------------------------------------------------*/ + for(size_t i = 1; i < 10; ++i) + { + data.clear(); + data.push_back(0x56); + data.push_back(0x83); + data.push_back(i); + data.push_back(0x00); + + for(size_t j = 0; j < 60; j++) + { + data.push_back(linearColorMap[pktIdx++]); + } + + SendCommand(data); + } + SendApplyPacket(0xFF); +} + +void CMKeyboardV2Controller::SetSingleLED(uint8_t /*in_led*/, RGBColor /*in_color*/) +{ +} + +void CMKeyboardV2Controller::MagicCommand(uint8_t profileId) +{ + SendCommand( + { + 0x56, 0x81, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + profileId, 0x00, 0x00, 0x00, 0xBB, 0xBB, 0xBB, 0xBB} + ); +}; + +void CMKeyboardV2Controller::_SetEffectMode(uint8_t effectId) +{ + std::vector data; + + switch(effectId) + { + case STATIC: + case DIRECT: + case CYCLE: + case BREATHE: + case CIRCLE_SPECTRUM: + case REACTIVE_TORNADO: + data = std::vector + { + 0x56, 0x81, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x88, 0x88, 0x88, 0x88, + }; + break; + + case WAVE: + data = std::vector + { + 0x56, 0x81, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x99, 0x99, 0x99, 0x99 + }; + break; + + case STARS: + case RAINDROPS: + case SNOW: + case CROSS: + case RIPPLE: + case REACTIVE_PUNCH: + case REACTIVE_FADE: + case HEARTBEAT: + case FIREBALL: + case WATER_RIPPLE: + data = std::vector + { + 0x56, 0x81, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x88, 0x88, 0x88, 0x88, + }; + break; + + case CUSTOMIZED: + data = std::vector{ + 0x56, 0x81, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x00, 0x00, 0xBB, 0xBB, 0xBB, 0xBB, + }; + break; + + default: + break; + } + + SendCommand(data); +} + +void CMKeyboardV2Controller::SendApplyPacket(uint8_t mode) +{ + SendCommand({0x51, 0x28, 0x00, 0x00, mode}); +} + + +/*---------------------------------------------------------*\ +| Sets the speed for each mode. Seems like almost every mode| +| has a different set of speed settings. | +\*---------------------------------------------------------*/ +void CMKeyboardV2Controller::_UpdateSpeed(mode selectedMode, uint8_t &cSpeed1, uint8_t &cSpeed2) +{ + std::vectorvSpeed1{0x00, 0x00, 0x00, 0x00, 0x00}; + std::vectorvSpeed2{0x00, 0x00, 0x00, 0x00, 0x00}; + + switch(selectedMode.value) + { + case CROSS: + case REACTIVE_FADE: + vSpeed1 = std::vector{0x17, 0x0E, 0x0B, 0x0A, 0x04}; + vSpeed2 = std::vector{0x01, 0x01, 0x02, 0x05, 0x04}; + break; + + case WAVE: + vSpeed1 = std::vector{0x17, 0x0D, 0x07, 0x09, 0x08}; + vSpeed2 = std::vector{0x01, 0x04, 0x06, 0x0C, 0x11}; + break; + + case REACTIVE_PUNCH: + vSpeed1 = std::vector{0x0E, 0x0A, 0x04, 0x07, 0x01}; + break; + + case BREATHE: + vSpeed1 = std::vector{0x08, 0x0A, 0x0C, 0x07, 0x09}; + vSpeed2 = std::vector{0x01, 0x02, 0x04, 0x04, 0x09}; + break; + + case CIRCLE_SPECTRUM: + case REACTIVE_TORNADO: + switch (selectedMode.direction) + { + case MODE_DIRECTION_LEFT: + vSpeed1 = std::vector{0xFF, 0xFE, 0xFD, 0xFC, 0xFC}; + vSpeed2 = std::vector{0x04, 0x08, 0x08, 0x0C, 0x00}; + break; + + default: + case MODE_DIRECTION_RIGHT: + vSpeed1 = std::vector{0x00, 0x01, 0x02, 0x03, 0x04}; + vSpeed2 = std::vector{0x0C, 0x08, 0x08, 0x04, 0x00}; + break; + } + break; + + case CYCLE: + vSpeed1 = std::vector{0x10, 0x0C, 0x08, 0x04, 0x00}; + break; + + case RIPPLE: + case WATER_RIPPLE: + vSpeed1 = std::vector{0x36, 0x18, 0x0C, 0x06, 0x02}; + break; + + case FIREBALL: + case HEARTBEAT: + vSpeed1 = std::vector{0x01, 0x02, 0x03, 0x05, 0x09}; + break; + + case RAINDROPS: + case SNOW: + vSpeed1 = std::vector{0x0B, 0x08, 0x05, 0x02, 0x00}; + vSpeed2 = std::vector{0x08, 0x18, 0x30, 0x38, 0x40}; + break; + + case STARS: + vSpeed1 = std::vector{0x17, 0x0E, 0x08, 0x0A, 0x0A}; + vSpeed2 = std::vector{0x01, 0x01, 0x01, 0x02, 0x04}; + break; + + case OFF: + default: + break; + } + + if(selectedMode.speed >= 1 && selectedMode.speed <= 5) + { + cSpeed1 = vSpeed1[selectedMode.speed-1]; + cSpeed2 = vSpeed2[selectedMode.speed-1]; + } +} + +void CMKeyboardV2Controller::SetCustomMode() +{ + std::lock_guard guard(m_mutex); + + SendCommand({0x41, 0x80}); + SendCommand({0x52}); +} + +void CMKeyboardV2Controller::SetMode(mode selectedMode) +{ + std::vector data(64, 0); + std::vector data1(64, 0); + std::vector data2(64, 0); + + uint8_t cColor1_R, cColor1_G, cColor1_B; + uint8_t cColor2_R, cColor2_G, cColor2_B; + + RGBColor color1 = 0; + RGBColor color2 = 0; + uint8_t cSpeed1 = 0; + uint8_t cSpeed2 = 0; + + _UpdateSpeed(selectedMode, cSpeed1, cSpeed2); + + uint8_t cBright = (uint8_t)selectedMode.brightness; + uint8_t cDirection = 0; + uint8_t effectId = selectedMode.value; + + if(selectedMode.colors.size() >= 1) + { + color1 = selectedMode.colors[0]; + cColor1_R = (uint8_t)RGBGetRValue(color1); + cColor1_G = (uint8_t)RGBGetGValue(color1); + cColor1_B = (uint8_t)RGBGetBValue(color1); + } + + if(selectedMode.colors.size() >= 2) + { + color2 = selectedMode.colors[1]; + cColor2_R = (uint8_t)RGBGetRValue(color2); + cColor2_G = (uint8_t)RGBGetGValue(color2); + cColor2_B = (uint8_t)RGBGetBValue(color2); + } + + switch(selectedMode.direction) + { + case MODE_DIRECTION_LEFT: + case MODE_DIRECTION_HORIZONTAL: + cDirection = 0x04; + break; + + case MODE_DIRECTION_RIGHT: + cDirection = 0x00; + break; + + case MODE_DIRECTION_UP: + case MODE_DIRECTION_VERTICAL: + cDirection = 0x06; + break; + + case MODE_DIRECTION_DOWN: + cDirection = 0x02; + break; + + default: + break; + } + + SetCustomMode(); + + std::lock_guard guard(m_mutex); + _SetEffectMode(effectId); + + switch(effectId) + { + case OFF: + break; + + case DIRECT: + break; + + case STATIC: + { + data = std::vector + { + 0x56, 0x83, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x01, 0x00, 0xC1, 0x00, 0x00, 0x00, 0x00, + cColor1_R, cColor1_G, cColor1_B, cBright, 0x00, 0x00, 0x00, 0x00, + }; + SendCommand(data); + } + break; + + case WAVE: + { + data = std::vector + { + 0x56, 0x83, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x32, 0x00, 0xC1, cSpeed1, 0x00, 0x00, 0x00, + 0xFF, 0xFF, 0xFF, cBright, 0x00, cDirection, cSpeed2, 0x00, + 0x00, 0x04, 0x08 + }; + SendCommand(data); + } + break; + + case STARS: + { + data = std::vector + { + 0x56, 0x83, 0x00, 0x00, 0x0D, 0x00, 0x0D, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x07, 0x00, 0x01, 0x00, + 0x00, 0x01, 0x00, 0xC1, 0x00, 0x00, 0x00, 0x00, + cColor2_R, cColor2_G, cColor2_B, cBright, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x40, 0x00, 0x80, cSpeed1, 0x10, 0x00, 0x00, + cColor1_R, cColor1_G, cColor1_B, cBright, 0x00, 0x00, cSpeed2, 0x01, + 0x01, 0x10, 0x08, 0x01, 0x10, 0x00, 0x00, 0x00, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF + }; + SendCommand(data); + + data1 = std::vector + { + 0x56, 0x83, 0x01, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF + }; + + data2 = std::vector + { + 0x56, 0x83, 0x01, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF + }; + + data = m_bMoreFFs ? data2 : data1; + + SendCommand(data); + } + break; + + case RAINDROPS: + { + data = std::vector + { + 0x56, 0x83, 0x00, 0x00, 0x0D, 0x00, 0x0D, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x07, 0x00, 0x01, 0x00, + 0x00, 0x01, 0x00, 0xC1, 0x00, 0x00, 0x00, 0x00, + cColor2_R, cColor2_G, cColor2_B, cBright, 0x00, 0x00, 0x00, 0x00, + 0x81, 0x40, 0x00, 0x80, cSpeed1, 0x10, 0x00, 0x00, + cColor1_R, cColor1_G, cColor1_B, cBright, 0x00, 0x00, 0x03, 0x00, + cSpeed2, 0x18, 0x04, 0x10, 0x01, 0x00, 0x00, 0x00, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF + }; + SendCommand(data); + + data1 = std::vector + { + 0x56, 0x83, 0x01, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF + }; + + data2 = std::vector + { + 0x56, 0x83, 0x01, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF + }; + + data = m_bMoreFFs ? data2 : data1; + + SendCommand(data); + } + break; + + case SNOW: + { + data = std::vector + { + 0x56, 0x83, 0x00, 0x00, 0x0D, 0x00, 0x0D, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x07, 0x00, 0x01, 0x00, + 0x00, 0x01, 0x00, 0xC1, 0x00, 0x00, 0x00, 0x00, + cColor2_R, cColor2_G, cColor2_B, cBright, 0x00, 0x00, 0x00, 0x00, + 0x81, 0x40, 0x00, 0x80, cSpeed1, 0x10, 0x00, 0x00, + cColor1_R, cColor1_G, cColor1_B, cBright, 0x00, 0x00, 0x03, 0x00, + cSpeed2, 0xFF, 0x10, 0x10, 0x01, 0x40, 0x00, 0x00, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF + }; + SendCommand(data); + + data = std::vector + { + 0x56, 0x83, 0x01, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF + }; + SendCommand(data); + } + break; + + case CYCLE: + { + data = std::vector + { + 0x56, 0x83, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x31, 0x00, 0xC1, cSpeed1, 0x00, 0x00, 0x00, + 0x40, 0x00, 0xFF, cBright, 0x00, 0x00, 0x03, 0x00, + }; + + SendCommand(data); + } + break; + + case BREATHE: + { + data = std::vector + { + 0x56, 0x83, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x30, 0x00, 0xC1, cSpeed1, 0x00, 0x00, 0x00, + cColor1_R, cColor1_G, cColor1_B, cBright, 0x01, 0x00, cSpeed2, 0x00, + }; + SendCommand(data); + } + break; + + case CIRCLE_SPECTRUM: + { + /*---------------------------------------------------*\ + | Speed and directions are interlinked. Probably has | + | to do how speed is computed within the firmware. | + | The speed values for this mode take into account | + | the direction. | + \*---------------------------------------------------*/ + data = std::vector + { + 0x56, 0x83, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x34, 0x00, 0xC1, 0x04, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xFF, cBright, 0x00, 0x00, cSpeed1, 0x00, + 0x00, cSpeed2, 0x00, 0x04, 0xA0, 0x00, 0x30, 0x00, + }; + SendCommand(data); + } + break; + + case CROSS: + { + data = std::vector + { + 0x56, 0x83, 0x00, 0x00, 0x0C, 0x00, 0x0C, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x07, 0x00, 0x01, 0x00, + 0x00, 0x01, 0x00, 0xC1, 0x00, 0x00, 0x00, 0x00, + cColor2_R, cColor2_G, cColor2_B, cBright, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x80, 0x00, 0x80, cSpeed1, 0x10, 0x00, 0x00, + cColor1_R, cColor1_G, cColor1_B, cBright, 0x00, 0x00, cSpeed2, 0x01, + 0x03, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF + }; + SendCommand(data); + + data1 = std::vector + { + 0x56, 0x83, 0x01, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + }; + + data2 = std::vector + { + 0x56, 0x83, 0x01, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + }; + + data = m_bMoreFFs ? data2 : data1; + SendCommand(data); + } + break; + + case SINGLE: + break; + + case RIPPLE: + { + data = std::vector + { + 0x56, 0x83, 0x00, 0x00, 0x0C, 0x00, 0x0C, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x07, 0x00, 0x01, 0x00, + 0x00, 0x01, 0x00, 0xC1, 0x00, 0x00, 0x00, 0x00, + cColor2_R, cColor2_G, cColor2_B, cBright, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x82, 0x00, 0x80, cSpeed1, 0x10, 0x00, 0x00, + cColor1_R, cColor1_G, cColor1_B, cBright, 0x00, 0x00, 0x01, 0x00, + 0x00, 0x01, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF + }; + SendCommand(data); + + data = std::vector + { + 0x56, 0x83, 0x01, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF + }; + SendCommand(data); + } + break; + + case REACTIVE_PUNCH: + { + data = std::vector + { + 0x56, 0x83, 0x00, 0x00, 0x0B, 0x00, 0x0B, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x07, 0x00, 0x01, 0x00, + 0x00, 0x01, 0x00, 0xC1, 0x00, 0x00, 0x00, 0x00, + cColor2_R, cColor2_G, cColor2_B, cBright, 0x00, 0x00, 0x00, 0x00, + 0x28, 0x80, 0x00, 0x80, cSpeed1, 0x10, 0x00, 0x00, + cColor1_R, cColor1_G, cColor1_B, cBright, 0x00, 0x00, 0x01, 0x00, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF + }; + + SendCommand(data); + + data1 = std::vector + { + 0x56, 0x83, 0x01, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF + }; + + data2 = std::vector + { + 0x56, 0x83, 0x01, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF + }; + + data = m_bMoreFFs ? data2 : data1; + + SendCommand(data); + } + break; + + case REACTIVE_FADE: + { + data = std::vector + { + 0x56, 0x83, 0x00, 0x00, 0x0C, 0x00, 0x0C, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x07, 0x00, 0x01, 0x00, + 0x00, 0x01, 0x00, 0xC1, 0x00, 0x00, 0x00, 0x00, + cColor2_R, cColor2_G, cColor2_B, cBright, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x80, 0x00, 0x80, cSpeed1, 0x10, 0x00, 0x00, + cColor1_R, cColor1_G, cColor1_B, cBright, 0x00, 0x00, 0x01, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF + }; + SendCommand(data); + + data1 = std::vector + { + 0x56, 0x83, 0x01, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + }; + + data2 = std::vector + { + 0x56, 0x83, 0x01, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + }; + + data = m_bMoreFFs ? data2 : data1; + + SendCommand(data); + } + break; + + case REACTIVE_TORNADO: + { + /*---------------------------------------------------*\ + | Speed and directions are interlinked. Probably has | + | to do how speed is computed within the firmware. | + | The speed values for this mode take into account | + | the direction. | + \*---------------------------------------------------*/ + data = std::vector + { + 0x56, 0x83, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x83, 0x00, 0xC1, 0x04, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xFF, cBright, 0x00, 0x00, cSpeed1, 0x00, + 0x00, cSpeed2, 0x00, 0x00, 0x30, 0x00, 0x10, 0x00, + }; + SendCommand(data); + } + break; + + case HEARTBEAT: + { + data = std::vector + { + 0x56, 0x83, 0x00, 0x00, 0x0C, 0x00, 0x0C, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x07, 0x00, 0x01, 0x00, + 0x00, 0x01, 0x00, 0xC1, 0x00, 0x00, 0x00, 0x00, + cColor2_R, cColor2_G, cColor2_B, cBright, 0x00, 0x00, 0x00, 0x00, + 0x20, 0xA0, 0x00, 0x80, 0x20, 0x10, 0x00, 0x00, + cColor1_R, cColor1_G, cColor1_B, cBright, 0x00, 0x00, cSpeed1, 0x00, + 0x02, 0xFF, 0x00, 0x03, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF + }; + SendCommand(data); + + data = std::vector + { + 0x56, 0x83, 0x01, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + }; + SendCommand(data); + } + break; + + case FIREBALL: + { + data = std::vector + { + 0x56, 0x83, 0x00, 0x00, 0x0C, 0x00, 0x0C, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x07, 0x00, 0x01, 0x00, + 0x00, 0x01, 0x00, 0xC1, 0x00, 0x00, 0x00, 0x00, + cColor2_R, cColor2_G, cColor2_B, cBright, 0x00, 0x00, 0x00, 0x00, + 0x20, 0xA0, 0x00, 0x80, 0x10, 0x10, 0x00, 0x00, + cColor1_R, cColor1_G, cColor1_B, cBright, 0x00, 0x00, cSpeed1, 0x00, + 0x01, 0x08, 0x09, 0x04, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF + }; + SendCommand(data); + + data = std::vector + { + 0x56, 0x83, 0x01, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + }; + SendCommand(data); + } + break; + + case WATER_RIPPLE: + { + data = std::vector + { + 0x56, 0x83, 0x00, 0x00, 0x0C, 0x00, 0x0C, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x07, 0x00, 0x01, 0x00, + 0x00, 0x01, 0x00, 0xC1, 0x00, 0x00, 0x00, 0x00, + cColor2_R, cColor2_G, cColor2_B, cBright, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x82, 0x00, 0x80, cSpeed1, 0x10, 0x00, 0x00, + cColor1_R, cColor1_G, cColor1_B, cBright, 0x00, 0x00, 0x06, 0x00, + 0x00, 0x90, 0x14, 0x20, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF + }; + SendCommand(data); + + data = std::vector + { + 0x56, 0x83, 0x01, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + }; + SendCommand(data); + } + + case SNAKE: + default: + break; + } + + switch (effectId) + { + case OFF: + SendCommand({0x51, 0x28, 0x00, 0x00, 0x10}); + SendCommand({0x41, 0x80}); + break; + + default: + SendCommand({0x41, 0x80}); + SendCommand({0x51, 0x28, 0x00, 0x00, 0xFF}); + break; + } +} + +struct stCMKeyboardV2_mode CMKeyboardV2_modes[] = +{ +/*----------------------------------------------------------------------------------------------------------------------------------------*\ +| Speed Brightness | +| NAME VALUE MIN MAX SET MAX DIR Number of Colors COLOR_MODE FLAGS | +\*----------------------------------------------------------------------------------------------------------------------------------------*/ + {"Direct", DIRECT, 1, 5, 3, 0xFF, 0, 0, MODE_COLORS_PER_LED, MODE_FLAG_HAS_PER_LED_COLOR}, + {"Static", STATIC, 1, 5, 3, 0xFF, 0, 1, MODE_COLORS_MODE_SPECIFIC, MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | + MODE_FLAG_HAS_BRIGHTNESS }, + {"Wave", WAVE, 1, 5, 3, 0xFF, MODE_DIRECTION_LEFT,1, MODE_COLORS_NONE, MODE_FLAG_HAS_BRIGHTNESS | + MODE_FLAG_HAS_SPEED | + MODE_FLAG_HAS_DIRECTION_LR | + MODE_FLAG_HAS_DIRECTION_UD}, + {"Crosshair", CROSS, 1, 5, 3, 0xFF, 0, 2, MODE_COLORS_MODE_SPECIFIC, MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | + MODE_FLAG_HAS_BRIGHTNESS | + MODE_FLAG_HAS_SPEED }, + {"Reactive Fade",REACTIVE_FADE,1,5, 3, 0xFF, 0, 2, MODE_COLORS_MODE_SPECIFIC, MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | + MODE_FLAG_HAS_BRIGHTNESS | + MODE_FLAG_HAS_SPEED }, + {"Stars", STARS, 1, 5, 3, 0xFF, 0, 2, MODE_COLORS_MODE_SPECIFIC, MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | + MODE_FLAG_HAS_BRIGHTNESS | + MODE_FLAG_HAS_SPEED }, + {"Raindrops", RAINDROPS, 1, 5, 3, 0xFF, 0, 2, MODE_COLORS_MODE_SPECIFIC, MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | + MODE_FLAG_HAS_BRIGHTNESS | + MODE_FLAG_HAS_SPEED }, + {"Color Cycle", CYCLE, 1, 5, 3, 0xFF, 0, 0, MODE_COLORS_NONE, MODE_FLAG_HAS_BRIGHTNESS | + MODE_FLAG_HAS_SPEED }, + {"Breathing", BREATHE, 1, 5, 3, 0xFF, 0, 1, MODE_COLORS_MODE_SPECIFIC, MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | + MODE_FLAG_HAS_BRIGHTNESS | + MODE_FLAG_HAS_SPEED }, + {"Ripple", RIPPLE, 1, 5, 3, 0xFF, 0, 2, MODE_COLORS_MODE_SPECIFIC, MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | + MODE_FLAG_HAS_BRIGHTNESS | + MODE_FLAG_HAS_SPEED }, + {"Fireball", FIREBALL, 1, 5, 3, 0xFF, 0, 2, MODE_COLORS_MODE_SPECIFIC, MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | + MODE_FLAG_HAS_BRIGHTNESS | + MODE_FLAG_HAS_SPEED }, + {"Water Ripple",WATER_RIPPLE,1,5, 3, 0xFF, 0, 2, MODE_COLORS_MODE_SPECIFIC, MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | + MODE_FLAG_HAS_BRIGHTNESS | + MODE_FLAG_HAS_SPEED }, + {"Reactive Punch",REACTIVE_PUNCH,1,5,3, 0xFF, 0, 2, MODE_COLORS_MODE_SPECIFIC, MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | + MODE_FLAG_HAS_BRIGHTNESS | + MODE_FLAG_HAS_SPEED }, + {"Snowing", SNOW, 1, 5, 3, 0xFF, 0, 2, MODE_COLORS_MODE_SPECIFIC, MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | + MODE_FLAG_HAS_BRIGHTNESS | + MODE_FLAG_HAS_SPEED }, + {"Heartbeat", HEARTBEAT, 1, 5, 3, 0xFF, 0, 2, MODE_COLORS_MODE_SPECIFIC, MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | + MODE_FLAG_HAS_BRIGHTNESS | + MODE_FLAG_HAS_SPEED }, + {"Circle Spectrum",CIRCLE_SPECTRUM,1,5,3,0xFF, MODE_DIRECTION_LEFT,0, MODE_COLORS_NONE, MODE_FLAG_HAS_BRIGHTNESS | + MODE_FLAG_HAS_SPEED | + MODE_FLAG_HAS_DIRECTION_LR}, + {"Reactive Tornado",REACTIVE_TORNADO,1,5,3,0xFF,MODE_DIRECTION_LEFT,0, MODE_COLORS_NONE, MODE_FLAG_HAS_BRIGHTNESS | + MODE_FLAG_HAS_SPEED | + MODE_FLAG_HAS_DIRECTION_LR}, + {"Off", OFF, 0, 0, 0, 0xFF, MODE_DIRECTION_LEFT, 0, MODE_COLORS_NONE, 0}, + { 0, NONE, 0, 0, 0, 0, 0, 0, 0, 0}, +}; + +void CMKeyboardV2Controller::InitializeModes(std::vector &modes) +{ + stCMKeyboardV2_mode * pCurrentMode = CMKeyboardV2_modes; + + while (pCurrentMode->value != NONE) + { + mode m; + + m.name = std::string(pCurrentMode->name); + m.value = pCurrentMode->value; + m.flags = pCurrentMode->flags; + m.color_mode = pCurrentMode->color_mode; + m.speed_min = pCurrentMode->speed_min; + m.speed_max = pCurrentMode->speed_max; + m.speed = pCurrentMode->speed; + m.brightness_min = 0x00; + m.brightness_max = 0xFF; + m.brightness = 0xFF; + m.colors_min = pCurrentMode->nColors; + m.colors_max = pCurrentMode->nColors; + m.colors.resize(pCurrentMode->nColors); + m.direction = pCurrentMode->direction; + + modes.push_back(m); + + pCurrentMode++; + } +} diff --git a/Controllers/CoolerMasterController/CMKeyboardV2Controller.h b/Controllers/CoolerMasterController/CMKeyboardV2Controller.h new file mode 100644 index 00000000..9c2dd35c --- /dev/null +++ b/Controllers/CoolerMasterController/CMKeyboardV2Controller.h @@ -0,0 +1,54 @@ +/*-------------------------------------------------------------------*\ +| CMKeyboardV2Controller.h | +| | +| Driver for Coolermaster V2 | +| | +| Tam D (too.manyhobbies) 30th Nov 2023 | +| | +\*-------------------------------------------------------------------*/ +#include "CMKeyboardAbstractController.h" + +struct stCMKeyboardV2_mode +{ + const char *name; + unsigned int value; + unsigned int speed_min; + unsigned int speed_max; + unsigned int speed; + unsigned int brightness; + unsigned int direction; + unsigned int nColors; + unsigned int color_mode; + unsigned int flags; +}; + +class CMKeyboardV2Controller : public CMKeyboardAbstractController +{ +public: + CMKeyboardV2Controller(hid_device* dev_handle, hid_device_info* dev_info); + ~CMKeyboardV2Controller(); + + /*---------------------------------------------------------*\ + | Protocol specific funtions to be implmented | + \*---------------------------------------------------------*/ + void SetLeds(std::vector leds, std::vector colors); + void SetSingleLED(uint8_t in_led, RGBColor in_color); + void Initialize(); + void Shutdown(); + void SetLEDControl(bool bManual); + void SendApplyPacket(uint8_t mode); + void MagicStartupPacket(); + void MagicCommand(uint8_t profileId); + void SetCustomMode(); + void SetMode(mode selectedMode); + void SetEffect(uint8_t effectId, uint8_t p1, uint8_t p2, uint8_t p3, RGBColor color1, RGBColor color2); + void InitializeModes(std::vector &modes); + KEYBOARD_LAYOUT GetKeyboardLayout(); + +private: + void _SetEffectMode(uint8_t effectId); + void _UpdateSpeed(mode selectedMode, uint8_t &cSpeed1, uint8_t &cSpeed2); + std::string _GetFirmwareVersion(); + + bool m_bMoreFFs; +}; diff --git a/Controllers/CoolerMasterController/CMMKController.cpp b/Controllers/CoolerMasterController/CMMKController.cpp deleted file mode 100644 index efd6cbac..00000000 --- a/Controllers/CoolerMasterController/CMMKController.cpp +++ /dev/null @@ -1,320 +0,0 @@ -/*-------------------------------------------------------------------*\ -| CMMKController.cpp | -| | -| Lukas N (chmod222) 28th Jun 2020 | -| Tam D (too.manyhobbies) 25th Apr 2021 | -| | -\*-------------------------------------------------------------------*/ - -#include "CMMKController.h" - -CMMKController::CMMKController(hid_device* dev, hid_device_info* dev_info) -{ - location = dev_info->path; - - const int szTemp = 256; - wchar_t tmpName[szTemp]; - - hid_get_manufacturer_string(dev, tmpName, szTemp); - std::wstring wName = std::wstring(tmpName); - vendor_name = std::string(wName.begin(), wName.end()); - - hid_get_product_string(dev, tmpName, szTemp); - wName = std::wstring(tmpName); - device_name = std::string(wName.begin(), wName.end()); - - 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 = std::string(buf); - - enum cmmk_product_type kb_type = cmmk_get_device_model(&cmmk_handle); - - switch(kb_type) - { - case CMMK_PRODUCT_MASTERKEYS_PRO_S: - case CMMK_PRODUCT_MASTERKEYS_SK630: - kb_size = KEYBOARD_SIZE_TKL; - row_count = CMMK_ROWS_MAX - 1; - column_count = CMMK_COLS_MAX - 4; - break; - - case CMMK_PRODUCT_MASTERKEYS_PRO_L: - case CMMK_PRODUCT_MASTERKEYS_SK650: - kb_size = KEYBOARD_SIZE_FULL; - row_count = CMMK_ROWS_MAX - 1; - column_count = CMMK_COLS_MAX; - break; - - case CMMK_PRODUCT_MASTERKEYS_MK750: - default: - kb_size = KEYBOARD_SIZE_FULL; - row_count = CMMK_ROWS_MAX; - column_count = CMMK_COLS_MAX; - } - - /*--------------------------------------------------------------*\ - | Detect the keyboard version and set the appropriate layout. | - \*--------------------------------------------------------------*/ - - switch(firmware_version[0]) - { - case '1': - kb_layout_type = KEYBOARD_LAYOUT_ANSI_QWERTY; - break; - - /*--------------------------------------------------------------*\ - | In case we need to handle different versions in the future. | - \*--------------------------------------------------------------*/ - default: - kb_layout_type = KEYBOARD_LAYOUT_ISO_QWERTY; - break; - } - - /*--------------------------------------------------------------*\ - | Populate key offsets. | - \*--------------------------------------------------------------*/ - keyboard_layout* kb_layout; - if(KEYBOARD_LAYOUT_ANSI_QWERTY == kb_layout_type) - { - switch (kb_type) - { - case CMMK_PRODUCT_MASTERKEYS_PRO_L: - kb_layout = &layout_ansi_pro_l; - break; - case CMMK_PRODUCT_MASTERKEYS_PRO_S: - kb_layout = &layout_ansi_pro_s; - break; - case CMMK_PRODUCT_MASTERKEYS_MK750: - kb_layout = &layout_ansi_mk750; - break; - case CMMK_PRODUCT_MASTERKEYS_SK630: - kb_layout = &layout_ansi_sk630; - break; - case CMMK_PRODUCT_MASTERKEYS_SK650: - kb_layout = &layout_ansi_sk650; - break; - - default: - kb_layout = 0; - break; - } - } - else - { - switch (kb_type) - { - case CMMK_PRODUCT_MASTERKEYS_PRO_L: - kb_layout = &layout_iso_pro_l; - break; - case CMMK_PRODUCT_MASTERKEYS_PRO_S: - kb_layout = &layout_iso_pro_s; - break; - case CMMK_PRODUCT_MASTERKEYS_MK750: - kb_layout = &layout_iso_mk750; - break; - case CMMK_PRODUCT_MASTERKEYS_SK630: - kb_layout = &layout_iso_sk630; - break; - case CMMK_PRODUCT_MASTERKEYS_SK650: - kb_layout = &layout_iso_sk650; - break; - - default: - kb_layout = 0; - break; - } - } - - std::vector keys_fn, keys_main, keys_num, keys_extra; - - memset(&kb_transform, -1, row_count*column_count); - - int key_idx = 0; - if(kb_layout) - { - for(int row = 0; row < row_count; row++) - { - for(int col = 0; col < column_count; col++) - { - int val = (*kb_layout)[row][col]; - - if (-1 != val) - { - kb_offsets.ansi.push_back(val); - kb_transform[row][col] = key_idx; - key_idx++; - } - } - } - } -} - -CMMKController::~CMMKController() -{ - cmmk_detach(&cmmk_handle); -} - -std::string CMMKController::GetDeviceName() -{ - return device_name; -} - -std::string CMMKController::GetDeviceVendor() -{ - return vendor_name; -} - -std::string CMMKController::GetLocation() -{ - return location; -} - -std::string CMMKController::GetFirmwareVersion() -{ - return firmware_version; -} - -uint8_t CMMKController::GetRowCount() -{ - return row_count; -} - -uint8_t CMMKController::GetColumnCount() -{ - return column_count; -} - -KEYBOARD_LAYOUT CMMKController::GetLayout() -{ - return kb_layout_type; -} - -keyboard_layout * CMMKController::GetTransform() -{ - return &kb_transform; -} - -KEYBOARD_SIZE CMMKController::GetSize() -{ - return kb_size; -} - -layout_values CMMKController::GetLayoutValues() -{ - return kb_offsets; -} - -void CMMKController::SetFirmwareControl() -{ - ActivateMode(CMMK_FIRMWARE); -} - -void CMMKController::SetManualControl() -{ - ActivateMode(CMMK_MANUAL); -} - -void CMMKController::SetSingle(int row, int col, struct rgb color) -{ - cmmk_set_single_key(&cmmk_handle, row, col, &color); -} - -void CMMKController::SetAll(struct cmmk_color_matrix const& colors) -{ - cmmk_set_leds(&cmmk_handle, &colors); -} - -void CMMKController::SetAllSingle(struct rgb color) -{ - cmmk_set_all_single(&cmmk_handle, &color); -} - -void CMMKController::SetMode(cmmk_effect_fully_lit eff) -{ - ActivateEffect(CMMK_EFFECT_FULLY_LIT); - cmmk_set_effect_fully_lit(&cmmk_handle, &eff); -} - -void CMMKController::SetMode(cmmk_effect_breathe eff) -{ - ActivateEffect(CMMK_EFFECT_BREATHE); - cmmk_set_effect_breathe(&cmmk_handle, &eff); -} - -void CMMKController::SetMode(cmmk_effect_cycle eff) -{ - ActivateEffect(CMMK_EFFECT_CYCLE); - cmmk_set_effect_cycle(&cmmk_handle, &eff); -} - -void CMMKController::SetMode(cmmk_effect_single eff) -{ - ActivateEffect(CMMK_EFFECT_SINGLE); - cmmk_set_effect_single(&cmmk_handle, &eff); -} - -void CMMKController::SetMode(cmmk_effect_wave eff) -{ - ActivateEffect(CMMK_EFFECT_WAVE); - cmmk_set_effect_wave(&cmmk_handle, &eff); -} - -void CMMKController::SetMode(cmmk_effect_ripple eff) -{ - ActivateEffect(CMMK_EFFECT_RIPPLE); - cmmk_set_effect_ripple(&cmmk_handle, &eff); -} - -void CMMKController::SetMode(cmmk_effect_cross eff) -{ - ActivateEffect(CMMK_EFFECT_CROSS); - cmmk_set_effect_cross(&cmmk_handle, &eff); -} - -void CMMKController::SetMode(cmmk_effect_raindrops eff) -{ - ActivateEffect(CMMK_EFFECT_RAINDROPS); - cmmk_set_effect_raindrops(&cmmk_handle, &eff); -} - -void CMMKController::SetMode(cmmk_effect_stars eff) -{ - ActivateEffect(CMMK_EFFECT_STARS); - cmmk_set_effect_stars(&cmmk_handle, &eff); -} - -void CMMKController::SetMode(cmmk_effect_snake eff) -{ - 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) - { - cmmk_set_control_mode(&cmmk_handle, mode); - - current_mode = mode; - current_effect = -1; - } -} - -void CMMKController::ActivateEffect(int effect) -{ - ActivateMode(CMMK_EFFECT); - - if (current_effect != effect) - { - cmmk_set_active_effect(&cmmk_handle, (enum cmmk_effect_id)effect); - - current_effect = effect; - } -} diff --git a/Controllers/CoolerMasterController/CMMKController.h b/Controllers/CoolerMasterController/CMMKController.h deleted file mode 100644 index 2f132862..00000000 --- a/Controllers/CoolerMasterController/CMMKController.h +++ /dev/null @@ -1,97 +0,0 @@ -/*-------------------------------------------------------------------*\ -| CMMKController.h | -| | -| Driver for Coolermaster MasterKeys keyboards | -| | -| Lukas N (chmod222) 28th Jun 2020 | -| | -\*-------------------------------------------------------------------*/ - -#include -#include -#include -#include - -typedef int16_t keyboard_layout[CMMK_ROWS_MAX][CMMK_COLS_MAX]; - -/*---------------------------------------------------------*\ -| i'm not thrilled with the include path, but this will | -| work for now. fixing this would need to happen in libcmmk | -\*---------------------------------------------------------*/ -#pragma GCC push -#pragma GCC diagnostic ignored "-Wunused-variable" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#pragma GCC pop - -#pragma once - -class CMMKController -{ -public: - CMMKController(hid_device* dev_handle, hid_device_info* dev_info); - ~CMMKController(); - - std::string GetDeviceName(); - std::string GetDeviceVendor(); - std::string GetLocation(); - std::string GetFirmwareVersion(); - uint8_t GetRowCount(); - uint8_t GetColumnCount(); - - KEYBOARD_LAYOUT GetLayout(); - KEYBOARD_SIZE GetSize(); - layout_values GetLayoutValues(); - keyboard_layout* GetTransform(); - - void SetFirmwareControl(); - void SetManualControl(); - - void SetSingle(int row, int col, struct rgb color); - void SetAll(struct cmmk_color_matrix const& colors); - void SetAllSingle(struct rgb color); - - void SetMode(cmmk_effect_fully_lit eff); - void SetMode(cmmk_effect_breathe eff); - void SetMode(cmmk_effect_cycle eff); - void SetMode(cmmk_effect_single eff); - void SetMode(cmmk_effect_wave eff); - void SetMode(cmmk_effect_ripple eff); - void SetMode(cmmk_effect_cross eff); - void SetMode(cmmk_effect_raindrops eff); - void SetMode(cmmk_effect_stars eff); - void SetMode(cmmk_effect_snake eff); - - bool PositionValid(int y, int x); - -private: - void ActivateMode(int mode); - void ActivateEffect(int effect); - - int current_mode = -1; - int current_effect = -1; - - std::string device_name; - std::string vendor_name; - std::string location; - std::string firmware_version; - - KEYBOARD_SIZE kb_size; - KEYBOARD_LAYOUT kb_layout_type; - layout_values kb_offsets; - keyboard_layout kb_transform; - keyboard_layout* kb_layout; - - uint8_t row_count; - uint8_t column_count; - - mutable struct cmmk cmmk_handle; -}; diff --git a/Controllers/CoolerMasterController/CoolerMasterControllerDetect.cpp b/Controllers/CoolerMasterController/CoolerMasterControllerDetect.cpp index aa5326cc..f4f75b2b 100644 --- a/Controllers/CoolerMasterController/CoolerMasterControllerDetect.cpp +++ b/Controllers/CoolerMasterController/CoolerMasterControllerDetect.cpp @@ -17,8 +17,9 @@ #include "RGBController_CMARGBGen2A1Controller.h" #include "RGBController_CMRGBController.h" #include "RGBController_CMR6000Controller.h" -#include "RGBController_CMMKController.h" #include "RGBController_CMMonitorController.h" +#include "RGBController_CMKeyboardController.h" + /*-----------------------------------------------------*\ | Coolermaster USB vendor ID | \*-----------------------------------------------------*/ @@ -26,13 +27,8 @@ /*-----------------------------------------------------*\ | Coolermaster Keyboards | +| PIDs defined in `CMMKControllerV2.h` | \*-----------------------------------------------------*/ -#define COOLERMASTER_MASTERKEYS_PRO_L_PID 0x003B -#define COOLERMASTER_MASTERKEYS_PRO_L_WHITE_PID 0x0047 -#define COOLERMASTER_MASTERKEYS_PRO_S_PID 0x003C -#define COOLERMASTER_MASTERKEYS_MK750_PID 0x0067 -#define COOLERMASTER_MASTERKEYS_SK630_PID 0x0089 -#define COOLERMASTER_MASTERKEYS_SK650_PID 0x008D /*-----------------------------------------------------*\ | Coolermaster GPUs | @@ -125,16 +121,75 @@ void DetectCoolerMasterGPU(hid_device_info* info, const std::string&) } } -void DetectCoolerMasterKeyboards(hid_device_info* info, const std::string&) +void DetectCoolerMasterV1Keyboards(hid_device_info* info, const std::string& name) { hid_device* dev = hid_open_path(info->path); if(dev) { - CMMKController* controller = new CMMKController(dev, info); - RGBController_CMMKController* rgb_controller = new RGBController_CMMKController(controller); - // Constructor sets the name - ResourceManager::get()->RegisterRGBController(rgb_controller); + switch(info->product_id) + { + case COOLERMASTER_KEYBOARD_PRO_L_PID: + case COOLERMASTER_KEYBOARD_PRO_L_WHITE_PID: + case COOLERMASTER_KEYBOARD_PRO_S_PID: + { + CMKeyboardV1Controller* controller = new CMKeyboardV1Controller(dev, info); + controller->SetDeviceName(name); + RGBController_CMKeyboardController* rgb_controller = new RGBController_CMKeyboardController(controller); + ResourceManager::get()->RegisterRGBController(rgb_controller); + } + break; + + default: + + LOG_DEBUG("[%s] Controller not created as the product ID %04X is missing from detector switch", name.c_str(), info->product_id); + break; + } + } +} + +void DetectCoolerMasterV2Keyboards(hid_device_info* info, const std::string& name) +{ + hid_device* dev = hid_open_path(info->path); + + if(dev) + { + switch(info->product_id) + { + case COOLERMASTER_KEYBOARD_PRO_L_PID: + case COOLERMASTER_KEYBOARD_PRO_L_WHITE_PID: + case COOLERMASTER_KEYBOARD_PRO_S_PID: + { + CMKeyboardV1Controller* controller = new CMKeyboardV1Controller(dev, info); + controller->SetDeviceName(name); + RGBController_CMKeyboardController* rgb_controller = new RGBController_CMKeyboardController(controller); + ResourceManager::get()->RegisterRGBController(rgb_controller); + } + break; + + case COOLERMASTER_KEYBOARD_SK622B_PID: + case COOLERMASTER_KEYBOARD_SK622W_PID: + case COOLERMASTER_KEYBOARD_SK630_PID: + case COOLERMASTER_KEYBOARD_SK650_PID: + case COOLERMASTER_KEYBOARD_SK652_PID: + case COOLERMASTER_KEYBOARD_SK653_PID: + case COOLERMASTER_KEYBOARD_CK530_PID: + case COOLERMASTER_KEYBOARD_CK530_V2_PID: + case COOLERMASTER_KEYBOARD_CK550_V2_PID: + case COOLERMASTER_KEYBOARD_CK552_V2_PID: + case COOLERMASTER_KEYBOARD_MK730_PID: + case COOLERMASTER_KEYBOARD_MK750_PID: + { + CMKeyboardV2Controller* controller = new CMKeyboardV2Controller(dev, info); + controller->SetDeviceName(name); + RGBController_CMKeyboardController* rgb_controller = new RGBController_CMKeyboardController(controller); + ResourceManager::get()->RegisterRGBController(rgb_controller); + } + + default: + LOG_DEBUG("[%s] Controller not created as the product ID %04X is missing from detector switch", name.c_str(), info->product_id); + break; + } } } @@ -227,13 +282,24 @@ void DetectCoolerMasterMonitor(hid_device_info* info, const std::string& name) /*-----------------------------------------------------*\ | Coolermaster Keyboards | +| PIDs defined in `CMKeyboardDevices.h` | \*-----------------------------------------------------*/ -REGISTER_HID_DETECTOR_IPU("Cooler Master MasterKeys Pro L", DetectCoolerMasterKeyboards, COOLERMASTER_VID, COOLERMASTER_MASTERKEYS_PRO_L_PID, 1, 0xFF00, 1); -REGISTER_HID_DETECTOR_IPU("Cooler Master MasterKeys Pro L White", DetectCoolerMasterKeyboards, COOLERMASTER_VID, COOLERMASTER_MASTERKEYS_PRO_L_WHITE_PID, 1, 0xFF00, 1); -REGISTER_HID_DETECTOR_IPU("Cooler Master MasterKeys Pro S", DetectCoolerMasterKeyboards, COOLERMASTER_VID, COOLERMASTER_MASTERKEYS_PRO_S_PID, 1, 0xFF00, 1); -REGISTER_HID_DETECTOR_IPU("Cooler Master MK750", DetectCoolerMasterKeyboards, COOLERMASTER_VID, COOLERMASTER_MASTERKEYS_MK750_PID, 1, 0xFF00, 1); -REGISTER_HID_DETECTOR_IPU("Cooler Master SK630", DetectCoolerMasterKeyboards, COOLERMASTER_VID, COOLERMASTER_MASTERKEYS_SK630_PID, 1, 0xFF00, 1); -REGISTER_HID_DETECTOR_IPU("Cooler Master SK650", DetectCoolerMasterKeyboards, COOLERMASTER_VID, COOLERMASTER_MASTERKEYS_SK650_PID, 1, 0xFF00, 1); +REGISTER_HID_DETECTOR_IPU("Cooler Master MasterKeys Pro S", DetectCoolerMasterV1Keyboards, COOLERMASTER_VID, COOLERMASTER_KEYBOARD_PRO_S_PID, 1, 0xFF00, 1); +REGISTER_HID_DETECTOR_IPU("Cooler Master MasterKeys Pro L", DetectCoolerMasterV1Keyboards, COOLERMASTER_VID, COOLERMASTER_KEYBOARD_PRO_L_PID, 1, 0xFF00, 1); +REGISTER_HID_DETECTOR_IPU("Cooler Master MasterKeys Pro L White", DetectCoolerMasterV1Keyboards, COOLERMASTER_VID, COOLERMASTER_KEYBOARD_PRO_L_WHITE_PID, 1, 0xFF00, 1); +REGISTER_HID_DETECTOR_IPU("Cooler Master MK850", DetectCoolerMasterV2Keyboards, COOLERMASTER_VID, COOLERMASTER_KEYBOARD_MK850_PID, 1, 0xFF00, 1); +REGISTER_HID_DETECTOR_IPU("Cooler Master SK622 White", DetectCoolerMasterV2Keyboards, COOLERMASTER_VID, COOLERMASTER_KEYBOARD_SK622W_PID, 1, 0xFF00, 1); +REGISTER_HID_DETECTOR_IPU("Cooler Master SK622 Black", DetectCoolerMasterV2Keyboards, COOLERMASTER_VID, COOLERMASTER_KEYBOARD_SK622B_PID, 1, 0xFF00, 1); +REGISTER_HID_DETECTOR_IPU("Cooler Master SK630", DetectCoolerMasterV2Keyboards, COOLERMASTER_VID, COOLERMASTER_KEYBOARD_SK630_PID, 1, 0xFF00, 1); +REGISTER_HID_DETECTOR_IPU("Cooler Master SK650", DetectCoolerMasterV2Keyboards, COOLERMASTER_VID, COOLERMASTER_KEYBOARD_SK650_PID, 1, 0xFF00, 1); +REGISTER_HID_DETECTOR_IPU("Cooler Master SK652", DetectCoolerMasterV2Keyboards, COOLERMASTER_VID, COOLERMASTER_KEYBOARD_SK652_PID, 1, 0xFF00, 1); +REGISTER_HID_DETECTOR_IPU("Cooler Master SK653", DetectCoolerMasterV2Keyboards, COOLERMASTER_VID, COOLERMASTER_KEYBOARD_SK653_PID, 1, 0xFF00, 1); +REGISTER_HID_DETECTOR_IPU("Cooler Master MK730", DetectCoolerMasterV2Keyboards, COOLERMASTER_VID, COOLERMASTER_KEYBOARD_MK730_PID, 1, 0xFF00, 1); +REGISTER_HID_DETECTOR_IPU("Cooler Master MK750", DetectCoolerMasterV2Keyboards, COOLERMASTER_VID, COOLERMASTER_KEYBOARD_MK750_PID, 1, 0xFF00, 1); +REGISTER_HID_DETECTOR_IPU("Cooler Master CK530", DetectCoolerMasterV2Keyboards, COOLERMASTER_VID, COOLERMASTER_KEYBOARD_CK530_PID, 1, 0xFF00, 1); +REGISTER_HID_DETECTOR_IPU("Cooler Master CK530 V2", DetectCoolerMasterV2Keyboards, COOLERMASTER_VID, COOLERMASTER_KEYBOARD_CK530_V2_PID, 1, 0xFF00, 1); +REGISTER_HID_DETECTOR_IPU("Cooler Master CK550 V2", DetectCoolerMasterV2Keyboards, COOLERMASTER_VID, COOLERMASTER_KEYBOARD_CK550_V2_PID, 1, 0xFF00, 1); +REGISTER_HID_DETECTOR_IPU("Cooler Master CK550 V1 / CK552", DetectCoolerMasterV2Keyboards, COOLERMASTER_VID, COOLERMASTER_KEYBOARD_CK552_V2_PID, 1, 0xFF00, 1); /*-----------------------------------------------------*\ | Coolermaster LEDstrip controllers | diff --git a/Controllers/CoolerMasterController/RGBController_CMKeyboardController.cpp b/Controllers/CoolerMasterController/RGBController_CMKeyboardController.cpp new file mode 100644 index 00000000..1f5c5968 --- /dev/null +++ b/Controllers/CoolerMasterController/RGBController_CMKeyboardController.cpp @@ -0,0 +1,185 @@ +/*-------------------------------------------------------------------*\ +| RGBController_CMKeyboardController.cpp | +| | +| Controller for Coolermaster keyboards | +| | +| Tam D (too.manyhobbies) 30th Nov 2023 | +| | +\*-------------------------------------------------------------------*/ +#include "RGBController_CMKeyboardController.h" +#include "CMKeyboardDevices.h" + +/**------------------------------------------------------------------*\ + @name Coolermaster Masterkeys Keyboards + @category Keyboard + @type USB + @save :robot: + @direct :white_check_mark: + @effects :white_check_mark: + @detectors DetectCoolerMasterKeyboards + @comment + In CMKeyboardV1Controller brightness control not supported. + Supported effects differ between CMKeyboardV1Controller and + CMKeyboardV2Controller. +\*-------------------------------------------------------------------*/ +RGBController_CMKeyboardController::RGBController_CMKeyboardController(CMKeyboardAbstractController* pController) +{ + m_pController = pController; + vendor = m_pController->GetDeviceVendor(); + type = DEVICE_TYPE_KEYBOARD; + description = "Cooler Master Keyboard Device"; + version = m_pController->GetFirmwareVersion(); + + /*----------------------------------------------------------------*\ + | Coolermaster uses the name field to store the serial number in | + | many of their keyboards. | + \*----------------------------------------------------------------*/ + serial = m_pController->GetDeviceSerial(); + location = m_pController->GetLocation(); + m_keyboardLayout = m_pController->GetKeyboardLayout(); + name = m_pController->GetDeviceName(); + + m_pController->InitializeModes(modes); + + SetupZones(); +} + +RGBController_CMKeyboardController::~RGBController_CMKeyboardController() +{ + for(size_t i = 0; i < m_pUnknownKeyNames.size(); i++) + { + if(m_pUnknownKeyNames[i]) + { + delete(m_pUnknownKeyNames[i]); + } + } + + delete m_pLayoutManager; +} + +#include +#define COOLERMASTER_ZONES_MAX 1 +void RGBController_CMKeyboardController::SetupZones() +{ + std::string physical_size; + unsigned int max_led_value = 0; + const cm_kb_device* coolermaster = m_pController->GetDeviceData(); + + /*---------------------------------------------------------*\ + | Fill in zones from the device data | + \*---------------------------------------------------------*/ + for(size_t i = 0; i < COOLERMASTER_ZONES_MAX; i++) + { + if(coolermaster->zones[i] == NULL) + { + break; + } + else + { + zone new_zone; + + new_zone.name = coolermaster->zones[i]->name; + new_zone.type = coolermaster->zones[i]->type; + + if(new_zone.type == ZONE_TYPE_MATRIX) + { + KeyboardLayoutManager new_kb(m_keyboardLayout, coolermaster->layout_new->base_size, coolermaster->layout_new->key_values); + + matrix_map_type * new_map = new matrix_map_type; + new_zone.matrix_map = new_map; + + new_map->map = new unsigned int[new_map->height * new_map->width]; + + if(coolermaster->layout_new->base_size != KEYBOARD_SIZE_EMPTY) + { + /*---------------------------------------------------------*\ + | Minor adjustments to keyboard layout | + \*---------------------------------------------------------*/ + keyboard_keymap_overlay_values* temp = coolermaster->layout_new; + new_kb.ChangeKeys(*temp); + + new_map->height = new_kb.GetRowCount(); + new_map->width = new_kb.GetColumnCount(); + + /*---------------------------------------------------------*\ + | Matrix map still uses declared zone rows and columns | + | as the packet structure depends on the matrix map | + \*---------------------------------------------------------*/ + new_kb.GetKeyMap(new_map->map, KEYBOARD_MAP_FILL_TYPE_COUNT, new_map->height, new_map->width); + + /*---------------------------------------------------------*\ + | Create LEDs for the Matrix zone | + | Place keys in the layout to populate the matrix | + \*---------------------------------------------------------*/ + new_zone.leds_count = new_kb.GetKeyCount(); + LOG_DEBUG("[%s] Created KB matrix with %d rows and %d columns containing %d keys", + m_pController->GetDeviceName().c_str(), new_kb.GetRowCount(), new_kb.GetColumnCount(), new_zone.leds_count); + + for(size_t led_idx = 0; led_idx < new_zone.leds_count; led_idx++) + { + led new_led; + + new_led.name = new_kb.GetKeyNameAt(led_idx); + new_led.value = new_kb.GetKeyValueAt(led_idx); + max_led_value = std::max(max_led_value, new_led.value); + leds.push_back(new_led); + } + } + + /*---------------------------------------------------------*\ + | Add 1 the max_led_value to account for the 0th index | + \*---------------------------------------------------------*/ + max_led_value++; + } + + /*---------------------------------------------------------*\ + | name is not set yet so description is used instead | + \*---------------------------------------------------------*/ + LOG_DEBUG("[%s] Creating a %s zone: %s with %d LEDs", description.c_str(), + ((new_zone.type == ZONE_TYPE_MATRIX) ? "matrix": "linear"), + new_zone.name.c_str(), new_zone.leds_count); + new_zone.leds_min = new_zone.leds_count; + new_zone.leds_max = new_zone.leds_count; + zones.push_back(new_zone); + + } + } + + + SetupColors(); +} + +void RGBController_CMKeyboardController::ResizeZone(int /*zone*/, int /*new_size*/) +{ +} + +void RGBController_CMKeyboardController::DeviceUpdateLEDs() +{ + m_pController->SetLeds(leds, colors); +} + +void RGBController_CMKeyboardController::UpdateSingleLED(int led, RGBColor color) +{ + uint8_t key_value = m_pLayoutManager->GetKeyValueAt(led); + m_pController->SetSingleLED(key_value, color); +} + +void RGBController_CMKeyboardController::UpdateSingleLED(int led) +{ + m_pController->SetSingleLED(led, colors[led]); +} + +void RGBController_CMKeyboardController::UpdateZoneLEDs(int /*zone_idx*/) +{ + DeviceUpdateLEDs(); +} + +void RGBController_CMKeyboardController::DeviceUpdateMode() +{ + m_pController->SetMode(modes[active_mode]); +} + +void RGBController_CMKeyboardController::SetCustomMode() +{ + +} diff --git a/Controllers/CoolerMasterController/RGBController_CMKeyboardController.h b/Controllers/CoolerMasterController/RGBController_CMKeyboardController.h new file mode 100644 index 00000000..b863045b --- /dev/null +++ b/Controllers/CoolerMasterController/RGBController_CMKeyboardController.h @@ -0,0 +1,41 @@ +/*-------------------------------------------------------------------*\ +| RGBController_CMKeyboardController.h | +| | +| Controller for Coolermaster keyboards | +| | +| Tam D (too.manyhobbies) 30th Nov 2023 | +| | +\*-------------------------------------------------------------------*/ +#pragma once + +#include "RGBController.h" +#include "CMKeyboardAbstractController.h" +#include "CMKeyboardV1Controller.h" +#include "CMKeyboardV2Controller.h" +#include "CMKeyboardDevices.h" + +class RGBController_CMKeyboardController : public RGBController +{ +public: + RGBController_CMKeyboardController(CMKeyboardAbstractController* pController); + ~RGBController_CMKeyboardController(); + + void SetupZones(); + void ResizeZone(int zone, int new_size); + + void DeviceUpdateLEDs(); + void UpdateSingleLED(int led, RGBColor color); + void UpdateSingleLED(int led); + void UpdateZoneLEDs(int zone_idx); + + void SetCustomMode(); + void DeviceUpdateMode(); + +private: + CMKeyboardAbstractController* m_pController;; + KeyboardLayoutManager* m_pLayoutManager; + KEYBOARD_LAYOUT m_keyboardLayout; + KEYBOARD_SIZE m_keyboardSize; + layout_values m_layoutValues; + std::vector m_pUnknownKeyNames; +}; diff --git a/Controllers/CoolerMasterController/RGBController_CMMKController.cpp b/Controllers/CoolerMasterController/RGBController_CMMKController.cpp deleted file mode 100644 index 4e26d1ba..00000000 --- a/Controllers/CoolerMasterController/RGBController_CMMKController.cpp +++ /dev/null @@ -1,503 +0,0 @@ -/*-------------------------------------------------------------------*\ -| RGBController_CMMKController.cpp | -| | -| Driver for Coolermaster MasterKeys keyboards | -| | -| Lukas N (chmod222) 28th Jun 2020 | -| Tam D (too.manyhobbies) 25th Apr 2021 | -| | -\*-------------------------------------------------------------------*/ - -#include "RGBController_CMMKController.h" - -#include - -using namespace std::chrono_literals; - -#define CMMK_SPEED_MIN CMMK_SPEED0 -#define CMMK_SPEED_MID CMMK_SPEED2 -#define CMMK_SPEED_MAX CMMK_SPEED4 -#define CMMK_MODE_FIRMWARE 0xFF -#define CMMK_MODE_MANUAL 0x7F - -/**------------------------------------------------------------------*\ - @name Coolermaster Masterkeys Keyboards - @category Keyboard - @type USB - @save :robot: - @direct :white_check_mark: - @effects :white_check_mark: - @detectors DetectCoolerMasterKeyboards - @comment -\*-------------------------------------------------------------------*/ - -RGBController_CMMKController::RGBController_CMMKController(CMMKController* controller_ptr) -{ - controller = controller_ptr; - name = controller->GetDeviceName(); - vendor = controller->GetDeviceVendor(); - type = DEVICE_TYPE_KEYBOARD; - description = "Cooler Master MasterKeys Device"; - version = controller->GetFirmwareVersion(); - serial = ""; - location = controller->GetLocation(); - - mode Direct; - Direct.name = "Direct"; - Direct.value = CMMK_MODE_MANUAL; - Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR; - Direct.color_mode = MODE_COLORS_PER_LED; - modes.push_back(Direct); - - mode Static; - Static.name = "Static"; - Static.value = CMMK_EFFECT_FULLY_LIT; - Static.flags = MODE_FLAG_HAS_MODE_SPECIFIC_COLOR; - Static.color_mode = MODE_COLORS_MODE_SPECIFIC; - Static.colors_min = 1; - Static.colors_max = 1; - Static.colors.resize(1); - modes.push_back(Static); - - mode Breathing; - Breathing.name = "Breathing"; - Breathing.value = CMMK_EFFECT_BREATHE; - Breathing.flags = MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_SPEED; - Breathing.color_mode = MODE_COLORS_MODE_SPECIFIC; - Breathing.speed_min = CMMK_SPEED_MIN; - Breathing.speed_max = CMMK_SPEED_MAX; - Breathing.speed = CMMK_SPEED_MID; - Breathing.colors_min = 1; - Breathing.colors_max = 1; - Breathing.colors.resize(1); - modes.push_back(Breathing); - - mode Cycle; - Cycle.name = "Spectrum Cycle"; - Cycle.value = CMMK_EFFECT_CYCLE; - Cycle.flags = MODE_FLAG_HAS_SPEED; - Cycle.color_mode = MODE_COLORS_NONE; - Cycle.speed_min = 2 * CMMK_SPEED_MIN; //Spectrum Cycle uses a unique speed range - Cycle.speed_max = 2 * CMMK_SPEED_MAX; - Cycle.speed = 2 * CMMK_SPEED_MID; - modes.push_back(Cycle); - - mode Reactive; - Reactive.name = "Reactive"; - Reactive.value = CMMK_EFFECT_SINGLE; - Reactive.flags = MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_SPEED; - Reactive.color_mode = MODE_COLORS_MODE_SPECIFIC; - Reactive.speed_min = CMMK_SPEED_MIN; - Reactive.speed_max = CMMK_SPEED_MAX; - Reactive.speed = CMMK_SPEED_MID; - Reactive.colors_min = 2; - Reactive.colors_max = 2; - Reactive.colors.resize(2); - modes.push_back(Reactive); - - mode Wave; - Wave.name = "Rainbow Wave"; - Wave.value = CMMK_EFFECT_WAVE; - Wave.flags = MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_DIRECTION_LR | MODE_FLAG_HAS_DIRECTION_UD; - Wave.color_mode = MODE_COLORS_MODE_SPECIFIC; - Wave.speed_min = CMMK_SPEED_MIN; - Wave.speed_max = CMMK_SPEED_MAX; - Wave.speed = CMMK_SPEED_MID; - Wave.direction = MODE_DIRECTION_LEFT; - Wave.colors_min = 1; - Wave.colors_max = 1; - Wave.colors.resize(1); - modes.push_back(Wave); - - mode Ripple; - Ripple.name = "Ripple Effect"; - Ripple.value = CMMK_EFFECT_RIPPLE; - Ripple.flags = MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_RANDOM_COLOR | MODE_FLAG_HAS_SPEED; - Ripple.color_mode = MODE_COLORS_MODE_SPECIFIC; - Ripple.speed_min = CMMK_SPEED_MIN; - Ripple.speed_max = CMMK_SPEED_MAX; - Ripple.speed = CMMK_SPEED_MID; - Ripple.colors_min = 2; - Ripple.colors_max = 2; - Ripple.colors.resize(2); - modes.push_back(Ripple); - - mode Cross; - Cross.name = "Cross"; - Cross.value = CMMK_EFFECT_CROSS; - Cross.flags = MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_SPEED; - Cross.color_mode = MODE_COLORS_MODE_SPECIFIC; - Cross.speed_min = CMMK_SPEED_MIN; - Cross.speed_max = CMMK_SPEED_MAX; - Cross.speed = CMMK_SPEED_MID; - Cross.colors_min = 2; - Cross.colors_max = 2; - Cross.colors.resize(2); - modes.push_back(Cross); - - mode Raindrops; - Raindrops.name = "Raindrops"; - Raindrops.value = CMMK_EFFECT_RAINDROPS; - Raindrops.flags = MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_SPEED; - Raindrops.color_mode = MODE_COLORS_MODE_SPECIFIC; - Raindrops.speed_min = CMMK_SPEED_MIN; - Raindrops.speed_max = CMMK_SPEED_MAX; - Raindrops.speed = CMMK_SPEED_MID; - Raindrops.colors_min = 2; - Raindrops.colors_max = 2; - Raindrops.colors.resize(2); - modes.push_back(Raindrops); - - mode Stars; - Stars.name = "Starfield"; - Stars.value = CMMK_EFFECT_STARS; - Stars.flags = MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_SPEED; - Stars.color_mode = MODE_COLORS_MODE_SPECIFIC; - Stars.speed_min = CMMK_SPEED_MIN; - Stars.speed_max = CMMK_SPEED_MAX; - Stars.speed = CMMK_SPEED_MID; - Stars.colors_min = 2; - Stars.colors_max = 2; - Stars.colors.resize(2); - modes.push_back(Stars); - - mode Snake; - Snake.name = "Snake"; - Snake.value = CMMK_EFFECT_SNAKE; - Snake.flags = MODE_FLAG_HAS_SPEED; - Snake.color_mode = MODE_COLORS_NONE; - Snake.speed_min = CMMK_SPEED_MIN; - Snake.speed_max = CMMK_SPEED_MAX; - Snake.speed = CMMK_SPEED_MID; - modes.push_back(Snake); - - mode FirmwareControl; - FirmwareControl.name = "Firmware Controlled"; - FirmwareControl.value = 0xFF; - FirmwareControl.flags = 0; - FirmwareControl.color_mode = MODE_COLORS_NONE; - modes.push_back(FirmwareControl); - - SetupZones(); -} - -RGBController_CMMKController::~RGBController_CMMKController() -{ - delete controller; -} - -void RGBController_CMMKController::SetupZones() -{ - /*---------------------------------------------------------*\ - | Create the keyboard zone usiung Keyboard Layout Manager | - \*---------------------------------------------------------*/ - zone new_zone; - new_zone.name = ZONE_EN_KEYBOARD; - new_zone.type = ZONE_TYPE_MATRIX; - - layoutManager = new KeyboardLayoutManager(controller->GetLayout(), controller->GetSize(), controller->GetLayoutValues()); - - matrix_map_type * new_map = new matrix_map_type; - new_zone.matrix_map = new_map; - new_zone.matrix_map->height = layoutManager->GetRowCount(); - new_zone.matrix_map->width = layoutManager->GetColumnCount(); - - new_zone.matrix_map->map = new unsigned int[new_map->height * new_map->width]; - new_zone.leds_count = layoutManager->GetKeyCount(); - new_zone.leds_min = new_zone.leds_count; - new_zone.leds_max = new_zone.leds_count; - - /*---------------------------------------------------------*\ - | Matrix map still uses declared zone rows and columns | - | as the packet structure depends on the matrix map | - \*---------------------------------------------------------*/ - layoutManager->GetKeyMap(new_map->map, KEYBOARD_MAP_FILL_TYPE_COUNT, new_map->height, new_map->width); - - /*---------------------------------------------------------*\ - | Create LEDs for the Matrix zone | - | Place keys in the layout to populate the matrix | - \*---------------------------------------------------------*/ - for(size_t led_idx = 0; led_idx < new_zone.leds_count; led_idx++) - { - led new_led; - - new_led.name = layoutManager->GetKeyNameAt(led_idx); - new_led.value = layoutManager->GetKeyValueAt(led_idx); - leds.push_back(new_led); - } - - zones.push_back(new_zone); - - SetupColors(); -} - -void RGBController_CMMKController::ResizeZone(int /*zone*/, int /*new_size*/) -{ - /*---------------------------------------------------------*\ - | This device does not support resizing zones | - \*---------------------------------------------------------*/ -} - -struct rgb map_to_cmmk_rgb(RGBColor input) -{ - return rgb - { - (uint8_t)RGBGetRValue(input), - (uint8_t)RGBGetGValue(input), - (uint8_t)RGBGetBValue(input) - }; -} - -enum cmmk_wave_direction map_to_cmmk_dir(int input) -{ - switch(input) - { - case MODE_DIRECTION_LEFT: - return CMMK_RIGHT_TO_LEFT; - - case MODE_DIRECTION_RIGHT: - return CMMK_LEFT_TO_RIGHT; - - case MODE_DIRECTION_UP: - return CMMK_FRONT_TO_BACK; - - case MODE_DIRECTION_DOWN: - return CMMK_BACK_TO_FRONT; - - default: - return CMMK_RIGHT_TO_LEFT; - } -} - - -void RGBController_CMMKController::copy_buffers(std::vector &in_colors, struct cmmk_color_matrix& mat, std::atomic& dirty) -{ - dirty.store(false); - - keyboard_layout * transform = controller->GetTransform(); - - if(0 == transform) - { - return; - } - - for(int row = 0; row < controller->GetRowCount(); row++) - { - for(int col = 0; col < controller->GetColumnCount(); col++) - { - int key_idx = (*transform)[row][col]; - - if(-1 == key_idx) - { - continue; - } - - struct rgb color = map_to_cmmk_rgb(in_colors[key_idx]); - - dirty.store(true); - mat.data[row][col] = color; - } - } -} - -void RGBController_CMMKController::DeviceUpdateLEDs() -{ - copy_buffers(colors, current_matrix, dirty); - - if(force_update.load() || dirty.load()) - { - controller->SetAll(current_matrix); - - force_update.store(false); - } -} - -void RGBController_CMMKController::UpdateZoneLEDs(int zone_idx) -{ - /*---------------------------------------------------------*\ - | This device only supports a single zone, as a result we | - | update all LEDs. | - \*---------------------------------------------------------*/ - DeviceUpdateLEDs(); -} - -void RGBController_CMMKController::UpdateSingleLED(int led_idx, RGBColor color) -{ - keyboard_layout * transform = controller->GetTransform(); - led selected_led = leds[led_idx]; - - if(0 == transform) - { - return; - } - - // this is really expensive - for(int row = 0; row < controller->GetRowCount(); row++) - { - for(int col = 0; col < controller->GetColumnCount(); col++) - { - int val = (*transform)[row][col]; - - if(val != (int)selected_led.value) - { - continue; - } - - controller->SetSingle(row, col, map_to_cmmk_rgb(color)); - dirty.store(false); - - return; - } - } - -} - -void RGBController_CMMKController::UpdateSingleLED(int led_idx) -{ - UpdateSingleLED(led_idx, colors[led_idx]); -} - -void RGBController_CMMKController::SetCustomMode() -{ - active_mode = 1; -} - -void RGBController_CMMKController::DeviceUpdateMode() -{ - force_update.store(true); - - switch(modes[active_mode].value) - { - case CMMK_MODE_FIRMWARE: - controller->SetFirmwareControl(); - break; - - case CMMK_MODE_MANUAL: - controller->SetManualControl(); - break; - - case CMMK_EFFECT_FULLY_LIT: - { - cmmk_effect_fully_lit fully_lit_effect; - - fully_lit_effect.color = map_to_cmmk_rgb(modes[active_mode].colors[0]); - - controller->SetMode(fully_lit_effect); - } - break; - - case CMMK_EFFECT_BREATHE: - { - cmmk_effect_breathe breathe_effect; - - breathe_effect.speed = (uint8_t)modes[active_mode].speed; - breathe_effect.color = map_to_cmmk_rgb(modes[active_mode].colors[0]); - - controller->SetMode(breathe_effect); - } - break; - - case CMMK_EFFECT_CYCLE: - { - cmmk_effect_cycle cycle_effect; - - cycle_effect.speed = (uint8_t)modes[active_mode].speed; - - controller->SetMode(cycle_effect); - } - break; - - case CMMK_EFFECT_SINGLE: - { - cmmk_effect_single single_effect; - - single_effect.speed = (uint8_t)modes[active_mode].speed; - single_effect.active = map_to_cmmk_rgb(modes[active_mode].colors[0]); - single_effect.rest = map_to_cmmk_rgb(modes[active_mode].colors[1]); - - controller->SetMode(single_effect); - } - break; - - case CMMK_EFFECT_WAVE: - { - cmmk_effect_wave wave_effect; - - wave_effect.speed = (uint8_t)modes[active_mode].speed; - wave_effect.direction = map_to_cmmk_dir(modes[active_mode].direction); - wave_effect.start = map_to_cmmk_rgb(modes[active_mode].colors[0]); - - controller->SetMode(wave_effect); - } - break; - - case CMMK_EFFECT_RIPPLE: - { - cmmk_effect_ripple ripple_effect; - - ripple_effect.speed = (uint8_t)modes[active_mode].speed; - ripple_effect.active = map_to_cmmk_rgb(modes[active_mode].colors[0]); - ripple_effect.rest = map_to_cmmk_rgb(modes[active_mode].colors[1]); - - if(modes[active_mode].color_mode == MODE_COLORS_RANDOM) - { - ripple_effect.ripple_type = CMMK_RIPPLE_RANDOM_COLOR; - } - else - { - ripple_effect.ripple_type = CMMK_RIPPLE_GIVEN_COLOR; - } - - controller->SetMode(ripple_effect); - } - break; - - case CMMK_EFFECT_CROSS: - { - cmmk_effect_cross cross_effect; - - cross_effect.speed = (uint8_t)modes[active_mode].speed; - cross_effect.active = map_to_cmmk_rgb(modes[active_mode].colors[0]); - cross_effect.rest = map_to_cmmk_rgb(modes[active_mode].colors[1]); - - controller->SetMode(cross_effect); - } - break; - - case CMMK_EFFECT_RAINDROPS: - { - cmmk_effect_raindrops raindrops_effect; - - raindrops_effect.speed = (uint8_t)modes[active_mode].speed; - raindrops_effect.interval = CMMK_SPEED_MID; - raindrops_effect.active = map_to_cmmk_rgb(modes[active_mode].colors[0]); - raindrops_effect.rest = map_to_cmmk_rgb(modes[active_mode].colors[1]); - - controller->SetMode(raindrops_effect); - } - break; - - case CMMK_EFFECT_STARS: - { - cmmk_effect_stars stars_effect; - - stars_effect.speed = (uint8_t)modes[active_mode].speed; - stars_effect.interval = CMMK_SPEED_MID; - stars_effect.active = map_to_cmmk_rgb(modes[active_mode].colors[0]); - stars_effect.rest = map_to_cmmk_rgb(modes[active_mode].colors[1]); - - controller->SetMode(stars_effect); - } - break; - - case CMMK_EFFECT_SNAKE: - { - cmmk_effect_snake snake_effect; - - snake_effect.speed = (uint8_t)modes[active_mode].speed; - - controller->SetMode(snake_effect); - } - break; - } -} diff --git a/Controllers/CoolerMasterController/RGBController_CMMKController.h b/Controllers/CoolerMasterController/RGBController_CMMKController.h deleted file mode 100644 index 55b99c84..00000000 --- a/Controllers/CoolerMasterController/RGBController_CMMKController.h +++ /dev/null @@ -1,46 +0,0 @@ -/*-------------------------------------------------------------------*\ -| RGBController_CMMKController.h | -| | -| Driver for Coolermaster MasterKeys keyboards | -| | -| Lukas N (chmod222) 28th Jun 2020 | -| Tam D (too.manyhobbies) 25th Apr 2021 | -| | -\*-------------------------------------------------------------------*/ - -#pragma once - -#include -#include "RGBController.h" -#include "CMMKController.h" -#include "RGBControllerKeyNames.h" -#include "KeyboardLayoutManager.h" - -class RGBController_CMMKController : public RGBController -{ -public: - RGBController_CMMKController(CMMKController* controller_ptr); - ~RGBController_CMMKController(); - - void SetupZones(); - void ResizeZone(int zone, int new_size); - - void DeviceUpdateLEDs(); - void UpdateSingleLED(int led, RGBColor color); - void UpdateSingleLED(int led); - void UpdateZoneLEDs(int zone_idx); - - void SetCustomMode(); - void DeviceUpdateMode(); - -private: - void copy_buffers(std::vector &in_colors, struct cmmk_color_matrix& mat, std::atomic& dirty); - - CMMKController* controller; - KeyboardLayoutManager* layoutManager; - - struct cmmk_color_matrix current_matrix; - - std::atomic dirty; - std::atomic force_update; -}; diff --git a/OpenRGB.pro b/OpenRGB.pro index baa113ad..970bedc1 100644 --- a/OpenRGB.pro +++ b/OpenRGB.pro @@ -71,8 +71,6 @@ INCLUDEPATH += dependencies/httplib \ dependencies/json/ \ dependencies/libe131/src/ \ - dependencies/libcmmk/include/ \ - dependencies/libcmmk/src/mappings/ \ dependencies/libusb-1.0.22/include/ \ dependencies/mdns \ dependencies/mbedtls-2.24.0/include/ \ @@ -245,17 +243,6 @@ HEADERS += dependencies/Swatches/swatches.h \ dependencies/hidapi/hidapi/hidapi.h \ dependencies/json/json.hpp \ - dependencies/libcmmk/include/libcmmk/libcmmk.h \ - dependencies/libcmmk/src/mappings/ansi/pro_s.h \ - dependencies/libcmmk/src/mappings/ansi/pro_l.h \ - dependencies/libcmmk/src/mappings/ansi/mk750.h \ - dependencies/libcmmk/src/mappings/ansi/sk630.h \ - dependencies/libcmmk/src/mappings/ansi/sk650.h \ - dependencies/libcmmk/src/mappings/iso/pro_s.h \ - dependencies/libcmmk/src/mappings/iso/pro_l.h \ - dependencies/libcmmk/src/mappings/iso/mk750.h \ - dependencies/libcmmk/src/mappings/iso/sk630.h \ - dependencies/libcmmk/src/mappings/iso/sk650.h \ LogManager.h \ NetworkClient.h \ NetworkProtocol.h \ @@ -407,7 +394,10 @@ HEADERS += Controllers/ColorfulTuringGPUController/RGBController_ColorfulTuringGPU.h \ Controllers/CoolerMasterController/CMARGBcontroller.h \ Controllers/CoolerMasterController/CMARGBGen2A1controller.h \ - Controllers/CoolerMasterController/CMMKController.h \ + Controllers/CoolerMasterController/CMKeyboardAbstractController.h \ + Controllers/CoolerMasterController/CMKeyboardDevices.h \ + Controllers/CoolerMasterController/CMKeyboardV1Controller.h \ + Controllers/CoolerMasterController/CMKeyboardV2Controller.h \ Controllers/CoolerMasterController/CMMMController.h \ Controllers/CoolerMasterController/CMMM711Controller.h \ Controllers/CoolerMasterController/CMMonitorController.h \ @@ -417,7 +407,7 @@ HEADERS += Controllers/CoolerMasterController/CMSmallARGBController.h \ Controllers/CoolerMasterController/RGBController_CMARGBController.h \ Controllers/CoolerMasterController/RGBController_CMARGBGen2A1Controller.h \ - Controllers/CoolerMasterController/RGBController_CMMKController.h \ + Controllers/CoolerMasterController/RGBController_CMKeyboardController.h \ Controllers/CoolerMasterController/RGBController_CMMMController.h \ Controllers/CoolerMasterController/RGBController_CMMM711Controller.h \ Controllers/CoolerMasterController/RGBController_CMMonitorController.h \ @@ -875,7 +865,6 @@ SOURCES += dependencies/hueplusplus-1.0.0/src/Utils.cpp \ dependencies/hueplusplus-1.0.0/src/ZLLSensors.cpp \ dependencies/libe131/src/e131.c \ - dependencies/libcmmk/src/libcmmk.c \ main.cpp \ cli.cpp \ LogManager.cpp \ @@ -1038,18 +1027,21 @@ SOURCES += Controllers/ColorfulTuringGPUController/RGBController_ColorfulTuringGPU.cpp \ Controllers/CoolerMasterController/CMARGBcontroller.cpp \ Controllers/CoolerMasterController/CMARGBGen2A1controller.cpp \ - Controllers/CoolerMasterController/CMMKController.cpp \ + Controllers/CoolerMasterController/CMKeyboardDevices.cpp \ Controllers/CoolerMasterController/CMMMController.cpp \ Controllers/CoolerMasterController/CMMM711Controller.cpp \ Controllers/CoolerMasterController/CMMonitorController.cpp \ Controllers/CoolerMasterController/CMMP750Controller.cpp \ + Controllers/CoolerMasterController/CMKeyboardAbstractController.cpp \ + Controllers/CoolerMasterController/CMKeyboardV1Controller.cpp \ + Controllers/CoolerMasterController/CMKeyboardV2Controller.cpp \ Controllers/CoolerMasterController/CMR6000Controller.cpp \ Controllers/CoolerMasterController/CMRGBController.cpp \ Controllers/CoolerMasterController/CMSmallARGBController.cpp \ Controllers/CoolerMasterController/CoolerMasterControllerDetect.cpp \ Controllers/CoolerMasterController/RGBController_CMARGBController.cpp \ Controllers/CoolerMasterController/RGBController_CMARGBGen2A1Controller.cpp \ - Controllers/CoolerMasterController/RGBController_CMMKController.cpp \ + Controllers/CoolerMasterController/RGBController_CMKeyboardController.cpp \ Controllers/CoolerMasterController/RGBController_CMMMController.cpp \ Controllers/CoolerMasterController/RGBController_CMMM711Controller.cpp \ Controllers/CoolerMasterController/RGBController_CMMonitorController.cpp \ diff --git a/README.md b/README.md index 53cc62b9..7361941d 100644 --- a/README.md +++ b/README.md @@ -327,7 +327,6 @@ There have been two instances of hardware damage in OpenRGB's development and we * NVFC: https://github.com/graphitemaster/NVFC * Qt-Plus (ColorWheel): https://github.com/liuyanghejerry/Qt-Plus * AMD ADL Libraries: https://github.com/GPUOpen-LibrariesAndSDKs/display-library - * libcmmk: https://github.com/chmod222/libcmmk * hueplusplus: https://github.com/enwi/hueplusplus * httplib: https://github.com/yhirose/cpp-httplib * mdns: https://github.com/mjansson/mdns @@ -355,3 +354,6 @@ While no code from these projects directly made its way into OpenRGB, these proj * g810-led: https://github.com/MatMoul/g810-led * liquidctl: https://github.com/jonasmalacofilho/liquidctl * Annemone: https://github.com/manualmanul/Annemone + * libcmmk: https://github.com/chmod222/libcmmk + * Signal RGB Plugins: https://gitlab.com/signalrgb/signal-plugins/-/tree/master/Plugins + * k550-macos https://github.com/vookimedlo/ck550-macos/tree/master diff --git a/dependencies/libcmmk/include/libcmmk/libcmmk.h b/dependencies/libcmmk/include/libcmmk/libcmmk.h deleted file mode 100644 index 6667a5f8..00000000 --- a/dependencies/libcmmk/include/libcmmk/libcmmk.h +++ /dev/null @@ -1,426 +0,0 @@ -/* - * This file is part of libcmmk. - * - * libcmmk is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * libcmmk is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with libcmmk. If not, see . - */ -#ifndef LIBCMMK_H -#define LIBCMMK_H - -#include - -#include - -#if defined(__cplusplus) -extern "C" { -#endif - -#define BYTE_SIZE 8 - -#define CMMK_ROWS_MAX 7 -#define CMMK_COLS_MAX 22 - -#define CMMK_FW_SIZE 16 -#define CMMK_KEYLIST_SIZE 256 -#define CMMK_BUFFER_SIZE 65 - -/* - * If we have C99 support (which we do, because libusb-1.0 requires it...), define some handy - * macros. - */ -#if __STDC_VERSION__ >= 199901L - /* struct rgb from 0xRRGGBB */ - #define MKRGB(hex) (struct rgb){((hex) >> 16) & 0xFF, ((hex) >> 8) & 0xFF, (hex) & 0xFF } - - /* struct rgb from single parts */ - #define MKRGBS(r, g, b) (struct rgb){ (r), (g), (b) } -#endif - -struct rgb { - unsigned char R; - unsigned char G; - unsigned char B; -}; - - -/* Result codes */ -enum cmmk_result { - CMMK_OK = 0, - CMMK_ERR, /* Non-specific error */ - CMMK_LAYOUT_DETECTION_FAILED, - CMMK_USB_COMM, /* An error happened while trying to talk to the device */ - CMMK_INVAL, /* Invalid parameter given */ -}; - -/* - * Physical USB product IDs for general device type detection only. - */ -enum cmmk_product { - CMMK_USB_MASTERKEYS_PRO_L = 0x003b, - CMMK_USB_MASTERKEYS_PRO_L_WHITE = 0x0047, - CMMK_USB_MASTERKEYS_PRO_S = 0x003c, - CMMK_USB_MASTERKEYS_MK750 = 0x0067, - CMMK_USB_MASTERKEYS_SK630 = 0x0089, - CMMK_USB_MASTERKEYS_SK650 = 0x008d, -}; - -/* - * The specific layout of a given device. - */ -enum cmmk_layout { - CMMK_LAYOUT_US_S, - CMMK_LAYOUT_US_L, /* TODO */ - CMMK_LAYOUT_US_MK750, /* TODO */ - CMMK_LAYOUT_US_SK630, /* TODO */ - CMMK_LAYOUT_US_SK650, /* TODO */ - CMMK_LAYOUT_EU_S, /* TODO */ - CMMK_LAYOUT_EU_L, - CMMK_LAYOUT_EU_MK750, - CMMK_LAYOUT_EU_SK630, - CMMK_LAYOUT_EU_SK650, - - CMMK_LAYOUT_INVAL /* end marker */ -}; - -/* Apparently can be anything in range [0x00, 0x50]. - * Over 0x50 it just stops animating */ -enum cmmk_effect_speed { - CMMK_SPEED0 = 0x46, - CMMK_SPEED1 = 0x41, - CMMK_SPEED2 = 0x38, - CMMK_SPEED3 = 0x3D, - CMMK_SPEED4 = 0x31 -}; - -enum cmmk_wave_direction { - CMMK_LEFT_TO_RIGHT = 0x00, - CMMK_RIGHT_TO_LEFT = 0x04, - CMMK_BACK_TO_FRONT = 0x02, - CMMK_FRONT_TO_BACK = 0x06 -}; - -enum cmmk_ripple_type { - CMMK_RIPPLE_GIVEN_COLOR, /* use the given color */ - CMMK_RIPPLE_RANDOM_COLOR = 0x80 /* use a random color */ -}; - -enum cmmk_control_mode { - /* Firmware controls everything */ - CMMK_FIRMWARE = 0x00, - - /* Firmware controlled effect, configured via software */ - CMMK_EFFECT = 0x01, - - /* Manual control of everything */ - CMMK_MANUAL = 0x02, - - /* Profile setup (may actually be a misnomer, as saving the profile works - * in effect mode as well */ - CMMK_PROFILE_CUSTOMIZATION = 0x03 -}; - -enum cmmk_effect_id { - CMMK_EFFECT_FULLY_LIT = 0x00, - CMMK_EFFECT_BREATHE = 0x01, - CMMK_EFFECT_CYCLE = 0x02, - CMMK_EFFECT_SINGLE = 0x03, - CMMK_EFFECT_WAVE = 0x04, - CMMK_EFFECT_RIPPLE = 0x05, - CMMK_EFFECT_CROSS = 0x06, - CMMK_EFFECT_RAINDROPS = 0x07, - CMMK_EFFECT_STARS = 0x08, - CMMK_EFFECT_SNAKE = 0x09, - CMMK_EFFECT_CUSTOMIZED = 0x0a, - CMMK_EFFECT_MULTILAYER = 0xe0, - CMMK_EFFECT_OFF = 0xfe -}; - -/* These enums are only used for display or similar purposes. - * - * All the important layout information is contained in `enum cmmk_layout'. But because - * most of the time, library users really want the model and layout information separated, - * these two helpers abstract it away a bit. */ -enum cmmk_layout_type { - CMMK_LAYOUT_TYPE_ANSI, - CMMK_LAYOUT_TYPE_ISO -}; - -enum cmmk_product_type { - CMMK_PRODUCT_MASTERKEYS_PRO_L, - CMMK_PRODUCT_MASTERKEYS_PRO_S, - CMMK_PRODUCT_MASTERKEYS_MK750, - CMMK_PRODUCT_MASTERKEYS_SK630, - CMMK_PRODUCT_MASTERKEYS_SK650, -}; - -/* - * Attach to and detach from USB device - */ -struct cmmk { - /* libusb_context *cxt; */ - hid_device *dev; - - /* - * Internal product IDs that are not all that useful outside the library. - */ - int product; - int layout; - - /* - * Lookup map to get matrix positions for keys in constant time. - */ - int8_t rowmap[CMMK_KEYLIST_SIZE]; - int8_t colmap[CMMK_KEYLIST_SIZE]; - - int multilayer_mode; -}; - -/* Helper types because passing multi dim arrays as parameter is yucky */ -struct cmmk_color_matrix { - struct rgb data[CMMK_ROWS_MAX][CMMK_COLS_MAX]; -}; - -struct cmmk_effect_matrix { - uint8_t data[CMMK_ROWS_MAX][CMMK_COLS_MAX]; /* values as type of enum cmmk_effect_id */ -}; - -/* Generic effect type for when type safety becomes too verbose. - * - * No sanity checking is done before sending this off to the firmware, so try to stay within - * normal parameters. */ -struct cmmk_generic_effect { - int p1; - int p2; - int p3; - - struct rgb color1; - struct rgb color2; -}; - -struct cmmk_effect_fully_lit { - struct rgb color; -}; - -struct cmmk_effect_breathe { - int speed; - - struct rgb color; -}; - -struct cmmk_effect_cycle { - int speed; -}; - -struct cmmk_effect_single { - int speed; - - struct rgb active; - struct rgb rest; -}; - -struct cmmk_effect_wave { - int speed; - - enum cmmk_wave_direction direction; - - struct rgb start; -}; - -struct cmmk_effect_ripple { - int speed; - - enum cmmk_ripple_type ripple_type; - - struct rgb active; - struct rgb rest; -}; - -struct cmmk_effect_cross { - int speed; - - struct rgb active; - struct rgb rest; -}; - -struct cmmk_effect_raindrops { - int speed; - int interval; - - struct rgb active; - struct rgb rest; -}; - -struct cmmk_effect_stars { - int speed; - int interval; - - struct rgb active; - struct rgb rest; -}; - -struct cmmk_effect_snake { - int speed; -}; - -/* Tries to find a connected, compatible device. Returns 0 and sets *product to the - * first device it finds */ -int cmmk_find_device(int *product); - -/* - * If layout = -1, try to automatically determine the layout. Otherwise, use one of the values - * enumerated in `enum cmmk_layout'. - * - * Note that autodetection is based on unproven theories right now (see issue #10). - * Your mileage may vary. - * - * If layout autodetection fails, 1 is returned and cmmk_detach is called implicitely. - */ -int cmmk_attach(struct cmmk *dev, int product, int layout); -int cmmk_attach_path(struct cmmk *dev, char const *path, int product, int layout); -int cmmk_detach(struct cmmk *dev); - -/* Resets the layout to the given ID and regenerates lookup tables */ -int cmmk_force_layout(struct cmmk *dev, int layout); - -/* fw must be up to 8 bytes to read the entire version string */ -int cmmk_get_firmware_version(struct cmmk *dev, char *fw, size_t fwsiz); - -enum cmmk_product_type cmmk_get_device_model(struct cmmk *dev); -enum cmmk_layout_type cmmk_get_device_layout(struct cmmk *dev); - -const char * cmmk_product_to_str(int product); -const char * cmmk_layout_to_str(int layout); - -/* - * Enter and leave direct control mode. Any control commands outside of control - * mode are ignored. Enabling control mode while inside control mode will reset - * active effect and allow direct control over LEDs. - */ -int cmmk_set_control_mode(struct cmmk *dev, int mode); - -/* Only meaningful in profile customization mode */ -int cmmk_get_active_profile(struct cmmk *dev, int *prof); -int cmmk_set_active_profile(struct cmmk *dev, int prof); - -int cmmk_save_active_profile(struct cmmk *dev); - -/* Predefined effects */ -int cmmk_get_active_effect(struct cmmk *dev, enum cmmk_effect_id *eff); -int cmmk_set_active_effect(struct cmmk *dev, enum cmmk_effect_id eff); - -/* Fetch the list of enabled effects. Updates "n" with the number of effects actually - * read. - */ -int cmmk_get_enabled_effects( - struct cmmk *dev, - enum cmmk_effect_id *effs, - size_t siz, - size_t *n); - -/* Sets the list of enabled effects. Buffer size is implied and should of course be - * at least as big as n. */ -int cmmk_set_enabled_effects( - struct cmmk *dev, - enum cmmk_effect_id const *effs, - size_t n); - -/* - * Get and set effect configurations. - * - * Caveeat: In customization mode, you can only change the configuration of an effect when it is - * currently active. This does not seem to be the case in effects mode. - */ -int cmmk_get_effect(struct cmmk *dev, enum cmmk_effect_id id, struct cmmk_generic_effect *eff); -int cmmk_set_effect(struct cmmk *dev, enum cmmk_effect_id id, struct cmmk_generic_effect const *eff); - -int cmmk_get_effect_fully_lit(struct cmmk *dev, struct cmmk_effect_fully_lit *eff); -int cmmk_set_effect_fully_lit(struct cmmk *dev, struct cmmk_effect_fully_lit const *eff); - -int cmmk_get_effect_breathe(struct cmmk *dev, struct cmmk_effect_breathe *eff); -int cmmk_set_effect_breathe(struct cmmk *dev, struct cmmk_effect_breathe const *eff); - -int cmmk_get_effect_cycle(struct cmmk *dev, struct cmmk_effect_cycle *eff); -int cmmk_set_effect_cycle(struct cmmk *dev, struct cmmk_effect_cycle const *eff); - -int cmmk_get_effect_single(struct cmmk *dev, struct cmmk_effect_single *eff); -int cmmk_set_effect_single(struct cmmk *dev, struct cmmk_effect_single const *eff); - -int cmmk_get_effect_wave(struct cmmk *dev, struct cmmk_effect_wave *eff); -int cmmk_set_effect_wave(struct cmmk *dev, struct cmmk_effect_wave const *eff); - -int cmmk_get_effect_ripple(struct cmmk *dev, struct cmmk_effect_ripple *eff); -int cmmk_set_effect_ripple(struct cmmk *dev, struct cmmk_effect_ripple const *eff); - -int cmmk_get_effect_cross(struct cmmk *dev, struct cmmk_effect_cross *eff); -int cmmk_set_effect_cross(struct cmmk *dev, struct cmmk_effect_cross const *eff); - -int cmmk_get_effect_raindrops(struct cmmk *dev, struct cmmk_effect_raindrops *eff); -int cmmk_set_effect_raindrops(struct cmmk *dev, struct cmmk_effect_raindrops const *eff); - -int cmmk_get_effect_stars(struct cmmk *dev, struct cmmk_effect_stars *eff); -int cmmk_set_effect_stars(struct cmmk *dev, struct cmmk_effect_stars const *eff); - -int cmmk_get_effect_snake(struct cmmk *dev, struct cmmk_effect_snake *eff); -int cmmk_set_effect_snake(struct cmmk *dev, struct cmmk_effect_snake const *eff); - -/* - * colmap *must* be at least 6x22. Otherwise, segmentation faults ensue. - * - * CAVEAT: The result will be wrong immediately after switching profiles. A few milliseconds - * of delay need to be inserted after the switch and before the query. - */ -int cmmk_get_customized_leds(struct cmmk *dev, struct cmmk_color_matrix *colmap); -int cmmk_set_customized_leds(struct cmmk *dev, struct cmmk_color_matrix const *colmap); - -/* - * Switch multilayer mode on (active > 0) or off (active == 0). - * - * Affects effect configuration getters and setters. - */ -int cmmk_switch_multilayer(struct cmmk *dev, int active); - -int cmmk_get_multilayer_map(struct cmmk *dev, struct cmmk_effect_matrix *effmap); -int cmmk_set_multilayer_map(struct cmmk *dev, struct cmmk_effect_matrix const *effmap); - -/* - * Set the single key `key' to the given color. - */ -int cmmk_set_single_key_by_id(struct cmmk *dev, int key, struct rgb const *color); - -/* - * Set the single key in row `row` and column `col` to the given color. - */ -int cmmk_set_single_key(struct cmmk *dev, int row, int col, struct rgb const *color); -int cmmk_lookup_key_id(struct cmmk *dev, int row, int col); -/* - * Set the entire keyboard to the given color. - */ -int cmmk_set_all_single(struct cmmk *dev, struct rgb const *col); -/* - * Set the entire keyboard in one step from the given map. - * - * Keys in the map are indized by their individual mappings, so - * colmap[K_ESC] will address the ESC key, much like - * set_single_key(..., K_ESC, ...) will. - */ -int cmmk_set_leds(struct cmmk *dev, struct cmmk_color_matrix const *colmap); - -#ifdef CMMK_DECLARE_DEBUG_FUNCTIONS - int cmmk_send_anything(struct cmmk *dev, unsigned char *data, size_t data_siz); -#endif - -#if defined(__cplusplus) -} -#endif - -#endif /* !defined(LIBCMMK_H) */ diff --git a/dependencies/libcmmk/src/libcmmk.c b/dependencies/libcmmk/src/libcmmk.c deleted file mode 100644 index 021fc7ef..00000000 --- a/dependencies/libcmmk/src/libcmmk.c +++ /dev/null @@ -1,1080 +0,0 @@ -/* - * This file is part of libcmmk. - * - * libcmmk is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * libcmmk is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with libcmmk. If not, see . - */ -#include - -#ifndef WIN32 -#include /* getuid() */ -#endif -#include /* memset() */ -#include - -#include - -#ifdef CMMK_TRACE -#include -#include -#endif - -/* Initialize keyboard layouts */ -typedef int16_t keyboard_layout[CMMK_ROWS_MAX][CMMK_COLS_MAX]; - -#include "mappings/iso/pro_s.h" -#include "mappings/iso/pro_l.h" -#include "mappings/iso/mk750.h" -#include "mappings/iso/sk630.h" -#include "mappings/iso/sk650.h" - -#include "mappings/ansi/pro_s.h" -#include "mappings/ansi/pro_l.h" -#include "mappings/ansi/mk750.h" -#include "mappings/ansi/sk630.h" -#include "mappings/ansi/sk650.h" - -static keyboard_layout const *keyboard_layouts[] = { - [CMMK_LAYOUT_US_S] = &layout_ansi_pro_s, - [CMMK_LAYOUT_US_L] = &layout_ansi_pro_l, - [CMMK_LAYOUT_US_MK750] = &layout_ansi_mk750, - [CMMK_LAYOUT_US_SK630] = &layout_ansi_sk630, - [CMMK_LAYOUT_US_SK650] = &layout_ansi_sk650, - [CMMK_LAYOUT_EU_S] = &layout_iso_pro_s, - [CMMK_LAYOUT_EU_L] = &layout_iso_pro_l, - [CMMK_LAYOUT_EU_MK750] = &layout_iso_mk750, - [CMMK_LAYOUT_EU_SK630] = &layout_iso_sk630, - [CMMK_LAYOUT_EU_SK650] = &layout_iso_sk650, -}; - -/* Some global definitions */ -enum { - CMMK_USB_VENDOR = 0x2516, - - CMMK_USB_INTERFACE = 1, - - CMMK_USB_EP_IN = 0x04, - CMMK_USB_EP_OUT = 0x83 -}; - -/* linear -> matrix */ -static int transpose(struct cmmk *dev, struct rgb const *linear, struct cmmk_color_matrix *matrix) -{ - int i; - - for (i = 0; i < CMMK_KEYLIST_SIZE; ++i) { - if (dev->rowmap[i] < 0 || dev->colmap[i] < 0) { - continue; - } - - matrix->data[dev->rowmap[i]][dev->colmap[i]] = linear[i]; - } - - return CMMK_OK; -} - -/* Too bad C doesn't have templates */ -static int transpose_effects(struct cmmk *dev, uint8_t const *linear, struct cmmk_effect_matrix *matrix) -{ - int i; - - for (i = 0; i < CMMK_KEYLIST_SIZE; ++i) { - if (dev->rowmap[i] < 0 || dev->colmap[i] < 0) { - continue; - } - - matrix->data[dev->rowmap[i]][dev->colmap[i]] = linear[i]; - } - - return CMMK_OK; -} - -/* matrix -> linear */ -int transpose_reverse(struct cmmk *dev, struct cmmk_color_matrix const *matrix, struct rgb *linear) -{ - keyboard_layout const *layout = keyboard_layouts[dev->layout]; - - int i; - int j; - - for (i = 0; i < CMMK_ROWS_MAX; ++i) { - for (j = 0; j < CMMK_COLS_MAX; ++j) { - int pos = 0; - - if ((pos = (*layout)[i][j]) < 0 || pos > CMMK_KEYLIST_SIZE) { - continue; - } - - linear[pos] = matrix->data[i][j]; - } - } - - return CMMK_OK; -} - -int transpose_effects_reverse(struct cmmk *dev, struct cmmk_effect_matrix const *matrix, uint8_t *linear) -{ - keyboard_layout const *layout = keyboard_layouts[dev->layout]; - - int i; - int j; - - for (i = 0; i < CMMK_ROWS_MAX; ++i) { - for (j = 0; j < CMMK_COLS_MAX; ++j) { - int pos = 0; - - if ((pos = (*layout)[i][j]) < 0 || pos > CMMK_KEYLIST_SIZE) { - continue; - } - - linear[pos] = matrix->data[i][j]; - } - } - - return CMMK_OK; -} - -#ifdef CMMK_TRACE -static void hexdump(void const *ptr, size_t buflen) -{ - unsigned char *buf = (unsigned char*)ptr; - size_t i; - size_t j; - - printf(" 0 1 2 3 4 5 6 7 8 9 A B C D E F\n"); - for (i = 0; i < buflen; i += 16) { - printf("%06lx: ", i); - - for (j = 0; j < 16; j++) { - if (i+j < buflen) { - printf("%02x ", buf[i+j]); - } else { - printf(" "); - } - } - - printf(" "); - - for (j = 0; j < 16; j++) { - if (i+j < buflen) { - printf("%c", isprint(buf[i+j]) ? buf[i+j] : '.'); - } - } - - printf("\n"); - } -} -#endif - -static int send_command(hid_device *dev, unsigned char *data, size_t datasiz) -{ -#ifdef CMMK_TRACE - printf(">>\n"); - hexdump(data, datasiz); -#endif - - if (hid_write(dev, data, datasiz) < 0) { - return CMMK_USB_COMM; - } - - if (hid_read(dev, data, datasiz) < 0) { - return CMMK_USB_COMM; - } - -#ifdef CMMK_TRACE - printf("<<\n"); - hexdump(data, datasiz); -#endif - - return CMMK_OK; -} - -int cmmk_find_device(int *product) -{ - static int supported_devices[] = { - CMMK_USB_MASTERKEYS_PRO_L, - CMMK_USB_MASTERKEYS_PRO_S, - CMMK_USB_MASTERKEYS_MK750, - CMMK_USB_MASTERKEYS_PRO_L_WHITE, - CMMK_USB_MASTERKEYS_SK630, - CMMK_USB_MASTERKEYS_SK650, - }; - - struct hid_device_info *list = NULL; - - int res = 1; - - list = hid_enumerate(CMMK_USB_VENDOR, 0); - - for (struct hid_device_info *dev = list; dev != NULL; dev = dev->next) { - for (size_t j = 0; j < (sizeof(supported_devices) / sizeof(supported_devices[0])); ++j) { - if (dev->product_id == supported_devices[j] && dev->interface_number == CMMK_USB_INTERFACE) { - *product = dev->product_id; - - res = 0; - - break; - } - } - } - - hid_free_enumeration(list); - - return res; -} - - -static int cmmk_try_determine_layout(struct cmmk *dev, int product) -{ - char fw[CMMK_FW_SIZE]; - - enum cmmk_layout_type general_layout = CMMK_LAYOUT_TYPE_ANSI; - enum cmmk_product_type device_model = 0; - - if (cmmk_get_firmware_version(dev, fw, CMMK_FW_SIZE) == 0) { - if (fw[0] == '1') { - /* ANSI firmware */ - general_layout = CMMK_LAYOUT_TYPE_ANSI; - } else { - general_layout = CMMK_LAYOUT_TYPE_ISO; - } - } - - switch ((enum cmmk_product) product) { - case CMMK_USB_MASTERKEYS_PRO_L: - case CMMK_USB_MASTERKEYS_PRO_L_WHITE: device_model = CMMK_PRODUCT_MASTERKEYS_PRO_L; break; - case CMMK_USB_MASTERKEYS_PRO_S: device_model = CMMK_PRODUCT_MASTERKEYS_PRO_S; break; - case CMMK_USB_MASTERKEYS_MK750: device_model = CMMK_PRODUCT_MASTERKEYS_MK750; break; - case CMMK_USB_MASTERKEYS_SK630: device_model = CMMK_PRODUCT_MASTERKEYS_SK630; break; - case CMMK_USB_MASTERKEYS_SK650: device_model = CMMK_PRODUCT_MASTERKEYS_SK650; break; - } - - if (general_layout == CMMK_LAYOUT_TYPE_ANSI) { - switch (device_model) { - case CMMK_PRODUCT_MASTERKEYS_PRO_L: return CMMK_LAYOUT_US_L; - case CMMK_PRODUCT_MASTERKEYS_PRO_S: return CMMK_LAYOUT_US_S; - case CMMK_PRODUCT_MASTERKEYS_MK750: return CMMK_LAYOUT_US_MK750; - case CMMK_PRODUCT_MASTERKEYS_SK630: return CMMK_LAYOUT_US_SK630; - case CMMK_PRODUCT_MASTERKEYS_SK650: return CMMK_LAYOUT_US_SK630; - } - } else { - switch (device_model) { - case CMMK_PRODUCT_MASTERKEYS_PRO_L: return CMMK_LAYOUT_EU_L; - case CMMK_PRODUCT_MASTERKEYS_PRO_S: return CMMK_LAYOUT_EU_S; - case CMMK_PRODUCT_MASTERKEYS_MK750: return CMMK_LAYOUT_EU_MK750; - case CMMK_PRODUCT_MASTERKEYS_SK630: return CMMK_LAYOUT_EU_SK630; - case CMMK_PRODUCT_MASTERKEYS_SK650: return CMMK_LAYOUT_EU_SK650; - } - } - - return -1; -} - -/* - * Attach to and detach from USB device - */ -int cmmk_attach(struct cmmk *dev, int product, int layout) -{ - struct hid_device_info *list; - - list = hid_enumerate(CMMK_USB_VENDOR, product); - - dev->product = product; - - for (struct hid_device_info *dev_info = list; dev_info != NULL; dev_info = dev_info->next) { - if (dev_info->interface_number != CMMK_USB_INTERFACE) { - continue; - } - - dev->dev = hid_open_path(dev_info->path); - - if (layout < 0) { - if ((layout = cmmk_try_determine_layout(dev, product)) < 0) { - hid_free_enumeration(list); - cmmk_detach(dev); - - return CMMK_LAYOUT_DETECTION_FAILED; - } - } - - break; - } - - hid_free_enumeration(list); - - if (dev->dev != NULL) { - /* - * Generate lookup map - */ - cmmk_force_layout(dev, layout); - - dev->multilayer_mode = 0; - - return CMMK_OK; - } else { - return 1; - } -} - -int cmmk_attach_path(struct cmmk *dev, char const *path, int product, int layout) -{ - dev->dev = hid_open_path(path); - - if (dev->dev != NULL) { - if (layout < 0) { - layout = cmmk_try_determine_layout(dev, product); - } - - /* - * Generate lookup map - */ - cmmk_force_layout(dev, layout); - - dev->multilayer_mode = 0; - - return CMMK_OK; - } else { - return 1; - } -} - -int cmmk_detach(struct cmmk *dev) -{ - hid_close(dev->dev); - - return CMMK_OK; -} - -int cmmk_force_layout(struct cmmk *dev, int layout) -{ - int i; - int j; - - keyboard_layout const *keyboard_layout; - - dev->layout = layout; - - memset(dev->rowmap, -1, sizeof(dev->rowmap)); - memset(dev->colmap, -1, sizeof(dev->colmap)); - - keyboard_layout = keyboard_layouts[dev->layout]; - - for (i = 0; i < CMMK_ROWS_MAX; ++i) { - for (j = 0; j < CMMK_COLS_MAX; ++j) { - int p = (*keyboard_layout)[i][j]; - - if (p < 0) { - continue; - } - - dev->rowmap[p] = i; - dev->colmap[p] = j; - } - } - - return CMMK_OK; -} - -int cmmk_get_firmware_version(struct cmmk *dev, char *fw, size_t fwsiz) -{ - unsigned char data[CMMK_BUFFER_SIZE] = {0x00, 0x01, 0x02}; - int r; - - if ((r = send_command(dev->dev, data, CMMK_BUFFER_SIZE)) != 0) { - return r; - } - - /* Don't want to read past the response buffer */ - if (fwsiz > 60) { - fwsiz = 60; - } - - memcpy(fw, (char *)data + 4, fwsiz); - - return CMMK_OK; -} - -enum cmmk_product_type cmmk_get_device_model(struct cmmk *dev) -{ - switch (dev->layout) { - case CMMK_LAYOUT_US_S: - case CMMK_LAYOUT_EU_S: - return CMMK_PRODUCT_MASTERKEYS_PRO_S; - - case CMMK_LAYOUT_US_L: - case CMMK_LAYOUT_EU_L: - return CMMK_PRODUCT_MASTERKEYS_PRO_L; - - case CMMK_LAYOUT_US_MK750: - case CMMK_LAYOUT_EU_MK750: - return CMMK_PRODUCT_MASTERKEYS_MK750; - } - - assert(0 && "unreachable"); -} - -enum cmmk_layout_type cmmk_get_device_layout(struct cmmk *dev) -{ - switch (dev->layout) { - case CMMK_LAYOUT_US_S: - case CMMK_LAYOUT_US_L: - case CMMK_LAYOUT_US_MK750: - return CMMK_LAYOUT_TYPE_ANSI; - - case CMMK_LAYOUT_EU_S: - case CMMK_LAYOUT_EU_L: - case CMMK_LAYOUT_EU_MK750: - return CMMK_LAYOUT_TYPE_ISO; - } - - assert(0 && "unreachable"); -} - -const char * cmmk_product_to_str(int product) -{ - switch ((enum cmmk_product) product) { - case CMMK_USB_MASTERKEYS_PRO_S: return "Cooler Master Masterkeys Pro S"; - case CMMK_USB_MASTERKEYS_PRO_L: return "Cooler Master Masterkeys Pro L"; - case CMMK_USB_MASTERKEYS_PRO_L_WHITE: return "Cooler Master Masterkeys Pro L White"; - case CMMK_USB_MASTERKEYS_MK750: return "Cooler Master Masterkeys MK750"; - case CMMK_USB_MASTERKEYS_SK630: return "Cooler Master Masterkeys SK630"; - case CMMK_USB_MASTERKEYS_SK650: return "Cooler Master Masterkeys SK650"; - } - - return "unknown"; -} - -const char * cmmk_layout_to_str(int layout) -{ - switch ((enum cmmk_layout) layout) { - case CMMK_LAYOUT_US_S: - case CMMK_LAYOUT_US_L: - case CMMK_LAYOUT_US_MK750: - case CMMK_LAYOUT_US_SK630: - case CMMK_LAYOUT_US_SK650: - return "US"; - case CMMK_LAYOUT_EU_S: - case CMMK_LAYOUT_EU_L: - case CMMK_LAYOUT_EU_MK750: - case CMMK_LAYOUT_EU_SK630: - case CMMK_LAYOUT_EU_SK650: - return "EU"; - - case CMMK_LAYOUT_INVAL: - return "invalid"; - } - - return "unknown"; -} - -/* - * Enter and leave direct control mode. Any control commands outside of control - * mode are ignored. - */ -int cmmk_set_control_mode(struct cmmk *dev, int mode) -{ - unsigned char data[CMMK_BUFFER_SIZE] = {0x00, 0x41, mode}; - - return send_command(dev->dev, data, CMMK_BUFFER_SIZE); -} - -int cmmk_set_active_profile(struct cmmk *dev, int prof) -{ - unsigned char setprof[CMMK_BUFFER_SIZE] = {0x00, 0x51, 0x00, 0x00, 0x00, prof}; - - return send_command(dev->dev, setprof, CMMK_BUFFER_SIZE); -} - -int cmmk_get_active_profile(struct cmmk *dev, int *prof) -{ - int r; - - unsigned char getprof[CMMK_BUFFER_SIZE] = {0x00, 0x52, 0x00}; - - if ((r = send_command(dev->dev, getprof, CMMK_BUFFER_SIZE)) != 0) - return r; - - *prof = getprof[4]; - - return CMMK_OK; -} - -int cmmk_save_active_profile(struct cmmk *dev) -{ - unsigned char saveprof[CMMK_BUFFER_SIZE] = {0x00, 0x50, 0x55}; - - return send_command(dev->dev, saveprof, CMMK_BUFFER_SIZE); -} - - -static int set_effect1(struct cmmk *dev, int eff) -{ - unsigned char data[CMMK_BUFFER_SIZE] = {0x00, 0x51, 0x28, 0x00, 0x00, eff}; - - return send_command(dev->dev, data, CMMK_BUFFER_SIZE); -} - - -static int set_effect( - struct cmmk *dev, - int eff, - int p1, int p2, int p3, - struct rgb const *col1, - struct rgb const *col2) -{ - unsigned char data[CMMK_BUFFER_SIZE] = { - 0x00, 0x51, 0x2c, dev->multilayer_mode, 0x00, eff, p1, - p2, p3, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - - if (col1 != NULL) { - data[11] = col1->R; - data[12] = col1->G; - data[13] = col1->B; - } - - if (col2 != NULL) { - data[14] = col2->R; - data[15] = col2->G; - data[16] = col2->B; - } - - memset(data + 17, 0xff, 48); - - return send_command(dev->dev, data, CMMK_BUFFER_SIZE); -} - -static int get_effect( - struct cmmk *dev, - int eff, - int *p1, int *p2, int *p3, - struct rgb *col1, - struct rgb *col2) -{ - int r; - - unsigned char data[CMMK_BUFFER_SIZE] = { - 0x00, 0x52, 0x2c, dev->multilayer_mode, 0x00, eff - }; - - memset(data + 6, 0xff, 59); - - if ((r = send_command(dev->dev, data, CMMK_BUFFER_SIZE)) != 0) { - return r; - } - - if (p1) { - *p1 = data[5]; - } - - if (p2) { - *p2 = data[6]; - } - - if (p3) { - *p3 = data[7]; - } - - if (col1) { - col1->R = data[10]; - col1->G = data[11]; - col1->B = data[12]; - } - - if (col2) { - col2->R = data[13]; - col2->G = data[14]; - col2->B = data[15]; - } - - return CMMK_OK; -} - -int cmmk_set_active_effect(struct cmmk *dev, enum cmmk_effect_id eff) -{ - if (eff < 0 || (eff > CMMK_EFFECT_CUSTOMIZED - && eff != CMMK_EFFECT_OFF - && eff != CMMK_EFFECT_MULTILAYER)) { - return CMMK_INVAL; - } - - return set_effect1(dev, eff); -} - -int cmmk_get_active_effect(struct cmmk *dev, enum cmmk_effect_id *eff) -{ - unsigned char data[CMMK_BUFFER_SIZE] = {0x00, 0x52, 0x28}; - int r; - - if ((r = send_command(dev->dev, data, CMMK_BUFFER_SIZE)) != 0) { - return r; - } - - *eff = data[4]; - - return CMMK_OK; -} - -int cmmk_get_effect(struct cmmk *dev, enum cmmk_effect_id id, struct cmmk_generic_effect *eff) -{ - return get_effect(dev, id, &eff->p1, &eff->p2, &eff->p3, &eff->color1, &eff->color2); -} -int cmmk_set_effect(struct cmmk *dev, enum cmmk_effect_id id, struct cmmk_generic_effect const *eff) -{ - return set_effect(dev, id, eff->p1, eff->p2, eff->p3, &eff->color1, &eff->color2); -} - - -int cmmk_get_enabled_effects( - struct cmmk *dev, - enum cmmk_effect_id *effs, - size_t siz, - size_t *n) -{ - unsigned char data[CMMK_BUFFER_SIZE] = {0x00, 0x52, 0x29}; - - size_t i; - size_t j = 0; - - int r; - - if ((r = send_command(dev->dev, data, CMMK_BUFFER_SIZE)) != 0) { - return r; - } - - for (i = 4; data[i] != 0xff && j < siz; ++i) { - effs[j++] = data[i]; - } - - *n = j; - return CMMK_OK; -} - -int cmmk_set_enabled_effects( - struct cmmk *dev, - enum cmmk_effect_id const *effs, - size_t n) -{ - unsigned char data[CMMK_BUFFER_SIZE] = {0x00, 0x51, 0x29}; - - size_t i; - - for (i = 0; i < n; ++i) { - data[5 + i] = effs[i]; - } - - while (i < 18) { - data[5 + i] = 0xff; - - ++i; - } - - return send_command(dev->dev, data, sizeof(data));; -} - -int cmmk_get_effect_fully_lit(struct cmmk *dev, struct cmmk_effect_fully_lit *eff) -{ - return get_effect(dev, CMMK_EFFECT_FULLY_LIT, NULL, NULL, NULL, &eff->color, NULL); -} - -int cmmk_set_effect_fully_lit(struct cmmk *dev, struct cmmk_effect_fully_lit const *eff) -{ - return set_effect(dev, CMMK_EFFECT_FULLY_LIT, 0x00, 0x00, 0xff, &eff->color, NULL); -} - - -int cmmk_get_effect_breathe(struct cmmk *dev, struct cmmk_effect_breathe *eff) -{ - return get_effect(dev, CMMK_EFFECT_BREATHE, &eff->speed, NULL, NULL, &eff->color, NULL); -} - -int cmmk_set_effect_breathe(struct cmmk *dev, struct cmmk_effect_breathe const *eff) -{ - return set_effect(dev, CMMK_EFFECT_BREATHE, eff->speed, 0x00, 0xff, &eff->color, NULL); -} - - -int cmmk_get_effect_cycle(struct cmmk *dev, struct cmmk_effect_cycle *eff) -{ - return get_effect(dev, CMMK_EFFECT_CYCLE, &eff->speed, NULL, NULL, NULL, NULL); -} - -int cmmk_set_effect_cycle(struct cmmk *dev, struct cmmk_effect_cycle const *eff) -{ - return set_effect(dev, CMMK_EFFECT_CYCLE, eff->speed, 0x00, 0xff, NULL, NULL); -} - - -int cmmk_get_effect_single(struct cmmk *dev, struct cmmk_effect_single *eff) -{ - return get_effect(dev, CMMK_EFFECT_SINGLE, &eff->speed, NULL, NULL, &eff->active, &eff->rest); -} - -int cmmk_set_effect_single(struct cmmk *dev, struct cmmk_effect_single const *eff) -{ - return set_effect(dev, CMMK_EFFECT_SINGLE, eff->speed, 0x00, 0xff, &eff->active, &eff->rest); -} - - -int cmmk_get_effect_wave(struct cmmk *dev, struct cmmk_effect_wave *eff) -{ - int r; - int p2; - - if ((r = get_effect(dev, CMMK_EFFECT_WAVE, &eff->speed, &p2, NULL, &eff->start, NULL)) != 0) { - return r; - } - - eff->direction = p2; - return CMMK_OK; -} - -int cmmk_set_effect_wave(struct cmmk *dev, struct cmmk_effect_wave const *eff) -{ - return set_effect(dev, CMMK_EFFECT_WAVE, eff->speed, eff->direction, 0xff, &eff->start, NULL); -} - - -int cmmk_get_effect_ripple(struct cmmk *dev, struct cmmk_effect_ripple *eff) -{ - int r; - int p2; - - if ((r = get_effect(dev, CMMK_EFFECT_RIPPLE, &eff->speed, &p2, NULL, &eff->active, &eff->rest)) != 0) { - return r; - } - - eff->ripple_type = (p2 == 0x80) ? CMMK_RIPPLE_RANDOM_COLOR : CMMK_RIPPLE_GIVEN_COLOR; - - return CMMK_OK; -} - -int cmmk_set_effect_ripple(struct cmmk *dev, struct cmmk_effect_ripple const *eff) -{ - return set_effect(dev, CMMK_EFFECT_RIPPLE, eff->speed, eff->ripple_type ? 0x80 : 0x00, 0xff, &eff->active, &eff->rest); -} - - -int cmmk_get_effect_cross(struct cmmk *dev, struct cmmk_effect_cross *eff) -{ - return get_effect(dev, CMMK_EFFECT_CROSS, &eff->speed, NULL, NULL, &eff->active, &eff->rest); -} - -int cmmk_set_effect_cross(struct cmmk *dev, struct cmmk_effect_cross const *eff) -{ - return set_effect(dev, CMMK_EFFECT_CROSS, eff->speed, 0x00, 0xff, &eff->active, &eff->rest); -} - - -int cmmk_get_effect_raindrops(struct cmmk *dev, struct cmmk_effect_raindrops *eff) -{ - return get_effect(dev, CMMK_EFFECT_RAINDROPS, &eff->speed, NULL, &eff->interval, &eff->active, &eff->rest); -} - -int cmmk_set_effect_raindrops(struct cmmk *dev, struct cmmk_effect_raindrops const *eff) -{ - return set_effect(dev, CMMK_EFFECT_RAINDROPS, eff->speed, 0x00, eff->interval, &eff->active, &eff->rest); -} - - -int cmmk_get_effect_stars(struct cmmk *dev, struct cmmk_effect_stars *eff) -{ - return get_effect(dev, CMMK_EFFECT_STARS, &eff->speed, NULL, &eff->interval, &eff->active, &eff->rest); -} - -int cmmk_set_effect_stars(struct cmmk *dev, struct cmmk_effect_stars const *eff) -{ - return set_effect(dev, CMMK_EFFECT_STARS, eff->speed, 0x00, eff->interval, &eff->active, &eff->rest); -} - -int cmmk_get_effect_snake(struct cmmk *dev, struct cmmk_effect_snake *eff) -{ - return get_effect(dev, CMMK_EFFECT_SNAKE, &eff->speed, NULL, NULL, NULL, NULL); -} - -int cmmk_set_effect_snake(struct cmmk *dev, struct cmmk_effect_snake const *eff) -{ - return set_effect(dev, CMMK_EFFECT_SNAKE, eff->speed, 0x00, 0xff, NULL, NULL); -} - -int cmmk_set_customized_leds(struct cmmk *dev, struct cmmk_color_matrix const *colmap) -{ - const unsigned char HEADER_SIZE = 5; - unsigned char data[CMMK_BUFFER_SIZE] = {0x00, 0x51, 0xa8}; - - int i; - int j; - -#ifdef _MSC_VER - struct rgb linear[CMMK_KEYLIST_SIZE] = { 0 }; -#else - struct rgb linear[CMMK_KEYLIST_SIZE] = {}; -#endif - struct rgb *nextcol = linear; - - transpose_reverse(dev, colmap, linear); - - for (i = 0; i < 8; ++i) { - data[3] = i*2; - - for (j = 0; j < 16; ++j) { - int const offset = HEADER_SIZE + (j * 3); - - data[offset] = nextcol->R; - data[offset + 1] = nextcol->G; - data[offset + 2] = nextcol->B; - - ++nextcol; - } - - send_command(dev->dev, data, CMMK_BUFFER_SIZE); - } - - return CMMK_OK; -} - -int cmmk_get_customized_leds(struct cmmk *dev, struct cmmk_color_matrix *colmap) -{ -#ifdef _MSC_VER - struct rgb linear[CMMK_KEYLIST_SIZE] = { 0 }; -#else - struct rgb linear[CMMK_KEYLIST_SIZE] = {}; -#endif - - const unsigned char HEADER_SIZE = 5; - unsigned char data[CMMK_BUFFER_SIZE] = {0x00, 0x52, 0xa8}; - - int i; - int j; - - struct rgb *ptr = linear; - - for (i = 0; i < 8; ++i) { - data[3] = i * 2; - - send_command(dev->dev, data, CMMK_BUFFER_SIZE); - - for (j = 0; j < 16; ++j) { - int const offset = (HEADER_SIZE - 1) + (j * 3); - - ptr->R = data[offset]; - ptr->G = data[offset + 1]; - ptr->B = data[offset + 2]; - - ++ptr; - } - } - - transpose(dev, linear, colmap); - - return CMMK_OK; -} - -int cmmk_switch_multilayer(struct cmmk *dev, int active) -{ - dev->multilayer_mode = active > 0; - - return CMMK_OK; -} - -int cmmk_get_multilayer_map(struct cmmk *dev, struct cmmk_effect_matrix *effmap) -{ - const unsigned char HEADER_SIZE = 9; - unsigned char data_size = CMMK_BUFFER_SIZE - HEADER_SIZE; - int r; - - unsigned char data[CMMK_BUFFER_SIZE]; - unsigned char header[CMMK_BUFFER_SIZE] = {0x00, 0x51, 0xa0, 0x01, 0x00}; - uint8_t linear[CMMK_KEYLIST_SIZE]; - - /* Call 1 */ - memcpy(data, header, HEADER_SIZE); - data[5] = 0x00; - data[6] = 0x07; - - if ((r = send_command(dev->dev, data, CMMK_BUFFER_SIZE)) != 0) { - return r; - } - - memcpy(linear, data + HEADER_SIZE - 1, data_size); - - /* Call 2 */ - memcpy(data, header, HEADER_SIZE); - data[5] = 0x07; - data[6] = 0x07; - - if ((r = send_command(dev->dev, data, CMMK_BUFFER_SIZE)) != 0) { - return r; - } - - memcpy(linear + 56, data + HEADER_SIZE - 1, data_size); - - /* Call 3 */ - memcpy(data, header, HEADER_SIZE); - data[5] = 0x0e; - data[6] = 0x01; - - if ((r = send_command(dev->dev, data, CMMK_BUFFER_SIZE)) != 0) { - return r; - } - - memcpy(linear + 112, data + HEADER_SIZE - 1, data_size); - - transpose_effects(dev, linear, effmap); - - return CMMK_OK; -} - -int cmmk_set_multilayer_map(struct cmmk *dev, struct cmmk_effect_matrix const *effmap) -{ - const unsigned char HEADER_SIZE = 9; - unsigned char data_size = CMMK_BUFFER_SIZE - HEADER_SIZE; - int r; - - unsigned char data[CMMK_BUFFER_SIZE]; - unsigned char header[CMMK_BUFFER_SIZE] = {0x00, 0x51, 0xa0, 0x01, 0x00}; - uint8_t linear[CMMK_KEYLIST_SIZE] = {0}; - - transpose_effects_reverse(dev, effmap, linear); - - /* Call 1 */ - memcpy(data, header, HEADER_SIZE); - data[5] = 0x00; - data[6] = 0x07; - - memcpy(data + HEADER_SIZE, linear, data_size); - - if ((r = send_command(dev->dev, data, CMMK_BUFFER_SIZE)) != 0) { - return r; - } - - /* Call 2 */ - memcpy(data, header, HEADER_SIZE); - data[5] = 0x07; - data[6] = 0x07; - - memcpy(data + HEADER_SIZE, linear + 56, data_size); - - if ((r = send_command(dev->dev, data, CMMK_BUFFER_SIZE)) != 0) { - return r; - } - - /* Call 3 */ - memcpy(data, header, HEADER_SIZE); - data[5] = 0x0e; - data[6] = 0x01; - - memcpy(data + HEADER_SIZE, linear + 112, data_size); - - if ((r = send_command(dev->dev, data, CMMK_BUFFER_SIZE)) != 0) { - return r; - } - - return CMMK_OK; -} - -int cmmk_lookup_key_id(struct cmmk *dev, int row, int col) -{ - keyboard_layout const *layout = keyboard_layouts[dev->layout]; - - return (*layout)[row][col]; -} - -/* - * Set the single key `key' to the given color. - */ -int cmmk_set_single_key_by_id(struct cmmk *dev, int key, struct rgb const *color) -{ - unsigned char data[CMMK_BUFFER_SIZE] = {0x00, 0xc0, 0x01, 0x01, 0x00, key, color->R, color->G, color->B}; - - return send_command(dev->dev, data, sizeof(data)); -} - -/* - * Set the single key in row `row` and column `col` to the given color. - */ -int cmmk_set_single_key(struct cmmk *dev, int row, int col, struct rgb const *color) -{ - int key = cmmk_lookup_key_id(dev, row, col); - - return cmmk_set_single_key_by_id(dev, key, color); -} - - -/* - * Set the entire keyboard to the given color. - */ -int cmmk_set_all_single(struct cmmk *dev, struct rgb const *col) -{ - unsigned char data[CMMK_BUFFER_SIZE] = {0x00, 0xc0, 0x00, 0x00, 0x00, col->R, col->G, col->B}; - - return send_command(dev->dev, data, sizeof(data)); -} - - -/* - * Set the entire keyboard in one step from the given map. - * - * colmap *must* be at least CMMK_KEYLIST_SIZE entries long. - * Otherwise, segmentation faults ensue. - * - * Keys in the map are indized by their individual mappings, so - * colmap[K_ESC] will address the ESC key, much like - * set_single_key(..., K_ESC, ...) will. - */ -int cmmk_set_leds(struct cmmk *dev, struct cmmk_color_matrix const *colmap) -{ - unsigned char data[CMMK_BUFFER_SIZE]; - - int i; - int j; - -#ifdef _MSC_VER - struct rgb linear[CMMK_KEYLIST_SIZE] = { 0 }; -#else - struct rgb linear[CMMK_KEYLIST_SIZE] = {}; -#endif - struct rgb *nextcol = linear; - - transpose_reverse(dev, colmap, linear); - - for (i = 0; i < 8; ++i) { - data[0] = 0x00; - data[1] = 0xc0; - data[2] = 0x02; - data[3] = i*2; - data[4] = 0x00; - - for (j = 0; j < 16; ++j) { - int const offset = 5 + (j * 3); - - data[offset] = nextcol->R; - data[offset + 1] = nextcol->G; - data[offset + 2] = nextcol->B; - - ++nextcol; - } - - send_command(dev->dev, data, CMMK_BUFFER_SIZE); - } - - return CMMK_OK; -} - - -/* - * Unpublished functions (debug, survey, ...) - */ -int cmmk_send_anything(struct cmmk *dev, unsigned char *data, size_t data_siz) -{ - return send_command(dev->dev, data, data_siz); -} diff --git a/dependencies/libcmmk/src/mappings/ansi/mk750.h b/dependencies/libcmmk/src/mappings/ansi/mk750.h deleted file mode 100644 index 2809393d..00000000 --- a/dependencies/libcmmk/src/mappings/ansi/mk750.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * This file is part of libcmmk. - * - * libcmmk is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * libcmmk is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with libcmmk. If not, see . - */ -static keyboard_layout layout_ansi_mk750 = { - {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, -}; \ No newline at end of file diff --git a/dependencies/libcmmk/src/mappings/ansi/pro_l.h b/dependencies/libcmmk/src/mappings/ansi/pro_l.h deleted file mode 100644 index ca35349a..00000000 --- a/dependencies/libcmmk/src/mappings/ansi/pro_l.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * This file is part of libcmmk. - * - * libcmmk is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * libcmmk is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with libcmmk. If not, see . - */ -static keyboard_layout layout_ansi_pro_l = { - /* - ESC F1 F2 F3 F4 XXX F5 F6 F7 F8 XXX F9 F10 F11 F12 PRN SCL PAU P1 P2 P3 P4 */ - {11, 22, 30, 25, 27, -1, 7, 51, 57, 62, -1, 86, 87, 83, 85, 79, 72, 0, 101, 109, 117, 119}, - - /* - ` 1 2 3 4 5 6 7 8 9 0 - = XXX BCK INS HOM PUP #LCK #/ #* #- */ - {14, 15, 23, 31, 39, 38, 46, 47, 55, 63, 71, 70, 54, -1, 81, 3, 1, 2, 100, 108, 116, 118}, - - /* - TAB Q W E R T Y U I O P [ ] XXX \ DEL END PDN #7 #8 #9 #+ */ - {9, 8, 16, 24, 32, 33, 41, 40, 48, 56, 64, 65, 49, -1, 82, 94, 92, 88, 96, 104, 112, 110}, - - /* - CAP A S D F G H J K L ; ' XXX XXX ENT XXX XXX XXX #4 #5 #6 XXX */ - {17, 10, 18, 26, 34, 35, 43, 42, 50, 58, 66, 67, -1, -1, 84, -1, -1, -1, 97, 105, 113, -1}, - - /* - LSHFT XXX Z X C V B N M , . / XXX XXX RSHFT XXX UP XXX #1 #2 #3 #ENTER */ - {73, -1, 12, 20, 28, 36, 37, 45, 44, 52, 60, 69, -1, -1, 74, -1, 80, -1, 98, 106, 114, 111}, - - /* - LCTRL LWIN LALT XXX XXX XXX SPACE XXX XXX XXX RALT RWIN FN XXX RCTRL LEFT DOWN RIGHT #0 XXX #. XXX */ - {6, 90, 75, -1, -1, -1, 91, -1, -1, -1, 77, 78, 61, -1, 4, 95, 93, 5, 107, -1, 115, -1}, - - /* Bottom row does not exist */ - {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, -}; \ No newline at end of file diff --git a/dependencies/libcmmk/src/mappings/ansi/pro_s.h b/dependencies/libcmmk/src/mappings/ansi/pro_s.h deleted file mode 100644 index b0bba177..00000000 --- a/dependencies/libcmmk/src/mappings/ansi/pro_s.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * This file is part of libcmmk. - * - * libcmmk is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * libcmmk is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with libcmmk. If not, see . - */ -static keyboard_layout layout_ansi_pro_s = { - /* - ESC F1 F2 F3 F4 XXX F5 F6 F7 F8 XXX F9 F10 F11 F12 PRN SCL PAU XXX XXX XXX XXX */ - {96, 97, 98, 99, 104, -1, 105, 106, 112, 113, -1, 114, 67, 68, 69, 102, 103, 107, -1, -1, -1, -1}, - - /* - ` 1 2 3 4 5 6 7 8 9 0 - = XXX BCK INS HOM PUP XXX XXX XXX XXX */ - {0, 1, 8, 9, 16, 17, 24, 25, 32, 33, 40, 41, 48, -1, 49, 56, 57, 64, -1, -1, -1, -1}, - - /* - TAB Q W E R T Y U I O P [ ] XXX \ DEL END PDN XXX XXX XXX XXX */ - {2, 3, 10, 11, 18, 19, 26, 27, 34, 35, 42, 43, 50, -1, 51, 58, 59, 66, -1, -1, -1, -1}, - - /* - CAP A S D F G H J K L ; ' XXX XXX ENT XXX XXX XXX XXX XXX XXX XXX */ - {4, 5, 12, 13, 20, 21, 28, 29, 36, 37, 44, 45, -1, -1, 52, -1, -1, -1, -1, -1, -1, -1}, - - /* - LSHFT XXX Z X C V B N M , . / XXX XXX RSHFT XXX UP XXX XXX XXX XXX XXX */ - {6, -1, 7, 14, 15, 22, 23, 30, 31, 38, 39, 46, -1, -1, 47, -1, 61, -1, -1, -1, -1, -1}, // after / was 1 BAD - - /* - LCTRL LWIN LALT XXX XXX XXX SPACE XXX XXX XXX RALT RWIN FN XXX RCTRL LEFT DOWN RIGHT XXX XXX XXX XXX */ - {91, 90, 92, -1, -1, -1, 93, -1, -1, -1, 94, 60, 95, -1, 54, 63, 62, 70, -1, -1, -1, -1}, - - {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, -}; \ No newline at end of file diff --git a/dependencies/libcmmk/src/mappings/ansi/sk630.h b/dependencies/libcmmk/src/mappings/ansi/sk630.h deleted file mode 100644 index 54de4c9f..00000000 --- a/dependencies/libcmmk/src/mappings/ansi/sk630.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * This file is part of libcmmk. - * - * libcmmk is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * libcmmk is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with libcmmk. If not, see . - */ -static keyboard_layout layout_ansi_sk630 = { - /* - ESC F1 F2 F3 F4 XXX F5 F6 F7 F8 XXX F9 F10 F11 F12 PRN SCL PAU XXX XXX XXX XXX */ - { 9, 33, 41, 49, 57, -1, 73, 81, 89, 97, -1, 105, 113, 121, 129, 137, 145, 153, -1, -1, -1, -1}, - - /* - ^ 1 2 3 4 5 6 7 8 9 0 ß ´ XXX BCK INS HOM PUP XXX XXX XXX` XXX */ - {10, 26, 34, 42, 50, 58, 66, 74, 82, 90, 98, 106, 114, -1, 130, 138, 146, 154, -1, -1, -1, -1}, - - /* - TAB Q W E R T Z/Y U I O P { } XXX | DEL END PGDN XXX XXX XXX XXX */ - {11, 27, 35, 43, 51, 59, 67, 75, 83, 91, 99, 107, 115, -1, 131, 139, 147, 155, -1, -1, -1, -1}, - - /* - CAP A S D F G H J K L ; " XXX XXX ENT XXX XXX XXX XXX XXX XXX XXX */ - {12, 28, 36, 44, 52, 60, 68, 76, 84, 92, 100, 108, -1, -1, 132, -1, -1, -1, -1, -1, -1, -1}, - - /* - LSHFT Z X C V B N M < > ? XXX XXX XXX RSHFT XXX UP XXX XXX XXX XXX XXX */ - {13, 29, 37, 45, 53, 61, 69, 77, 85, 93, 101, -1, -1, -1, 133, -1, 149, -1, -1, -1, -1, -1}, - - /* - LCTRL LWIN LALT XXX XXX XXX SPACE XXX XXX XXX RALT RWIN FN XXX RCTRL LEFT DOWN RIGHT XXX XXX XXX XXX */ - {14, 22, 30, -1, -1, -1, 62, -1, -1, -1, 94, 102, 110, -1, 134, 142, 150, 158, -1, -1, -1, -1}, - - /* Bottom row does not exist */ - {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, -}; diff --git a/dependencies/libcmmk/src/mappings/ansi/sk650.h b/dependencies/libcmmk/src/mappings/ansi/sk650.h deleted file mode 100644 index 913c0b9c..00000000 --- a/dependencies/libcmmk/src/mappings/ansi/sk650.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * This file is part of libcmmk. - * - * libcmmk is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * libcmmk is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with libcmmk. If not, see . - */ -static keyboard_layout layout_ansi_sk650 = { - {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, -}; \ No newline at end of file diff --git a/dependencies/libcmmk/src/mappings/iso/mk750.h b/dependencies/libcmmk/src/mappings/iso/mk750.h deleted file mode 100644 index 5cc2ec13..00000000 --- a/dependencies/libcmmk/src/mappings/iso/mk750.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * This file is part of libcmmk. - * - * libcmmk is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * libcmmk is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with libcmmk. If not, see . - */ -static keyboard_layout layout_iso_mk750 = { - /* - ESC F1 F2 F3 F4 XXX F5 F6 F7 F8 XXX F9 F10 F11 F12 PRN SCL PAU MUT PLA REW FWD */ - {96, 97, 98, 99, 104, -1, 105, 106, 112, 113, -1, 114, 67, 68, 69, 102, 103, 107, 111, 110, 108, 109}, - - /* - ^ 1 2 3 4 5 6 7 8 9 0 ß ´ XXX BCK INS HOM PUP #LCK #/ #* #- */ - {0, 1, 8, 9, 16, 17, 24, 25, 32, 33, 40, 41, 48, -1, 49, 56, 57, 64, 72, 73, 80, 81}, - - /* - TAB Q W E R T Z/Y U I O P Ü/[ +/] XXX ENT DEL END PDN #7 #8 #9 #+ */ - {2, 3, 10, 11, 18, 19, 26, 27, 34, 35, 42, 43, 50, -1, 52, 58, 59, 66, 74, 75, 82, 83}, - - /* - CAP A S D F G H J K L Ö/; Ä/' #/C42 XXX XXX XXX XXX XXX #4 #5 #6 XXX */ - {4, 5, 12, 13, 20, 21, 28, 29, 36, 37, 44, 45, 119, -1, -1, -1, -1, -1, 76, 77, 84, -1}, - - /* - LSHFT . - */ -static keyboard_layout layout_iso_pro_l = { - /* - ESC F1 F2 F3 F4 XXX F5 F6 F7 F8 XXX F9 F10 F11 F12 PRN SCL PAU P1 P2 P3 P4 */ - {11, 22, 30, 25, 27, -1, 7, 51, 57, 62, -1, 86, 87, 83, 85, 79, 72, 0, 101, 109, 117, 119}, - - /* - ^ 1 2 3 4 5 6 7 8 9 0 ß ´ XXX BCK INS HOM PUP #LCK #/ #* #- */ - {14, 15, 23, 31, 39, 38, 46, 47, 55, 63, 71, 70, 54, -1, 81, 3, 1, 2, 100, 108, 116, 118}, - - /* - TAB Q W E R T Z/Y U I O P Ü/[ +/] XXX ENT DEL END PDN #7 #8 #9 #+ */ - {9, 8, 16, 24, 32, 33, 41, 40, 48, 56, 64, 65, 49, -1, 84, 94, 92, 88, 96, 104, 112, 110}, - - /* - CAP A S D F G H J K L Ö/; Ä/' #/C42 XXX XXX XXX XXX XXX #4 #5 #6 XXX */ - {17, 10, 18, 26, 34, 35, 43, 42, 50, 58, 66, 67, 68, -1, -1, -1, -1, -1, 97, 105, 113, -1}, - - /* - LSHFT . - */ -static keyboard_layout layout_iso_pro_s = { -/* ESC F1 F2 F3 F4 XXX F5 F6 F7 F8 XXX F9 F10 F11 F12 PRN SCRLK PAUSE XXX XXX XXX XXX */ -{ 96, 97, 98, 99, 104, -1, 105, 106, 112, 113, -1, 114, 67, 68, 69, 102, 103, 107, -1, -1, -1, -1}, - -/* ` 1 2 3 4 5 6 7 8 9 0 - +/ˆ XXX BKSPC INSRT HOME PGUP NUMLK #/ #* #- */ -{ 0, 1, 8, 9, 16, 17, 24, 25, 32, 33, 40, 41, 48, -1, 49, 56, 57, 64, -1, -1, -1, -1}, - -/* TAB Q W E R T Y U I O P [ ]/¨ XXX ENTER DELTE END PGDN #7 #8 #9 #+ */ -{ 2, 3, 10, 11, 18, 19, 26, 27, 34, 35, 42, 43, 50, -1, 52, 58, 59, 66, -1, -1, -1, -1}, - -/* CAPLK A S D F G H J K L ; ' \ XXX XXX XXX XXX XXX #4 #5 #6 XXX */ -{ 4, 5, 12, 13, 20, 21, 28, 29, 36, 37, 44, 45, 89, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - -/* LSHFT < Z X C V B N M , . / XXX XXX RSHFT XXX UP XXX #1 #2 #3 #ENTR */ -{ 6, 100, 7, 14, 15, 22, 23, 30, 31, 38, 39, 46, -1, -1, 47, -1, 61, -1, -1, -1, -1, -1}, - -/* LCTRL LWIN LALT XXX XXX XXX SPACE XXX XXX XXX RALT RWIN FNC XXX RCTRL LEFT DOWN RIGHT #0 XXX #. XXX */ -{ 91, 90, 92, -1, -1, -1, 93, -1, -1, -1, 94, 95, 60, -1, 54, 63, 62, 70, -1, -1, -1, -1}, - -{ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, -}; diff --git a/dependencies/libcmmk/src/mappings/iso/sk630.h b/dependencies/libcmmk/src/mappings/iso/sk630.h deleted file mode 100644 index 972c243d..00000000 --- a/dependencies/libcmmk/src/mappings/iso/sk630.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * This file is part of libcmmk. - * - * libcmmk is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * libcmmk is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with libcmmk. If not, see . - */ -static keyboard_layout layout_iso_sk630 = { - /* - ESC F1 F2 F3 F4 XXX F5 F6 F7 F8 XXX F9 F10 F11 F12 PRN SCL PAU MUT PLA REW FWD */ - { 9, 33, 41, 49, 57, -1, 73, 81, 89, 97, -1, 105, 113, 121, 129, 137, 145, 153, -1, -1, -1, -1}, - - /* - ^ 1 2 3 4 5 6 7 8 9 0 ß ´ XXX BCK INS HOM PUP #LCK #/ #* #- */ - {10, 26, 34, 42, 50, 58, 66, 74, 82, 90, 98, 106, 114, -1, 130, 138, 146, 154, -1, -1, -1, -1}, - - /* - TAB Q W E R T Z/Y U I O P Ü/[ +/] XXX ENT DEL END PDN #7 #8 #9 #+ */ - {11, 27, 35, 43, 51, 59, 67, 75, 83, 91, 99, 107, 115, -1, 132, 139, 147, 155, -1, -1, -1, -1}, - - /* - CAP A S D F G H J K L Ö/; Ä/' #/C42 XXX XXX XXX XXX XXX #4 #5 #6 XXX */ - {12, 28, 36, 44, 52, 60, 68, 76, 84, 92, 100, 108, 124, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - - /* - LSHFT . - */ -static keyboard_layout layout_iso_sk650 = { - /* - ESC F1 F2 F3 F4 XXX F5 F6 F7 F8 XXX F9 F10 F11 F12 PRN SCL PAU MUT PLA REW FWD */ - { 9, 33, 41, 49, 57, -1, 73, 81, 89, 97, -1, 105, 113, 121, 129, 137, 145, 153, -1, -1, -1, -1}, - - /* - ^ 1 2 3 4 5 6 7 8 9 0 ß ´ XXX BCK INS HOM PUP #LCK #/ #* #- */ - {10, 26, 34, 42, 50, 58, 66, 74, 82, 90, 98, 106, 114, -1, 130, 138, 146, 154, 162, 170, 178, 186}, - - /* - TAB Q W E R T Z/Y U I O P Ü/[ +/] XXX ENT DEL END PDN #7 #8 #9 #+ */ - {11, 27, 35, 43, 51, 59, 67, 75, 83, 91, 99, 107, 115, -1, 132, 139, 147, 155, 163, 171, 179, 187}, - - /* - CAP A S D F G H J K L Ö/; Ä/' #/C42 XXX XXX XXX XXX XXX #4 #5 #6 XXX */ - {12, 28, 36, 44, 52, 60, 68, 76, 84, 92, 100, 108, 124, -1, -1, -1, -1, -1, 164, 172, 180, -1}, - - /* - LSHFT