confirm prefs update, fix bg_pixmap sz, plugin layout tweaks
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / shudmp.C
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <fcntl.h>
5 #include <error.h>
6 #include <signal.h>
7
8 #include <libusb-1.0/libusb.h>
9
10 #define SHUTTLE_INTERFACE 0
11
12 libusb_device_handle *devsh = 0;
13 int claimed = -1;
14
15 void usb_done()
16 {
17         if( devsh ) {
18                 if( claimed > 0 ) {
19                         int sh_iface = SHUTTLE_INTERFACE;
20                         libusb_release_interface(devsh, sh_iface);
21                         libusb_attach_kernel_driver(devsh, sh_iface);
22                         claimed = 0;
23                 }
24                 libusb_close(devsh);
25                 devsh = 0;
26         }
27         if( claimed >= 0 ) {
28                 libusb_exit(0);
29                 claimed = -1;
30         }
31 }
32
33 void usb_probe()
34 {
35         int ret = libusb_init(0);
36         if( ret < 0 ) return;
37         claimed = 0;
38         devsh = libusb_open_device_with_vid_pid(0, 0x0b33, 0x0030);
39         if( devsh ) {
40                 int sh_iface = SHUTTLE_INTERFACE;
41                 libusb_detach_kernel_driver(devsh, sh_iface);
42                 ret = libusb_claim_interface(devsh, sh_iface);
43                 if( ret >= 0 ) claimed = 1;
44         }
45         if( !claimed )
46                 usb_done();
47 }
48
49 int done = 0;
50 void sigint(int n) { done = 1; }
51
52 int main(int ac, char **av)
53 {
54         setbuf(stdout, 0);
55         usb_probe();
56         if( claimed > 0 ) {
57                 signal(SIGINT, sigint);
58                 while( !done ) {
59                         int len = 0;
60                         static const int IN_ENDPOINT = 0x81;
61                         unsigned char dat[5];
62                         int ret = libusb_interrupt_transfer(devsh,
63                                         IN_ENDPOINT, dat, sizeof(dat), &len, 100);
64                         if( ret != 0 ) {
65                                 if( ret == LIBUSB_ERROR_TIMEOUT ) continue;
66                                 printf("error: %s\n", libusb_strerror((libusb_error)ret));
67                                 sleep(1);  continue;
68                         }
69                         printf("shuttle: ");
70                         for( int i=0; i<len; ++i ) printf(" %02x", dat[i]);
71                         printf("\n");
72                 }
73         }
74         usb_done();
75         return 0;
76 }
77