2021-01-02 18:24:55 +13:00
|
|
|
defmodule Gcode do
|
2021-01-04 22:14:40 +13:00
|
|
|
alias Gcode.{Model.Program, Model.Serialise, Result}
|
|
|
|
|
2021-01-02 18:24:55 +13:00
|
|
|
@moduledoc """
|
2021-01-06 20:59:13 +13:00
|
|
|
Gcode - a library for parsing and serialising G-code.
|
|
|
|
|
|
|
|
If you haven't heard of G-code before, then you probably don't need this
|
|
|
|
library, but if you're working with CNC machines or 3D printers then G-code is
|
|
|
|
the defacto standard for working with these machines. As such it behoves us
|
|
|
|
to have first class support for working with G-code in Elixir.
|
|
|
|
|
|
|
|
You're welcome.
|
|
|
|
|
|
|
|
For functions related to parsing G-code files and commands, see the `Parser`
|
|
|
|
module. For generating your own programs see the contents of `Model`, and for
|
|
|
|
converting programs back into G-code see the `Model.Serialise` protocol.
|
2021-01-02 18:24:55 +13:00
|
|
|
"""
|
|
|
|
|
|
|
|
@doc """
|
2021-01-04 22:14:40 +13:00
|
|
|
Serialise a program to a String.
|
2021-01-02 18:24:55 +13:00
|
|
|
"""
|
2021-01-04 22:14:40 +13:00
|
|
|
@spec serialise(Program.t()) :: Result.t(String.t(), {:serialise_error, any})
|
|
|
|
def serialise(%Program{} = program) do
|
|
|
|
program
|
|
|
|
|> Serialise.serialise()
|
|
|
|
|> Result.Enum.map(fn block ->
|
|
|
|
{:ok, "#{block}\r\n"}
|
|
|
|
end)
|
|
|
|
|> Result.Enum.join("")
|
2021-01-02 18:24:55 +13:00
|
|
|
end
|
|
|
|
end
|