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

Swap, Scroll and If plugins

Announcements of new plugins or updates.

Moderators: _X7JAY7X_, caesar, IFR, mattcro, limbo

Post Reply
krisp
Plugin Author
Posts: 51
Joined: February 17th, 2006, 4:53 am

Swap, Scroll and If plugins

Post by krisp »

Hello,

I wrote a few very simple plugins to do things that LCDSmartie couldn't easily do on its own. Personally I like a constant display on my VFD rather than swapping screens. Currently it is set up to use the first three characters of both lines to display a CPU usage graph, then the top line has case/cpu temperature or download mbps if there is downstream activity, followed by free hard drive space. the bottom line has beyondtv status and currently recording show.

Anyways, the three plugins I needed to do this have their source pasted in below. They are written in C#. A brief explanation preceeds each code snippet.

Swap

The swap plugin swaps between two or more screens at a regular interval. It's syntax is

$dll(swap,1,string1#string2#string3...#stringN,time_in_seconds-1)

Code: Select all

using System;


namespace swap
{
    public class LCDSmartie
    {
        private Int32 i;
        private Int32 hold;
        private Int32 strnum;

        private string[] swaplist;
        public LCDSmartie()
        {
            i = 0;
            hold = 5;
            strnum = 0;
        }

        public string function1(string param1, string param2)
        {
            try
            {
                swaplist = param1.Split('#');

                if (param2 != null)
                    hold = Int32.Parse(param2);

                if (i == hold)
                {
                    i = 0;
                    strnum++;
                }
                else
                    i++;

                if (strnum == swaplist.Length)
                    strnum = 0;

                return swaplist[strnum];

            }
            catch (Exception e)
            {
                return e.ToString();
            }
        }

        public int GetMinRefreshInterval()
        {
            return 1000;
        }
    }
}
Scroll

The scroll plugin simply scrolls specified text in a specified width. Basicly it lets you scroll part of a line. I'm aware that limbo has a similar plugin but I was unable to reach his download page so I wrote my own. It's a bit dirty, it will restart the line right after the string is finished, so if you want to pad it with spaces you have to do it manually. Syntax:

$dll(scroll,1,text_to_scroll,width)

Code: Select all

using System;

namespace scroll
{
    public class LCDSmartie
    {
        private String scrollString;
        private Int32 i;
        private Int32 len;
                
        public LCDSmartie()
        {
            i = 0;
            len = 0;
        }

        // Scroll text, wrapping around at the end
        public string function1(String param1, String param2)
        {
            try
            {
                this.scrollString = param1;
                len = Int32.Parse(param2);

                i++;             
                
                if (i >= scrollString.Length)
                    i = 0;

                if (scrollString.Length < len)
                    return scrollString;
                else if ((i + len) > scrollString.Length)
                {
                    String tmp;
                    int j = scrollString.Length - i;
                    tmp = scrollString.Substring(i, j);
                    tmp = tmp + scrollString.Substring(0, len - j);
                    return tmp;
                }
                else
                    return scrollString.Substring(i, len);
            }
            catch (Exception e)
            {
                return "Error: " + e.ToString();
            }
        }
    }
}
If

This very simple plugin simply compares two strings and allows for two different outputs depending on whether or not the first string = the second string. For example, If network downstream in mbit = 0.0, display temperature, otherwise display the network downstream in mbit. The syntax for this one is a bit more complicated, but pretty easy to understand.

$dll(if,1,string1#string2,display1#display2

display1 is displayed if string1 = string2, otherwise display2 is shown.

Code: Select all

using System;

namespace @if
{
    public class LCDSmartie
    {
        // string compare, if param1a == param1b, return param2a else param2b
        public string function1(string param1, string param2)
        {
            try
            {
                string[] strs = param1.Split('#');
                string[] rets = param2.Split('#');

                if (rets[0] == null || rets[1] == null)
                    return "Too few arguments";

                if (strs[0] == null || strs[1] == null)
                    return "Too few arguments";
                else if (strs[0].CompareTo(strs[1]) == 0)
                    return rets[0];
                else
                    return rets[1];
            }
            catch (Exception e)
            {
                return e.ToString();
            }
        }
    }
}
Hope this is of use to someone.


if_scroll_swap.zip
if_scroll_swap_source.zip
You do not have the required permissions to view the files attached to this post.

Jumpin' Jon
Plugin Author
Posts: 35
Joined: August 3rd, 2005, 12:34 am
Contact:

Post by Jumpin' Jon »

Wow - nice work.

I hope you don't mind - I'm guessing you won't - I took the liberty of compiling the code, which can be downloaded below. I compiled it using the free Visual C# 2005 Express Edition.

DLLs: if_scroll_swap.zip 5KB
Source: if_scroll_swap_source.zip 37KB

These also make a perfect little template for any other C# developers. Again, nice work.

JJ

krisp
Plugin Author
Posts: 51
Joined: February 17th, 2006, 4:53 am

Post by krisp »

Thanks, I'm glad you find them useful. That's what they are here for :)

Jumpin' Jon
Plugin Author
Posts: 35
Joined: August 3rd, 2005, 12:34 am
Contact:

Post by Jumpin' Jon »

Here's an example of using the if plugin to beautify the output from the RSS plugin, if the feed is down...

$dll(if,1,$Rss(http://news.bbc.co.uk/rss/newsonline_uk ... 91.xml,d,1)#[Rss: Read Timeout],News Feed Down#$Rss(http://news.bbc.co.uk/rss/newsonline_uk ... 91.xml,d,1))

JJ

mattcro
Forum Supporter
Posts: 590
Joined: March 8th, 2006, 1:58 pm
Location: Scotland

Post by mattcro »

Bug report - at least I think it's swap.dll's fault

I'm attempting to use swap.dll (as compiled and posted above by JJ) to cycle between a few status items in the corner of my Winamp display, so I can have track title and time permanently displayed, plus CPU usage and temp cycling in a corner.

I'm using a custom char for a little CPU symbol, and swap.dll appears to mess up the output slightly. I think the problem may be due to the string variable type, since the output is only corrupted if characters with an ASCII value >127 are included in the parameter for swap.dll.

For example, this code swaps between displaying CPU temp (with my LCD's char code 233 for the degree symbol) and the mp3 bitrate, and the $Chr(223) results in corrupted output:

Code: Select all

$dll(swap,1,$Temp2$Chr(223)C#$Right($WinampKBPS,$4%)k,1)
I get 2 characters instead of the degree symbol, and those characters have the character codes 194 and 161. The Smartie preview window (LCD simulation) also shows two characters corresponding to these ASCII codes.

If there are no characters with codes >127 in the swap.dll parameter, the output is correct. I suspect swap.dll is mangling the parameter string - certainly the parameter string works as expected (as do the custom characters) if it is used directly in Smartie.

However, that would mean that Smartie evaluates the innermost (most nested) parameters first, which may well be the case - I don't know...

Matt.

Jumpin' Jon
Plugin Author
Posts: 35
Joined: August 3rd, 2005, 12:34 am
Contact:

Post by Jumpin' Jon »

Hi Matt,

I'm not sure exactly what causes this problem, but I suspect it is because you're trying to pass (what .NET considers to be) an unprintable character.

Can you see what kind of success or failure you get if you try to pass those same chars to my Formatting plugin.. just out of interest.

Ta,
JJ

mattcro
Forum Supporter
Posts: 590
Joined: March 8th, 2006, 1:58 pm
Location: Scotland

Post by mattcro »

Just experimented the formatting plugin and also scroll.dll, and they give the same results as swap - characters with ASCII code >127 (as far as I can tell) get mangled. Usually, the result is two characters in place of the single input character, so I wonder if the plugins (or at least the .NET library functions) are treating these characters as multibyte chars, or generating multibyte characters in their output.

If so, would it work better to use char arrays? This appears to the what the demo plugin uses. I don't know the ins and outs of the string type but I understand it will use multibyte characters as needed, which is probably not the best thing for writing to LCDs - in cases like this you would want to preserve any extended characters as their raw byte value rather than convert them to anything else.

I tried the same input strings with width.dll (by ReverseEngineered), and the characters are processed correctly. I had a look at the source of width.dll and it also uses strings, but uses a different method of handling the parameters, like so:

Code: Select all

__stdcall  function1(char *param1, char *param2)
{
    string input = param2;
    string output;
    char *cPtr = 0;
    ...

    // Parse format string for values
    cPtr = param1;
    while (*cPtr != '\0')
    {
        if (isdigit(*cPtr))
        {
            // Must be the width
            width = atoi(cPtr);
            while (isdigit(*cPtr))
            ...

    // Now have the correct output string, so create a "C string" and return it
    cOutput = new char[output.length()+1];
    strcpy(cOutput,output.c_str());
    
    return cOutput;
}

Maybe it makes a difference that it was compiled in plain C++ (non-.NET), but it might be worth trying this method in swap/if/scroll.

Matt.

DotA_Player
Posts: 57
Joined: February 23rd, 2008, 7:42 pm

Re: Swap, Scroll and If plugins

Post by DotA_Player »

Scroll plugin = Nice job, better than Limbo's - because it looks very bad when the line have to finish and then it's rescrolling - You're giving us choice unlike Libmo :smt006 , and I don't get why Limbo used one scrolling and one static section (static is useless - you can put static data outside scroll function...)

If plugin - Will be definitively useful for many people, so for me.

:?: Swap plugin - I don't get purpose of this plugin, it does the same as smartie's screen changing ... doesn't it ?

Edit : I found one lil' defect at Scroll plugin - It'd be good to let us set the speed(set scroll interval), or control speed from smartie's scroll interval setting.

DotA_Player
Posts: 57
Joined: February 23rd, 2008, 7:42 pm

Re: Swap, Scroll and If plugins

Post by DotA_Player »

I have the same problem - need use swap with custom chars ... chinese symbols instead. I use a little icon of envelope made of 2 chars. It's weird, because on display is displayed 1corrupted char, next to is 1st custom char of my image (correctly dispayed) and then 2 corrupted chars. btw, the corrupted chars are not actually corrupted, but that's chinese symbols, made of 2 characters (They concur each other).


Pity is, that his plugin development seems to be dead ;(

Post Reply