Beispiel #1
0
    def blink(self, color: RGB, blinks: int = 1, delay_ms: int = 500) -> None:
        blinks = RangeInt(blinks, 1, self.MAX_BLINKS, "blinks")
        delay_ms = RangeInt(delay_ms, 1, self.MAX_DELAY, "delay_ms")

        pattern = Pattern()
        for x in range(blinks):
            if x:
                pattern.addColorAndDuration(OFF, delay_ms)
            pattern.addColorAndDuration(color, delay_ms)
        pattern.addColorAndDuration(OFF, 0)

        from core.FadeStickUSB import sendControlTransfer, R_USB_SEND, R_SET_CONFIG
        sendControlTransfer(self, R_USB_SEND, R_SET_CONFIG, FS_MODE_PATTERN,
                            pattern.getBytePattern())
Beispiel #2
0
 def test_get_int_pattern2(self):
     p = Pattern()
     p.addColorAndDuration(self.red, 100)
     p.addColorAndDuration(self.green, 100)
     self.assertEqual([2,
                       255, 0, 0, 10,
                       0, 255, 0, 10], p.getIntPattern()[:9])
Beispiel #3
0
    def test_get_pattern_immutable(self):
        p1 = Pattern()
        p1.addColorAndDuration(self.red, 1)

        p2 = Pattern()
        self.assertEqual([], p2.getPattern())
        self.assertEqual([(self.red, 1)], list(map(lambda cd: (cd.color, cd.duration), p1.getPattern())))
Beispiel #4
0
    def morph(self,
              end_color: RGB,
              duration: int = 1000,
              steps: int = MAX_STEPS) -> None:
        duration = RangeInt(duration, 1, self.MAX_DURATION, "duration")
        steps = RangeInt(steps, 1, self.MAX_STEPS, "steps")

        r_end, g_end, b_end = end_color
        start_color = self.getColor()
        r_start, g_start, b_start = start_color
        pattern: Pattern = Pattern()
        ms_delay = floor(float(duration) / float(steps))

        for n in range(0, steps):  # Range is exclusive
            d = 1.0 * (n + 1) / float(steps)
            r = (r_start * (1 - d)) + (r_end * d)
            g = (g_start * (1 - d)) + (g_end * d)
            b = (b_start * (1 - d)) + (b_end * d)
            pattern.addColorAndDuration(RGB(int(r), int(g), int(b)), ms_delay)

        from core.FadeStickUSB import sendControlTransfer, R_USB_SEND, R_SET_CONFIG
        sendControlTransfer(self, R_USB_SEND, R_SET_CONFIG, FS_MODE_PATTERN,
                            pattern.getBytePattern())
Beispiel #5
0
 def test_get_int_pattern_duration(self):
     p = Pattern()
     p.addColorAndDuration(self.red, 9)
     self.assertEqual([1, 255, 0, 0, 1], p.getIntPattern()[:5])
Beispiel #6
0
 def test_get_int_pattern_empty(self):
     p = Pattern()
     self.assertEqual([0] * Pattern.PATTERN_BUFFER_BYTE_LENGTH, p.getIntPattern())
Beispiel #7
0
 def test_get_pattern_many(self):
     pattern = Pattern()
     pattern.addColorAndDuration(self.red, 1)
     p = pattern.getPattern()
     self.assertEqual([(self.red, 1)], list(map(lambda cd: (cd.color, cd.duration), p)))
Beispiel #8
0
 def test_get_pattern_empty(self):
     pattern = Pattern()
     self.assertEqual([], pattern.getPattern())
Beispiel #9
0
 def test_add_color_and_durations_over_max(self):
     pattern = Pattern()
     for i in range(0, Pattern.MAX_BUFFER_SIZE+1):
         pattern.addColorAndDuration(self.red, 100)
     self.assertEqual(Pattern.MAX_BUFFER_SIZE, len(pattern))
Beispiel #10
0
 def test_add_color_and_durations(self):
     pattern = Pattern()
     pattern.addColorAndDuration(self.red, 100)
     pattern.addColorAndDuration(self.green, 200)
     self.assertEqual([(self.red, 100), (self.green, 200)],
                      list(map(lambda cd: (cd.color, cd.duration), pattern.getPattern())))
Beispiel #11
0
 def test_add_color_and_duration(self):
     pattern = Pattern()
     pattern.addColorAndDuration(self.red, 100)
     self.assertEqual((self.red, 100), (pattern.getPattern()[0].color, pattern.getPattern()[0].duration))
Beispiel #12
0
    def test_immutable(self):
        pattern = Pattern()
        pattern.addColorAndDuration(self.red, 100)

        pattern = Pattern()
        self.assertEqual(0, len(pattern))