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;
}
*pkt++ = leds[i].b;
}
- return sizeof(npix_packet);
+ return pkt - npix_packet;
}
/*** Main ***/
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();
static const char *usb_strings[] = {
"United Computer Wizards",
- "Neopixel Indicators",
+ "Neopixel Rainbow",
usb_serial_number,
};
.bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = 0x01,
.bmAttributes = USB_ENDPOINT_ATTR_BULK,
- .wMaxPacketSize = sizeof(led_rgb),
+ .wMaxPacketSize = 64,
.bInterval = 1,
}};
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;
}
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;
}