mirror of
https://github.com/MatMoul/g810-led.git
synced 2024-12-23 17:26:11 +00:00
New custom effects.
This commit is contained in:
parent
b4ea216a6f
commit
33dd0713e1
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include <functional>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
// Global variables to know when a user activate input
|
// Global variables to know when a user activate input
|
||||||
@ -30,10 +31,33 @@ void Test1Effects( LedKeyboard& kbd )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int StartEffectsAndWaitForUser( LedKeyboard& kbd )
|
void Test2Effects( LedKeyboard& kbd )
|
||||||
|
{
|
||||||
|
LedKeyboard::Key key = LedKeyboard::Key::t;
|
||||||
|
LedKeyboard::Color color;
|
||||||
|
color.red = 0;
|
||||||
|
color.green = 0;
|
||||||
|
color.blue = 0;
|
||||||
|
|
||||||
|
while ( !KeyPressed )
|
||||||
|
{
|
||||||
|
++color.blue;
|
||||||
|
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, std::function< void( LedKeyboard& ) > EffectsFunction )
|
||||||
{
|
{
|
||||||
// Start the effects on a thread
|
// Start the effects on a thread
|
||||||
std::thread lThread( Test1Effects, std::ref( kbd ) );
|
std::thread lThread( EffectsFunction, std::ref( kbd ) );
|
||||||
|
|
||||||
// Wait for user input
|
// Wait for user input
|
||||||
std::cout << "Press enter to quit";
|
std::cout << "Press enter to quit";
|
||||||
@ -57,10 +81,8 @@ int StartCustomEffects( LedKeyboard& kbd, int argc, char** argv )
|
|||||||
|
|
||||||
KeyPressed = false;
|
KeyPressed = false;
|
||||||
std::string Type = argv[0];
|
std::string Type = argv[0];
|
||||||
if ( Type == "test1" )
|
if ( Type == "test1" ) return StartEffectsAndWaitForUser( kbd, Test1Effects );
|
||||||
{
|
else if ( Type == "test2" ) return StartEffectsAndWaitForUser( kbd, Test2Effects );
|
||||||
return StartEffectsAndWaitForUser( kbd );
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// No custom effects of this name
|
// No custom effects of this name
|
||||||
|
Loading…
Reference in New Issue
Block a user