Mercurial > rcctl_linux
annotate rcctl.c @ 7:d2b8d45019d9
minor tweak
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Wed, 05 Jan 2011 22:34:41 +0900 |
parents | cd846ca24ca4 |
children | a630b07450be |
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"); | |
95 printf("Adapted to linux by yaz / honeyplanet development\n"); | |
96 printf("usage: %s <options> <vender> <song number>\n", cmd); | |
97 printf("options: -d <debug level>\n"); | |
98 exit(0); | |
99 } | |
0 | 100 |
101 | |
2 | 102 int main(int argc, char **argv) |
0 | 103 { |
1
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
104 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
|
105 unsigned char sbuf[8]; |
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
106 hid_return ret; |
2 | 107 int opt; |
0 | 108 |
2 | 109 if(argc < 3) { |
110 usage(argv[0]); | |
1
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
111 } |
0 | 112 |
2 | 113 while ((opt=getopt(argc, argv, "d:h")) != -1) { |
114 switch (opt) { | |
115 case 'd': | |
116 debug = atoi(optarg); | |
117 break; | |
118 case 'h': | |
119 default: | |
120 usage(argv[0]); | |
121 break; | |
122 } | |
123 } | |
124 argc -= optind; | |
125 argv += optind; | |
126 | |
127 if ((u = cdcnv(buf, *argv, *(argv+1))) < 0) { | |
128 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
|
129 return 1; |
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
130 } |
7 | 131 debug(2, "cdcnv %d\n", u); |
2 | 132 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
|
133 |
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
134 if (init_usb()) |
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
135 return 255; |
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
136 |
6 | 137 debug(1, "done.\n"); |
0 | 138 |
6 | 139 debug(1, ""); |
1
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
140 for(i=0; i<u; i++ ) { |
6 | 141 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
|
142 } |
6 | 143 message(1, "\n"); |
0 | 144 |
1
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
145 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
|
146 |
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
147 /* u is the total length of the packet to send */ |
6 | 148 debug(1,""); |
1
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
149 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
|
150 sbuf[(i-1)%8] = buf[i] & 0x00ff; |
6 | 151 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
|
152 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
|
153 ret = hid_set_output_report(hidif, PATH_IN, 2, (char *)sbuf, 8); |
6 | 154 message(1, "**WRITE** "); |
1
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
155 if (ret != HID_RET_SUCCESS) { |
6 | 156 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
|
157 } |
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
158 } |
0 | 159 } |
6 | 160 message(1, "\n"); |
0 | 161 |
1
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
162 if(fin_usb()) |
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
163 return 255; |
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
164 |
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
165 return 0; |
0 | 166 } |