PDA

View Full Version : How to manage states....



Billmans
February 20th, 2006, 08:04 AM
I am looking to set up a system for my HT. I have worked with basic Girder 3.3 stuff before.

Currently I have learned all my remote key presses using an Ocelot and the plugin is working in Girder 4. I am Sending IR to all my components using the ocelot. I am using a ira-3 for recieving the ir from a Microsoft Media Center remote control, The ira-3 is using the built in plugin as the one from home-electro does not work, (starts up fine, but as soon as I push a button on the remote, girder crashes, memory exception).

So the basics are working....

What I would like to do is not add some logic to this. For example.

When I push "TV" on the remote I want to send a power to the amp,tv,cable box etc. Then when I hit "RADIO" I want to send a power to the tv,cable box to turn off, and tell the amp to turn to tuner. (this I can do). But now if I hit TV again, it sends the power to amp,tv,cable box and now my amp is off, tv on, and cable box on.

I have looked and can not find any distinct codes for my gear so I need to some how store the state of the item.

So I assume that I am going to have to script this with LUA, but I am not sure how to start. Can somebody give me a idea, even code hints to start this off. I just need one basic example how to handle my example above and I should be able to run with that. Just not sure what is the best approach and I don't want to get to complicated unless I have to. I am sure this has been done before, so any input would be greatly appreciated.

Sorry for the long-winded post........

quixote
February 20th, 2006, 08:15 AM
I can give you a thorough explanation with code when I get home from work later this evening. I had the same problem, but I've got it all worked out thanks to a lot of help from the good folks on this forum.

quixote
February 20th, 2006, 03:16 PM
Here is the code that I use for TV power toggle. I have this script activate in a macro with my TV power IR code from the USB-UIRT.



if TVpower == tonumber (0) then TVpower = (1)
elseif TVpower == tonumber (1) then TVpower = (0)
end

r = win.RegSetIntValue ("HKEY_LOCAL_MACHINE", "Software\\Promixis\\Girder\\4\\","TVpower", (TVpower))
if not r then
print ("Error setting int value")
end

TVpowerTEXT = TVpowerTEXT or 0
if TVpower == (0) then TVpowerTEXT = tostring "OFF"
elseif TVpower == (1) then TVpowerTEXT = tostring "ON"
end

r = win.RegSetStringValue ("HKEY_LOCAL_MACHINE", "Software\\Promixis\\Girder\\4\\","TVpowerTEXT", (TVpowerTEXT))
if not r then
print ("Error setting int value")
end

This will set variables for TVpower and TVpowerTEXT. The latter is solely for the purpose of creating an OSD to show me whether Girder thinks the TV is on or off. It also writes the values to the registry. This way you can check the TV power status when you restart Girder. You can do that by creating a script action that fires on startup like this:


TVpower = TVpower or 0
TVpower = win.RegGetIntValue("HKEY_LOCAL_MACHINE", "Software\\Promixis\\Girder\\4\\","TVpower")
if not TVpower then
TVpower = 0
end


This way of saving the variables is extremely useful. I use this method for all of my lights and even what input my TV is currently using.

After you have set the variable you can do all sorts of cool stuff. An example would be what you're trying to do. For the sake of simplicity, let's just say that you want a button to do something based on whether or not the TV is on, lets say a Girder event that you've named 'TVPowerButton' -
you would create a script like this:



if TVpower == tonumber (0) then gir.TriggerEvent('TVPowerButton',18)
end


So that would fire the TVPowerButton event only if the TV is off.

Let me know if I wasn't clear enough.

Billmans
February 22nd, 2006, 07:19 PM
I think I understand how this is working and successfully tested most of it.

I am a little confused how to use the following command....

gir.TriggerEvent('TVPowerButton',18)

I created and ocelot event to send the IR to my TV, in the tree I called it TVPowerButton as in your example above. In the tree macro I recieve the IR input from my ira-3, I have the script attached to the tree which seems to execute, but the IR send does not happen. If I test the IR event with F5, it works fine.

I have read in another post about GUID's do I need to use this instead of the name TVPowerButton, if so I am at a loss on how to find this value.

Thanks again for you help.

Rob H
February 22nd, 2006, 11:59 PM
If you open the logger you should see the TVPowerButton event - just drag it from there to your IR send action in your GML.

quixote
February 23rd, 2006, 04:56 AM
I think I understand how this is working and successfully tested most of it.

I am a little confused how to use the following command....

gir.TriggerEvent('TVPowerButton',18)

I created and ocelot event to send the IR to my TV, in the tree I called it TVPowerButton as in your example above. In the tree macro I recieve the IR input from my ira-3, I have the script attached to the tree which seems to execute, but the IR send does not happen. If I test the IR event with F5, it works fine.

I have read in another post about GUID's do I need to use this instead of the name TVPowerButton, if so I am at a loss on how to find this value.

Thanks again for you help.

You can also add an event to your macro, then right click on it and select edit. There is a drop-down box at the top where you can select different sources for the event. Select "Girder Event" and then type in the name of the event in the second box. It's case sensitive, so be sure you match the name exactly as you typed it in your script. Hit ok and that's it.