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.

162 lines
3.6 KiB

  1. package nanoleaf
  2. import "encoding/binary"
  3. type EffectInfo struct {
  4. EffectsList []string `json:"effectsList"`
  5. Select string `json:"select"`
  6. }
  7. type PanelLayout struct {
  8. GlobalOrientation GlobalOrientation `json:"globalOrientation"`
  9. Data PanelLayoutData `json:"layout"`
  10. }
  11. type GlobalOrientation struct {
  12. Value int `json:"value"`
  13. Max int `json:"max"`
  14. Min int `json:"min"`
  15. }
  16. type PanelLayoutData struct {
  17. NumPanels int `json:"numPanels"`
  18. SideLength int `json:"sideLength"`
  19. PositionData []PositionData `json:"positionData"`
  20. }
  21. type PositionData struct {
  22. PanelID uint16 `json:"panelId"`
  23. X int `json:"x"`
  24. Y int `json:"y"`
  25. O int `json:"o"`
  26. ShapeType int `json:"shapeType"`
  27. }
  28. type StateBool struct {
  29. Value bool `json:"value"`
  30. }
  31. type StateInt struct {
  32. Value int `json:"value"`
  33. Max int `json:"max"`
  34. Min int `json:"min"`
  35. }
  36. type State struct {
  37. Brightness StateInt `json:"brightness"`
  38. ColorMode string `json:"colorMode"`
  39. Ct StateInt `json:"ct"`
  40. Hue StateInt `json:"hue"`
  41. On StateBool `json:"on"`
  42. Sat StateInt `json:"sat"`
  43. }
  44. type Overview struct {
  45. Name string `json:"name"`
  46. SerialNumber string `json:"serialNo"`
  47. Manufacturer string `json:"manufacturer"`
  48. FirmwareVersion string `json:"firmwareVersion"`
  49. HardwareVersion string `json:"hardwareVersion"`
  50. Model string `json:"model"`
  51. Effects EffectInfo `json:"effects"`
  52. PanelLayout PanelLayout `json:"panelLayout"`
  53. State State `json:"state"`
  54. }
  55. type DeviceInfo struct {
  56. SerialNumber string `json:"serialNumber"`
  57. HardwareVersion string `json:"hardwareVersion"`
  58. FirmwareVersion string `json:"firmwareVersion"`
  59. BootloaderVersion string `json:"bootloaderVersion"`
  60. ModelNumber string `json:"modelNumber"`
  61. }
  62. type TokenResponse struct {
  63. Token string `json:"auth_token"`
  64. }
  65. type PanelUpdate []byte
  66. func (u *PanelUpdate) Add(message [8]byte) {
  67. if len(*u) < 2 {
  68. *u = make([]byte, 2, 10)
  69. }
  70. binary.BigEndian.PutUint16(*u, binary.BigEndian.Uint16(*u)+1)
  71. *u = append(*u, message[:]...)
  72. }
  73. func (u *PanelUpdate) Len() int {
  74. if len(*u) < 2 {
  75. return 0
  76. }
  77. return int(binary.BigEndian.Uint16(*u))
  78. }
  79. type PanelEventMessage []byte
  80. func (remote PanelEventMessage) Count() int {
  81. return int(binary.BigEndian.Uint16(remote[0:]))
  82. }
  83. func (remote PanelEventMessage) ValidateLength() bool {
  84. return len(remote) >= (2 + remote.Count()*5)
  85. }
  86. func (remote PanelEventMessage) PanelID(idx int) uint16 {
  87. return binary.BigEndian.Uint16(remote[2+(idx*5):])
  88. }
  89. func (remote PanelEventMessage) TouchType(idx int) int {
  90. value := int(remote[2+(idx*5)])
  91. return (value & 0b11100000) >> 5
  92. }
  93. func (remote PanelEventMessage) TouchStrength(idx int) int {
  94. value := int(remote[2+(idx*5)])
  95. return (value & 0b00011110) >> 1
  96. }
  97. func (remote PanelEventMessage) SwipedFromPanelID(idx int) uint16 {
  98. return binary.BigEndian.Uint16(remote[2+(idx*5)+3:])
  99. }
  100. var shapeTypeMap = map[int]string{
  101. 0: "Triangle",
  102. 1: "Rhythm",
  103. 2: "Square",
  104. 3: "Control Square Master",
  105. 4: "Control Square Passive",
  106. 7: "Hexagon (Shapes)",
  107. 8: "Triangle (Shapes)",
  108. 9: "Mini Triangle (Shapes)",
  109. 12: "Shapes Controller",
  110. }
  111. var shapeIconMap = map[int]string{
  112. 0: "triangle",
  113. 1: "rhythm",
  114. 2: "Square",
  115. 3: "square",
  116. 4: "square",
  117. 7: "hexagon",
  118. 8: "triangle",
  119. 9: "triangle-small",
  120. 12: "hexagon",
  121. }
  122. var shapeWidthMap = map[int]int{
  123. 0: 150,
  124. 1: -1,
  125. 2: 100,
  126. 3: 100,
  127. 4: 100,
  128. 7: 67,
  129. 8: 134,
  130. 9: 67,
  131. 12: -1,
  132. }
  133. var httpMessage = []byte(`{ "write": { "command": "display", "animType": "extControl", "extControlVersion": "v2" }}`)