-
Notifications
You must be signed in to change notification settings - Fork 2
/
pumpTyp.erl
41 lines (36 loc) · 1.27 KB
/
pumpTyp.erl
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
-module(pumpTyp).
-export([create/0, init/0]).
% -export([dispose/2, enable/2, new_version/2]).
% -export([get_initial_state/3, get_connections_list/2]). % use resource_type
% -export([update/3, execute/7, refresh/4, cancel/4, update/7, available_ops/2]).
create() -> {ok, spawn(?MODULE, init, [])}.
init() ->
survivor:entry(pumpTyp_created),
loop().
loop() ->
receive
% get_initial_state, self(), ]
{initial_state, [ResInst_Pid, [PipeInst_Pid, RealWorldCmdFn]], ReplyFn} ->
ReplyFn(#{resInst => ResInst_Pid, pipeInst => PipeInst_Pid,
rw_cmd => RealWorldCmdFn, on_or_off => off}),
loop();
{switchOff, State, ReplyFn} ->
#{rw_cmd := ExecFn} = State, ExecFn(off),
ReplyFn(State#{on_or_off := off}),
loop();
{switchOn, State, ReplyFn} ->
#{rw_cmd := ExecFn} = State, ExecFn(on),
ReplyFn(State#{on_or_off := on}),
loop();
{isOn, State, ReplyFn} ->
#{on_or_off := OnOrOff} = State,
ReplyFn(OnOrOff),
loop();
{flow_influence, State, ReplyFn} ->
#{on_or_off := OnOrOff} = State,
FlowInfluenceFn = fun(Flow) -> flow(Flow, OnOrOff) end, % placeholder only.
ReplyFn(FlowInfluenceFn),
loop()
end.
flow(Flow, on) -> (250 - 5 * Flow - 2 * Flow * Flow);
flow(_Flow, off) -> 0.