diff --git a/CppKeyboardColour/CppKeyboardColour.cpp b/CppKeyboardColour/CppKeyboardColour.cpp index b49d4ec..eaad173 100644 Binary files a/CppKeyboardColour/CppKeyboardColour.cpp and b/CppKeyboardColour/CppKeyboardColour.cpp differ diff --git a/CppKeyboardColour/IKeyboard.h b/CppKeyboardColour/IKeyboard.h index 823fefa..daf92a0 100644 --- a/CppKeyboardColour/IKeyboard.h +++ b/CppKeyboardColour/IKeyboard.h @@ -16,5 +16,7 @@ class IKeyboard virtual void PlayAnimation(IAnimation& animation, bool bShouldLoop) = 0; virtual KeyboardType GetKBType() const = 0; - virtual ~IKeyboard() = default; + virtual bool SetSpeedFactor(float factor) = 0; + + virtual ~IKeyboard() = default; }; \ No newline at end of file diff --git a/CppKeyboardColour/Keyboard.cpp b/CppKeyboardColour/Keyboard.cpp index 468075c..5ec754f 100644 --- a/CppKeyboardColour/Keyboard.cpp +++ b/CppKeyboardColour/Keyboard.cpp @@ -6,61 +6,78 @@ using millisec = std::chrono::milliseconds; Keyboard::Keyboard(KeyboardType kbType, IKeyboardCommunicatorPtr ptrKbComms) - : m_kbType(kbType), - m_ptrKbComms(std::move(ptrKbComms)) + : m_kbType(kbType), + m_ptrKbComms(std::move(ptrKbComms)) { } void Keyboard::SetColour(uint8_t r, uint8_t g, uint8_t b, Zone zone) { - m_ptrKbComms->SetKBColour(zone, m_colourFactory.Create(r, g, b)); + m_ptrKbComms->SetKBColour(zone, m_colourFactory.Create(r, g, b)); } KeyboardType Keyboard::GetKBType() const { - return m_kbType; + return m_kbType; }; void Keyboard::SendCode(uint32_t code) { - m_ptrKbComms->SendKBCode(code); + m_ptrKbComms->SendKBCode(code); } void Keyboard::SetBacklightOff() { - this->SetColour(0x00, 0x00, 0x00, Zone::ALL); + this->SetColour(0x00, 0x00, 0x00, Zone::ALL); } void Keyboard::SetBacklightOn() { - this->SetColour(0x00, 0x00, 0xFF, Zone::ALL); + this->SetColour(0x00, 0x00, 0xFF, Zone::ALL); +} + +bool Keyboard::SetSpeedFactor(float factor) +{ + // Convert percent (1-250) to speed multiplier (0.01 - 2.5) + int percent = static_cast(factor * 100.0f); + if (percent < 1 || percent > 250) + { + std::cout << "Speed value out of range (1-250). Animation will not play.\n"; + return false; // reject invalid speed + } + + m_speedFactor = factor; + return true; } void Keyboard::Animate(IAnimation& animation) { - for (size_t i = 0; i < animation.Size(); ++i) - { - if (const auto frame = animation.GetFrame(i)) - { - m_ptrKbComms->SetKBColour(frame->zone, frame->colour); - std::this_thread::sleep_for(millisec(frame->ms_time)); - } - } + // Apply speed factor to the sleep duration + float invSpeed = 1.0f / m_speedFactor; + for (size_t i = 0; i < animation.Size(); ++i) + { + if (const auto frame = animation.GetFrame(i)) + { + m_ptrKbComms->SetKBColour(frame->zone, frame->colour); + uint32_t sleepMs = static_cast(frame->ms_time * invSpeed); + if (sleepMs < 1) sleepMs = 1; + std::this_thread::sleep_for(millisec(sleepMs)); + } + } } void Keyboard::PlayAnimation(IAnimation& animation, bool bShouldLoop) { - if (!animation.IsSupportedKB(this->GetKBType())) - { - std::wcout << animation.GetName() << L" animation is not supported on this system.\n"; - return; - } - - std::wcout << L"Playing " << animation.GetName() << L" animation...\n"; + if (!animation.IsSupportedKB(this->GetKBType())) + { + std::wcout << animation.GetName() << L" animation is not supported on this system.\n"; + return; + } - do - { - this->Animate(animation); + std::wcout << L"Playing " << animation.GetName() << L" animation...\n"; - } while (bShouldLoop); -} + do + { + this->Animate(animation); + } while (bShouldLoop); +} \ No newline at end of file diff --git a/CppKeyboardColour/Keyboard.h b/CppKeyboardColour/Keyboard.h index bc44a93..ccfe51c 100644 --- a/CppKeyboardColour/Keyboard.h +++ b/CppKeyboardColour/Keyboard.h @@ -23,6 +23,8 @@ class Keyboard KeyboardType GetKBType() const; + bool SetSpeedFactor(float factor) override; + ~Keyboard() = default; private: @@ -30,5 +32,7 @@ class Keyboard ColourFactory m_colourFactory{}; IKeyboardCommunicatorPtr m_ptrKbComms{}; + float m_speedFactor = 1.0f; + void Animate(IAnimation& animation); }; diff --git a/CppKeyboardColour/ThemeCommandLine.cpp b/CppKeyboardColour/ThemeCommandLine.cpp index 3297592..e79d2d2 100644 --- a/CppKeyboardColour/ThemeCommandLine.cpp +++ b/CppKeyboardColour/ThemeCommandLine.cpp @@ -108,4 +108,18 @@ std::unique_ptr ProcessThemeCommandLine(const std::vector& cmdLines) +{ + for (size_t i = 0; i < cmdLines.size(); ++i) + { + if (cmdLines[i] == L"-speed" && i + 1 < cmdLines.size()) + { + int percent = std::stoi(cmdLines[i + 1]); + if (percent <= 0) percent = 100; + return static_cast(percent) / 100.0f; + } + } + return 1.0f; // normal speed } \ No newline at end of file diff --git a/CppKeyboardColour/ThemeCommandLine.h b/CppKeyboardColour/ThemeCommandLine.h index dc21151..63ca959 100644 --- a/CppKeyboardColour/ThemeCommandLine.h +++ b/CppKeyboardColour/ThemeCommandLine.h @@ -22,4 +22,6 @@ enum class BacklightType ThemeFlags ProcessCmdThemeFlags(const std::vector& cmdLines); BacklightType ProcessBacklightCommandLine(const std::vector& cmdLines); SystemAnimation ProcessSystemAnimationCommandLine(const std::vector& cmdLines); -std::unique_ptr ProcessThemeCommandLine(const std::vector& cmdLines); \ No newline at end of file +std::unique_ptr ProcessThemeCommandLine(const std::vector& cmdLines); + +float ProcessSpeedCommandLine(const std::vector& cmdLines); \ No newline at end of file diff --git a/CppKeyboardColour/stdafx.cpp b/CppKeyboardColour/stdafx.cpp index bd74dc9..ce410ee 100644 Binary files a/CppKeyboardColour/stdafx.cpp and b/CppKeyboardColour/stdafx.cpp differ diff --git a/README.md b/README.md index 4a84cf9..bdc8fc8 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ This is a cleaner, more organized, and efficient version of the initial program. - **Predefined Animated Effects:** - 🌈 **Fading Colors:** Smooth color transitions (predefined themes). - 🎥 **Optimized Animations:** Enhanced visual effects using animation objects. + - ⏱️ **Custom Speed:** Change the speed to make an animation faster or slower. ⚠️ **Important Note:** This application requests for **Administrator privileges**. Please ensure you accept the Windows UAC prompt, as Windows Management Instrumentation (WMI) requires this to function correctly. @@ -33,7 +34,7 @@ The following commands are supported and can be executed via the **Command Promp Extract the program zip and run the commands **as an administrator**. To execute the `.exe` files, prepend the `.\` before the command. ```bash -.\CLEVO_KeyboardColour.exe theme/inbuilt/backlight [argument] +.\CLEVO_KeyboardColour.exe theme/inbuilt/backlight [argument] -speed [speed] ``` --- @@ -133,6 +134,25 @@ Extract the program zip and run the commands **as an administrator**. To execute --- +### ⏱️ Custom Speed: + +- **Slower** + ```bash + .\CLEVO_KeyboardColour.exe theme colourtransform -speed 50 + ``` + 🌈 Creates a slow rainbow sweep effect with smooth transitions at 50% speed. + +- **Faster** + ```bash + .\CLEVO_KeyboardColour.exe theme colourtransform -speed 200 + ``` + 🌈 Creates a fast rainbow sweep effect with smooth transitions at 200% speed. + + +**Setting speed is not required. You can leave it out, and it will default to the standard speed.** + +--- + ## 🛠️ How to Use 1. Download the release which contains the version of the program that supports your system. @@ -145,7 +165,7 @@ Extract the program zip and run the commands **as an administrator**. To execute 4. Run the desired command using the syntax: ``` - .\CLEVO_KeyboardColour.exe theme/inbuilt/backlight [argument] + .\CLEVO_KeyboardColour.exe theme/inbuilt/backlight [argument] -speed [speed] ``` ---