-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUSBLauncher_StrikerII.m
248 lines (238 loc) · 10.2 KB
/
USBLauncher_StrikerII.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
//
// USBLauncher_StrikerII.m
// USB Missile Launcher NZ
//
// Created by David Wilson on 7/05/17.
// Copyright © 2017 David G. Wilson. All rights reserved.
//
#import "USBLauncher_StrikerII.h"
@implementation USBLauncher_StrikerII
#pragma mark - HID CONTROL of launcher - Striker II
- (void)missileControlWithBits:(UInt8)controlBits
{
uint8_t report[8] = {0x14, 0x14, 0, 0, 0, 0, 0, 0};
// IOHIDDeviceRef device = [privateDataRef hidDevice];
IOHIDDeviceRef device = [self hidDevice];
// NSLog(@"%02X", controlBits);
if (controlBits & 0x01) //Left
report[0] |= 0x0c;
if (controlBits & 0x02) //Right
report[0] |= 0x0d;
if (controlBits & 0x04) //Up
report[0] |= 0x0e;
if (controlBits & 0x08) //Down
report[0] |= 0x0f;
if (controlBits & 0x10) //Fire
report[0] |= 0x0a;
if (controlBits & 0x64) //Laser
report[0] |= 0x0b;
if (controlBits > 0)
report[1] |= 0x0;
IOHIDDeviceSetReport(device, kIOHIDReportTypeOutput, 0, report, sizeof(report));
}
@end
//if ([[privateDataRef getLauncherType] isEqualToString:@"StrikerII"])
//{
// // This code is here because I need to know the launcher type so that the right launcher can be parked
// // So this procedure ends up being call again by the procedure that is being called, i.e. MissileLauncher_Park
// if (controlBits & 32) // Park
// {
// //NSLog(@"USBMissileControl: MissileControl - MissileLauncher Park");
// // controlBits = 0; // we're outa here, so don't need to worry about setting the controlBits
// [self MissileLauncher_Park];
// return self;
// }
//
// /*
// 2007-06-21 21:33:12.295 USB Missile Launcher NZ[14304] controlLauncher: Laser Toggle Request START
// 2007-06-21 21:33:12.295 USB Missile Launcher NZ[14304] USBMissileControl: launcherType = StrikerII
// 2007-06-21 21:33:12.295 USB Missile Launcher NZ[14304] USBMissileControl: USBVendorID = 4400 (0x1130)
// 2007-06-21 21:33:12.296 USB Missile Launcher NZ[14304] USBMissileControl: USBProductID = 514 (0x202)
// 2007-06-21 21:33:12.296 USB Missile Launcher NZ[14304] USBMissileControl: controlBits 64
// 2007-06-21 21:33:12.296 USB Missile Launcher NZ[14304] USBMissileControl: STRIKER II reqBuffer[0]=11, reqBuffer[1]=11
// 2007-06-21 21:33:12.297 USB Missile Launcher NZ[14304] USBMissileControl: STRIKER II reqBuffer[0]=20, reqBuffer[1]=20
//
// --> here's the reason the laser goes off, this is being called twice...
//
// 2007-06-21 21:33:12.298 USB Missile Launcher NZ[14304] USBMissileControl: launcherType = StrikerII
// 2007-06-21 21:33:12.298 USB Missile Launcher NZ[14304] USBMissileControl: USBVendorID = 4400 (0x1130)
// 2007-06-21 21:33:12.298 USB Missile Launcher NZ[14304] USBMissileControl: USBProductID = 514 (0x202)
// 2007-06-21 21:33:12.298 USB Missile Launcher NZ[14304] USBMissileControl: controlBits 64
// 2007-06-21 21:33:12.298 USB Missile Launcher NZ[14304] USBMissileControl: STRIKER II reqBuffer[0]=11, reqBuffer[1]=11
// 2007-06-21 21:33:12.299 USB Missile Launcher NZ[14304] USBMissileControl: STRIKER II reqBuffer[0]=20, reqBuffer[1]=20
// 2007-06-21 21:33:12.300 USB Missile Launcher NZ[14304] controlLauncher: Laser Toggle Request FINISH
// */
//
//
// // ===========================================================================
// // Control of USB Missile Launcher - Striker II
// // ===========================================================================
// if (debugCommands)
// {
// NSLog(@"USBMissileControl: launcherType = %@", [privateDataRef getLauncherType]);
// NSLog(@"USBMissileControl: USBVendorID = %d (0x%d)", (int)[privateDataRef getusbVendorID], (int)[privateDataRef getusbVendorID]);
// NSLog(@"USBMissileControl: USBProductID = %d (0x%d)", (int)[privateDataRef getusbProductID], (int)[privateDataRef getusbProductID]);
// // NSLog(@"USBMissileControl: device = (0x%x)", [privateDataRef deviceInterface]);
// NSLog(@"USBMissileControl: controlBits = %d", controlBits);
// }
//
// /*
// USB Information (hexadecimal values):
// Vendor ID: 1130
// Product ID: 0202
//
// Ignore this little table for now, I'm just trying to reverse engineer
// what the launcher developers have done. not much help for up/left try activities
// like the other launchers support.
// | 16 | 8 | 4 | 2 | 1 |
// |------|---|---|---|---|
// | 0 | 1 | 0 | 1 | 0 | 10 - fire
// | 0 | 1 | 0 | 1 | 1 | 11 - laser
// | 0 | 1 | 1 | 0 | 0 | 12 - left
// | 0 | 1 | 1 | 0 | 1 | 13 - right
// | 0 | 1 | 1 | 1 | 0 | 14 - up
// | 0 | 1 | 1 | 1 | 1 | 15 - down
// | 1 | 0 | 1 | 0 | 0 | 20 - release
//
// Toy Command Bytes (hexadecimal values):
// Fire Missile = 0x0a 10
// Laser Toggle = 0x0b 11
// Move Left = 0x0c 12
// Move Right = 0x0d 13
// Move Up = 0x0e 14
// Move Down = 0x0f 15
// Release = 0x14 20
//
//
// This documentation from the supplier would appear to be WRONG!
// Actually bytes 0 and 1 need to be filled followed by zeros in the remaining bytes up to 8.
// This information was discovered by using SnoopyPro on a PC.
//
// Sending Toy Commands with Control Transfer (PC to Toy):
// Byte 0: 0
// Byte 1: toyCommandByte
// Byte 2: toyCommandByte
//
// Example Toy Command with Control Transfer: Move Left
// Byte 0: 0
// Byte 1: 0x0c
// Byte 2: 0x0c Send...
//
// Byte 0: 0
// Byte 1: 0x14
// Byte 2: 0x14 Send...
// */
// reqBuffer[0] = 0;
// if (controlBits & 1)
// reqBuffer[0] = 0x0c;//left
//
// if (controlBits & 2)
// reqBuffer[0] = 0x0d;//right
//
// if (controlBits & 4)
// reqBuffer[0] = 0x0e;//up
//
// if (controlBits & 8)
// reqBuffer[0] = 0x0f;//down
//
// if (controlBits & 16)
// reqBuffer[0] = 0x0a;//fire
//
// if (controlBits & 64)
// reqBuffer[0] = 0x0b;//Laser Toggle
//
// if (reqBuffer[0] == 0)
// {
// reqBuffer[0] = 0x14; // this is a guess. If I come back into this routine with a 0 controlBit
// reqBuffer[1] = 0x14; // then perhaps I should send a "stop" or in this case a "release" to the launcher?
// } else
// {
// reqBuffer[1] = reqBuffer[0];
// }
// reqBuffer[2] = 0;
// reqBuffer[3] = 0;
// reqBuffer[4] = 0;
// reqBuffer[5] = 0;
// reqBuffer[6] = 0;
// reqBuffer[7] = 0;
// devRequest.bmRequestType = USBmakebmRequestType(kUSBOut, kUSBClass, kUSBInterface);
// devRequest.bRequest = kUSBRqSetConfig;
// devRequest.wValue = kUSBConfDesc;
// devRequest.wIndex = 0;
// devRequest.wLength = 8;
// devRequest.pData = reqBuffer;
// if (debugCommands)
// {
// NSLog(@"USBMissileControl: STRIKER II reqBuffer[0]=%d, reqBuffer[1]=%d", reqBuffer[0], reqBuffer[1]);
// }
// kr = (*missileDevice)->DeviceRequest(missileDevice, &devRequest);
// if (kr != kIOReturnSuccess)
// {
// if (kr == kIOReturnNoDevice)
// {
// if (debugCommands)
// NSLog(@"USBMissileControl: %@ IOReturn: kIOReturnNoDevice", [privateDataRef getLauncherType]);
// } else
// if (kr == kIOReturnNotOpen)
// {
// if (debugCommands)
// NSLog(@"USBMissileControl: %@ IOReturn: kIOReturnNotOpen", [privateDataRef getLauncherType]);
// } else
// {
// EvaluateUSBErrorCode(missileDevice, missileInterface, kr);
// }
// }
//
// // if (controlBits & 64) //Laser Toggle
// // if ((controlBits & 16) || (controlBits & 64))
// if (controlBits & 16)
// {
// // after the fire comand, we can't send the "release" to the launcher
// // so, NO OPP
// } else
// {
// reqBuffer[0] = 0x14; // release
// reqBuffer[1] = 0x14; // release
// reqBuffer[2] = 0;
// reqBuffer[3] = 0;
// reqBuffer[4] = 0;
// reqBuffer[5] = 0;
// reqBuffer[6] = 0;
// reqBuffer[7] = 0;
// devRequest.bmRequestType = USBmakebmRequestType(kUSBOut, kUSBClass, kUSBInterface);
// devRequest.bRequest = kUSBRqSetConfig;
// devRequest.wValue = kUSBConfDesc;
// // devRequest.wIndex = 0; // Switched this to 1 after mail from Erik Mason - 1 May 2007
// devRequest.wIndex = 1; // having this as 1 may cause a problem with the "release" command
// // Erik Mason reported that movement doesn't stop until launcher reaches end of travel
// devRequest.wLength = 8;
// devRequest.pData = reqBuffer;
// if (debugCommands)
// {
// NSLog(@"USBMissileControl: STRIKER II reqBuffer[0]=%d, reqBuffer[1]=%d", reqBuffer[0], reqBuffer[1]);
// }
// kr = (*missileDevice)->DeviceRequest(missileDevice, &devRequest);
// if (kr != kIOReturnSuccess)
// {
// if (kr == kIOReturnNoDevice)
// {
// if (debugCommands)
// NSLog(@"USBMissileControl: %@ IOReturn: kIOReturnNoDevice", [privateDataRef getLauncherType]);
// } else
// if (kr == kIOReturnNotOpen)
// {
// if (debugCommands)
// NSLog(@"USBMissileControl: %@ IOReturn: kIOReturnNotOpen", [privateDataRef getLauncherType]);
// } else
// {
// EvaluateUSBErrorCode(missileDevice, missileInterface, kr);
// }
// }
// }
//
// // ===========================================================================
// // END OF Control of USB Missile Launcher - Striker II
// // ===========================================================================
//
//}
//else