예제 #1
0
파일: hklifxd.go 프로젝트: EmuxEvans/hklifx
func toggleBulb(bulb *lifx.Bulb) {
	if bulb.GetPower() == 0 {
		client.LightOn(bulb)
	} else {
		client.LightOff(bulb)
	}
}
예제 #2
0
파일: hklifxd.go 프로젝트: EmuxEvans/hklifx
func updateBulb(bulb *lifx.Bulb) {
	on := true
	if bulb.GetPower() == 0 {
		on = false
	}

	state := bulb.GetState()

	name := bulb.GetLabel()
	if light, found := lights[name]; found == true && state.Visible == false {
		log.Printf("Remove light", light)
		removeLight(light, name)
		return
	}

	light_bulb := lightForBulb(bulb).bulb

	light_bulb.SetOn(on)

	brightness := float64(state.Brightness) / float64(math.MaxUint16) * 100
	saturation := float64(state.Saturation) / float64(math.MaxUint16) * 100
	hue := float64(state.Hue) / float64(math.MaxUint16) * 360

	light_bulb.SetBrightness(int(brightness))
	light_bulb.SetSaturation(saturation)
	light_bulb.SetHue(hue)

	log.Println("LIFX is now", on)
	log.Println("Brightness", brightness)
	log.Println("Saturation", saturation)
	log.Println("Hue", hue)
}