golibbuttplug

package module
v0.0.0-...-0cf68e8 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2017 License: BSD-3-Clause Imports: 10 Imported by: 1

README

golibbuttplug

GoDoc Go Report Card Build Status codecov.io

Package golibbuttplug provides a Buttplug websocket client.

Buttplug is a quasi-standard set of technologies and protocols to allow developers to write software that controls an array of sex toys in a semi-future-proof way.

Disclaimer

This project is not officially part of Metafetish, but you can contact me at their forums.

golibbuttplug is released under a BSD-style license.

Documentation

Overview

Package golibbuttplug provides a Buttplug websocket client.

Buttplug (https://buttplug.io/) is a quasi-standard set of technologies and protocols to allow developers to write software that controls an array of sex toys in a semi-future-proof way.

Index

Examples

Constants

View Source
const (
	// CommandStopDevice ...
	CommandStopDevice = "StopDeviceCmd"
	// CommandRaw ...
	CommandRaw = "RawCmd"
	// CommandSingleMotorVibrate ...
	CommandSingleMotorVibrate = "SingleMotorVibrateCmd"
	// CommandKiiroo ...
	CommandKiiroo = "KiirooCmd"
	// CommandFleshlightLaunchFW12 ...
	CommandFleshlightLaunchFW12 = "FleshlightLaunchFW12Cmd"
	// CommandLovense ...
	CommandLovense = "LovenseCmd"
	// CommandVorzeA10Cyclone ...
	CommandVorzeA10Cyclone = "VorzeA10CycloneCmd"
)
View Source
const DefaultName = "golibbuttplug"

DefaultName is used when no name is specified when creating a new client.

Variables

View Source
var (
	// ErrUnsupported is the error returned when the command executed is
	// not supported by the device.
	ErrUnsupported = errors.New("unsupported command")
	// ErrInvalidSpeed is the error retured when the speed is not supported
	// by the device.
	ErrInvalidSpeed = errors.New("invalid speed")
	// ErrInvalidPosition is the error retured when the position is not
	// supported by the device.
	ErrInvalidPosition = errors.New("invalid position")
	// ErrInvalidCmd is the error retured when the command is not
	// supported by the device.
	ErrInvalidCmd = errors.New("invalid command")
)

Functions

This section is empty.

Types

type Client

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

Client is a websocket API client that performs operations against a Buttplug server.

Example

This example demonstrates how to connect to Buttplug server websocket, search for devices and perform operations on the discovered devices.

// Contexts can be used to cancel client connection.
rootctx := context.Background()
// Create a new session with the server as "ExampleClient".
c, err := NewClient(rootctx, "ws://127.0.0.1:12345", "ExampleClient", nil)
if err != nil {
	log.Fatal(err)
}
// Scan for devices.
if err := c.StartScanning(); err != nil {
	log.Fatal(err)
}
// Wait for scanning to finish.
ctx, cancel := context.WithTimeout(rootctx, 30*time.Second)
err = c.WaitOnScanning(ctx)
cancel()
if err == context.DeadlineExceeded {
	// Stop scanning.
	if err := c.StopScanning(); err != nil {
		log.Fatal(err)
	}
} else if err != nil {
	log.Fatal(err)
}
// Get all known devices.
for _, d := range c.Devices() {
	// Test if the RawCmd is supported by the device.
	if d.IsSupported("RawCmd") {
		log.Printf("%s supports RawCmd", d.Name())
		// Send a RawCmd.
		if err := d.RawCmd([]byte{0x00, 0x10}); err != nil {
			log.Printf("RawCmd failed: %v", err)
		}
	}
	// Try sending a Fleshlight Launch command.
	if err := d.FleshlightLaunchFW12Cmd(50, 20); err != nil {
		log.Printf("Launch command failed: %v", err)
	}
}
// Stop all devices.
if err := c.StopAllDevices(); err != nil {
	log.Fatal(err)
}
// Close the connection.
c.Close()
Output:

func NewClient

func NewClient(ctx context.Context, addr, name string, tlscfg *tls.Config) (c *Client, err error)

NewClient returns a new client with a connection to a Buttplug server.

func (*Client) Close

func (c *Client) Close()

Close the connection.

func (*Client) Devices

func (c *Client) Devices() []*Device

Devices returns all devices currently known by the client.

func (*Client) Disconnected

func (c *Client) Disconnected() <-chan struct{}

Disconnected returns a receiver channel that is closed when the client has stopped.

func (*Client) StartScanning

func (c *Client) StartScanning() error

StartScanning requests to have the server start scanning for devices on all busses that it knows about. Useful for protocols like Bluetooth, which require an explicit discovery phase.

func (*Client) StopAllDevices

func (c *Client) StopAllDevices() error

StopAllDevices tells the server to stop all devices. Can be used for emergency situations, on client shutdown for cleanup, etc.

func (*Client) StopScanning

func (c *Client) StopScanning() error

StopScanning requests to have the server stop scanning for devices. Useful for protocols like Bluetooth, which may not timeout otherwise.

func (*Client) WaitOnScanning

func (c *Client) WaitOnScanning(ctx context.Context) error

WaitOnScanning waits until the server has stopped scanning on all busses.

type Device

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

Device structs represents a connected device and can be used to execute commands.

func (*Device) Disconnected

func (d *Device) Disconnected() <-chan struct{}

Disconnected returns a receiving channel, that is closed when the device is removed.

func (*Device) FleshlightLaunchFW12Cmd

func (d *Device) FleshlightLaunchFW12Cmd(pos, spd int) error

FleshlightLaunchFW12Cmd causes a toy that supports Fleshlight Launch (Firmware Version 1.2) style commands to run whatever event may be related.

func (*Device) IsSupported

func (d *Device) IsSupported(msgtype string) bool

IsSupported returns true if the message type is supported.

func (*Device) KiirooCmd

func (d *Device) KiirooCmd(cmd int) error

KiirooCmd causes a toy that supports Kiiroo style commands to run whatever event may be related.

func (*Device) LovenseCmd

func (d *Device) LovenseCmd(cmd string) error

LovenseCmd causes a toy that supports Lovense style commands to run whatever event may be related.

func (*Device) Name

func (d *Device) Name() string

Name returns the device name.

func (*Device) RawCmd

func (d *Device) RawCmd(cmd []byte) error

RawCmd sends a raw byte string to a device.

func (*Device) SingleMotorVibrateCmd

func (d *Device) SingleMotorVibrateCmd(spd float64) error

SingleMotorVibrateCmd causes a toy that supports vibration to run at a certain speed. In order to abstract the dynamic range of different toys, the value sent is a float with a range of [0.0-1.0].

func (*Device) StopDeviceCmd

func (d *Device) StopDeviceCmd() error

StopDeviceCmd stops a device from whatever actions it may be taking.

func (*Device) String

func (d *Device) String() string

func (*Device) Supported

func (d *Device) Supported() []string

Supported returns a list of all supported message types for this device.

func (*Device) VorzeA10CycloneCmd

func (d *Device) VorzeA10CycloneCmd(spd int, clockwise bool) error

VorzeA10CycloneCmd causes a toy that supports VorzeA10Cyclone style commands to run whatever event may be related.

Directories

Path Synopsis
Package buttplugtest provides utilities for buttplug testing.
Package buttplugtest provides utilities for buttplug testing.
Package message contains types and handlers for Buttplug messages.
Package message contains types and handlers for Buttplug messages.

Jump to

Keyboard shortcuts

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