Mercurial > rcctl_linux
annotate rcctl.c @ 2:b16b82dbfe87
massive cleanup
| author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
|---|---|
| date | Wed, 05 Jan 2011 21:41:39 +0900 |
| parents | 05cc06e88a57 |
| children | cd846ca24ca4 |
| 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 ------------------------------------------------------*/ |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
17 #define __LINUX__ |
| 0 | 18 #include <fcntl.h> |
| 19 #include <stdio.h> | |
| 2 | 20 //#include <termios.h> |
| 21 //#include <unistd.h> | |
| 22 //#include <sys/ioctl.h> | |
|
1
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
23 |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
24 #define HID_MAX_USAGES 16 |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
25 typedef unsigned int __u32; |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
26 typedef unsigned int kernel_ulong_t; |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
27 |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
28 #include <hid.h> |
| 0 | 29 #include <libusb.h> |
| 30 | |
|
1
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
31 #include <linux/types.h> |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
32 |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
33 #define BITS_PER_LONG 32 |
| 0 | 34 |
|
1
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
35 #include <asm/types.h> |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
36 #include <errno.h> |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
37 #include <string.h> |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
38 |
| 2 | 39 #include "debug.h" |
|
1
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
40 |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
41 #ifndef S_VERS |
| 2 | 42 #define S_VERS "0.50" |
| 0 | 43 #endif |
| 44 | |
|
1
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
45 /* globals */ |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
46 HIDInterface *hidif; |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
47 extern int errno; |
| 2 | 48 int debug = 0; |
| 0 | 49 |
|
1
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
50 /* prototypes */ |
| 0 | 51 int cdcnv(int buf[], char *mak, char *cod); |
| 52 extern char *cverrstr[]; | |
| 53 | |
|
1
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
54 int init_usb(void) |
| 0 | 55 { |
|
1
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
56 hid_return ret; |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
57 |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
58 /* 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
|
59 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
|
60 |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
61 /* see include/debug.h for possible values */ |
| 2 | 62 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
|
63 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
|
64 /* passed directly to libusb */ |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
65 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
|
66 |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
67 ret = hid_init(); |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
68 if (ret != HID_RET_SUCCESS) { |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
69 fprintf(stderr, "hid_init failed with return code %d\n", ret); |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
70 return 1; |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
71 } |
| 0 | 72 |
|
1
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
73 hidif = hid_new_HIDInterface(); |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
74 if (hidif == 0) { |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
75 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
|
76 return 1; |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
77 } |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
78 |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
79 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
|
80 if (ret != HID_RET_SUCCESS) { |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
81 fprintf(stderr, "hid_force_open failed with return code %d\n", ret); |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
82 return 1; |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
83 } |
| 0 | 84 |
|
1
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
85 return 0; |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
86 } /* end of init_usb() */ |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
87 |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
88 |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
89 int fin_usb() |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
90 { |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
91 hid_return ret; |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
92 |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
93 ret = hid_close(hidif); |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
94 if (ret != HID_RET_SUCCESS) { |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
95 fprintf(stderr, "hid_close failed with return code %d\n", ret); |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
96 return 1; |
| 0 | 97 } |
|
1
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
98 |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
99 hid_delete_HIDInterface(&hidif); |
| 0 | 100 |
|
1
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
101 ret = hid_cleanup(); |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
102 if (ret != HID_RET_SUCCESS) { |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
103 fprintf(stderr, "hid_cleanup failed with return code %d\n", ret); |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
104 return 1; |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
105 } |
| 0 | 106 |
|
1
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
107 return 0; |
| 0 | 108 } |
| 109 | |
| 2 | 110 void usage(char *cmd) |
| 111 { | |
| 112 printf("'Oke-Con' controller, version " S_VERS ".\n"); | |
| 113 printf("Copyright (C) 1997-2002 by Tosy / W341IG.\n"); | |
| 114 printf("Adapted to linux by yaz / honeyplanet development\n"); | |
| 115 printf("usage: %s <options> <vender> <song number>\n", cmd); | |
| 116 printf("options: -d <debug level>\n"); | |
| 117 exit(0); | |
| 118 } | |
| 0 | 119 |
| 120 | |
| 2 | 121 int main(int argc, char **argv) |
| 0 | 122 { |
|
1
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
123 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
|
124 unsigned char sbuf[8]; |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
125 hid_return ret; |
| 2 | 126 int opt; |
| 0 | 127 |
| 2 | 128 if(argc < 3) { |
| 129 usage(argv[0]); | |
|
1
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
130 } |
| 0 | 131 |
| 2 | 132 while ((opt=getopt(argc, argv, "d:h")) != -1) { |
| 133 switch (opt) { | |
| 134 case 'd': | |
| 135 debug = atoi(optarg); | |
| 136 break; | |
| 137 case 'h': | |
| 138 default: | |
| 139 usage(argv[0]); | |
| 140 break; | |
| 141 } | |
| 142 } | |
| 143 argc -= optind; | |
| 144 argv += optind; | |
| 145 | |
| 146 if ((u = cdcnv(buf, *argv, *(argv+1))) < 0) { | |
| 147 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
|
148 return 1; |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
149 } |
| 2 | 150 debug(1, "cdcnv %d\n", u); |
| 151 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
|
152 |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
153 if (init_usb()) |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
154 return 255; |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
155 |
| 2 | 156 debug(1, " done.\n"); |
| 0 | 157 |
|
1
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
158 for(i=0; i<u; i++ ) { |
| 2 | 159 debug(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
|
160 } |
| 2 | 161 debug(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 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
|
164 |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
165 /* u is the total length of the packet to send */ |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
166 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
|
167 sbuf[(i-1)%8] = buf[i] & 0x00ff; |
| 2 | 168 debug(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
|
169 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
|
170 ret = hid_set_output_report(hidif, PATH_IN, 2, (char *)sbuf, 8); |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
171 fprintf(stderr, "**WRITE**\n"); |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
172 if (ret != HID_RET_SUCCESS) { |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
173 fprintf(stderr, "hid_set_output_report failed with return code %d\n", ret); |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
174 } |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
175 } |
| 0 | 176 } |
| 2 | 177 debug(1, "\n"); |
| 0 | 178 |
|
1
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
179 if(fin_usb()) |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
180 return 255; |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
181 |
|
05cc06e88a57
modified to make use of libhid to access the device
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
0
diff
changeset
|
182 return 0; |
| 0 | 183 } |
