-
Notifications
You must be signed in to change notification settings - Fork 24
/
luxafor-win.py
157 lines (141 loc) · 3.98 KB
/
luxafor-win.py
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import argparse
import pywinusb.hid as hid
def main():
# Get Device, catch exception if not found
try:
device = hid.HidDeviceFilter(vendor_id = 0x04D8, product_id = 0xF372).get_devices()[0]
except:
print 'Device Error'
raise SystemExit
# Setup argument parser
parser = initArgParser()
args = parser.parse_args()
# Determine which action
if args.action == 'color':
setColor(device, args)
elif args.action == 'fade':
setFade(device, args)
elif args.action == 'strobe':
setStrobe(device, args)
elif args.action == 'wave':
setWave(device, args)
elif args.action == 'pattern':
setPattern(device, args)
def setPattern(device, args):
# Check for arguments & set values if needed
if not args.t:
args.t = 5
if not args.p or args.p > 8:
args.p = 1
# Open device
device.open()
# Retrieve Data
reports = device.find_output_reports()
# Set Data
values = [0,6,args.p,args.t,0,0,0,0,0]
reports[0].set_raw_data(values)
reports[0].send()
# Close Device
device.close()
def setWave(device, args):
# Check for arguments & set values if needed
if not args.r:
args.r = 0
if not args.g:
args.g = 0
if not args.b:
args.b = 0
if not args.w or args.w > 5:
args.w = 1
if not args.s:
args.s = 30
if not args.t:
args.t = 5
# Open Device
device.open()
# Retrieve Data
reports = device.find_output_reports()
# Set Data
values = [0,4,args.w,args.r,args.g,args.b,0,args.t,args.s]
reports[0].set_raw_data(values)
reports[0].send()
# Close Device
device.close()
def setStrobe(device, args):
# Check for arguments & set values if needed
if not args.r:
args.r = 0
if not args.g:
args.g = 0
if not args.b:
args.b = 0
if not args.l:
args.l = 255
if not args.s:
args.s = 30
if not args.t:
args.t = 5
# Open Device
device.open()
# Retrieve Data
reports = device.find_output_reports()
values = [0,3,args.l,args.r,args.g,args.b,args.s,0,args.t]
reports[0].set_raw_data(values)
reports[0].send()
# Close Device
device.close()
def setFade(device, args):
# Check for arguments & set values if needed
if not args.r:
args.r = 0
if not args.g:
args.g = 0
if not args.b:
args.b = 0
if not args.l:
args.l = 255
if not args.s:
args.s = 30
# Open Device
device.open()
# Retrieve Data
reports = device.find_output_reports()
values = [0,2,args.l,args.r,args.g,args.b,args.s,0,0]
reports[0].set_raw_data(values)
reports[0].send()
# Close Device
device.close()
def setColor(device, args):
# Check for arguments & set values if needed
if not args.r:
args.r = 0
if not args.g:
args.g = 0
if not args.b:
args.b = 0
if not args.l:
args.l = 255
# Open Device
device.open()
# Retrieve Data
reports = device.find_output_reports()
values = [0,1,args.l,args.r,args.g,args.b,0,0,0]
reports[0].set_raw_data(values)
reports[0].send()
# Close Device
device.close()
def initArgParser():
# Setup argument parser
parser = argparse.ArgumentParser(description='Luxafor Arguments')
parser.add_argument('action', help='Action', choices=["color", "fade", "wave", "strobe", "pattern"])
parser.add_argument('-l', help='LED', type=int)
parser.add_argument('-b', help='Blue Value', type=int)
parser.add_argument('-r', help='Red Value', type=int)
parser.add_argument('-g', help='Green Value', type=int)
parser.add_argument('-s', help='Speed Value', type=int)
parser.add_argument('-t', help='Repeat Value', type=int)
parser.add_argument('-w', help='Wave Value', type=int)
parser.add_argument('-p', help='Pattern Value', type=int)
return parser
if __name__ == '__main__':
main()