Subversion Repositories Code-Repo

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
265 Kevin 1
'''Generates the byte array for setting the global brightness.'''
2
def CMD_Set_BC(brightness):
3
	barray = bytearray.fromhex('7E 00 02 0A')
4
	barray.extend([brightness])
5
	barray.extend([Calculate_Checksum(barray)])
6
	return barray
7
 
8
'''Generates the byte array for clearing all pixels.'''
9
def CMD_Clear():
10
	return bytearray.fromhex('7E 00 01 0B F4')
11
 
12
'''Generates the command for setting a specific pixel.'''
13
def CMD_Set_Pixel(layer, row, column, r, g, b):
14
	barray = bytearray.fromhex('7E 00 07 10')
15
	barray.extend([layer,row,column,r,g,b,])
16
	barray.extend([Calculate_Checksum(barray)])
17
	return barray
18
 
19
'''Generates the command for setting the entire cube.'''
20
def CMD_Set_All(leds):
21
	barray = bytearray.fromhex('7E 09 01 11')
22
	barray.extend(leds)
23
	barray.extend([Calculate_Checksum(barray)])
24
	return barray
25
 
26
'''Generates the command for setting the rotating overlay text.'''
27
def CMD_Start_Text(r, g, b, string):
28
	length = len(string) + 4
29
	barray = bytearray.fromhex('7E 00') 
30
	barray.extend([length, 0x20, r, g, b])
31
	barray.extend(string.encode())
32
	barray.extend([Calculate_Checksum(barray)])
33
	return barray
34
 
35
'''Generates the command for stopping the rotating overlay text.'''
36
def CMD_Stop_Text():
37
	return bytes.fromhex('7E 00 01 21 DE')
38
 
39
def Calculate_Checksum(barray):
40
	s = 0
41
	for entry in range(3,len(barray)):
42
		s += barray[entry]
43
	return 255 - (s & 0xFF)