I'm a moron. I coded for LCD screen on my keyobard

K.I.L.E.R

Retarded moron
Veteran
I manged to do it via reading the docs.
The docs are very nicely detailed but not overly detailed. Well done Logitech, you guys are a good example.
I spent about an hour doing this(reading & understanding docs at around 2:30 in the morning) so please don't knock the simplicity.

You need the WIndows 32 api but not MFC because you need access to unsigned longs called 'DWORD' which are Microsoft's version of an integer(aka unsigned long, 64 bit long turned into an unsigned thing which is just 32b).
I'm guessing it has to do with compacting stuff into large bitsets.

Storing 2 DWORD into a single long.

Anyway here's code:

Code:
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include "lglcd.h"


int main(int argc, char *argv[]){
  const int BITMAP_AREA = 160 * 43;

  DWORD priority;
  lgLcdConnectContext connection;
  lgLcdOpenContext openContext;
  lgLcdDeviceDesc deviceDescription;
  lgLcdBitmap160x43x1 bitmap;


  if(lgLcdInit() == ERROR_SUCCESS){
    connection.appFriendlyName = "Kruno";
    connection.isAutostartable = true;
    connection.isPersistent = true;
    connection.onConfigure.configCallback = NULL;
    connection.onConfigure.configContext = NULL;

    if(lgLcdConnect(&connection) == ERROR_SUCCESS){
      if(lgLcdEnumerate(connection.connection, 0, &deviceDescription) == ERROR_SUCCESS){
        openContext.connection = connection.connection;
        openContext.index = 0;
        openContext.onSoftbuttonsChanged.softbuttonsChangedCallback = NULL;
        openContext.onSoftbuttonsChanged.softbuttonsChangedContext = NULL;

        if(lgLcdOpen(&openContext) == ERROR_SUCCESS){
          priority = LGLCD_ASYNC_UPDATE(LGLCD_PRIORITY_ALERT);
          bitmap.hdr.Format = LGLCD_BMP_FORMAT_160x43x1;

          for(int i=0; i < BITMAP_AREA; i++)
            bitmap.pixels[i] = 0xff;

          if(lgLcdUpdateBitmap(openContext.device, &bitmap.hdr, priority) == ERROR_SUCCESS){
            Sleep(2000);
          }
        }

        lgLcdClose(openContext.index);
      }
    }
  }

  lgLcdDeInit();
  return 0;
}


Given as to how bored I am I might right my own vector library to do some basic rendering but generally what I need are some bitmaps that draw icons but before that I need to find something useful to use the LCD with.

Any ideas?
 
Cool stuff, even if I don't have such a keyboard it's nice to see IHVs providing tools to help you take advantage of your hardware. Do they include source code? Linux guys would throw a party if they did. :)

Anyway, DWORDs aren't microsoft's "int". They are double-words. A word is the CPU basic unit of storage in terms of hardware registers and it's 16bit, 32 bit or 64 bit depending on the systems architecture. The C/C++ type "int" is exactly supposed to represent a word of the particular system it'll be run on. That's why an int is 32 bits in windows 95 and up, but it used to be 16 bits before that, when the API was created. Back then, the API defined type DWORD was 32 bits, or double the size of a word, and due to backward compatibility it stayed. They avoid platform specific types like "int" to ease porting code to other systems like the various LP* types you'll find (long pointers, also reminiscent of the 16 bit days) and many more. It's not just to drive you mad learning a new set of types.

So, to end this story, you could just "#define DWORD unsigned int;" safely without worrying since you'll never run that code in win 3.1. :D
 
it's a G15 isn't it?
one idea I got about potential uses is, some program to use the keyboard as a calculator ;) (with the keypad, and a programmable key to launch it).

but I don't know what the logitech software is able to do, maybe they thought of that before me.

should be very simple and even maybe useful.
 
Thanks t0y.
Yes it is a G15 keyboard.
Your calculator idea sounds great.
Question is, how will I do square roots and stuff on it? There's no button for it on the keypad. :(
 
I wasn't even thinking about something more complicated than 4 operation calculator with crude text output ;)
(I almost only use windows calc for that)



well there would be the option of using programmable keys but you'd have to use left hand and remember where sqrt, cos, sin and others are. But you can as well press num lock and use the arrow keys to select the alternative operators.

I made a drawing, wanted to test my Paint skills even if this wasted some of my time :p
don't take that as a great real functioning thing.

calculette9gh.png


forgot to add, these lines of I/O, they scroll ^^. and you'd have to deal with previous result, how to keep it and do stuff. but at this point, you may be willing to use backspace, then, why not just use all the keyboard anyway to get stuff done (your program would have focus in windoze). Yeah, why use num lock when there are the arrow keys just so close. me dumb :LOL:

should I add, inputting " 2145 - 121" on the same line is stupid, two 10-digit numbers and op wouldn't have enough room to fit.

I hope I gave you some ideas. .


I much like the concept of this keyboard, too bad it's too big for me, expensive and I like my normal keyboard. (not overly expensive but I'd rather spend the scarce money elsewhere..)
I agree it's cool stuff, allowing us to play with it that way is a good thing.
 
Last edited by a moderator:
I didn't think of it like that Blaz.
I could use the 5 programmable keys to select an operation.
Nice.

It's too bad the LCD screen doesn't have it's own processor. I would have liked to code this stuff in ASM.
 
thanks.

this really seems a fun product, with endless possibilities. I even think of displaying grey by blinking a pixel fast enough (depends on the response time and the speed of connection for it to be possible).

also, what would be nice when you get some results, could you dump the bitmap to a file so we can get "screenshots" ;)
 
Last edited by a moderator:
If I ever decide to get to creating a calculator I'll be sure to give you my program and emulator.

At this moment I'm just playing around with it.
I just found out Logitech has a font library under it's "samples" folder which could prove to be very helpful because at this moment I'm finding out that pixel values in a bitmap of 0x00 are ignored.

Bloody crap.

Code:
#define CHAR_WIDTH 4
#define CHAR_HEIGHT 5
#define a 0xFF,
#define b 0x00,

const unsigned char zero[] =
{
a a a a
a b b a
a b b a
a b b a
a a a a
};

const unsigned char one[] =
{
a a a b
b b a b
b b a b
b b a b
a a a a
};

const unsigned char two[] =
{
a a a b
b b a b
a a a b
a b b b
a a a a
};

#undef a
#undef b
 
Well I have pretty much everything working, minus the calculator part.
I've been spending more time trying to get the bloody pixels to show up correctly.

They're all over the place.
 
Back
Top