Posted by
| Nick Gammon
Australia (23,102 posts) Bio
Forum Administrator |
Message
| Full documentation
Load DLL
You need to load the DLL from inside MUSHclient, within a Lua scripting environment (main program or plugin):
assert (loadlib ("G15_Display.dll", "luaopen_g15")) () -- install
g15.SetAsForeground (true) -- bring to foreground
For Lua 5.1 onwards (MUSHclient 3.80 onwards) you need to use package.loadlib, like this:
assert (package.loadlib ("G15_Display.dll", "luaopen_g15")) () -- install
Once installed, the g15 table has the following functions:
IsOpen - check if the keyboard interface loaded OK.
IsConnected - check if the keyboard is connected OK. If not, other functions will raise an error.
assert (g15.IsConnected ())
Update - force an update of the LCD screen - done automatically after setting text but you can do it manually if you are using scrolling text, say every second or so.
AddText - adds a new "text" object, returning a userdata which can be used to change the text in it.
All arguments have defaults.
Syntax:
tud = g15.addtext (type, size, align, pixels, x, y)
- type = one of: static/scrolling (default: static)
- size = one of: small/medium/big (default: small)
- align = one of: left/center/right (default: left)
- pixels = maximum width in pixels (eg. up to 160) (default: 80)
- x = X-position (0 = left) (default: 0)
- y = Y-position (0 = top) (default: 0)
eg.
hp_text = g15.AddText ("static", "small", "right", 40, 0, 0)
Small text is 7 point, medium is 8 point, big is 12 point.
AddProgressBar - adds a new "progress bar" object, returning a userdata which can be used to change the progress amount in it.
All arguments have defaults.
Syntax:
pud = g15.AddProgressBar (type, sizeX, sizeY, x, y)
- type = one of: cursor/filled/dot (default: cursor)
- sizeX = width in pixels (default: 120)
- sizeY = height in pixels (default: 5)
- x = X-position (0 = left) (default: 0)
- y = Y-position (0 = top) (default: 0)
eg.
hp_bar = g15.AddProgressBar ("filled", 100, 8, 50, 0)
SetAsForeground - brings that page on the LCD screen to the front or back.
g15.SetAsForeground (true) -- make foreground
ButtonTriggered - returns true if the corresponding button is triggered
print (g15.ButtonTriggered (2))
ButtonReleased - returns true if the corresponding button is released
print (g15.ButtonReleased (3))
ButtonIsPressed - returns true if the corresponding button is pressed right now
print (g15.ButtonIsPressed (4))
Close - closes the G15 library, releasing the LCD device
The Close function was released on 16 April 2007 in the Lua 5.1 version, and is intended to be used in OnPluginClose to properly release the device.
Text Methods
Once you have created a text object with g15.AddText you can do the following things to it:
set - set the text
eg.
hp_text:set ("Your health is low")
Note the colon after the userdata, which makes it supply the userdata itself as the first argument (the "self" parameter).
visible - make visible or invisible
eg.
hp_text:visible (true) -- make visible
Progress Bar Methods
Once you have created a progress bar object with g15.AddProgressBar you can do the following things to it:
percent - set the percentage filled
eg.
hp_bar:percent (45) -- make 45% filled
Note the colon after the userdata, which makes it supply the userdata itself as the first argument (the "self" parameter).
If the argument is outside the range 0 to 100 it is forced into that range.
visible - make visible or invisible
eg.
hp_bar:visible (false) -- make invisible
Notes
- The LCD screen size currently is 160 x 43 pixels.
- Personally I couldn't get ButtonTriggered and ButtonReleased to do anything. However ButtonIsPressed seemed to correctly return true if the button was held down when the call is made.
- I seem to be having problems with the display disconnecting if the computer goes to sleep. Perhaps this wouldn't happen in practice, but I have released an updated DLL recently that removes the test for whether or not the display is connected. You can still test it yourself with IsConnected, but the other functions will now complete, whether or not the display is connected (I think).
- I wasn't able to work out how to reliably remove things (other than making it crash <groan>), however I thought you probably would have a standard setup that doesn't need changing much. The SDK implements some sort of "pages" concept that I couldn't see a great use for. If you wanted to have two (or more) pages of information you can probably use the "visible" property to do this. Make two sets of things, one visible and the other invisible, and toggle back and forth between them.
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|