#!/usr/bin/env python

import rospy
from fadecandy_msgs.msg import LEDArray, LEDStrip
from std_msgs.msg import ColorRGBA


def main():
    rospy.init_node('fadecandy_client', anonymous=True)

    led_array_pub = rospy.Publisher('set_leds', LEDArray, queue_size=1)

    colors = [ColorRGBA(r=1, g=1, b=1), ColorRGBA(r=1), ColorRGBA(g=1), ColorRGBA(b=1)]

    num_led_strips = 8
    bar_start = 0
    bar_length = 3
    num_leds = 21
    color_i = 0
    while not rospy.is_shutdown():
        led_array = LEDArray()

        for led_strip in range(num_led_strips):
            led_strip = LEDStrip()
            led_strip.colors = [ColorRGBA()] * num_leds
            for bar_offset in range(bar_length):
                led_strip.colors[(bar_start + bar_offset) % num_leds] = colors[color_i]
            led_array.strips.append(led_strip)

        led_array_pub.publish(led_array)

        bar_start = (bar_start + 1) % num_leds
        if bar_start == 0:
            color_i = (color_i + 1) % len(colors)
        rospy.sleep(0.1)


if __name__ == '__main__':
    main()
