<commit_before># implements commands for BlinkM module
# <NAME>
# 2013

# todo: check data passed in is only byte-size (check for > 256?)

from smbus import SMBus

class led:
	def __init__(self, bus, address):
		self.bus = SMBus(bus)
		self.address = address

	def setrgb(self, r, g, b):
		self.bus.write_byte(self.address, ord('n'))
		sendthreebytes(self.bus, self.address, r, g, b)
	
	def fadergb(self, r, g, b):
		self.bus.write_byte(self.address, ord('c'))
		sendthreebytes(self.bus, self.address, r, g, b)

	def fadehsb(self, r, g, b):
		self.bus.write_byte(self.address, ord('h'))
		sendthreebytes(self.bus, self.address, r, g, b)

	def faderandomrgb(self, r, g, b):
		self.bus.write_byte(self.address, ord('C'))
		sendthreebytes(self.bus, self.address, r, g, b)

	def faderandomhsb(self, r, g, b):
		self.bus.write_byte(self.address, ord('H'))
		sendthreebytes(self.bus, self.address, r, g, b)

	def playscript(self, n, r, p):
		self.bus.write_byte(self.address, ord('p'))
		sendthreebytes(self.bus, self.address, n, r, p)

	def stopscript(self):
		self.bus.write_byte(self.address, ord('o'))

	def setfadespeed(self, f):
		self.bus.write_byte(self.address, ord('f'))
		self.bus.write_byte(self.address, f)

	def settimeadjust(self, t):
		self.bus.write_byte(self.address, ord('t'))
		self.bus.write_byte(self.address, t)

	#def getrgbcolour(self):
		# ???

#	def writescript(self, n, p, ...)
#	def readscript(self, n, p	)

	def scriptlengthrepeats(self, n, l, r):
		self.bus.write_byte(self.address, ord('L'))
		sendthreebytes(self.bus, self.address, n, l, r)

#	def setaddress(self, a, ...)
#	def getaddress(self)

	def getfirmware(self):
		#self.bus.write_byte(self.address, ord('Z'))
		fw = bytearray()
		fw = self.bus.read_block_data(self.address, ord('Z'))
		print fw
	#	print chr(self.bus.read_byte(self.address))
	#	print chr(self.bus.read_byte(self.address))
		
	def startupparams(self, m, n, r, f, t):
		self.bus.write_byte(self.address, ord('B'))
		sendthreebytes(self.bus, self.address, m, n, r)
		self.bus.write_byte(self.address, f)
		self.bus.write_byte(self.address, t)
		
def sendthreebytes(bus, address, one, two, three):
	bus.write_byte(address, one)
	bus.write_byte(address, two)
	bus.write_byte(address, three)
<commit_msg>Updated sendbyte to send unlimited number of bytes.<commit_after># implements commands for BlinkM module
# <NAME>
# 2013

# todo: check data passed in is only byte-size (check for > 256?)


class led:
	def __init__(self, bus = 1, addr = 0x09):
		from smbus import SMBus
		self.bus = SMBus(bus)
		self.addr = addr

	def setrgb(self, r, g, b):
		sendbytes(self.bus, self.addr, ord('n'), r, g, b)
	
	def fadergb(self, r, g, b):
		sendbytes(self.bus, self.addr, ord('c'), r, g, b)

	def fadehsb(self, r, g, b):
		sendbytes(self.bus, self.addr, ord('h'), r, g, b)

	def faderandomrgb(self, r, g, b):
		sendbytes(self.bus, self.addr, ord('C'), r, g, b)

	def faderandomhsb(self, r, g, b):
		sendbytes(self.bus, self.addr, ord('H'), r, g, b)

	def playscript(self, n, r, p):
		sendbytes(self.bus, self.addr, ord('p'), n, r, p)

	def stopscript(self):
		sendbytes(self.bus, self.addr, ord('o'))

	def setfadespeed(self, f):
		sendbytes(self.bus, self.addr, ord('f'), f)

	def settimeadjust(self, t):
		sendbytes(self.bus, self.addr, ord('t'), t)

	#def getrgbcolour(self):
		# ???

#	def writescript(self, n, p, ...)
#	def readscript(self, n, p	)

	def scriptlengthrepeats(self, n, l, r):
		sendbytes(self.bus, self.addr, ord('L'), n, l, r)

#	def setaddr(self, a, ...)
#	def getaddr(self)

	def getfirmware(self):
		sendbytes(self.bus, self.addr, ord('Z'))
		print readbytes(self.bus, self.addr, 2)
	#	print chr(self.bus.read_byte(self.address)) 
	#	print chr(self.bus.read_byte(self.address)) 
		
	def startupparams(self, m, n, r, f, t):
		sendbytes(self.bus, self.addr, ord('B'), m, n, r, f, t)
	
def sendbytes(bus, addr, *bytes):
	for byte in bytes:
		bus.write_byte(addr, byte)
	
def readbytes(bus, addr, nb_bytes):
	for i in range(nb_bytes):
		yield bus.read_byte(addr, byte)
{'fraction_non_alphanumeric': 0.17445328031809146, 'fraction_numerical': 0.004721669980119284, 'mean_word_length': 4.366666666666666, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6654562', 'n_tokens_mistral': 1729, 'n_tokens_neox': 1615, 'n_words': 397}