www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Logitech G15 Display SDK in D

reply Mike <vertex gmx.at> writes:
Hi!

I've just bought this nice new gaming keyboard with the fancy LCD  =

(http://www.logitech.com/index.cfm/keyboards/keyboard/devices/3498&cl=3D=
us,en)  =

and wanted to ask if anybody has ever translated the SDK to D. If not, I=
'm  =

currently looking into how much work it would be. If anybody's intereste=
d  =

I'll wrap it in a nice class and post it here (don't know when, I've got=
  =

so much work in my day job currently).

As a side note ( billbaxter): Maybe you remember that I've said I'd port=
  =

WinTab to D - I'm in the process of setting up classes for various input=
  =

devices right now (mostly MIDI control devices like Vestax DJ console), =
so  =

WinTab is on my todo-asap-list - but, as I said, I have not much time  =

right now, eventually I'll be able to do it. And programming the G15  =

display is simply more fun right now :)

-Mike


-- =

Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Mar 10 2008
next sibling parent reply lutger <lutger.blijdestijn gmail.com> writes:
Mike wrote:

 Hi!
 
 I've just bought this nice new gaming keyboard with the fancy LCD

 and wanted to ask if anybody has ever translated the SDK to D. If not, I'm
 currently looking into how much work it would be. If anybody's interested
 I'll wrap it in a nice class and post it here (don't know when, I've got
 so much work in my day job currently).
 
 As a side note ( billbaxter): Maybe you remember that I've said I'd port
 WinTab to D - I'm in the process of setting up classes for various input
 devices right now (mostly MIDI control devices like Vestax DJ console), so
 WinTab is on my todo-asap-list - but, as I said, I have not much time
 right now, eventually I'll be able to do it. And programming the G15
 display is simply more fun right now :)
 
 -Mike
 
 

Hi, I have made a simple binding + wrapper once, but only for the low level c library for windows, not the full C++ sdk. The binding and wrapping of this library is not much work at all, however porting the whole C++ sdk is more work. Since the c++ sdk is built on the c library, you could also make one from scratch in D. There is also a G15 library + driver available under linux. If you want I can see if I can find my old G15 code and post it. Perhaps it would be interesting to start a cross-platform G15 library in D? I'm willing to contribute (for linux code too).
Mar 10 2008
parent reply Mike <vertex gmx.at> writes:
That would be great - I've looked through the files and - yeah - the C  
part is easy, the C++ part seems a bit harder. Maybe your bindings could  
serve as a starting point for a library; maybe some "advanced input  
device" library - with bindings and high-level abstraction for keyboards  
like the G15 and graphics tablets (since I'm doing that anyway). I think  
that would go well together in a library. I don't know about Linux,  
however, recently installed it on my laptop and still I have only managed  
to get Hello World to compile&run :)

I've got a seminar now (Excel 2007 *sigh*) so I'm in a bit of a hurry, but  
I'll check the NG this evening.

-Mike

On Mon, 10 Mar 2008 15:49:11 +0100, lutger <lutger.blijdestijn gmail.com>  
wrote:

 Hi, I have made a simple binding + wrapper once, but only for the low  
 level
 c library for windows, not the full C++ sdk. The binding and wrapping of
 this library is not much work at all, however porting the whole C++ sdk  
 is
 more work. Since the c++ sdk is built on the c library, you could also  
 make
 one from scratch in D. There is also a G15 library + driver available  
 under
 linux.

 If you want I can see if I can find my old G15 code and post it. Perhaps  
 it
 would be interesting to start a cross-platform G15 library in D? I'm
 willing to contribute (for linux code too).

-- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Mar 10 2008
parent reply Lutger <lutger.blijdestijn gmail.com> writes:
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

I see I didn't get very far, it still compiles and works with dmd 1.022 
though.

I remember having some difficulties with the lib format provided by 
logitech, I think I just compiled a dll from this myself or found one 
via the internet.
Mar 10 2008
next sibling parent Mike <vertex gmx.at> writes:
On Tue, 11 Mar 2008 00:58:35 +0100, Lutger <lutger.blijdestijn gmail.com>  
wrote:

 I see I didn't get very far, it still compiles and works with dmd 1.022
 though.

 I remember having some difficulties with the lib format provided by
 logitech, I think I just compiled a dll from this myself or found one
 via the internet.

