<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>about:benjie &#187; MythPyWii</title>
	<atom:link href="http://www.benjiegillam.com/tag/mythpywii/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>
	<lastBuildDate>Tue, 06 Apr 2010 14:14:35 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>MythPyWii Power Update (v17)</title>
		<link>http://www.benjiegillam.com/2009/10/mythpywii-power-update-v17/</link>
		<comments>http://www.benjiegillam.com/2009/10/mythpywii-power-update-v17/#comments</comments>
		<pubDate>Sat, 03 Oct 2009 17:37:58 +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[Personal]]></category>
		<category><![CDATA[Open source]]></category>

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



Image via Wikipedia



Thanks to Matthew Zimmerman for sending me his modified version of MythPyWii, it now has power-saving &#8211; after 35 minutes of inactivity the Wiimote turns off. You can download the latest version, as always, here; or you can get this specific version (v17) here.
I love open source!

]]></description>
			<content:encoded><![CDATA[<div class="zemanta-img" style="margin: 1em; display: block;">
<div>
<dl class="wp-caption alignright" style="width: 282px;">
<dt class="wp-caption-dt"><a href="http://commons.wikipedia.org/wiki/Image:Myth_tv_logo.png"><img title="Myth tv logo" src="http://upload.wikimedia.org/wikipedia/commons/6/6a/Myth_tv_logo.png" alt="Myth tv logo" width="272" height="91" /></a></dt>
<dd class="wp-caption-dd zemanta-img-attribution" style="font-size: 0.8em;">Image via <a href="http://commons.wikipedia.org/wiki/Image:Myth_tv_logo.png">Wikipedia</a></dd>
</dl>
</div>
</div>
<p>Thanks to Matthew Zimmerman for sending me his modified version of MythPyWii, it now has power-saving &#8211; after 35 minutes of inactivity the Wiimote turns off. You can download the latest version, as always, <a title="Latest MythPyWii version" href="http://www.benjiegillam.com/code/myth_py_wii.py" target="_blank">here</a>; or you can get this specific version (v17) <a title="MythPyWii revision 17" href="http://www.benjiegillam.com/code/myth_py_wii.r17.py" target="_blank">here</a>.</p>
<p>I love open source!</p>
<div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><a class="zemanta-pixie-a" title="Reblog this post [with Zemanta]" href="http://reblog.zemanta.com/zemified/422a939e-dfa7-48f3-9059-6e69acd0420a/"><img class="zemanta-pixie-img" style="border: medium none ; float: right;" src="http://img.zemanta.com/reblog_c.png?x-id=422a939e-dfa7-48f3-9059-6e69acd0420a" alt="Reblog this post [with Zemanta]" /></a><span class="zem-script more-related pretty-attribution"><script src="http://static.zemanta.com/readside/loader.js" type="text/javascript"></script></span></div>
]]></content:encoded>
			<wfw:commentRss>http://www.benjiegillam.com/2009/10/mythpywii-power-update-v17/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<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 &#8211; 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 &#8211; 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 &#8211; 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>
		<slash:comments>4</slash:comments>
		</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>
<p><strong>UPDATE</strong>: If you&#8217;re getting errors like:</p>
<blockquote><p>$ myth_py_wii.py<br />
Please open Mythfrontend and then press 1&amp;2 on the wiimote&#8230;<br />
Connected to a wiimote <img src='http://www.benjiegillam.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
Logged in to MythFrontend<br />
TypeError: wmcb() takes exactly 2 arguments (3 given)<br />
TypeError: wmcb() takes exactly 2 arguments (3 given)<br />
TypeError: wmcb() takes exactly 2 arguments (3 given)<br />
TypeError: wmcb() takes exactly 2 arguments (3 given)</p></blockquote>
<p>Then you have a more up to date version of cwiid than me. The fix is simple &#8211; change line 141:<br />
def wmcb(self, messages):<br />
to:<br />
def wmcb(self, messages<strong>, timeIgnore</strong>):</p>
<p>Thanks to Mike H for pointing out this issue.</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="Reblog this post [with Zemanta]" href="http://reblog.zemanta.com/zemified/cee41f52-af92-4108-aa88-c7472551c21d/"><img class="zemanta-pixie-img" style="border: medium none; float: right;" src="http://img.zemanta.com/reblog_c.png?x-id=cee41f52-af92-4108-aa88-c7472551c21d" alt="Reblog this post [with Zemanta]" /></a><span class="zem-script more-related pretty-attribution"><script src="http://static.zemanta.com/readside/loader.js" type="text/javascript"></script></span></div>
]]></content:encoded>
			<wfw:commentRss>http://www.benjiegillam.com/2008/09/new-minor-mythpywii-release-r15/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</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!) &#8211; 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; &#8211; 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>
		<slash:comments>6</slash:comments>
		</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 &#8211; minor technical hitch &#8211; 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 &#8211; 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 &#8211; 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) &#8211; 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>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MythPyWii &#8211; 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) &#8211; but those that exist only seem to use the Wiimote as a keyboard &#8211; 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; &#8211; 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 &#8211; 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; &#8211; 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 &#8211; 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>". 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'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; "Enable Network Remote Control interface", "Network Remote Control Port: 6546"</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, ...)</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't blame me if it messes up your computer! (It should be fine though...) 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>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>
