device

package
v0.0.0-...-73beaae Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2020 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StringOp

func StringOp(i message.Instruction) interface{}

StringOp simply returns the type of the received message as a string

Types

type CapabilityImplementation

type CapabilityImplementation func(message.Instruction) interface{}

CapabilityImplementation is a function typedef; these functions accept a `message.Instruction` and return whatever the specific device needs.

type Generic

type Generic interface {
	// Capabilities returns the capabilities supported by this device
	Capabilities() []string

	// HasCapabilities returns true/false if a device supports all the specified capabilities
	HasCapabilities(...string) bool

	// CapabilitySubset takes a slice of 'requested' capabilities and returns the subset supported by
	// this device
	CapabilitySubset(...string) []string

	// Name returns the name of the device
	Name() string

	// Send an instruction to the device
	Send(message.Instruction)

	// Stop cleans up whatever resources we might have opened when connecting to the device
	Stop()
}

Generic provides a generic interface for interacting with devices

type ImplementationSet

type ImplementationSet map[string]CapabilityImplementation

ImplementationSet maps a feature to a CapabilityImplementation for a device

func StringifyImplementationSet

func StringifyImplementationSet(capabilities ...string) ImplementationSet

StringifyImplementationSet will bind the StringOp implementation to every specified capabilitiy just used for debugging

type Set

type Set struct {
	// contains filtered or unexported fields
}

Set is a container for an arbitrary number of devices, with methods for interacting with them as a collection

func (*Set) Len

func (s *Set) Len() int

Len returns the number of devices in the device set

func (*Set) Register

func (s *Set) Register(d Generic)

Register adds a device to the `Set`

func (*Set) Send

func (s *Set) Send(m message.Instruction)

Send will pass the `message.Instruction` along to any contained devices which support the instruction type. This could be heavily optimized.

func (*Set) Stop

func (s *Set) Stop()

Stop sends a shutdown signal to every registered device

type UDPVibrator

type UDPVibrator struct {
	// contains filtered or unexported fields
}

UDPVibrator is a test/demo device. It simply accepts instructions and writes them out to a udp connection

func NewUDPVibrator

func NewUDPVibrator(conf UDPVibratorConfig) (*UDPVibrator, error)

NewUDPVibrator returns a fully-initialized UdpVibrator ready for use

func (*UDPVibrator) Capabilities

func (vibrator *UDPVibrator) Capabilities() []string

Capabilities returns the capabilities supported by this device. This device only supports vibrate on/off, we assume the device tracks its own internal state, so sending "vibrate, vibrate, vibrate" will result in the device turning on, then off, then on.

func (*UDPVibrator) CapabilitySubset

func (vibrator *UDPVibrator) CapabilitySubset(requestedCaps ...string) []string

CapabilitySubset takes a list of requested capabilities and returns those which this device supports

func (*UDPVibrator) HasCapabilities

func (vibrator *UDPVibrator) HasCapabilities(requestedCaps ...string) bool

HasCapabilities returns true/false if all capabilities are supported by this device

func (*UDPVibrator) Name

func (vibrator *UDPVibrator) Name() string

Name returns the vibrator name

func (*UDPVibrator) Send

func (vibrator *UDPVibrator) Send(m message.Instruction)

Send a message to the vibrator

func (*UDPVibrator) Stop

func (vibrator *UDPVibrator) Stop()

Stop closes the network connection to the vibrator

type UDPVibratorConfig

type UDPVibratorConfig struct {
	Endpoint string
}

UDPVibratorConfig configures the UdpVibrator `Endpoint` an "ip:port" address for the device. e.g: "127.0.0.1:9999"

Jump to

Keyboard shortcuts

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