I'm seeing what I can do about the linking. Hope you don't mind if I tango-fy your code. -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Mar 11 2008
prev sibling parent reply Mike <vertex gmx.at> writes:
On Tue, 11 Mar 2008 00:58:35 +0100, Lutger <lutger.blijdestijn gmail.com>  
wrote:

 I see I didn't get very far, it still compiles and works with dmd 1.022
 though.

 I remember having some difficulties with the lib format provided by
 logitech, I think I just compiled a dll from this myself or found one
 via the internet.

I think I'm giving up too ... tried various ways to convert the COFF lib to OMF, the best result was 1 missing symbol. Maybe linking with another linker would help. I'm not sure about the dll thing, since lglcd.lib is just a wrapper that loads the "real" dll. So loading a DLL to load a DLL sounds a bit strange. But there is an alternative implementation, at least I've found some hints on google. Maybe that's a good way. -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Mar 11 2008
parent reply lutger <lutger.blijdestijn gmail.com> writes:
Mike wrote:

 On Tue, 11 Mar 2008 00:58:35 +0100, Lutger <lutger.blijdestijn gmail.com>
 wrote:
 
 I see I didn't get very far, it still compiles and works with dmd 1.022
 though.

 I remember having some difficulties with the lib format provided by
 logitech, I think I just compiled a dll from this myself or found one
 via the internet.

I think I'm giving up too ... tried various ways to convert the COFF lib to OMF, the best result was 1 missing symbol. Maybe linking with another linker would help. I'm not sure about the dll thing, since lglcd.lib is just a wrapper that loads the "real" dll. So loading a DLL to load a DLL sounds a bit strange. But there is an alternative implementation, at least I've found some hints on google. Maybe that's a good way.

Are you sure it's just an import library? I know I've tried loading the functions dynamically from the real dll but that didn't work. I have downloaded some binding somewhere and I believe they have just wrapped the lib as a dll, so I did that myself. I just tested a simple program on windows and it does work, I'll go check it out further, might take a couple of days though.
Mar 11 2008
parent Mike <vertex gmx.at> writes:
On Wed, 12 Mar 2008 00:26:31 +0100, lutger <lutger.blijdestijn gmail.com>  
wrote:

 Mike wrote:

 On Tue, 11 Mar 2008 00:58:35 +0100, Lutger  
 <lutger.blijdestijn gmail.com>
 wrote:

 I see I didn't get very far, it still compiles and works with dmd 1.022
 though.

 I remember having some difficulties with the lib format provided by
 logitech, I think I just compiled a dll from this myself or found one
 via the internet.

I think I'm giving up too ... tried various ways to convert the COFF lib to OMF, the best result was 1 missing symbol. Maybe linking with another linker would help. I'm not sure about the dll thing, since lglcd.lib is just a wrapper that loads the "real" dll. So loading a DLL to load a DLL sounds a bit strange. But there is an alternative implementation, at least I've found some hints on google. Maybe that's a good way.

functions dynamically from the real dll but that didn't work. I have downloaded some binding somewhere and I believe they have just wrapped the lib as a dll, so I did that myself. I just tested a simple program on windows and it does work, I'll go check it out further, might take a couple of days though.

So ... I've done some research now :) lglcd.lib imports the LoadLibrary, RegOpen, RegQuery stuff from windows and nothing else. There are some other very interesting symbols in lglcd.lib: - a registry key - "szPathToDLL" - "GetInterface" GetInterface is a symbol that is exported by lglcdapi.dll, so it's save to say that this lib does nothing than get the location of lglcdapi.dll and fetch an interface from there. That's not too hard to do, and we'll end up with a nice D interface to work with instead of C function prototypes. Together with the structs and magic numbers from the SDK this should work well. It's way past midnight so I probably won't get far tonight, but we'll see. -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Mar 11 2008
prev sibling parent reply Bill Baxter <dnewsgroup billbaxter.com> writes:
Mike wrote:
 Hi!
 
 I've just bought this nice new gaming keyboard with the fancy LCD 
 (http://www.logitech.com/index.cfm/keyboards/keyboard/devices/3498&cl=us,en) 
 and wanted to ask if anybody has ever translated the SDK to D. If not, 
 I'm currently looking into how much work it would be. If anybody's 
 interested I'll wrap it in a nice class and post it here (don't know 
 when, I've got so much work in my day job currently).
 
 As a side note ( billbaxter): Maybe you remember that I've said I'd port 
 WinTab to D - I'm in the process of setting up classes for various input 
 devices right now (mostly MIDI control devices like Vestax DJ console), 
 so WinTab is on my todo-asap-list - but, as I said, I have not much time 
 right now, eventually I'll be able to do it. And programming the G15 
 display is simply more fun right now :)

