unit UISync;

{$IFDEF FPC}
  {$MODE Delphi}
{$ENDIF}

interface

uses
  Classes, HPSDRNetwork;

type
  TAddDeviceProc = procedure(const Dev: THPSDRDevice; const Entry: string) of object;
  TUpdateStatusProc = procedure(FwdW, SWRV, SupplyV, SupplyA: Double;
    PLLLock, HWPTT: Boolean; ADCOverload: Byte) of object;
  TUpdateDDCSeqOrNoDeviceProc = procedure(DDCIdx: Integer; Seq: LongWord) of object;

  TDeviceFoundSync = class
  private
    FCallback: TAddDeviceProc;
    FDev:      THPSDRDevice;
    FEntry:    string;
  public
    constructor Create(ACallback: TAddDeviceProc; const D: THPSDRDevice;
      const E: string);
    procedure Execute;
  end;

  TStatusUISync = class
  private
    FCallback: TUpdateStatusProc;
    FFwdW:    Double;
    FSWRV:    Double;
    FSupplyV: Double;
    FSupplyA: Double;
    FPLLLock: Boolean;
    FHWPTT:   Boolean;
    FADCOverload: Byte;
  public
    constructor Create(ACallback: TUpdateStatusProc;
      FW, SW, SV, SA: Double; PLL, HWPTT: Boolean; ADCOverload: Byte);
    procedure Execute;
  end;

  TDDCSeqSync = class
  private
    FCallback: TUpdateDDCSeqOrNoDeviceProc;
    FDDCIdx:  Integer;
    FSeq:     LongWord;
  public
    constructor Create(ACallback: TUpdateDDCSeqOrNoDeviceProc;
      Idx: Integer; Seq: LongWord);
    procedure Execute;
  end;

implementation

constructor TDeviceFoundSync.Create(ACallback: TAddDeviceProc;
  const D: THPSDRDevice; const E: string);
begin
  inherited Create;
  FCallback := ACallback;
  FDev      := D;
  FEntry    := E;
end;

procedure TDeviceFoundSync.Execute;
begin
  FCallback(FDev, FEntry);
end;

constructor TStatusUISync.Create(ACallback: TUpdateStatusProc;
  FW, SW, SV, SA: Double; PLL, HWPTT: Boolean; ADCOverload: Byte);
begin
  inherited Create;
  FCallback    := ACallback;
  FFwdW        := FW;
  FSWRV        := SW;
  FSupplyV     := SV;
  FSupplyA     := SA;
  FPLLLock     := PLL;
  FHWPTT       := HWPTT;
  FADCOverload := ADCOverload;
end;

procedure TStatusUISync.Execute;
begin
  FCallback(FFwdW, FSWRV, FSupplyV, FSupplyA, FPLLLock, FHWPTT, FADCOverload);
end;

constructor TDDCSeqSync.Create(ACallback: TUpdateDDCSeqOrNoDeviceProc;
  Idx: Integer; Seq: LongWord);
begin
  inherited Create;
  FCallback := ACallback;
  FDDCIdx   := Idx;
  FSeq      := Seq;
end;

procedure TDDCSeqSync.Execute;
begin
  FCallback(FDDCIdx, FSeq);
end;

end.
