device

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2021 License: ISC Imports: 8 Imported by: 3

Documentation

Overview

Package device contains abstractions to handle devices.

Index

Constants

View Source
const DebounceFrequency = time.Second / 20 // 20Hz

Variables

This section is empty.

Functions

This section is empty.

Types

type ButtplugConnection

type ButtplugConnection interface {
	Command(ctx context.Context, msg buttplug.Message) (buttplug.Message, error)
	Send(ctx context.Context, msgs ...buttplug.Message)
}

ButtplugConnection describes a connection to the Buttplug (Intiface) controller. A *buttplug.Websocket will satisfy this.

type Controller

type Controller struct {
	// Device is the device that this controller belongs to.
	Device
	// contains filtered or unexported fields
}

Controller binds a device and a websocket together to provide abstraction methods for controlling it.

func NewController

func NewController(conn ButtplugConnection, device Device, debounceFreq time.Duration) *Controller

NewController creates a new device controller.

func (*Controller) Battery

func (c *Controller) Battery() (float64, error)

Battery queries for the battery level. The returned number is between 0 and 1.

func (*Controller) Linear

func (c *Controller) Linear(vectors map[int]Vector) error

Linear asks the server to linearly move the device over a certain amount of time. Linear can be asynchronous.

func (*Controller) RSSILevel

func (c *Controller) RSSILevel() (float64, error)

RSSILevel gets the received signal strength indication level, expressed as dB gain, typically like [-100:0], where -100 is the number returned.

func (*Controller) Rotate

func (c *Controller) Rotate(rotations map[int]Rotation) error

Rotate asks the server to rotate some or all of the device's motors. Rotate can be asynchronous.

func (*Controller) Stop

func (c *Controller) Stop() error

Stop asks the server to stop the device. Stop ca be asynchronous.

func (*Controller) Vibrate

func (c *Controller) Vibrate(motorSpeeds map[int]float64) error

Vibrate asks the server to start vibrating. Vibrate can be asynchronous.

func (*Controller) VibrationMotors

func (c *Controller) VibrationMotors() int

VibrationMotors returns the number of vibration motors for the device. 0 is returned if the device doesn't support vibration.

func (*Controller) VibrationSteps

func (c *Controller) VibrationSteps() []int

VibrationSteps returns the number of vibration steps that the device can support. The returned list has the length of the number of motors, with each item being the step count of each motor. Nil is returned if the device doesn't support vibration or if the server doesn't have this information.

func (*Controller) WithAsync

func (c *Controller) WithAsync() *Controller

WithAsync returns a new Controller that is fully asynchronous. When that's the case, Controller will send commands asynchronously whenever possible. The return types for command methods will always be a zero-value. Methods that behave differently when async will be explicitly documented.

func (*Controller) WithContext

func (c *Controller) WithContext(ctx context.Context) *Controller

WithContext returns a new Controller that internally uses the given context.

type Device

type Device struct {
	// Name is the device name.
	Name buttplug.DeviceName
	// Index identifies the device.
	Index buttplug.DeviceIndex
	// Messages holds the message types that the device will accept and the
	// features that it supports.
	Messages DeviceMessages
}

Device describes a single device.

type DeviceMessages

type DeviceMessages map[buttplug.MessageType]buttplug.GenericMessageAttributes

DeviceMessages is a type that holds the supported message types for a device.

type Manager

type Manager struct {
	// Broadcaster echoes the event channels that Manager listens to. This is
	// useful for guaranteeing that events are only handled after Manager itself
	// is updated.
	buttplug.Broadcaster
	// DebounceFrequency determines the frequency to debounce certain commands
	// when sending them to the websocket. It works around the internal event
	// buffers for real-time control. Default is 20Hz. -1 to disable.
	DebounceFrequency time.Duration
	// contains filtered or unexported fields
}

Manager holds an internal state of devices and does its best to keep it updated. A zero-value Manager instance is a valid Manager instance.

func NewManager

func NewManager() *Manager

NewManager creates a new device manager.

func (*Manager) Controller

func (m *Manager) Controller(conn ButtplugConnection, ix buttplug.DeviceIndex) *Controller

Controller returns a new device controller for the given device index. If the device is not found, then nil is returned.

func (*Manager) Devices

func (m *Manager) Devices() []Device

Devices returns the list of known devices. The list returned is sorted.

func (*Manager) Listen

func (m *Manager) Listen(ch <-chan buttplug.Message)

Listen listens to the given channel asynchronously. The listening routine stops when the channel closes.

func (*Manager) ListenPassthrough added in v0.0.3

func (m *Manager) ListenPassthrough(ch <-chan buttplug.Message) <-chan buttplug.Message

ListenPassthrough calls both Listen and the broadcaster's Subscribe to return a new event channel that has events passed through from the given channel. This is a helper method that abstracts the calls that most people would do all in one line. This way, the user can write this:

for ev := range m.ListenPassthrough(ws.Open(ctx)) {
}

func (*Manager) Wait

func (m *Manager) Wait()

Wait waits until all the background goroutines of Manager exits.

type Rotation

type Rotation struct {
	// Speed is the rotation speed.
	Speed float64
	// Clockwise is the direction of rotation.
	Clockwise bool
}

Rotation describes a rotation that rotating motor does.

type Vector

type Vector struct {
	// Duration is the movement time.
	Duration time.Duration
	// Position is the target position ranging from 0.0 to 1.0.
	Position float64
}

Vector describes the linear movement of a motor.

Jump to

Keyboard shortcuts

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