using System;
using System.Windows.Forms;
using WiimoteLib;
using Phidgets;
using Phidgets.Events;

namespace WiiCar
{
	public partial class Form1 : Form
	{
		private Wiimote wm;
		private InterfaceKit ik;

		public Form1()
		{
			InitializeComponent();
		}

		private void Form1_Load(object sender, EventArgs e)
		{
			ik = new InterfaceKit();
			ik.open();

			wm = new Wiimote();
			wm.Connect();
			wm.SetReportType(InputReport.ButtonsAccel, true);
			wm.WiimoteChanged += new EventHandler<WiimoteChangedEventArgs>(wm_WiimoteChanged);
		}

		void wm_WiimoteChanged(object sender, WiimoteChangedEventArgs args)
		{
			WiimoteState ws = args.WiimoteState;

			ik.outputs[0] = ws.ButtonState.One;
			ik.outputs[1] = ws.ButtonState.Two;
			ik.outputs[2] = (ws.AccelState.Values.Y < -0.3f);
			ik.outputs[3] = (ws.AccelState.Values.Y >  0.3f);
		}
	}
}
