You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

150 lines
3.4 KiB

package nanoleaf
import "encoding/binary"
type EffectInfo struct {
EffectsList []string `json:"effectsList"`
Select string `json:"select"`
}
type PanelLayout struct {
GlobalOrientation GlobalOrientation `json:"globalOrientation"`
Data PanelLayoutData `json:"layout"`
}
type GlobalOrientation struct {
Value int `json:"value"`
Max int `json:"max"`
Min int `json:"min"`
}
type PanelLayoutData struct {
NumPanels int `json:"numPanels"`
SideLength int `json:"sideLength"`
PositionData []PositionData `json:"positionData"`
}
type PositionData struct {
PanelID uint16 `json:"panelId"`
X int `json:"x"`
Y int `json:"y"`
O int `json:"o"`
ShapeType int `json:"shapeType"`
}
type StateBool struct {
Value bool `json:"value"`
}
type StateInt struct {
Value int `json:"value"`
Max int `json:"max"`
Min int `json:"min"`
}
type State struct {
Brightness StateInt `json:"brightness"`
ColorMode string `json:"colorMode"`
Ct StateInt `json:"ct"`
Hue StateInt `json:"hue"`
On StateBool `json:"on"`
Sat StateInt `json:"sat"`
}
type Overview struct {
Name string `json:"name"`
SerialNumber string `json:"serialNo"`
Manufacturer string `json:"manufacturer"`
FirmwareVersion string `json:"firmwareVersion"`
HardwareVersion string `json:"hardwareVersion"`
Model string `json:"model"`
Effects EffectInfo `json:"effects"`
PanelLayout PanelLayout `json:"panelLayout"`
State State `json:"state"`
}
type DeviceInfo struct {
SerialNumber string `json:"serialNumber"`
HardwareVersion string `json:"hardwareVersion"`
FirmwareVersion string `json:"firmwareVersion"`
BootloaderVersion string `json:"bootloaderVersion"`
ModelNumber string `json:"modelNumber"`
}
type TokenResponse struct {
Token string `json:"auth_token"`
}
type PanelUpdate []byte
func (u *PanelUpdate) Add(message [8]byte) {
if len(*u) < 2 {
*u = make([]byte, 2, 10)
}
binary.BigEndian.PutUint16(*u, binary.BigEndian.Uint16(*u)+1)
*u = append(*u, message[:]...)
}
func (u *PanelUpdate) Len() int {
if len(*u) < 2 {
return 0
}
return int(binary.BigEndian.Uint16(*u))
}
type PanelEventMessage []byte
func (remote PanelEventMessage) Count() int {
return int(binary.BigEndian.Uint16(remote[0:]))
}
func (remote PanelEventMessage) ValidateLength() bool {
return len(remote) >= (2 + remote.Count()*5)
}
func (remote PanelEventMessage) PanelID(idx int) uint16 {
return binary.BigEndian.Uint16(remote[2+(idx*5):])
}
func (remote PanelEventMessage) TouchType(idx int) int {
value := int(remote[2+(idx*5)])
return (value & 0b11100000) >> 5
}
func (remote PanelEventMessage) TouchStrength(idx int) int {
value := int(remote[2+(idx*5)])
return (value & 0b00011110) >> 1
}
func (remote PanelEventMessage) SwipedFromPanelID(idx int) uint16 {
return binary.BigEndian.Uint16(remote[2+(idx*5)+3:])
}
var shapeTypeMap = map[int]string{
0: "Triangle",
1: "Rhythm",
2: "Square",
3: "Control Square Master",
4: "Control Square Passive",
7: "Hexagon (Shapes)",
8: "Triangle (Shapes)",
9: "Mini Triangle (Shapes)",
12: "Shapes Controller",
}
var shapeWidthMap = map[int]int{
0: 150,
1: -1,
2: 100,
3: 100,
4: 100,
7: 67,
8: 134,
9: 67,
12: -1,
}
var httpMessage = []byte(`{ "write": { "command": "display", "animType": "extControl", "extControlVersion": "v2" }}`)