Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added checks of retrun codes from logitech sdk #2107

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 33 additions & 5 deletions Project-Aurora/Project-Aurora/Devices/Logitech/LogitechDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ class LogitechDevice : Device
{
private String devicename = "Logitech";
private bool isInitialized = false;
private bool ledSDKPresent = false;

private bool keyboard_updated = false;
private bool peripheral_updated = false;
Expand Down Expand Up @@ -180,15 +181,22 @@ public bool Initialize()
{
LogitechGSDK.LGDLL? dll = null;
if (Global.Configuration.VarRegistry.GetVariable<bool>($"{devicename}_override_dll"))
{
dll = Global.Configuration.VarRegistry.GetVariable<LogitechGSDK.LGDLL>($"{devicename}_override_dll_option");
}

LogitechGSDK.InitDLL(dll);

if (!LogitechGSDK.LogiLedInit())
{
Global.logger.Error("Logitech LED SDK could not be initialized.");

LogitechGSDK.LogiLedShutdown();
LogitechGSDK.ReleaseDLL();

isInitialized = false;
/* we have the SKD present but neither GHub nor LGS is running */
ledSDKPresent = true;
return false;
}

Expand Down Expand Up @@ -216,6 +224,7 @@ public bool Initialize()
}

isInitialized = true;
ledSDKPresent = true;
return true;
}
else
Expand Down Expand Up @@ -305,21 +314,28 @@ private void SetOneKey(Logitech_keyboardBitmapKeys key, Color color)

private void SendColorsToKeyboard(bool forced = false)
{
bool bOk;

if (!Enumerable.SequenceEqual(bitmap, previous_bitmap) || forced)
{
LogitechGSDK.LogiLedSetTargetDevice(LogitechGSDK.LOGI_DEVICETYPE_PERKEY_RGB);
bOk = LogitechGSDK.LogiLedSetTargetDevice(LogitechGSDK.LOGI_DEVICETYPE_PERKEY_RGB);

if(!LogitechGSDK.LogiLedSetLightingFromBitmap(bitmap) || !bOk)
{
isInitialized = false;
}

LogitechGSDK.LogiLedSetLightingFromBitmap(bitmap);
bitmap.CopyTo(previous_bitmap, 0);
keyboard_updated = true;
}
}

private void SendColorToPeripheral(Color color, bool forced = false)
{
bool bOk;
if (!previous_peripheral_Color.Equals(color) || forced)
{
LogitechGSDK.LogiLedSetTargetDevice(LogitechGSDK.LOGI_DEVICETYPE_RGB);
bOk = LogitechGSDK.LogiLedSetTargetDevice(LogitechGSDK.LOGI_DEVICETYPE_RGB);

if (Global.Configuration.allow_peripheral_devices)
{
Expand All @@ -330,15 +346,21 @@ private void SendColorToPeripheral(Color color, bool forced = false)

//System.Diagnostics.Debug.WriteLine("R: " + red_amt + " G: " + green_amt + " B: " + blue_amt);

LogitechGSDK.LogiLedSetLighting(red_amt, green_amt, blue_amt);
if(!LogitechGSDK.LogiLedSetLighting(red_amt, green_amt, blue_amt) || !bOk)
{
isInitialized = false;
}
previous_peripheral_Color = color;
peripheral_updated = true;
}
else
{
if (peripheral_updated)
{
LogitechGSDK.LogiLedRestoreLighting();
if(LogitechGSDK.LogiLedRestoreLighting() || !bOk)
{
isInitialized = false;
}
peripheral_updated = false;
}
}
Expand All @@ -347,6 +369,12 @@ private void SendColorToPeripheral(Color color, bool forced = false)

public bool IsInitialized()
{
if(ledSDKPresent && !isInitialized)
{
Initialize();
}


return this.isInitialized;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ public static void InitDLL(LGDLL? dll = null)
initd = true;
}

public static void ReleaseDLL()
{
initd = false;
}

//LED SDK
private const int LOGI_DEVICETYPE_MONOCHROME_ORD = 0;
private const int LOGI_DEVICETYPE_RGB_ORD = 1;
Expand Down