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 “Area” (for want of a better name).
Please note that this instruction assumes familiarity with the Quadrant and Quadzone instructions.
Similar to the Grouping GOG 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.
Replace both the Quadrant and Quadzone definitions with the following singular block of code:
/// <summary>
/// Area of most Weight/COG
/// </summary>
[DataMember]
public Area Area;
Next we are going to add the new struct so that we can use this definition. Below the BalanceBoardState struct add the following code:
/// <summary>
/// Area Types and Variables
/// </summary>
[Serializable]
[DataContract]
public struct Area
{
/// <summary>
/// Current Balance Board Zone Area
/// </summary>
[DataMember]
public string CurrentZone;/// <summary>
/// Current Balance Board Quad Area
/// </summary>
[DataMember]
public string CurrentQuad;}
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.
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:
// Shorthand the values for lazyness (Kg)
float TLkg = mWiimoteState.BalanceBoardState.SensorValuesKg.TopLeft;
float TRkg = mWiimoteState.BalanceBoardState.SensorValuesKg.TopRight;
float BLkg = mWiimoteState.BalanceBoardState.SensorValuesKg.BottomLeft;
float BRkg = mWiimoteState.BalanceBoardState.SensorValuesKg.BottomRight;
The above stays the same as in the Quadrant and Quadzone instructions. The following is the new Quad:
#region calculate and set values for quad
// Merged Version
if (TLkg > TRkg && TLkg > BRkg && TLkg > BLkg) { mWiimoteState.BalanceBoardState.Area.CurrentQuad = “Top Left”; }
if (TRkg > TLkg && TRkg > BRkg && TRkg > BLkg) { mWiimoteState.BalanceBoardState.Area.CurrentQuad = “Top Right”; }
if (BLkg > TLkg && BLkg > BRkg && BLkg > TRkg) { mWiimoteState.BalanceBoardState.Area.CurrentQuad = “Bottom Left”; }
if (BRkg > TLkg && BRkg > BLkg && BRkg > TRkg) { mWiimoteState.BalanceBoardState.Area.CurrentQuad = “Bottom Right”; }#endregion calculate and set values for quad
And here we have the new Zone:
#region calculate and set values for zone
if ((TLkg + TRkg) > (TLkg + BLkg) &&
(TLkg + TRkg) > (TLkg + BLkg) &&
(TLkg + TRkg) > (BLkg + BRkg))
{
mWiimoteState.BalanceBoardState.Area.CurrentZone = “Top”;
}if ((BLkg + BRkg) > (TLkg + BLkg) &&
(BLkg + BRkg) > (TLkg + BLkg) &&
(BLkg + BRkg) > (TLkg + TRkg))
{
mWiimoteState.BalanceBoardState.Area.CurrentZone = “Bottom”;
}if ((TLkg + BLkg) > (TLkg + TRkg) &&
(TLkg + BLkg) > (BLkg + BRkg) &&
(TLkg + BLkg) > (TRkg + BRkg))
{
mWiimoteState.BalanceBoardState.Area.CurrentZone = “Left”;
}if ((TRkg + BRkg) > (TLkg + TRkg) &&
(TRkg + BRkg) > (BLkg + BRkg) &&
(TRkg + BRkg) > (TLkg + BLkg))
{
mWiimoteState.BalanceBoardState.Area.CurrentZone = “Right”;
}#endregion calculate and set values for zone
And that’s it! You can call the new code definitions (ie from within WiimoteInfo.cs) as follows:
// Quadrant output can also be run from here
lblQuad.Text = ws.BalanceBoardState.Area.CurrentQuad;// Quadzone output can also be run from here
lblZone.Text = ws.BalanceBoardState.Area.CurrentZone;
So why bother doing this, you may ask…. Well….
say what do you think