-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlights.py~
More file actions
35 lines (30 loc) · 1.69 KB
/
lights.py~
File metadata and controls
35 lines (30 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import time
from binascii import unhexlify
import serial
PORT = "/dev/ttyUSB0"
ser = serial.Serial(PORT)
lights = [["Dirty Lab", "26", "labs"], ["Clean Lab Cabinets", "3", "labs"], ["Clean Lab", "4", "labs"], ["South West Bedroom", "6", "living"], ["Downstairs Bedroom", "7", "living"], ["North West Bedroom", "9", "living"], ["North East Bedroom", "21", "living"], ["South East Bedroom", "28", "living"], ["West Balcony", "35", "outside"], ["Front Porch", "35", "outside"], ["Back Porch", "36", "outside"], ["Kitchen", "11", "community"], ["Front Indoor Lights", "12", "community"], ["White Board Lights", "31", "community"], ["Kitchen Cabinets", "38", "community"], ["Main Room", "11", "community"], ["Media Room", "20", "community"], ["Upper Floor", "0", "community"], ["East Upper Bathroom", "17", "bathrooms"], ["West Upper Bathroom", "15", "bathrooms"], ["West Lower Bathroom", "13", "bathrooms"]];
settings = dict()
settings["ON"] = ["182","\\05380079"]
settings["OFF"] = ["62","\\05380001"]
def change(status, whichLights):
if (status != "ON"):
status = "OFF"
for light in whichLights:
tempHex = light
if (len(str(light)) == 1):
tempHex = "0" + tempHex
chksum = bin((int(settings[status][0]) + int(light)) % 256 ).replace("0b","")
newsum = ""
for i in list(str(chksum)):
if i=="1":
newsum += "0"
else:
newsum += "1"
cSum = hex(1+int(newsum,2)).replace("0x","")
fullStr = (settings[status][1] + tempHex + cSum).upper()
finalStr = ""
for i in list(fullStr):
finalStr+=hex(ord(i[0])).replace("0x","")
finalStr+="0D"
ser.write(unhexlify(finalStr))