<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>

<channel>
	<title>about:benjie</title>
	<atom:link href="http://www.benjiegillam.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.benjiegillam.com</link>
	<description>Benjie Gillam's blog, and home of MythPyWii - probably the best Wii remote (Wiimote) interface to MythTV - see sidebar.</description>
	<pubDate>Thu, 18 Sep 2008 19:19:21 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.2</generator>
	<language>en</language>
			<item>
		<title>MythPyWii Bugfixes and Enhancements</title>
		<link>http://www.benjiegillam.com/2008/09/mythpywii-bugfixes-and-enhancements/</link>
		<comments>http://www.benjiegillam.com/2008/09/mythpywii-bugfixes-and-enhancements/#comments</comments>
		<pubDate>Thu, 18 Sep 2008 19:17:52 +0000</pubDate>
		<dc:creator>Benjie</dc:creator>
		
		<category><![CDATA[Code]]></category>

		<category><![CDATA[Linux]]></category>

		<category><![CDATA[MythPyWii]]></category>

		<category><![CDATA[MythTV]]></category>

		<category><![CDATA[bugfixes]]></category>

		<category><![CDATA[timestretch]]></category>

		<guid isPermaLink="false">http://www.benjiegillam.com/?p=157</guid>
		<description><![CDATA[

I&#8217;ve just updated MythPyWii to handle the connection to Mythfrontend more smoothly, and to give feedback via the wiimote on error/disconnect. (i.e. if myth closes, the wiimote shakes, and the LED pattern changes to [ . # # . ] instead of [ # . . # ] just before the wiimote turns itself off). [...]]]></description>
			<content:encoded><![CDATA[<div class="zemanta-img zemanta-action-click">
<div class="wp-caption alignright" style="width: 250px"><a href="http://www.flickr.com/photos/16419724@N00/282707058"><img title="Software Bugs" src="http://farm1.static.flickr.com/113/282707058_02305d3cce_m.jpg" alt="Software Bugs" height="211" width="240"></a><p class="wp-caption-text">Image by FastJack via Flickr</p></div>
</div>
<p>I&#8217;ve just updated MythPyWii to handle the connection to Mythfrontend more smoothly, and to give feedback via the wiimote on error/disconnect. (i.e. if myth closes, the wiimote shakes, and the LED pattern changes to [ . # # . ] instead of [ # . . # ] just before the wiimote turns itself off). This means if there are issues connecting to Mythfrontend you can retry again simply by pressing 1&amp;2 once more (fix any issues first though - e.g. closed mythfrontend/no remote interface enabled).</p>
<p>I&#8217;ve fixed a little bug with timestretching, and have also improved the timestretch responsiveness by emulating not just the left/right keys but also the up/down keys (which increase/decrease timestretch by 0.25 instead of just 0.05).</p>
<p>As always, download the latest version of MythPyWii <a href="http://www.benjiegillam.com/mythpywii-installation/">here</a>.</p>
<p>Ah hah, an update to <a class="zem_slink" title="Zemanta" rel="homepage" href="http://www.zemanta.com">Zemanta</a> has just been released! Integration with Facebook and Flickr, eh? I best sign up for a Flickr account then, I suppose&#8230; Argh! They seem to have broken images with my theme - I fixed it by adding this CSS to my theme (copied from firebug):</p>
<p><code class="source">
.alignright {
  float:right;
}

.wp-caption {
  -moz-border-radius-bottomleft:3px;
  -moz-border-radius-bottomright:3px;
  -moz-border-radius-topleft:3px;
  -moz-border-radius-topright:3px;
  background-color:#F3F3F3;
  border:1px solid #DDDDDD;
  margin:10px;
  padding-top:4px;
  text-align:center;
}
</code>
</p>
<h6 class="zemanta-related-title" style="font-size: 1em;">Related articles by Zemanta</h6>
<ul class="zemanta-article-ul">
<li class="zemanta-article-ul-li"><a href="http://www.zemanta.com/blog/new-release-my-friends-my-flickr-and-filter/">New release: My Friends, My Flickr and Filter</a></li>
<li class="zemanta-article-ul-li"><a href="http://blogs.talis.com/nodalities/2008/09/zemanta-gets-personal.php">Zemanta gets personal</a></li>
<li class="zemanta-article-ul-li"><a href="http://www.readwriteweb.com/archives/zemanta_releases_major_upgrade.php">Zemanta Releases Major Upgrade - Now It&#8217;s All About You</a></li>
</ul>
<div style="margin-top: 10px; height: 15px;" class="zemanta-pixie"><a class="zemanta-pixie-a" href="http://reblog.zemanta.com/zemified/0bc437ae-68b8-4224-93a6-1ff26b41280f/" title="Zemified by Zemanta"><img style="border: medium none ; float: right;" class="zemanta-pixie-img" src="http://img.zemanta.com/reblog_c.png?x-id=0bc437ae-68b8-4224-93a6-1ff26b41280f" alt="Reblog this post [with Zemanta]"></a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.benjiegillam.com/2008/09/mythpywii-bugfixes-and-enhancements/feed/</wfw:commentRss>
		</item>
		<item>
		<title>New (Minor) MythPyWii Release (r15)</title>
		<link>http://www.benjiegillam.com/2008/09/new-minor-mythpywii-release-r15/</link>
		<comments>http://www.benjiegillam.com/2008/09/new-minor-mythpywii-release-r15/#comments</comments>
		<pubDate>Thu, 18 Sep 2008 08:08:45 +0000</pubDate>
		<dc:creator>Benjie</dc:creator>
		
		<category><![CDATA[Code]]></category>

		<category><![CDATA[Computers]]></category>

		<category><![CDATA[Hardware]]></category>

		<category><![CDATA[Linux]]></category>

		<category><![CDATA[MythPyWii]]></category>

		<category><![CDATA[MythTV]]></category>

		<category><![CDATA[documentation]]></category>

		<category><![CDATA[error handling]]></category>

		<category><![CDATA[feedback]]></category>

		<guid isPermaLink="false">http://www.benjiegillam.com/?p=150</guid>
		<description><![CDATA[Image via Wikipedia 
Thanks to a heads up from Sam, I have updated the MythPyWii script with better error handling and more informative feedback messages. Hopefully now when you run the script you will know what to do! I&#8217;ve also fixed a few minor bugs in the documentation.
As always, you can download the latest version [...]]]></description>
			<content:encoded><![CDATA[<div class="zemanta-img" style="margin: 1em; float: right; display: block;"><a href="http://commons.wikipedia.org/wiki/Image:Bash_screenshot.png"><img style="border: medium none; display: block;" src="http://upload.wikimedia.org/wikipedia/commons/thumb/e/e7/Bash_screenshot.png/202px-Bash_screenshot.png" alt="Screenshot of a sample Bash session, taken on ..." /></a><span class="zemanta-img-attribution">Image via <a href="http://commons.wikipedia.org/wiki/Image:Bash_screenshot.png">Wikipedia</a> </span></div>
<p>Thanks to a heads up from Sam, I have updated the MythPyWii script with better error handling and more informative feedback messages. Hopefully now when you run the script you will know what to do! I&#8217;ve also fixed a few minor bugs in the documentation.</p>
<p>As always, you can download the latest version of MythPyWii <a title="MythPyWii latest version download and instructions" href="http://www.benjiegillam.com/mythpywii-installation/">here</a>.</p>
<p>I should probably make a GUI for MythPyWii at some point&#8230; though it seems a little pointless at the moment. I could allow you to change the controls to your liking, I spose&#8230;</p>
<h6 class="zemanta-related-title" style="font-size: 1em;">Related articles by Zemanta</h6>
<ul class="zemanta-article-ul">
<li class="zemanta-article-ul-li"><a href="http://www.linux.com/feature/145949">Dress up your Python scripts with EasyGui</a></li>
</ul>
<div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><a class="zemanta-pixie-a" title="Zemified by Zemanta" href="http://reblog.zemanta.com/zemified/d1f120f3-1241-4782-8e54-da95a0d5b147/"><img class="zemanta-pixie-img" style="border: medium none; float: right;" src="http://img.zemanta.com/reblog_e.png?x-id=d1f120f3-1241-4782-8e54-da95a0d5b147" alt="Reblog this post [with Zemanta]" /></a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.benjiegillam.com/2008/09/new-minor-mythpywii-release-r15/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Dara O&#8217;Briain Quote - Night Person</title>
		<link>http://www.benjiegillam.com/2008/09/dara-obriain-quote-night-person/</link>
		<comments>http://www.benjiegillam.com/2008/09/dara-obriain-quote-night-person/#comments</comments>
		<pubDate>Tue, 16 Sep 2008 08:51:04 +0000</pubDate>
		<dc:creator>Benjie</dc:creator>
		
		<category><![CDATA[Personal]]></category>

		<category><![CDATA[Dara O'Briain]]></category>

		<category><![CDATA[Day person]]></category>

		<category><![CDATA[Night person]]></category>

		<category><![CDATA[Quote]]></category>

		<guid isPermaLink="false">http://www.benjiegillam.com/?p=146</guid>
		<description><![CDATA[Image via Wikipedia 
I have no ID card, passport, drivers license, that will say, for example, I&#8217;m a &#8220;night person&#8221;. I don&#8217;t do daylight, I don&#8217;t trust daylight, I don&#8217;t like it. Many of you are day people, you&#8217;re fine with it. Grand! If you&#8217;re a day person, night-time leaves you alone. But if you&#8217;re [...]]]></description>
			<content:encoded><![CDATA[<div class="zemanta-img" style="margin: 1em; float: right; display: block;"><a href="http://commons.wikipedia.org/wiki/Image:Dara_%C3%93_Briain.jpg"><img style="border: medium none; display: block;" src="http://upload.wikimedia.org/wikipedia/commons/thumb/f/f1/Dara_%C3%93_Briain.jpg/202px-Dara_%C3%93_Briain.jpg" alt="Dublin, Ireland: Dara Ó Briain." /></a><span class="zemanta-img-attribution">Image via <a href="http://commons.wikipedia.org/wiki/Image:Dara_%C3%93_Briain.jpg">Wikipedia</a> </span></div>
<blockquote><p><em>I have no ID card, passport, drivers license, that will say, for example, I&#8217;m a &#8220;night person&#8221;. I don&#8217;t do daylight, I don&#8217;t trust daylight, I don&#8217;t like it. Many of you are day people, you&#8217;re fine with it. Grand! If you&#8217;re a day person, night-time leaves you alone. But if you&#8217;re a night person, daylight has no such qualms. Daylight will climb underneath the curtains, bounce off the carpet, off the ceiling, off the carpet, off the ceiling into your fecking eyes and wake you up.</em></p>
<p style="text-align: right;">&#8211; Dara O&#8217;Briain<br />
(Live from the Theatre Royal)</p></blockquote>
<p>Dara, me old pal, you&#8217;ve got it spot on there. [Ali-G style, making "N" with fingers] Night-time iz de bezt! [/Ali-G]</p>
<p>I have to work during the day because thats when all the people I communicate with are working! However, I do it from home, with the blinds and curtains shut, and often with the light off too, basking in the light of my LCD monitor, with brightness as low as it will go. Daylight makes me screw my eyes up, forces me to shut one eye, and makes me generally look as if I am in pain. Which I am&#8230; strong daylight physically hurts my eyes. For proof of my anguish all you have to do is ask me to keep my eyes open for a photo in bright sunlight. You&#8217;ll see me struggle and fail to do so - and even if I do succeed, the photo looks horrible because the rest of my face is contorted with the effort of keeping both eyes open at once. At night time, or in the dark, no such problem, and my eyes work great together. Just not during the day.</p>
<p>If only it was easier to sleep when it is light outside&#8230;</p>
<h6 class="zemanta-related-title" style="font-size: 1em;">Related articles by Zemanta</h6>
<ul class="zemanta-article-ul">
<li class="zemanta-article-ul-li"><a href="http://www.telegraph.co.uk/news/main.jhtml?xml=/news/2008/01/28/npolice228.xml">Leaked memos reveal &#8216;confusing&#8217; ID card plans</a></li>
<li class="zemanta-article-ul-li"><a href="http://www.theregister.co.uk/2008/01/28/ips_coercive_driving_scheme/">&#8216;Coercion&#8217; plan to force ID cards on first time drivers</a></li>
</ul>
<div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><a class="zemanta-pixie-a" title="Zemified by Zemanta" href="http://reblog.zemanta.com/zemified/bdb6ae61-a5b3-4469-9989-6a7463822342/"><img class="zemanta-pixie-img" style="border: medium none; float: right;" src="http://img.zemanta.com/reblog_c.png?x-id=bdb6ae61-a5b3-4469-9989-6a7463822342" alt="Reblog this post [with Zemanta]" /></a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.benjiegillam.com/2008/09/dara-obriain-quote-night-person/feed/</wfw:commentRss>
		</item>
		<item>
		<title>MythPyWii Video</title>
		<link>http://www.benjiegillam.com/2008/09/mythpywii-video/</link>
		<comments>http://www.benjiegillam.com/2008/09/mythpywii-video/#comments</comments>
		<pubDate>Fri, 12 Sep 2008 22:26:39 +0000</pubDate>
		<dc:creator>Benjie</dc:creator>
		
		<category><![CDATA[Computers]]></category>

		<category><![CDATA[Hardware]]></category>

		<category><![CDATA[Linux]]></category>

		<category><![CDATA[MythPyWii]]></category>

		<category><![CDATA[MythTV]]></category>

		<category><![CDATA[Controls]]></category>

		<category><![CDATA[Instructions]]></category>

		<category><![CDATA[Video]]></category>

		<category><![CDATA[Video editing]]></category>

		<guid isPermaLink="false">http://www.benjiegillam.com/?p=136</guid>
		<description><![CDATA[Here&#8217;s the short version:

Despite having got up at 3:30am this morning and being extremely tired, it&#8217;s been quite a good day. I finished setting up the media centre, hooked it up to the TV and got it working, sound and all. It seems the PC doesn&#8217;t run video smoothly at 1080p (not suprisingly, it was [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s the short version:</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="350" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="http://www.youtube.com/v/Fx8uoTlZXF0" /><embed type="application/x-shockwave-flash" width="425" height="350" src="http://www.youtube.com/v/Fx8uoTlZXF0"></embed></object></p>
<p>Despite having got up at 3:30am this morning and being extremely tired, it&#8217;s been quite a good day. I finished setting up the media centre, hooked it up to the TV and got it working, sound and all. It seems the PC doesn&#8217;t run video smoothly at 1080p (not suprisingly, it was bought a good few years ago on a budget, it&#8217;s an onboard graphics card too!) - but that&#8217;s OK. I dropped it down to ~720p and it seems to run great.</p>
<p>It&#8217;s completely diskless, it&#8217;s only purpose being to play MythTV videos from my main mythbackend. It might find itself playing some DVDs at some point also, we&#8217;ll see.</p>
<p>I installed <a title="MythPyWii is a wiimote interface to MythTV" href="http://www.benjiegillam.com/2008/09/mythpywii-a-wiimote-interface-to-mythtv-using-python/" target="_blank">MythPyWii</a> on it, using my new MythPyWii Install Instructions, which I wrote today and you can <a title="MythPyWii Installation Instructions Ubuntu" href="http://www.benjiegillam.com/mythpywii-installation/" target="_blank">find here</a>. (I also made a page detailing the controls, <a title="MythPyWii Controls" href="http://www.benjiegillam.com/mythpywii-2-controls/" target="_blank">here</a>. Both links can also be found in my sidebar.) Everything went smoothly, so I made the video I had been promising. This is my first time *ever* doing any video editing, and this video was all filmed in one take with no rehersals, so please bear with me! The longer version is better if you need help during the install/etc, and is linked to on the instructions page.</p>
<p>Here goes, I know it&#8217;s a bit long&#8230; perhaps I will make a scripted version sometime which is shorter:</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="350" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="http://www.youtube.com/v/fqacVgG394I" /><embed type="application/x-shockwave-flash" width="425" height="350" src="http://www.youtube.com/v/fqacVgG394I"></embed></object></p>
<p>For anyone wondering, I used &#8220;Kino&#8221; to edit the video. It&#8217;s OK, took me a little while to figure it out. &#8220;Add text to&#8221; is a filter under FX called &#8220;Tilter&#8221; - Text fILTER, I guess&#8230; How intuitive&#8230; <img src='http://www.benjiegillam.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.benjiegillam.com/2008/09/mythpywii-video/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Zombie MythPyWii Update</title>
		<link>http://www.benjiegillam.com/2008/09/zombie-mythpywii-update/</link>
		<comments>http://www.benjiegillam.com/2008/09/zombie-mythpywii-update/#comments</comments>
		<pubDate>Fri, 12 Sep 2008 03:37:33 +0000</pubDate>
		<dc:creator>Benjie</dc:creator>
		
		<category><![CDATA[Code]]></category>

		<category><![CDATA[Computers]]></category>

		<category><![CDATA[Hardware]]></category>

		<category><![CDATA[Linux]]></category>

		<category><![CDATA[MythPyWii]]></category>

		<category><![CDATA[MythTV]]></category>

		<category><![CDATA[Diskless Booting]]></category>

		<category><![CDATA[OhSoTired]]></category>

		<category><![CDATA[Python]]></category>

		<category><![CDATA[Wiimote]]></category>

		<guid isPermaLink="false">http://www.benjiegillam.com/?p=119</guid>
		<description><![CDATA[I can&#8217;t sleep, so I thought it would be wise to give you an update on my previous post about MythPyWii, despite feeling a bit like the living dead must feel. (And having to frequently remove Artie from the keyboard, bless her.)
Unfortunately I have not been able to get a video of MythPyWii yet because [...]]]></description>
			<content:encoded><![CDATA[<p>I can&#8217;t sleep, so I thought it would be wise to give you an update on my <a title="MythPyWii is born" href="http://www.benjiegillam.com/2008/09/mythpywii-a-wiimote-interface-to-mythtv-using-python/" target="_blank">previous post about MythPyWii</a>, despite feeling a bit like the <a title="Wikipedia Zombie Article" href="http://en.wikipedia.org/wiki/Zombie" target="_blank">living dead</a> must feel. (And having to frequently remove Artie from the keyboard, bless her.)</p>
<p>Unfortunately I have not been able to get a video of MythPyWii yet because - minor technical hitch - I can&#8217;t find a VGA cable to connect my PC to my TV! (Wanted to show off the TV at the same time, it&#8217;s a good excuse!) I have, however, set up completely <a title="Diskless Mythbuntu Installation Instructions" href="https://help.ubuntu.com/community/MythTV/Install/Hardy/Diskless" target="_blank">diskless booting</a> on the old PC - and it&#8217;s working great! Took me a little bit of hacking (2 hours) to get it working well with my setup mind, not bad for my first ever diskless box! Hopefully it gives me a chance to outline every required piece of software on mythbuntu too. <img src='http://www.benjiegillam.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I&#8217;ve also been hacking away at MythPyWii, it now has the following improvements:</p>
<ul>
<li>Button repeats are sensible (if you hold &#8220;up&#8221;, it will simulate pressing up, pause 0.5 seconds, and then repeat every 0.15 seconds)</li>
<li>Manually repeating a button works better (previously we ignored any button press 0.5s after the previous one. Now, instead, we reset the delay every time a different key is pressed/released on the Wiimote, so you can tap up as fast as you want (and as fast as mythfrontend can handle))</li>
<li>Slowmo/doubletime - I&#8217;ve added time stretching. To activate, hold the wiimote flat, hold B and A together, and then twist, as with fast forwarding. When you let go, myth will be left in slowmo, if this is not what you want, adjust timestretch to 1x using the same method! Enjoy!</li>
<li>Fractionally tidier code. This is a mess already (as you would expect for a first attempt at a programming language) - if anyone out there rocks at Python, any tips would be appreciated!</li>
</ul>
<p>Here&#8217;s the latest code:</p>
<p><code class="source">
<span class="enscript-comment">#!/usr/bin/env python
</span><span class="enscript-string">&quot;&quot;&quot;
Copyright (c) 2008, Benjie Gillam
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
    * Neither the name of MythPyWii nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &quot;AS IS&quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
&quot;&quot;&quot;</span>
<span class="enscript-comment"># By Benjie Gillam http://www.benjiegillam.com/mythpywii/
</span>
<span class="enscript-keyword">import</span> cwiid, time, StringIO, sys, asyncore, socket
<span class="enscript-keyword">from</span> math <span class="enscript-keyword">import</span> log, floor, atan, sqrt, cos, exp

<span class="enscript-comment"># Note to self - list of good documentation:
</span><span class="enscript-comment"># cwiid: http://flx.proyectoanonimo.com/proyectos/cwiid/
</span><span class="enscript-comment"># myth telnet: http://www.mythtv.org/wiki/index.php/Telnet_socket
</span>
<span class="enscript-keyword">def</span> <span class="enscript-function-name">do_scale</span>(input, max, divisor=None):
	<span class="enscript-keyword">if</span> divisor <span class="enscript-keyword">is</span> None: divisor = max
	<span class="enscript-keyword">if</span> (input &gt; 1): input = 1
	<span class="enscript-keyword">if</span> (input &lt; -1): input = -1
	input = int(input * divisor)
	<span class="enscript-keyword">if</span> input&gt;max: input = max
	<span class="enscript-keyword">elif</span> input &lt; -max: input = -max
	<span class="enscript-keyword">return</span> input


<span class="enscript-keyword">class</span> MythSocket(asyncore.dispatcher):
	firstData = True
	data = <span class="enscript-string">&quot;&quot;</span>
	prompt=<span class="enscript-string">&quot;\n# &quot;</span>
	owner = None
	buffer = <span class="enscript-string">&quot;&quot;</span>
	callbacks = []
	oktosend = True
	<span class="enscript-keyword">def</span> <span class="enscript-function-name">__init__</span>(self, owner):
		self.owner = owner
		asyncore.dispatcher.__init__(self)
		self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
		self.connect((<span class="enscript-string">&quot;localhost&quot;</span>, 6546))
	<span class="enscript-keyword">def</span> <span class="enscript-function-name">handle_connect</span>(self):
		<span class="enscript-keyword">print</span> <span class="enscript-string">&quot;Connected&quot;</span>
	<span class="enscript-keyword">def</span> <span class="enscript-function-name">handle_close</span>(self):
		<span class="enscript-keyword">print</span> <span class="enscript-string">&quot;Closed&quot;</span>
		self.close()
	<span class="enscript-keyword">def</span> <span class="enscript-function-name">handle_read</span>(self):
		self.data = self.data + self.recv(8192)
		<span class="enscript-keyword">while</span> len(self.data)&gt;0:
			a = self.data.find(self.prompt)
			<span class="enscript-keyword">if</span> a&gt;-1:
				self.oktosend = True
				result = self.data[:a]
				self.data = self.data[a+len(self.prompt):]
				<span class="enscript-keyword">if</span> <span class="enscript-keyword">not</span> self.firstData:
					<span class="enscript-keyword">print</span> <span class="enscript-string">&quot;&lt;&lt;&lt;&quot;</span>, result
					cb = self.callbacks.pop(0)
					<span class="enscript-keyword">if</span> cb:
						cb(result)
				<span class="enscript-keyword">else</span>:
					<span class="enscript-keyword">print</span> <span class="enscript-string">&quot;Logged in to MythFrontend&quot;</span>
					self.firstData = False
			<span class="enscript-keyword">else</span>:
				<span class="enscript-keyword">break</span>;
	<span class="enscript-keyword">def</span> <span class="enscript-function-name">writable</span>(self):
		<span class="enscript-keyword">return</span> (self.oktosend) <span class="enscript-keyword">and</span> (len(self.buffer) &gt; 0) <span class="enscript-keyword">and</span> (self.buffer.find(<span class="enscript-string">&quot;\n&quot;</span>) &gt; 0)
	<span class="enscript-keyword">def</span> <span class="enscript-function-name">handle_write</span>(self):
		a = self.buffer.find(<span class="enscript-string">&quot;\n&quot;</span>)
		sent = self.send(self.buffer[:a+1])
		<span class="enscript-keyword">print</span> <span class="enscript-string">&quot;&gt;&gt;&gt;&quot;</span>, self.buffer[:sent-1]
		self.buffer = self.buffer[sent:]
		self.oktosend = False
	<span class="enscript-keyword">def</span> <span class="enscript-function-name">cmd</span>(self, data, cb = None):
		self.buffer += data + <span class="enscript-string">&quot;\n&quot;</span>
		self.callbacks.append(cb)
	<span class="enscript-keyword">def</span> <span class="enscript-function-name">raw</span>(self, data):
		cmds = data.split(<span class="enscript-string">&quot;\n&quot;</span>)
		<span class="enscript-keyword">for</span> cmd <span class="enscript-keyword">in</span> cmds:
			<span class="enscript-keyword">if</span> len(cmd.strip())&gt;0:
				self.cmd(cmd)
	<span class="enscript-keyword">def</span> <span class="enscript-function-name">ok</span>(self):
		<span class="enscript-keyword">return</span> len(self.callbacks) == len(self.buffer) == 0


<span class="enscript-keyword">class</span> WiiMyth:
	wii_calibration = False
	wm = None
	ms = None
	wii_calibration = None
	<span class="enscript-comment">#Initialize variables
</span>	reportvals = {<span class="enscript-string">&quot;accel&quot;</span>:cwiid.RPT_ACC, <span class="enscript-string">&quot;button&quot;</span>:cwiid.RPT_BTN, <span class="enscript-string">&quot;ext&quot;</span>:cwiid.RPT_EXT,  <span class="enscript-string">&quot;status&quot;</span>:cwiid.RPT_STATUS}
	report={<span class="enscript-string">&quot;accel&quot;</span>:True, <span class="enscript-string">&quot;button&quot;</span>:True}
	state = {<span class="enscript-string">&quot;acc&quot;</span>:[0, 0, 1]}
	lasttime = 0.0
	laststate = {}
	responsiveness = 0.15
	firstPress = True
	firstPressDelay = 0.5
	maxButtons = 0
	<span class="enscript-comment">#wii_rel = lambda v, axis: float(v - self.wii_calibration[0][axis]) / (
</span>	<span class="enscript-comment">#	self.wii_calibration[1][axis] - self.wii_calibration[0][axis])
</span>	<span class="enscript-keyword">def</span> <span class="enscript-function-name">wii_rel</span>(self, v, axis):
		<span class="enscript-keyword">return</span> float(v - self.wii_calibration[0][axis]) / (
		self.wii_calibration[1][axis] - self.wii_calibration[0][axis])
	<span class="enscript-keyword">def</span> <span class="enscript-function-name">wmconnect</span>(self):
		<span class="enscript-keyword">print</span> <span class="enscript-string">&quot;Please press 1&amp;2 on the wiimote...&quot;</span>
		try:
			self.wm = cwiid.Wiimote()
		<span class="enscript-keyword">except</span>:
			self.wm = None
			<span class="enscript-keyword">if</span> self.ms <span class="enscript-keyword">is</span> <span class="enscript-keyword">not</span> None:
				self.ms.close()
				self.ms = None
			<span class="enscript-keyword">return</span> None
		self.ms = MythSocket(self)
		<span class="enscript-keyword">print</span> <span class="enscript-string">&quot;Connected...&quot;</span>
		self.wm.rumble=1
		time.sleep(.2)
		self.wm.rumble=0
		<span class="enscript-comment"># Wiimote calibration data (cache this)
</span>		self.wii_calibration = self.wm.get_acc_cal(cwiid.EXT_NONE)
		<span class="enscript-keyword">return</span> self.wm
	<span class="enscript-keyword">def</span> <span class="enscript-function-name">wmcb</span>(self, messages):
		state = self.state
		<span class="enscript-keyword">for</span> message <span class="enscript-keyword">in</span> messages:
			<span class="enscript-keyword">if</span> message[0] == cwiid.MESG_BTN:
				state[<span class="enscript-string">&quot;buttons&quot;</span>] = message[1]
			<span class="enscript-comment">#elif message[0] == cwiid.MESG_STATUS:
</span>			<span class="enscript-comment">#	print &quot;\nStatus: &quot;, message[1]
</span>			<span class="enscript-keyword">elif</span> message[0] == cwiid.MESG_ERROR:
				<span class="enscript-keyword">if</span> message[1] == cwiid.ERROR_DISCONNECT:
					self.wm = None
					<span class="enscript-keyword">if</span> self.ms <span class="enscript-keyword">is</span> <span class="enscript-keyword">not</span> None:
						self.ms.close()
						self.ms = None
					<span class="enscript-keyword">continue</span>
				<span class="enscript-keyword">else</span>:
					<span class="enscript-keyword">print</span> <span class="enscript-string">&quot;ERROR: &quot;</span>, message[1]
			<span class="enscript-keyword">elif</span> message[0] == cwiid.MESG_ACC:
				state[<span class="enscript-string">&quot;acc&quot;</span>] = message[1]
			<span class="enscript-keyword">else</span>:
				<span class="enscript-keyword">print</span> <span class="enscript-string">&quot;Unknown message!&quot;</span>, message
			laststate = self.laststate
			<span class="enscript-keyword">if</span> (<span class="enscript-string">'buttons'</span> <span class="enscript-keyword">in</span> laststate) <span class="enscript-keyword">and</span> (laststate[<span class="enscript-string">'buttons'</span>] &lt;&gt; state[<span class="enscript-string">'buttons'</span>]):
				<span class="enscript-keyword">if</span> state[<span class="enscript-string">'buttons'</span>] == 0:
					self.maxButtons = 0
				<span class="enscript-keyword">elif</span> state[<span class="enscript-string">'buttons'</span>] &lt; self.maxButtons:
					<span class="enscript-keyword">continue</span>
				<span class="enscript-keyword">else</span>:
					self.maxButtons = state[<span class="enscript-string">'buttons'</span>]
				self.lasttime = 0
				self.firstPress = True
				<span class="enscript-keyword">if</span> laststate[<span class="enscript-string">'buttons'</span>] == cwiid.BTN_B <span class="enscript-keyword">and</span> <span class="enscript-keyword">not</span> state[<span class="enscript-string">'buttons'</span>] == cwiid.BTN_B:
					del state[<span class="enscript-string">'BTN_B'</span>]
					self.ms.cmd(<span class="enscript-string">'play speed normal'</span>)
				<span class="enscript-keyword">if</span> (laststate[<span class="enscript-string">'buttons'</span>] &amp; cwiid.BTN_A <span class="enscript-keyword">and</span> laststate[<span class="enscript-string">'buttons'</span>] &amp; cwiid.BTN_B) <span class="enscript-keyword">and</span> <span class="enscript-keyword">not</span> (state[<span class="enscript-string">'buttons'</span>] &amp; cwiid.BTN_A <span class="enscript-keyword">and</span> state[<span class="enscript-string">'buttons'</span>] &amp; cwiid.BTN_B):
					del state[<span class="enscript-string">'BTN_AB'</span>]
					<span class="enscript-comment">#self.ms.cmd('play speed normal')
</span>			<span class="enscript-keyword">if</span> self.ms.ok() <span class="enscript-keyword">and</span> (self.wm <span class="enscript-keyword">is</span> <span class="enscript-keyword">not</span> None) <span class="enscript-keyword">and</span> (state[<span class="enscript-string">&quot;buttons&quot;</span>] &gt; 0) <span class="enscript-keyword">and</span> (time.time() &gt; self.lasttime+self.responsiveness):
				self.lasttime = time.time()
				wasFirstPress = False
				<span class="enscript-keyword">if</span> self.firstPress:
					wasFirstPress = True
					self.lasttime = self.lasttime + self.firstPressDelay
					self.firstPress = False
				<span class="enscript-comment"># Stuff that doesn't need roll/etc calculations
</span>				<span class="enscript-keyword">if</span> state[<span class="enscript-string">&quot;buttons&quot;</span>] == cwiid.BTN_HOME:
					self.ms.cmd(<span class="enscript-string">'key escape'</span>)
				<span class="enscript-keyword">if</span> state[<span class="enscript-string">&quot;buttons&quot;</span>] == cwiid.BTN_A:
					self.ms.cmd(<span class="enscript-string">'key enter'</span>)
				<span class="enscript-keyword">if</span> state[<span class="enscript-string">&quot;buttons&quot;</span>] == cwiid.BTN_MINUS:
					self.ms.cmd(<span class="enscript-string">'key d'</span>)
				<span class="enscript-keyword">if</span> state[<span class="enscript-string">&quot;buttons&quot;</span>] == cwiid.BTN_UP:
					self.ms.cmd(<span class="enscript-string">'key up'</span>)
				<span class="enscript-keyword">if</span> state[<span class="enscript-string">&quot;buttons&quot;</span>] == cwiid.BTN_DOWN:
					self.ms.cmd(<span class="enscript-string">'key down'</span>)
				<span class="enscript-keyword">if</span> state[<span class="enscript-string">&quot;buttons&quot;</span>] == cwiid.BTN_LEFT:
					self.ms.cmd(<span class="enscript-string">'key left'</span>)
				<span class="enscript-keyword">if</span> state[<span class="enscript-string">&quot;buttons&quot;</span>] == cwiid.BTN_RIGHT:
					self.ms.cmd(<span class="enscript-string">'key right'</span>)
				<span class="enscript-keyword">if</span> state[<span class="enscript-string">&quot;buttons&quot;</span>] == cwiid.BTN_PLUS:
					self.ms.cmd(<span class="enscript-string">'key p'</span>)
				<span class="enscript-keyword">if</span> state[<span class="enscript-string">&quot;buttons&quot;</span>] == cwiid.BTN_1:
					self.ms.cmd(<span class="enscript-string">'key i'</span>)
				<span class="enscript-keyword">if</span> state[<span class="enscript-string">&quot;buttons&quot;</span>] == cwiid.BTN_2:
					self.ms.cmd(<span class="enscript-string">'key m'</span>)
				<span class="enscript-comment"># Do we need to calculate roll, etc?
</span>				<span class="enscript-comment"># Currently only BTN_B needs this.
</span>				calcAcc = state[<span class="enscript-string">&quot;buttons&quot;</span>] &amp; cwiid.BTN_B
				<span class="enscript-keyword">if</span> calcAcc:
					<span class="enscript-comment"># Calculate the roll/etc.
</span>					X = self.wii_rel(state[<span class="enscript-string">&quot;acc&quot;</span>][cwiid.X], cwiid.X)
					Y = self.wii_rel(state[<span class="enscript-string">&quot;acc&quot;</span>][cwiid.Y], cwiid.Y)
					Z = self.wii_rel(state[<span class="enscript-string">&quot;acc&quot;</span>][cwiid.Z], cwiid.Z)
					<span class="enscript-keyword">if</span> (Z==0): Z=0.00000001 <span class="enscript-comment"># Hackishly prevents divide by zeros
</span>					roll = atan(X/Z)
					<span class="enscript-keyword">if</span> (Z &lt;= 0.0):
						<span class="enscript-keyword">if</span> (X&gt;0): roll += 3.14159
						<span class="enscript-keyword">else</span>: roll -= 3.14159
					pitch = atan(Y/Z*cos(roll))
					<span class="enscript-comment">#print &quot;X: %f, Y: %f, Z: %f; R: %f, P: %f; B: %d    \r&quot; % (X, Y, Z, roll, pitch, state[&quot;buttons&quot;]),
</span>					sys.stdout.flush()
				<span class="enscript-keyword">if</span> state[<span class="enscript-string">&quot;buttons&quot;</span>] &amp; cwiid.BTN_B <span class="enscript-keyword">and</span> state[<span class="enscript-string">&quot;buttons&quot;</span>] &amp; cwiid.BTN_LEFT:
					self.ms.cmd(<span class="enscript-string">'play seek beginning'</span>)
				<span class="enscript-keyword">if</span> state[<span class="enscript-string">&quot;buttons&quot;</span>] &amp; cwiid.BTN_B <span class="enscript-keyword">and</span> state[<span class="enscript-string">&quot;buttons&quot;</span>] &amp; cwiid.BTN_A:
					speed=do_scale(roll/3.14159, 20, 25)
					<span class="enscript-keyword">if</span> (speed&lt;-10): speed = -10
					state[<span class="enscript-string">'BTN_AB'</span>] = speed
					cmd = <span class="enscript-string">&quot;&quot;</span>
					<span class="enscript-comment"># on first press,  press a,
</span>					<span class="enscript-comment"># after then use the diff to press left/right
</span>					<span class="enscript-keyword">if</span> <span class="enscript-keyword">not</span> <span class="enscript-string">'BTN_AB'</span> <span class="enscript-keyword">in</span> laststate:
						<span class="enscript-comment"># # query location
</span>						<span class="enscript-comment"># Playback Recorded 00:04:20 of 00:25:31 1x 30210 2008-09-10T09:18:00 6523 /video/30210_20080910091800.mpg 25
</span>						cmd += <span class="enscript-string">&quot;play speed normal\nkey a\n&quot;</span><span class="enscript-comment">#&quot;play speed normal\n&quot;
</span>					<span class="enscript-keyword">else</span>:
						speed = speed - laststate[<span class="enscript-string">'BTN_AB'</span>]
					<span class="enscript-keyword">if</span> speed &gt; 0:
						cmd += abs(speed)*<span class="enscript-string">&quot;key right\n&quot;</span>
					<span class="enscript-keyword">elif</span> speed &lt; 0:
						cmd += abs(speed)*<span class="enscript-string">&quot;key left\n&quot;</span>
					<span class="enscript-keyword">if</span> speed &lt;&gt; 0:
						self.wm.rumble=1
						time.sleep(.05)
						self.wm.rumble=0
					<span class="enscript-keyword">if</span> cmd <span class="enscript-keyword">is</span> <span class="enscript-keyword">not</span> None <span class="enscript-keyword">and</span> cmd:
						self.ms.raw(cmd)
				<span class="enscript-keyword">if</span> state[<span class="enscript-string">&quot;buttons&quot;</span>] == cwiid.BTN_B:
					speed=do_scale(roll/3.14159, 8, 13)
					state[<span class="enscript-string">'BTN_B'</span>] = speed
					<span class="enscript-keyword">if</span> <span class="enscript-keyword">not</span> <span class="enscript-string">'BTN_B'</span> <span class="enscript-keyword">in</span> laststate:
						<span class="enscript-comment"># # query location
</span>						<span class="enscript-comment"># Playback Recorded 00:04:20 of 00:25:31 1x 30210 2008-09-10T09:18:00 6523 /video/30210_20080910091800.mpg 25
</span>						cmd = <span class="enscript-string">&quot;&quot;</span><span class="enscript-comment">#&quot;play speed normal\n&quot;
</span>						<span class="enscript-keyword">if</span> speed &gt; 0:
							cmd += <span class="enscript-string">&quot;key .\n&quot;</span>
						<span class="enscript-keyword">elif</span> speed &lt; 0:
							cmd += <span class="enscript-string">&quot;key ,\n&quot;</span>
						<span class="enscript-keyword">if</span> speed &lt;&gt; 0:
							cmd += <span class="enscript-string">&quot;key &quot;</span>+str(abs(speed)-1)+<span class="enscript-string">&quot;\n&quot;</span>
						<span class="enscript-comment">#print cmd
</span>					<span class="enscript-keyword">elif</span> laststate[<span class="enscript-string">'BTN_B'</span>]&lt;&gt;speed:
						self.wm.rumble=1
						time.sleep(.05)
						self.wm.rumble=0
						<span class="enscript-keyword">if</span> speed == 0:
							cmd = <span class="enscript-string">&quot;play speed normal&quot;</span>
						<span class="enscript-keyword">elif</span> ((laststate[<span class="enscript-string">'BTN_B'</span>] &gt; 0) <span class="enscript-keyword">and</span> (speed &gt; 0)) <span class="enscript-keyword">or</span> ((laststate[<span class="enscript-string">'BTN_B'</span>] &lt; 0) <span class="enscript-keyword">and</span> (speed &lt; 0)):
							cmd = <span class="enscript-string">&quot;key &quot;</span>+str(abs(speed)-1)+<span class="enscript-string">&quot;\n&quot;</span>
						<span class="enscript-keyword">elif</span> speed&gt;0:
							cmd = <span class="enscript-string">&quot;key .\nkey &quot;</span>+str(abs(speed)-1)+<span class="enscript-string">&quot;\n&quot;</span>
						<span class="enscript-keyword">else</span>:
							cmd = <span class="enscript-string">&quot;key ,\nkey &quot;</span>+str(abs(speed)-1)+<span class="enscript-string">&quot;\n&quot;</span>
					<span class="enscript-keyword">else</span>:
						cmd = None
					<span class="enscript-keyword">if</span> cmd <span class="enscript-keyword">is</span> <span class="enscript-keyword">not</span> None:
						self.ms.raw(cmd)
			self.laststate = state.copy() <span class="enscript-comment">#NOTE TO SELF: REMEMBER .copy() !!!
</span>	<span class="enscript-keyword">def</span> <span class="enscript-function-name">mythLocation</span>(self, data):
		<span class="enscript-comment">#Playback Recorded 00:00:49 of 00:25:31 1x 30210 2008-09-10T09:18:00 1243 /video/30210_20080910091800.mpg 25
</span>		<span class="enscript-comment">#PlaybackBox
</span>		temp = data.split(<span class="enscript-string">&quot; &quot;</span>)
		output = {}
		output[<span class="enscript-string">'mode'</span>] = temp[0]
		<span class="enscript-keyword">if</span> output[<span class="enscript-string">'mode'</span>] == <span class="enscript-string">&quot;Playback&quot;</span>:
			output[<span class="enscript-string">'position'</span>] = temp[2]
			output[<span class="enscript-string">'max'</span>] = temp[4]
		<span class="enscript-keyword">return</span> output
	<span class="enscript-keyword">def</span> <span class="enscript-function-name">main</span>(self):
		<span class="enscript-keyword">while</span> True:
			<span class="enscript-keyword">if</span> self.wm <span class="enscript-keyword">is</span> None:
				<span class="enscript-comment">#Connect wiimote
</span>				self.wmconnect()
				<span class="enscript-keyword">if</span> self.wm:
					<span class="enscript-comment">#Tell Wiimote to display rock sign
</span>					self.wm.led = cwiid.LED1_ON | cwiid.LED4_ON
					self.wm.rpt_mode = sum(self.reportvals[a] <span class="enscript-keyword">for</span> a <span class="enscript-keyword">in</span> self.report <span class="enscript-keyword">if</span> self.report[a])
					self.wm.enable(cwiid.FLAG_MESG_IFC | cwiid.FLAG_REPEAT_BTN)
					self.wm.mesg_callback = self.wmcb
			asyncore.loop(timeout=0, count=1)
			time.sleep(0.05)
		<span class="enscript-keyword">print</span> <span class="enscript-string">&quot;Exited Safely&quot;</span>

<span class="enscript-comment"># Instantiate our class, and start.
</span>inst = WiiMyth()
inst.main()
</code>
<span style="display: block; text-align: center;">Download this code: <a href="http://www.benjiegillam.com/code/myth_py_wii.r14.py" title="Download the above code as a text file.">/code/myth_py_wii.r14.py</a></span></p>
<p>Hopefully tomorrow I can have it up and running, get a video up, and decent install instructions. Hopefully.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.benjiegillam.com/2008/09/zombie-mythpywii-update/feed/</wfw:commentRss>
		</item>
		<item>
		<title>MythPyWii - A Wiimote Interface To MythTV Using Python</title>
		<link>http://www.benjiegillam.com/2008/09/mythpywii-a-wiimote-interface-to-mythtv-using-python/</link>
		<comments>http://www.benjiegillam.com/2008/09/mythpywii-a-wiimote-interface-to-mythtv-using-python/#comments</comments>
		<pubDate>Wed, 10 Sep 2008 17:45:51 +0000</pubDate>
		<dc:creator>Benjie</dc:creator>
		
		<category><![CDATA[Code]]></category>

		<category><![CDATA[Computers]]></category>

		<category><![CDATA[Hardware]]></category>

		<category><![CDATA[Linux]]></category>

		<category><![CDATA[MythTV]]></category>

		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[MythPyWii]]></category>

		<category><![CDATA[Python]]></category>

		<category><![CDATA[Wii]]></category>

		<category><![CDATA[Wii Remote]]></category>

		<category><![CDATA[Wiimote]]></category>

		<guid isPermaLink="false">http://www.benjiegillam.com/?p=117</guid>
		<description><![CDATA[Image via Wikipedia 
MythPyWii (yes, I&#8217;m not very good at names, better suggestions welcome in the comments!) is born!
I love the Wiimote (Wii Remote) so much, I&#8217;ve just been gagging for a way to hook it up to my computer and do something useful. I started by hooking it up to Neverball and that was [...]]]></description>
			<content:encoded><![CDATA[<div class="zemanta-img" style="margin: 1em; float: right; display: block;"><a href="http://commons.wikipedia.org/wiki/Image:Wii_Remote_Image.jpg"><img style="border: medium none ; display: block;" src="http://upload.wikimedia.org/wikipedia/commons/thumb/b/bc/Wii_Remote_Image.jpg/202px-Wii_Remote_Image.jpg" alt="An image of the Wii remote (with wrist strap) ..."></a><span class="zemanta-img-attribution">Image via <a href="http://commons.wikipedia.org/wiki/Image:Wii_Remote_Image.jpg">Wikipedia</a> </span></div>
<p>MythPyWii (yes, I&#8217;m not very good at names, better suggestions welcome in the comments!) is born!</p>
<p>I love the Wiimote (<a class="zem_slink" title="Wii Remote" rel="wikipedia" href="http://en.wikipedia.org/wiki/Wii_Remote">Wii Remote</a>) so much, I&#8217;ve just been gagging for a way to hook it up to my computer and do something useful. I started by hooking it up to <a class="zem_slink" title="Neverball" rel="wikipedia" href="http://en.wikipedia.org/wiki/Neverball">Neverball</a> and that was cool, but I wanted something better. I&#8217;ve always thought it would make a great remote control for Mythfrontend (from the <a class="zem_slink" title="MythTV" rel="wikipedia" href="http://en.wikipedia.org/wiki/MythTV">MythTV</a> package) - but those that exist only seem to use the Wiimote as a keyboard - they ignore it&#8217;s accelerometers and other such things. (And I want one that doesn&#8217;t require a <a class="zem_slink" title="Wii" rel="wikipedia" href="http://en.wikipedia.org/wiki/Wii">wii</a> sensor bar, because I don&#8217;t have a second one!)</p>
<p>I wanted better. But I never seemed to have the time to make it. That is, until Jof told me &#8220;go and learn <a class="zem_slink" title="Python (programming language)" rel="wikipedia" href="http://en.wikipedia.org/wiki/Python_%28programming_language%29">Python</a>&#8220;. This was the perfect project for starting python. That is a lie, it was way too complex, but I thought &#8220;why bother if it isn&#8217;t challenging&#8221; - it turned out to be a kind of baptism by fire.</p>
<p>If you are in a rush, or hate nerdy stuff, skip to the next title &#8220;How To Install&#8221;.</p>
<p>Having had <a class="zem_slink" title="PHP" rel="wikipedia" href="http://en.wikipedia.org/wiki/PHP">PHP</a> as my main programming language for such a long long long time, switching to Python sounded like fun. It has got a very nice syntax, and is a very clear language&#8230; except for it&#8217;s major overuse of references. For example:</p>
<blockquote><p>a = [2, 3]<br />
b = [1, a, 4]<br />
print b<br />
# Outputs [1, [2, 3], 4]<br />
b[1][1] = &#8220;x&#8221;<br />
print b<br />
# Outputs [1, [2, 'x'], 4]<br />
print a<br />
# Outputs [2, 'x'], not [2, 3] as I expect, coming from PHP.</p></blockquote>
<p>Still this is &#8220;easily&#8221; got around by making sure you <strong>copy</strong> objects rather than just equating them. And checking your code thoroughly.</p>
<p>This was my first time interfacing with mythfrontend in any way, and I chose to try and script mythfrontend&#8217;s telnet socket interface. It was also my first time programming an interface to the wiimote, so I chose to use the cwiid package, as that is what I used to control neverball, and it seemed to work well. A few days of reading python tutorials, hacking and swearing, I finally acheived what I had set out to do - fastforwarding using the accelerometers. A couple of hours later and I had a fully working wiimote interface to mythtv&#8230;</p>
<p>My thoughts on the mythtv telnet socket interface: its very basic, and quite slow, but definitely better than nothing. I think a few iterations down the line and it could be awesome. My biggest problem with it currently is how slowly it does &#8220;query location&#8221; - it takes almost a second to get back to you with an answer, which means you can&#8217;t do location based buttons easily. (For example, I wanted A to be &#8220;p&#8221; (play/pause) when playing back a video, and &#8220;enter&#8221; (accept, OK, &#8230;) when not doing so.) I found the best way to do things in the end was to get the program to emulate the keyboard after all, admittedly sometimes with macros.</p>
<h3>How To Install</h3>
<p>You should definitely keep in mind that this project is not even <a class="zem_slink" title="Software release life cycle" rel="wikipedia" href="http://en.wikipedia.org/wiki/Software_release_life_cycle">alpha stage</a>. Its my first real forray into the world of Python, my first real forray into programming with the wiimote, AND my first real forray with using mythfrontend&#8217;s telnet interface - all in all it is very new to me. It seems to work, just about, so I thought I would release what I have so far, and then set about tidying it up. I had intended to release a video at this point too, but I am just too excited! You can download the code here:</p>
<p><code class="source">
<span class="enscript-comment">#!/usr/bin/env python
</span><span class="enscript-string">&quot;&quot;&quot;
Copyright (c) 2008, Benjie Gillam
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
    * Neither the name of MythPyWii nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &quot;AS IS&quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
&quot;&quot;&quot;</span>
<span class="enscript-comment"># By Benjie Gillam http://www.benjiegillam.com/mythpywii/
</span>
<span class="enscript-keyword">import</span> cwiid, time, StringIO, sys, asyncore, socket
<span class="enscript-keyword">from</span> math <span class="enscript-keyword">import</span> log, floor, atan, sqrt, cos, exp

<span class="enscript-comment"># Note to self - list of good documentation:
</span><span class="enscript-comment"># cwiid: http://flx.proyectoanonimo.com/proyectos/cwiid/
</span><span class="enscript-comment"># myth telnet: http://www.mythtv.org/wiki/index.php/Telnet_socket
</span>
<span class="enscript-keyword">class</span> MythSocket(asyncore.dispatcher):
	firstData = True
	data = <span class="enscript-string">&quot;&quot;</span>
	prompt=<span class="enscript-string">&quot;\n# &quot;</span>
	owner = None
	buffer = <span class="enscript-string">&quot;&quot;</span>
	callbacks = []
	oktosend = True
	<span class="enscript-keyword">def</span> <span class="enscript-function-name">__init__</span>(self, owner):
		self.owner = owner
		asyncore.dispatcher.__init__(self)
		self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
		self.connect((<span class="enscript-string">&quot;localhost&quot;</span>, 6546))
	<span class="enscript-keyword">def</span> <span class="enscript-function-name">handle_connect</span>(self):
		<span class="enscript-keyword">print</span> <span class="enscript-string">&quot;Connected&quot;</span>
	<span class="enscript-keyword">def</span> <span class="enscript-function-name">handle_close</span>(self):
		<span class="enscript-keyword">print</span> <span class="enscript-string">&quot;Closed&quot;</span>
		self.close()
	<span class="enscript-keyword">def</span> <span class="enscript-function-name">handle_read</span>(self):
		self.data = self.data + self.recv(8192)
		<span class="enscript-keyword">while</span> len(self.data)&gt;0:
			a = self.data.find(self.prompt)
			<span class="enscript-keyword">if</span> a&gt;-1:
				self.oktosend = True
				result = self.data[:a]
				self.data = self.data[a+len(self.prompt):]
				<span class="enscript-keyword">if</span> <span class="enscript-keyword">not</span> self.firstData:
					<span class="enscript-keyword">print</span> <span class="enscript-string">&quot;&lt;&lt;&lt;&quot;</span>, result
					cb = self.callbacks.pop(0)
					<span class="enscript-keyword">if</span> cb:
						cb(result)
				<span class="enscript-keyword">else</span>:
					<span class="enscript-keyword">print</span> <span class="enscript-string">&quot;Logged in to MythFrontend&quot;</span>
					self.firstData = False
			<span class="enscript-keyword">else</span>:
				<span class="enscript-keyword">break</span>;
	<span class="enscript-keyword">def</span> <span class="enscript-function-name">writable</span>(self):
		<span class="enscript-keyword">return</span> (self.oktosend) <span class="enscript-keyword">and</span> (len(self.buffer) &gt; 0) <span class="enscript-keyword">and</span> (self.buffer.find(<span class="enscript-string">&quot;\n&quot;</span>) &gt; 0)
	<span class="enscript-keyword">def</span> <span class="enscript-function-name">handle_write</span>(self):
		a = self.buffer.find(<span class="enscript-string">&quot;\n&quot;</span>)
		sent = self.send(self.buffer[:a+1])
		<span class="enscript-keyword">print</span> <span class="enscript-string">&quot;&gt;&gt;&gt;&quot;</span>, self.buffer[:sent-1]
		self.buffer = self.buffer[sent:]
		self.oktosend = False
	<span class="enscript-keyword">def</span> <span class="enscript-function-name">cmd</span>(self, data, cb = None):
		self.buffer += data + <span class="enscript-string">&quot;\n&quot;</span>
		self.callbacks.append(cb)
	<span class="enscript-keyword">def</span> <span class="enscript-function-name">raw</span>(self, data):
		cmds = data.split(<span class="enscript-string">&quot;\n&quot;</span>)
		<span class="enscript-keyword">for</span> cmd <span class="enscript-keyword">in</span> cmds:
			<span class="enscript-keyword">if</span> len(cmd.strip())&gt;0:
				self.cmd(cmd)
	<span class="enscript-keyword">def</span> <span class="enscript-function-name">ok</span>(self):
		<span class="enscript-keyword">return</span> len(self.callbacks) == len(self.buffer) == 0


<span class="enscript-keyword">class</span> WiiMyth:
	wii_calibration = False
	wm = None
	ms = None
	wii_calibration = None
	<span class="enscript-comment">#Initialize variables
</span>	reportvals = {<span class="enscript-string">&quot;accel&quot;</span>:cwiid.RPT_ACC, <span class="enscript-string">&quot;button&quot;</span>:cwiid.RPT_BTN, <span class="enscript-string">&quot;ext&quot;</span>:cwiid.RPT_EXT,  <span class="enscript-string">&quot;status&quot;</span>:cwiid.RPT_STATUS}
	report={<span class="enscript-string">&quot;accel&quot;</span>:True, <span class="enscript-string">&quot;button&quot;</span>:True}
	state = {<span class="enscript-string">&quot;acc&quot;</span>:[0, 0, 1]}
	lasttime = 0.0
	laststate = {}
	responsiveness = 0.5
	<span class="enscript-comment">#wii_rel = lambda v, axis: float(v - self.wii_calibration[0][axis]) / (
</span>	<span class="enscript-comment">#	self.wii_calibration[1][axis] - self.wii_calibration[0][axis])
</span>	<span class="enscript-keyword">def</span> <span class="enscript-function-name">wii_rel</span>(self, v, axis):
		<span class="enscript-keyword">return</span> float(v - self.wii_calibration[0][axis]) / (
		self.wii_calibration[1][axis] - self.wii_calibration[0][axis])
	<span class="enscript-keyword">def</span> <span class="enscript-function-name">wmconnect</span>(self):
		<span class="enscript-keyword">print</span> <span class="enscript-string">&quot;Please press 1&amp;2 on the wiimote...&quot;</span>
		try:
			self.wm = cwiid.Wiimote()
		<span class="enscript-keyword">except</span>:
			self.wm = None
			<span class="enscript-keyword">if</span> self.ms <span class="enscript-keyword">is</span> <span class="enscript-keyword">not</span> None:
				self.ms.close()
				self.ms = None
			<span class="enscript-keyword">return</span> None
		self.ms = MythSocket(self)
		<span class="enscript-keyword">print</span> <span class="enscript-string">&quot;Connected...&quot;</span>
		self.wm.rumble=1
		time.sleep(.2)
		self.wm.rumble=0
		<span class="enscript-comment"># Wiimote calibration data (cache this)
</span>		self.wii_calibration = self.wm.get_acc_cal(cwiid.EXT_NONE)
		<span class="enscript-keyword">return</span> self.wm
	<span class="enscript-keyword">def</span> <span class="enscript-function-name">wmcb</span>(self, messages):
		state = self.state
		<span class="enscript-keyword">for</span> message <span class="enscript-keyword">in</span> messages:
			<span class="enscript-keyword">if</span> message[0] == cwiid.MESG_BTN:
				state[<span class="enscript-string">&quot;buttons&quot;</span>] = message[1]
			<span class="enscript-comment">#elif message[0] == cwiid.MESG_STATUS:
</span>			<span class="enscript-comment">#	print &quot;\nStatus: &quot;, message[1]
</span>			<span class="enscript-keyword">elif</span> message[0] == cwiid.MESG_ERROR:
				<span class="enscript-keyword">if</span> message[1] == cwiid.ERROR_DISCONNECT:
					self.wm = None
					<span class="enscript-keyword">if</span> self.ms <span class="enscript-keyword">is</span> <span class="enscript-keyword">not</span> None:
						self.ms.close()
						self.ms = None
					<span class="enscript-keyword">continue</span>
				<span class="enscript-keyword">else</span>:
					<span class="enscript-keyword">print</span> <span class="enscript-string">&quot;ERROR: &quot;</span>, message[1]
			<span class="enscript-keyword">elif</span> message[0] == cwiid.MESG_ACC:
				state[<span class="enscript-string">&quot;acc&quot;</span>] = message[1]
			<span class="enscript-keyword">else</span>:
				<span class="enscript-keyword">print</span> <span class="enscript-string">&quot;Unknown message!&quot;</span>, message
			laststate = self.laststate
			<span class="enscript-keyword">if</span> (<span class="enscript-string">'buttons'</span> <span class="enscript-keyword">in</span> laststate) <span class="enscript-keyword">and</span> (laststate[<span class="enscript-string">'buttons'</span>] &lt;&gt; state[<span class="enscript-string">'buttons'</span>]):
				<span class="enscript-keyword">if</span> laststate[<span class="enscript-string">'buttons'</span>] &amp; cwiid.BTN_B <span class="enscript-keyword">and</span> <span class="enscript-keyword">not</span> state[<span class="enscript-string">'buttons'</span>] &amp; cwiid.BTN_B:
					del state[<span class="enscript-string">'BTN_B'</span>]
					self.ms.cmd(<span class="enscript-string">'play speed normal'</span>)
			<span class="enscript-keyword">if</span> self.ms.ok() <span class="enscript-keyword">and</span> (self.wm <span class="enscript-keyword">is</span> <span class="enscript-keyword">not</span> None) <span class="enscript-keyword">and</span> (state[<span class="enscript-string">&quot;buttons&quot;</span>] &gt; 0) <span class="enscript-keyword">and</span> (time.time() &gt; self.lasttime+self.responsiveness):
				self.lasttime = time.time()
				<span class="enscript-comment"># Stuff that doesn't need roll/etc calculations
</span>				<span class="enscript-keyword">if</span> state[<span class="enscript-string">&quot;buttons&quot;</span>] &amp; cwiid.BTN_HOME:
					self.ms.cmd(<span class="enscript-string">'key escape'</span>)
				<span class="enscript-keyword">if</span> state[<span class="enscript-string">&quot;buttons&quot;</span>] &amp; cwiid.BTN_A:
					self.ms.cmd(<span class="enscript-string">'key enter'</span>)
				<span class="enscript-keyword">if</span> state[<span class="enscript-string">&quot;buttons&quot;</span>] &amp; cwiid.BTN_MINUS:
					self.ms.cmd(<span class="enscript-string">'key d'</span>)
				<span class="enscript-keyword">if</span> state[<span class="enscript-string">&quot;buttons&quot;</span>] &amp; cwiid.BTN_UP:
					self.ms.cmd(<span class="enscript-string">'key up'</span>)
				<span class="enscript-keyword">if</span> state[<span class="enscript-string">&quot;buttons&quot;</span>] &amp; cwiid.BTN_DOWN:
					self.ms.cmd(<span class="enscript-string">'key down'</span>)
				<span class="enscript-keyword">if</span> state[<span class="enscript-string">&quot;buttons&quot;</span>] &amp; cwiid.BTN_LEFT:
					self.ms.cmd(<span class="enscript-string">'key left'</span>)
				<span class="enscript-keyword">if</span> state[<span class="enscript-string">&quot;buttons&quot;</span>] &amp; cwiid.BTN_RIGHT:
					self.ms.cmd(<span class="enscript-string">'key right'</span>)
				<span class="enscript-keyword">if</span> state[<span class="enscript-string">&quot;buttons&quot;</span>] &amp; cwiid.BTN_PLUS:
					self.ms.cmd(<span class="enscript-string">'key p'</span>)
				<span class="enscript-keyword">if</span> state[<span class="enscript-string">&quot;buttons&quot;</span>] &amp; cwiid.BTN_1:
					self.ms.cmd(<span class="enscript-string">'key i'</span>)
				<span class="enscript-keyword">if</span> state[<span class="enscript-string">&quot;buttons&quot;</span>] &amp; cwiid.BTN_2:
					self.ms.cmd(<span class="enscript-string">'key m'</span>)
				<span class="enscript-comment"># Do we need to calculate roll, etc?
</span>				<span class="enscript-comment"># Currently only BTN_B needs this.
</span>				calcAcc = state[<span class="enscript-string">&quot;buttons&quot;</span>] &amp; cwiid.BTN_B
				<span class="enscript-keyword">if</span> calcAcc:
					<span class="enscript-comment"># Calculate the roll/etc.
</span>					X = self.wii_rel(state[<span class="enscript-string">&quot;acc&quot;</span>][cwiid.X], cwiid.X)
					Y = self.wii_rel(state[<span class="enscript-string">&quot;acc&quot;</span>][cwiid.Y], cwiid.Y)
					Z = self.wii_rel(state[<span class="enscript-string">&quot;acc&quot;</span>][cwiid.Z], cwiid.Z)
					<span class="enscript-keyword">if</span> (Z==0): Z=0.00000001 <span class="enscript-comment"># Hackishly prevents divide by zeros
</span>					roll = atan(X/Z)
					<span class="enscript-keyword">if</span> (Z &lt;= 0.0):
						<span class="enscript-keyword">if</span> (X&gt;0): roll += 3.14159
						<span class="enscript-keyword">else</span>: roll -= 3.14159
					pitch = atan(Y/Z*cos(roll))
					<span class="enscript-comment">#print &quot;X: %f, Y: %f, Z: %f; R: %f, P: %f; B: %d    \r&quot; % (X, Y, Z, roll, pitch, state[&quot;buttons&quot;]),
</span>					sys.stdout.flush()
				<span class="enscript-keyword">if</span> state[<span class="enscript-string">&quot;buttons&quot;</span>] &amp; cwiid.BTN_B:
					speed = roll/3.14159
					<span class="enscript-keyword">if</span> (speed &gt; 1): speed = 1
					<span class="enscript-keyword">if</span> (speed &lt; -1): speed = -1
					speed = int(speed * 13)
					<span class="enscript-keyword">if</span> abs(speed)&gt;9:
						<span class="enscript-keyword">if</span> speed&gt;0: speed = 9
						<span class="enscript-keyword">else</span>: speed = -9
					state[<span class="enscript-string">'BTN_B'</span>] = speed
					<span class="enscript-keyword">if</span> <span class="enscript-keyword">not</span> <span class="enscript-string">'BTN_B'</span> <span class="enscript-keyword">in</span> laststate:
						<span class="enscript-comment"># # query location
</span>						<span class="enscript-comment"># Playback Recorded 00:04:20 of 00:25:31 1x 30210 2008-09-10T09:18:00 6523 /video/30210_20080910091800.mpg 25
</span>						cmd = <span class="enscript-string">&quot;&quot;</span><span class="enscript-comment">#&quot;play speed normal\n&quot;
</span>						<span class="enscript-keyword">if</span> speed &gt; 0:
							cmd += <span class="enscript-string">&quot;key .\n&quot;</span>
						<span class="enscript-keyword">elif</span> speed &lt; 0:
							cmd += <span class="enscript-string">&quot;key ,\n&quot;</span>
						<span class="enscript-keyword">if</span> speed &lt;&gt; 0:
							cmd += <span class="enscript-string">&quot;key &quot;</span>+str(abs(speed)-1)+<span class="enscript-string">&quot;\n&quot;</span>
						<span class="enscript-comment">#print cmd
</span>					<span class="enscript-keyword">elif</span> laststate[<span class="enscript-string">'BTN_B'</span>]&lt;&gt;speed:
						self.wm.rumble=1
						time.sleep(.05)
						self.wm.rumble=0
						<span class="enscript-keyword">if</span> speed == 0:
							cmd = <span class="enscript-string">&quot;play speed normal&quot;</span>
						<span class="enscript-keyword">elif</span> ((laststate[<span class="enscript-string">'BTN_B'</span>] &gt; 0) <span class="enscript-keyword">and</span> (speed &gt; 0)) <span class="enscript-keyword">or</span> ((laststate[<span class="enscript-string">'BTN_B'</span>] &lt; 0) <span class="enscript-keyword">and</span> (speed &lt; 0)):
							cmd = <span class="enscript-string">&quot;key &quot;</span>+str(abs(speed)-1)+<span class="enscript-string">&quot;\n&quot;</span>
						<span class="enscript-keyword">elif</span> speed&gt;0:
							cmd = <span class="enscript-string">&quot;key .\nkey &quot;</span>+str(abs(speed)-1)+<span class="enscript-string">&quot;\n&quot;</span>
						<span class="enscript-keyword">else</span>:
							cmd = <span class="enscript-string">&quot;key ,\nkey &quot;</span>+str(abs(speed)-1)+<span class="enscript-string">&quot;\n&quot;</span>
					<span class="enscript-keyword">else</span>:
						cmd = None
					<span class="enscript-keyword">if</span> cmd <span class="enscript-keyword">is</span> <span class="enscript-keyword">not</span> None:
						self.ms.raw(cmd)
			self.laststate = state.copy() <span class="enscript-comment">#NOTE TO SELF: REMEMBER .copy() !!!
</span>	<span class="enscript-keyword">def</span> <span class="enscript-function-name">mythLocation</span>(self, data):
		<span class="enscript-comment">#Playback Recorded 00:00:49 of 00:25:31 1x 30210 2008-09-10T09:18:00 1243 /video/30210_20080910091800.mpg 25
</span>		<span class="enscript-comment">#PlaybackBox
</span>		temp = data.split(<span class="enscript-string">&quot; &quot;</span>)
		output = {}
		output[<span class="enscript-string">'mode'</span>] = temp[0]
		<span class="enscript-keyword">if</span> output[<span class="enscript-string">'mode'</span>] == <span class="enscript-string">&quot;Playback&quot;</span>:
			output[<span class="enscript-string">'position'</span>] = temp[2]
			output[<span class="enscript-string">'max'</span>] = temp[4]
		<span class="enscript-keyword">return</span> output
	<span class="enscript-keyword">def</span> <span class="enscript-function-name">main</span>(self):
		<span class="enscript-keyword">while</span> True:
			<span class="enscript-keyword">if</span> self.wm <span class="enscript-keyword">is</span> None:
				<span class="enscript-comment">#Connect wiimote
</span>				self.wmconnect()
				<span class="enscript-keyword">if</span> self.wm:
					<span class="enscript-comment">#Tell Wiimote to display rock sign
</span>					self.wm.led = cwiid.LED1_ON | cwiid.LED4_ON
					self.wm.rpt_mode = sum(self.reportvals[a] <span class="enscript-keyword">for</span> a <span class="enscript-keyword">in</span> self.report <span class="enscript-keyword">if</span> self.report[a])
					self.wm.enable(cwiid.FLAG_MESG_IFC | cwiid.FLAG_REPEAT_BTN)
					self.wm.mesg_callback = self.wmcb
			asyncore.loop(timeout=0, count=1)
			time.sleep(0.05)
		<span class="enscript-keyword">print</span> <span class="enscript-string">&quot;Exited Safely&quot;</span>

<span class="enscript-comment"># Instantiate our class, and start.
</span>inst = WiiMyth()
inst.main()
</code>
<span style="display: block; text-align: center;">Download this code: <a href="http://www.benjiegillam.com/code/myth_py_wii.r12.py" title="Download the above code as a text file.">/code/myth_py_wii.r12.py</a></span></p>
<p>First, load up mythfrontend. Then run the script using "<strong>python myth_py_wii.r12.py</strong>&#8220;. Once it is running it will prompt you to press 1+2 on the Wiimote. Doing so should make the LEDs flash at the bottom of the wiimote, and then a good few seconds later (up to 30) the wiimote should vibrate to let you know it is activated, and LED1+LED4 should be turned on (my Wiimote version of rock-hands). Then navigate using the controls below.</p>
<p>Unfortunately I have not tested this on any computer but my own. Hopefully in a few days time I can write some decent install instructions. However for now you will have to try your best, with the following hopefully helpful hints:</p>
<p>You need (some of and probably more than) the following installed (<a class="zem_slink" title="Ubuntu" rel="wikipedia" href="http://en.wikipedia.org/wiki/Ubuntu">Ubuntu Hardy</a>):</p>
<ul>
<li>GNU/Linux</li>
<li>working bluetooth connectivity (bluetooth keyfobs are really cheap now, and most work out of the box with Hardy)</li>
<li>a Wiimote (duh!)</li>
<li>python-cwiid, libcwiid1, libcwiid1-dev</li>
<li>python (I&#8217;m using 2.5)</li>
<li>a working mythfrontend</li>
<li>patience</li>
</ul>
<p>You also need to set mythfrontend up to accept remote connections on port 6546 (this took a couple of attempts to activate for me - try restarting mythfrontend once you have modified and saved the settings). You can find this under something similar to <strong>Mythfrontend Main Menu &gt; Utilities/Setup &gt; Setup &gt; General &gt; page 4 &gt; &#8220;Enable Network Remote Control interface&#8221;, &#8220;Network Remote Control Port: 6546&#8243;</strong></p>
<p>Hopefully thats enough to get you started. I aim to release a video soon to show it in action. One last thing - the controls!</p>
<h3>Controls</h3>
<p>These are liable to change, but for now, here is how they are mapped:</p>
<ul>
<li>Keypad : same as keypad on keyboard</li>
<li>A : Enter (Accept, OK, next, &#8230;)</li>
<li>Minus (-) : d (Delete)</li>
<li>Home : escape (Exit to previous menu/exit mythfrontend)</li>
<li>Plus (+) : p (Play/pause)</li>
<li>1 : Info</li>
<li>2 : Menu</li>
<li>B + twist wiimote : rewind (if twisted to the left) or fastforward (otherwise) with speed dependant on twist amount.</li>
</ul>
<h3>A comment on twisting:</h3>
<p>Point the wii remote at the screen, and twist from the elbow so that it continues to point at the screen.</p>
<p>The maximum fastforward/rewind speed is 180x. The speeds are dictated by mythfrontend itself. When you rotate the wiimote, you will feel a slight vibration (0.05 seconds) to let you know you have gone up or down a speed segment. To stop fastforwarding/rewinding, simply let go of B.</p>
<p>Beware: there is no power saving built in - however you should be able to turn the wiimote off (power button) when not in use, and turn it back on by holding down 1 and 2 to make it sync.</p>
<p>I know this post is a bit of an info burst, I just want to get this out there so other people can hack with it and give me some feedback. Let me know what you think!</p>
<h3>Known bugs:</h3>
<p>Everything! This is pre-alpha software, don&#8217;t blame me if it messes up your computer! (It should be fine though&#8230;) Biggest known bug at the moment is with key repeats being really slow/unreliable.</p>
<p style="text-align: center;"><strong>ENJOY!<br />
(and let me know what you think in the comments)</strong></p>
<div style="margin-top: 10px; height: 15px;" class="zemanta-pixie"><a class="zemanta-pixie-a" href="http://reblog.zemanta.com/zemified/a8dcc3d0-8dce-4fdc-a906-fe3028caae05/" title="Zemified by Zemanta"><img style="border: medium none ; float: right;" class="zemanta-pixie-img" src="http://img.zemanta.com/reblog_c.png?x-id=a8dcc3d0-8dce-4fdc-a906-fe3028caae05" alt="Reblog this post [with Zemanta]"></a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.benjiegillam.com/2008/09/mythpywii-a-wiimote-interface-to-mythtv-using-python/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Ever Wondered How Many Firefox Tabs You Have Open?</title>
		<link>http://www.benjiegillam.com/2008/09/ever-wondered-how-many-firefox-tabs-you-have-open/</link>
		<comments>http://www.benjiegillam.com/2008/09/ever-wondered-how-many-firefox-tabs-you-have-open/#comments</comments>
		<pubDate>Tue, 09 Sep 2008 15:36:18 +0000</pubDate>
		<dc:creator>Benjie</dc:creator>
		
		<category><![CDATA[Code]]></category>

		<category><![CDATA[Computers]]></category>

		<category><![CDATA[Internet]]></category>

		<category><![CDATA[Linux]]></category>

		<category><![CDATA[Adobe Flash]]></category>

		<category><![CDATA[JavaScript]]></category>

		<category><![CDATA[Mozilla Firefox 3]]></category>

		<category><![CDATA[Tab]]></category>

		<guid isPermaLink="false">http://www.benjiegillam.com/?p=116</guid>
		<description><![CDATA[Image via Wikipedia 
To find out, open Tools &#62; Error Console, and copy and paste this lump of javascript into the &#8220;code&#8221; box and press enter:

javascript:var w=Components.classes['@mozilla.org/appshell/window-mediator;1'].getService(Components.interfaces.nsIWindowMediator).getEnumerator('navigator:browser'),t=0;while(w.hasMoreElements())t+=w.getNext().document.getElementById(&#34;content&#34;).mTabs.length;alert(&#34;You have &#34;+t+&#34; tabs open&#34;);

I&#8217;ve just closed 48 tabs, and found that there was still loads of tabs open (and I didn&#8217;t want to continue counting) so I wrote [...]]]></description>
			<content:encoded><![CDATA[<div class="zemanta-img" style="margin: 1em; float: right; display: block;"><a href="http://en.wikipedia.org/wiki/Image:Firefox-logo.svg"><img style="border: medium none ; display: block;" src="http://upload.wikimedia.org/wikipedia/en/thumb/e/e3/Firefox-logo.svg/202px-Firefox-logo.svg.png" alt="Mozilla Firefox Icon" height="124" width="130"></a><span class="zemanta-img-attribution">Image via <a href="http://en.wikipedia.org/wiki/Image:Firefox-logo.svg">Wikipedia</a> </span></div>
<p>To find out, open Tools &gt; Error Console, and copy and paste this lump of javascript into the &#8220;code&#8221; box and press enter:<br />
<code class="source">
javascript:<span class="enscript-keyword">var</span> w=Components.classes[<span class="enscript-string">'@mozilla.org/appshell/window-mediator;1'</span>].getService(Components.interfaces.nsIWindowMediator).getEnumerator(<span class="enscript-string">'navigator:browser'</span>),t=0;<span class="enscript-keyword">while</span>(w.hasMoreElements())t+=w.getNext().document.getElementById(<span class="enscript-string">&quot;content&quot;</span>).mTabs.length;alert(<span class="enscript-string">&quot;You have &quot;</span>+t+<span class="enscript-string">&quot; tabs open&quot;</span>);</code>
<br />
I&#8217;ve just closed 48 tabs, and found that there was still loads of tabs open (and I didn&#8217;t want to continue counting) so I wrote this code (inspired by <a title="Open Tab Count firefox extension" href="https://addons.mozilla.org/en-US/firefox/addon/8363" target="_blank">Open Tab Count</a> firefox extension) and found I had 77 still open! For those of you who&#8217;s mental arithmetic is poor, that&#8217;s a total of <strong>125 tabs</strong>! And <a class="zem_slink" title="Mozilla Firefox 3" rel="wikipedia" href="http://en.wikipedia.org/wiki/Mozilla_Firefox_3">firefox 3</a> still runs really smoothly with little delay when changing tabs, and my system is using less than 2 GB of it&#8217;s available 4GB of <a class="zem_slink" title="Random access memory" rel="wikipedia" href="http://en.wikipedia.org/wiki/Random_access_memory">RAM</a>. Now, I think that&#8217;s pretty impressive, and would like to see Google Chrome compete with that with it&#8217;s one-process-per-tab design! (If only FF3s <a class="zem_slink" title="JavaScript" rel="wikipedia" href="http://en.wikipedia.org/wiki/JavaScript">JS</a> was as fast&#8230;)</p>
<p>Whilst I am talking about browsers, I feel I should moan that <a class="zem_slink" title="Adobe Flash" rel="wikipedia" href="http://en.wikipedia.org/wiki/Adobe_Flash">Flash 10</a> for GNU/Linux is still really unstable, I have to restart firefox a couple of times a day because it&#8217;s audio gets corrupted or it stops working and just displays a white box in firefox. If only I could restart flash without restarting firefox&#8230; Can I do that?</p>
<h6 class="zemanta-related-title" style="font-size: 1em;">Related articles by Zemanta</h6>
<ul class="zemanta-article-ul">
<li class="zemanta-article-ul-li"><a href="http://lifehacker.com/5044518/enable-chromes-best-features-in-firefox">Enable Chrome&#8217;s Best Features in Firefox [Firefox]</a></li>
</ul>
<div style="margin-top: 10px; height: 15px;" class="zemanta-pixie"><a class="zemanta-pixie-a" href="http://reblog.zemanta.com/zemified/3c6b13d5-6170-4311-9dbd-1569799d4bb7/" title="Zemified by Zemanta"><img style="border: medium none ; float: right;" class="zemanta-pixie-img" src="http://img.zemanta.com/reblog_c.png?x-id=3c6b13d5-6170-4311-9dbd-1569799d4bb7" alt="Reblog this post [with Zemanta]"></a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.benjiegillam.com/2008/09/ever-wondered-how-many-firefox-tabs-you-have-open/feed/</wfw:commentRss>
		</item>
		<item>
		<title>John Lewis Just Snail Mailed Me&#8230;</title>
		<link>http://www.benjiegillam.com/2008/09/john-lewis-just-snail-mailed-me/</link>
		<comments>http://www.benjiegillam.com/2008/09/john-lewis-just-snail-mailed-me/#comments</comments>
		<pubDate>Fri, 05 Sep 2008 12:23:37 +0000</pubDate>
		<dc:creator>Benjie</dc:creator>
		
		<category><![CDATA[Hardware]]></category>

		<category><![CDATA[Personal]]></category>

		<category><![CDATA[Component video]]></category>

		<category><![CDATA[Currys]]></category>

		<category><![CDATA[High-definition television]]></category>

		<category><![CDATA[High-definition video]]></category>

		<category><![CDATA[Television]]></category>

		<guid isPermaLink="false">http://www.benjiegillam.com/?p=115</guid>
		<description><![CDATA[Image via Wikipedia 
&#8230; And told me I can have the TV (LG 42LG6000) at just £699.98 - to match the price at Currys - saving me £49.02 (towards the HTPC  )! WHY DIDN&#8217;T THEY PHONE ME?! I could have ordered it yesterday (when I phoned them&#8230;) and had it 24 hours earlier!
I phoned [...]]]></description>
			<content:encoded><![CDATA[<div class="zemanta-img" style="margin: 1em; float: right; display: block;"><a href="http://commons.wikipedia.org/wiki/Image:Common_Video_Resolutions_2.svg"><img style="border: medium none; display: block;" src="http://upload.wikimedia.org/wikipedia/commons/thumb/a/a2/Common_Video_Resolutions_2.svg/202px-Common_Video_Resolutions_2.svg.png" alt="New chart for video resolution template." /></a><span class="zemanta-img-attribution">Image via <a href="http://commons.wikipedia.org/wiki/Image:Common_Video_Resolutions_2.svg">Wikipedia</a> </span></div>
<p>&#8230; And told me I can have the TV (LG <a title="42LG6000 at John Lewis" href="http://www.johnlewis.com/230480958/Product.aspx" target="_blank">42LG6000</a>) at just £699.98 - to match the price at <a class="zem_slink" title="Currys" rel="homepage" href="http://www.currys.co.uk/">Currys</a> - saving me £49.02 (towards the HTPC <img src='http://www.benjiegillam.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> )! WHY DIDN&#8217;T THEY PHONE ME?! I could have ordered it yesterday (when I phoned them&#8230;) and had it 24 hours earlier!</p>
<p>I phoned them, confirmed the sale and paid over the phone, and its being delivered in about a weeks time!</p>
<p>I&#8217;M SO EXCITED! AHAHAHAHAAAHAHAHAHAAAHAHAAA (manic laughter&#8230; if you need a better impression, ask Jem).</p>
<p>NEW TV! If only I had some stuff to make use of it on - we don&#8217;t have anything <a class="zem_slink" title="High-definition video" rel="wikipedia" href="http://en.wikipedia.org/wiki/High-definition_video">High Definition</a> at the moment&#8230; And I&#8217;m not sure we&#8217;re gunna get some for a while&#8230; Oh well, the screens the important thing, finally I can enjoy the beauty of <a class="zem_slink" title="Wii" rel="wikipedia" href="http://en.wikipedia.org/wiki/Wii">Wii</a> over <a class="zem_slink" title="Component video" rel="wikipedia" href="http://en.wikipedia.org/wiki/Component_video">component video</a> cable (rather than SCART rubbish), and have an insanely large computer monitor! I wonder if I have the spare parts around to make a makeshift low-powered media PC. We really need a desk to put it on.</p>
<p>SO EXCITED!</p>
<div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><a class="zemanta-pixie-a" title="Zemified by Zemanta" href="http://reblog.zemanta.com/zemified/c9698792-33f2-402e-9d42-d8f5a9a20233/"><img class="zemanta-pixie-img" style="border: medium none; float: right;" src="http://img.zemanta.com/reblog_c.png?x-id=c9698792-33f2-402e-9d42-d8f5a9a20233" alt="Reblog this post [with Zemanta]" /></a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.benjiegillam.com/2008/09/john-lewis-just-snail-mailed-me/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Married Life&#8230;</title>
		<link>http://www.benjiegillam.com/2008/09/married-life/</link>
		<comments>http://www.benjiegillam.com/2008/09/married-life/#comments</comments>
		<pubDate>Fri, 05 Sep 2008 09:01:02 +0000</pubDate>
		<dc:creator>Benjie</dc:creator>
		
		<category><![CDATA[Hardware]]></category>

		<category><![CDATA[Linux]]></category>

		<category><![CDATA[MythTV]]></category>

		<category><![CDATA[Personal]]></category>

		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[Wedding]]></category>

		<category><![CDATA[Artemis]]></category>

		<category><![CDATA[High-definition television]]></category>

		<category><![CDATA[Home theater PC]]></category>

		<category><![CDATA[Television]]></category>

		<guid isPermaLink="false">http://www.benjiegillam.com/?p=114</guid>
		<description><![CDATA[&#8230; is great! For those of you who don&#8217;t know, I got married last month (and then spent 2 weeks on honeymoon in Athens!) - it was fantastic, though very very hot. During the trip we kept a moblog - which you can view here (little point repeating the content on this blog!). We&#8217;ve now [...]]]></description>
			<content:encoded><![CDATA[<p>&#8230; is great! For those of you who don&#8217;t know, I got married last month (and then spent 2 weeks on honeymoon in <a class="zem_slink" title="Athens" rel="wikipedia" href="http://en.wikipedia.org/wiki/Athens">Athens</a>!) - it was fantastic, though very very hot. During the trip we kept a <a title="Mobile Blog - see Wikipedia" href="http://en.wikipedia.org/wiki/Moblog" target="_blank">moblog</a> - which you can <a title="Jemjie's Moblog" href="http://www.moblog.net/jemjie/" target="_blank">view here</a> (little point repeating the content on this blog!). We&#8217;ve now moved into our new flat, unpacked, got a kitten, <a title="Artemis Gillam" href="http://www.moblog.net/view/848125/artemis-the-kitten" target="_blank">Artemis</a> Gillam (seen here curled up next to my keyboard), and FINALLY have internet again, and now are both back to work. Yay. <img src='http://www.benjiegillam.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Hopefully soon we&#8217;ll have our new <a class="zem_slink" title="Television" rel="wikipedia" href="http://en.wikipedia.org/wiki/Television">TV</a> (a 42&#8243; LG <a title="LG 42LG6000 at John Lewis" href="http://www.johnlewis.com/230480958/Product.aspx" target="_blank">42LG6000</a> LCD 1080p TV, John Lewis are currently price-matching it for us with Currys (£749 -&gt; £699.99)) which I am sure will be the subject of many blog posts in the future whilst I try and build the perfect <a class="zem_slink" title="Home theater PC" rel="wikipedia" href="http://en.wikipedia.org/wiki/Home_theater_PC">HTPC</a> for it (running <a class="zem_slink" title="MythTV" rel="wikipedia" href="http://en.wikipedia.org/wiki/MythTV">MythTV</a> of course!) and pimp it out with compiz, allow controlling of it from a <a title="Wiimote - Wii Remote" href="http://en.wikipedia.org/wiki/Wii_Remote" target="_blank">Wiimote</a>, and all that jazz. Sounds like fun! Hopefully I can get a little more hardcore in my hacking of the OS (as it doesn&#8217;t have to be stable in the short term, unlike my work PC) - and this is also the perfect opportunity for me to brush up on my python skills, rather than doing everything in <a class="zem_slink" title="PHP" rel="wikipedia" href="http://en.wikipedia.org/wiki/PHP">PHP</a>! (When you know one language so well, its hard not to neglect all the others, even if they are technically better in many ways&#8230;)</p>
<p>Whilst we&#8217;re on the subject of the TV - though I have not received it yet, there is one thing I was surprised to find when I went and viewed it - the TV, when on it&#8217;s stand, is *very* wobbly. A gentle touch of the finger is enough to move it up and down (though not rotate it on it&#8217;s stand) - and it wobbles for a good few seconds before coming back to stationary. Compared to other similarly sized TVs of other brands it is very noticeable - however it does not seem to be about to topple over, even when you are a little more vigorous with it, so I suppose it is nothing to worry too much about&#8230; The kitten should not be able to do it too much damage!</p>
<div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><a class="zemanta-pixie-a" title="Zemified by Zemanta" href="http://reblog.zemanta.com/zemified/6438cd77-346d-40d7-85aa-5d71dcb0573f/"><img class="zemanta-pixie-img" style="border: medium none; float: right;" src="http://img.zemanta.com/reblog_c.png?x-id=6438cd77-346d-40d7-85aa-5d71dcb0573f" alt="Reblog this post [with Zemanta]" /></a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.benjiegillam.com/2008/09/married-life/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Ubuntu NFS Home Directory Issues</title>
		<link>http://www.benjiegillam.com/2008/05/ubuntu-nfs-home-directory-issues/</link>
		<comments>http://www.benjiegillam.com/2008/05/ubuntu-nfs-home-directory-issues/#comments</comments>
		<pubDate>Sat, 24 May 2008 09:39:14 +0000</pubDate>
		<dc:creator>Benjie</dc:creator>
		
		<category><![CDATA[Computers]]></category>

		<category><![CDATA[Linux]]></category>

		<category><![CDATA[fixes]]></category>

		<category><![CDATA[GNOME Display Manager]]></category>

		<category><![CDATA[Home directory]]></category>

		<category><![CDATA[NFS]]></category>

		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://www.benjiegillam.com/?p=112</guid>
		<description><![CDATA[
Image by Blyzz via Flickr

If you choose to mount over NFS just one of your user&#8217;s home directories (e.g. /home/jem) under Ubuntu, then you may come accross issues such as failure to log in, the screen freezing (but mouse still moving), loss of configuration data (e.g. icons in your panels), being told that your login [...]]]></description>
			<content:encoded><![CDATA[<div class="zemanta-img" style="margin: 1em; float: right;"><a href="http://www.flickr.com/photos/29335908@N00/2496064731" target="_blank"><img style="border: medium none; display: block;" src="http://farm3.static.flickr.com/2176/2496064731_25750fe13f_m.jpg" alt="Horny Humpback" /></a></p>
<p class="zemanta-img-attribution">Image by <a href="http://www.flickr.com/photos/29335908@N00/2496064731" target="_blank">Blyzz</a> via Flickr</p>
</div>
<p>If you choose to <a href="https://help.ubuntu.com/community/SettingUpNFSHowTo">mount over NFS</a> just one of your user&#8217;s home directories (e.g. /home/jem) under <a class="zem_slink" title="Ubuntu (Linux distribution)" rel="homepage" href="http://www.ubuntu.com/" target="_blank">Ubuntu</a>, then you may come accross issues such as failure to log in, the screen freezing (but mouse still moving), loss of configuration data (e.g. icons in your panels), being told that your login session lasted under 10 seconds, and just general instability.</p>
<p>The reason for this is, in Ubuntu&#8217;s rush to get you to the Desktop quickly, it loads up <a class="zem_slink" title="GNOME Display Manager" rel="homepage" href="http://www.gnome.org/projects/gdm" target="_blank">GDM</a> (and possibly auto-logs you in) *before* your <a class="zem_slink" title="Home directory" rel="wikipedia" href="http://en.wikipedia.org/wiki/Home_directory" target="_blank">home directory</a> is mounted over <a class="zem_slink" title="Network File System (protocol)" rel="wikipedia" href="http://en.wikipedia.org/wiki/Network_File_System_%28protocol%29" target="_blank">NFS</a>. This is a simple issue of priorities. However, if you log in before the home directory has been mounted, then gconfd-2 and other similar apps will load (or save) settings to your (supposedly empty) /home/jem on your hard drive. When you give up and log out (e.g. <a class="zem_slink" title="X Window System" rel="wikipedia" href="http://en.wikipedia.org/wiki/X_Window_System" target="_blank">Control-Alt-Backspace</a>, or a proper logout), and log back in again, these programs will still be accessing the wrong settings, because they continue to run in the background.</p>
<p>The solution is to abort Ubuntu&#8217;s Windows-like behaviour of allowing you to log in before everything has started running at boot time - change GDMs priority from 14 to 80 (or some other number). I chose to do this the lazy way, using &#8220;<tt>bum</tt>&#8220;. BUM, the Boot Up Manager, is a simple way to change all things related to booting. It is easy to use, though it does take quite a while (a few minutes!) to start the first time you run it. It must be run in a graphical environment. Simply tick the advanced box, go to the third tab, find gdm, and change its priority up to 80. Save, exit and reboot, and all is well again in the world&#8230; though you may have to restore your settings from a backup, or go through the long process of re-configuring your desktop the way you like it.</p>
<p>Good luck!</p>
<p><fieldset class="zemanta-related" style="margin: 0.5em 0pt 1em; padding: 0pt;"><legend class="zemanta-title">Related articles</legend></p>
<ul class="zemanta-article-ul" style="margin: 1em 0pt 1.5em; padding: 0pt;">
<li class="zemanta-article" style="margin: 0.5em 2em;"><a title="Open in new window" href="http://www.cnet.com/8301-13880_1-9884908-68.html?part=rss&amp;subj=news" target="_blank">Get started faster in Ubuntu</a> [via Zemanta]</li>
<li class="zemanta-article" style="margin: 0.5em 2em;"><a title="Open in new window" href="http://lifehacker.com/379886/load-desktop-backgrounds-immediately-in-linux" target="_blank">Load Desktop Backgrounds Immediately in Linux [How To]</a> [via Zemanta]</li>
</ul>
<p></fieldset></p>
<div class="zemanta-pixie" style="margin: 5px 0pt; width: 100%;"><a class="zemanta-pixie-a" title="Zemified by Zemanta" href="http://www.zemanta.com/"><img class="zemanta-pixie-img" style="border: medium none; float: right;" src="http://img.zemanta.com/pixie.png?x-id=559c713d-f8df-418e-8561-bd51a361a037" alt="" /></a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.benjiegillam.com/2008/05/ubuntu-nfs-home-directory-issues/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
