1 /*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <stdint.h>
20 #include <string.h>
21
22 #include "accessory.h"
23
usage(char * name)24 static void usage(char* name) {
25 fprintf(stderr, "Usage: %s [-a] [-h] [-ic input card] [-id input device] "
26 "[-oc output card] [-d output device] [-a] [-h] [-i]\n\n"
27 "\t-ic, -id, -oc and -od specify ALSA card and device numbers\n"
28 "\t-a : enables AccessoryChat mode\n"
29 "\t-i : enables HID pass through (requires running as root\n"
30 "\t-h : prints this usage message\n", name);
31 }
32
main(int argc,char * argv[])33 int main(int argc, char* argv[])
34 {
35 unsigned int input_card = 2;
36 unsigned int input_device = 0;
37 unsigned int output_card = 0;
38 unsigned int output_device = 0;
39 unsigned int enable_accessory = 0;
40 unsigned int enable_hid = 0;
41
42 /* parse command line arguments */
43 argv += 1;
44 while (*argv) {
45 if (strcmp(*argv, "-ic") == 0) {
46 argv++;
47 if (*argv)
48 input_card = atoi(*argv);
49 } else if (strcmp(*argv, "-id") == 0) {
50 argv++;
51 if (*argv)
52 input_device = atoi(*argv);
53 } else if (strcmp(*argv, "-oc") == 0) {
54 argv++;
55 if (*argv)
56 output_card = atoi(*argv);
57 } else if (strcmp(*argv, "-od") == 0) {
58 argv++;
59 if (*argv)
60 output_device = atoi(*argv);
61 } else if (strcmp(*argv, "-a") == 0) {
62 enable_accessory = 1;
63 } else if (strcmp(*argv, "-h") == 0) {
64 usage(argv[0]);
65 return 1;
66 } else if (strcmp(*argv, "-i") == 0) {
67 enable_hid = 1;
68 }
69 if (*argv)
70 argv++;
71 }
72
73 init_audio(input_card, input_device, output_card, output_device);
74 if (enable_hid)
75 init_hid();
76 usb_run(enable_accessory);
77
78 return 0;
79 }
80