Mercurial > rcctl_linux
annotate rcctl.c @ 8:a630b07450be
revised help message
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Thu, 06 Jan 2011 03:38:31 +0900 |
parents | d2b8d45019d9 |
children | c6f444d2272c |
rev | line source |
---|---|
0 | 1 /* rcctl.c --------------------------------------------- |
1
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
2 $Id: rcctl.c,v 1.1 2002/12/21 01:13:28 tosy Exp $ |
0 | 3 |
2 | 4 v0.10 97.08.15 初期版(コミケット52) |
5 v0.11 97.08.27 通信タイミング修正 | |
6 v0.12 97.09.12 U-kara-2サポート | |
7 v0.12a 97.09.15 返り値設定 | |
1
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
8 v0.12b 97.09.20 Bug fix (JOY:[SP]) |
2 | 9 v0.20 97.10.01 FreeBSD版 |
1
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
10 v0.20a 97.10.18 Bug fix (X2k:[SP],[ST]) |
2 | 11 v0.21 97.12.10 ALISA-3シーケンス修正 |
12 v0.30 97.12.13 コード変換部(cdcnv.c)分離 | |
13 v0.40 02.12.16 USB版対応 | |
14 v0.50 11.01.06 linux専用に書き直し (yaz) | |
15 【cdcnv.c の履歴も参照のこと】 | |
1
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
16 ------------------------------------------------------*/ |
6 | 17 |
0 | 18 #include <stdio.h> |
1
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
19 #include <hid.h> |
0 | 20 #include <libusb.h> |
2 | 21 #include "debug.h" |
1
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
22 |
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
23 #ifndef S_VERS |
2 | 24 #define S_VERS "0.50" |
0 | 25 #endif |
26 | |
1
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
27 /* globals */ |
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
28 HIDInterface *hidif; |
2 | 29 int debug = 0; |
0 | 30 |
1
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
31 /* prototypes */ |
0 | 32 int cdcnv(int buf[], char *mak, char *cod); |
33 extern char *cverrstr[]; | |
34 | |
1
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
35 int init_usb(void) |
0 | 36 { |
1
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
37 hid_return ret; |
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
38 |
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
39 /* vendor id and product id of okecon */ |
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
40 HIDInterfaceMatcher matcher = { 0x0bfe, 0x2022, NULL, NULL, 0 }; |
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
41 |
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
42 /* see include/debug.h for possible values */ |
2 | 43 hid_set_debug(debug); |
1
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
44 hid_set_debug_stream(stderr); |
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
45 /* passed directly to libusb */ |
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
46 hid_set_usb_debug(0); |
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
47 |
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
48 ret = hid_init(); |
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
49 if (ret != HID_RET_SUCCESS) { |
6 | 50 message(0, "hid_init failed with return code %d\n", ret); |
1
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
51 return 1; |
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
52 } |
0 | 53 |
1
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
54 hidif = hid_new_HIDInterface(); |
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
55 if (hidif == 0) { |
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
56 fprintf(stderr, "hid_new_HIDInterface() failed, out of memory?\n"); |
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
57 return 1; |
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
58 } |
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
59 |
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
60 ret = hid_force_open(hidif, 0, &matcher, 3); |
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
61 if (ret != HID_RET_SUCCESS) { |
6 | 62 message(0, "hid_force_open failed with return code %d\n", ret); |
1
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
63 return 1; |
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
64 } |
0 | 65 |
1
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
66 return 0; |
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
67 } /* end of init_usb() */ |
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
68 |
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
69 |
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
70 int fin_usb() |
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
71 { |
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
72 hid_return ret; |
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
73 |
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
74 ret = hid_close(hidif); |
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
75 if (ret != HID_RET_SUCCESS) { |
6 | 76 message(0, "hid_close failed with return code %d\n", ret); |
1
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
77 return 1; |
0 | 78 } |
1
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
79 |
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
80 hid_delete_HIDInterface(&hidif); |
0 | 81 |
1
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
82 ret = hid_cleanup(); |
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
83 if (ret != HID_RET_SUCCESS) { |
6 | 84 message(0, "hid_cleanup failed with return code %d\n", ret); |
1
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
85 return 1; |
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
86 } |
0 | 87 |
1
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
88 return 0; |
0 | 89 } |
90 | |
2 | 91 void usage(char *cmd) |
92 { | |
93 printf("'Oke-Con' controller, version " S_VERS ".\n"); | |
94 printf("Copyright (C) 1997-2002 by Tosy / W341IG.\n"); | |
8 | 95 printf("Adapted to linux by yaz / honeyplanet development.\n"); |
2 | 96 printf("usage: %s <options> <vender> <song number>\n", cmd); |
8 | 97 printf("options: -d <debug level> specify debug message level\n"); |
98 printf(" -h show this help\n"); | |
2 | 99 exit(0); |
100 } | |
0 | 101 |
102 | |
2 | 103 int main(int argc, char **argv) |
0 | 104 { |
1
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
105 int i, u, buf[16]; |
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
106 unsigned char sbuf[8]; |
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
107 hid_return ret; |
2 | 108 int opt; |
0 | 109 |
2 | 110 if(argc < 3) { |
111 usage(argv[0]); | |
1
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
112 } |
0 | 113 |
2 | 114 while ((opt=getopt(argc, argv, "d:h")) != -1) { |
115 switch (opt) { | |
116 case 'd': | |
117 debug = atoi(optarg); | |
118 break; | |
119 case 'h': | |
120 default: | |
121 usage(argv[0]); | |
122 break; | |
123 } | |
124 } | |
125 argc -= optind; | |
126 argv += optind; | |
127 | |
128 if ((u = cdcnv(buf, *argv, *(argv+1))) < 0) { | |
129 fprintf(stderr, "%s: %s\n", *argv, cverrstr[~u]); | |
1
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
130 return 1; |
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
131 } |
7 | 132 debug(2, "cdcnv %d\n", u); |
2 | 133 debug(1, "Initializing....\n"); |
1
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
134 |
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
135 if (init_usb()) |
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
136 return 255; |
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
137 |
6 | 138 debug(1, "done.\n"); |
0 | 139 |
6 | 140 debug(1, ""); |
1
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
141 for(i=0; i<u; i++ ) { |
6 | 142 message(1, "%02x ", buf[i]); |
1
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
143 } |
6 | 144 message(1, "\n"); |
0 | 145 |
1
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
146 const int PATH_IN[1] = { 0xffa10004 }; |
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
147 |
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
148 /* u is the total length of the packet to send */ |
6 | 149 debug(1,""); |
1
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
150 for(i=1; i<u; i++ ) { |
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
151 sbuf[(i-1)%8] = buf[i] & 0x00ff; |
6 | 152 message(1, "%02x ", sbuf[(i-1)%8]); |
1
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
153 if ((i == 8)||(i == (u-1))) { |
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
154 ret = hid_set_output_report(hidif, PATH_IN, 2, (char *)sbuf, 8); |
6 | 155 message(1, "**WRITE** "); |
1
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
156 if (ret != HID_RET_SUCCESS) { |
6 | 157 message(0, "hid_set_output_report failed with return code %d\n", ret); |
1
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
158 } |
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
159 } |
0 | 160 } |
6 | 161 message(1, "\n"); |
0 | 162 |
1
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
163 if(fin_usb()) |
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
164 return 255; |
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
165 |
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
166 return 0; |
0 | 167 } |