Advertisement
maxkhl

colorInterface.py

Nov 4th, 2017
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.90 KB | None | 0 0
  1. import socket
  2. import time
  3.  
  4. global aSocket
  5. global IP
  6. global PORT
  7.  
  8. IP = "192.168.1.204"
  9. PORT = 8899
  10.  
  11. aSocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP
  12.  
  13. def sendOnCommand(zone=0):
  14.     codes = bytes([0x42, 0x45, 0x47, 0x49, 0x4B])
  15.     sendCommand(codes[zone], 0x00)
  16.     time.sleep(0.1)
  17.  
  18. def sendOffCommand(zone=0):
  19.     codes = bytes([0x41, 0x46, 0x48, 0x4A, 0x4C])
  20.     sendCommand(codes[zone], 0x00)
  21.  
  22. def sendWhiteCommand(zone=0):
  23.     sendOnCommand(zone)
  24.    
  25.     codes = bytes([0xC2, 0xC5, 0xC7, 0xC9, 0xCB])
  26.     sendCommand(codes[zone], 0x00)
  27.  
  28. def sendDiscoCommand(zone=0):
  29.     sendOnCommand(zone)
  30.    
  31.     sendCommand(0x4D, 0x00)
  32.  
  33. def sendDiscoDecCommand(zone=0):
  34.     sendOnCommand(zone)
  35.    
  36.     sendCommand(0x43, 0x00)
  37.  
  38. def sendDiscoIncCommand(zone=0):
  39.     sendOnCommand(zone)
  40.    
  41.     sendCommand(0x44, 0x00)
  42.  
  43. #brightness between 0 & 18
  44. def sendBrightnessCommand(zone, brightness):
  45.     sendOnCommand(zone)
  46.    
  47.     codes = bytes([0x02, 0x03, 0x04, 0x05, 0x08, 0x09, 0x0A, 0x0B, 0x0D, 0x0E, 0x0F, 0x10, 0x12, 0x13, 0x14, 0x15, 0x17, 0x18, 0x19])
  48.     sendCommand(0x4E, codes[brightness])
  49.  
  50. #brightness between 0 & 255
  51. #note there are more colours (0-255) in between, this color chart is just steps of 16.
  52. #    0x00 Violet
  53. #    0x10 Royal_Blue
  54. #    0x20 Baby_Blue
  55. #    0x30 Aqua
  56. #    0x40 Mint
  57. #    0x50 Seafoam_Green
  58. #    0x60 Green
  59. #    0x70 Lime_Green
  60. #    0x80 Yellow
  61. #    0x90 Yellow_Orange
  62. #    0xA0 Orange
  63. #    0xB0 Red
  64. #    0xC0 Pink
  65. #    0xD0 Fusia
  66. #    0xE0 Lilac
  67. #    0xF0 Lavendar
  68. def sendColorCommand(zone, color):
  69.     sendOnCommand(zone)
  70.    
  71.     sendCommand(0x40, color)
  72.  
  73. def sendCommand(code, param):
  74.     sendData(bytes([code, param, 0x55]))
  75.    
  76. def sendData(byArr):
  77.     aSocket.sendto(byArr, (IP, PORT))
  78.    
  79. #sendWhiteCommand(0)
  80. #sendBrightnessCommand(0,0)
  81. #time.sleep(3)
  82. #sendBrightnessCommand(0,18)
  83.  
  84. #col = 0
  85. #while True:
  86. #   sendColorCommand(0, col)
  87. #   col = col + 1
  88. #   time.sleep(0.1)
  89. #sendColorCommand(0, 255)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement