View Full Version : Getting Started
harleydude
November 1st, 2006, 09:22 AM
Thanks for allowing me to be part of the beta process. I have downloaded the 503 alpha version and have played with it quite a bit and have looked thru some of the new lua code. I realize that somethings might be changing but is there any docs that describe some of the new ways to write plug-ins and what not?
Rick
Rob H
November 1st, 2006, 10:02 AM
No docs yet I'm afraid :(
If you're converting an existing serial plugin for example, the main thing you need to do is create a DM Provider for it. I'd probably recommend taking a look at luascript\DeviceManager\Providers\PluginBased.lua as a starting point, and one or more of the plugins that inherits from it.
The main thing that you will need to do in your plugin is to add a Publisher e.g.
require 'Classes.Publisher'
in the Initialize method :-
self.Publisher = Classes.Publisher:New()
and add a Subscribe() method to your plugin
Subscribe = function(self, handler)
self.Publisher:Subscribe(handler)
end,
Where previously you might have used gir.TriggerEvent() you can now use
self.Publisher:Event() and anything that subscribes to the plugin will now get a callback.
You're provider (if derived from PluginBased) will need a GetPlugin method that returns the plugin instance, and a PluginEventHandler method. You'll also need to override either AddDevices() or GetDeviceTable() to provide the DM with the devices and controls supported by the plugin. See Providers\Simple.lua for the format of the device table returned by GetDeviceTable.
If the provider is for an AV receiver then it's probably best to derive from GenericAVReceiver which adds a few methods and expects a couple of methods to be defined in the plugin.
If you have any questions, post them here and Mike or I will try to answer them.
I appreciate that the amount of things to learn can seem quite overwhelming (I know, I've been there!), but it's not really all that bad.
harleydude
November 3rd, 2006, 09:29 AM
Well so far I have a plugin that sends events to the DM and the status of the device reports the changes however if I trigger an action from the tree the event is seen in my provider, but the devices state does not appear to update. Below is where I think that should occur. It is probably due to my lack of know what is right.
-- device calls this to have a command performed by the provider/plugin
-- this gets called from actions in the GML tree
DeviceCommand = function (self,Command,Device,Control,newvalue)
if Command == DeviceManager.Devices.Commands.Action then
print (Command, Device:GetID(), Control:GetID(), newvalue)
DeviceManager.Providers.Classes.Base.DeviceCommand (self,Command,Device,Control)
end
end,
Rob H
November 3rd, 2006, 09:36 AM
There are a couple of ways to do this - you can either override DeviceCommand or you can bind a function to your control's Command property (this is my preferred way of doing it as it puts most of the code in one place).
Here's the GetDeviceTable from my LGTV provider :-
GetDeviceTable = function(self)
local plugin = self:GetPlugin()
local dt = {
['TV'] = {Type = 'AV\\Television', Name = 'LG TV', Description = 'LG LCD or Plasma TV',
Sources = plugin:GetInputs(),
SourceCommand = function(value) plugin:MainInput(value) end ,
Aspects = plugin:GetAspectRatios(),
AspectCommand = function(value) plugin:AspectRatio(value) end,
PowerCommand = self:MakeToggleFunc(function() plugin:PowerOn() end, function() plugin:PowerOff() end),
MuteCommand = self:MakeToggleFunc(function() plugin:Mute() end, function() plugin:UnMute() end),
Controls = {
Balance = {Class = 'Balance', ID = 'Balance', Command = function(value) plugin:Balance(value) end},
Brightness = {Class = 'VerticalSlider', ID = 'Brightness', Command = function(value) plugin:Brightness(value) end},
Contrast = {Class = 'VerticalSlider', ID = 'Contrast', Command = function(value) plugin:Contrast(value) end},
Colour = {Class = 'VerticalSlider', ID = 'Colour', Command = function(value) plugin:Colour(value) end},
Sharpness = {Class = 'VerticalSlider', ID = 'Sharpness', Command = function(value) plugin:Sharpness(value) end},
ColourTemperature = {Class = 'TextSpin', ID = 'Colour temperature', Command = function(value) plugin:ColourTemperature(value) end, Values = plugin:GetColourTemps()},
Red = {Class = 'VerticalSlider', ID = 'Red', Command = function(value) plugin:AdjustRed(value) end, Values = {Min = -40, Max = 40}},
Green = {Class = 'VerticalSlider', ID = 'Green', Command = function(value) plugin:AdjustGreen(value) end, Values = {Min = -40, Max = 40}},
Blue = {Class = 'VerticalSlider', ID = 'Blue', Command = function(value) plugin:AdjustBlue(value) end, Values = {Min = -40, Max = 40}},
Keylock = {Class = 'Switch', ID = 'Keylock', Command = function(value) plugin:KeyLock(value) end},
}
}
}
return dt
end,
If you want to post the source of your plugin I or Mike will try to help.
harleydude
November 3rd, 2006, 10:04 AM
Balance = {Class = 'Balance', ID = 'Balance', Command = function(value) plugin:Balance(value) end},
Ok, in your example if I had an action that adjusted the Balance, the plugin:Balance(value) function will be called instead of the DeviceCommand() function I mentioned. Then the plugin:Balance(value) would perform the action and would report back the result via the self.Publisher:Event() routine and the DM will be notified of the new state. Is that correct?
Rob H
November 3rd, 2006, 10:46 AM
That's the idea, yes.
harleydude
November 3rd, 2006, 10:53 AM
Cool thanks. I just set it up and it works great. I will post the code once I clean it up a bit. I have some more questions but posting the code will help.
Rob H
November 3rd, 2006, 11:40 AM
Good news!
harleydude
November 3rd, 2006, 12:42 PM
One thing I noticed is that DM events only show up in the Logger and not in the Add Event dialog. Is this going to always be the case?
Rob H
November 3rd, 2006, 01:07 PM
Not sure - we don't currently have a mechanism in the DM to register the events, but we can look into that - good point. I'm not sure whether this will be possible since devices can come and go.
Personally, I never use the Add Event dialog, so I hadn't noticed this before.
rpalmer68
December 19th, 2006, 07:12 PM
Hi Folks,
I've just installed G5 and I'm afraid I'm totally confused with this Device Manager stuff!
I'm currently using the serial NEC Plasma plugin from the downloads area to control my plasma from G4, and I assume that this is not the way to do it now and I should be using DM somehow.
Rather than asking lots of questions at this point, maybe Rob H if you could email me all the required files to use your LGTV plugin and an indication of the folders they shoud go in then I should be able to work out how to convert the NEC plugin from this.
At this stage I just can't get my head around devices and providers and how to actually allocate the serial commands to send to the physical decice.
Maybe I'm missing something, is there in fact a Device, Provider and a plugin with the serial commands?
Anyway, I'm happy to play with something I know works to understand the mechanics of it, I just need somethig that works to start with!
Many thanks
Richard
richard_palmer(@)iprimus.com.au
Rob H
December 20th, 2006, 03:16 AM
You should find that you already have all the required files installed with G5 I think.
rpalmer68
December 20th, 2006, 04:09 AM
You should find that you already have all the required files installed with G5 I think.
Which then means I'm totally confused/lost.
You showed a part of the code from your LGTV plugin, so let's assume I have an LG TV as well, how do I get G5 to talk to my LGTV using the device manager? I can't find an LGTV.lua file or any reference to anything like this in the folders/setup.
Richard
Rob H
December 20th, 2006, 04:20 AM
In luascript\DeviceManager\Providers you should have an LGLCD.lua which is the provider for plugins\serial\LGTV.lua
rpalmer68
December 20th, 2006, 04:27 AM
In luascript\DeviceManager\Providers you should have an LGLCD.lua which is the provider for plugins\serial\LGTV.lua
These don't seem to come with the G5 install as I don't have either of them.
Richard
Rob H
December 20th, 2006, 04:37 AM
Ah, my apologies, I'd thought that Ron had included them in the install.
Here they are :-
rpalmer68
December 20th, 2006, 04:59 AM
Thanks,
Having looked at the LGTV.lua I'm not sure I'm going to be able to convert the NEC Plasma plugin as easiy as I hoped... anyway I'll work my way through and see what I discover!
Thanks
Richard
Rob H
December 20th, 2006, 06:49 AM
First thing is to make sure that your plugin has a Subscribe method and uses a Publisher to send notifications of changes rather than using gir.TriggerEvent.
If you have questions then please ask them.
rpalmer68
December 20th, 2006, 07:31 AM
First thing is to make sure that your plugin has a Subscribe method and uses a Publisher to send notifications of changes rather than using gir.TriggerEvent.
If you have questions then please ask them.
Thanks Rob, but I think this is gonig to be all too complicated for this little black duck.
I consider myself to be technical, but I'm not a programmer and this goes well beyond my programming ability (in fact the G4 serial plugins were beyond me!).
I was expecting the DM was going to simplify the process of adding devices but I think I may be wrong.
From what I can see, for pre-defined devices it will work well, like if I had an LGTV using your files looks easy, but to add an NEC Plasma with totally different commands is going to require a lot of coding by somebody.
I'll take another look tomorrow when I've had some sleep (12:30am here now) but I don't like my chances! And since I'm not a programmer I don't want to waste your time asking lots of questions.
Cheers
Richard
Rob H
December 20th, 2006, 08:39 PM
Upload your serial plugin here, and I'll see what I can do when I have some spare time
rpalmer68
December 20th, 2006, 09:05 PM
Thanks,
It's the one I got from the downloads area.
From what I can see your LGTV plugin caters for a lot of different models and thus has a lot of code to cover this, I think I need to look at something more simple to understand what's really needed.
Anyway, here's the plugin, any assistance is greatly appreciated!
regards
Richard
rpalmer68
December 28th, 2006, 03:04 PM
Hi Rob,
Have you had a chance to look at this?
If not (and I understand) is there a simple provider/device/plugin combination you can point me to or send me that I can work off to try to create my own?
Maybe one with just one model and one or two commands.
Cheers
Richard
Rob H
December 28th, 2006, 04:12 PM
I'm afraid I haven't had a chance to look at it yet, sorry.
I've attached the serial device and provider (PAX100.lua) for a Panasonic Projector that is relatively simple.
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.