From 3b13f247b56dedd3f5c5cbdafefb42681eb193dc Mon Sep 17 00:00:00 2001 From: MatMoul Date: Fri, 30 Dec 2016 17:55:19 +0100 Subject: [PATCH] Add native effect support --- src/classes/Keyboard.cpp | 133 ++++++++++++++++++++++++++++----------- src/classes/Keyboard.h | 3 + src/main.cpp | 84 ++++++++++++++++++++----- 3 files changed, 169 insertions(+), 51 deletions(-) diff --git a/src/classes/Keyboard.cpp b/src/classes/Keyboard.cpp index 48b07b3..d73bc37 100644 --- a/src/classes/Keyboard.cpp +++ b/src/classes/Keyboard.cpp @@ -491,6 +491,13 @@ bool Keyboard::parseColor(std::string color, KeyColors &colors) { return true; } +bool Keyboard::parseSpeed(std::string speed, uint8_t &speedValue) { + if (speed.length() == 1) speed = speed + "0"; + if (speed.length() != 2) return false; + speedValue = std::stoul("0x"+speed, nullptr, 16); + return true; +} + bool Keyboard::sendDataInternal(unsigned char *data, uint16_t data_size) { if (m_isAttached == false) return false; int r; @@ -849,34 +856,6 @@ bool Keyboard::setFXColor(KeyColors colors) { int data_size = 20; unsigned char *data = new unsigned char[data_size]; - // Indicators - data[0] = 0x11; // Base address - data[1] = 0xff; // Base address - data[2] = 0x0c; // Base address - data[3] = 0x4c; // Base address - data[4] = 0x00; // Base address - data[5] = 0x40; // Base address - - data[6] = colors.red; - data[7] = colors.green; - data[8] = colors.blue; - - for(int i = 9; i < data_size; i++) data[i] = 0x00; - - retval = sendDataInternal(data, data_size); - - - data[0] = 0x11; // Base address - data[1] = 0xff; // Base address - data[2] = 0x0c; // Base address - data[3] = 0x5c; // Base address - - for(int i = 4; i < data_size; i++) data[i] = 0x00; - - retval = sendDataInternal(data, data_size); - - - // Keys data[0] = 0x11; // Base address data[1] = 0xff; // Base address @@ -884,17 +863,13 @@ bool Keyboard::setFXColor(KeyColors colors) { data[3] = 0x3c; // Base address data[4] = 0x00; // Base address data[5] = 0x01; // Base address - data[6] = colors.red; data[7] = colors.green; data[8] = colors.blue; data[9] = 0x02; - for(int i = 10; i < data_size; i++) data[i] = 0x00; - retval = sendDataInternal(data, data_size); - // Logo data[0] = 0x11; // Base address data[1] = 0xff; // Base address @@ -902,17 +877,103 @@ bool Keyboard::setFXColor(KeyColors colors) { data[3] = 0x3c; // Base address data[4] = 0x01; // Base address data[5] = 0x01; // Base address - data[6] = colors.red; data[7] = colors.green; data[8] = colors.blue; data[9] = 0x02; - for(int i = 10; i < data_size; i++) data[i] = 0x00; - retval = sendDataInternal(data, data_size); - + delete[] data; + return retval; +} + +bool Keyboard::setFXBreathing(KeyColors colors, uint8_t speed) { + bool retval = false; + int data_size = 20; + unsigned char *data = new unsigned char[data_size]; + + // Keys + data[0] = 0x11; // Base address + data[1] = 0xff; // Base address + data[2] = 0x0d; // Base address + data[3] = 0x3c; // Base address + data[4] = 0x00; // Base address + data[5] = 0x02; // Base address + data[6] = colors.red; + data[7] = colors.green; + data[8] = colors.blue; + data[9] = speed; // Speed + data[10] = 0x10; // ??? + data[11] = 0x00; + data[12] = 0x64; + for(int i = 13; i < data_size; i++) data[i] = 0x00; + retval = sendDataInternal(data, data_size); + + // Logo + data[0] = 0x11; // Base address + data[1] = 0xff; // Base address + data[2] = 0x0d; // Base address + data[3] = 0x3c; // Base address + data[4] = 0x01; // Base address + data[5] = 0x02; // Base address + data[6] = colors.red; + data[7] = colors.green; + data[8] = colors.blue; + data[9] = speed; // Speed + data[10] = 0x10; // ??? + data[11] = 0x00; + data[12] = 0x64; + for(int i = 13; i < data_size; i++) data[i] = 0x00; + retval = sendDataInternal(data, data_size); + + delete[] data; + return retval; +} + +bool Keyboard::setFXColorCycle(uint8_t speed) { + bool retval = false; + int data_size = 20; + unsigned char *data = new unsigned char[data_size]; + + // Keys + data[0] = 0x11; // Base address + data[1] = 0xff; // Base address + data[2] = 0x0d; // Base address + data[3] = 0x3c; // Base address + data[4] = 0x00; // Base address + data[5] = 0x03; // Base address + data[6] = 0x00; + data[7] = 0x00; + data[8] = 0x00; + data[9] = 0x00; + data[10] = 0x00; + data[11] = speed; // Speed + data[12] = 0x00; // ??? + data[13] = 0x00; + data[14] = 0x64; + for(int i = 15; i < data_size; i++) data[i] = 0x00; + retval = sendDataInternal(data, data_size); + + // Logo + data[0] = 0x11; // Base address + data[1] = 0xff; // Base address + data[2] = 0x0d; // Base address + data[3] = 0x3c; // Base address + data[4] = 0x01; // Base address + data[5] = 0x03; // Base address + data[6] = 0x00; + data[7] = 0x00; + data[8] = 0x00; + data[9] = 0x00; + data[10] = 0x00; + data[11] = speed; // Speed + data[12] = 0x00; // ??? + data[13] = 0x00; + data[14] = 0x64; + for(int i = 15; i < data_size; i++) data[i] = 0x00; + retval = sendDataInternal(data, data_size); + delete[] data; return retval; } diff --git a/src/classes/Keyboard.h b/src/classes/Keyboard.h index ebb847a..5c585b2 100644 --- a/src/classes/Keyboard.h +++ b/src/classes/Keyboard.h @@ -45,6 +45,7 @@ class Keyboard { bool parseKey(std::string key, KeyAddress &keyAddress); bool parseKeyGroup(std::string key, KeyGroup &keyGroup); bool parseColor(std::string color, KeyColors &colors); + bool parseSpeed(std::string speed, uint8_t &speedValue); bool setPowerOnEffect(PowerOnEffect powerOnEffect); bool setKey(KeyValue keyValue); bool setKey(Key key, KeyColors colors); @@ -52,6 +53,8 @@ class Keyboard { bool setAllKeys(KeyColors colors); bool setGroupKeys(KeyGroup keyGroup, KeyColors colors); bool setFXColor(KeyColors colors); + bool setFXBreathing(KeyColors colors, uint8_t speed); + bool setFXColorCycle(uint8_t speed); private: diff --git a/src/main.cpp b/src/main.cpp index b434683..08234bf 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -10,34 +10,40 @@ void usage() { cout<