Compare commits

...
6 changed files with 1321 additions and 0 deletions
@@ -0,0 +1,557 @@
/*-------------------------------------------------------------------*\
| QMKRGBMatrixController.cpp |
| |
| Driver for QMK keybaords using RGB Matrix |
| |
| Kasper 10th Octobber 2020 |
| |
\*-------------------------------------------------------------------*/
#include "QMKRGBMatrixController.h"
#include <cstring>
QMKRGBMatrixController::QMKRGBMatrixController
(
hid_device* dev_handle,
const char* path,
unsigned short vendor_id
)
{
dev = dev_handle;
location = path;
unsigned int massdrop_vid = 0x04D8;
// ATSAM (MD) boards will crash eventually if this is higher than 2
}
QMKRGBMatrixController::~QMKRGBMatrixController()
{
hid_close(dev);
}
std::string QMKRGBMatrixController::GetLocation()
{
return location;
}
void QMKRGBMatrixController::DirectModeSetSingleLED(unsigned int led, unsigned char red, unsigned char green, unsigned char blue)
{
unsigned char usb_buf[33];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, sizeof(usb_buf));
/*-----------------------------------------------------*\
| Set up config table request packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x00;
usb_buf[0x01] = QMK_RGBMATRIX_DIRECT_MODE_SET_SINGLE_LED;
usb_buf[0x02] = led;
usb_buf[0x03] = red;
usb_buf[0x04] = green;
usb_buf[0x05] = blue;
/*-----------------------------------------------------*\
| Send packet |
\*-----------------------------------------------------*/
hid_write(dev, usb_buf, 33);
hid_read(dev, usb_buf, 33);
}
void QMKRGBMatrixController::DirectModeSetLEDs(std::vector<RGBColor> colors, unsigned int leds_count)
{
unsigned int leds_sent = 0;
unsigned int leds_per_update = 20;
while(leds_sent < leds_count)
{
if((leds_count - leds_sent) < leds_per_update)
{
leds_per_update = leds_count - leds_sent;
}
unsigned char usb_buf[65];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, sizeof(usb_buf));
/*-----------------------------------------------------*\
| Set up config table request packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x00;
usb_buf[0x01] = QMK_RGBMATRIX_DIRECT_MODE_SET_LEDS;
usb_buf[0x02] = leds_sent;
usb_buf[0x03] = leds_per_update;
for(unsigned int led_idx = 0; led_idx < leds_per_update; led_idx++)
{
usb_buf[(led_idx * 3) + 4] = RGBGetRValue(colors[led_idx + leds_sent]);
usb_buf[(led_idx * 3) + 5] = RGBGetGValue(colors[led_idx + leds_sent]);
usb_buf[(led_idx * 3) + 6] = RGBGetBValue(colors[led_idx + leds_sent]);
}
hid_write(dev, usb_buf, 65);
hid_read_timeout(dev, usb_buf, 65, 3);
leds_sent += leds_per_update;
}
}
RGBColor QMKRGBMatrixController::DirectModeGetLEDColor(unsigned int led)
{
unsigned char usb_buf[33];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, sizeof(usb_buf));
/*-----------------------------------------------------*\
| Set up config table request packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x00;
usb_buf[0x01] = QMK_RGBMATRIX_DIRECT_MODE_GET_LED_COLOR;
usb_buf[0x02] = led;
do
{
hid_write(dev, (unsigned char*)usb_buf, 33);
hid_read_timeout(dev, (unsigned char*)usb_buf, 33, 20);
}
while(usb_buf[0x00] != QMK_RGBMATRIX_DIRECT_MODE_GET_LED_COLOR);
return ToRGBColor(usb_buf[1], usb_buf[2], usb_buf[3]);
}
void QMKRGBMatrixController::QMKModeSetModeAndSpeed(unsigned char mode, unsigned char speed)
{
unsigned char usb_buf[33];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, sizeof(usb_buf));
/*-----------------------------------------------------*\
| Set up config table request packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x00;
usb_buf[0x01] = QMK_RGBMATRIX_QMK_MODE_SET_MODE_AND_SPEED;
usb_buf[0x02] = mode;
usb_buf[0x03] = speed;
/*-----------------------------------------------------*\
| Send packet |
\*-----------------------------------------------------*/
hid_write(dev, usb_buf, 33);
hid_read(dev, usb_buf, 33);
}
void QMKRGBMatrixController::QMKModeSetColorModeAndSpeed(hsv_t hsv_color, unsigned char mode, unsigned char speed)
{
unsigned char usb_buf[33];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, sizeof(usb_buf));
/*-----------------------------------------------------*\
| Set up config table request packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x00;
usb_buf[0x01] = QMK_RGBMATRIX_QMK_MODE_SET_COLOR_MODE_AND_SPEED;
// qmk hue range is between 0-255, instead of the regular 0-359, so hue needs to be converted
usb_buf[0x02] = hsv_color.hue * 255 / 359;
usb_buf[0x03] = hsv_color.saturation;
usb_buf[0x04] = hsv_color.value;
usb_buf[0x05] = mode;
usb_buf[0x06] = speed;
/*-----------------------------------------------------*\
| Send packet |
\*-----------------------------------------------------*/
hid_write(dev, usb_buf, 33);
hid_read(dev, usb_buf, 33);
}
unsigned int QMKRGBMatrixController::QMKModeGetColor()
{
unsigned char usb_buf[33];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, sizeof(usb_buf));
/*-----------------------------------------------------*\
| Set up config table request packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x00;
usb_buf[0x01] = QMK_RGBMATRIX_QMK_MODE_GET_COLOR;
do
{
hid_write(dev, (unsigned char*)usb_buf, 33);
hid_read_timeout(dev, (unsigned char*)usb_buf, 33, 20);
}
while(usb_buf[0x00] != QMK_RGBMATRIX_QMK_MODE_GET_COLOR);
// qmk hue range is between 0-255, instead of the regular 0-359, so hue needs to be converted
unsigned int oldRange = 255;
unsigned int newRange = 359;
unsigned int convertedHue = (usb_buf[1] * newRange / oldRange);
hsv_t hsv;
hsv.hue = convertedHue;
hsv.saturation = usb_buf[2];
hsv.value = usb_buf[3];
return hsv2rgb(&hsv);
}
unsigned int QMKRGBMatrixController::GetProtocolVersion()
{
unsigned char usb_buf[33];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, sizeof(usb_buf));
/*-----------------------------------------------------*\
| Set up config table request packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x00;
usb_buf[0x01] = QMK_RGBMATRIX_GET_PROTOCOL_VERSION;
do
{
hid_write(dev, (unsigned char*)usb_buf, 33);
hid_read_timeout(dev, (unsigned char*)usb_buf, 33, 20);
}
while(usb_buf[0x00] != QMK_RGBMATRIX_GET_PROTOCOL_VERSION);
return usb_buf[1];
}
std::string QMKRGBMatrixController::GetDeviceName()
{
unsigned char usb_buf[33];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, sizeof(usb_buf));
/*-----------------------------------------------------*\
| Set up config table request packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x00;
usb_buf[0x01] = QMK_RGBMATRIX_GET_DEVICE_NAME;
do
{
hid_write(dev, (unsigned char*)usb_buf, 33);
hid_read_timeout(dev, (unsigned char*)usb_buf, 33, 20);
}
while(usb_buf[0x00] != QMK_RGBMATRIX_GET_DEVICE_NAME);
int i = 1;
std::string name;
while(usb_buf[i] != 0)
{
name.push_back(usb_buf[i]);
i++;
}
return name;
}
std::string QMKRGBMatrixController::GetDeviceVendor()
{
unsigned char usb_buf[33];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, sizeof(usb_buf));
/*-----------------------------------------------------*\
| Set up config table request packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x00;
usb_buf[0x01] = QMK_RGBMATRIX_GET_DEVICE_VENDOR;
do
{
hid_write(dev, (unsigned char*)usb_buf, 33);
hid_read_timeout(dev, (unsigned char*)usb_buf, 33, 20);
}
while(usb_buf[0x00] != QMK_RGBMATRIX_GET_DEVICE_VENDOR);
int i = 1;
std::string vendor;
while(usb_buf[i] != 0)
{
vendor.push_back(usb_buf[i]);
i++;
}
return vendor;
}
bool QMKRGBMatrixController::GetEnabledModes(int mode)
{
unsigned char usb_buf[33];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, sizeof(usb_buf));
/*-----------------------------------------------------*\
| Set up config table request packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x00;
usb_buf[0x01] = QMK_RGBMATRIX_GET_ENABLED_MODES;
usb_buf[0x02] = mode;
do
{
hid_write(dev, (unsigned char*)usb_buf, 33);
hid_read_timeout(dev, (unsigned char*)usb_buf, 33, 20);
}
while(usb_buf[0x00] != QMK_RGBMATRIX_GET_ENABLED_MODES);
return usb_buf[1] == QMK_RGBMATRIX_SUCCESS ? true : false;
}
unsigned int QMKRGBMatrixController::GetActiveMode()
{
unsigned char usb_buf[33];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, sizeof(usb_buf));
/*-----------------------------------------------------*\
| Set up config table request packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x00;
usb_buf[0x01] = QMK_RGBMATRIX_GET_ACTIVE_MODE;
do
{
hid_write(dev, (unsigned char*)usb_buf, 33);
hid_read_timeout(dev, (unsigned char*)usb_buf, 33, 20);
}
while(usb_buf[0x00] != QMK_RGBMATRIX_GET_ACTIVE_MODE);
return usb_buf[1];
}
unsigned int QMKRGBMatrixController::GetZonesCount()
{
unsigned char usb_buf[33];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, sizeof(usb_buf));
/*-----------------------------------------------------*\
| Set up config table request packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x00;
usb_buf[0x01] = QMK_RGBMATRIX_GET_ZONES_COUNT;
do
{
hid_write(dev, (unsigned char*)usb_buf, 33);
hid_read_timeout(dev, (unsigned char*)usb_buf, 33, 20);
}
while(usb_buf[0x00] != QMK_RGBMATRIX_GET_ZONES_COUNT);
return usb_buf[1];
}
std::string QMKRGBMatrixController::GetZoneName(int zone)
{
unsigned char usb_buf[33];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, sizeof(usb_buf));
/*-----------------------------------------------------*\
| Set up config table request packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x00;
usb_buf[0x01] = QMK_RGBMATRIX_GET_ZONE_NAME;
usb_buf[0x02] = zone;
do
{
hid_write(dev, (unsigned char*)usb_buf, 33);
hid_read_timeout(dev, (unsigned char*)usb_buf, 33, 20);
}
while(usb_buf[0x00] != QMK_RGBMATRIX_GET_ZONE_NAME);
int i = 1;
std::string name;
while(usb_buf[i] != 0)
{
name.push_back(usb_buf[i]);
i++;
}
return name;
}
unsigned int QMKRGBMatrixController::GetZoneType(int zone)
{
unsigned char usb_buf[33];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, sizeof(usb_buf));
/*-----------------------------------------------------*\
| Set up config table request packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x00;
usb_buf[0x01] = QMK_RGBMATRIX_GET_ZONE_TYPE;
usb_buf[0x02] = zone;
do
{
hid_write(dev, (unsigned char*)usb_buf, 33);
hid_read_timeout(dev, (unsigned char*)usb_buf, 33, 20);
}
while(usb_buf[0x00] != QMK_RGBMATRIX_GET_ZONE_TYPE);
return usb_buf[1];
}
unsigned int QMKRGBMatrixController::GetZoneSize(int zone)
{
unsigned char usb_buf[33];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, sizeof(usb_buf));
/*-----------------------------------------------------*\
| Set up config table request packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x00;
usb_buf[0x01] = QMK_RGBMATRIX_GET_ZONE_SIZE;
usb_buf[0x02] = zone;
do
{
hid_write(dev, (unsigned char*)usb_buf, 33);
hid_read_timeout(dev, (unsigned char*)usb_buf, 33, 20);
}
while(usb_buf[0x00] != QMK_RGBMATRIX_GET_ZONE_SIZE);
return usb_buf[1];
}
unsigned int QMKRGBMatrixController::GetLEDMatirxRows()
{
unsigned char usb_buf[33];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, sizeof(usb_buf));
/*-----------------------------------------------------*\
| Set up config table request packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x00;
usb_buf[0x01] = QMK_RGBMATRIX_GET_LED_MATRIX_ROWS;
do
{
hid_write(dev, (unsigned char*)usb_buf, 33);
hid_read_timeout(dev, (unsigned char*)usb_buf, 33, 1000);
}
while(usb_buf[0x00] != QMK_RGBMATRIX_GET_LED_MATRIX_ROWS);
return usb_buf[1];
}
unsigned int QMKRGBMatrixController::GetLEDMatirxColumns()
{
unsigned char usb_buf[33];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, sizeof(usb_buf));
/*-----------------------------------------------------*\
| Set up config table request packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x00;
usb_buf[0x01] = QMK_RGBMATRIX_GET_LED_MATRIX_COLUMNS;
do
{
hid_write(dev, (unsigned char*)usb_buf, 33);
hid_read_timeout(dev, (unsigned char*)usb_buf, 33, 20);
}
while(usb_buf[0x00] != QMK_RGBMATRIX_GET_LED_MATRIX_COLUMNS);
return usb_buf[1];
}
unsigned int QMKRGBMatrixController::GetLEDValueInMatrix(int column, int row)
{
unsigned char usb_buf[33];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, sizeof(usb_buf));
/*-----------------------------------------------------*\
| Set up config table request packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x00;
usb_buf[0x01] = QMK_RGBMATRIX_GET_LED_VALUE_IN_MATRIX;
usb_buf[0x02] = column;
usb_buf[0x03] = row;
do
{
hid_write(dev, (unsigned char*)usb_buf, 33);
hid_read_timeout(dev, (unsigned char*)usb_buf, 33, 20);
}
while(usb_buf[0x00] != QMK_RGBMATRIX_GET_LED_VALUE_IN_MATRIX);
return usb_buf[1];
}
std::string QMKRGBMatrixController::GetLEDName(int led_column, int led_row)
{
unsigned char usb_buf[33];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, sizeof(usb_buf));
/*-----------------------------------------------------*\
| Set up config table request packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x00;
usb_buf[0x01] = QMK_RGBMATRIX_GET_LED_NAME;
usb_buf[0x02] = led_column;
usb_buf[0x03] = led_row;
do
{
hid_write(dev, (unsigned char*)usb_buf, 33);
hid_read_timeout(dev, (unsigned char*)usb_buf, 33, 20);
}
while(usb_buf[0x00] != QMK_RGBMATRIX_GET_LED_NAME);
return QMKKeycodeToKeyNameMap[usb_buf[1]];
}
@@ -0,0 +1,319 @@
/*-------------------------------------------------------------------*\
| QMKRGBMatrixController.h |
| |
| Driver for QMK keybaords using RGB Matrix |
| |
| Kasper 10th Octobber 2020 |
| |
\*-------------------------------------------------------------------*/
#include <string>
#include <array>
#include <map>
#include <hidapi/hidapi.h>
#include "RGBController.h"
#include "hsv.h"
#pragma once
enum CommandsId {
QMK_RGBMATRIX_EOM,
QMK_RGBMATRIX_SUCCESS,
QMK_RGBMATRIX_FAILURE,
QMK_RGBMATRIX_DIRECT_MODE_SET_SINGLE_LED,
QMK_RGBMATRIX_DIRECT_MODE_SET_LEDS,
QMK_RGBMATRIX_DIRECT_MODE_GET_LED_COLOR,
QMK_RGBMATRIX_QMK_MODE_SET_MODE_AND_SPEED,
QMK_RGBMATRIX_QMK_MODE_SET_COLOR_MODE_AND_SPEED,
QMK_RGBMATRIX_QMK_MODE_GET_COLOR,
QMK_RGBMATRIX_GET_PROTOCOL_VERSION,
QMK_RGBMATRIX_GET_DEVICE_NAME,
QMK_RGBMATRIX_GET_DEVICE_VENDOR,
QMK_RGBMATRIX_GET_ENABLED_MODES,
QMK_RGBMATRIX_GET_ACTIVE_MODE,
QMK_RGBMATRIX_GET_ZONES_COUNT,
QMK_RGBMATRIX_GET_ZONE_NAME,
QMK_RGBMATRIX_GET_ZONE_TYPE,
QMK_RGBMATRIX_GET_ZONE_SIZE,
QMK_RGBMATRIX_GET_LED_MATRIX_COLUMNS,
QMK_RGBMATRIX_GET_LED_MATRIX_ROWS,
QMK_RGBMATRIX_GET_LED_VALUE_IN_MATRIX,
QMK_RGBMATRIX_GET_LED_NAME
};
enum ModeCommands
{
QMK_RGBMATRIX_MODE_OPENRGB_DIRECT = 1,
QMK_RGBMATRIX_MODE_SOLID_COLOR,
QMK_RGBMATRIX_MODE_ALPHA_MOD,
QMK_RGBMATRIX_MODE_GRADIENT_UP_DOWN,
QMK_RGBMATRIX_MODE_GRADIENT_LEFT_RIGHT,
QMK_RGBMATRIX_MODE_BREATHING,
QMK_RGBMATRIX_MODE_BAND_SAT,
QMK_RGBMATRIX_MODE_BAND_VAL,
QMK_RGBMATRIX_MODE_BAND_PINWHEEL_SAT,
QMK_RGBMATRIX_MODE_BAND_PINWHEEL_VAL,
QMK_RGBMATRIX_MODE_BAND_SPIRAL_SAT,
QMK_RGBMATRIX_MODE_BAND_SPIRAL_VAL,
QMK_RGBMATRIX_MODE_CYCLE_ALL,
QMK_RGBMATRIX_MODE_CYCLE_LEFT_RIGHT,
QMK_RGBMATRIX_MODE_CYCLE_UP_DOWN,
QMK_RGBMATRIX_MODE_CYCLE_OUT_IN,
QMK_RGBMATRIX_MODE_CYCLE_OUT_IN_DUAL,
QMK_RGBMATRIX_MODE_RAINBOW_MOVING_CHEVRON,
QMK_RGBMATRIX_MODE_CYCLE_PINWHEEL,
QMK_RGBMATRIX_MODE_CYCLE_SPIRAL,
QMK_RGBMATRIX_MODE_DUAL_BEACON,
QMK_RGBMATRIX_MODE_RAINBOW_BEACON,
QMK_RGBMATRIX_MODE_RAINBOW_PINWHEELS,
QMK_RGBMATRIX_MODE_RAINDROPS,
QMK_RGBMATRIX_MODE_JELLYBEAN_RAINDROPS,
QMK_RGBMATRIX_MODE_TYPING_HEATMAP,
QMK_RGBMATRIX_MODE_DIGITAL_RAIN,
QMK_RGBMATRIX_MODE_SOLID_REACTIVE_SIMPLE,
QMK_RGBMATRIX_MODE_SOLID_REACTIVE,
QMK_RGBMATRIX_MODE_SOLID_REACTIVE_WIDE,
QMK_RGBMATRIX_MODE_SOLID_REACTIVE_MULTIWIDE,
QMK_RGBMATRIX_MODE_SOLID_REACTIVE_CROSS,
QMK_RGBMATRIX_MODE_SOLID_REACTIVE_MULTICROSS,
QMK_RGBMATRIX_MODE_SOLID_REACTIVE_NEXUS,
QMK_RGBMATRIX_MODE_SOLID_REACTIVE_MULTINEXUS,
QMK_RGBMATRIX_MODE_SPLASH,
QMK_RGBMATRIX_MODE_MULTISPLASH,
QMK_RGBMATRIX_MODE_SOLID_SPLASH,
QMK_RGBMATRIX_MODE_SOLID_MULTISPLASH,
};
enum SpeedCommands
{
QMK_RGBMATRIX_SPEED_SLOWEST = 0x00, /* Slowest speed */
QMK_RGBMATRIX_SPEED_NORMAL = 0x7F, /* Normal speed */
QMK_RGBMATRIX_SPEED_FASTEST = 0xFF, /* Fastest speed */
};
class QMKRGBMatrixController
{
public:
QMKRGBMatrixController
(
hid_device* dev_handle,
const char* path,
unsigned short vendor_id
);
~QMKRGBMatrixController();
std::string GetLocation();
void DirectModeSetSingleLED(unsigned int led, unsigned char red, unsigned char green, unsigned char blue);
void DirectModeSetLEDs(std::vector<RGBColor> colors, unsigned int num_colors);
RGBColor DirectModeGetLEDColor(unsigned int led);
void QMKModeSetModeAndSpeed(unsigned char mode, unsigned char speed);
void QMKModeSetColorModeAndSpeed(hsv_t hsv_color, unsigned char mode, unsigned char speed);
unsigned int QMKModeGetColor();
unsigned int GetProtocolVersion();
std::string GetDeviceName();
std::string GetDeviceVendor();
bool GetEnabledModes(int mode);
unsigned int GetActiveMode();
unsigned int GetZonesCount();
std::string GetZoneName(int zone);
unsigned int GetZoneType(int zone);
unsigned int GetZoneSize(int zone);
unsigned int GetLEDMatirxRows();
unsigned int GetLEDMatirxColumns();
unsigned int GetLEDValueInMatrix(int column, int row);
std::string GetLEDName(int led_column, int led_row);
protected:
hid_device* dev;
private:
std::string location;
std::map<uint8_t, std::string> QMKKeycodeToKeyNameMap
{
{ 0, "" },
{ 1, "Right Fn" },
{ 2, "Right Fn" },
{ 3, "" },
{ 4, "A" },
{ 5, "B" },
{ 6, "C" },
{ 7, "D" },
{ 8, "E" },
{ 9, "F" },
{ 10, "G" },
{ 11, "H" },
{ 12, "I" },
{ 13, "J" },
{ 14, "K" },
{ 15, "L" },
{ 16, "M" },
{ 17, "N" },
{ 18, "O" },
{ 19, "P" },
{ 20, "Q" },
{ 21, "R" },
{ 22, "S" },
{ 23, "T" },
{ 24, "U" },
{ 25, "V" },
{ 26, "W" },
{ 27, "X" },
{ 28, "Y" },
{ 29, "Z" },
{ 30, "1" },
{ 31, "2" },
{ 32, "3" },
{ 33, "4" },
{ 34, "5" },
{ 35, "6" },
{ 36, "7" },
{ 37, "8" },
{ 38, "9" },
{ 39, "0" },
{ 40, "Enter" },
{ 41, "Escape" },
{ 42, "Backspace" },
{ 43, "Tab" },
{ 44, "Space" },
{ 45, "-" },
{ 46, "=" },
{ 47, "[" },
{ 48, "]" },
{ 49, "\\ (ANSI)" },
{ 50, "#" },
{ 51, ";" },
{ 52, "'" },
{ 53, "`" },
{ 54, "," },
{ 55, "." },
{ 56, "/" },
{ 57, "Caps Lock" },
{ 58, "F1" },
{ 59, "F2" },
{ 60, "F3" },
{ 61, "F4" },
{ 62, "F5" },
{ 63, "F6" },
{ 64, "F7" },
{ 65, "F8" },
{ 66, "F9" },
{ 67, "F10" },
{ 68, "F11" },
{ 69, "F12" },
{ 70, "Print Screen" },
{ 71, "Scroll Lock" },
{ 72, "Pause/Break" },
{ 73, "Insert" },
{ 74, "Home" },
{ 75, "Page Up" },
{ 76, "Delete" },
{ 77, "End" },
{ 78, "Page Down" },
{ 79, "Right Arrow" },
{ 80, "Left Arrow" },
{ 81, "Down Arrow" },
{ 82, "Up Arrow" },
{ 83, "Num Lock" },
{ 84, "Number Pad /" },
{ 85, "Number Pad *" },
{ 86, "Number Pad -" },
{ 87, "Number Pad +" },
{ 88, "Number Pad Enter" },
{ 89, "Number Pad 1" },
{ 90, "Number Pad 2" },
{ 91, "Number Pad 3" },
{ 92, "Number Pad 4" },
{ 93, "Number Pad 5" },
{ 94, "Number Pad 6" },
{ 95, "Number Pad 7" },
{ 96, "Number Pad 8" },
{ 97, "Number Pad 9" },
{ 98, "Number Pad 0" },
{ 99, "Number Pad ." },
{ 100, "\\ (ISO)" },
{ 101, "Menu" },
{ 102, "" },
{ 103, "" },
{ 104, "" },
{ 105, "" },
{ 106, "" },
{ 107, "" },
{ 108, "" },
{ 109, "" },
{ 110, "" },
{ 111, "" },
{ 112, "" },
{ 113, "" },
{ 114, "" },
{ 115, "" },
{ 116, "" },
{ 117, "" },
{ 118, "" },
{ 119, "" },
{ 120, "" },
{ 121, "" },
{ 122, "" },
{ 123, "" },
{ 124, "" },
{ 125, "" },
{ 126, "" },
{ 127, "" },
{ 128, "" },
{ 129, "" },
{ 130, "" },
{ 131, "" },
{ 132, "" },
{ 133, "" },
{ 134, "" },
{ 135, "\\ (INT1)" },
{ 136, "" },
{ 137, "" },
{ 138, "" },
{ 139, "" },
{ 140, "" },
{ 141, "" },
{ 142, "" },
{ 143, "" },
{ 144, "" },
{ 145, "" },
{ 146, "" },
{ 147, "" },
{ 148, "" },
{ 149, "" },
{ 150, "" },
{ 151, "" },
{ 152, "" },
{ 153, "" },
{ 154, "" },
{ 155, "" },
{ 156, "" },
{ 157, "" },
{ 158, "" },
{ 159, "" },
{ 160, "" },
{ 161, "" },
{ 162, "" },
{ 163, "" },
{ 164, "" },
{ 216, "Left Shift"}, // Space Cadet Left Shift
{ 217, "Right Shift"}, // Space Cadet Right Shift
{ 224, "Left Control" },
{ 225, "Left Shift" },
{ 226, "Left Alt" },
{ 227, "Left Windows" },
{ 228, "Right Control" },
{ 229, "Right Shift" },
{ 230, "Right Alt" },
{ 231, "Right Windows" },
};
};
@@ -0,0 +1,57 @@
/*-------------------------------------------------------------------*\
| QMKRGBMatrixControllerDetect.cpp |
| |
| Driver for QMK keybaords using RGB Matrix |
| |
| Kasper24 11th November 2020 |
| |
\*-------------------------------------------------------------------*/
#include "Detector.h"
#include "QMKRGBMatrixController.h"
#include "RGBController.h"
#include "RGBController_QMKRGBMatrix.h"
#include <hidapi/hidapi.h>
/*-----------------------------------------------------*\
| Protocol version |
\*-----------------------------------------------------*/
#define QMK_RGB_MATRIX_PROTOCOL_VERSION 0x01
/*-----------------------------------------------------*\
| Usage and Usage Page |
\*-----------------------------------------------------*/
#define QMK_USAGE_PAGE 0xFF60
#define QMK_USAGE 0x61
/*-----------------------------------------------------*\
| Massdrop |
\*-----------------------------------------------------*/
#define MASSDROP_VID 0x04D8
#define MASSDROP_ALT_PID 0xEED3
#define MASSDROP_CTRL_PID 0xEED2
void DetectQMKRGBMatrixControllers(hid_device_info* info, const std::string& name)
{
hid_device* dev = hid_open_path(info->path);
if(dev)
{
QMKRGBMatrixController* controller = new QMKRGBMatrixController(dev, info->path, info->vendor_id);
unsigned int version = controller->GetProtocolVersion();
if(version == QMK_RGB_MATRIX_PROTOCOL_VERSION)
{
RGBController_QMKRGBMatrix* rgb_controller = new RGBController_QMKRGBMatrix(controller, version);
ResourceManager::get()->RegisterRGBController(rgb_controller);
}
else
{
delete controller;
}
}
}
REGISTER_HID_DETECTOR_IPU("Massdrop Alt", DetectQMKRGBMatrixControllers, MASSDROP_VID, MASSDROP_ALT_PID, 1, QMK_USAGE_PAGE, QMK_USAGE);
REGISTER_HID_DETECTOR_IPU("Massdrop Ctrl", DetectQMKRGBMatrixControllers, MASSDROP_VID, MASSDROP_CTRL_PID, 1, QMK_USAGE_PAGE, QMK_USAGE);
REGISTER_HID_DETECTOR_IPU("SonixQMK 0C45:5004", DetectQMKRGBMatrixControllers, 0x0C45, 0x5004, 1, QMK_USAGE_PAGE, QMK_USAGE);
REGISTER_HID_DETECTOR_IPU("SonixQMK 0C45:5104", DetectQMKRGBMatrixControllers, 0x0C45, 0x5104, 1, QMK_USAGE_PAGE, QMK_USAGE);
@@ -0,0 +1,342 @@
/*-------------------------------------------------------------------*\
| RGBController_QMKRGBMatrix.cpp |
| |
| Driver for QMK keybaords using RGB Matrix |
| |
| Kasper24 11th November 2020 |
| |
\*-------------------------------------------------------------------*/
#include "hsv.h"
#include "RGBController_QMKRGBMatrix.h"
RGBController_QMKRGBMatrix::RGBController_QMKRGBMatrix(QMKRGBMatrixController* qmk_rgb_matrix_ptr, unsigned int protocol_version)
{
qmk_rgb_matrix = qmk_rgb_matrix_ptr;
name = qmk_rgb_matrix_ptr->GetDeviceName();
vendor = qmk_rgb_matrix_ptr->GetDeviceVendor();
description = "QMK RGB Matrix Device";
type = DEVICE_TYPE_KEYBOARD;
location = qmk_rgb_matrix_ptr->GetLocation();
version = std::to_string(protocol_version);
unsigned int current_mode = 1;
unsigned int hsv = 0;
//unsigned int hsv = qmk_rgb_matrix_ptr->QMKModeGetColor();
//if (qmk_rgb_matrix_ptr->GetEnabledModes(QMK_RGBMATRIX_MODE_OPENRGB_DIRECT))
InitializeMode("Direct", current_mode, MODE_FLAG_HAS_PER_LED_COLOR, MODE_COLORS_PER_LED, hsv);
// if (qmk_rgb_matrix_ptr->GetEnabledModes(QMK_RGBMATRIX_MODE_SOLID_COLOR))
// InitializeMode("Static", current_mode, MODE_FLAG_HAS_MODE_SPECIFIC_COLOR, MODE_COLORS_MODE_SPECIFIC, hsv);
// if (qmk_rgb_matrix_ptr->GetEnabledModes(QMK_RGBMATRIX_MODE_ALPHA_MOD))
// InitializeMode("Alpha Mod", current_mode, MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_SPEED,
// MODE_COLORS_MODE_SPECIFIC, hsv);
// if (qmk_rgb_matrix_ptr->GetEnabledModes(QMK_RGBMATRIX_MODE_GRADIENT_UP_DOWN))
// InitializeMode("Gradient Up Down", current_mode, MODE_FLAG_HAS_SPEED, MODE_COLORS_NONE, hsv);
// if (qmk_rgb_matrix_ptr->GetEnabledModes(QMK_RGBMATRIX_MODE_GRADIENT_LEFT_RIGHT))
// InitializeMode("Gradient Left Right", current_mode, MODE_FLAG_HAS_SPEED, MODE_COLORS_NONE, hsv);
// if (qmk_rgb_matrix_ptr->GetEnabledModes(QMK_RGBMATRIX_MODE_BREATHING))
// InitializeMode("Breathing", current_mode, MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_SPEED,
// MODE_COLORS_MODE_SPECIFIC, hsv);
// if (qmk_rgb_matrix_ptr->GetEnabledModes(QMK_RGBMATRIX_MODE_BAND_SAT))
// InitializeMode("Band Saturation", current_mode, MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_SPEED,
// MODE_COLORS_MODE_SPECIFIC, hsv);
// if (qmk_rgb_matrix_ptr->GetEnabledModes(QMK_RGBMATRIX_MODE_BAND_VAL))
// InitializeMode("Band Value", current_mode, MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_SPEED,
// MODE_COLORS_MODE_SPECIFIC, hsv);
// if (qmk_rgb_matrix_ptr->GetEnabledModes(QMK_RGBMATRIX_MODE_BAND_PINWHEEL_SAT))
// InitializeMode("Band Pinwheel Saturation", current_mode, MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_SPEED,
// MODE_COLORS_MODE_SPECIFIC, hsv);
// if (qmk_rgb_matrix_ptr->GetEnabledModes(QMK_RGBMATRIX_MODE_BAND_PINWHEEL_VAL))
// InitializeMode("Band Pinwheel Value", current_mode, MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_SPEED,
// MODE_COLORS_MODE_SPECIFIC, hsv);
// if (qmk_rgb_matrix_ptr->GetEnabledModes(QMK_RGBMATRIX_MODE_BAND_SPIRAL_SAT))
// InitializeMode("Band Spiral Saturation", current_mode, MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_SPEED,
// MODE_COLORS_MODE_SPECIFIC, hsv);
// if (qmk_rgb_matrix_ptr->GetEnabledModes(QMK_RGBMATRIX_MODE_BAND_SPIRAL_VAL))
// InitializeMode("Band Spiral Value", current_mode, MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_SPEED,
// MODE_COLORS_MODE_SPECIFIC, hsv);
// if (qmk_rgb_matrix_ptr->GetEnabledModes(QMK_RGBMATRIX_MODE_CYCLE_ALL))
// InitializeMode("Cycle All", current_mode, MODE_FLAG_HAS_SPEED, MODE_COLORS_NONE, hsv);
// if (qmk_rgb_matrix_ptr->GetEnabledModes(QMK_RGBMATRIX_MODE_CYCLE_LEFT_RIGHT))
// InitializeMode("Cycle Left Right", current_mode, MODE_FLAG_HAS_SPEED, MODE_COLORS_NONE, hsv);
// if (qmk_rgb_matrix_ptr->GetEnabledModes(QMK_RGBMATRIX_MODE_CYCLE_UP_DOWN))
// InitializeMode("Cycle Up Down", current_mode, MODE_FLAG_HAS_SPEED, MODE_COLORS_NONE, hsv);
// if (qmk_rgb_matrix_ptr->GetEnabledModes(QMK_RGBMATRIX_MODE_CYCLE_OUT_IN))
// InitializeMode("Cycle Out In", current_mode, MODE_FLAG_HAS_SPEED, MODE_COLORS_NONE, hsv);
// if (qmk_rgb_matrix_ptr->GetEnabledModes(QMK_RGBMATRIX_MODE_CYCLE_OUT_IN_DUAL))
// InitializeMode("Cycle Out In Dual", current_mode, MODE_FLAG_HAS_SPEED, MODE_COLORS_NONE, hsv);
// if (qmk_rgb_matrix_ptr->GetEnabledModes(QMK_RGBMATRIX_MODE_RAINBOW_MOVING_CHEVRON))
// InitializeMode("Rainbow Moving Chevron", current_mode, MODE_FLAG_HAS_SPEED, MODE_COLORS_NONE, hsv);
// if (qmk_rgb_matrix_ptr->GetEnabledModes(QMK_RGBMATRIX_MODE_CYCLE_PINWHEEL))
// InitializeMode("Cycle Pinwheel", current_mode, MODE_FLAG_HAS_SPEED, MODE_COLORS_NONE, hsv);
// if (qmk_rgb_matrix_ptr->GetEnabledModes(QMK_RGBMATRIX_MODE_CYCLE_SPIRAL))
// InitializeMode("Cycle Spiral", current_mode, MODE_FLAG_HAS_SPEED, MODE_COLORS_NONE, hsv);
// if (qmk_rgb_matrix_ptr->GetEnabledModes(QMK_RGBMATRIX_MODE_DUAL_BEACON))
// InitializeMode("Dual Beacon", current_mode, MODE_FLAG_HAS_SPEED, MODE_COLORS_NONE, hsv);
// if (qmk_rgb_matrix_ptr->GetEnabledModes(QMK_RGBMATRIX_MODE_RAINBOW_BEACON))
// InitializeMode("Rainbow Beacon", current_mode, MODE_FLAG_HAS_SPEED, MODE_COLORS_NONE, hsv);
// if (qmk_rgb_matrix_ptr->GetEnabledModes(QMK_RGBMATRIX_MODE_RAINBOW_PINWHEELS))
// InitializeMode("Rainbow Pinwheels", current_mode, MODE_FLAG_HAS_SPEED, MODE_COLORS_NONE, hsv);
// if (qmk_rgb_matrix_ptr->GetEnabledModes(QMK_RGBMATRIX_MODE_RAINDROPS))
// InitializeMode("Raindrops", current_mode, 0, MODE_COLORS_NONE, hsv);
// if (qmk_rgb_matrix_ptr->GetEnabledModes(QMK_RGBMATRIX_MODE_JELLYBEAN_RAINDROPS))
// InitializeMode("Jellybean Raindrops", current_mode, 0, MODE_COLORS_NONE, hsv);
// if (qmk_rgb_matrix_ptr->GetEnabledModes(QMK_RGBMATRIX_MODE_TYPING_HEATMAP))
// InitializeMode("Typing Heatmap", current_mode, 0, MODE_COLORS_NONE, hsv);
// if (qmk_rgb_matrix_ptr->GetEnabledModes(QMK_RGBMATRIX_MODE_DIGITAL_RAIN))
// InitializeMode("Digital Rain", current_mode, 0, MODE_COLORS_NONE, hsv);
// if (qmk_rgb_matrix_ptr->GetEnabledModes(QMK_RGBMATRIX_MODE_SOLID_REACTIVE_SIMPLE))
// InitializeMode("Solid Reactive Simple", current_mode, MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_SPEED,
// MODE_COLORS_MODE_SPECIFIC, hsv);
// if (qmk_rgb_matrix_ptr->GetEnabledModes(QMK_RGBMATRIX_MODE_SOLID_REACTIVE))
// InitializeMode("Solid Reactive", current_mode, MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_SPEED,
// MODE_COLORS_MODE_SPECIFIC, hsv);
// if (qmk_rgb_matrix_ptr->GetEnabledModes(QMK_RGBMATRIX_MODE_SOLID_REACTIVE_WIDE))
// InitializeMode("Solid Reactive Wide", current_mode, MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_SPEED,
// MODE_COLORS_MODE_SPECIFIC, hsv);
// if (qmk_rgb_matrix_ptr->GetEnabledModes(QMK_RGBMATRIX_MODE_SOLID_REACTIVE_MULTIWIDE))
// InitializeMode("Solid Reactive Multi Wide", current_mode, MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_SPEED,
// MODE_COLORS_MODE_SPECIFIC, hsv);
// if (qmk_rgb_matrix_ptr->GetEnabledModes(QMK_RGBMATRIX_MODE_SOLID_REACTIVE_CROSS))
// InitializeMode("Solid Reactive Cross", current_mode, MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_SPEED,
// MODE_COLORS_MODE_SPECIFIC, hsv);
// if (qmk_rgb_matrix_ptr->GetEnabledModes(QMK_RGBMATRIX_MODE_SOLID_REACTIVE_MULTICROSS))
// InitializeMode("Solid Reactive Multi Cross", current_mode, MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_SPEED,
// MODE_COLORS_MODE_SPECIFIC, hsv);
// if (qmk_rgb_matrix_ptr->GetEnabledModes(QMK_RGBMATRIX_MODE_SOLID_REACTIVE_NEXUS))
// InitializeMode("Solid Reactive Nexus", current_mode, MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_SPEED,
// MODE_COLORS_MODE_SPECIFIC, hsv);
// if (qmk_rgb_matrix_ptr->GetEnabledModes(QMK_RGBMATRIX_MODE_SOLID_REACTIVE_MULTINEXUS))
// InitializeMode("Solid Reactive Multi Nexus", current_mode, MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_SPEED,
// MODE_COLORS_MODE_SPECIFIC, hsv);
// if (qmk_rgb_matrix_ptr->GetEnabledModes(QMK_RGBMATRIX_MODE_SPLASH))
// InitializeMode("Rainbow Reactive Splash", current_mode, MODE_FLAG_HAS_SPEED, MODE_COLORS_NONE, hsv);
// if (qmk_rgb_matrix_ptr->GetEnabledModes(QMK_RGBMATRIX_MODE_MULTISPLASH))
// InitializeMode("Rainbow Reactive Multi Splash", current_mode, MODE_FLAG_HAS_SPEED, MODE_COLORS_NONE, hsv);
// if (qmk_rgb_matrix_ptr->GetEnabledModes(QMK_RGBMATRIX_MODE_SOLID_SPLASH))
// InitializeMode("Solid Reactive Splash", current_mode, MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_SPEED,
// MODE_COLORS_MODE_SPECIFIC, hsv);
// if (qmk_rgb_matrix_ptr->GetEnabledModes(QMK_RGBMATRIX_MODE_SOLID_MULTISPLASH))
// InitializeMode("Solid Reactive Multi Splash", current_mode, MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_SPEED,
// MODE_COLORS_MODE_SPECIFIC, hsv);
active_mode = qmk_rgb_matrix_ptr->GetActiveMode() - 1;
SetupZones();
}
RGBController_QMKRGBMatrix::~RGBController_QMKRGBMatrix()
{
for(unsigned int zone_index = 0; zone_index < zones.size(); zone_index++)
{
if(zones[zone_index].matrix_map != NULL)
{
delete zones[zone_index].matrix_map;
}
}
}
void RGBController_QMKRGBMatrix::SetupZones()
{
for(unsigned int i = 0; i < qmk_rgb_matrix->GetZonesCount(); i++)
{
zone keyboard_zone;
keyboard_zone.name = qmk_rgb_matrix->GetZoneName(i);
keyboard_zone.type = qmk_rgb_matrix->GetZoneType(i);
keyboard_zone.leds_min = qmk_rgb_matrix->GetZoneSize(i);
keyboard_zone.leds_max = keyboard_zone.leds_min;
keyboard_zone.leds_count = keyboard_zone.leds_min;
std::vector<std::string> led_names;
for (int i=0;i<keyboard_zone.leds_min;i++)
{
led_names.push_back("Unused");
}
if(keyboard_zone.type == ZONE_TYPE_MATRIX)
{
unsigned int led_matrix_columns = qmk_rgb_matrix->GetLEDMatirxColumns();
unsigned int led_matrix_rows = qmk_rgb_matrix->GetLEDMatirxRows();
keyboard_zone.matrix_map = new matrix_map_type;
keyboard_zone.matrix_map->height = led_matrix_rows;
keyboard_zone.matrix_map->width = led_matrix_columns;
unsigned int* matrix_map = new unsigned int[led_matrix_rows * led_matrix_columns];
for(unsigned int x = 0; x < led_matrix_rows; x++)
{
for(unsigned int y = 0; y < led_matrix_columns; y++)
{
unsigned int led_value = qmk_rgb_matrix->GetLEDValueInMatrix(y, x);
if(led_value != 255)
{
std::string led_name = qmk_rgb_matrix->GetLEDName(y, x);
led_names[led_value] = led_name;
}
else
{
led_value = 0xFFFFFFFF;
}
matrix_map[led_matrix_columns * x + y] = led_value;
}
}
keyboard_zone.matrix_map->map = matrix_map;
}
else
{
keyboard_zone.matrix_map = NULL;
}
zones.push_back(keyboard_zone);
for(unsigned int led_idx = 0; led_idx < keyboard_zone.leds_count; led_idx++)
{
led keyboard_led;
if(leds.size() < zones[0].leds_count)
{
if(led_idx < led_names.size()) keyboard_led.name = "Key: " + led_names[led_idx];
}
else
{
keyboard_led.name = zones[i].name + ": " + std::to_string(led_idx);
}
leds.push_back(keyboard_led);
}
}
SetupColors();
for(unsigned int i = 0; i < leds.size(); i++)
{
colors[i] = qmk_rgb_matrix->DirectModeGetLEDColor(i);
}
}
void RGBController_QMKRGBMatrix::ResizeZone(int /*zone*/, int /*new_size*/)
{
/*---------------------------------------------------------*\
| This device does not support resizing zones |
\*---------------------------------------------------------*/
}
void RGBController_QMKRGBMatrix::DeviceUpdateLEDs()
{
qmk_rgb_matrix->DirectModeSetLEDs(colors, leds.size());
}
void RGBController_QMKRGBMatrix::UpdateZoneLEDs(int /*zone*/)
{
DeviceUpdateLEDs();
}
void RGBController_QMKRGBMatrix::UpdateSingleLED(int led)
{
RGBColor color = colors[led];
unsigned char red = RGBGetRValue(color);
unsigned char grn = RGBGetGValue(color);
unsigned char blu = RGBGetBValue(color);
qmk_rgb_matrix->DirectModeSetSingleLED(led, red, grn, blu);
}
void RGBController_QMKRGBMatrix::SetCustomMode()
{
active_mode = 0;
}
void RGBController_QMKRGBMatrix::DeviceUpdateMode()
{
if(modes[active_mode].color_mode == MODE_COLORS_PER_LED)
{
DeviceUpdateLEDs();
}
else if(modes[active_mode].color_mode == MODE_COLORS_NONE)
{
qmk_rgb_matrix->QMKModeSetModeAndSpeed(modes[active_mode].value, modes[active_mode].speed);
}
else if(modes[active_mode].color_mode == MODE_COLORS_MODE_SPECIFIC)
{
RGBColor color = modes[active_mode].colors[0];
hsv_t hsv_color;
rgb2hsv(color, &hsv_color);
if(modes[active_mode].flags & MODE_FLAG_HAS_SPEED)
qmk_rgb_matrix->QMKModeSetColorModeAndSpeed(hsv_color, modes[active_mode].value, modes[active_mode].speed);
else
qmk_rgb_matrix->QMKModeSetColorModeAndSpeed(hsv_color, modes[active_mode].value, 127);
}
}
void RGBController_QMKRGBMatrix::InitializeMode
(
std::string name,
unsigned int &current_mode,
unsigned int flags,
unsigned int color_mode,
unsigned int hsv
)
{
mode qmk_mode;
qmk_mode.name = name;
qmk_mode.value = current_mode++;
qmk_mode.flags = flags;
qmk_mode.color_mode = color_mode;
if(flags & MODE_FLAG_HAS_SPEED)
{
qmk_mode.speed_min = QMK_RGBMATRIX_SPEED_SLOWEST;
qmk_mode.speed_max = QMK_RGBMATRIX_SPEED_FASTEST;
qmk_mode.speed = QMK_RGBMATRIX_SPEED_NORMAL;
}
if(flags & MODE_FLAG_HAS_MODE_SPECIFIC_COLOR)
{
qmk_mode.colors_min = 1;
qmk_mode.colors_max = 1;
qmk_mode.colors.resize(1);
qmk_mode.colors[0] = hsv;
}
modes.push_back(qmk_mode);
}
@@ -0,0 +1,40 @@
/*-------------------------------------------------------------------*\
| RGBController_QMKRGBMatrix.h |
| |
| Driver for QMK keybaords using RGB Matrix |
| |
| Kasper24 11th November 2020 |
| |
\*-------------------------------------------------------------------*/
#pragma once
#include "RGBController.h"
#include "QMKRGBMatrixController.h"
class RGBController_QMKRGBMatrix : public RGBController
{
public:
RGBController_QMKRGBMatrix(QMKRGBMatrixController* qmk_rgb_matrix_ptr, unsigned int protocol_version);
~RGBController_QMKRGBMatrix();
void SetupZones();
void ResizeZone(int zone, int new_size);
void DeviceUpdateLEDs();
void UpdateZoneLEDs(int zone);
void UpdateSingleLED(int led);
void SetCustomMode();
void DeviceUpdateMode();
private:
QMKRGBMatrixController* qmk_rgb_matrix;
void InitializeMode
(
std::string name,
unsigned int &current_mode,
unsigned int flags,
unsigned int color_mode,
unsigned int hsv
);
};
+6
View File
@@ -112,6 +112,7 @@ INCLUDEPATH +=
Controllers/PatriotViperController/ \
Controllers/PhilipsWizController/ \
Controllers/RazerController/ \
Controllers/QMKRGBMatrixController/ \
Controllers/RedragonController/ \
Controllers/RoccatController/ \
Controllers/SapphireGPUController/ \
@@ -320,6 +321,8 @@ HEADERS +=
Controllers/RazerController/RGBController_Razer.h \
Controllers/RazerController/RGBController_RazerAddressable.h \
Controllers/RazerController/RGBController_RazerKraken.h \
Controllers/QMKRGBMatrixController/RGBController_QMKRGBMatrix.h \
Controllers/QMKRGBMatrixController/QMKRGBMatrixController.h \
Controllers/RedragonController/RedragonM711Controller.h \
Controllers/RedragonController/RGBController_RedragonM711.h \
Controllers/RoccatController/RGBController_RoccatKoneAimo.h \
@@ -606,6 +609,9 @@ SOURCES +=
Controllers/RazerController/RGBController_Razer.cpp \
Controllers/RazerController/RGBController_RazerAddressable.cpp \
Controllers/RazerController/RGBController_RazerKraken.cpp \
Controllers/QMKRGBMatrixController/RGBController_QMKRGBMatrix.cpp \
Controllers/QMKRGBMatrixController/QMKRGBMatrixControllerDetect.cpp \
Controllers/QMKRGBMatrixController/QMKRGBMatrixController.cpp \
Controllers/RedragonController/RedragonM711Controller.cpp \
Controllers/RedragonController/RedragonControllerDetect.cpp \
Controllers/RedragonController/RGBController_RedragonM711.cpp \