From b4ea216a6f228b13a4dc8a9be7fceab15f7d39e5 Mon Sep 17 00:00:00 2001 From: Landrovan Date: Fri, 24 Mar 2017 22:35:10 -0400 Subject: [PATCH] Forgot to add file --- src/classes/CustomEffects.cpp | 77 +++++++++++++++++++++++++++++++++++ src/classes/CustomEffects.h | 12 ++++++ 2 files changed, 89 insertions(+) create mode 100644 src/classes/CustomEffects.cpp create mode 100644 src/classes/CustomEffects.h diff --git a/src/classes/CustomEffects.cpp b/src/classes/CustomEffects.cpp new file mode 100644 index 0000000..38821fb --- /dev/null +++ b/src/classes/CustomEffects.cpp @@ -0,0 +1,77 @@ +#include "CustomEffects.h" + +#include "Keyboard.h" + +#include +#include +#include + +// Global variables to know when a user activate input +std::atomic< bool > KeyPressed; + +void Test1Effects( LedKeyboard& kbd ) +{ + LedKeyboard::Key key = LedKeyboard::Key::r; + LedKeyboard::Color color; + color.red = 0; + color.green = 0; + color.blue = 0; + + while ( !KeyPressed ) + { + ++color.red; + LedKeyboard::KeyValue keyValue = { key, color }; + if (! kbd.open()) return; + if (! kbd.setKey(keyValue)) return; + if(! kbd.commit()) return; + + //std::cout << "TEST" << std::endl; + std::this_thread::sleep_for ( std::chrono::milliseconds( 10 ) ); + } +} + +int StartEffectsAndWaitForUser( LedKeyboard& kbd ) +{ + // Start the effects on a thread + std::thread lThread( Test1Effects, std::ref( kbd ) ); + + // Wait for user input + std::cout << "Press enter to quit"; + getchar(); + + // Stop the thread and wait for it to finish + KeyPressed = true; + lThread.join(); + + return 0; +} + + +int StartCustomEffects( LedKeyboard& kbd, int argc, char** argv ) +{ + if ( argc < 1 ) + { + // Not enough parameters + return 1; + } + + KeyPressed = false; + std::string Type = argv[0]; + if ( Type == "test1" ) + { + return StartEffectsAndWaitForUser( kbd ); + } + else + { + // No custom effects of this name + std::cout << "No effects of name: " << Type << std::endl; + } + + // First param is the custom effects to create. Convert it to an enum + + /*for ( int i = 0; i < argc; ++i ) + { + std::cout << argv[i] << std::endl; + }*/ + return 0; +} diff --git a/src/classes/CustomEffects.h b/src/classes/CustomEffects.h new file mode 100644 index 0000000..5d212d2 --- /dev/null +++ b/src/classes/CustomEffects.h @@ -0,0 +1,12 @@ +#ifndef __CUSTOM_EFFECTS__ +#define __CUSTOM_EFFECTS__ + +#include + +class LedKeyboard; + +// Start the custom effects and wait for user input before quitting. +// Assume the given arg are ONLY refering to the effects (so the program name and arguments are ommited). +int StartCustomEffects( LedKeyboard& kbd, int argc, char** argv ); + +#endif // __CUSTOM_EFFECTS__