Our new official repo is on github
LCD Smartie version 5.6 is released!
Download it now: https://github.com/LCD-Smartie/LCDSmartie/releases

Crystalfontz 635 LED & Menu Hack

General discussion about LCD Smartie.

Moderators: _X7JAY7X_, caesar, IFR, mattcro, limbo, Fast351

Post Reply
jbysmith
Posts: 3
Joined: December 26th, 2005, 2:12 am

Crystalfontz 635 LED & Menu Hack

Post by jbysmith »

I've been playing with LCDSmartie for a little while now, and aside from my one question about temperature conversion from MBM I've had really good results with it.

The only thing I was a little bummed about is that I'm using a CrystalFontz 635, which has four little LED's on the side that can be used for.. whatever.

I was also playing with the menu addon, which is pretty nice, but I figured, instead of "> Menuitem", how about lighting one of the LED's instead of showing a >.

So I made a slight modification to the source code to let me do this. It's actually a pretty slight modification. I changed three files.

First is ULCD, and added a dummy ToggleLED routine, so it wont splat if a different LCD display tries to use the function. (It just doesn't do anything.)

The second is ULCD_CF, added the real code to the ToggleLED routine. Nothing flash, just spits out a packet to set an LED.

The last is UData, where is captures a character in a line and interprets it as turning on an LED or turning them all off.

When used with the menu plugin, it strips out the > (replacing it with a space so it doesn't look silly) and lights the LED that's active instead. When the menu quits, it returns to page #2, where the very first character on line one is a ~, which tells it to clear all the LED's. (I dont use the ~ on my screens, pulled it out of thin air)

It's cheap, but it works pretty well.

Is this something I should post on here how to do? (I can put it as a simple list of instructions of what to change then recompile it in Delphi), or maybe put up the compiled program?

I was altho thinking about extending it a bit, say on a network usage page it can flash a light on send or receive activity, make the LED's into a simple graph of sorts or whatever. Again it would have to be a hack of the actual program.

Wanted to get the developer's feedback on this before I commit a faux-pas on his forums.

Thanks
limbo
Plugin Author
Posts: 1604
Joined: February 13th, 2005, 7:38 pm
Location: Athens - Greece
Contact:

Post by limbo »

Hello jbysmith
Sorry about the late reply I must missed the new post indicators :oops:


You can start a new topic and provide some info about this mod (if its possible [depending on the size of the code])
Try to PM Workshed he 's also maded an alterred version of the program and - I think that - clansley has informed him how to get an "CVS client" in order to keep the mods in the one compact release...

You can find some info about CVS here
Shadowhawk
Posts: 9
Joined: September 27th, 2005, 2:28 pm
Location: Milford, CT USA
Contact:

Post by Shadowhawk »

I'd be interested in this as well as a few others here, as I have been thusfar unable to figure out how to do almost the same thing in plugin form. It would be cool to have that functionality rolled into the main program for us CF-635 owners :D
jbysmith
Posts: 3
Joined: December 26th, 2005, 2:12 am

Crystalfontz 635 LED & Menu Hack

Post by jbysmith »

Ok, here's the code changes to get the 635's LEDs to work with the menu addon. Other LCD types *should* completely ignore the code, altho granted I haven't tested it, only have the 635 to play with. You'll need Delphi obviously to do this.


==========================================
First file to change is ULCD.PAS, this is the base class that all the actual LCD classes are derived from; it doesn't actually do anything. All the code gets overrided later.

Right at the beginning, look for the declaration of the TLCD class, and add the following code (I've marked all changes):

Code: Select all

  TLCD = class(TObject)
  public
    {***** START LED HACK *****}
        LastLED: Byte;
    Procedure ToggleLED(LEDNumber:Byte); Virtual;
    {***** END LED HACK *****}
    procedure setPosition(x, y: Integer); virtual;
That's the declarations. Next, need to get the constructor modified a tad:

Code: Select all

constructor TLCD.Create;
begin
  inherited;
  {***** START LED HACK *****}
  LastLED := 0;
  {***** END LED HACK *****}
end;
Then, the dummy procedure of the actual LED toggle. Can pretty much put this anywhere in the code.

Code: Select all

{***** START LED HACK *****}
Procedure TLCD.ToggleLED(LEDNumber:Byte);
Begin
    // Dummy Procedure
End;
{***** END LED HACK *****}
Other LCD types won't do anything as the procedure doesn't get overridden.

============================================

Now, we need to change the CrystalFontz code. Open up ULCD_CF.PAS.

At the beginning, where the LCD's class is declared, change it to look like:

Code: Select all

  TLCD_CF = class(TLCD)
    {***** START LED HACK *****}
    Procedure ToggleLED(LEDNumber:Byte); Override;
    {***** STOP LED HACK *****}
    procedure customChar(character: Integer; data: Array of Byte); override;
It's just telling Delphi we're overriding the dummy procedure that we defined earlier.

Now for the actual bit that sends the command to the LCD. Right at the beginning of the implementation section you'll see where the constants are defined. We're adding a command, and adding a procedure as well. Here's the code, it picks up at the end of the constants declarations.

Code: Select all

  CmdSendText = 31;
{***** START LED HACK *****}
  CmdSetLED = 34;

Procedure TLCD_CF.ToggleLED(LEDNumber:Byte);
Var
    TempByte : Byte;
Begin
    If LastLED <> LEDNumber Then
    Begin
        For TempByte := 5 To 12 Do PacketCmd(CmdSetLED,''+Chr(TempByte)+Chr(0)); {Clears all LEDs}
        Case LEDNumber Of
            1 : PacketCmd(CmdSetLED,''+#11+#100);
            2 : PacketCmd(CmdSetLED,''+#9+#100);
            3 : PacketCmd(CmdSetLED,''+#7+#100);
            4 : PacketCmd(CmdSetLED,''+#5+#100);
        End;
        LastLED := LEDNumber;
    End;
End;
{***** STOP LED HACK *****}
===========================================
One more file. Open up UDATA.PAS, we need to add the part where the code to toggle LED's is parsed.

You're lookig for the function called TData.change, here's a snippet with the new code.

Code: Select all

begin
  try
    ProcessPlugin(line, qstattemp, bCacheResults);

    {***** START LED HACK *****}
    if (pos('>', line) <> 0) then
    begin
        line := StringReplace(line, '>',' ', [rfReplaceAll]);

        Case QStatTemp Of
            1 : form1.LCD.toggleled(1);
            2 : form1.LCD.toggleled(2);
            3 : form1.LCD.toggleled(3);
            4 : form1.LCD.toggleled(4);
        End;
    end;

    if (pos('~', line) <> 0) then
    begin
        line := StringReplace(line, '~','', [rfReplaceAll]);
        form1.LCD.toggleled(0);
    end;
    {***** STOP LED HACK *****}

    if (Pos('$', line) = 0) then goto endChange;
============================================

That's it. Recompile it and you're good to go. Note that I used the ~ character to denotote the command to turn off all the LED's. I use this on the page that the menu DLL returns from. Feel free to change the ~ to whatever if you happen to use it on your screens.

When the menu DLL kicks in, it automatically puts a > on the active menu line. UDATA will trip it and replace it with a space to keep the lines lined up, and toggle the appropriate LED. When the menu DLL quits and goes to whatever page, it sees the ~ and turns off all the LED's again.

Just in case I missed something (I'm pretty sure this is complete but..) or dont have Delphi, I put a compiled version on a friend's web space, can get it here.

It also leaves a lot of room to be improved; I whipped this out in about 15 minutes, altho its seems to be working perfectly. The code to change the colors are from CF's datasheet; you can pick different colors or what have you as well.

I was thinking instead of doing a hack like this for one specific function, perhaps adding a new command to the parser to send a bit of raw data to the LCD that can be called from any addon. Granted the data will be specific to the LCD, but that'll be up to the end user to customize anyway. With something like this, you'll be able to access the CF's LED's, the SCAB unit for retrieving sensor data, or other types of things that other LCD displays are capable of. Perhaps I'll write up somthing like that down the road; with that in place it should give addon developers a lot more flexibility with what they're doing.
limbo
Plugin Author
Posts: 1604
Joined: February 13th, 2005, 7:38 pm
Location: Athens - Greece
Contact:

Post by limbo »

any news regarding the cvs?
gaga
Posts: 7
Joined: August 30th, 2005, 7:23 pm

Post by gaga »

Where could I download the compiled program?

Thank you.
alentsa
Posts: 1
Joined: September 10th, 2006, 7:46 am

Post by alentsa »

I am using Dashboard by Axcis Pty Ldt, and it works very well. I downloaded it from http://www.axcis.com.au It has a few interesting features, and one of them - you can control LEDs in CFA635. It has all functions of Smartie plus you can also change the screens using MCE remote control, program the second display to output the relevant information. It calls a slide show screen saver and much more.
Post Reply