本文整理汇总了Golang中github.com/pdf/golifx/common.Light.SetPowerDuration方法的典型用法代码示例。如果您正苦于以下问题:Golang Light.SetPowerDuration方法的具体用法?Golang Light.SetPowerDuration怎么用?Golang Light.SetPowerDuration使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/pdf/golifx/common.Light
的用法示例。
在下文中一共展示了Light.SetPowerDuration方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: GetHKLight
func GetHKLight(light common.Light) *HKLight {
hkLight, found := lights[light.ID()]
if found {
return hkLight
}
label, _ := light.GetLabel()
log.Debug.Printf("Creating New HKLight for %s", label)
info := accessory.Info{
Name: label,
Manufacturer: "LIFX",
}
acc := accessory.NewLightbulb(info)
power, _ := light.GetPower()
acc.Lightbulb.On.SetValue(power)
color, _ := light.GetColor()
hue, saturation, brightness := ConvertLIFXColor(color)
acc.Lightbulb.Brightness.SetValue(int(brightness))
acc.Lightbulb.Saturation.SetValue(saturation)
acc.Lightbulb.Hue.SetValue(hue)
config := hc.Config{Pin: pin}
transport, err := hc.NewIPTransport(config, acc.Accessory)
if err != nil {
log.Info.Panic(err)
}
go func() {
transport.Start()
}()
hkLight = &HKLight{acc, transport, nil}
lights[light.ID()] = hkLight
acc.OnIdentify(func() {
timeout := 1 * time.Second
for i := 0; i < 4; i++ {
ToggleLight(light)
time.Sleep(timeout)
}
})
acc.Lightbulb.On.OnValueRemoteUpdate(func(power bool) {
log.Debug.Printf("Changed State for %s", label)
light.SetPowerDuration(power, transitionDuration)
})
updateColor := func(light common.Light) {
currentPower, _ := light.GetPower()
// HAP: [0...360]
// LIFX: [0...MAX_UINT16]
hue := acc.Lightbulb.Hue.GetValue()
// HAP: [0...100]
// LIFX: [0...MAX_UINT16]
saturation := acc.Lightbulb.Saturation.GetValue()
// HAP: [0...100]
// LIFX: [0...MAX_UINT16]
brightness := acc.Lightbulb.Brightness.GetValue()
// [HSBKKelvinMin..HSBKKelvinMax]
kelvin := HSBKKelvinDefault
lifxHue := math.MaxUint16 * float64(hue) / float64(HueMax)
lifxSaturation := math.MaxUint16 * float64(saturation) / float64(SaturationMax)
lifxBrightness := math.MaxUint16 * float64(brightness) / float64(BrightnessMax)
color := common.Color{
uint16(lifxHue),
uint16(lifxSaturation),
uint16(lifxBrightness),
kelvin,
}
light.SetColor(color, transitionDuration)
if brightness > 0 && !currentPower {
log.Debug.Printf("Color changed for %s, turning on power.", label)
light.SetPowerDuration(true, transitionDuration)
} else if brightness == 0 && currentPower {
log.Debug.Printf("Color changed for %s, but brightness = 0 turning off power.", label)
light.SetPower(false)
}
}
acc.Lightbulb.Hue.OnValueRemoteUpdate(func(value float64) {
log.Debug.Printf("Changed Hue for %s to %f", label, value)
updateColor(light)
})
acc.Lightbulb.Saturation.OnValueRemoteUpdate(func(value float64) {
log.Debug.Printf("Changed Saturation for %s to %f", label, value)
//.........这里部分代码省略.........