From b6e727cef4bb5b6adb177aedf3e9f85b63923efe Mon Sep 17 00:00:00 2001 From: Micah Elizabeth Scott <micah@scanlime.org> Date: Tue, 23 Jul 2013 21:51:05 -0700 Subject: [PATCH] Update USB sample for 257-entry LUT, and test edge cases --- examples/usb-basic.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/examples/usb-basic.py b/examples/usb-basic.py index 21aa235..fe58bcf 100755 --- a/examples/usb-basic.py +++ b/examples/usb-basic.py @@ -33,14 +33,17 @@ for index in range(25): lut[index*64] = index | 0x40 lut[24*64] |= 0x20 for channel in range(3): - for row in range(256): - value = int(pow(row / 256.0, 2.2) * 0x10000) - i = (channel << 8) + row + for row in range(257): + value = min(0xFFFF, int(pow(row / 256.0, 2.2) * 0x10000)) + i = channel * 257 + row packetNum = i / 31 packetIndex = i % 31 + #print "%d, %d = 0x%04x" % (channel, row, value) lut[packetNum*64 + 2 + packetIndex*2] = value & 0xFF lut[packetNum*64 + 3 + packetIndex*2] = value >> 8 -dev.write(1, ''.join(map(chr, lut))) +lutPackets = ''.join(map(chr, lut)) +#print binascii.b2a_hex(lutPackets) +dev.write(1, lutPackets) print "LUT programmed" # Slowly push random frames to the device @@ -54,7 +57,7 @@ while True: else: control = index - data = chr(control) + ''.join(chr(random.randrange(256)) for i in range(63)) + data = chr(control) + ''.join(chr(random.choice([0, 255])) for i in range(63)) dev.write(1, data) #print binascii.b2a_hex(data) -- GitLab