示例#1
0
文件: pilight.go 项目: drewp/homeauto
func (b *Board) ReadLeds() (colors []color.Color, err error) {
	err = b.Write(0x3, make([]byte, 0))
	if err != nil {
		return
	}
	reader := textproto.NewReader(bufio.NewReader(b.ser))
	line, err := reader.ReadLineBytes()
	if err != nil {
		return
	}

	type LedsMessage struct {
		Leds []string
	}
	var ret LedsMessage
	err = json.Unmarshal(line, &ret)
	if err != nil {
		return
	}

	colors = make([]color.Color, len(ret.Leds))
	for i, c := range ret.Leds {
		r, g, b := hex.HexToRGB(hex.Hex(c))
		colors[i] = color.RGBA{r, g, b, 0}
	}

	return colors, nil
}
示例#2
0
文件: pilight.go 项目: drewp/homeauto
func getBodyStringColor(req *http.Request) (c color.Color, err error) {
	bytes := make([]byte, 1024)
	n, err := req.Body.Read(bytes)
	body := hex.Hex(string(bytes[:n]))
	if err != nil {
		return
	}
	r, g, b := hex.HexToRGB(body)
	return color.RGBA{r, g, b, 0}, nil
}