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 ¶
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 ¶
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 ¶
Event contains the values of a single Kiiroo event.
func (Event) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface.
func (*Event) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface.
type Events ¶
type Events []Event
Events is an ordered series of Event objects.
func (Events) Less ¶ added in v0.1.1
Less reports whether the element with index i should sort before the element with index j.
func (Events) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface.
func (*Events) UnmarshalText ¶
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.