kiiroo

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2018 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Overview

Package kiiroo manages the Kiiroo haptics protocol.

Kiiroo protocol is really wonkey so don't expect anything magical from it.

Protocol format is:

{<time>:<value>,<time>:<value>,...}

time : x.xx event time in sec
value: 0-4 position/intensity of event (but not for the Launch)

Using the Kirroo protocol, the positions sends to the Launch are always 5% and 95% (alternating.) Commands send to the Launch are interrupted/canceled by new ones, giving only the illusion of precision.

The value is used to determine if the Launch should move. The rate at which events are received determines the speed parameter of the movement command issued to the Launch.

Speed algorithm

Move with "default" speed of 50% when it has been >=2sec since last event.

Move at the "slowest" speed of 20% when is has been >=1sec since last event.

Raw speed value between events is 100 - (hundredth sec + 10%) as %. Eg:

0.20 sec = 100-22 = 78%
0.50 sec = 100-55 = 45%

If raw speed is bigger then previous speed, then increase speed with 1/6 of the difference. Eg:

Previous 50 and Raw 78 = 50+(78-50)/6 = 54%

If raw speed is smaller then previous speed, then decrease speed with 1/2 of the raw speed. Eg:

Previous 63 and Raw 45 = 63-45/2 = 41%

Speed can not go below 20%.

Movement algorithm

Stop moving if no signal has been received in 150ms.

Move only when value is different from previous event.

When events are coming in faster then 150ms, send command at 150ms intervals using last calculated speed. Reset the limiter when the receive window >150ms.

The speed is still calculated when the limiter is active, but the last send speed is used until the limiter is stopped.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrEventFormat is the error returned the event could not be parsed.
	ErrEventFormat = errors.New("invalid event format")
	// ErrNoEvents is the error returned when no events could be detected.
	ErrNoEvents = errors.New("no events found")
)

Functions

func Load

func Load(r io.Reader) (protocol.Player, error)

Load returns a Player with the Kiiroo subtitle/script loaded.

func LoadJSON added in v0.0.5

func LoadJSON(r io.Reader) (protocol.Player, error)

LoadJSON loads the FlMe JSON and returns a script player.

func LoadText added in v0.0.5

func LoadText(r io.Reader) (protocol.Player, error)

LoadText loads a VRP txt file and returns a script player.

Types

type Algorithm

type Algorithm interface {
	Actions(es Events) []protocol.TimedAction
}

Algorithm interface converts Kiiroo events into TimedActions.

type DefaultAlgorithm

type DefaultAlgorithm struct{}

DefaultAlgorithm implements the Algorithm interface trying to mimik the Kiiroo apps.

func (DefaultAlgorithm) Actions

func (da DefaultAlgorithm) Actions(es Events) []protocol.TimedAction

Actions converts Kiiroo events into Actions that can be send to a Launch.

type Event

type Event struct {
	Time  time.Duration
	Value int
}

Event contains the values of a single Kiiroo event.

func (Event) MarshalText

func (e Event) MarshalText() (text []byte, err error)

MarshalText implements the encoding.TextMarshaler interface.

func (*Event) UnmarshalText

func (e *Event) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

type Events

type Events []Event

Events is an ordered series of Event objects.

func (Events) Len added in v0.1.1

func (es Events) Len() int

Len is the number of elements in the collection.

func (Events) Less added in v0.1.1

func (es Events) Less(i, j int) bool

Less reports whether the element with index i should sort before the element with index j.

func (Events) MarshalText

func (es Events) MarshalText() (text []byte, err error)

MarshalText implements the encoding.TextMarshaler interface.

func (Events) Swap added in v0.1.1

func (es Events) Swap(i, j int)

Swap swaps the elements with indexes i and j.

func (*Events) UnmarshalText

func (es *Events) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

type ScriptPlayer

type ScriptPlayer struct {
	*protocol.TimedActionsPlayer
	// contains filtered or unexported fields
}

ScriptPlayer can load and play Kiiroo scripts/subtitles.

func NewScriptPlayer

func NewScriptPlayer() *ScriptPlayer

NewScriptPlayer returns a new ScriptPlayer using the default algorithm.

func (*ScriptPlayer) Load

func (k *ScriptPlayer) Load(r io.Reader) error

Load reads Kiiroo subtitle/script format.

Jump to

Keyboard shortcuts

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