unit ifkit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, PHIDGETEvents, PHIDGET_TLB, ComCtrls;

type
  TForm1 = class(TForm)
    TrackBar1: TTrackBar;
    TrackBar2: TTrackBar;
    TrackBar3: TTrackBar;
    TrackBar4: TTrackBar;
    TrackBar5: TTrackBar;
    TrackBar6: TTrackBar;
    TrackBar7: TTrackBar;
    TrackBar8: TTrackBar;
    Memo1: TMemo;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    CheckBox1: TCheckBox;
    Label9: TLabel;
    Label10: TLabel;
    CheckBox2: TCheckBox;
    CheckBox3: TCheckBox;
    CheckBox4: TCheckBox;
    CheckBox5: TCheckBox;
    CheckBox6: TCheckBox;
    CheckBox7: TCheckBox;
    CheckBox8: TCheckBox;
    CheckBox9: TCheckBox;
    CheckBox10: TCheckBox;
    CheckBox11: TCheckBox;
    CheckBox12: TCheckBox;
    CheckBox13: TCheckBox;
    CheckBox14: TCheckBox;
    CheckBox15: TCheckBox;
    CheckBox16: TCheckBox;
    PHIDGETIPhidgetInterfaceKitEvents1: TPHIDGETIPhidgetInterfaceKitEvents;
    procedure PHIDGETIPhidgetInterfaceKitEvents1Detach(Sender: TObject);
    procedure PHIDGETIPhidgetInterfaceKitEvents1Attach(Sender: TObject);
    procedure InterfaceKitEventsInputChange(Sender: TObject; Index: Integer;
      NewState: WordBool);
    procedure CheckBox8Click(Sender: TObject);
    procedure CheckBox7Click(Sender: TObject);
    procedure CheckBox6Click(Sender: TObject);
    procedure CheckBox5Click(Sender: TObject);
    procedure CheckBox4Click(Sender: TObject);
    procedure CheckBox3Click(Sender: TObject);
    procedure CheckBox2Click(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure InterfaceKitEventsSensorChange(Sender: TObject; Index,
      SensorValue: Integer);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  ifkit1 : IPhidgetInterfaceKit;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
    ifkit1:=CoPhidgetInterfaceKit.Create;
    PHIDGETIPhidgetInterfaceKitEvents1.Connect(ifkit1);
    ifkit1.Open(-1);
  memo1.Clear;
  CheckBox1.Enabled := false;
  CheckBox2.Enabled := false;
  CheckBox3.Enabled := false;
  CheckBox4.Enabled := false;
  CheckBox5.Enabled := false;
  CheckBox6.Enabled := false;
  CheckBox7.Enabled := false;
  CheckBox8.Enabled := false;
end;

procedure TForm1.InterfaceKitEventsSensorChange(Sender: TObject; Index,
  SensorValue: Integer);
begin
  case Index of
  0: begin
    TrackBar1.Position :=  SensorValue;
    Label1.Caption := inttostr(SensorValue);
  end;
  1: begin
     TrackBar2.Position :=  SensorValue;
    Label2.Caption := inttostr(SensorValue);
  end;
  2: begin
     TrackBar3.Position :=  SensorValue;
    Label3.Caption := inttostr(SensorValue);
  end;
  3: begin
     TrackBar4.Position :=  SensorValue;
    Label4.Caption := inttostr(SensorValue);
  end;
  4: begin
     TrackBar5.Position :=  SensorValue;
    Label5.Caption := inttostr(SensorValue);
  end;
  5: begin
     TrackBar6.Position :=  SensorValue;
    Label6.Caption := inttostr(SensorValue);
  end;
  6: begin
     TrackBar7.Position :=  SensorValue;
    Label7.Caption := inttostr(SensorValue);
  end;
  7: begin
     TrackBar8.Position :=  SensorValue;
    Label8.Caption := inttostr(SensorValue);
  end;
  end;
end;

procedure TForm1.CheckBox1Click(Sender: TObject);
begin
  if(CheckBox1.Checked) then begin
    ifkit1.OutputState[0] := true; end
  else begin
    ifkit1.OutputState[0] := false; end;
end;

procedure TForm1.CheckBox2Click(Sender: TObject);
begin
  if(CheckBox2.Checked) then begin
    ifkit1.OutputState[1] := true; end
  else begin
    ifkit1.OutputState[1] := false; end;
end;

procedure TForm1.CheckBox3Click(Sender: TObject);
begin
  if(CheckBox3.Checked) then begin
    ifkit1.OutputState[2] := true; end
  else begin
    ifkit1.OutputState[2] := false; end;
end;

procedure TForm1.CheckBox4Click(Sender: TObject);
begin
  if(CheckBox4.Checked) then begin
    ifkit1.OutputState[3] := true; end
  else begin
    ifkit1.OutputState[3] := false; end;
end;

procedure TForm1.CheckBox5Click(Sender: TObject);
begin
  if(CheckBox5.Checked) then begin
    ifkit1.OutputState[4] := true; end
  else begin
    ifkit1.OutputState[4] := false; end;
end;

procedure TForm1.CheckBox6Click(Sender: TObject);
begin
  if(CheckBox6.Checked) then begin
    ifkit1.OutputState[5] := true; end
  else begin
    ifkit1.OutputState[5] := false; end;
end;

procedure TForm1.CheckBox7Click(Sender: TObject);
begin
  if(CheckBox7.Checked) then begin
    ifkit1.OutputState[6] := true; end
  else begin
    ifkit1.OutputState[6] := false; end;
end;

procedure TForm1.CheckBox8Click(Sender: TObject);
begin
  if(CheckBox8.Checked) then begin
    ifkit1.OutputState[7] := true; end
  else begin
    ifkit1.OutputState[7] := false; end;
end;

procedure TForm1.InterfaceKitEventsInputChange(Sender: TObject; Index: Integer;
  NewState: WordBool);
begin
  case Index of
  0: CheckBox9.Checked := NewState; 
  1: CheckBox10.Checked := NewState;
  2: CheckBox11.Checked := NewState;
  3: CheckBox12.Checked := NewState;
  4: CheckBox13.Checked := NewState;
  5: CheckBox14.Checked := NewState;
  6: CheckBox15.Checked := NewState;
  7: CheckBox16.Checked := NewState;
  end
end;

procedure TForm1.PHIDGETIPhidgetInterfaceKitEvents1Attach(Sender: TObject);
begin
  memo1.lines.add(ifkit1.DeviceType+' Connected. Serial #'+IntToStr(ifkit1.SerialNumber));
    CheckBox1.Enabled := true;
    CheckBox2.Enabled := true;
    CheckBox3.Enabled := true;
    CheckBox4.Enabled := true;
    CheckBox5.Enabled := true;
    CheckBox6.Enabled := true;
    CheckBox7.Enabled := true;
    CheckBox8.Enabled := true;
end;

procedure TForm1.PHIDGETIPhidgetInterfaceKitEvents1Detach(Sender: TObject);
begin
  memo1.lines.add(ifkit1.DeviceType+' Disconnected. Serial #'+inttostr(ifkit1.SerialNumber));
    CheckBox1.Enabled := false;
    CheckBox2.Enabled := false;
    CheckBox3.Enabled := false;
    CheckBox4.Enabled := false;
    CheckBox5.Enabled := false;
    CheckBox6.Enabled := false;
    CheckBox7.Enabled := false;
    CheckBox8.Enabled := false;
end;

end.
