Пример #1
0
 def doTestRotateInset(self, mem):
     # A WSlice that starts past the beginning of the underlying WS2812 can be rotated
     ws = WS2812(spi_bus=1, led_count=7, mem=mem)
     for i in range(len(ws)):
         ws[i] = b'foo'
     self.assertTrue(all(bytes(ws[i]) == b'foo' for i in range(len(ws))))
     leds = WSlice(ws, 2, 5)
     n = len(leds)
     for i, t in zip(range(n), tg(n,0)):
         leds[i] = t
     self.assertEqual([tuple(led) for led in leds], [(0,1,2), (3,4,5), (6,7,8)])
     self.assertTrue(all(bytes(ws[i]) == b'foo' for i in range(len(ws)) if i not in range(2,5)))
     leds.cw()
     self.assertEqual([tuple(led) for led in leds], [(3,4,5), (6,7,8), (0,1,2)])
     self.assertTrue(all(bytes(ws[i]) == b'foo' for i in range(len(ws)) if i not in range(2,5)))
     leds.cw()
     self.assertEqual([tuple(led) for led in leds], [(6,7,8), (0,1,2), (3,4,5)])
     self.assertTrue(all(bytes(ws[i]) == b'foo' for i in range(len(ws)) if i not in range(2,5)))
     leds.cw()
     self.assertEqual([tuple(led) for led in leds], [(0,1,2), (3,4,5), (6,7,8)])
     self.assertTrue(all(bytes(ws[i]) == b'foo' for i in range(len(ws)) if i not in range(2,5)))
     leds.ccw()
     self.assertEqual([tuple(led) for led in leds], [(6,7,8), (0,1,2), (3,4,5)])
     self.assertTrue(all(bytes(ws[i]) == b'foo' for i in range(len(ws)) if i not in range(2,5)))
     leds.ccw()
     self.assertEqual([tuple(led) for led in leds], [(3,4,5), (6,7,8), (0,1,2)])
     self.assertTrue(all(bytes(ws[i]) == b'foo' for i in range(len(ws)) if i not in range(2,5)))
     leds.ccw()
     self.assertEqual([tuple(led) for led in leds], [(0,1,2), (3,4,5), (6,7,8)])
     self.assertTrue(all(bytes(ws[i]) == b'foo' for i in range(len(ws)) if i not in range(2,5)))
     ws = WS2812(spi_bus=1, led_count=90, mem=mem)
     for n in (1, 2, 7, 16, 33, 70):#, 190, 244, 400):
         leds = ref = None
         gc.collect()
         leds_start = n//7
         leds_end = n + n//7
         leds = WSlice(ws, leds_start, leds_end)
         self.assertEqual(len(leds), n)
         for i, t in enumerate(tg(n,0)):
             leds[i] = t
         ref = list(tuple(leds[i]) for i in range(n))
         #print("\n\nstart %d, end %d" % (leds_start, leds_end))
         #print("ref", ref)
         #print("leds", leds[:])
         for k in range(n):
             #print("\nk", k, "leds", leds[:])
             #print("leds before cw:", [tuple(leds[i]) for i in range(n)])
             leds.cw()
             #print(" leds after cw:", [tuple(leds[i]) for i in range(n)])
             #print("ref:", [ref[(k+1+i)%n] for i in range(n)])
             self.assertTrue(all(tuple(leds[i]) == ref[(k+1+i)%n] for i in range(n)))
         for k in range(n):
             leds.ccw()
             self.assertTrue(all(tuple(leds[i]) == ref[(-(k+1)+i)%n] for i in range(n)))
Пример #2
0
 def doTestRotatePart(self, mem):
     # Some part of a WSlice that starts past the beginning of the
     # underlying WS2812 can be rotated
     ws = WS2812(spi_bus=1, led_count=8, mem=mem)
     for i in range(len(ws)):
         ws[i] = b'foo'
     self.assertTrue(all(bytes(ws[i]) == b'foo' for i in range(len(ws))))
     leds = WSlice(ws, 2, 6)
     n = len(leds)
     for i, t in zip(range(n), tg(n,0)):
         leds[i] = t
     self.assertTrue(all(bytes(ws[i]) == b'foo' for i in range(len(ws)) if i not in range(2,6)))
     self.assertEqual([tuple(led) for led in leds], [(0,1,2), (3,4,5), (6,7,8), (9,10,11)])
     leds.cw(1)
     self.assertTrue(all(bytes(ws[i]) == b'foo' for i in range(len(ws)) if i not in range(2,6)))
     self.assertEqual([tuple(led) for led in leds], [(0,1,2), (6,7,8), (9,10,11), (3,4,5)])
     leds.cw(1)
     self.assertTrue(all(bytes(ws[i]) == b'foo' for i in range(len(ws)) if i not in range(2,6)))
     self.assertEqual([tuple(led) for led in leds], [(0,1,2), (9,10,11), (3,4,5), (6,7,8)])
     leds.cw(1)
     self.assertTrue(all(bytes(ws[i]) == b'foo' for i in range(len(ws)) if i not in range(2,6)))
     self.assertEqual([tuple(led) for led in leds], [(0,1,2), (3,4,5), (6,7,8), (9,10,11)])
     leds.ccw(1)
     self.assertTrue(all(bytes(ws[i]) == b'foo' for i in range(len(ws)) if i not in range(2,6)))
     self.assertEqual([tuple(led) for led in leds], [(0,1,2), (9,10,11), (3,4,5), (6,7,8)])
     leds.ccw(1)
     self.assertTrue(all(bytes(ws[i]) == b'foo' for i in range(len(ws)) if i not in range(2,6)))
     self.assertEqual([tuple(led) for led in leds], [(0,1,2), (6,7,8), (9,10,11), (3,4,5)])
     leds.ccw(1)
     self.assertTrue(all(bytes(ws[i]) == b'foo' for i in range(len(ws)) if i not in range(2,6)))
     self.assertEqual([tuple(led) for led in leds], [(0,1,2), (3,4,5), (6,7,8), (9,10,11)])
Пример #3
0
 def doTestRotate(self, mem):
     # A whole WSlice can be rotated
     ws = WS2812(spi_bus=1, led_count=75, mem=mem)
     for n in (1, 2, 7, 16, 33, 70):#, 190, 244, 400):
         leds = None
         t = None
         gc.collect()
         leds = WSlice(ws, 0, n)
         ws.fill_buf(tg(n, 0))
         ref = list(tuple(t) for t in tg(n, 0))
         self.assertTrue(all(tuple(leds[i]) == ref[i] for i in range(len(leds))))
         for k in range(n):
             leds.cw()
             self.assertTrue(all(tuple(leds[i]) == ref[(k+1+i)%n] for i in range(n)))
         for k in range(n):
             leds.ccw()
             self.assertTrue(all(tuple(leds[i]) == ref[(-(k+1)+i)%n] for i in range(n)))