logic_sim v0.1.4 LogicSim.Node behaviour View Source
A node is the basic building block of LogicSim. A node is a GenServer that has 0 or more inputs, and 0 or more outputs. Each node keeps track of which nodes are connected to each of its outputs. When an output changes the node sends a message to its connected nodes telling them what value to set on the input they are conneted to.
Nodes are modules that use LogicSim.Node
as demonstrated below, optionally specifying a list of inputs,
a list of outputs, and/or a map with additional state:
defmodule LogicSim.Node.Or do
use LogicSim.Node, inputs: [:a, :b], outputs: [:a]
defmodule LogicSim.Node.OnOffSwitch do
use LogicSim.Node, outputs: [:a], additional_state: %{on: false}
and implement the callback calculate_outputs/2 to generate all output values given the current input
values as demonstrated here (the Not
gate):
def calculate_outputs(_state, %{a: a} = _input_values) do
%{a: !a}
end
Link to this section Summary
Functions
Generic version of function that allows linking of two nodes without having to know or call the specific node type's version.
Link to this section Functions
get_state(server) View Source
link_output_to_node(server, output, node, input) View Source
Generic version of function that allows linking of two nodes without having to know or call the specific node type's version.