# HG changeset patch # User Peter Meerwald # Date 1304782198 -7200 # Node ID 71b9540bdd23a9620233558fd29454c7ab241cfa starting, importing Woo's code and adding minimon diff -r 000000000000 -r 71b9540bdd23 README.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README.txt Sat May 07 17:29:58 2011 +0200 @@ -0,0 +1,2 @@ + +based on Grace Woo's work: http://web.media.mit.edu/~gracewoo/stuff/picframe/ diff -r 000000000000 -r 71b9540bdd23 controlmsg.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/controlmsg.c Sat May 07 17:29:58 2011 +0200 @@ -0,0 +1,73 @@ +/* $Id: usbreplay.c,v 1.7 2004/02/07 17:02:32 bd Exp $ */ +/* Use only with the Hauppauge WinTV PVR usb2, VID/PID 2040/2900. */ +/* No commercial affiliation, warranty, copyright, party invitation, */ +/* fitness or non-fitness, implied or otherwise, is claimed by this comment. */ +/* Compile with -lusb, then put it where capture.pl will find it. */ + +#include +#include +#include +#include +#include + +struct usb_device *find_first_pvr() { + struct usb_bus *bus; + struct usb_device *dev; + + usb_init(); + usb_find_busses(); + usb_find_devices(); + + for (bus = usb_busses; bus; bus = bus->next) { + for (dev = bus->devices; dev; dev = dev->next) { + if (dev->descriptor.idVendor == 0x04e8 && + dev->descriptor.idProduct == 0x2027) { + fprintf(stderr, "Samsung photoframe in Mass Storage mode found ...\n"); + return dev; + } + else if (dev->descriptor.idVendor == 0x04e8 && + dev->descriptor.idProduct == 0x2028){ + fprintf(stderr, "Samsung photoframe in Custom Product mode found ...\n"); + return NULL; + } + } + } + fprintf(stderr, "No Samsung device found ...\n"); + return NULL; +} + + +int replay() { + int res = -1; + char buf[256]; + usb_dev_handle *udev; + struct usb_device *dev = NULL; + int numeps = 0; + + dev = find_first_pvr(); + if (dev == NULL) { + fprintf(stderr, "Since no Samsung device in Mass Storage mode found, not going to do anything\n"); + return 0; + } + udev = usb_open(dev); + + setuid(getuid()); + + strcpy(buf, "** no string **"); + res = usb_get_string_simple(udev, dev->descriptor.iManufacturer, buf, sizeof(buf)); + fprintf(stderr, "usb_get_string_simple => %d, %s\n", res, buf); + + char blah[254]; + memset(blah,0,254); + + res = usb_control_msg(udev, USB_TYPE_STANDARD | USB_ENDPOINT_IN, USB_REQ_GET_DESCRIPTOR, 0xfe, 0xfe, blah, 0xfe, 1000); + printf("usb_control_msg() = %d\n",res); + + fprintf(stderr, "Just switched to 0x2028 Custom Product mode\n"); + return 0; +} + + +int main(int argc, char *argv[]) { + return replay(); +} diff -r 000000000000 -r 71b9540bdd23 minimon.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/minimon.c Sat May 07 17:29:58 2011 +0200 @@ -0,0 +1,124 @@ +#include +#include +#include +#include +#include +#include "usb.h" + +static const char *progname = "minimon"; + +struct usb_device *find_dev() { + struct usb_bus *bus; + struct usb_device *dev; + + usb_init(); + usb_find_busses(); + usb_find_devices(); + + for (bus = usb_busses; bus; bus = bus->next) { + for (dev = bus->devices; dev; dev = dev->next) { + if (dev->descriptor.idVendor == 0x04e8 && + dev->descriptor.idProduct == 0x2028) { + return dev; + } + } + } + + return NULL; +} + +usb_dev_handle *dev_open(struct usb_device *dev) { + int res = -1; + char buf[256]; + usb_dev_handle *udev; + int numeps = 0; + + udev = usb_open(dev); + if (!udev) { + fprintf(stderr, "%s: failed to open device, exit.\n", progname); + exit(EXIT_FAILURE); + } + + setuid(getuid()); + + res = usb_set_configuration(udev, 1); + + usb_claim_interface(udev, 0); + numeps = dev->config[0].interface[0].altsetting[0].bNumEndpoints; + if (numeps == 0) { + fprintf(stderr, "%s: no endpoints, exit.\n", progname); + exit(EXIT_FAILURE); + } + + strcpy(buf, "** no string **"); + res = usb_get_string_simple(udev, dev->descriptor.iManufacturer, buf, sizeof(buf)); + fprintf(stderr, "usb_get_string_simple => %d, %s\n", res, buf); + + { + int eplist[] = { 0x2, 0x81, 0x83 }; + int eplength = sizeof(eplist)/sizeof(eplist[0]); + int *endpoint = eplist; + int i; + for (i=0; i= 0); + off = 0; // no header on subsequent chunks + } +} + +int main(int argc, char *argv[]) { + if (argc != 2) { + fprintf(stderr, "Usage: %s FILE", progname); + return EXIT_FAILURE; + } + + struct usb_device *dev = find_dev(index); + assert(dev != NULL); + + usb_dev_handle *udev = dev_open(dev); + + FILE *f = fopen(argv[1], "rb"); + if (f == NULL) { + fprintf(stderr, "%s: failed to open file '%s', exit.\n", progname, argv[1]); + exit(EXIT_FAILURE); + } + send_jpeg(f, udev); + fclose(f); + + return EXIT_SUCCESS; +} diff -r 000000000000 -r 71b9540bdd23 playusb.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/playusb.c Sat May 07 17:29:58 2011 +0200 @@ -0,0 +1,144 @@ +/** + * based on usbreplay.c + * -- takes a list of jpeg filenames (on stdin) and sends them to the device index X + * + */ + +#include +#include +#include +#include +#include +#include + +struct usb_device *find_pvr(int index) { + struct usb_bus *bus; + struct usb_device *dev; + + usb_init(); + //usb_set_debug(999999); + usb_find_busses(); + usb_find_devices(); + + while(index >= 0) { + for (bus = usb_busses; bus; bus = bus->next) { + for (dev = bus->devices; dev; dev = dev->next) { + if (dev->descriptor.idVendor == 0x04e8 && + dev->descriptor.idProduct == 0x2028) { + if (index == 0) + return dev; + --index; + } + } + } + } + return NULL; +} + +usb_dev_handle *dev_open(struct usb_device *dev) { + int res = -1; + char buf[256]; + usb_dev_handle *udev; + int numeps = 0; + + udev = usb_open(dev); + + setuid(getuid()); + + res = usb_set_configuration(udev, 1); + + usb_claim_interface(udev, 0); + numeps = dev->config[0].interface[0].altsetting[0].bNumEndpoints; + if (numeps == 0) { + fprintf(stderr, "** Did you forget to initialize the FX2 firmware with usbreplay -i?\n"); + exit(1); + } + + strcpy(buf, "** no string **"); + res = usb_get_string_simple(udev, dev->descriptor.iManufacturer, buf, sizeof(buf)); + fprintf(stderr, "usb_get_string_simple => %d, %s\n", res, buf); + + { + int eplist[] = { 0x2, 0x81, 0x83 }; + int eplength = sizeof(eplist)/sizeof(eplist[0]); + int *endpoint = eplist; + int i; + for (i=0; i= 0); + off = 0; // no header on subsequent chunks + } +} + +int main(int argc, char *argv[]) { + int index = 0; + if (argc > 1) { + if (sscanf(argv[1], "%d", &index) != 1) { + fprintf(stderr, "Usage: %s [device index] < filelist", argv[0]); + return -1; + } + } + + struct usb_device *dev = find_pvr(index); + assert (dev != NULL); + + usb_dev_handle *udev = dev_open(dev); + + while(1) { + // for each file in the list + while(!feof(stdin)) { + char fn[256]; + fgets(fn, 256, stdin); + int nn = strlen(fn); + if (nn > 0) { + if (fn[nn-1] == '\n') + fn[nn-1] = 0; + FILE *f = fopen(fn, "r"); + if (f == NULL) { + fprintf(stderr, "file %s not found\n", fn); + return 2; + } + send_jpeg(f, udev); + fclose(f); + } + } + fseek(stdin, 0, SEEK_SET); + } + return 0; +}