pattern

package
v0.0.0-...-0e88d40 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2021 License: ISC Imports: 7 Imported by: 0

README

go-lovense/pattern

Notes

File format:

V:1;T:Edge;F:v1,v2;S:100;M:...;#
0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;...
  • V is presumably the version. There doesn't seem to be code that checks for it, but presumably, it's just assumed to be 1.

  • F seems to be the motor:

    ("p" === k
      ? w.push("Air:Level")
      : "r" === k
      ? w.push("Rotate")
      : "v" === k
      ? w.push("Vibrate")
      : "v1" === k
      ? w.push("Vibrate1")
      : "v2" === k && w.push("Vibrate2"));
    
    • The Edge 2 has v1,v2, probably indicating 2 of its motors.
  • The source code seems to have toyOnlineImg, which can be useful for getting the image URL.

  • M is the MD5 hex digest of something. The code involves Math.random, so it's quite unclear. The routine generatePattern has this.

  • S is hard-coded to 100 in the generatePattern routine.

  • The final # seems to denote the separator for the metadata and the vibration data. The new lines are replaced out, and data are separated by ;.

  • The routine e.resetPatternTime is used for converting seconds to MM:SS. Tracing where it's called might be a good idea.

    • The code splits 0,0 in the data line into data0 and data1. The duration is calculated by doing

      resetPatternTime(100 * data0.length / 1000) = resetPatternTime(data0.length / 10)

    • The code also hard-codes a variable orderSpeed = 100. This seems to be used as the argument for setTimeout(). Presumably, this implies that each point in the file is executed within 100ms or 10Hz.

    • The code sets orderSpeed to patternData.data.S later on, however, presumably meaning that the S variable overrides the duration.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Feature

type Feature string

Feature is the type for the values in the F field.

const (
	AirPump  Feature = "p"
	Rotate   Feature = "r"
	Vibrate  Feature = "v"
	Vibrate1 Feature = "v1"
	Vibrate2 Feature = "v2"
)

Feature constants that are known from the Lovense Desktop's source code. Note that no validation is done against these features.

type Header struct {
	Version  Version       // V
	Type     string        // T
	Features []Feature     // F
	Interval time.Duration // S
	MD5Sum   string        // M
}

Header describes the header of a Lovense pattern file. It is everything that sits before a hash symbol (#) in a version 1 pattern file. All header fields are not guaranteed except for Interval.

type Pattern

type Pattern struct {
	Header
	Points Points
}

Pattern describes a pattern file.

func Parse

func Parse(r io.Reader) (*Pattern, error)

Parse consumes r fully and returns the Lovense pattern reader and all its points. It adds onto Reader a few guarantees.

type Point

type Point []Strength

Point describes the strengths of motors in an instant of time, or a point, in a Lovense pattern file. Version 0 pattern files will always only have a single motor, while version 1 pattern files can have more.

func (Point) Scale

func (p Point) Scale(v Version) []float64

Scale scales the point (list of strengths) into floats within range [0.0, 1.0].

func (Point) ScaleAppend

func (p Point) ScaleAppend(v Version, buf []float64) []float64

ScaleAppend is the append version of Scale.

type Points

type Points []Point

Points contains a list of points, each containing a list of vibration strength numbers. It holds multiple points representing multiple instants of time incremented by the Interval.

type Reader

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

Reader provides a Lovense pattern reader.

func NewReader

func NewReader(r io.Reader) *Reader

NewReader creates a new reader from the given io.Reader.

func (*Reader) ReadAllV0Points

func (r *Reader) ReadAllV0Points() (Points, error)

ReadAllV0Points reads all data points in a version 0 pattern file. Version 0 is not capable of containing data for more than 1 motor, so the length of the inner slice is always 1.

func (*Reader) ReadAllV1Points

func (r *Reader) ReadAllV1Points() (Points, error)

ReadAllV2Data reads all data points in a version 1 pattern file. It guarantees that all point pairs in the slice will be equally sized.

func (*Reader) ReadHeader

func (r *Reader) ReadHeader() (Header, error)

ReadHeader reads the header. Note that the method will consume more bytes from the io.Reader than it needs to, since the reader is buffered.

func (*Reader) ReadV1Points

func (r *Reader) ReadV1Points() (Point, error)

ReadV1Points reads a list of motor data points in a version 1 pattern file.

type Strength

type Strength uint8

Strength describes a single strength point inside a Lovense pattern file.

func (Strength) Scale

func (s Strength) Scale(v Version) float64

Scale scales the strength to a number within [0.0, 1.0].

type Version

type Version int

Version is the version of the pattern.

const (
	V0 Version = 0
	V1 Version = 1
)

func (Version) String

func (v Version) String() string

String returns version in "V:n" format.

Jump to

Keyboard shortcuts

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