block

package
v0.0.0-...-58d9c32 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 25, 2015 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HatCentre = 0

	HatNorth = 1
	HatEast  = 2
	HatSouth = 4
	HatWest  = 8

	HatMask = 15
	HatMax  = 16
)

hat values are bitmasks

View Source
const (
	Invalid = PortType(parser.Invalid)
	Bool    = PortType(parser.Bool)
	Float64 = PortType(parser.Scalar)
	Int     = PortType(parser.Hat)
	Any     = PortType(parser.Any)
)
View Source
const (
	DefaultTickFreq = 1e3 // 1 millisecond

)

Variables

View Source
var DefaultTypeMap = make(TypeMap)

Functions

func CheckInput

func CheckInput(i interface{}) error

func CheckInputs

func CheckInputs(typ string, v ...interface{}) error

func CheckOutput

func CheckOutput(p Port) error

func Connect

func Connect(i interface{}, port Port) error

func DebugOutput

func DebugOutput(w io.Writer, p *Profile, names ...string)

func PortString

func PortString(p Port) string

func Register

func Register(name string, fn func() Block)

func RegisterBoolFunc

func RegisterBoolFunc(name string, fn func(Param) (func(bool) bool, error))

func RegisterCmpFunc

func RegisterCmpFunc(name string, fn func(a, b float64) bool)

func RegisterHatFunc

func RegisterHatFunc(name string, f HatFunc)

func RegisterLogicFunc

func RegisterLogicFunc(name string, fn func(a, b bool) bool)

func RegisterMathBlock

func RegisterMathBlock(name string, fn func(a, b float64) float64)

func RegisterParam

func RegisterParam(name string, fn func(Param) (Block, error))

func RegisterScalarFunc

func RegisterScalarFunc(name string, fn func(Param) (func(float64) float64, error))

func RegisterStickFunc

func RegisterStickFunc(name string, ff func(p Param) (StickFunc, error))

func RegisterType

func RegisterType(t Type)

func VarArgCheck

func VarArgCheck(t string, iv interface{}, min int) error

func VarArgInput

func VarArgInput(t string, iv interface{}) *varArgInput

Types

type Block

type Block interface {
	Input() InputMap
	Output() OutputMap

	// Validate reports whether the Block is valid after setup.
	// It must check if all its non-optional inputs were set correctly.
	// Optional inputs should be set to a usable value typically
	// during Block creation.
	Validate() error
}

a block is a set of inputs and outputs producer blocks may have nil inputs, and sink blocks may have nil outputs

type Closer

type Closer interface {
	Close() error
}

type HatFunc

type HatFunc func(xi, yi int) int

type IO

type IO interface {
	Names() []string
	Value(sel string) interface{}
}

type InputMap

type InputMap interface {
	TypeInputMap
	Set(sel string, port Port) error
}

func MapInput

func MapInput(t string, v ...MapDecl) InputMap

func SingleInput

func SingleInput(t string, i interface{}) InputMap

type MapDecl

type MapDecl struct {
	N string
	V interface{}
}

type OutputMap

type OutputMap interface {
	IO
	Get(sel string) (Port, error)
}

func MapOutput

func MapOutput(t string, v ...MapDecl) OutputMap

func SingleOutput

func SingleOutput(t string, p Port) OutputMap

type Param

type Param interface {
	Arg(string) float64
	OptArg(string, float64) float64

	TickFreq() float64 // ticks per seconds: 1e6/float64(c.UpdateMicros)
	TickTime() float64 // time in seconds elapsed duting one tick: float64(c.UpdateMicros) / 1e6
}
var ProtoParam Param = new(protoparam)

ProtoParam represents an empty parameter map used during prototype creation in type checks. Arg() values will are eauql to 0.5, and OptArg() always returns the default. An update frequency of 1e3 is assumed. Block types registered using Register() or RegisterParam() should not return an error when this value is provided.

type Port

type Port interface{}

Port is one of:

*float64 - axis
*bool - button, flag
*int - hat

func ZeroValue

func ZeroValue(t PortType) Port

ZeroValue creates a zero value for a port type. Only concrete types are supported, for Invalid and Any it panics.

type PortType

type PortType parser.PortType

func PtrTypeOf

func PtrTypeOf(pport interface{}) PortType

func TypeOf

func TypeOf(port Port) PortType

type PortTypeMap

type PortTypeMap map[string]PortType

type Profile

type Profile struct {
	D       time.Duration
	Blocks  []Block
	Tickers []Ticker
	Names   map[Block]string
}

func Load

func Load(fn string) (*Profile, error)

func LoadProfile

func LoadProfile(fn string, tm TypeMap) (*Profile, error)

func Parse

func Parse(src string) (*Profile, error)

func ParseProfile

func ParseProfile(src string, tm TypeMap) (*Profile, error)

func (*Profile) Close

func (p *Profile) Close() error

func (*Profile) Tick

func (p *Profile) Tick()

type Proto

type Proto struct {
	TypeName  string
	NeedInput bool
	Create    func(Param) (Block, error)
}

Proto is a simple block type that implements input and output port reporting using a prototype block.

func (*Proto) Accept

func (t *Proto) Accept(i PortTypeMap) (PortTypeMap, error)

func (*Proto) Input

func (t *Proto) Input() TypeInputMap

func (*Proto) Name

func (t *Proto) Name() string

func (*Proto) New

func (t *Proto) New(p Param) (Block, error)

func (*Proto) Verify

func (t *Proto) Verify(p Param) error

type StickFunc

type StickFunc func(xi, yi float64) (xo, yo float64)

type Ticker

type Ticker interface {
	Tick()
}

ticker is an interface for blocks that needs update once upon each update tick.

type Type

type Type interface {
	Name() string
	New(Param) (Block, error)

	Verify(Param) error // verify parameters
	Input() TypeInputMap
	Accept(in PortTypeMap) (PortTypeMap, error) // tests wether type accepts in, and what it would return in this case
}

type TypeInputMap

type TypeInputMap interface {
	IO
	Type(sel string) PortType
}

TypeInputMap specifies order of inputs and their types for a Block Type. It is an error to call Type() with sel not in Names().

type TypeMap

type TypeMap map[string]Type

Directories

Path Synopsis
device

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL