<?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>dyadica.net &#187; Wii</title>
	<atom:link href="http://blog.dyadica.net/archives/category/wii/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.dyadica.net</link>
	<description>Fun and Games in the Dyadic Sea</description>
	<lastBuildDate>Wed, 21 Jul 2010 14:04:27 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Adding The Step Event</title>
		<link>http://blog.dyadica.net/archives/adding-the-step-event</link>
		<comments>http://blog.dyadica.net/archives/adding-the-step-event#comments</comments>
		<pubDate>Fri, 31 Jul 2009 22:26:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Balance Board]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Wii]]></category>
		<category><![CDATA[Balance]]></category>
		<category><![CDATA[balance board]]></category>
		<category><![CDATA[Quadrant]]></category>
		<category><![CDATA[Quadzone]]></category>
		<category><![CDATA[Stepping]]></category>
		<category><![CDATA[WiiFit]]></category>
		<category><![CDATA[wiimote]]></category>
		<category><![CDATA[wiimoteLib]]></category>

		<guid isPermaLink="false">http://blog.dyadica.net/?p=2337</guid>
		<description><![CDATA[In this Instruction we are going to modify WiimoteLib by including a new event trigger that is activated upon a change in either Quad or Zone value.
This is a very useful addition that allows for ...]]></description>
			<content:encoded><![CDATA[<p>In this Instruction we are going to modify WiimoteLib by including a new event trigger that is activated upon a change in either Quad or Zone value.</p>
<p>This is a very useful addition that allows for &#8220;singular&#8221; triggering so that you don&#8217;t have to rely on &#8220;flag checks&#8221; within the standard WiimoteState loop and thus allowing the Libary to do all the work!</p>
<p>Before we start, this instruction assumes you have previously completed the <a title="Areas Quad and Zone" href="http://blog.dyadica.net/pages/balance-board/areas-quad-and-zone">Areas Quad and Zone</a> Instruction.</p>
<p>Start off by opening up the Events.cs file and add the following code below the public class WiimoteChangedEventArgs:<span id="more-2337"></span></p>
<blockquote><p>/// &lt;summary&gt;<br />
/// Argument sent through the BalanceBoardStepEvent<br />
/// &lt;/summary&gt;<br />
public class BalanceBoardStepEventArgs : EventArgs<br />
{<br />
/// &lt;summary&gt;<br />
/// The current state of the Balance Board<br />
/// &lt;/summary&gt;<br />
public BalanceBoardState BalanceBoard;</p>
<p>/// &lt;summary&gt;<br />
/// The Type of trigger that activated the event<br />
/// &lt;/summary&gt;<br />
public StepType StepType;</p>
<p>/// &lt;summary&gt;<br />
/// Constructor<br />
/// &lt;/summary&gt;<br />
/// &lt;param name=&#8221;bb&#8221;&gt;Wiimote Balance Board State&lt;/param&gt;<br />
/// &lt;param name=&#8221;type&#8221;&gt;Step trigger type: Standard/Damped Quad/Zone&lt;/param&gt;<br />
public BalanceBoardStepEventArgs(BalanceBoardState bb, StepType type)<br />
{<br />
BalanceBoard = bb;<br />
StepType = type;<br />
}<br />
}</p></blockquote>
<p>What we have done here is create a new class that provides access to two arguments:</p>
<ol>
<li>BalanceBoardState</li>
<li>StepType</li>
</ol>
<p>By passing BalanceBoardState we are provided direct access to all the relevant Balance Board calls that we would normally have via WiimoteState. The StepType argument provides us with a reference to the trigger that we can then use to filter/output a desired response etc.</p>
<p>To define StepType open up DataTypes.cs and add the following enum block below the BalanceBoardState struct:</p>
<blockquote><p>/// &lt;summary&gt;<br />
/// The type of Step Triggered<br />
/// &lt;/summary&gt;<br />
[DataContract]<br />
public enum StepType<br />
{<br />
/// &lt;summary&gt;<br />
/// Zone Change<br />
/// &lt;/summary&gt;<br />
Zone = 0,<br />
/// &lt;summary&gt;<br />
/// Quad Change<br />
/// &lt;/summary&gt;<br />
Quad = 1,<br />
};</p></blockquote>
<p>Next we need to add this enum to the BalanceBoardState struct itself. We do this as follows:</p>
<blockquote><p>/// &lt;summary&gt;<br />
/// The Action which has Triggered the Step Event<br />
/// &lt;/summary&gt;<br />
[DataMember]<br />
public StepType StepType;</p></blockquote>
<p>With this done we now have all the foundations needed for the &#8220;Event&#8221;, now we need to add it! Open up Wiimote.cs and add the following block at the top just below the equivalent WiimoteChanged and WiimoteExtensionChanged handles.</p>
<blockquote><p>/// &lt;summary&gt;<br />
/// Event raised when a Balance Board Step is Triggered<br />
/// &lt;/summary&gt;<br />
public event EventHandler&lt;BalanceBoardStepEventArgs&gt; BalanceBoardStep;</p></blockquote>
<p>This defines our brand new BalanceBoardStep handle. With this in place we now need to be able to trigger it.  As we are going to use either a change in Zone or Quad location to trigger the call.</p>
<p>Update the Area struct (DataTypes.cs) to include two additional definitions as shown below:</p>
<blockquote><p>/// &lt;summary&gt;<br />
/// Last Balance Board Zone Area<br />
/// &lt;/summary&gt;<br />
[DataMember]<br />
public string LastZone;</p>
<p>/// &lt;summary&gt;<br />
/// Last Balance Board Quad Area<br />
/// &lt;/summary&gt;<br />
[DataMember]<br />
public string LastQuad;</p></blockquote>
<p>These 2 new definitions simply provide us with a location to archive the states of both Zone and Quad. I chose to add them like this as there is likely to be other occasions when access to this information would provide useful! Also facility is provided for standard WiimoteState access (just in case).</p>
<p>With this complete we now need to add the code to facilitate the trigger. Still within Wiimote.cs add the following two blocks just below the Area.Quad and Area.Zone updates within ParseExtension:</p>
<blockquote><p>#region step filtering quad</p>
<p>// calculate if there is a Quad Step<br />
if (mWiimoteState.BalanceBoardState.Area.CurrentQuad != mWiimoteState.BalanceBoardState.Area.LastQuad)<br />
{<br />
// update the archived Quad<br />
mWiimoteState.BalanceBoardState.Area.LastQuad = mWiimoteState.BalanceBoardState.Area.CurrentQuad;<br />
// post a Standard Step event<br />
if (BalanceBoardStep != null)<br />
{ BalanceBoardStep(this, new BalanceBoardStepEventArgs(mWiimoteState.BalanceBoardState, StepType.Quad)); }<br />
}</p>
<p>#endregion step filtering quad</p>
<p>#region step filtering zone</p>
<p>// calculate if there is a Zone Step<br />
if (mWiimoteState.BalanceBoardState.Area.CurrentZone != mWiimoteState.BalanceBoardState.Area.LastZone)<br />
{<br />
// update the archived Zone<br />
mWiimoteState.BalanceBoardState.Area.LastZone = mWiimoteState.BalanceBoardState.Area.CurrentZone;<br />
// post a Standard Step event<br />
if (BalanceBoardStep != null)<br />
{ BalanceBoardStep(this, new BalanceBoardStepEventArgs(mWiimoteState.BalanceBoardState, StepType.Zone)); }<br />
}</p>
<p>#endregion step filtering zone</p></blockquote>
<p>All we are doing here is comparing states. If there is a change we then call the Event and also update the archived state for the next comparison.</p>
<p>With this done our new BalanceBoardStep Event is now complete.. well nearly!</p>
<p>So how do we use it? The easy answer is in exactly the same way you would both the UpdateWiimoteChanged and UpdateExtensionChanged Events provided in the Wiimote Test Example that comes with WiimoteLib.</p>
<p>First within WiimoteInfo.cs create a new delegate referance below the 2 existing ones for Wiimote State/Extension:</p>
<blockquote><p>private delegate void UpdateBalanceBoardStepDelegate(BalanceBoardStepEventArgs args);</p></blockquote>
<p>Next we need to add a function to invoke the delegate, this allows for cross thread calls and is triggered a call from the main application</p>
<blockquote><p>public void UpdateStep(BalanceBoardStepEventArgs args)<br />
{<br />
BeginInvoke(new UpdateBalanceBoardStepDelegate(UpdateBalanceBoardStep), args);<br />
}</p></blockquote>
<p>Finally we add our work function. This function receives the Event and then uses the arguments provided to detirmine the required action  to take in an equivalent manner of  the existing Wiimote State/Extension functions.</p>
<blockquote><p>/// &lt;summary&gt;<br />
/// Board Step example to show triggering of action via one of the two current step filters<br />
/// Quad &#8211; Triggered via a change in Quad Area<br />
/// Zone &#8211; Triggered via a change in Zone Area<br />
/// &lt;/summary&gt;<br />
private void UpdateBalanceBoardStep(BalanceBoardStepEventArgs args)<br />
{<br />
BalanceBoardState bb = args.BalanceBoard;</p>
<p>switch (args.StepType)<br />
{<br />
case StepType.Quad:<br />
// Quadrant output usefull for WiiFit Step game equivalents<br />
lblQuad.Text = bb.Area.CurrentQuad;<br />
Console.WriteLine(&#8220;Call from quad step&#8221;);<br />
break;<br />
case StepType.Zone:<br />
// Quadzone output usefull for WiiFit Step game equivalents<br />
lblZone.Text = bb.Area.CurrentZone;<br />
Console.WriteLine(&#8220;Call from zone step&#8221;);<br />
break;<br />
}<br />
}</p></blockquote>
<p>We now have everything in place but before we can use the new Event we need to register it with the Wiimote etc as you would with the existing ones.</p>
<p>In your connection call add (MultipleWiimoteForm.cs/SingleWiimoteForm.cs) the following below the WiimoteChanged and WiimoteExtensionChanged register calls:</p>
<blockquote><p>wm.BalanceBoardStep += wm_BalanceBoardStep;</p></blockquote>
<p>Finally also add the corresponding function which is used to call the update within the WiimoteInfo.cs just below the equivalent State/Extension ones:</p>
<blockquote><p>void wm_BalanceBoardStep(object sender, BalanceBoardStepEventArgs e)<br />
{<br />
WiimoteInfo wi = mWiimoteMap[((Wiimote)sender).ID];<br />
wi.UpdateStep(e);<br />
}</p></blockquote>
<p>That&#8217;s it debug the program and enjoy&#8230;!</p>
<p><strong>Update: Step ON and Step OFF</strong><br />
<a id="update" class="update"></a></p>
<p>Ok we could stop here but lets expand things a little bit more by adding to the step Event facility a check too see weather we are &#8220;ON/OFF&#8221; the Board.</p>
<p>To do this we are going to add a check for a defined &#8220;Minimum Weight&#8221;. If the WeightKg is greater than the Minimum Weight then we are classed as being &#8220;On&#8221; the board. Simple eh! Start off by adding a the following new definitions to the BalanceBoardState struct:</p>
<blockquote><p>/// &lt;summary&gt;<br />
/// Are we on the Balance Board<br />
/// &lt;/summary&gt;<br />
[DataMember]<br />
public bool OnBoard;</p>
<p>/// &lt;summary&gt;<br />
/// Balance Board Minimum Weight Tolerance<br />
/// &lt;/summary&gt;<br />
[DataMember]<br />
public double Tolerance;</p></blockquote>
<p>Before we can use these new definitions we need to initialize them by assigning some default values. At the top of Wiimote.cs just above the Default constructor add the following :</p>
<blockquote><p>// Temporary Defaults<br />
private double Tolerance = 6;</p></blockquote>
<p>This enables access to the default value for customization at start up. This value can then be updated at run time, why? I have currently access to 2 boards. At rest one reads 2kg and the other 5kg, go figure!</p>
<p>Add the following to the SetBalanceBoardDefaults() function to set the default values.</p>
<blockquote><p>// set the default min weight used to trigger board use etc<br />
mWiimoteState.BalanceBoardState.Tolerance = Tolerance;<br />
mWiimoteState.BalanceBoardState.OnBoard = false;</p></blockquote>
<p>Please note I always assume the user not to be on the Board at startup. With these definitions in place we can now use them to check for both the stepping On and Off events but before we do that we need to add them to the StepType enum within DataTypes.cs as follows:</p>
<blockquote><p>/// &lt;summary&gt;<br />
/// Step On<br />
/// &lt;/summary&gt;<br />
On = 2,<br />
/// &lt;summary&gt;<br />
/// Step Off<br />
/// &lt;/summary&gt;<br />
Off = 3,</p></blockquote>
<p>Ok, now everything is in place lets use it. The next step is to enclose the existing Quad Zone and Step code in an IF statement that polls the weight against the tolerance. Here is our statement without the contents:</p>
<blockquote><p>if (mWiimoteState.BalanceBoardState.WeightKg &gt; mWiimoteState.BalanceBoardState.Tolerance)<br />
{<br />
// step ON event check  &#8211; (we will cover this next)<br />
// calculate and set values for Quad<br />
// calculate and set values for Zone<br />
// step filtering Quad<br />
// step filtering Zone<br />
}<br />
else<br />
{<br />
// step OFF event check &#8211; (we will cover this next)<br />
}</p></blockquote>
<p>Please update your Wiimote.cs to reflect the above. Once complete the next step is to add Triggers for both the OFF and On events. These event call are similar to those of Quad and Zone. Replace the //step On event check comment with the following block:</p>
<blockquote><p>#region On Board Step Event Check</p>
<p>if (!mWiimoteState.BalanceBoardState.OnBoard)<br />
{<br />
mWiimoteState.BalanceBoardState.OnBoard = true;<br />
if (BalanceBoardStep != null)<br />
{ BalanceBoardStep(this, new BalanceBoardStepEventArgs(mWiimoteState.BalanceBoardState, StepType.On)); }<br />
}</p>
<p>#endregion On Board Step Event Check</p></blockquote>
<p>Next replace the // step OFF event check comment with:</p>
<blockquote><p>#region Off Board Step Event Check</p>
<p>if (mWiimoteState.BalanceBoardState.OnBoard)<br />
{<br />
mWiimoteState.BalanceBoardState.OnBoard = false;<br />
if (BalanceBoardStep != null)<br />
{ BalanceBoardStep(this, new BalanceBoardStepEventArgs(mWiimoteState.BalanceBoardState, StepType.Off)); }<br />
}</p>
<p>#endregion Off Board Step Event Check</p></blockquote>
<p>Finally all we need to do is update the UpdateBalanceBoardStep function within WiimoteInfo.cs by adding the following cases to the switch statement:</p>
<blockquote><p>case StepType.On:<br />
// Your Code<br />
break;<br />
case StepType.Off:<br />
// Your Code<br />
break;</p></blockquote>
<p>There you have it! additional facility for logging when a user gets ON/OFF the balance board.</p>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 3051px; width: 1px; height: 1px;">
<p><a id="update" class="update &gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Ok we could stop here but lets expand things a little bit more by adding to the step Event facility a check too see weather we are">To do this we are going to add a check for a defined &#8220;Minimum Weight&#8221;. If the WeightKg is greater than the Minimum Weight then we are classed as being &#8220;On&#8221; the board. Simple eh! Start off by adding a the following new definitions to the BalanceBoardState struct:</a></p>
<blockquote><p><a id="update" class="update &gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Ok we could stop here but lets expand things a little bit more by adding to the step Event facility a check too see weather we are">/// &lt;summary&gt;<br />
/// Are we on the Balance Board<br />
/// &lt;/summary&gt;<br />
[DataMember]<br />
public bool OnBoard;</a></p>
<p><a id="update" class="update &gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Ok we could stop here but lets expand things a little bit more by adding to the step Event facility a check too see weather we are">/// &lt;summary&gt;<br />
/// Balance Board Minimum Weight Tolerance<br />
/// &lt;/summary&gt;<br />
[DataMember]<br />
public double Tolerance;</a></p></blockquote>
<p><a id="update" class="update &gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Ok we could stop here but lets expand things a little bit more by adding to the step Event facility a check too see weather we are">Before we can use these new definitions we need to initialize them by assigning some default values. At the top of Wiimote.cs just above the Default constructor add the following :</a></p>
<blockquote><p><a id="update" class="update &gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Ok we could stop here but lets expand things a little bit more by adding to the step Event facility a check too see weather we are">// Temporary Defaults<br />
private double Tolerance = 6;</a></p></blockquote>
<p><a id="update" class="update &gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Ok we could stop here but lets expand things a little bit more by adding to the step Event facility a check too see weather we are">This enables access to the default value for customization at start up. This value can then be updated at run time, why? I have currently access to 2 boards. At rest one reads 2kg and the other 5kg, go figure!</a></p>
<p><a id="update" class="update &gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Ok we could stop here but lets expand things a little bit more by adding to the step Event facility a check too see weather we are">Add the following to the </a><a title="SetBalanceBoardDefaults Function" href="http://blog.dyadica.net/pages/balance-board/grouping-the-cog-systems#update">SetBalanceBoardDefaults()</a> function to set the default values.</p>
<p>// set the default min weight used to trigger board use etc<br />
mWiimoteState.BalanceBoardState.Tolerance = Tolerance;<br />
mWiimoteState.BalanceBoardState.OnBoard = false;</p>
<p>Please note I always assume the user not to be on the Board at startup. With these definitions in place we can now use them to check for both the stepping On and Off events but before we do that we need to add them to the StepType enum within DataTypes.cs as follows:</p>
<blockquote><p>/// &lt;summary&gt;<br />
/// Step On<br />
/// &lt;/summary&gt;<br />
On = 2,<br />
/// &lt;summary&gt;<br />
/// Step Off<br />
/// &lt;/summary&gt;<br />
Off = 3,</p></blockquote>
<p>Ok, now everything is in place lets use it. The next step is to enclose the existing Quad Zone and Step code in an IF statement that polls the weight against the tolerance. Here is our statement without the contents:</p>
<blockquote><p>if (mWiimoteState.BalanceBoardState.WeightKg &gt; mWiimoteState.BalanceBoardState.Tolerance)<br />
{<br />
// step ON event check  &#8211; (we will cover this next)<br />
// calculate and set values for Quad<br />
// calculate and set values for Zone<br />
// step filtering Quad<br />
// step filtering Zone<br />
}<br />
else<br />
{<br />
// step OFF event check &#8211; (we will cover this next)<br />
}</p></blockquote>
<p>Please update your Wiimote.cs to reflect the above. Once complete the next step is to add Triggers for both the OFF and On events. These event call are similar to those of Quad and Zone. Replace the //step On event check comment with the following block:</p>
<blockquote><p>#region On Board Step Event Check</p>
<p>if (!mWiimoteState.BalanceBoardState.OnBoard)<br />
{<br />
mWiimoteState.BalanceBoardState.OnBoard = true;<br />
if (BalanceBoardStep != null)<br />
{ BalanceBoardStep(this, new BalanceBoardStepEventArgs(mWiimoteState.BalanceBoardState, StepType.On)); }<br />
}</p>
<p>#endregion On Board Step Event Check</p></blockquote>
<p>Next replace the // step OFF event check comment with:</p>
<blockquote><p>#region Off Board Step Event Check</p>
<p>if (mWiimoteState.BalanceBoardState.OnBoard)<br />
{<br />
mWiimoteState.BalanceBoardState.OnBoard = false;<br />
if (BalanceBoardStep != null)<br />
{ BalanceBoardStep(this, new BalanceBoardStepEventArgs(mWiimoteState.BalanceBoardState, StepType.Off)); }<br />
}</p>
<p>#endregion Off Board Step Event Check</p></blockquote>
<p>Finally all we need to do is update the UpdateBalanceBoardStep function within WiimoteInfo.cs by adding the following cases to the switch statement:</p>
<blockquote><p>case StepType.On:<br />
// Your Code<br />
break;<br />
case StepType.Off:<br />
// Your Code<br />
break;</p></blockquote>
<p>There you have it! additional facility for logging when a user gets ON/OFF the balance board.</p></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.dyadica.net/archives/adding-the-step-event/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Merging Quadzone and Quadrant</title>
		<link>http://blog.dyadica.net/archives/merging-quadzone-and-quadrant</link>
		<comments>http://blog.dyadica.net/archives/merging-quadzone-and-quadrant#comments</comments>
		<pubDate>Thu, 30 Jul 2009 22:24:13 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Balance Board]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Wii]]></category>
		<category><![CDATA[Area]]></category>
		<category><![CDATA[balance board]]></category>
		<category><![CDATA[Quad]]></category>
		<category><![CDATA[Quadrant]]></category>
		<category><![CDATA[Quadzone]]></category>
		<category><![CDATA[WiiFit]]></category>
		<category><![CDATA[wiimote]]></category>
		<category><![CDATA[wiimoteLib]]></category>
		<category><![CDATA[Zone]]></category>

		<guid isPermaLink="false">http://blog.dyadica.net/?p=2323</guid>
		<description><![CDATA[Here we have another step down the path towards full Balance Board Orientation. This time out we are going to merge the Quadrant and Quadzone functionality into a new collective known as &#8220;Area&#8221; (for want ...]]></description>
			<content:encoded><![CDATA[<p>Here we have another step down the path towards full Balance Board Orientation. This time out we are going to merge the Quadrant and Quadzone functionality into a new collective known as &#8220;Area&#8221; (for want of a better name).</p>
<p>Please note that this instruction assumes familiarity with the <a title="The Quadrant Filter" href="http://blog.dyadica.net/pages/balance-board/the-quadrant-filter">Quadrant</a> and <a title="The Quadzone Filter" href="http://blog.dyadica.net/pages/balance-board/the-quadzone-filter">Quadzone</a> instructions.</p>
<p>Similar to the <a title="Grouping The COG Systems" href="http://blog.dyadica.net/pages/balance-board/grouping-the-cog-systems">Grouping GOG</a> instruction we are going to start by modifying the DataTypes.cs file  by grouping the two existing definitions by grouping them together in a new struct.</p>
<p>Replace both the Quadrant and Quadzone definitions with the following singular block of code:</p>
<blockquote><p>/// &lt;summary&gt;<br />
/// Area of most Weight/COG<br />
/// &lt;/summary&gt;<br />
[DataMember]<br />
public Area Area;</p></blockquote>
<p>Next we are going to add the new struct so that we can use this definition. Below the BalanceBoardState struct add the following code:<span id="more-2323"></span></p>
<blockquote><p>/// &lt;summary&gt;<br />
/// Area Types and Variables<br />
/// &lt;/summary&gt;<br />
[Serializable]<br />
[DataContract]<br />
public struct Area<br />
{<br />
/// &lt;summary&gt;<br />
/// Current Balance Board Zone Area<br />
/// &lt;/summary&gt;<br />
[DataMember]<br />
public string CurrentZone;</p>
<p>/// &lt;summary&gt;<br />
/// Current Balance Board Quad Area<br />
/// &lt;/summary&gt;<br />
[DataMember]<br />
public string CurrentQuad;</p>
<p>}</p></blockquote>
<p>What we have here are 2 definitions for the current Quad and Zone. All we really need to do now is to update the existing Quadrant and Quadzone definitions to reflect the new Area.Quad and Area.Zone setup.</p>
<p>Open up Wiimote.cs and add the following (or replace) the following definitions to the balance board case within ParseExtension. Just below the COG ones:</p>
<blockquote><p>// Shorthand the values for lazyness (Kg)<br />
float TLkg = mWiimoteState.BalanceBoardState.SensorValuesKg.TopLeft;<br />
float TRkg = mWiimoteState.BalanceBoardState.SensorValuesKg.TopRight;<br />
float BLkg = mWiimoteState.BalanceBoardState.SensorValuesKg.BottomLeft;<br />
float BRkg = mWiimoteState.BalanceBoardState.SensorValuesKg.BottomRight;</p></blockquote>
<p>The above stays the same as in the Quadrant and Quadzone instructions. The following is the new Quad:</p>
<blockquote><p>#region calculate and set values for quad</p>
<p>// Merged Version<br />
if (TLkg &gt; TRkg &amp;&amp; TLkg &gt; BRkg &amp;&amp; TLkg &gt; BLkg) { mWiimoteState.BalanceBoardState.Area.CurrentQuad = &#8220;Top Left&#8221;; }<br />
if (TRkg &gt; TLkg &amp;&amp; TRkg &gt; BRkg &amp;&amp; TRkg &gt; BLkg) { mWiimoteState.BalanceBoardState.Area.CurrentQuad = &#8220;Top Right&#8221;; }<br />
if (BLkg &gt; TLkg &amp;&amp; BLkg &gt; BRkg &amp;&amp; BLkg &gt; TRkg) { mWiimoteState.BalanceBoardState.Area.CurrentQuad = &#8220;Bottom Left&#8221;; }<br />
if (BRkg &gt; TLkg &amp;&amp; BRkg &gt; BLkg &amp;&amp; BRkg &gt; TRkg) { mWiimoteState.BalanceBoardState.Area.CurrentQuad = &#8220;Bottom Right&#8221;; }</p>
<p>#endregion calculate and set values for quad</p></blockquote>
<p>And here we have the new Zone:</p>
<blockquote><p>#region calculate and set values for zone</p>
<p>if ((TLkg + TRkg) &gt; (TLkg + BLkg) &amp;&amp;<br />
(TLkg + TRkg) &gt; (TLkg + BLkg) &amp;&amp;<br />
(TLkg + TRkg) &gt; (BLkg + BRkg))<br />
{<br />
mWiimoteState.BalanceBoardState.Area.CurrentZone = &#8220;Top&#8221;;<br />
}</p>
<p>if ((BLkg + BRkg) &gt; (TLkg + BLkg) &amp;&amp;<br />
(BLkg + BRkg) &gt; (TLkg + BLkg) &amp;&amp;<br />
(BLkg + BRkg) &gt; (TLkg + TRkg))<br />
{<br />
mWiimoteState.BalanceBoardState.Area.CurrentZone = &#8220;Bottom&#8221;;<br />
}</p>
<p>if ((TLkg + BLkg) &gt; (TLkg + TRkg) &amp;&amp;<br />
(TLkg + BLkg) &gt; (BLkg + BRkg) &amp;&amp;<br />
(TLkg + BLkg) &gt; (TRkg + BRkg))<br />
{<br />
mWiimoteState.BalanceBoardState.Area.CurrentZone = &#8220;Left&#8221;;<br />
}</p>
<p>if ((TRkg + BRkg) &gt; (TLkg + TRkg) &amp;&amp;<br />
(TRkg + BRkg) &gt; (BLkg + BRkg) &amp;&amp;<br />
(TRkg + BRkg) &gt; (TLkg + BLkg))<br />
{<br />
mWiimoteState.BalanceBoardState.Area.CurrentZone = &#8220;Right&#8221;;<br />
}</p>
<p>#endregion calculate and set values for zone</p></blockquote>
<p>And that&#8217;s it! You can call the new code definitions (ie from within WiimoteInfo.cs) as follows:</p>
<blockquote><p>// Quadrant output can also be run from here<br />
lblQuad.Text = ws.BalanceBoardState.Area.CurrentQuad;</p>
<p>// Quadzone output can also be run from here<br />
lblZone.Text = ws.BalanceBoardState.Area.CurrentZone;</p></blockquote>
<p>So why bother doing this, you may ask&#8230;. Well&#8230;.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.dyadica.net/archives/merging-quadzone-and-quadrant/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Wii Motion Plus Beta Support</title>
		<link>http://blog.dyadica.net/archives/wii-motion-plus-beta-support</link>
		<comments>http://blog.dyadica.net/archives/wii-motion-plus-beta-support#comments</comments>
		<pubDate>Thu, 23 Jul 2009 22:54:58 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Wiimote]]></category>
		<category><![CDATA[hardware]]></category>
		<category><![CDATA[brian peek]]></category>
		<category><![CDATA[wii motion plus]]></category>
		<category><![CDATA[wiimote]]></category>
		<category><![CDATA[wiimoteLib]]></category>

		<guid isPermaLink="false">http://blog.dyadica.net/?p=2319</guid>
		<description><![CDATA[Brian has done it again, check out the following cross-posting from brianpeek.com detailing beta support for the Wii Motion Plus:
I have posted a new version of WiimoteLib as a beta for people to play around ...]]></description>
			<content:encoded><![CDATA[<p>Brian has done it again, check out the following cross-posting from brianpeek.com detailing beta support for the Wii Motion Plus:</p>
<blockquote><p>I have posted a new version of <a href="http://wiimotelib.codeplex.com/" target="_blank">WiimoteLib</a> as a beta for people to play around with the <a href="http://www.amazon.com/dp/B001TOQ8NO/tag=brianpcom-20" target="_blank">Wii MotionPlus accessory</a>.  Please note that this is not a stable release and should only be used if you wish to mess around with the MotionPlus.  Also note that only C# source code is included in this release as it is not a final build.  Here’s the change log:</p>
<p><span style="text-decoration: underline;">v1.8.0.0</span></p>
<ul>
<li>Taiko Drum Master&#8217;s TaTaCon drum controller supported (Dean Herbert)</li>
<li>Bare-bones Wii MotionPlus support (wiibrew.org, testing by Tyler Tolley)</li>
<li>WiimoteTest UI changed to add MotionPlus data
<ul>
<li>Please note that the current version is VERY flakey and may not work at all for you.</li>
<li>Pair your Wiimote, plug in your MotionPlus, call InitializeMotionPlus()</li>
<li>Extensions plugged into the MotionPlus will give wacky results&#8230;not supported&#8230;yet!</li>
<li>Internal changes to perhaps fix some threading issues</li>
</ul>
</li>
</ul>
<p>So remember, it’s a beta, it may not work for you, and the data you’ll get back from the accessory is just the raw data it provides.  You won’t get real orientation values.</p>
<p>That said, head over to <a href="http://wiimotelib.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=30401" target="_blank">CodePlex</a> and give it a try! (Brian Peek)</p></blockquote>
<p>Great work Brian!<a id="update" class="update" /></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.dyadica.net/archives/wii-motion-plus-beta-support/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Dampened and Standard COG</title>
		<link>http://blog.dyadica.net/archives/dampened-and-standard-cog</link>
		<comments>http://blog.dyadica.net/archives/dampened-and-standard-cog#comments</comments>
		<pubDate>Wed, 15 Jul 2009 22:23:55 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Balance Board]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Wii]]></category>
		<category><![CDATA[balance board]]></category>
		<category><![CDATA[Cent]]></category>
		<category><![CDATA[Center Of Gravity]]></category>
		<category><![CDATA[Dampened COG]]></category>
		<category><![CDATA[WiiFit]]></category>
		<category><![CDATA[wiimote]]></category>
		<category><![CDATA[wiimoteLib]]></category>

		<guid isPermaLink="false">http://blog.dyadica.net/?p=2187</guid>
		<description><![CDATA[A bit of history: Inspired by endquotes WPF implementation of COG I developed an equivalent system for WiimoteLib that provides  facility for Dampened COG output. As stated, I find the two systems can be used ...]]></description>
			<content:encoded><![CDATA[<p>A bit of history: Inspired by endquotes <a title="endquotes COG" href="http://www.brianpeek.com/forums/t/928.aspx">WPF implementation of COG</a> I developed an equivalent system for WiimoteLib that provides  facility for Dampened COG output. As stated, I find the two systems can be used to compliment each other greatly depending upon the desired application requirement. To me the next obvious step was to group both of the outputs together as two available types under the single banner CenterOfGravity.</p>
<p>Using the format of the Wiimote Test application, once complete this instruction will enable access to each COG output as follows:</p>
<blockquote><p>// Standard COG<br />
lblCOG.Text = ws.BalanceBoardState.CenterOfGravity.Standard.ToString();<br />
// Dampened COG<br />
lblDampenedCOG.Text = ws.BalanceBoardState.CenterOfGravity.Dampened.ToString();</p></blockquote>
<p>Before you start this instruction assumes use of a raw copy of WiimoteLib 1.7 and have looked at the <a title="dampened cog instruction" href="http://blog.dyadica.net/pages/balance-board/dampened-cog">Adding Dampened COG to WiimoteLib</a> instruction.</p>
<p>Here is how its done:<span id="more-2187"></span></p>
<p>First we are going to add new public struct CenterOfGravity to Data Types.cs. Just below the existing BalanceBoardState struct add the following block of code:</p>
<blockquote><p>/// &lt;summary&gt;<br />
/// Center Of Gravity Types and Variables<br />
/// &lt;/summary&gt;<br />
[Serializable]<br />
[DataContract]<br />
public struct CenterOfGravity<br />
{<br />
/// &lt;summary&gt;<br />
/// Center of gravity of Balance Board user<br />
/// &lt;/summary&gt;<br />
[DataMember]<br />
public PointF Standard;<br />
/// &lt;summary&gt;<br />
/// Dampened Center of gravity of Balance Board<br />
/// &lt;/summary&gt;<br />
[DataMember]<br />
public Point Dampened;<br />
/// &lt;summary&gt;<br />
/// Offset for Center of gravity Damping<br />
/// &lt;/summary&gt;<br />
[DataMember]<br />
public Point DampOffset;<br />
/// &lt;summary&gt;<br />
/// Limits for Center of gravity Damping<br />
/// &lt;/summary&gt;<br />
[DataMember]<br />
public int DampX, DampY;<br />
}</p></blockquote>
<p>As you can see this block contains all the same code as within the previous dampened COG instruction, however we have also added a new member &#8220;Standard&#8221;. Standard is going to reflect the existing COG setup when we are done.</p>
<p>Next (Assuming a raw copy of WiimoteLib 1.7) we need to remove the existing code block defining CenterOfGravity from the BalanceBoardState struct:</p>
<blockquote><p>/// &lt;summary&gt;<br />
/// Center of gravity of Balance Board user<br />
/// &lt;/summary&gt;<br />
[DataMember]<br />
public PointF CenterOfGravity;</p></blockquote>
<p>and replace it with the following new definition:</p>
<blockquote><p>/// &lt;summary&gt;<br />
/// Center of gravity of Balance Board user<br />
/// &lt;/summary&gt;<br />
[DataMember]<br />
public CenterOfGravity CenterOfGravity;</p></blockquote>
<p>Next we need to add the following two new functions to Wiimote.cs, I have included them just below the ParseExtension function. These functions are used to provide an initial damping offset (calibration value) and calculate the Dampened COG at run time. These functions are in essence the same as within the dampened COG instruction, however now containing the new updated syntax.</p>
<blockquote><p>/// &lt;summary&gt;<br />
/// Function used to set the damping offset<br />
/// &lt;/summary&gt;<br />
public void SetDampenOffset()<br />
{ mWiimoteState.BalanceBoardState.CenterOfGravity.DampOffset = GetDampenedCenterOfGravity(); }</p>
<p>/// &lt;summary&gt;<br />
/// Function to get Dampened COG without the offset so it can also be used to set the offset<br />
/// &lt;/summary&gt;<br />
private Point GetDampenedCenterOfGravity()<br />
{<br />
mWiimoteState.BalanceBoardState.CenterOfGravity.Dampened.X += -(mWiimoteState.BalanceBoardState.SensorValuesRaw.TopLeft + mWiimoteState.BalanceBoardState.SensorValuesRaw.BottomLeft);<br />
mWiimoteState.BalanceBoardState.CenterOfGravity.Dampened.Y += -(mWiimoteState.BalanceBoardState.SensorValuesRaw.TopLeft + mWiimoteState.BalanceBoardState.SensorValuesRaw.TopRight);<br />
mWiimoteState.BalanceBoardState.CenterOfGravity.Dampened.X += (mWiimoteState.BalanceBoardState.SensorValuesRaw.TopRight + mWiimoteState.BalanceBoardState.SensorValuesRaw.BottomRight);<br />
mWiimoteState.BalanceBoardState.CenterOfGravity.Dampened.Y += (mWiimoteState.BalanceBoardState.SensorValuesRaw.BottomLeft + mWiimoteState.BalanceBoardState.SensorValuesRaw.BottomRight);</p>
<p>if (mWiimoteState.BalanceBoardState.CenterOfGravity.DampX == 0 || mWiimoteState.BalanceBoardState.CenterOfGravity.DampY == 0)<br />
{<br />
mWiimoteState.BalanceBoardState.CenterOfGravity.DampX = 500; // hack to cater for zero value at start up<br />
mWiimoteState.BalanceBoardState.CenterOfGravity.DampY = 800; // hack to cater for zero value at start up<br />
}</p>
<p>int DampX = mWiimoteState.BalanceBoardState.CenterOfGravity.DampX;<br />
int DampY = mWiimoteState.BalanceBoardState.CenterOfGravity.DampY;</p>
<p>mWiimoteState.BalanceBoardState.CenterOfGravity.Dampened.X = mWiimoteState.BalanceBoardState.CenterOfGravity.Dampened.X / DampX;<br />
mWiimoteState.BalanceBoardState.CenterOfGravity.Dampened.Y = mWiimoteState.BalanceBoardState.CenterOfGravity.Dampened.Y / DampY;</p>
<p>return mWiimoteState.BalanceBoardState.CenterOfGravity.Dampened;<br />
}</p></blockquote>
<p>As before, inclusion of the DampX and DampY variables enables individual axis stiffness customization, which is usefull due the rectangular nature of the Balance Board.</p>
<p>Next in order to use these functions we need to add the following code to the parse extension function. I do this just below the existing COG code:</p>
<blockquote><p>Point DCOG = GetDampenedCenterOfGravity();</p>
<p>mWiimoteState.BalanceBoardState.CenterOfGravity.Dampened.X = DCOG.X &#8211; mWiimoteState.BalanceBoardState.CenterOfGravity.DampOffset.X;<br />
mWiimoteState.BalanceBoardState.CenterOfGravity.Dampened.Y = DCOG.Y &#8211; mWiimoteState.BalanceBoardState.CenterOfGravity.DampOffset.Y;</p></blockquote>
<p>Whilst we are here we also need to update the existing COG code to reflect the new syntax. Just above the code you have just put in update the COG alocations to reflect the following:</p>
<blockquote><p>mWiimoteState.BalanceBoardState.CenterOfGravity.Standard.X = ((float)(Kx &#8211; 1) / (float)(Kx + 1)) * (float)(-BSL / 2);<br />
mWiimoteState.BalanceBoardState.CenterOfGravity.Standard.Y = ((float)(Ky &#8211; 1) / (float)(Ky + 1)) * (float)(-BSW / 2);</p></blockquote>
<p>Ok, we are nearly done. Finally we need to add a call to the SetDampenOffset() function in order to define an offset value at start up. Still within Wiimote.cs add the following call within InitializeExtension() inside the ExtensionType.BalanceBoard case,  just above the break.</p>
<blockquote><p>SetDampenOffset();</p></blockquote>
<p>And thats it, now you should have acces to both the Standard and Dampened COG values via the new CenterOfGravity grouping. As a final thought, yes it has dawned on me that dampened may be better as damped lol!<a id="update" class="update"></a></p>
<p><strong>Update: The SetBalanceBoardDefaults() Function</strong></p>
<p>Whilst developing the code for the Orientation implementation, it became apparent that there was need for an initialize function that could be used to define defaults and provide facility for resetting etc.</p>
<p>I have decided to add the definition here as really Damped COG  is the first time that we needed its capabilities, remember the hack to cater for zero values at start up:</p>
<blockquote><p>if (mWiimoteState.BalanceBoardState.DampX == 0 || mWiimoteState.BalanceBoardState.DampY == 0)<br />
{<br />
mWiimoteState.BalanceBoardState.DampX = 500; // hack to cater for zero value at start up<br />
mWiimoteState.BalanceBoardState.DampY = 800; // hack to cater for zero value at start up<br />
}</p></blockquote>
<p>This modification will <span style="text-decoration: line-through;">not only allow us to remove it, but also</span> provide a location for defining other variables later on. Start off by adding the following variable definitions to the top of Wiimote.cs just above the default constructor:</p>
<blockquote><p>private int Dx = 500;<br />
private int Dy = 800;</p></blockquote>
<p>Next we need to add the function itself. Add the following right below the ParseExtension function:</p>
<blockquote><p>/// &lt;summary&gt;<br />
/// Function used to set the initial defaults.<br />
/// These can be customised above and/or at runtime.<br />
/// &lt;/summary&gt;<br />
private void SetBalanceBoardDefaults()<br />
{<br />
// set the individual damping tolerances for both the<br />
// X and Y axies of the board (good for a rectangle)<br />
mWiimoteState.BalanceBoardState.CenterOfGravity.DampX = Dx;<br />
mWiimoteState.BalanceBoardState.CenterOfGravity.DampY = Dy;<br />
}</p></blockquote>
<p>With this in place all we need to do now is to add a call to the function at startup. Add the following (Currently I am undecided about merging the two together!) right before the call to SetDampenOffset() within the InitializeExtension() function.</p>
<blockquote><p>SetBalanceBoardDefaults();</p></blockquote>
<p>With that done we are finished and now have provision for defining defaults etc!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.dyadica.net/archives/dampened-and-standard-cog/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Balance Board Quadzone Filter for WiimoteLib</title>
		<link>http://blog.dyadica.net/archives/the-balance-board-quadzone-filter-for-wiimotelib</link>
		<comments>http://blog.dyadica.net/archives/the-balance-board-quadzone-filter-for-wiimotelib#comments</comments>
		<pubDate>Tue, 14 Jul 2009 22:23:20 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Wii]]></category>
		<category><![CDATA[balance board]]></category>
		<category><![CDATA[Quadzone]]></category>
		<category><![CDATA[WiiFit]]></category>
		<category><![CDATA[wiimote]]></category>
		<category><![CDATA[wiimoteLib]]></category>
		<category><![CDATA[Zones]]></category>

		<guid isPermaLink="false">http://blog.dyadica.net/?p=2157</guid>
		<description><![CDATA[There are times when using the WiiFit Balance Board with WiimoteLib that I find it useful to have direct access to which particular &#8220;Zone&#8221; currently has focus (most weight or COG applied), just think WiiFit ...]]></description>
			<content:encoded><![CDATA[<p>There are times when using the WiiFit Balance Board with WiimoteLib that I find it useful to have direct access to which particular &#8220;Zone&#8221; currently has focus (most weight or COG applied), just think WiiFit areobics etc. Output is fed back as a string which can then be used as desired eg in a switch or if statement etc.</p>
<p>Here&#8217;s how its done:</p>
<p>First of all open up Data Types.cs and add the following code block within the BalanceBoardState struct:</p>
<blockquote><p>/// &lt;summary&gt;<br />
/// Current Balance Board Zone<br />
/// &lt;/summary&gt;<br />
[DataMember]<br />
public string Quadzone;</p></blockquote>
<p>Next open up Wiimote.cs and locate the parse extension function. For convenience sake the following block shorthands the values included with WiimoteLib to help with RSI. Add the following code below the existing COG code just above the break:<span id="more-2157"></span></p>
<blockquote><p>// Shorthand the values for lazyness (Raw)<br />
// float TLrkg = mWiimoteState.BalanceBoardState.SensorValuesRaw.TopLeft;<br />
// float TRrkg = mWiimoteState.BalanceBoardState.SensorValuesRaw.TopRight;<br />
// float BLrkg = mWiimoteState.BalanceBoardState.SensorValuesRaw.BottomLeft;<br />
// float BRrkg = mWiimoteState.BalanceBoardState.SensorValuesRaw.BottomRight;</p>
<p>// Shorthand the values for lazyness (Kg)<br />
float TLkg = mWiimoteState.BalanceBoardState.SensorValuesKg.TopLeft;<br />
float TRkg = mWiimoteState.BalanceBoardState.SensorValuesKg.TopRight;<br />
float BLkg = mWiimoteState.BalanceBoardState.SensorValuesKg.BottomLeft;<br />
float BRkg = mWiimoteState.BalanceBoardState.SensorValuesKg.BottomRight;</p></blockquote>
<p>As you can see I have included facility for using the raw values, but personally I have not found a need to yet! Next we need to add the code that will enable Zone output at run time. Below the shorthand code add the following block:</p>
<blockquote><p>if ((TLkg + TRkg) &gt; (TLkg + BLkg) &amp;&amp;<br />
(TLkg + TRkg) &gt; (TLkg + BLkg) &amp;&amp;<br />
(TLkg + TRkg) &gt; (BLkg + BRkg)) { mWiimoteState.BalanceBoardState.Quadzone = &#8220;Top&#8221;; }</p>
<p>if ((BLkg + BRkg) &gt; (TLkg + BLkg) &amp;&amp;<br />
(BLkg + BRkg) &gt; (TLkg + BLkg) &amp;&amp;<br />
(BLkg + BRkg) &gt; (TLkg + TRkg)) { mWiimoteState.BalanceBoardState.Quadzone = &#8220;Bottom&#8221;; }</p>
<p>if ((TLkg + BLkg) &gt; (TLkg + TRkg) &amp;&amp;<br />
(TLkg + BLkg) &gt; (BLkg + BRkg) &amp;&amp;<br />
(TLkg + BLkg) &gt; (TRkg + BRkg)) { mWiimoteState.BalanceBoardState.Quadzone = &#8220;Left&#8221;; }</p>
<p>if ((TRkg + BRkg) &gt; (TLkg + TRkg) &amp;&amp;<br />
(TRkg + BRkg) &gt; (BLkg + BRkg) &amp;&amp;<br />
(TRkg + BRkg) &gt; (TLkg + BLkg)) { mWiimoteState.BalanceBoardState.Quadzone = &#8220;Right&#8221;; }</p></blockquote>
<p>If you want you can also add definitions for angle zones however as with the raw value definitions I dont really find much use for them, however here they are just in case:</p>
<blockquote><p>//if ((TLkg + BRkg) &gt; (TLkg + TRkg) &amp;&amp;<br />
//     (TLkg + BRkg) &gt; (BLkg + BRkg) &amp;&amp;<br />
//     (TLkg + BRkg) &gt; (TLkg + BLkg) &amp;&amp;<br />
//     (TLkg + BRkg) &gt; (TRkg + BLkg)) { mWiimoteState.BalanceBoardState.Quadzone = &#8220;Left-Right&#8221;; }</p>
<p>//if ((TRkg + BLkg) &gt; (TLkg + TRkg) &amp;&amp;<br />
//     (TRkg + BLkg) &gt; (BLkg + BRkg) &amp;&amp;<br />
//     (TRkg + BLkg) &gt; (TLkg + BLkg) &amp;&amp;<br />
//     (TRkg + BLkg) &gt; (TLkg + BRkg)) { mWiimoteState.BalanceBoardState.Quadzone = &#8220;Right-Left&#8221;; }</p></blockquote>
<p>Once complete Quadzone is now available by the normal means for example:</p>
<blockquote><p>WiimoteState ws = state;<br />
BalanceBoardState bb = ws.BalanceBoardState;</p>
<p>string current_zone = bb.Quadzone;</p></blockquote>
<p>That&#8217;s all there is to it easy eh!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.dyadica.net/archives/the-balance-board-quadzone-filter-for-wiimotelib/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Balance Board Quadrant Filter for WiimoteLib</title>
		<link>http://blog.dyadica.net/archives/the-balance-board-quadrant-filter-for-wiimotelib</link>
		<comments>http://blog.dyadica.net/archives/the-balance-board-quadrant-filter-for-wiimotelib#comments</comments>
		<pubDate>Tue, 14 Jul 2009 22:23:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Wii]]></category>
		<category><![CDATA[balance board]]></category>
		<category><![CDATA[Balance Board Filters]]></category>
		<category><![CDATA[Quadrant]]></category>
		<category><![CDATA[Quadzone]]></category>
		<category><![CDATA[WiiFit]]></category>
		<category><![CDATA[wiimote]]></category>
		<category><![CDATA[wiimoteLib]]></category>

		<guid isPermaLink="false">http://blog.dyadica.net/?p=2163</guid>
		<description><![CDATA[There are times when using the WiiFit Balance Board with WiimoteLib that I find it useful to have direct access to which particular &#8220;Quadrant&#8221; currently has focus (most weight or COG applied), as with the ...]]></description>
			<content:encoded><![CDATA[<p>There are times when using the WiiFit Balance Board with WiimoteLib that I find it useful to have direct access to which particular &#8220;Quadrant&#8221; currently has focus (most weight or COG applied), as with the Quadzone Filter just think WiiFit areobics etc.</p>
<p>When used in conjunction with the Quadzone Filter you have the basic tools needed for very simple forms of navigation. As with the Quadzone filter, output is fed back as a string which can then be used as desired eg in a switch or if statement etc.</p>
<p>So without further ado heres how its done:</p>
<p>First of all open up Data Types.cs and add the following code block within the BalanceBoardState struct:</p>
<blockquote><p>/// &lt;summary&gt;<br />
/// Current Balance Board Quadrant, SJB<br />
/// &lt;/summary&gt;<br />
[DataMember]<br />
public string Quadrant;</p></blockquote>
<p>Next open up Wiimote.cs and locate the parse extension function. For convenience sake the following block shorthands the values included with WiimoteLib. The code is the same as that used in the Quadzone tutorial so if you have already implemented it there you can skip this step, otherwise add the following code below the existing COG code just above the break:<span id="more-2163"></span></p>
<blockquote><p>// Shorthand the values for lazyness (Raw)<br />
// float TLrkg = mWiimoteState.BalanceBoardState.SensorValuesRaw.TopLeft;<br />
// float TRrkg = mWiimoteState.BalanceBoardState.SensorValuesRaw.TopRight;<br />
// float BLrkg = mWiimoteState.BalanceBoardState.SensorValuesRaw.BottomLeft;<br />
// float BRrkg = mWiimoteState.BalanceBoardState.SensorValuesRaw.BottomRight;</p>
<p>// Shorthand the values for lazyness (Kg)<br />
float TLkg = mWiimoteState.BalanceBoardState.SensorValuesKg.TopLeft;<br />
float TRkg = mWiimoteState.BalanceBoardState.SensorValuesKg.TopRight;<br />
float BLkg = mWiimoteState.BalanceBoardState.SensorValuesKg.BottomLeft;<br />
float BRkg = mWiimoteState.BalanceBoardState.SensorValuesKg.BottomRight;</p></blockquote>
<p>As you can see I have included suggested functionality for using the raw values, but personally I have not found a need to yet. Its just there for reference! Next we need to add the code that will enable Quadrant output at run time. Below the shorthand code add the following block:</p>
<blockquote><p>// Calculate the heavest quadrant<br />
if (TLkg &gt; TRkg &amp;&amp; TLkg &gt; BRkg &amp;&amp; TLkg &gt; BLkg) { mWiimoteState.BalanceBoardState.Quadrant = &#8220;TL&#8221;; }<br />
if (TRkg &gt; TLkg &amp;&amp; TRkg &gt; BRkg &amp;&amp; TRkg &gt; BLkg) { mWiimoteState.BalanceBoardState.Quadrant = &#8220;TR&#8221;; }<br />
if (BLkg &gt; TLkg &amp;&amp; BLkg &gt; BRkg &amp;&amp; BLkg &gt; TRkg) { mWiimoteState.BalanceBoardState.Quadrant = &#8220;BL&#8221;; }<br />
if (BRkg &gt; TLkg &amp;&amp; BRkg &gt; BLkg &amp;&amp; BRkg &gt; TRkg) { mWiimoteState.BalanceBoardState.Quadrant = &#8220;BR&#8221;; }</p></blockquote>
<p>Once complete Quadrantis available by the normal means for example:</p>
<blockquote><p>WiimoteState ws = state;<br />
BalanceBoardState bb = ws.BalanceBoardState;</p>
<p>string current_quad = bb.Quadrant;</p>
<p>//Or following the Wiimote Test example<br />
lblQuad.Text = ws.BalanceBoardState.Quadrant;</p></blockquote>
<p>That&#8217;s all there is to it easy eh! If you haven&#8217;t seen the Quadzone tutorial yet, go check it out. The two methods compliment each other greatly!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.dyadica.net/archives/the-balance-board-quadrant-filter-for-wiimotelib/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding Dampened COG to WiimoteLib</title>
		<link>http://blog.dyadica.net/archives/adding-dampened-cog-to-wiimotelib</link>
		<comments>http://blog.dyadica.net/archives/adding-dampened-cog-to-wiimotelib#comments</comments>
		<pubDate>Tue, 14 Jul 2009 16:32:39 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Wii]]></category>
		<category><![CDATA[hardware]]></category>
		<category><![CDATA[balance board]]></category>
		<category><![CDATA[Center of]]></category>
		<category><![CDATA[Center Of Gravity]]></category>
		<category><![CDATA[COG]]></category>
		<category><![CDATA[Dampened COG]]></category>
		<category><![CDATA[WiiFit]]></category>
		<category><![CDATA[wiimote]]></category>

		<guid isPermaLink="false">http://blog.dyadica.net/?p=2133</guid>
		<description><![CDATA[Inspired by endquotes WPF implementation of COG I have developed an equivalent system for WiimoteLib that provides the library with facility for Dampened COG output. I find the two systems can be used to compliment ...]]></description>
			<content:encoded><![CDATA[<p>Inspired by endquotes <a title="endquotes COG" href="http://www.brianpeek.com/forums/t/928.aspx">WPF implementation of COG</a> I have developed an equivalent system for WiimoteLib that provides the library with facility for Dampened COG output. I find the two systems can be used to compliment each other greatly depending upon the desired application requirement. Before you start this instruction assumes use of a raw copy of WiimoteLib 1.7</p>
<p>Here is how its done:</p>
<p>Open up Data Types.cs and within the public struct BalanceBoardState add the following blocks of code:<span id="more-2133"></span></p>
<blockquote><p>/// &lt;summary&gt;<br />
/// Dampened Center of gravity of Balance Board<br />
/// &lt;/summary&gt;<br />
[DataMember]<br />
public Point DampenedCOG;</p>
<p>/// &lt;summary&gt;<br />
/// Offset for Center of gravity Damping<br />
/// &lt;/summary&gt;<br />
[DataMember]<br />
public Point DampingOffset;</p>
<p>/// &lt;summary&gt;<br />
/// Limits for Center of gravity Damping<br />
/// &lt;/summary&gt;<br />
[DataMember]<br />
public int DampX, DampY;</p></blockquote>
<p>Next we need to add the following two new functions to Wiimote.cs, I have included them just below the ParseExtension function. These functions are used to provide an initial damping offset (calibration value) and calculate the Dampened COG at run time.</p>
<blockquote><p>/// &lt;summary&gt;<br />
/// Function used to set the damping offset<br />
/// &lt;/summary&gt;<br />
public void SetDampenOffset()<br />
{ mWiimoteState.BalanceBoardState.DampingOffset = GetDampenedCenterOfGravity(); }</p>
<p>/// &lt;summary&gt;<br />
/// Function to get Dampened COG without the offset so it can also be used to set the offset<br />
/// &lt;/summary&gt;<br />
private Point GetDampenedCenterOfGravity()<br />
{</p>
<p>mWiimoteState.BalanceBoardState.DampenedCOG.X += -(mWiimoteState.BalanceBoardState.SensorValuesRaw.TopLeft + mWiimoteState.BalanceBoardState.SensorValuesRaw.BottomLeft);<br />
mWiimoteState.BalanceBoardState.DampenedCOG.Y += -(mWiimoteState.BalanceBoardState.SensorValuesRaw.TopLeft + mWiimoteState.BalanceBoardState.SensorValuesRaw.TopRight);<br />
mWiimoteState.BalanceBoardState.DampenedCOG.X += (mWiimoteState.BalanceBoardState.SensorValuesRaw.TopRight + mWiimoteState.BalanceBoardState.SensorValuesRaw.BottomRight);<br />
mWiimoteState.BalanceBoardState.DampenedCOG.Y += (mWiimoteState.BalanceBoardState.SensorValuesRaw.BottomLeft + mWiimoteState.BalanceBoardState.SensorValuesRaw.BottomRight);</p>
<p>if (mWiimoteState.BalanceBoardState.DampX == 0 || mWiimoteState.BalanceBoardState.DampY == 0)<br />
{<br />
mWiimoteState.BalanceBoardState.DampX = 500; // hack to cater for zero value at start up<br />
mWiimoteState.BalanceBoardState.DampY = 800; // hack to cater for zero value at start up<br />
}</p>
<p>int DampX = mWiimoteState.BalanceBoardState.DampX;<br />
int DampY = mWiimoteState.BalanceBoardState.DampY;</p>
<p>mWiimoteState.BalanceBoardState.DampenedCOG.X = mWiimoteState.BalanceBoardState.DampenedCOG.X / DampX;<br />
mWiimoteState.BalanceBoardState.DampenedCOG.Y = mWiimoteState.BalanceBoardState.DampenedCOG.Y / DampY;</p>
<p>return mWiimoteState.BalanceBoardState.DampenedCOG;</p>
<p>}</p></blockquote>
<p>The inclusion of the DampX and DampY variables enables individual axis stiffness customization, which is usefull due the rectangular nature of the Balance Board.</p>
<p>Next in order to use these functions we need to add the following code to the parse extension function. I do this just below the existing COG code:</p>
<blockquote><p>Point DCOG = GetDampenedCenterOfGravity();</p>
<p>mWiimoteState.BalanceBoardState.DampenedCOG.X = DCOG.X &#8211; mWiimoteState.BalanceBoardState.DampingOffset.X;<br />
mWiimoteState.BalanceBoardState.DampenedCOG.Y = DCOG.Y &#8211; mWiimoteState.BalanceBoardState.DampingOffset.Y;</p></blockquote>
<p>Ok, we are nearly done. Finally we need to add a call to the SetDampenOffset() function in order to define an offset value at start up. Still within Wiimote.cs add the following call within InitializeExtension() inside the ExtensionType.BalanceBoard case,  just above the break.</p>
<blockquote><p>SetDampenOffset();</p></blockquote>
<p>And thats it, now you should have acces to DampenedCOG in the usual manner!<a id="update" class="update"></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.dyadica.net/archives/adding-dampened-cog-to-wiimotelib/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Balance Board BMI</title>
		<link>http://blog.dyadica.net/archives/balance-board-bmi</link>
		<comments>http://blog.dyadica.net/archives/balance-board-bmi#comments</comments>
		<pubDate>Sat, 11 Jul 2009 21:23:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Wii]]></category>
		<category><![CDATA[hardware]]></category>
		<category><![CDATA[balance board]]></category>
		<category><![CDATA[Balance Board BMI]]></category>
		<category><![CDATA[BMI]]></category>
		<category><![CDATA[Body Mass Index]]></category>
		<category><![CDATA[wiici]]></category>
		<category><![CDATA[WiiFit]]></category>
		<category><![CDATA[wiimote]]></category>
		<category><![CDATA[wiimoteLib]]></category>

		<guid isPermaLink="false">http://blog.dyadica.net/?p=2024</guid>
		<description><![CDATA[Want to be able to calculate your BMI via WiimoteLib so you can use your board ala WiiFit, heres how its done:
Before we start, for a detailed description of BMI please refer to the following ...]]></description>
			<content:encoded><![CDATA[<p>Want to be able to calculate your BMI via WiimoteLib so you can use your board ala WiiFit, heres how its done:</p>
<p>Before we start, for a detailed description of BMI please refer to the following Wikipedia article: <a title="BMI Wikipedia article" href="http://en.wikipedia.org/wiki/Body_mass_index">http://en.wikipedia.org/wiki/Body_mass_index</a></p>
<p>The formula for calculating BMI is a simple one and can be defined as follows:</p>
<blockquote><p>BMI = Weight in kilograms / height in meters² &#8211; Metric<br />
BMI = (weight in pounds * 703 ) / height in inches² &#8211; Imperial</p></blockquote>
<p>The following function is passed a WiimoteState value ws and returns BMI as a double. The division by 100 is used to convert a cm user_height value into meters and can quite easily be replaced/removed if desired.<span id="more-2024"></span> In my setup I use a trackbar so that a user can easily input their height as required</p>
<blockquote><p>private double GetTheBodyMassIndex(WiimoteState ws)<br />
{<br />
double w = (double)(ws.BalanceBoardState.WeightKg);<br />
double h = (double)(user_heght / 100);<br />
double bmi = (double)(w) / (double)(h * h);<br />
return bmi;<br />
}</p></blockquote>
<p>Simple eh! Ok what about the detailing the users Body Mass Status. Well the Wikipedia article also details the divisions of BMI which we can use to define a users BMI status. Take a look at the following function:</p>
<blockquote><p>private string GetTheBodyMassStatus(double bmi)<br />
{<br />
string status = &#8220;Undefined&#8221;;<br />
// Severely underweight: &lt; 16.5<br />
if (bmi &lt; 16.5) { status = &#8220;Severely Underweight&#8221;;  }<br />
// Underweight: 16.5 &#8211; 18.5<br />
else if (bmi &gt; 16.5 &amp;&amp; bmi &lt; 18.5) { status = &#8220;Underweight&#8221;; }<br />
// Normal 18.5: &#8211; 25<br />
else if (bmi &gt; 18.5 &amp;&amp; bmi &lt; 25) { status = &#8220;Normal&#8221;; }<br />
// Overweight: 25 &#8211; 30<br />
else if (bmi &gt; 25 &amp;&amp; bmi &lt; 30) { status = &#8220;Overweight&#8221;; }<br />
// Obese Class: 1 30 &#8211; 35<br />
else if (bmi &gt; 30 &amp;&amp; bmi &lt; 35) { status = &#8220;Obese Class 1&#8243;; }<br />
// Obese Class: 2 35 &#8211; 40<br />
else if (bmi &gt; 35 &amp;&amp; bmi &lt; 40) { status = &#8220;Obese Class 2&#8243;; }<br />
// Obese Class: 3 &gt; 40<br />
else if (bmi &gt; 40) { status = &#8220;Obese Class 3&#8243;; }<br />
return status;<br />
}</p></blockquote>
<p>All we are doing here is using an if statement to filter the BMI value into the defined weight categories. The result is then returned as a string, again simple!</p>
<p>To call the functions just place the relevant triggers in your Wiimote Changed Event function (Mine is called UpdateWiimoteChanged) eg:</p>
<blockquote><p>public void UpdateWiimoteChanged(WiimoteChangedEventArgs args)<br />
{<br />
try<br />
{<br />
WiimoteState ws = args.WiimoteState;<br />
double bmi = GetTheBodyMassIndex(ws);<br />
string status = GetTheBodyMassStatus(bmi);<br />
}<br />
catch (Exception ex)<br />
{<br />
Console.WriteLine(&#8220;Caught: &#8221; + ex.Message.ToString());<br />
}<br />
}</p></blockquote>
<p>And thats all there is to it, BMI ala WiiFit via WiimoteLib. The next stage is to build this functionality into the library itself. Please check back soon for more details!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.dyadica.net/archives/balance-board-bmi/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Real Balance Board Orientation</title>
		<link>http://blog.dyadica.net/archives/real-balance-board-orientation</link>
		<comments>http://blog.dyadica.net/archives/real-balance-board-orientation#comments</comments>
		<pubDate>Fri, 10 Jul 2009 22:01:57 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Balance Board]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Wii]]></category>
		<category><![CDATA[hardware]]></category>
		<category><![CDATA[balance board]]></category>
		<category><![CDATA[Board Orientation]]></category>
		<category><![CDATA[wiici]]></category>
		<category><![CDATA[WiiFit]]></category>
		<category><![CDATA[wiimote]]></category>
		<category><![CDATA[wiimoteLib]]></category>

		<guid isPermaLink="false">http://blog.dyadica.net/?p=2014</guid>
		<description><![CDATA[Today is a good day. After a exactly one year and two days, I have finally cracked the enigma of Balance Board Orientation, and have a version which robust enough for release.
Needless to say I ...]]></description>
			<content:encoded><![CDATA[<p>Today is a good day. After a exactly one year and two days, I have finally cracked the enigma of Balance Board Orientation, and have a version which robust enough for release.</p>
<p>Needless to say I am overjoyed, check out the video:</p>
<p><span class="onevid_big"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="344" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/4vdADALPsbc&amp;hl=en&amp;fs=1&amp;" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="425" height="344" src="http://www.youtube.com/v/4vdADALPsbc&amp;hl=en&amp;fs=1&amp;" allowscriptaccess="always" allowfullscreen="true"></embed></object></span></p>
<p>During the last year I have developed numerous implementations for the task, most of which worked, however none strong enough to deal with the heterogeneous error known as untrained users, however no more!</p>
<p>I am now working on implementing the system fully within both WiimoteLib and the WiiCi driver. Check back soon for more details.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.dyadica.net/archives/real-balance-board-orientation/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Status of Wii MotionPlus Support for WiimoteLib</title>
		<link>http://blog.dyadica.net/archives/status-of-wii-motionplus-support-for-wiimotelib</link>
		<comments>http://blog.dyadica.net/archives/status-of-wii-motionplus-support-for-wiimotelib#comments</comments>
		<pubDate>Fri, 19 Jun 2009 22:01:45 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Wii]]></category>
		<category><![CDATA[hardware]]></category>
		<category><![CDATA[brian peek]]></category>
		<category><![CDATA[wii motion plus]]></category>
		<category><![CDATA[wiimote]]></category>
		<category><![CDATA[wiimoteLib]]></category>

		<guid isPermaLink="false">http://blog.dyadica.net/?p=2067</guid>
		<description><![CDATA[Here is a Cross Post from brianpeek.com detailing Brian&#8217;s current progress with the Wii Motion Plus: Source
Ok, I get about 10 emails a day on this, so I figure a status update is in order.
The ...]]></description>
			<content:encoded><![CDATA[<p>Here is a Cross Post from brianpeek.com detailing Brian&#8217;s current progress with the Wii Motion Plus: <a href="http://brianpeek.com/blog/archive/2009/06/19/status-of-wii-motionplus-support-for-wiimotelib.aspx">Source</a></p>
<blockquote><p>Ok, I get about 10 emails a day on this, so I figure a status update is in order.</p>
<p>The Wii MotionPlus extension for the Wiimote was released last week.  Since then, I and others have been working to figure out how the device works.  Unfortunately, it does NOT work as every other extension controller has worked up until this point, mostly due to the fact that the Wii MotionPlus accessory has an expansion port of its own so all of the other extension controllers can plug into it.</p>
<p>In the past few days, some progress has been made thanks to the folks over at wiibrew.org, although functionality is nowhere near complete.  For example, it’s currently impossible to have the Wiimote notify you when the Wii MotionPlus is inserted into the bottom of the Wiimote, like all of the other extension controllers do.</p>
<p>I have been working with the information at wiibrew.org and am trying to get things working reliably with my library so that developers can actually get some degree of functionality out of it.</p>
<p>So, all that said, expect to see a new (likely beta) version of WiimoteLib “soon” that has some bare-bones Wii MotionPlus functionality included.  It won’t be perfect, complete, or bug free, but it will allow you to tinker with the device a bit.  I will update my blog when the new version is available.  Thanks!</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://blog.dyadica.net/archives/status-of-wii-motionplus-support-for-wiimotelib/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
