-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimpulsegenerator.adb
57 lines (48 loc) · 1.48 KB
/
impulsegenerator.adb
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
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
with RandomNumber;
with Heart;
package body ImpulseGenerator is
procedure Init(Gen : out GeneratorType) is
begin
Gen.IsOn := False;
Gen.Impulse := Measures.Joules'First;
end Init;
procedure On(Gen : in out GeneratorType) is
begin
Gen.IsOn := True;
end On;
procedure Off(Gen : in out GeneratorType) is
begin
Gen.IsOn := False;
end Off;
function IsOn(Gen : in GeneratorType) return Boolean is
begin
return Gen.IsOn;
end IsOn;
procedure SetImpulse(Gen : in out GeneratorType; J : in Measures.Joules) is
begin
-- Only set the impulse if the machine is on
if Gen.IsOn then
Gen.Impulse := J;
end if;
end SetImpulse;
procedure Tick(Gen : in GeneratorType; Hrt : in out Heart.HeartType) is
HrtVariable : Heart.HeartType;
begin
-- Administer the impulse if the generator is on
if Gen.IsOn then
-- For an 'out' variable, we must create a new variable for
-- the call, and the copy the output value from
-- Heart.SetImpulse back to Ptnt
HrtVariable := Hrt;
Heart.SetImpulse(HrtVariable, Gen.Impulse);
if (Gen.Impulse /= 0) then
Put("generate a impulse -->");
Put(Item => Gen.Impulse);
New_Line;
end if;
Hrt := HrtVariable;
end if;
end Tick;
end ImpulseGenerator;