annotate minimon.c @ 3:e8957085fe8a

working
author Peter Meerwald <pmeerw@pmeerw.net>
date Sun, 08 May 2011 23:08:45 +0200
parents bac8ed8d6eb9
children 078dc69945ad
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
1 #include <stdlib.h>
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
2 #include <stdio.h>
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
3 #include <string.h>
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
4 #include <fcntl.h>
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
5 #include <assert.h>
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
6 #include "usb.h"
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
7
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
8 static const char *progname = "minimon";
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
9
1
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
10 static int need_switch = 0;
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
11 static int have_idx = -1;
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
12
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
13 typedef struct {
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
14 int mass_id;
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
15 int custom_id;
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
16 const char *name;
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
17 int width;
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
18 int height;
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
19 } id_info_t;
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
20
2
bac8ed8d6eb9 add jpeg coding and test stuff
Peter Meerwald <pmeerw@pmeerw.net>
parents: 1
diff changeset
21 // there are many more,
1
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
22 static id_info_t ids[] = {
2
bac8ed8d6eb9 add jpeg coding and test stuff
Peter Meerwald <pmeerw@pmeerw.net>
parents: 1
diff changeset
23 {0x2027, 0x2028, "SPF-107H", 1024, 600},
1
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
24 {0xffff, 0xffff, "SPF-75H", 800, 480},
2
bac8ed8d6eb9 add jpeg coding and test stuff
Peter Meerwald <pmeerw@pmeerw.net>
parents: 1
diff changeset
25 {0xffff, 0xffff, "SPF-83H", 800, 600},
1
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
26 {0xffff, 0xffff, "SPF-85H", 800, 600}, // 85P??
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
27 {0x2033, 0x2034, "SPF-87H", 800, 480},
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
28 {0x2035, 0x2036, "SPF-107H", 1024, 600},
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
29 {0, 0, } // end-of-list
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
30 };
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
31
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
32 static int in_list(int id, id_info_t *list) {
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
33 if (!list)
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
34 return 0;
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
35
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
36 int idx = 0;
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
37 while (list->mass_id || list->custom_id) {
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
38 if (id == list->mass_id) {
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
39 // still in mass-storage mode, need to switch
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
40 need_switch = 1;
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
41 return idx;
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
42 }
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
43 else if (id == list->custom_id) {
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
44 need_switch = 0;
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
45 return idx;
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
46 }
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
47 idx++;
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
48 list++;
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
49 }
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
50
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
51 return -1;
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
52 }
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
53
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
54 static struct usb_device *find_dev() {
0
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
55 struct usb_bus *bus;
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
56 struct usb_device *dev;
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
57
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
58 usb_init();
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
59 usb_find_busses();
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
60 usb_find_devices();
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
61
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
62 for (bus = usb_busses; bus; bus = bus->next) {
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
63 for (dev = bus->devices; dev; dev = dev->next) {
1
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
64 if (dev->descriptor.idVendor == 0x04e8) {
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
65 // found a Samsung device, good
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
66 int idx = -1;
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
67 if ((idx = in_list(dev->descriptor.idProduct, ids)) >= 0) {
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
68 have_idx = idx;
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
69 return dev;
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
70 }
0
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
71 }
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
72 }
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
73 }
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
74
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
75 return NULL;
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
76 }
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
77
1
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
78 static usb_dev_handle *dev_open(struct usb_device *dev) {
0
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
79 int res = -1;
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
80 usb_dev_handle *udev;
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
81 int numeps = 0;
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
82
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
83 udev = usb_open(dev);
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
84 if (!udev) {
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
85 fprintf(stderr, "%s: failed to open device, exit.\n", progname);
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
86 exit(EXIT_FAILURE);
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
87 }
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
88
2
bac8ed8d6eb9 add jpeg coding and test stuff
Peter Meerwald <pmeerw@pmeerw.net>
parents: 1
diff changeset
89 // setuid(getuid());
0
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
90
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
91 res = usb_set_configuration(udev, 1);
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
92
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
93 usb_claim_interface(udev, 0);
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
94 numeps = dev->config[0].interface[0].altsetting[0].bNumEndpoints;
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
95 if (numeps == 0) {
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
96 fprintf(stderr, "%s: no endpoints, exit.\n", progname);
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
97 exit(EXIT_FAILURE);
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
98 }
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
99
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
100 {
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
101 int eplist[] = { 0x2, 0x81, 0x83 };
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
102 int eplength = sizeof(eplist)/sizeof(eplist[0]);
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
103 int *endpoint = eplist;
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
104 int i;
1
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
105 for (i = 0; i < eplength; i++) {
0
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
106 res = usb_resetep(udev, *endpoint);
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
107 res = usb_clear_halt(udev, *endpoint);
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
108 endpoint++;
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
109 }
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
110 }
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
111
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
112 return udev;
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
113 }
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
114
1
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
115 static void send_jpeg(FILE *f, usb_dev_handle *udev) {
0
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
116 fseek(f, 0, SEEK_END);
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
117 int sz = ftell(f);
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
118 fseek(f, 0, SEEK_SET);
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
119
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
120 #define URBBUF_MAX 0x20000
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
121 char buf[URBBUF_MAX];
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
122
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
123 #define HDR_LEN 12
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
124 char hdr[HDR_LEN] = {0xa5, 0x5a, 0x18, 0x04, 0xff, 0xff, 0xff, 0xff, 0x48, 0x00, 0x00, 0x00};
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
125 *(int *)(hdr+4) = sz;
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
126
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
127 memcpy(buf, hdr, HDR_LEN);
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
128 int off = HDR_LEN;
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
129
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
130 while(!feof(f)) {
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
131 int nr = fread(buf+off, 1, URBBUF_MAX - off, f);
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
132 if (nr < 0) break;
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
133 // pad
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
134 memset(buf + off + nr, 0, URBBUF_MAX - off - nr);
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
135
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
136 // write it out chunk by chunk
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
137 int timeout = 1000;
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
138 int endpoint = 0x2;
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
139 int res = usb_bulk_write(udev, endpoint, buf, URBBUF_MAX, timeout);
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
140
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
141 assert(res >= 0);
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
142 off = 0; // no header on subsequent chunks
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
143 }
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
144 }
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
145
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
146 int main(int argc, char *argv[]) {
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
147 if (argc != 2) {
1
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
148 fprintf(stderr, "Usage: %s <.jpg file>\n", progname);
0
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
149 return EXIT_FAILURE;
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
150 }
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
151
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
152 struct usb_device *dev = find_dev(index);
1
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
153 if (!dev) {
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
154 fprintf(stderr, "%s: no photo frame device found, exit.\n", progname);
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
155 exit(EXIT_FAILURE);
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
156 }
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
157
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
158 if (need_switch) {
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
159 fprintf(stderr, "%s: found %s, trying to switch to custom product mode...\n",
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
160 ids[have_idx].name, progname);
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
161
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
162 usb_dev_handle *udev;
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
163
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
164 udev = usb_open(dev);
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
165 if (!udev) {
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
166 fprintf(stderr, "%s: failed to open device, exit.\n", progname);
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
167 exit(EXIT_FAILURE);
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
168 }
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
169
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
170 char buf[254];
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
171 memset(buf, 0, 254);
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
172
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
173 int res = usb_control_msg(udev, USB_TYPE_STANDARD | USB_ENDPOINT_IN, USB_REQ_GET_DESCRIPTOR,
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
174 0xfe, 0xfe, buf, 0xfe, 1000);
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
175 fprintf(stderr, "%s: usb_control_msg() = %d\n", progname, res);
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
176
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
177 usb_close(udev);
2
bac8ed8d6eb9 add jpeg coding and test stuff
Peter Meerwald <pmeerw@pmeerw.net>
parents: 1
diff changeset
178 usleep(500000);
1
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
179 }
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
180
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
181 dev = find_dev(index);
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
182 if (!dev || need_switch) {
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
183 fprintf(stderr, "%s: no photo frame device found, exit.\n", progname);
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
184 exit(EXIT_FAILURE);
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
185 }
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
186
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
187 fprintf(stderr, "%s: found %s (%d x %d)\n",
111d4bbce605 improving
Peter Meerwald <pmeerw@pmeerw.net>
parents: 0
diff changeset
188 progname, ids[have_idx].name, ids[have_idx].width, ids[have_idx].height);
0
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
189
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
190 usb_dev_handle *udev = dev_open(dev);
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
191
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
192 FILE *f = fopen(argv[1], "rb");
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
193 if (f == NULL) {
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
194 fprintf(stderr, "%s: failed to open file '%s', exit.\n", progname, argv[1]);
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
195 exit(EXIT_FAILURE);
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
196 }
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
197 send_jpeg(f, udev);
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
198 fclose(f);
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
199
2
bac8ed8d6eb9 add jpeg coding and test stuff
Peter Meerwald <pmeerw@pmeerw.net>
parents: 1
diff changeset
200 while (1) {
bac8ed8d6eb9 add jpeg coding and test stuff
Peter Meerwald <pmeerw@pmeerw.net>
parents: 1
diff changeset
201 char buf[2];
bac8ed8d6eb9 add jpeg coding and test stuff
Peter Meerwald <pmeerw@pmeerw.net>
parents: 1
diff changeset
202 int res = usb_control_msg(udev, USB_TYPE_VENDOR | USB_ENDPOINT_IN, USB_REQ_GET_DESCRIPTOR,
bac8ed8d6eb9 add jpeg coding and test stuff
Peter Meerwald <pmeerw@pmeerw.net>
parents: 1
diff changeset
203 0x0, 0x0, buf, 0x2, 1000);
bac8ed8d6eb9 add jpeg coding and test stuff
Peter Meerwald <pmeerw@pmeerw.net>
parents: 1
diff changeset
204 fprintf(stderr, "%s: usb_control_msg() = %d\n", progname, res);
bac8ed8d6eb9 add jpeg coding and test stuff
Peter Meerwald <pmeerw@pmeerw.net>
parents: 1
diff changeset
205
bac8ed8d6eb9 add jpeg coding and test stuff
Peter Meerwald <pmeerw@pmeerw.net>
parents: 1
diff changeset
206 usleep(500000);
bac8ed8d6eb9 add jpeg coding and test stuff
Peter Meerwald <pmeerw@pmeerw.net>
parents: 1
diff changeset
207 }
bac8ed8d6eb9 add jpeg coding and test stuff
Peter Meerwald <pmeerw@pmeerw.net>
parents: 1
diff changeset
208
bac8ed8d6eb9 add jpeg coding and test stuff
Peter Meerwald <pmeerw@pmeerw.net>
parents: 1
diff changeset
209 usb_close(udev);
bac8ed8d6eb9 add jpeg coding and test stuff
Peter Meerwald <pmeerw@pmeerw.net>
parents: 1
diff changeset
210
0
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
211 return EXIT_SUCCESS;
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
212 }

Repositories maintained by Peter Meerwald, pmeerw@pmeerw.net.