func main() { //Lookup all bulbs bulbs, _ := golifx.LookupBulbs() //Get label location, _ := bulbs[0].GetLabel() fmt.Printf("Label: %s\n", location) //Ven LiFX //Get power state powerState, _ := bulbs[0].GetPowerState() //Turn if off if !powerState { bulbs[0].SetPowerState(true) } ticker := time.NewTicker(time.Second) counter := 0 hsbk := &golifx.HSBK{ Hue: 2000, Saturation: 13106, Brightness: 65535, Kelvin: 3200, } //Change color every second for _ = range ticker.C { bulbs[0].SetColorState(hsbk, 500) counter++ hsbk.Hue += 5000 if counter > 10 { ticker.Stop() break } } //Turn off bulbs[0].SetPowerState(false) }
func main() { flag.Parse() if mac != "" { hwAddr, err := parseMac(mac) if err != nil { isSilent.error(err) } bulb := &golifx.Bulb{} bulb.SetHardwareAddress(hwAddr) if turnOn { if duration == 0 { bulb.SetPowerState(true) } else { bulb.SetPowerDurationState(true, uint32(duration)) } return } if turnOff { if duration == 0 { bulb.SetPowerState(false) } else { bulb.SetPowerDurationState(false, uint32(duration)) } return } if hue != -1 && (hue < 0 || hue > _MAX) { isSilent.error(errors.New("Incorrect hue")) } if saturation != -1 && (saturation < 0 || saturation > _MAX) { isSilent.error(errors.New("Incorrect saturation")) } if brightness != -1 && (brightness < 0 || brightness > _MAX) { isSilent.error(errors.New("Incorrect brightness")) } if kelvin != -1 && (kelvin < 2500 || kelvin > 9000) { isSilent.error(errors.New("Incorrect kelvin")) } if hue != -1 || saturation != -1 || brightness != -1 || kelvin != -1 { var err error var color *golifx.HSBK if hue != -1 && saturation != -1 && brightness != -1 && kelvin != -1 { color = &golifx.HSBK{ Hue: uint16(hue), Saturation: uint16(saturation), Brightness: uint16(brightness), Kelvin: uint16(kelvin), } } else { bulbState, err := bulb.GetColorState() color = bulbState.Color if err != nil { isSilent.error(err) } if hue != -1 { color.Hue = uint16(hue) } if saturation != -1 { color.Saturation = uint16(saturation) } if brightness != -1 { color.Brightness = uint16(brightness) } if kelvin != -1 { color.Kelvin = uint16(kelvin) } } bulbState, err := bulb.SetColorStateWithResponse(color, uint32(duration)) if err != nil { isSilent.error(err) } if !isSilent { if jsonFormat { b, _ := json.Marshal(bulbState) fmt.Println(string(b)) } else { fmt.Println(bulbState) } } } return } if lookupBulbs { bulbs, err := golifx.LookupBulbs() if err != nil { isSilent.error(err) } for _, bulb := range bulbs { if showLabel { _, err := bulb.GetLabel() if err != nil { isSilent.error(err) } } if showHostInfo { _, err := bulb.GetStateHostInfo() if err != nil { isSilent.error(err) } } if showHostFirmware { _, err := bulb.GetHostFirmware() if err != nil { isSilent.error(err) } } if showWifiInfo { _, err := bulb.GetWifiInfo() if err != nil { isSilent.error(err) } } if showWifiFirmware { _, err := bulb.GetWifiFirmware() if err != nil { isSilent.error(err) } } if showPowerState { _, err := bulb.GetPowerState() if err != nil { isSilent.error(err) } } if showBulbVersion { _, err := bulb.GetVersion() if err != nil { isSilent.error(err) } } if showInfo { _, err := bulb.GetInfo() if err != nil { isSilent.error(err) } } if showLocation { _, err := bulb.GetLocation() if err != nil { isSilent.error(err) } } if showGroup { _, err := bulb.GetGroup() if err != nil { isSilent.error(err) } } if showColor { _, err := bulb.GetColorState() if err != nil { isSilent.error(err) } } } if jsonFormat { b, _ := json.Marshal(bulbs) fmt.Println(string(b)) } else { for id, bulb := range bulbs { fmt.Print(bulb) if id < len(bulbs)-1 { fmt.Println("----------------") } } } return } }