{ RoboLinex 1.5 Programa de control de dispositivos RCX de Lego en entorno grfico. Copyright (C) 2003 Prodel S.A Programador: Daniel Pascual Dominguez Este programa es software libre. Puede redistribuirlo y/o modificarlo bajo los términos de la Licencia Pública General de GNU según es publicada por la Free Software Foundation, bien de la versión 2 de dicha Licencia o bien (según su elección) de cualquier versión posterior. Este programa se distribuye con la esperanza de que sea útil, pero SIN NINGUNA GARANTÍA, incluso sin la garantía MERCANTIL implícita o sin garantizar la CONVENIENCIA PARA UN PROPÓSITO PARTICULAR. Véase la Licencia Pública General de GNU para más detalles. Debería haber recibido una copia de la Licencia Pública General junto con este programa. Si no ha sido así, escriba a la Free Software Foundation, Inc., en 675 Mass Ave, Cambridge, MA 02139, EEUU. } unit uentradas; interface uses SysUtils, Types, Classes, Variants, QTypes, QGraphics, QControls, QForms, QDialogs, QStdCtrls, QExtCtrls, selentradas; type Tfentradasp4 = class(TForm) Image1: TImage; Image2: TImage; Image3: TImage; Image4: TImage; Panel1: TPanel; Button1: TButton; Button2: TButton; Label1: TLabel; Image6: TImage; Image7: TImage; Panel2: TPanel; Button3: TButton; Button4: TButton; Label2: TLabel; Image5: TImage; Image8: TImage; Image9: TImage; Image10: TImage; Image11: TImage; Shape1: TShape; Shape2: TShape; procedure Image2Click(Sender: TObject); procedure Image1Click(Sender: TObject); procedure Image9Click(Sender: TObject); procedure Image3Click(Sender: TObject); procedure Image4Click(Sender: TObject); procedure Button4Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Image5Click(Sender: TObject); procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Image7Click(Sender: TObject); procedure FormCreate(Sender: TObject); private { Private declarations } estado:integer; comando:string; comandoset:string; entrada:string; tipo:string; extx,exty:integer; inicial:integer; simple:integer; limiteluz:integer; mayor:integer; aleatorio:integer; tiempo:single; public { Public declarations } selecentrada: Tselecentrada; procedure inicializar(est,posix,posiy:integer;tip:string;ini,simpl:integer;entrad:string;limitelu,mayo,aleatori:integer;tiemp:single); procedure cambiaestado; function dar_comando_ini:string; function dar_comando:string; function dar_comando_clear:string; function dar_comando_fin:string; function dar_estado:string; end; var fentradasp4: Tfentradasp4; procedure Replace(var S : String; Const OldString, NewString : String); implementation {$R *.xfm} procedure Tfentradasp4.inicializar(est,posix,posiy:integer;tip:string;ini,simpl:integer;entrad:string;limitelu,mayo,aleatori:integer;tiemp:single); var stiemp,lim:string; begin estado:=est; Top:=posiy; left:=posix; width:=63; height:=64; inicial:=ini; simple:=simpl; selecentrada.entrada:=entrad; limiteluz:=limitelu; mayor:=mayo; aleatorio:=aleatori; tiempo:=tiemp; tipo:=tip; // extx:=255; // if (tipo='1') or (tipo='2') then // begin exty:=64; extx:=277; // end; // if inicial=2 then exty:=193; // if inicial=3 then exty:=257; if tipo='2' then begin image1.picture:=image2.Picture; comando:=''; comandoset:=''; // selecentrada.Hide; end; if tipo='1' then begin image1.picture:=image9.Picture; comando:=''; comandoset:=''; // selecentrada.Hide; end; if tipo='3' then begin height:=131; // exty:=80; // extx:=63; image1.picture:=image3.Picture; comando:=''; comandoset:=''; panel2.left:=0; panel1.left:=80; str(limiteluz,lim); label2.caption:=lim; if mayor=0 then begin image5.picture:=image8.Picture; mayor:=0; end else begin image5.picture:=image10.Picture; mayor:=1; end // selecentrada.Hide; end; if tipo='4' then begin height:=131; panel2.left:=80; panel1.left:=0; // exty:=80; // extx:=63; image1.picture:=image4.Picture; comando:=''; comandoset:=''; stiemp:=formatfloat('#,##0.00',tiempo); label1.caption:=stiemp; if aleatori=1 then begin image7.picture:=image6.Picture; aleatorio:=1; end else begin image7.picture:=image11.Picture; aleatorio:=0; end; //estado:=0; // cambiaestado; // selecentrada.Hide; end; entrada:=entrad; selecentrada.inicializar(posix+15,posiy-37,entrada); end; procedure Tfentradasp4.cambiaestado; begin if estado=1 then begin width:=63; height:=64; estado:=0; end else begin width:=extx; height:=exty; estado:=1; end; end; procedure Tfentradasp4.Image1Click(Sender: TObject); begin cambiaestado; end; procedure Tfentradasp4.Image2Click(Sender: TObject); begin image1.picture:=image2.Picture; comando:=''; tipo:='2'; cambiaestado; // selecentrada.hide; end; procedure Tfentradasp4.Image9Click(Sender: TObject); begin image1.picture:=image9.Picture; comando:=''; tipo:='1'; cambiaestado; // selecentrada.hide; end; procedure Tfentradasp4.Image3Click(Sender: TObject); begin height:=131; width:=63; image1.picture:=image3.Picture; comando:=''; comandoset:=''; panel2.left:=0; panel1.left:=80; tipo:='3'; // cambiaestado; estado:=0; // selecentrada.hide; end; procedure Tfentradasp4.Image4Click(Sender: TObject); begin panel2.left:=80; panel1.left:=0; height:=131; width:=63; image1.picture:=image4.Picture; comando:=''; comandoset:=''; tipo:='4'; //cambiaestado; estado:=0; end; procedure Tfentradasp4.Button4Click(Sender: TObject); var slimit:string; begin if limiteluz > 0 then begin limiteluz:=limiteluz-1; str(limiteluz,slimit); label2.caption:=slimit; end; end; procedure Tfentradasp4.Button3Click(Sender: TObject); var slimit:string; begin if limiteluz < 100 then begin limiteluz:=limiteluz+1; str(limiteluz,slimit); label2.caption:=slimit; end; end; procedure Tfentradasp4.Image5Click(Sender: TObject); begin if mayor=1 then begin image5.picture:=image8.Picture; mayor:=0; end else begin image5.picture:=image10.Picture; mayor:=1; end; end; procedure Tfentradasp4.Button1Click(Sender: TObject); var stiemp:string; begin if tiempo > 0.1 then begin tiempo:=tiempo-0.1; stiemp:=formatfloat('#,##0.00',tiempo); label1.caption:=stiemp; end; end; procedure Tfentradasp4.Button2Click(Sender: TObject); var stiemp:string; begin tiempo:=tiempo+0.1; stiemp:=formatfloat('#,##0.00',tiempo); //str(tiempo,stiemp); label1.caption:=stiemp; end; procedure Tfentradasp4.Image7Click(Sender: TObject); begin if aleatorio=0 then begin image7.picture:=image6.Picture; aleatorio:=1; end else begin image7.picture:=image11.Picture; aleatorio:=0; end end; function Tfentradasp4.dar_comando_ini:string; begin dar_comando_ini:=''; if (tipo = '1') or (tipo='2')then dar_comando_ini:='SetSensor(SENSOR_'+selecentrada.dar_entrada+',SENSOR_TOUCH);'; // showmessage(tipo); if (tipo = '3') then dar_comando_ini:='SetSensor(SENSOR_'+selecentrada.dar_entrada+',SENSOR_LIGHT);'; end; function Tfentradasp4.dar_comando_fin:string; var limite,stiem:string; begin str(limiteluz,limite); dar_comando_fin:=''; if (tipo='1') then dar_comando_fin:='until(SENSOR_'+selecentrada.dar_entrada+' == 1);'; if (tipo='2') then dar_comando_fin:='until(SENSOR_'+selecentrada.dar_entrada+' == 0);'; if (tipo='3') then if mayor=1 then dar_comando_fin:='until(SENSOR_'+selecentrada.dar_entrada+' > '+limite+');' else dar_comando_fin:='until(SENSOR_'+selecentrada.dar_entrada+' < '+limite+');' end; function Tfentradasp4.dar_comando:string; var stiempo,stiem,t1,t2:string; top,ti,code:integer; begin if (tipo='4') then if aleatorio=0 then begin //ti:=trunc(tiempo); //str(ti,t1); t1:= formatfloat('#,##',tiempo*100); // str(tiempo*100,t1); //replace(t1,',','.'); //val(t1,ti,code); //ti:=ti*100; //str(ti,t2); dar_comando:='Wait('+t1+');' end else begin top:=trunc(tiempo); randomize; str(random(top*100),stiem); dar_comando:='Wait('+stiem+');' end else dar_comando:=''; end; function Tfentradasp4.dar_comando_clear:string; begin dar_comando_clear:=''; dar_comando_clear:='ClearSensor(SENSOR_'+selecentrada.dar_entrada+');'; end; function Tfentradasp4.dar_estado:string; var cadena:string; sest,sposix,sposiy,sini,ssimpl,slimiteluz,smayor,saleatorio,stiempo:string; begin str(estado,sest); str(left,sposix); str(top,sposiy); str(inicial,sini); str(simple,ssimpl); str(limiteluz,slimiteluz); str(mayor,smayor); str(aleatorio,saleatorio); //str(tiempo,stiempo); stiempo:=formatfloat('#,##0.00',tiempo); replace(stiempo,',','*'); dar_estado:=sest+' '+sposix+' '+sposiy+' '+tipo+' '+sini+' '+ssimpl+' '+selecentrada.entrada+' '+slimiteluz+' '+smayor+' '+saleatorio+' '+stiempo; end; procedure Tfentradasp4.FormCreate(Sender: TObject); begin Application.CreateForm(Tselecentrada, selecentrada); //selecentrada.Visible:=false; //selecentrada.inicializar(posix+15,posiy-37,entrada); end; procedure Replace(var S : String; Const OldString, NewString : String); var P, L : Integer; begin if Pos(OldString, NewString)=0 then begin L :=Length(OldString); P :=Pos(OldString, S); while P > 0 do begin delete(S, P, L); insert(NewString, S, P); P := Pos(OldString, S); end end; end; end.