Skip to content

Instantly share code, notes, and snippets.

@ebete
Created December 29, 2018 15:49
Show Gist options
  • Save ebete/a07b64c1c203429f8c21fb0e63f91445 to your computer and use it in GitHub Desktop.
Save ebete/a07b64c1c203429f8c21fb0e63f91445 to your computer and use it in GitHub Desktop.
C# wrapper class for the Logitech keyboard display SDK C++ library LogitechLcdEnginesWrapper.dll.
using System.Runtime.InteropServices;
namespace LogitechSdkWrapper {
/// <summary>
/// C# wrapper for the Logitech keyboard display SDK C++ library LogitechLcdEnginesWrapper.dll.
/// </summary>
public static class LogitechSdk {
#region Constants
/// <summary>
/// Left button of the color display.
/// </summary>
public const int LcdColorButtonLeft = 0x00000100;
/// <summary>
/// Right button of the color display.
/// </summary>
public const int LcdColorButtonRight = 0x00000200;
/// <summary>
/// OK button of the color display.
/// </summary>
public const int LcdColorButtonOk = 0x00000400;
/// <summary>
/// Cancel button of the color display.
/// </summary>
public const int LcdColorButtonCancel = 0x00000800;
/// <summary>
/// Up button of the color display.
/// </summary>
public const int LcdColorButtonUp = 0x00001000;
/// <summary>
/// Down button of the color display.
/// </summary>
public const int LcdColorButtonDown = 0x00002000;
/// <summary>
/// Menu button of the color display.
/// </summary>
public const int LcdColorButtonMenu = 0x00004000;
/// <summary>
/// First button of the monochrome display.
/// </summary>
public const int LcdMonoButton0 = 0x00000001;
/// <summary>
/// Second button of the monochrome display.
/// </summary>
public const int LcdMonoButton1 = 0x00000002;
/// <summary>
/// Third button of the monochrome display.
/// </summary>
public const int LcdMonoButton2 = 0x00000004;
/// <summary>
/// Fourth button of the monochrome display.
/// </summary>
public const int LcdMonoButton3 = 0x00000008;
/// <summary>
/// Pixel width of the monochrome displays.
/// </summary>
public const int LcdMonoWidth = 160;
/// <summary>
/// Pixel height of the monochrome displays.
/// </summary>
public const int LcdMonoHeight = 43;
/// <summary>
/// Pixel width of the color displays.
/// </summary>
public const int LcdColorWidth = 320;
/// <summary>
/// Pixel height of the color displays.
/// </summary>
public const int LcdColorHeight = 240;
/// <summary>
/// Identifies the device as a monochrome display.
/// </summary>
public const int LcdTypeMono = 0x00000001;
/// <summary>
/// Identifies the device as a color display.
/// </summary>
public const int LcdTypeColor = 0x00000002;
#endregion
#region Global LCD functions
/// <summary>
/// Make the necessary initialisations. You must call this function prior to any other
/// function in the library.
/// </summary>
/// <param name="friendlyName">The name of your applet, you can’t change it after initialisation.</param>
/// <param name="lcdType">Defines the type of your applet LCD target.</param>
/// <returns>Whether the function succeeded.</returns>
[DllImport("LogitechLcdEnginesWrapper", EntryPoint = "LogiLcdInit", CharSet = CharSet.Unicode,
CallingConvention = CallingConvention.Cdecl)]
public static extern bool LcdInit(string friendlyName, int lcdType);
/// <summary>
/// Check if a device of the type specified by the parameter is connected.
/// </summary>
/// <param name="lcdType">Defines the LCD type to look for.</param>
/// <returns>
/// If a device supporting the LCD type specified is found, it returns <see langword="true" />. If the device
/// has not been found or the <see cref="LcdInit"/> function has not been called before, returns
/// <see langword="false" />.
/// </returns>
[DllImport("LogitechLcdEnginesWrapper", EntryPoint = "LogiLcdIsConnected", CharSet = CharSet.Unicode,
CallingConvention = CallingConvention.Cdecl)]
public static extern bool LcdIsConnected(int lcdType);
/// <summary>
/// Check if the button specified by the parameter is being pressed.
/// </summary>
/// <param name="button">Defines the button to check on.</param>
/// <returns>
/// If the button specified is being pressed it returns <see langword="true" />. Otherwise
/// <see langword="false" />.
/// </returns>
[DllImport("LogitechLcdEnginesWrapper", EntryPoint = "LogiLcdIsButtonPressed", CharSet = CharSet.Unicode,
CallingConvention = CallingConvention.Cdecl)]
public static extern bool LcdIsButtonPressed(int button);
/// <summary>
/// Update the LCD. You have to call this function every frame of your main loop to keep the LCD up to date.
/// </summary>
[DllImport("LogitechLcdEnginesWrapper", EntryPoint = "LogiLcdUpdate", CharSet = CharSet.Unicode,
CallingConvention = CallingConvention.Cdecl)]
public static extern void LcdUpdate();
/// <summary>
/// Kills the applet and frees memory used by the SDK.
/// </summary>
[DllImport("LogitechLcdEnginesWrapper", EntryPoint = "LogiLcdShutdown", CharSet = CharSet.Unicode,
CallingConvention = CallingConvention.Cdecl)]
public static extern void LcdShutdown();
#endregion
#region Monochrome LCD functions
/// <summary>
/// Sets the specified image as background for the monochrome lcd device connected.
/// </summary>
/// <param name="monoBitmap">
/// The array of pixels that defines the actual monochrome bitmap.
/// The array of pixels is organised as a rectangular area, 160 bytes wide and 43 bytes high. Despite the display
/// being monochrome, 8 bits per pixel are used here for simple manipulation of individual pixels.
/// The pixel will turn on if the value assigned to that byte is &gt;&#61; 128, it will remain off if
/// the value is &lt; 128. The pixels are ordered top-left to bottom-right, progressing horizontally.
/// </param>
/// <returns><see langword="true" /> if it succeeds, <see langword="false" /> otherwise.</returns>
[DllImport("LogitechLcdEnginesWrapper", EntryPoint = "LogiLcdMonoSetBackground", CharSet = CharSet.Unicode,
CallingConvention = CallingConvention.Cdecl)]
public static extern bool LcdMonoSetBackground(byte[] monoBitmap);
/// <summary>
/// Sets the specified text in the requested line on the monochrome LCD device.
/// </summary>
/// <param name="lineNumber">
/// The line on the screen you want the text to appear. The monochrome LCD display has 4 lines, so this parameter
/// can be any number from 0 to 3.
/// </param>
/// <param name="text">The text you want to display.</param>
/// <returns><see langword="true" /> if it succeeds, <see langword="false" /> otherwise.</returns>
[DllImport("LogitechLcdEnginesWrapper", EntryPoint = "LogiLcdMonoSetText", CharSet = CharSet.Unicode,
CallingConvention = CallingConvention.Cdecl)]
public static extern bool LcdMonoSetText(int lineNumber, string text);
#endregion
#region Color LCD functions
/// <summary>
/// Sets the specified image as background for the color lcd device connected.
/// </summary>
/// <param name="colorBitmap">
/// The array of pixels that define the actual color bitmap.
/// The array of pixels is organised as a rectangular area, 320 wide and 240 high. Since the color LCD can
/// display the full RGB gamma, 32 bits per pixel (4 bytes) are used. The size of the colorBitmap array has to
/// be 320x240x4 = 307200 bytes (300 KiB). The byte order for each pixel is BGRA. The pixels are ordered
/// top-left to bottom-right, progressing horizontally.
/// </param>
/// <returns><see langword="true" /> if it succeeds, <see langword="false" /> otherwise.</returns>
[DllImport("LogitechLcdEnginesWrapper", EntryPoint = "LogiLcdColorSetBackground", CharSet = CharSet.Unicode,
CallingConvention = CallingConvention.Cdecl)]
public static extern bool LcdColorSetBackground(byte[] colorBitmap);
/// <summary>
/// Sets the specified text in the first line on the color lcd device connected. The font size that will be
/// displayed is bigger than the one used in the other lines, so you can use this function to set the title of
/// your applet/page.
/// </summary>
/// <param name="text">Defines the text you want to display as title.</param>
/// <param name="red">Intensity of the red component of the title.</param>
/// <param name="green">Intensity of the green component of the title.</param>
/// <param name="blue">Intensity of the blue component of the title.</param>
/// <returns><see langword="true" /> if it succeeds, <see langword="false" /> otherwise.</returns>
[DllImport("LogitechLcdEnginesWrapper", EntryPoint = "LogiLcdColorSetTitle", CharSet = CharSet.Unicode,
CallingConvention = CallingConvention.Cdecl)]
public static extern bool LcdColorSetTitle(string text, int red = 255, int green = 255, int blue = 255);
/// <summary>
/// Sets the specified text in the requested line on the color LCD device.
/// </summary>
/// <param name="lineNumber">
/// The line on the screen you want the text to appear. The color lcd display has 8 lines for standard text,
/// so this parameter can be any number from 0 to 7.
/// </param>
/// <param name="text">Defines the text you want to display.</param>
/// <param name="red">Intensity of the red component of the text.</param>
/// <param name="green">Intensity of the green component of the text.</param>
/// <param name="blue">Intensity of the blue component of the text.</param>
/// <returns><see langword="true" /> if it succeeds, <see langword="false" /> otherwise.</returns>
[DllImport("LogitechLcdEnginesWrapper", EntryPoint = "LogiLcdColorSetText", CharSet = CharSet.Unicode,
CallingConvention = CallingConvention.Cdecl)]
public static extern bool LcdColorSetText(int lineNumber, string text, int red = 255, int green = 255,
int blue = 255);
#endregion
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment