From 4bfa9811b3dbc4838c87d22cc9b5957441202d24 Mon Sep 17 00:00:00 2001 From: MatMoul Date: Fri, 30 Dec 2016 21:35:26 +0100 Subject: [PATCH] Add wave effect --- src/classes/Keyboard.cpp | 146 +++++++++++++++++++++++++++++++++++++++ src/classes/Keyboard.h | 3 + src/main.cpp | 64 +++++++++++++++++ 3 files changed, 213 insertions(+) diff --git a/src/classes/Keyboard.cpp b/src/classes/Keyboard.cpp index d73bc37..fe548f3 100644 --- a/src/classes/Keyboard.cpp +++ b/src/classes/Keyboard.cpp @@ -978,3 +978,149 @@ bool Keyboard::setFXColorCycle(uint8_t speed) { return retval; } +bool Keyboard::setFXHWave(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] = 0x3b; // Base address + data[4] = 0x00; // Base address + data[5] = 0x04; // Base address + data[6] = 0x00; + data[7] = 0x00; + data[8] = 0x00; + data[9] = 0x00; + data[10] = 0x00; + data[11] = 0x00; + data[12] = 0x88; + data[13] = 0x01; + data[14] = 0x64; + data[15] = speed; // Speed + for(int i = 16; 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] = 0x3b; // 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] = 0x88; + data[13] = 0x64; + data[14] = 0x00; + data[15] = 0x00; + for(int i = 16; i < data_size; i++) data[i] = 0x00; + retval = sendDataInternal(data, data_size); + + delete[] data; + return retval; +} + +bool Keyboard::setFXVWave(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] = 0x3b; // Base address + data[4] = 0x00; // Base address + data[5] = 0x04; // Base address + data[6] = 0x00; + data[7] = 0x00; + data[8] = 0x00; + data[9] = 0x00; + data[10] = 0x00; + data[11] = 0x00; + data[12] = 0x88; + data[13] = 0x02; + data[14] = 0x64; + data[15] = speed; // Speed + for(int i = 16; 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] = 0x3b; // 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] = 0x88; + data[13] = 0x64; + data[14] = 0x00; + data[15] = 0x00; + for(int i = 16; i < data_size; i++) data[i] = 0x00; + retval = sendDataInternal(data, data_size); + + delete[] data; + return retval; +} + +bool Keyboard::setFXCWave(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] = 0x3b; // Base address + data[4] = 0x00; // Base address + data[5] = 0x04; // Base address + data[6] = 0x00; + data[7] = 0x00; + data[8] = 0x00; + data[9] = 0x00; + data[10] = 0x00; + data[11] = 0x00; + data[12] = 0x88; + data[13] = 0x03; + data[14] = 0x64; + data[15] = speed; // Speed + for(int i = 16; 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] = 0x3b; // 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] = 0x88; + data[13] = 0x64; + data[14] = 0x00; + data[15] = 0x00; + for(int i = 16; 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 5c585b2..8bfedee 100644 --- a/src/classes/Keyboard.h +++ b/src/classes/Keyboard.h @@ -55,6 +55,9 @@ class Keyboard { bool setFXColor(KeyColors colors); bool setFXBreathing(KeyColors colors, uint8_t speed); bool setFXColorCycle(uint8_t speed); + bool setFXHWave(uint8_t speed); + bool setFXVWave(uint8_t speed); + bool setFXCWave(uint8_t speed); private: diff --git a/src/main.cpp b/src/main.cpp index 08234bf..39e51aa 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -25,6 +25,9 @@ void usage() { cout<<" -fx-color color :\t\tSet static color effect\n"; cout<<" -fx-breathing color, speed :\tSet breathing effect\n"; cout<<" -fx-cycle speed :\t\tSet color cycle effect\n"; + cout<<" -fx-hwave speed :\t\tSet horizontal color wave effect\n"; + cout<<" -fx-vwave speed :\t\tSet vertical color wave effect\n"; + cout<<" -fx-cwave speed :\t\tSet center color wave effect\n"; cout<<"\n"; cout<<" -p profilefile :\t\tLoad a profile\n"; cout<<"\n"; @@ -261,8 +264,66 @@ int setFXColorCycle(string speed) { return 1; } +int setFXHWave(string speed) { + Keyboard lg_kbd; + Keyboard::KeyColors colors; + uint8_t speedValue; + if (lg_kbd.parseSpeed(speed, speedValue) == true) { + colors.red = 0xff; + colors.green = 0xff; + colors.blue = 0xff; + lg_kbd.attach(); + lg_kbd.setGroupKeys(Keyboard::KeyGroup::indicators, colors); + lg_kbd.commit(); + lg_kbd.detach(); + lg_kbd.attach(); + lg_kbd.setFXHWave(speedValue); + lg_kbd.detach(); + return 0; + } + return 1; +} +int setFXVWave(string speed) { + Keyboard lg_kbd; + Keyboard::KeyColors colors; + uint8_t speedValue; + if (lg_kbd.parseSpeed(speed, speedValue) == true) { + colors.red = 0xff; + colors.green = 0xff; + colors.blue = 0xff; + lg_kbd.attach(); + lg_kbd.setGroupKeys(Keyboard::KeyGroup::indicators, colors); + lg_kbd.commit(); + lg_kbd.detach(); + lg_kbd.attach(); + lg_kbd.setFXVWave(speedValue); + lg_kbd.detach(); + return 0; + } + return 1; +} +int setFXCWave(string speed) { + Keyboard lg_kbd; + Keyboard::KeyColors colors; + uint8_t speedValue; + if (lg_kbd.parseSpeed(speed, speedValue) == true) { + colors.red = 0xff; + colors.green = 0xff; + colors.blue = 0xff; + lg_kbd.attach(); + lg_kbd.setGroupKeys(Keyboard::KeyGroup::indicators, colors); + lg_kbd.commit(); + lg_kbd.detach(); + lg_kbd.attach(); + lg_kbd.setFXCWave(speedValue); + lg_kbd.detach(); + return 0; + } + return 1; + return 1; +} int loadProfile(string profileFile) { ifstream file; @@ -371,6 +432,9 @@ int main(int argc, char *argv[]) { else if (argCmd == "-fx-color" && argc == 3) return setFXColor(argv[2]); else if (argCmd == "-fx-breathing" && argc == 4) return setFXBreathing(argv[2], argv[3]); else if (argCmd == "-fx-cycle" && argc == 3) return setFXColorCycle(argv[2]); + else if (argCmd == "-fx-hwave" && argc == 3) return setFXHWave(argv[2]); + else if (argCmd == "-fx-vwave" && argc == 3) return setFXVWave(argv[2]); + else if (argCmd == "-fx-cwave" && argc == 3) return setFXCWave(argv[2]); } usage(); return 1;