-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelevator.adb.bak
137 lines (123 loc) · 3.77 KB
/
elevator.adb.bak
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
with Text_Io; use Text_Io;
with Ada.Integer_Text_Io; use Ada.Integer_Text_Io;
with Ada.Float_Text_Io; use Ada.Float_Text_Io;
with Ada.Numerics.Float_Random; use Ada.Numerics.Float_Random;
with Ada.Calendar; use Ada.Calendar;
with cart; use cart;
with floors; use floors;
WITH NT_Console; USE NT_Console;
procedure elevator is
cart_one : cart.cart := initCart;
task semaphore is
entry P; -- Dijkstra’s terminology
entry V; -- from the Dutch
end semaphore;
task body semaphore is
begin
loop
accept P; -- won’t accept another P until a caller asks for V
accept V;
end loop;
end semaphore;
-- Prints the elevator
PROCEDURE Print_Elevator(level : Integer) IS
Min_Level : Integer := 0;
Top_Level : Integer := 8;
print_iterator : integer := 0;
BEGIN
semaphore.p;
For I in min_level .. top_level LOOP
Goto_XY(40,12-print_iterator);
Put(Integer'Image(i));
IF I = Level THEN
Goto_XY(42,12-print_iterator);
Put("| [] |");
ELSE
Goto_XY(42,12-print_iterator);
Put("| |");
END IF;
print_iterator := print_iterator + 1;
END LOOP;
Goto_XY(0,1);
semaphore.v;
end;
--- TASK BUTTONS ----
task button_signals is
entry cart_press (F : in integer);
entry floor_press (D : in floors.direction; L : in integer);
end button_signals;
task body button_signals is
begin
loop
select
accept cart_press(F : in integer) do
pressCartButton(cart_one, F);
end cart_press;
or
accept floor_press(D : in direction; L : in integer) do
pressFloorButton(cart_one, L, D);
end floor_press;
end select;
end loop;
end button_signals;
-- Gets user input
task Get_Input;
task body Get_Input is
Level: String (1..80);
direction: String (1..80);
Length : Integer;
LengthDir : Integer;
LevelInt : Integer;
BEGIN
semaphore.p;
Goto_XY(0,0);
Put ("What do you want to do? ex. t4(to floor 4), u2(up from floor 2), d1 (down from floor 1)");
Goto_XY(0,1);
semaphore.v;
LOOP
semaphore.p;
Goto_XY(0,1);
semaphore.v;
Get_Line (level, Length);
New_Line;
IF level (1..1) = "u" THEN
LevelInt := Integer'Value (Level (2 .. 2));
button_signals.floor_press(Up, levelInt);
ELSIF level (1..1) = "d" THEN
LevelInt := Integer'Value (Level (2 .. 2));
button_signals.floor_press(Down, levelInt);
ELSIF level (1..1) = "t" THEN
LevelInt := Integer'Value (Level (2 .. 2));
button_signals.cart_press(levelInt);
end if;
semaphore.p;
Goto_XY(0,1);
Put(" "); new_line;
semaphore.v;
end loop;
end Get_Input;
-- simulation task that accepts input from terminal
PROCEDURE Inside_Elevator IS
button : String (1..80);
Length : Integer;
level : Integer;
BEGIN
Put ("Press which button?> ");
Get_Line (button, Length);
New_Line;
Level := Integer'Value (button (1..Length));
end inside_elevator;
task driveC;
task body driveC is
begin
loop
driveCart(cart_one);
Print_Elevator(cart_one.level.level);
end loop;
end driveC;
--- MAIN ---
begin
loop
delaY 60.0; --Run forever until closed
end loop;
end elevator;