Skip to content

Instantly share code, notes, and snippets.

@demonixis
Created August 14, 2012 11:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save demonixis/3348659 to your computer and use it in GitHub Desktop.
Save demonixis/3348659 to your computer and use it in GitHub Desktop.
A basic input helper for testing LibWiimote
using System;
using System.Collections.Generic;
using System.Drawing;
using WiimoteLib;
namespace SpaceGame
{
public class WiimoteHelper
{
private Wiimote wiimote;
public byte BatteryLevel;
#region Wiimote buttons
public bool Up = false;
public bool Down = false;
public bool Left = false;
public bool Right = false;
public bool A = false;
public bool B = false;
public bool Minus = false;
public bool Home = false;
public bool Plus = false;
public bool One = false;
public bool Two = false;
#endregion
#region Nunchuck buttons / Joystick
public bool C;
public float NunchukX;
public float NunchukY;
#endregion
public WiimoteHelper()
{
try
{
wiimote = new Wiimote();
wiimote.WiimoteChanged += new EventHandler<WiimoteChangedEventArgs>(wiimote_WiimoteChanged);
wiimote.WiimoteExtensionChanged += new EventHandler<WiimoteExtensionChangedEventArgs>(wiimote_WiimoteExtensionChanged);
wiimote.Connect();
wiimote.SetReportType(InputReport.IRAccel, true);
wiimote.SetLEDs(true, false, false, true);
}
catch (Exception ex)
{
Console.Error.WriteLine(ex.ToString());
}
}
void wiimote_WiimoteExtensionChanged(object sender, WiimoteExtensionChangedEventArgs e)
{
if (e.Inserted)
wiimote.SetReportType(InputReport.IRExtensionAccel, true);
else
wiimote.SetReportType(InputReport.IRAccel, true);
}
void wiimote_WiimoteChanged(object sender, WiimoteChangedEventArgs e)
{
WiimoteState state = e.WiimoteState;
BatteryLevel = state.Battery;
A = state.ButtonState.A;
B = state.ButtonState.B;
Home = state.ButtonState.Home;
Minus = state.ButtonState.Minus;
Plus = state.ButtonState.Plus;
One = state.ButtonState.One;
Two = state.ButtonState.Two;
Up = state.ButtonState.Up;
Down = state.ButtonState.Down;
Left = state.ButtonState.Left;
Right = state.ButtonState.Right;
// Nunchuck
NunchukState nunchuck = state.NunchukState;
C = nunchuck.C;
NunchukX = nunchuck.Joystick.X;
NunchukY = nunchuck.Joystick.Y;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment