Redcloud Remote Configuration For Multiple Remotes Via XML

Do you have questions about writing plugins or scripts in Python? Meet the coders here.
Post Reply
M7DNYTE
Posts: 6
Joined: Mon Jan 18, 2010 7:35 am

Redcloud Remote Configuration For Multiple Remotes Via XML

Post by M7DNYTE » Mon Jan 18, 2010 8:05 am

Here's the hardware that I am running:
Windows XP
EventGhost 0.3.7.r1366
Xbox hacked DVDIR remote receiver
Redcloud remote drivers

At first I was receiving 'Unknown Code' errors with my remotes (non xbox remotes), but I was able to get this working pretty basically after manually editing the 'xbcdrc_mapping' dictionary variable. Noticing that the plugin system here is built off of Python, I thought that it might be interesting to be able to define remote codes and event names via xml, so I created a testing file using this structure:
'
<xml>
<remote>
<name>XBox Remote</name>
<eventPrefix>TV</eventPrefix>
<buttons>
<button>
<event>UP</event>
<code>006a60a</code>
</button>
<button>
<event>DOWN</event>
<code>006a70a</code>
</button>
<button>
<event>LEFT</event>
<code>006a90a</code>
</button>
<button>
<event>RIGHT</event>
<code>006a80a</code>
</button>
<button>
<event>POWER</event>
<code>006d500</code>
</button>
</buttons>
</remote>
</xml>
'
I was able to append this xml to the xbcdrc_mapping using the following code in an external installation of Python (using Idle):
'
import xml.dom.minidom
xmlDoc=xml.dom.minidom.parse("buttonMap.xml") # Open the xml button map document
root=xmlDoc.childNodes[0]
remotes=root.childNodes
for remote in xmlDoc.getElementsByTagName('remote'): # Traverse each remote node
prefixNode=remote.getElementsByTagName('eventPrefix') # Retrieve remote's prefix to be used
prefix= prefixNode[0].childNodes[0].data # in the event name
for button in remote.getElementsByTagName('button'): # Traverse each remote's button
codeNode=button.getElementsByTagName('code') # Retrieve the event code
code=codeNode[0].firstChild.data
eventNode=button.getElementsByTagName('event') # Retrieve the event name
event=eventNode[0].firstChild.data
xbcdrc_mapping[str(code)]=str(prefix+'_'+event)
'

It seems as though there is a full installation of Python included, and EventGhost is using v2.6, which is the same version I am running Idle on... I'm probably doing something really stupid, probably in combination due to the fact that I just picked up python today, and it's near 3am, hahaha.

Could anyone assist me in this? I think I just only need to know how to include xml.dom.minidom properly. Being able to control all my media on my pc via universal remotes is so close I can practically taste it...

PS, thanks for all the hard work on EventGhost... Soooo much better than LIRC (even on linux) I had almost given up on being able to be able to control XBMC, etc in windows with my 5 dollar remote reciever... You guys are awesome!

*Edit*
Crap. Tabs were removed... I'll upload the files I was working with. I think that should be it. If anyone needs anything else, just let me know...
Attachments
__init__.py
XBCDRC plugin init.py
(29.23 KiB) Downloaded 244 times
workspace.py
The stand-alone version of what I was working with for testing
(3.12 KiB) Downloaded 212 times
buttonMap.xml
XML of remote buttons and events
(515 Bytes) Downloaded 204 times

User avatar
Bitmonster
Site Admin
Posts: 2239
Joined: Mon Feb 06, 2006 10:28 pm

Re: Redcloud Remote Configuration For Multiple Remotes Via XML

Post by Bitmonster » Mon Jan 18, 2010 8:37 am

Well, a little bit overengineered I would say.

Why not just modify the mapping with python directly?

Every plugin returns itself through eg.result after it is executed. So just place a PythonScript directly after the plugin in the Autostart macro and do something like this:

Code: Select all

xbcdrc_mapping = eg.result.thread.xbcdrc_mapping
xbcdrc_mapping['006a60a'] = 'UP'
xbcdrc_mapping['006a70a'] = 'DOWN'
....
Restart EG and your done.
Please post software-related questions in the forum - PMs will only be answered, if really private, thanks!

M7DNYTE
Posts: 6
Joined: Mon Jan 18, 2010 7:35 am

Re: Redcloud Remote Configuration For Multiple Remotes Via XML

Post by M7DNYTE » Mon Jan 18, 2010 4:26 pm

Yeah, it is over engineered, if what I wanted to do was just for me ( I already got 1/3 of my remote working by editing the actual plugin)...
Honestly, the end result of this project was to create a script that I could run and generate codes and events for any remote I came across... It would be sort of be like lirc's functionality (irrecord ) for defining them ...

I think this might be easier for some people who have IR remotes and aren't good enough to really edit python scripts or, even XML... Or, even people who are too lazy and don't want to type them all out hahaha...

I thought I'd take it in baby steps this time, so I only put in my initial question...

Good to know about that other little feature, though... I think I might just create that secondary script in the autostart macro... might make things easier to read and such for now...

M7DNYTE
Posts: 6
Joined: Mon Jan 18, 2010 7:35 am

Re: Redcloud Remote Configuration For Multiple Remotes Via XML

Post by M7DNYTE » Wed Jan 20, 2010 12:01 am

So, I was able to get the xml stuff working with just a python script plugin as previously mentioned. I attached the script text in a text file if anyone else wants it.

