Created
September 17, 2015 22:56
-
-
Save ikkentim/1573b4521cbbdbad186e to your computer and use it in GitHub Desktop.
List logitech devices connected, quick and dirty written
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Runtime.InteropServices; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace TestList | |
{ | |
internal static class LgLcd | |
{ | |
public delegate int OnConfigureDelegate(int connection, IntPtr pContext); | |
public delegate int OnSoftButtonsDelegate(int device, int dwButtons, IntPtr pContext); | |
public const int InvalidConnection = -1; | |
public const int InvalidDevice = -1; | |
public const uint ButtonButton0 = 0x00000001; | |
public const uint ButtonButton1 = 0x00000002; | |
public const uint ButtonButton2 = 0x00000004; | |
public const uint ButtonButton3 = 0x00000008; | |
public const uint BitmapFormat160X43X1 = 0x00000001; | |
public const uint BitmapWidth = 160; | |
public const uint BitmapHeight = 43; | |
public const uint PriorityIdleNoShow = 0; | |
public const uint PriorityBackground = 64; | |
public const uint PriorityNormal = 128; | |
public const uint PriorityAlert = 255; | |
[DllImport("LgLcd.dll", EntryPoint = "lgLcdInit")] | |
public static extern int Init(); | |
[DllImport("LgLcd.dll", EntryPoint = "lgLcdDeInit")] | |
public static extern int DeInit(); | |
[DllImport("LgLcd.dll", EntryPoint = "lgLcdConnect")] | |
public static extern int Connect(ref ConnectContext ctx); | |
[DllImport("LgLcd.dll", EntryPoint = "lgLcdDisconnect")] | |
public static extern int Disconnect(int connection); | |
[DllImport("LgLcd.dll", EntryPoint = "lgLcdEnumerate")] | |
public static extern int Enumerate(int connection, int index, out DeviceDescription description); | |
[DllImport("LgLcd.dll", EntryPoint = "lgLcdOpen")] | |
public static extern int Open(ref OpenContext ctx); | |
[DllImport("LgLcd.dll", EntryPoint = "lgLcdClose")] | |
public static extern int Close(int device); | |
[DllImport("LgLcd.dll", EntryPoint = "lgLcdReadSoftButtons")] | |
public static extern int ReadSoftButtons(int device, out int buttons); | |
[DllImport("LgLcd.dll", EntryPoint = "lgLcdUpdateBitmap")] | |
public static extern int UpdateBitmap(int device, ref Bitmap160X43X1 bitmap, uint priority); | |
[DllImport("LgLcd.dll", EntryPoint = "lgLcdSetAsLCDForegroundApp")] | |
public static extern int SetAsLCDForegroundApp(int device, int toggle); | |
[StructLayout(LayoutKind.Sequential)] | |
public struct Bitmap160X43X1 | |
{ | |
public BitmapHeader Header; | |
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 6880)] | |
public byte[] Pixels; | |
} | |
[StructLayout(LayoutKind.Sequential)] | |
public struct BitmapHeader | |
{ | |
public uint Format; | |
} | |
[StructLayout(LayoutKind.Sequential)] | |
public struct ConfigureContext | |
{ | |
public OnConfigureDelegate ConfigCallback; | |
public IntPtr ConfigContext; | |
} | |
[StructLayout(LayoutKind.Sequential)] | |
public struct ConnectContext | |
{ | |
public string AppFriendlyName; | |
public bool IsPersistent; | |
public bool IsAutostartable; | |
public ConfigureContext OnConfigure; | |
public int Connection; | |
} | |
[StructLayout(LayoutKind.Sequential)] | |
public struct DeviceDescription | |
{ | |
public int Width; | |
public int Height; | |
public int BitsPerPixel; | |
public int SoftButtonsCount; | |
} | |
[StructLayout(LayoutKind.Sequential)] | |
public struct OpenContext | |
{ | |
public int Connection; | |
public int Index; | |
public SoftButtonsChangedContext OnSoftButtonsChanged; | |
public int Device; | |
} | |
[StructLayout(LayoutKind.Sequential)] | |
public struct SoftButtonsChangedContext | |
{ | |
public OnSoftButtonsDelegate Callback; | |
public IntPtr Context; | |
} | |
} | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
LgLcd.ConnectContext ctx = new LgLcd.ConnectContext(); | |
ctx.AppFriendlyName = "List"; | |
LgLcd.Init(); | |
var openResult = LgLcd.Connect(ref ctx); | |
Console.WriteLine("Conn: {0}", ctx.Connection); | |
LgLcd.DeviceDescription desc = new LgLcd.DeviceDescription(); | |
int i = 0; | |
while (0 == LgLcd.Enumerate(ctx.Connection, i, out desc)) | |
{ | |
Console.WriteLine("{4}: {0}x{1}, bbp {2}, {3} buttons", desc.Width, desc.Height, desc.BitsPerPixel, | |
desc.SoftButtonsCount, i); | |
i++; | |
} | |
Console.WriteLine("Detected devices: {0}", i); | |
Console.ReadLine(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment