From 052d67b2aa4b96fb98b17f9519665a02c6f4b055 Mon Sep 17 00:00:00 2001 From: HunterZ <> Date: Mon, 12 Mar 2018 19:42:42 -0700 Subject: [PATCH] Logitech fixes: - only initialize Logitech SDK once - only save initial lighting on initialize - simplify code (even though it's already the simplest wrapper of all the supported APIs) --- UniLight/LLEDUtil.cpp | 23 +++++++++++++---------- UniLight/UniLight.vcxproj | 12 ++++++------ 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/UniLight/LLEDUtil.cpp b/UniLight/LLEDUtil.cpp index 8ef1980..a90d81d 100644 --- a/UniLight/LLEDUtil.cpp +++ b/UniLight/LLEDUtil.cpp @@ -17,10 +17,13 @@ namespace bool initLLED() { - if (!initialized) initialized = LogiLedInit(); + if (initialized) return true; - // don't really care if this succeeds - LogiLedSaveCurrentLighting(); + if (LogiLedInit()) + { + LogiLedSaveCurrentLighting(); + initialized = true; + } return initialized; } @@ -38,16 +41,16 @@ namespace LLEDUtil { LogiLedRestoreLighting(); - void LogiLedShutdown(); + LogiLedShutdown(); } bool LLEDUtilC::SetLLEDColor(unsigned char red, unsigned char green, unsigned char blue) { - if (!initialized && !initLLED()) return false; - - // target only RGB devices (as opposed to monochrome) - if (!LogiLedSetTargetDevice(LOGI_DEVICETYPE_PERKEY_RGB | LOGI_DEVICETYPE_RGB)) return false; - - return LogiLedSetLighting(b2p(red), b2p(green), b2p(blue)); + return + ( + initLLED() && + LogiLedSetTargetDevice(LOGI_DEVICETYPE_PERKEY_RGB | LOGI_DEVICETYPE_RGB) && + LogiLedSetLighting(b2p(red), b2p(green), b2p(blue)) + ); } } diff --git a/UniLight/UniLight.vcxproj b/UniLight/UniLight.vcxproj index a325b83..345cdbc 100644 --- a/UniLight/UniLight.vcxproj +++ b/UniLight/UniLight.vcxproj @@ -1,5 +1,5 @@  - + Debug @@ -42,32 +42,32 @@ {28F74A2D-E89D-4D21-A6E8-7A5C2EDBD870} Win32Proj UniLight - 8.1 + 10.0.16299.0 Application true - v140 + v141 Unicode Application false - v140 + v141 true Unicode Application true - v140 + v141 Unicode Application false - v140 + v141 true Unicode