A question, though: why can I import xml.dom.minidom in the eventghost python script action, but not in the actual plugin code?

Another idea floating around in the ol' noggin:
Lets say that on the particular error of an unrecognized code being recieved by the remote, I wanted a plugin to pop up a window that would allow me to set a name to that particular code and insert it into the xml button definition.
Would it be possible to have a plugin read ( sorta like 'tail -f') in errors from the log? Or, would there be some better way for me to go about this?
Attachments
remote_forum.txt
Text file containing the script
(1.12 KiB) Downloaded 205 times

stottle
Plugin Developer
Posts: 636
Joined: Sun Apr 26, 2009 10:59 pm

Re: Redcloud Remote Configuration For Multiple Remotes Via XML

Post by stottle » Wed Jan 20, 2010 1:13 am

One problem with catching unknowns is that many receivers collect signals not intended for the computer. These junk codes are harmlessly ignored, and I wouldn't want a pop-up for each one.

If that isn't your situation, the easiest thing to do is probably have a macro that catches Unknown remote events.

Brett

M7DNYTE
Posts: 6
Joined: Mon Jan 18, 2010 7:35 am

Re: Redcloud Remote Configuration For Multiple Remotes Via XML

Post by M7DNYTE » Wed Jan 20, 2010 8:47 am

So, yeah, I think that automatic entering of unknown codes would be good in my case, as it is a remote trainer functionality. Therefore, it wouldn't be on all of the time, and can be disabled when you don't want to have the popups or whatever. I actually did get a version working that gets the job done for me, at least. I ended up having to edit the redcloud plugin to add a trigger on the event of unknown codes, and sent the code value as the event payload. Then, had a macro that was triggered by the event that would add a new event to the xml, where the name of the event was set to the event code. After this, the autostart macro is run again, and the xml data is loaded, so no duplicate events are registered.

Like I said, I just got this working sort of hackishly for now. I'll make it better and stuff on my own time (which could be a lil bit) and post it, but if anyone else wants this, it will give me initiative, and I'll make it a priority to finalize it.

All in all, yeah, I think the trainer functionality is pretty nifty. Didn't have to enter anything, just pressed buttons on my remote, and event codes were automatically generated for use with my remote.

I would still like to know how to get xml imported in the plugin python file, though. I think that it could be a nifty addition to redcloud's plugin... But I can't write that functionality till I figure that out ( and some other things in plugin development... )

User avatar
jinxdone
Plugin Developer
Posts: 443
Joined: Tue Jan 02, 2007 4:08 pm

Re: Redcloud Remote Configuration For Multiple Remotes Via XML

Post by jinxdone » Wed Jan 20, 2010 11:03 am

Actually, I was also planning on adding a learning mode for unknown codes to the xbcdrc remote plugin. And well, I havn't gotten around to it.

I was thinking I should make the learn mode add the new codes to a xbcdrc_learnt array, which would be used like the xbcdrc_mapping array. Also somewhere in the learn mode window I was going to add a link to the xbcdrc plugin's thread so an user could easily report his xbcdrc_learnt array so I could add the new codes to the plugin's xbcdrc_mapping array in the SVN.

Anyway, it sounds very much like what you are doing, minus the XML. I guess yours could be used for a more general purpose storing of code -> name mappings. Keep up the good work. :)

stottle
Plugin Developer
Posts: 636
Joined: Sun Apr 26, 2009 10:59 pm

Re: Redcloud Remote Configuration For Multiple Remotes Via XML

Post by stottle » Wed Jan 20, 2010 3:28 pm

M7DNYTE wrote:A question, though: why can I import xml.dom.minidom in the eventghost python script action, but not in the actual plugin code?
Is there some sort of error? Usually python is smart enough to find modules. I know Bitmonster plays some tricks to make it easier to load plugins, but I would still expect this to work. What happens in the shell (PyCrust) if you try the import?

Brett

M7DNYTE
Posts: 6
Joined: Mon Jan 18, 2010 7:35 am

Re: Redcloud Remote Configuration For Multiple Remotes Via XML

Post by M7DNYTE » Wed Feb 17, 2010 3:35 am

stottle wrote: Is there some sort of error? Usually python is smart enough to find modules. I know Bitmonster plays some tricks to make it easier to load plugins, but I would still expect this to work. What happens in the shell (PyCrust) if you try the import?
Huh... Quite strange. Now it seems to work fine. Before, the plugin would just fail and not run. Guess that's what happens when you're learning... I just tried the import, but had just been updating what code I already had written, just to give an update of something a little better (some basic error handling, etc) if anyone was really following this. I'll have to try to do more at a later date. Yeah, I'll probably chug along slowly but surely on this one; hopefully more frequent than the last update, haha.

Also, I know that the "xml" used isn't really standard... That will come next...
Also, if anyone is out there, let me know if there's a simpler way of doing the crazy things that I am trying... Still new to this whole python thing...

But, here goes...
Attachments
__init__.py
My version of the redcl0ud plugin. Unknown code received generates an event with a payload of the unknown code.
(29.18 KiB) Downloaded 224 times
RemoteLearning.xml
Remote Learning Saved Event Ghost State. This has the learning script, and also the code reading script.
(22.76 KiB) Downloaded 196 times
buttonMap.xml
My Generated Buttonmap.xml file. This can be placed in the eventghost instalation directory, or will be created automatically if not found.
(4.94 KiB) Downloaded 200 times

Post Reply