What did you say you did about the Pascal calling convention? Was that you? Someone explained previously here you have to reverse the order of the arguments or something like that, but I can't find the message. I thought I'd take a shot at porting the header, but all I get is Error 42: Symbol Undefined _WTOpenW 12 I tried the various combinations of making the import lib with /system and without. And making the prototypes extern(Windows) vs extern(C). No luck so far. The entry in WINTAB32.DEF looks like this: WTOpenW 12 1021 And the prototype i'm using looks like this: HCTX WTOpenW(HWND, LPLOGCONTEXTW, BOOL); --bb
Mar 11 2008
parent Mike <vertex gmx.at> writes:
On Tue, 11 Mar 2008 22:43:44 +0100, Bill Baxter  =

<dnewsgroup billbaxter.com> wrote:

 What did you say you did about the Pascal calling convention?  Was tha=

 you?  Someone explained previously here you have to reverse the order =

 the arguments or something like that, but I can't find the message.

Yeah, that was me. I've never tried to import the lib, what I've done is= = load wintab32.dll directly and call the functions in there. That works, = at = least in my little exploratory tests. The important thing is this: wintab.h: HCTX WTOpenW(HWND, LPLOGCONTEXTW, BOOL); wintab.d: extern (Pascal) { alias HCTX function(BOOL, LPLOGCONTEXTW, HWND) WTOpenFunc; } Below is what I have tried out, and what seems to work. I still need to = = find out the location of wintab32.dll (should be in the registry) and fi= ll = in the missing dll functions then it should be ready to build some = higher-level stuff on top. ------------------------------------------------------------------------= --------------- // test to see how tablet support works in D module tablet; import std.stdio; import std.string; import std.c.windows.windows; // wintab32 magic numbers // info categories enum ETabConsts { WTI_INTERFACE =3D 1, IFC_WINTABID =3D 1, IFC_SPECVERSION =3D 2, IFC_IMPLVERSION =3D 3, IFC_NDEVICES =3D 4, IFC_NCURSORS =3D 5, IFC_NCONTEXTS =3D 6, IFC_CTXOPTIONS =3D 7, IFC_CTXSAVESIZE =3D 8, IFC_NEXTENSIONS =3D 9, IFC_NMANAGERS =3D 10, IFC_MAX =3D 10, = = WTI_STATUS =3D 2, STA_CONTEXTS =3D 1, STA_SYSCTXS =3D 2, STA_PKTRATE =3D 3, STA_PKTDATA =3D 4, STA_MANAGERS =3D 5, STA_SYSTEM =3D 6, STA_BUTTONUSE =3D 7, STA_SYSBTNUSE =3D 8, STA_MAX =3D 8, = WTI_DEFCONTEXT =3D 3, WTI_DEFSYSCTX =3D 4, WTI_DDCTXS =3D 400, WTI_DSCTXS =3D 500, CTX_NAME =3D 1, CTX_OPTIONS =3D 2, CTX_STATUS =3D 3, CTX_LOCKS =3D 4, CTX_MSGBASE =3D 5, CTX_DEVICE =3D 6, CTX_PKTRATE =3D 7, CTX_PKTDATA =3D 8, CTX_PKTMODE =3D 9, CTX_MOVEMASK =3D 10, CTX_BTNDNMASK =3D 11, CTX_BTNUPMASK =3D 12, CTX_INORGX =3D 13, CTX_INORGY =3D 14, CTX_INORGZ =3D 15, CTX_INEXTX =3D 16, CTX_INEXTY =3D 17, CTX_INEXTZ =3D 18, CTX_OUTORGX =3D 19, CTX_OUTORGY =3D 20, CTX_OUTORGZ =3D 21, CTX_OUTEXTX =3D 22, CTX_OUTEXTY =3D 23, CTX_OUTEXTZ =3D 24, CTX_SENSX =3D 25, CTX_SENSY =3D 26, CTX_SENSZ =3D 27, CTX_SYSMODE =3D 28, CTX_SYSORGX =3D 29, CTX_SYSORGY =3D 30, CTX_SYSEXTX =3D 31, CTX_SYSEXTY =3D 32, CTX_SYSSENSX =3D 33, CTX_SYSSENSY =3D 34, CTX_MAX =3D 34, = WTI_DEVICES =3D 100, DVC_NAME =3D 1, DVC_HARDWARE =3D 2, DVC_NCSRTYPES =3D 3, DVC_FIRSTCSR =3D 4, DVC_PKTRATE =3D 5, DVC_PKTDATA =3D 6, DVC_PKTMODE =3D 7, DVC_CSRDATA =3D 8, DVC_XMARGIN =3D 9, DVC_YMARGIN =3D 10, DVC_ZMARGIN =3D 11, DVC_X =3D 12, DVC_Y =3D 13, DVC_Z =3D 14, DVC_NPRESSURE =3D 15, DVC_TPRESSURE =3D 16, DVC_ORIENTATION =3D 17, DVC_ROTATION =3D 18, DVC_PNPID =3D 19, DVC_MAX =3D 19, = WTI_CURSORS =3D 200, CSR_NAME =3D 1, CSR_ACTIVE =3D 2, CSR_PKTDATA =3D 3, CSR_BUTTONS =3D 4, CSR_BUTTONBITS =3D 5, CSR_BTNNAMES =3D 6, CSR_BUTTONMAP =3D 7, CSR_SYSBTNMAP =3D 8, CSR_NPBUTTON =3D 9, CSR_NPBTNMARKS =3D 10, CSR_NPRESPONSE =3D 11, CSR_TPBUTTON =3D 12, CSR_TPBTNMARKS =3D 13, CSR_TPRESPONSE =3D 14, CSR_PHYSID =3D 15, CSR_MODE =3D 16, CSR_MINPKTDATA =3D 17, CSR_MINBUTTONS =3D 18, CSR_CAPABILITIES =3D 19, CSR_TYPE =3D 20, CSR_MAX =3D 20, = WTI_EXTENSIONS =3D 300, EXT_NAME =3D 1, EXT_TAG =3D 2, EXT_MASK =3D 3, EXT_SIZE =3D 4, EXT_AXES =3D 5, EXT_DEFAULT =3D 6, EXT_DEFCONTEXT =3D 7, EXT_DEFSYSCTX =3D 8, EXT_CURSORS =3D 9 , EXT_MAX =3D 109, } // wintab32.dll function prototypes // note: define arguments in reverse order for extern(Pascal) to work extern (Pascal) { typedef UINT function(void *lpOutput, UINT nIndex, UINT wCategory) = WTInfoFunc; } class CTabletTest { public: this() { writef("Checking tablet ... "); mLibraryHandle =3D = LoadLibraryA(toStringz("C:\\WINDOWS\\system32\\wintab32.dll")); // aargh= ! if (mLibraryHandle is null) { writefln("not found."); } else { try { UINT temp; writefln("found."); WTInfo =3D cast(WTInfoFunc)GetProcAddress(myLibraryHandle, = toStringz("WTInfoA")); temp =3D WTInfo(&myBuffer, ETabConsts.IFC_WINTABID, = ETabConsts.WTI_INTERFACE); for (UINT i =3D 0; i < temp - 1; i++) { writef(cast(char)mBuffer[i]); } writef(" (spec/impl: "); temp =3D WTInfo(&mBuffer, ETabConsts.IFC_SPECVERSION, = ETabConsts.WTI_INTERFACE); writef(mBuffer[1], ".", mBuffer[0]); temp =3D WTInfo(&mBuffer, ETabConsts.IFC_IMPLVERSION, = ETabConsts.WTI_INTERFACE); writef("/", mBuffer[1], ".", mBuffer[0]); writefln(")"); = temp =3D WTInfo(&mBuffer, ETabConsts.IFC_NDEVICES, = ETabConsts.WTI_INTERFACE); writefln("Devices: ", mBufferUINT); = } catch (Exception e) { writefln("Exception while initializing tablet support: ", e.msg); FreeLibrary(mLibraryHandle); } } } = ~this() { if (mLibraryHandle !is null) FreeLibrary(mLibraryHandle); } = private: HMODULE mLibraryHandle =3D null; = // WTab functions WTInfoFunc WTInfo; = // buffer for communicating with wintab32.dll union { UINT mBufferUINT; byte[1000] mBuffer; } } -- = Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Mar 11 2008