library Test;

uses
  math,
  Windows,
  Forms,
  Classes,
  SysUtils,
  Settings in 'Settings.pas' {SettingsForm};

{$E dlp}

{$R *.RES} // VersionInfo


const
  CHANNEL_COUNT =  3;  // max 32


VAR x : double;
type
  TArrayValues = array [0..CHANNEL_COUNT - 1] of double;
  TArrayStates = array [0..CHANNEL_COUNT - 1] of boolean;
  TArrayGains  = array [0..CHANNEL_COUNT - 1] of integer;

procedure ShowSettings; export; stdcall;
begin
  TSettingsForm.Execute;
end;

procedure Init(Handle : HWND; Path : PChar); export; stdcall;
begin
  DecimalSeparator := '.';
  Application.Handle := Handle;
//  Calibration.Path   := StrPas(Path);
end;

procedure Final; export; stdcall;
begin
  Application.Handle := 0;
end;

procedure DiveceList(var Text: PChar); export; stdcall;
var
  List : TStringList;
begin
  List := TStringList.create;
  try
//    Device.DiveceList(StringList);
    List.Add('ADCxxxx Test');

    Text := List.GetText;
  finally
    List.Free;
  end;
end;

function ConnectTo(const Inf: PChar):BOOL;export; stdcall;
begin
//  MessageBox(Application.Handle , Inf, '', MB_OK);
  Result := True;
end;

function Connected(const Inf: PChar):BOOL;export; stdcall;
begin
//  MessageBox(Application.Handle , Inf, '', MB_OK);
  Result := True;
end;

procedure Disconnect;export; stdcall;
begin

end;

function GetCount:UCHAR; export; stdcall;
begin
  Result := CHANNEL_COUNT;
end;


procedure GetValues(var ArrayValues: TArrayValues; var ArrayStates: TArrayStates; var ArrayGains: TArrayGains); export; stdcall;
var
  i : integer;
begin

  for i := 0 to CHANNEL_COUNT - 1 do
     ArrayStates[i] := true;

  ArrayValues[0] := RoundTo(10 * Sin(x * 180 / PI), -4);
  ArrayValues[1] := RoundTo(20 * Sin(x * 180 / PI), -4);
  if ArrayValues[1] > 0 then
      ArrayValues[1] := 1
  else
      ArrayValues[1] := - 1;
  ArrayValues[2] := RoundTo(30 * Cos(x * 180 / PI), -4);
  x := x + 0.1;

  ArrayStates[0] := true;
  ArrayStates[1] := true;
  ArrayStates[2] := true;

  for i := 0 to CHANNEL_COUNT - 1 do
     ArrayGains[i] := 1;
end;

procedure Start;export; stdcall;
begin
  X := 0;
end;

procedure Stop;export; stdcall;
begin

end;

procedure About; export; stdcall;
begin
  Application.MessageBox('www.spetsribor.com', 'About...');
end;

exports
  Init,
  Final,
  DiveceList,
  ShowSettings,
  ConnectTo,
  Connected,
  Disconnect,
  GetCount,
  GetValues,
  Start,
  Stop,
  About;

end.
