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

namespace IFKitEx1
{
	public partial class Form1 : Form
	{
		InterfaceKit ifKit;

		public Form1()
		{
			InitializeComponent();
		}

		private void Form1_Load(object sender, EventArgs e)
		{
			ifKit = new InterfaceKit();
			ifKit.Attach += new AttachEventHandler(ifKit_Attach);
			ifKit.Detach += new DetachEventHandler(ifKit_Detach);
			ifKit.SensorChange += new SensorChangeEventHandler(ifKit_SensorChange);
			ifKit.InputChange += new InputChangeEventHandler(ifKit_InputChange);
			ifKit.open();
		}

		void ifKit_InputChange(object sender, InputChangeEventArgs e)
		{
			switch(e.Index)
			{
				case 0:
					chkSwitch.Checked = e.Value;
					break;
			}
		}

		void ifKit_SensorChange(object sender, SensorChangeEventArgs e)
		{
			switch(e.Index)
			{
				case 0:
					tbSlider.Value = e.Value;
					break;
				case 1:
					System.Diagnostics.Debug.WriteLine(e.Value);
					float temp = (e.Value - 200) / 4.0f;
					lblTemp.Text = (temp.ToString()) + "C/" + (((9/5.0f)*temp)+32) + "F";
					break;
				case 2:
					lblForce.Text = e.Value.ToString();
					break;
				case 3:
					lblLight.Text = e.Value.ToString();
					break;
			}
		}

		void ifKit_Detach(object sender, DetachEventArgs e)
		{
			lblAttached.Text = "Detached";
		}

		void ifKit_Attach(object sender, AttachEventArgs e)
		{
			lblAttached.Text = "Attached";
		}

		private void chkLED_CheckedChanged(object sender, EventArgs e)
		{
			ifKit.outputs[0] = chkLED.Checked;
		}
	}
}