gmcl_g19 - G19 support for GMod

After GMod already supports the Logitech G15 using I hacked together a nice module which adds a rendertarget for your Logitech G19 keyboard.
[release]
Functions:
g19.StartDraw() – Begins rendering to the G19 rendertarget
g19.EndDraw() – Finishes rendering to the G19 rendertarget
g19.Update() – Makes the G19 display redraw

g19.SetForceForeground(true/false) – Forces your applet to be in foreground (or disables the forcing again)
g19.SetPriority(priority) – Sets the priority of your applet. For use with the LGLCD_PRIOTIY_ constants.

g19.SetColor(R,G,B) – Sets the color of the LCD backlight
g19.SetMLEDs(M1,M2,M3,MR) – Sets the state of the M-Keys (each is a bool)

g19.GetButtonState() – Gets the G19 buttons state (use bitmask operations to get the states of the individual buttons)

Variables/Constants:
g19.BUTTON_LEFT, g19.BUTTON_RIGHT, g19.BUTTON_UP, g19.BUTTON_DOWN, g19.BUTTON_OK, g19.BUTTON_CANCEL. g19.BUTTON_MENU – For usage with GetButtonState or the hook
g19.LGLCD_PRIORITY_IDLE_NO_SHOW, g19.LGLCD_PRIORITY_BACKGROUND, g19.LGLCD_PRIORITY_NORMAL, g19.LGLCD_PRIORITY_ALERT – For setting the priority

Hooks:
G19ButtonChanged – Called when a button gets changed, see usage in example Lua

Example Usage: (adds a hook for button changes and renders the view of the RTCam to the G19)
[lua]
require(“g19”) – Initialzes the module

local rtTexture = surface.GetTextureID( “pp/rt” )

hook.Add(“HUDPaint”,“HP_G19”,function()
g19.StartDraw() --Begins rendering to the G19 rendertarget
surface.SetTexture( rtTexture )
surface.SetDrawColor( 255, 255, 255, 255 )
surface.DrawTexturedRect( 0,0,320,240 )
g19.EndDraw() --Finishes rendering to the G19 rendertarget
end)

timer.Create(“G19RefreshTimer”,(1/15),0,function()
g19.Update() --Makes the G19 display redraw
end)

hook.Add(“G19ButtonChanged”,“G19_BCHanged”,function(button,pressed)
if button == g19.BUTTON_LEFT and pressed then
print(“Left pressed!”)
end
end)

function G19IsButtonPressed(button)
return ((g19.GetButtonState() & button) ~= 0)
end
[/lua]

Information:
Rendering to the G19 RT has been tested to work in the hooks “PostRenderVGUI” and “HUDPaint” so far.
It is not advised to call g19.Update() each frame since it will severely drain your framerate. My timer (as you see) runs at 15 times a sec which causes no noticeable FPS drop.

Download:
Binary: http://natesync.net/public/doridian/gmod/gmcl_g19.dll
Source: http://svn.doridian.de/gmdlls/gmcl_g19/ User: guest, Password: guest
To run this module you need the Visual C++ 2010 Redistributable downloadable from Microsoft here: http://www.microsoft.com/downloads/details.aspx?FamilyID=a7b7a05e-6de6-4d3a-a423-37bf0912db84&displaylang=en
(To compile the source you need the lglcd.h and lglcd.lib from the Logitech SDK, which is included with the G19 driver)

Demo: (filmed by my iPhone, so not best quality)

Credits:
Jinto - Ideas on how to do things which I took from gm_image (renderContext->ReadPixels)
Wizard of Ass - Motivation / Testing
https://github.com/signal11/hidapi - For being able to use it for direct access to the keyboard
[/release]

Now I’m totally gonna get a G19. Awesome!

Anything useful for non-developers yet? I have a Logitech G19.

The module just has been released yet, what do you exspect?

I’m already coding on a HUD extension but I’m not sure if I gonna release it.

Sometimes when a module is released the guy who made it has some small example that uses the module in some way.
I was more thinking about that.

Well, my example up there works. It renders the view of the current RTCam to your G19 LCD In case that’s any use for you. :wink:

Awesome, screen shot would be nice too :stuck_out_tongue:

Surely a photo/video would be better here? :stuck_out_tongue:

Haha, yes, them things.

Added a little demo video to the OP.

WoW!
finally a reason to buy a G19 :wink:

Awesome, but why the hill do you need a keyboard with a screen? :lol:

I would buy one but 150 euro’s for a keyboard is just a little to much.

By making this module, you increased Logitech’s sales count for the G19 by at least one.

Why the hell would you need a computer? Why the hell would you need a car? Why the hell would you need a house? Why the hell do you need laws?

Why the hell would you want laws? Why the hell would you want a house? Why the hell would you want a car? Why the hell would you want a(n awesome) computer? Why the hell would you want a keyboard with a screen?

Suddenly all of the Lua section buys G19s.

Ebay has them for 129$, woot.

Cool.

But don’t use surface.GetTextureID in HUDPaint.

Fix’d in OP.

I’m taking parts of derma and recode them to work on the derma and make the buttons work with the g19 buttons.

Works pretty good for now but its alot of work :frowning:

In germany you can get the G19 for 109€ and ZERO Euro shipping :wink:

error loading module ‘g19’ from file ‘c:\program files (x86)\steam\steamapps\xxx\garrysmod\garrysmod\lua\includes\modules\gmcl_g19.dll’:
The Module couldn’t be found.

A friend of me keeps getting that error, if you enter the path manual within windows explorer it opens the file… (so it exists)
What’s going wrong?