unit Zero;
{ -----------------------------------------------------------
  WinCDR (c) J.Dempster, University of Strathclyde 1996-97
  ViewWCP channel zero level setup module
  -----------------------------------------------------------}

interface

uses
  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  Forms, Dialogs, StdCtrls, Global, Mask, Shared, fileio, ValidatedEdit, math ;

type
  TZeroFrm = class(TForm)
    bOK: TButton;
    bCancel: TButton;
    GroupBox1: TGroupBox;
    edChannel: TEdit;
    Label3: TLabel;
    edLevel: TValidatedEdit;
    procedure FormActivate(Sender: TObject);
    procedure bOKClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    ChSel : LongInt ;
    NewZeroAt : LongInt ;
  end;

var
  ZeroFrm: TZeroFrm;

implementation

{$R *.DFM}

uses maths ;

procedure TZeroFrm.FormActivate(Sender: TObject);
begin
     edChannel.text := format('Ch.%d %s',[ChSel,Channel[ChSel].ADCName]) ;
     edLevel.Value := Channel[ChSel].ADCZero ;

     end ;


procedure TZeroFrm.bOKClick(Sender: TObject);
begin
    Channel[ChSel].ADCZero := Round(edLevel.Value) ;
    Channel[ChSel].ADCZero := Max(-Channel[ChSel].ADCMaxValue-1,Channel[ChSel].ADCZero) ;
    Channel[ChSel].ADCZero := Min(Channel[ChSel].ADCMaxValue,Channel[ChSel].ADCZero) ;
    Channel[ChSel].ADCZeroAt := -1 ;
    SaveCDRHeader( CDRfH ) ;
    end;


end.
