Gcode.Model.Block (gcode v0.4.1)

A sequence of G-code words on a single line.

Link to this section Summary

Types

Any error results in this module will return this type

t()

Functions

Set a comment on the block (this is just a sugar to make sure that the comment is rendered on the same line as the block).

Initialise a new empty G-code program.

Pushes a Word onto the word list.

An accessor which returns the block's words in the correct order.

Link to this section Types

Link to this type

block_contents()

Specs

Link to this type

block_error()

Specs

block_error() :: {:block_error, String.t()}

Any error results in this module will return this type

Specs

t() :: %Gcode.Model.Block{
  comment: Gcode.Option.t(Gcode.Model.Comment),
  words: [block_contents()]
}

Link to this section Functions

Link to this function

comment(block, comment)

Specs

Set a comment on the block (this is just a sugar to make sure that the comment is rendered on the same line as the block).

Note: Once a block has a comment set, it cannot be overwritten.

Examples

iex> {:ok, comment} = Comment.init("Jen, in the swing seat, with her night terrors")
...> {:ok, block} = Block.init()
...> {:ok, block} = Block.comment(block, comment)
...> Result.ok?(block.comment)
true

Specs

init() :: Gcode.Result.t(t())

Initialise a new empty G-code program.

Example

iex> Block.init()
{:ok, %Block{words: [], comment: none()}}
Link to this function

push(block, pushable)

Specs

Pushes a Word onto the word list.

Note: Block stores the words in reverse order because of Erlang list semantics, you should pretty much always use words/1 to retrieve them in the correct order.

Example

iex> {:ok, block} = Block.init()
...> {:ok, word} = Word.init("G", 0)
...> {:ok, block} = Block.push(block, word)
...> {:ok, word} = Word.init("N", 100)
...> Block.push(block, word)
{:ok, %Block{words: [%Word{word: "N", address: %Integer{i: 100}}, %Word{word: "G", address: %Integer{i: 0}}]}}

Specs

An accessor which returns the block's words in the correct order.

iex> {:ok, block} = Block.init()
...> {:ok, word} = Word.init("G", 0)
...> {:ok, block} = Block.push(block, word)
...> {:ok, word} = Word.init("N", 100)
...> {:ok, block} = Block.push(block, word)
...> Block.words(block)
{:ok, [%Word{word: "G", address: %Integer{i: 0}}, %Word{word: "N", address: %Integer{i: 100}}]}