Skip to content

Commit

Permalink
added checks of retrun codes from logitech sdk
Browse files Browse the repository at this point in the history
- added an option to deinit and release the LGS/GHub dll
- check if the sdk functions actually succeed

solution for:
- Aurora starting after LGS/Ghub
- Connection to LGS/GHub lost (program closed/restarted)
- detaching/reattaching a device

issue: antonpup#1953
  • Loading branch information
supergrml authored and Cheerpipe committed Jun 21, 2020
1 parent 33a9f49 commit 431281a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
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

0 comments on commit 431281a

Please sign in to comment.