Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program test12;
- uses
- gpio,
- App, Objects, Menus, Drivers, Views, Dialogs, MsgBox, StdDlg;
- type
- TMyApp = object(TApplication)
- constructor Init;
- end;
- TLightsDialog = object(TDialog)
- state1, state2, state3 : boolean;
- button1, button2, button3 : PButton;
- constructor Init;
- procedure HandleEvent(var Event: TEvent); virtual;
- end;
- PLightsDialog = ^TLightsDialog;
- const
- circuit1 = '16';
- circuit2 = '20';
- circuit3 = '21';
- cmCircuit1 = 1001;
- cmCircuit2 = 1002;
- cmCircuit3 = 1003;
- constructor TMyApp.Init;
- var
- pLights : PLightsDialog;
- begin
- inherited Init;
- pLights := New (PLightsDialog, Init);
- ExecuteDialog (pLights, nil);
- end;
- procedure TLightsDialog.HandleEvent(var Event: TEvent);
- begin
- inherited HandleEvent(Event);
- if Event.What = evCommand then
- begin
- case Event.Command of
- cmCircuit1:
- begin
- if state1 then begin
- gpio.port_write(circuit1, '0');
- state1 := false;
- button1^.Title := NewStr('Circuit 1 [ ]');
- DrawView;
- end else begin
- gpio.port_write(circuit1, '1');
- state1 := true;
- button1^.Title := NewStr('Circuit 1 [X]');
- DrawView;
- end;
- end;
- cmCircuit2:
- begin
- if state2 then begin
- gpio.port_write(circuit2, '0');
- state2 := false;
- button2^.Title := NewStr('Circuit 2 [ ]');
- DrawView;
- end else begin
- gpio.port_write(circuit2, '1');
- state2 := true;
- button2^.Title := NewStr('Circuit 2 [X]');
- DrawView;
- end;
- end;
- cmCircuit3:
- begin
- if state3 then begin
- gpio.port_write(circuit3, '0');
- state3 := false;
- button3^.Title := NewStr('Circuit 3 [ ]');
- DrawView;
- end else begin
- gpio.port_write(circuit3, '1');
- state3 := true;
- button3^.Title := NewStr('Circuit 3 [X]');
- DrawView;
- end;
- end;
- cmQuit:
- begin
- gpio.port_write(circuit1, '0');
- gpio.port_write(circuit2, '0');
- gpio.port_write(circuit3, '0');
- gpio.release(circuit1);
- gpio.release(circuit2);
- gpio.release(circuit3);
- TApplication.Done;
- end;
- end;
- end;
- end;
- constructor TLightsDialog.Init;
- var
- R : TRect;
- begin
- R.Assign(20, 3, 60, 17);
- inherited Init (R, 'Lights');
- R.Assign(10, 2, 30, 3);
- button1 := New(PButton, Init(R, 'Circuit 1 [ ]', cmCircuit1, 0));
- Insert(button1);
- R.Assign(10, 5, 30, 6);
- button2 := New(PButton, Init(R, 'Circuit 2 [ ]', cmCircuit2, 0));
- Insert(button2);
- R.Assign(10, 8, 30, 9);
- button3 := New(PButton, Init(R, 'Circuit 3 [ ]', cmCircuit3, 0));
- Insert(button3);
- R.Assign(10, 11, 30, 12);
- Insert (New(PButton, Init(R, 'Quit App', cmQuit, 0)));
- state1 := false;
- state2 := false;
- state3 := false;
- gpio.setup_output(circuit1);
- gpio.setup_output(circuit2);
- gpio.setup_output(circuit3);
- end;
- var
- MyApp : TMyApp;
- begin
- MyApp.Init;
- MyApp.Run;
- MyApp.Done;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement