Documentation ¶
Index ¶
- Variables
- func Argument(address byte) stringFunc
- func Code(address byte) codeFunc
- func Command(address Addressable, v float64, accepts ...Addressable) commandFunc
- func LimitCode(c codeFunc, min float64, max float64) codeFunc
- func LimitCommand(c commandFunc, limits ...Parameter) commandFunc
- type Addressable
- type CodePoint
- type Document
- type Fragment
- type HookFn
- type Keyable
- type Parameter
- type Valuable
Constants ¶
This section is empty.
Variables ¶
var ( A = Code('A') B = Code('B') C = Code('C') D = Code('D') E = Code('E') F = Code('F') G = Code('G') H = Code('H') I = Code('I') J = Code('J') K = Code('K') L = Code('L') M = Code('M') N = Code('M') O = Code('O') P = Code('P') Q = Code('Q') R = Code('R') S = Code('S') T = Code('T') U = Code('U') V = Code('V') W = Code('W') X = Code('X') Y = Code('Y') Z = Code('Z') String = Argument('_') Comment = Argument(';') )
var ( Initializer = code{ // contains filtered or unexported fields } Finalizer = code{ // contains filtered or unexported fields } )
var PanicOnLimitFailure bool
var Precision = 2
Functions ¶
func Argument ¶
func Argument(address byte) stringFunc
Argument is similar to Code, but rather than have a function that takes a float64 as its value, it accepts a string. This way you can have commands like M400 that optionally have a string value to write to an LCD.
func Code ¶
func Code(address byte) codeFunc
Code creates a code func for the given address. For example: `banana : =Code('X')` returns a code function, `banana()` that can be used to represent an X code in the final output.
func Command ¶
func Command(address Addressable, v float64, accepts ...Addressable) commandFunc
Command is a slightly higher order GCode, that is, one that can accept arguments/parameters. This function will generate a function for creating functions (trippy, I know), that allows you to define what commands are available to your gcode program.
Why would you even go down this route? This lets the compiler help enforce the available commands and it also lets us add constraints rather than it just being a simple string.
The command returned by this function will only accept values that are provided and will consume them in the order defined in the argument list. That is to say, if you want to accept Z Y into your M9001 command, you can with `Command(M, 9001.0, Z, Y)`.
The address is the GCode underwhich this command lives(M, G, etc.).
func LimitCode ¶
LimitCode adds a limiter to the possible values of a code. Any code wrapped with this function can only have values between the min and max.
func LimitCommand ¶
func LimitCommand(c commandFunc, limits ...Parameter) commandFunc
LimitCommand wraps the given commandFunc and applies a series of limits to its inputs. The limits are expected to be in tupes (min, max) and share the same address (X, Y, etc.). If the address is not the same or the count of the limits in not even either: - the error is ignored and all limits are ignored - a panic is triggered
This is controlled by the PanicOnLimitFailure variable.
Types ¶
type Addressable ¶
type Addressable interface {
Address() byte
}
type Document ¶
type Document struct {
// contains filtered or unexported fields
}
Document is a gcode document or program that controls a machine of some kind. It supports the addition of hooks to alter the behavior of gcode on a per-document level. This allows the document to be changed to suit different machines or limitations. For example, let's say that at a general level, you want to change from tool 1 to tool 2. Not all machines have automatic tool changers and some require a different procedure to change the tool.
Having a hook on the M600 command, for example, allows the original generator of the gcode to be unconcerned with _how_ the "filament" (in this case) changes, just that it changes. A machine can override the M600 command and insert the correct procedure (move to a specific point, pause, re-probe, etc.).
*Any* gcode can be intercepted with a hook, with the addition of a couple extra ones. There are Initializer and Finalizer hooks available, to do exactly what their names are -- add a fragment to the beginning or end of the document, respectively.
func (*Document) AddFragment ¶
AddFragment appends the contents of a fragment to the document
func (*Document) AddHook ¶
AddHook sets the hook function for the given command. There can only be one hook per command.
func (*Document) AddLines ¶
func (d *Document) AddLines(l ...code)
/ AddLines adds one or more lines of Codes to the document
func (*Document) Initalizer ¶
type Fragment ¶
type Fragment []code
Fragment is a collection of codes, intended to be part of a final gcode document
func Parse ¶
Parse works through the reader line-wise, converting each line into the correct code values. It attempts to use the correct addresses and vaues that will match the original input. Addresses (G,M, T, etc.) are expected to be upper case, otherwise they will be considered as string arguments.
Empty lines are ignored and will not be present in the resulting output of Fragment.String().
func ParseString ¶
ParseString is a helper function. Rather than a reader, it takes a string and turns it into a reader for you.
type HookFn ¶
HookFn is a function that accepts a CodePoint and returns a Fragment that contains a replacement definition. The original codepoint will not be part of the final document *unless it is returned as part of the Fragment*.
type Parameter ¶
type Parameter interface { Addressable Valuable }