Advertisement
Guest User

Untitled

a guest
Jul 27th, 2016
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 3.17 KB | None | 0 0
  1. program test12;
  2.  
  3. uses
  4.   gpio,
  5.   App, Objects, Menus, Drivers, Views, Dialogs, MsgBox, StdDlg;
  6.  
  7. type
  8.   TMyApp = object(TApplication)
  9.     constructor Init;
  10.   end;
  11.  
  12.   TLightsDialog = object(TDialog)
  13.     state1, state2, state3 : boolean;
  14.     button1, button2, button3 : PButton;
  15.  
  16.     constructor Init;
  17.     procedure HandleEvent(var Event: TEvent); virtual;
  18.   end;
  19.   PLightsDialog = ^TLightsDialog;
  20.  
  21. const
  22.   circuit1 = '16';
  23.   circuit2 = '20';
  24.   circuit3 = '21';
  25.  
  26.   cmCircuit1 = 1001;
  27.   cmCircuit2 = 1002;
  28.   cmCircuit3 = 1003;
  29.  
  30.  
  31. constructor TMyApp.Init;
  32. var
  33.   pLights : PLightsDialog;
  34. begin
  35.   inherited Init;
  36.  
  37.   pLights := New (PLightsDialog, Init);
  38.   ExecuteDialog (pLights, nil);
  39. end;
  40.  
  41.  
  42. procedure TLightsDialog.HandleEvent(var Event: TEvent);
  43. begin
  44.   inherited HandleEvent(Event);
  45.   if Event.What = evCommand then
  46.   begin
  47.     case Event.Command of
  48.     cmCircuit1:
  49.       begin
  50.         if state1 then begin
  51.           gpio.port_write(circuit1, '0');
  52.           state1 := false;
  53.           button1^.Title := NewStr('Circuit 1  [ ]');
  54.           DrawView;
  55.         end else begin
  56.           gpio.port_write(circuit1, '1');
  57.           state1 := true;
  58.           button1^.Title := NewStr('Circuit 1  [X]');
  59.           DrawView;
  60.         end;
  61.       end;
  62.     cmCircuit2:
  63.       begin
  64.         if state2 then begin
  65.           gpio.port_write(circuit2, '0');
  66.           state2 := false;
  67.           button2^.Title := NewStr('Circuit 2  [ ]');
  68.           DrawView;
  69.         end else begin
  70.           gpio.port_write(circuit2, '1');
  71.           state2 := true;
  72.           button2^.Title := NewStr('Circuit 2  [X]');
  73.           DrawView;
  74.         end;
  75.       end;      
  76.     cmCircuit3:
  77.       begin
  78.         if state3 then begin
  79.           gpio.port_write(circuit3, '0');
  80.           state3 := false;
  81.           button3^.Title := NewStr('Circuit 3  [ ]');
  82.           DrawView;
  83.         end else begin
  84.           gpio.port_write(circuit3, '1');
  85.           state3 := true;
  86.           button3^.Title := NewStr('Circuit 3  [X]');
  87.           DrawView;
  88.         end;
  89.       end;
  90.     cmQuit:
  91.       begin
  92.         gpio.port_write(circuit1, '0');
  93.         gpio.port_write(circuit2, '0');
  94.         gpio.port_write(circuit3, '0');
  95.         gpio.release(circuit1);
  96.         gpio.release(circuit2);
  97.         gpio.release(circuit3);
  98.         TApplication.Done;
  99.       end;
  100.     end;
  101.   end;
  102. end;
  103.  
  104. constructor TLightsDialog.Init;
  105. var  
  106.   R : TRect;
  107. begin
  108.   R.Assign(20, 3, 60, 17);
  109.   inherited Init (R, 'Lights');
  110.  
  111.   R.Assign(10, 2, 30, 3);
  112.   button1 := New(PButton, Init(R, 'Circuit 1  [ ]', cmCircuit1, 0));
  113.   Insert(button1);
  114.  
  115.   R.Assign(10, 5, 30, 6);
  116.   button2 := New(PButton, Init(R, 'Circuit 2  [ ]', cmCircuit2, 0));
  117.   Insert(button2);
  118.  
  119.   R.Assign(10, 8, 30, 9);
  120.   button3 := New(PButton, Init(R, 'Circuit 3  [ ]', cmCircuit3, 0));
  121.   Insert(button3);
  122.  
  123.   R.Assign(10, 11, 30, 12);
  124.   Insert (New(PButton, Init(R, 'Quit App', cmQuit, 0)));
  125.  
  126.   state1 := false;
  127.   state2 := false;
  128.   state3 := false;
  129.  
  130.   gpio.setup_output(circuit1);
  131.   gpio.setup_output(circuit2);
  132.   gpio.setup_output(circuit3);
  133. end;
  134.  
  135.  
  136. var
  137.   MyApp : TMyApp;
  138.  
  139. begin
  140.   MyApp.Init;
  141.   MyApp.Run;
  142.   MyApp.Done;
  143. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement