mirror of
https://github.com/MatMoul/g810-led.git
synced 2024-12-24 09:46:11 +00:00
Forgot to add file
This commit is contained in:
parent
b600a67659
commit
b4ea216a6f
77
src/classes/CustomEffects.cpp
Normal file
77
src/classes/CustomEffects.cpp
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
#include "CustomEffects.h"
|
||||||
|
|
||||||
|
#include "Keyboard.h"
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
|
#include <chrono>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
}
|
12
src/classes/CustomEffects.h
Normal file
12
src/classes/CustomEffects.h
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#ifndef __CUSTOM_EFFECTS__
|
||||||
|
#define __CUSTOM_EFFECTS__
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
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__
|
Loading…
Reference in New Issue
Block a user