Documentation ¶
Overview ¶
Package light implements LIFX LAN Protocol for LIFX light devices:
https://lan.developer.lifx.com/docs/light-messages
Please refer to its parent package for more background/context.
Example ¶
This example demonstrates how to set color on a light device.
package main import ( "context" "log" "time" "go.yhsif.com/lifxlan" "go.yhsif.com/lifxlan/light" ) func main() { // Need proper initialization on real code. var ( device light.Device // Important to set timeout to context when requiring ack. timeout time.Duration // Color to set. color lifxlan.Color ) ctx, cancel := context.WithTimeout(context.Background(), timeout) defer cancel() if err := device.SetColor( ctx, nil, // conn, use nil so that SetColors will maintain it for us &color, 0, // fade in duration true, // ack ); err != nil { log.Fatal(err) } }
Output:
Index ¶
Examples ¶
Constants ¶
const ( Get lifxlan.MessageType = 101 SetColor lifxlan.MessageType = 102 State lifxlan.MessageType = 107 SetLightPower lifxlan.MessageType = 117 SetWaveformOptional lifxlan.MessageType = 119 )
Light related MessageType values.
Variables ¶
This section is empty.
Functions ¶
func ConvertSkewRatio ¶
ConvertSkewRatio scales [0, 1] into [-32768, 32767].
Types ¶
type BoolUint8 ¶
type BoolUint8 uint8
BoolUint8 is the uint8 value used to represent bool.
func Bool2Uint8 ¶
Bool2Uint8 converts bool value into BoolUint8 value.
type Device ¶
type Device interface { lifxlan.Device // GetColor returns the current color on this light device. // // If conn is nil, // a new connection will be made and guaranteed to be closed before returning. // You should pre-dial and pass in the conn if you plan to call APIs on this // device repeatedly. GetColor(ctx context.Context, conn net.Conn) (*lifxlan.Color, error) // SetColor sets the light device with the given color. // // If conn is nil, // a new connection will be made and guaranteed to be closed before returning. // You should pre-dial and pass in the conn if you plan to call APIs on this // device repeatedly. // // If ack is false, // this function returns nil error after the API is sent successfully. // If ack is true, // this function will only return nil error after it received ack from the // device. SetColor(ctx context.Context, conn net.Conn, color *lifxlan.Color, transition time.Duration, ack bool) error // SetLightPower sets the power level of the device and specifies how long it // will take to transition to the new power state. // // If conn is nil, // a new connection will be made and guaranteed to be closed before returning. // You should pre-dial and pass in the conn if you plan to call APIs on this // device repeatedly. // // If ack is false, // this function returns nil error after the API is sent successfully. // If ack is true, // this function will only return nil error after it received ack from the // device. SetLightPower(ctx context.Context, conn net.Conn, power lifxlan.Power, transition time.Duration, ack bool) error // SetWaveform sends SetWaveformOptional message as defined in // // https://lan.developer.lifx.com/docs/changing-a-device#setwaveformoptional---packet-119 SetWaveform(ctx context.Context, conn net.Conn, args *SetWaveformArgs, ack bool) error }
Device is a wrapped lifxlan.Device that provides light related APIs.
func Wrap ¶
Wrap tries to wrap a lifxlan.Device into a light device.
When force is false and d is already a light device, d will be casted and returned directly. Otherwise, this function calls a light device API, and only returns a non-nil Device if it supports the API.
If the device is not a light device, the function might block until ctx is cancelled.
When returning a valid light device, the device's Label is guaranteed to be cached.
type RawSetColorPayload ¶
type RawSetColorPayload struct { Color lifxlan.Color Duration lifxlan.TransitionTime // contains filtered or unexported fields }
RawSetColorPayload defines the struct to be used for encoding and decoding.
https://lan.developer.lifx.com/docs/changing-a-device#setcolor---packet-102
type RawSetLightPowerPayload ¶ added in v0.3.1
type RawSetLightPowerPayload struct { Level lifxlan.Power Duration lifxlan.TransitionTime }
RawSetLightPowerPayload defines the struct to be used for encoding and decoding.
https://lan.developer.lifx.com/docs/changing-a-device#setlightpower---packet-117
type RawSetWaveformOptionalPayload ¶
type RawSetWaveformOptionalPayload struct { Transient BoolUint8 Color lifxlan.Color Period lifxlan.TransitionTime Cycles float32 SkewRatio int16 Waveform Waveform SetHue BoolUint8 SetSaturation BoolUint8 SetBrightness BoolUint8 SetKelvin BoolUint8 // contains filtered or unexported fields }
RawSetWaveformOptionalPayload defines the struct to be used for encoding and decoding.
https://lan.developer.lifx.com/docs/changing-a-device#setwaveformoptional---packet-119
type RawStatePayload ¶
type RawStatePayload struct { Color lifxlan.Color Power lifxlan.Power Label lifxlan.Label // contains filtered or unexported fields }
RawStatePayload defines the struct to be used for encoding and decoding.
https://lan.developer.lifx.com/docs/information-messages#lightstate---packet-107
type SetWaveformArgs ¶
type SetWaveformArgs struct { // True means that after the waveform it should go back to its original color. Transient bool // The target color. Color *lifxlan.Color // Duration of a cycle. Period time.Duration // Number of cycles. Cycles float32 // Type of waveform. Waveform Waveform // SkewRatio should be in range [0, 1] and it is only used with WaveformPulse. // // https://lan.developer.lifx.com/docs/waveforms#pulse SkewRatio float64 // The color args with Keep* set to true will not be changed. // // For example the current color has H 255, S 255, B 255 and K 255, // and the target color has H 0, S 0, B 0, K 0. // When KeepHue is false and all else are true, // Only H will be changed during the waveform, // S, B, and K won't be changed. // // Please note this is the reverse of the set_* definitions of // RawSetWaveformOptionalPayload. // The reason is to make sure that when they are all zero values, // it behaves the same as SetWaveform message as defined in: // https://lan.developer.lifx.com/docs/changing-a-device#setwaveform---packet-103 KeepHue bool KeepSaturation bool KeepBrightness bool KeepKelvin bool }
SetWaveformArgs is the args to be translated into RawSetWaveformOptionalPayload.
type Waveform ¶
type Waveform uint8
Waveform defines the type of the waveform.
https://lan.developer.lifx.com/docs/waveforms
const ( // https://lan.developer.lifx.com/docs/waveforms#saw WaveformSaw Waveform = 0 // https://lan.developer.lifx.com/docs/waveforms#sine WaveformSine Waveform = 1 // https://lan.developer.lifx.com/docs/waveforms#half-sine WaveformHalfSine Waveform = 2 // https://lan.developer.lifx.com/docs/waveforms#triangle WaveformTriangle Waveform = 3 // https://lan.developer.lifx.com/docs/waveforms#pulse WaveformPulse Waveform = 4 )
Waveform values.