From d0abeba4132c15783e3981591e75dbcf4e20186b Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Sun, 20 Feb 2022 16:50:07 +0100 Subject: [PATCH] Rainbow: Bug fixes --- rainbow/daemon/burrow-rainbowd.c | 4 ++-- rainbow/firmware/main.c | 15 +++++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/rainbow/daemon/burrow-rainbowd.c b/rainbow/daemon/burrow-rainbowd.c index 99d575f..6ec4546 100644 --- a/rainbow/daemon/burrow-rainbowd.c +++ b/rainbow/daemon/burrow-rainbowd.c @@ -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 ***/ diff --git a/rainbow/firmware/main.c b/rainbow/firmware/main.c index 5dee456..dbae813 100644 --- a/rainbow/firmware/main.c +++ b/rainbow/firmware/main.c @@ -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; } -- 2.39.2