unit Unit1;

interface

uses
  com_funkce, Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Menus, ExtCtrls, jpeg, TeeProcs, TeEngine, Chart,
  Series, OleCtrls, VCFI;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Label2: TLabel;
    MainMenu1: TMainMenu;
    N1: TMenuItem;
    Close1: TMenuItem;
    Help1: TMenuItem;
    Uloitjako1: TMenuItem;
    SaveDialog1: TSaveDialog;
    ListBox1: TListBox;
    Label3: TLabel;
    Label4: TLabel;
    Panel1: TPanel;
    Button2: TButton;
    Help2: TMenuItem;
    About1: TMenuItem;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Close1Click(Sender: TObject);
    procedure Uloitjako1Click(Sender: TObject);
    procedure FormResize(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure About1Click(Sender: TObject);
    procedure Help2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
panel1.Left:=0;
panel1.Width:=form1.ClientWidth-5;
button2.Font.Color:=clred;
listbox1.Width:=form1.ClientWidth-2;


end;

procedure TForm1.Button1Click(Sender: TObject);
var   poslat,i:word;
      pom01,pom02,pom03:integer;
      report:string;
begin
pom01:=0;
listbox1.Clear;
  try

    opencom(pchar('com1,4800,E,8,1'));
    Label2.Visible:=false;
    sendbyte(14);
    while pom01<>(-1) do begin
    pom01:=readbyte;
    if pom01<>(-1) then begin
        pom02:=readbyte;
        pom03:=readbyte;
        case pom03 of
            1: report:='Relé 0 ZAPNUTO';
            2: report:='Relé 0 VYPNUTO';
            3: report:='Relé 1 ZAPNUTO';
            4: report:='Relé 1 VYPNUTO';
            5: report:='Příliž vysoká teplota';
            6: report:='Výpadek zařízení';
            7: report:='Závada zařízení';
            8: report:='Relé 0 VYPNUTO manuálně';
            9: report:='Relé 0 ZAPNUTO manuálně';
            10: report:='Relé 1 VYPNUTO manuálně';
            11: report:='Relé 1 ZAPNUTO manuálně';
        else
            report:='Chyba';
        end;
        listbox1.Items.Add(Inttostr(pom01) +'.'+ Inttostr(pom02)+'. ... '+ report);
      end;
    end;
    closecom();
  except
    Label2.Visible:=true;
  end;

end;

procedure TForm1.Close1Click(Sender: TObject);
begin
form1.Close;
end;

procedure TForm1.Uloitjako1Click(Sender: TObject);
begin
Savedialog1.FileName:='c:\E_man_log01.txt';
if savedialog1.Execute then begin
    Listbox1.Items.SaveToFile(savedialog1.FileName);
                       end;
end;

procedure TForm1.FormResize(Sender: TObject);
begin
panel1.Width:=form1.ClientWidth;
listbox1.Height:=form1.ClientHeight-listbox1.Top-5;
end;

procedure TForm1.Button2Click(Sender: TObject);
var i: integer;
begin
opencom(pchar('com1,4800,E,8,1'));
sendbyte(36);
    i:=readbyte;
    listbox1.Clear;
    if i=37 then begin
        listbox1.Items.Add('MCU memory cleared!');
      end
    else begin
         listbox1.Items.Add('MCU memory NOT cleared!');
         end;
closecom();

end;


procedure TForm1.About1Click(Sender: TObject);
begin
listbox1.Clear;
listbox1.Items.Add('Event Manager');
listbox1.Items.Add('ver.: 01');
listbox1.Items.Add('Author:');
listbox1.Items.Add('František Chytka');
listbox1.Items.Add('BBCE 2011');
listbox1.Items.Add('VUT Brno - FEKT');

end;

procedure TForm1.Help2Click(Sender: TObject);
begin
listbox1.Clear;
listbox1.Items.Add('Use the Read MCU button to load all events from MCU');
listbox1.Items.Add('to E-Manager.');
listbox1.Items.Add('If it does not work, or makes the errors,');
listbox1.Items.Add('the problem is in COM Port connection.');
listbox1.Items.Add('');
listbox1.Items.Add('Use the Clear! button for clearing whole EEPROM');
listbox1.Items.Add('MCU memory. All unsaved events data will be lost!');
listbox1.Items.Add('');
listbox1.Items.Add('Use File->Save as... for saving logs from the list');
listbox1.Items.Add('to .txt text format.');
listbox1.Items.Add('');
listbox1.Items.Add('The COM connection is mapped on COM1 Port.');
listbox1.Items.Add('Baud rate: 4800 baud');
listbox1.Items.Add('Data bits: 8 b');
listbox1.Items.Add('Parity: Even');
listbox1.Items.Add('Stop bits: 1');
end;

end.
