]> mj.ucw.cz Git - home-hw.git/commitdiff
Rainbow: Bug fixes
authorMartin Mares <mj@ucw.cz>
Sun, 20 Feb 2022 15:50:07 +0000 (16:50 +0100)
committerMartin Mares <mj@ucw.cz>
Sun, 20 Feb 2022 15:50:07 +0000 (16:50 +0100)
rainbow/daemon/burrow-rainbowd.c
rainbow/firmware/main.c

index 99d575f65f5be708958fec8ba6f60befb7974e90..6ec45464ce195b0df91bdfc6569cd9e26fe49688 100644 (file)
@@ -97,7 +97,7 @@ static void mqtt_msg_callback(struct mosquitto *mosq UNUSED, void *obj UNUSED, c
                return;
 
        uint index;
-       if (str_to_uint(&index, m->topic + strlen(px), NULL, STN_DEC | STN_WHOLE) || index >= NPIX_NUM_LEDS) {
+       if (str_to_uint(&index, m->topic + strlen(px), NULL, 10 | STN_WHOLE) || index >= NPIX_NUM_LEDS) {
                msg(L_ERROR, "Unsupported topic: %s", m->topic);
                return;
        }
@@ -217,7 +217,7 @@ static int npix_build_packet(void)
                *pkt++ = leds[i].b;
        }
 
-       return sizeof(npix_packet);
+       return pkt - npix_packet;
 }
 
 /*** Main ***/
index 5dee4564b8244db0917182c687248b5626ff273b..dbae8134d271b07465e5de6685ac910750131c77 100644 (file)
@@ -168,7 +168,7 @@ static void neopixel_init(void)
        timer_set_dma_on_update_event(TIM4);
        TIM_DIER(TIM4) |= TIM_DIER_UDE;
 
-       led_rgb[0][1] = 0xaa;
+       led_rgb[NPIX_NUM_LEDS-1][1] = 0xaa;
 
        timer_enable_counter(TIM4);
        neopixel_recalc();
@@ -201,7 +201,7 @@ static char usb_serial_number[13];
 
 static const char *usb_strings[] = {
        "United Computer Wizards",
-       "Neopixel Indicators",
+       "Neopixel Rainbow",
        usb_serial_number,
 };
 
@@ -228,7 +228,7 @@ static const struct usb_endpoint_descriptor endpoints[] = {{
        .bDescriptorType = USB_DT_ENDPOINT,
        .bEndpointAddress = 0x01,
        .bmAttributes = USB_ENDPOINT_ATTR_BULK,
-       .wMaxPacketSize = sizeof(led_rgb),
+       .wMaxPacketSize = 64,
        .bInterval = 1,
 }};
 
@@ -313,11 +313,14 @@ static enum usbd_request_return_codes dfu_control_cb(usbd_device *dev UNUSED,
        return USBD_REQ_HANDLED;
 }
 
+static byte usb_rx_buf[3*NPIX_NUM_LEDS];
+
 static void ep01_cb(usbd_device *dev, uint8_t ep UNUSED)
 {
        // We received a frame from the USB host
-       uint len = usbd_ep_read_packet(dev, 0x01, led_rgb, sizeof(led_rgb));
+       uint len = usbd_ep_read_packet(dev, 0x01, usb_rx_buf, sizeof(usb_rx_buf));
        debug_printf("USB: Host sent %u bytes\n", len);
+       memcpy(led_rgb, usb_rx_buf, len);
        neopixel_want_send = 1;
 }
 
@@ -392,10 +395,10 @@ int main(void)
        u32 last_send = 0;
 
        for (;;) {
-               if (ms_ticks - last_blink >= 100) {
+               if (ms_ticks - last_blink >= 300) {
                        debug_led_toggle();
                        last_blink = ms_ticks;
-                       led_rgb[NPIX_NUM_LEDS - 1][1] ^= 0x33;
+                       // led_rgb[NPIX_NUM_LEDS - 1][1] ^= 0x33;
                        neopixel_want_send = 1;
                }