From: Martin Mares Date: Sat, 11 Apr 2020 13:53:17 +0000 (+0200) Subject: DMX: A simple test program X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=0dbfc94be9d0f4fd5b72ab3c6f15f9b18d4096e3;p=home-hw.git DMX: A simple test program --- diff --git a/dmx/test/Makefile b/dmx/test/Makefile new file mode 100644 index 0000000..a31dce1 --- /dev/null +++ b/dmx/test/Makefile @@ -0,0 +1,9 @@ +UCWCF:=$(shell PKG_CONFIG_PATH=$(LIBUCW)/lib/pkgconfig pkg-config --cflags libucw) +UCWLF:=$(shell PKG_CONFIG_PATH=$(LIBUCW)/lib/pkgconfig pkg-config --libs libucw) + +CFLAGS=-std=gnu99 -O2 -Wall -Wextra -Wno-parentheses $(UCWCF) +LDLIBS=-lusb-1.0 $(UCWLF) + +all: test + +test: test.c diff --git a/dmx/test/test.c b/dmx/test/test.c new file mode 100644 index 0000000..210b136 --- /dev/null +++ b/dmx/test/test.c @@ -0,0 +1,73 @@ +#include + +#include +#include +#include +#include +#include +#include + +#include "../firmware/interface.h" + +struct libusb_context *usb_ctxt; +struct libusb_device_handle *devh; + +static libusb_device *find_device(void) +{ + libusb_device **devlist; + ssize_t devn = libusb_get_device_list(usb_ctxt, &devlist); + if (devn < 0) + { + fprintf(stderr, "Cannot enumerate USB devices: error %d\n", (int) devn); + exit(1); + } + + for (ssize_t i=0; i "); + int x = atoi(argv[1]); + int y = atoi(argv[2]); + + int err; + if (err = libusb_init(&usb_ctxt)) + die("Cannot initialize libusb: error %d", err); + + libusb_device *dev = find_device(); + + if (err = libusb_open(dev, &devh)) + die("Cannot open device: error %d", err); + // libusb_reset_device(devh); + if (err = libusb_claim_interface(devh, 0)) + die("Cannot claim interface: error %d", err); + + byte packet[5] = { 0, x, y, 0, 0 }; + int len = sizeof(packet); + int transferred; + if (err = libusb_bulk_transfer(devh, 0x01, packet, len, &transferred, 1000)) + die("Transfer failed: error %d\n", err); + if (transferred != len) + die("Short transfer: %d out of %d bytes", transferred, len); + + return 0; +}