Skip to content
This repository was archived by the owner on Mar 18, 2022. It is now read-only.

Commit 5538027

Browse files
committed
Added Process, Stop and RawData.
1 parent bc519fc commit 5538027

4 files changed

Lines changed: 135 additions & 15 deletions

File tree

GCAdapter.cc

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ int AddAdapter(libusb_device *dev) {
117117
}
118118
NAN_METHOD(Load) {
119119
if(info.Length()>0) {
120-
Nan::ThrowError("Load() must not have arguments");
120+
Nan::ThrowError("Process() must not have arguments");
121121
return;
122122
}
123123
int payload_size = 0, tmp = 0;
@@ -126,6 +126,10 @@ NAN_METHOD(Load) {
126126
info.GetReturnValue().Set(return_value);
127127
}
128128
NAN_METHOD(Request) {
129+
if (info.Length()>0) {
130+
Nan::ThrowError("Load() must not have arguments");
131+
return;
132+
}
129133
adapter_thread_running.Set(true);
130134
adapter_thread = thread(Read);
131135
auto return_string = PollBytes(controller_payload);
@@ -204,12 +208,79 @@ unsigned int GetNthBit(uint8_t number,int n) {
204208
unsigned int bit = (unsigned)(number & (1 << n - 1));
205209
return bit >> n-1;
206210
}
211+
NAN_METHOD(Process) {
212+
if (info.Length()>0) {
213+
Nan::ThrowError("Process() must not have arguments");
214+
return;
215+
}
216+
adapter_thread_running.Set(true);
217+
adapter_thread = thread(Read);
218+
Nan::HandleScope arr_scope;
219+
v8::Handle<v8::Array> arr = Nan::New<v8::Array>();
220+
for (int i = 0; i < 4; i++) {
221+
arr->Set(i,GetGamepadStatus(controller_payload, i+1));
222+
}
223+
info.GetReturnValue().Set(arr);
224+
}
225+
NAN_METHOD(RawData) {
226+
if (info.Length()>0) {
227+
Nan::ThrowError("RawData() must not have arguments");
228+
return;
229+
}
230+
adapter_thread_running.Set(true);
231+
adapter_thread = thread(Read);
232+
stringstream return_value;
233+
return_value << "[";
234+
for (int i = 0; i < 10; i++) {
235+
return_value << bitset<8>(controller_payload[i]) << ",";
236+
}
237+
return_value << bitset<8>(controller_payload[10]) << "]";
238+
auto chain = Nan::New<v8::String>(return_value.str()).ToLocalChecked();
239+
info.GetReturnValue().Set(chain);
240+
}
241+
242+
v8::Local<v8::Object> GetGamepadStatus(uint8_t * results, int port)
243+
{
244+
using namespace v8;
245+
using namespace Nan;
246+
Local<Object> status = New<Object>();
247+
248+
status->Set(New<String>("connected").ToLocalChecked(), New<Boolean>(GetNthBit(results[1 * port], 5)));
249+
250+
status->Set(New<String>("buttonA").ToLocalChecked(), New<Boolean>(GetNthBit(results[2 * port], 1)));
251+
status->Set(New<String>("buttonB").ToLocalChecked(), New<Boolean>(GetNthBit(results[2 * port], 2)));
252+
status->Set(New<String>("buttonX").ToLocalChecked(), New<Boolean>(GetNthBit(results[2 * port], 3)));
253+
status->Set(New<String>("buttonY").ToLocalChecked(), New<Boolean>(GetNthBit(results[2 * port], 4)));
254+
255+
status->Set(New<String>("padLeft").ToLocalChecked(), New<Boolean>(GetNthBit(results[2 * port], 5)));
256+
status->Set(New<String>("padRight").ToLocalChecked(), New<Boolean>(GetNthBit(results[2 * port], 6)));
257+
status->Set(New<String>("padDown").ToLocalChecked(), New<Boolean>(GetNthBit(results[2 * port], 7)));
258+
status->Set(New<String>("padUp").ToLocalChecked(), New<Boolean>(GetNthBit(results[2 * port], 8)));
259+
260+
status->Set(New<String>("buttonL").ToLocalChecked(), New<Boolean>(GetNthBit(results[3 * port], 4)));
261+
status->Set(New<String>("buttonR").ToLocalChecked(), New<Boolean>(GetNthBit(results[3 * port], 3)));
262+
status->Set(New<String>("buttonZ").ToLocalChecked(), New<Boolean>(GetNthBit(results[3 * port], 2)));
263+
status->Set(New<String>("buttonStart").ToLocalChecked(), New<Boolean>(GetNthBit(results[3 * port], 1)));
264+
265+
status->Set(New<String>("mainStickHorizontal").ToLocalChecked(), New<Number>(results[4 * port]/128.0 - 1));
266+
status->Set(New<String>("mainVertical").ToLocalChecked(), New<Number>(results[5 * port]/128.0 - 1));
267+
268+
status->Set(New<String>("cStickHorizontal").ToLocalChecked(), New<Number>(results[6 * port]/128.0 -1));
269+
status->Set(New<String>("cStickVertical").ToLocalChecked(), New<Number>(results[7 * port]/128.0 -1));
270+
271+
status->Set(New<String>("triggerL").ToLocalChecked(), New<Number>(results[8 * port]/256.0));
272+
status->Set(New<String>("triggerR").ToLocalChecked(), New<Number>(results[9 * port]/256.0));
273+
274+
return status;
275+
}
207276

208277
NAN_MODULE_INIT(Bridge) {
209278
NAN_EXPORT(target,Load);
210279
NAN_EXPORT(target,Setup);
211280
NAN_EXPORT(target,Request);
281+
NAN_EXPORT(target, Process);
212282
NAN_EXPORT(target, Stop);
283+
NAN_EXPORT(target, RawData);
213284
}
214285

215-
NODE_MODULE(BridgeTest_2,Bridge)
286+
NODE_MODULE(gca_node,Bridge)

GCAdapter.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,21 @@
44
#include <libusb-1.0/libusb.h>
55
#endif
66
#include <sstream>
7-
#include <nan.h>
87

98
#pragma once
109

1110
int AddAdapter(libusb_device *dev);
1211
NAN_METHOD(Load);
1312
NAN_METHOD(Setup);
1413
NAN_METHOD(Request);
14+
NAN_METHOD(Process);
15+
NAN_METHOD(Stop);
16+
NAN_METHOD(RawData);
1517
void Read();
1618
bool IsAccessible(libusb_device *dev);
1719
std::string PollBytes(uint8_t *results);
1820
unsigned int GetNthBit(uint8_t number, int n);
21+
v8::Local<v8::Object> GetGamepadStatus(uint8_t * results, int port);
1922

2023
const uint16_t GAMECUBE_VID = 0x057E;
2124
const uint16_t GAMECUBE_PID = 0x0337;

README.md

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ gca-node is a NodeJS addon that adds Nintendo&reg; Wii U GameCube&trade; Adapter
44

55
## Usage
66

7-
**gca-node currently only builds on Windows 7+**, although there is planned support for Linux and Mac OS.
7+
**gca-node currently only builds on Windows 7+ 64-bit**, although there is planned support for Linux and Mac OS.
88
As of now, it can only be used on NW.js.
99

1010
### Prerequisites
@@ -20,15 +20,17 @@ As of now, it can only be used on NW.js.
2020
3. Open the CLI inside the repository and execute `node-gyp rebuild`.
2121

2222
### NW.js
23-
1. Copy the included `configure.bat` to your NW.js project.
24-
2. Open the CLI inside your NW.js project, and run the `configure.bat` file to install the addon.
25-
3. Whenever you need to use gca-node, use an alias for require so that other NodeJS tools like webpack do not mistake it as a NodeJS module.
23+
1. Add `gca-node` to your project's `package.json` dependencies.
24+
2. Copy the included `configure.bat` to your NW.js project.
25+
3. Open the CLI inside your NW.js project, and run the `configure.bat` file to install the addon.
26+
4. **[Tip]:** Whenever you need to use gca-node, use an alias for require so that other NodeJS tools like webpack do not mistake it as a NodeJS module.
2627
```
2728
var native_require = eval('require');
28-
gca_node = native_require('gca-node.node')
29+
gca_node = native_require('gca-node.node');
2930
```
3031

3132
## gca-node API
33+
To be added on Wiki pages.
3234

3335
### Setup()
3436
Detects the first Nintendo&reg; Wii U GameCube&trade; Adapter connected in your computer.
@@ -38,19 +40,49 @@ Returns 0 if the setup has detected one.
3840
Claims the interface to be used on the NodeJS application.
3941
Returns 0 if an interface has been succesfully claimed.
4042

41-
### Read()
42-
TODO. Returns an object with the current status of the GameCube controller.
43+
### Process()
44+
Returns an array of 4 objects with the current status of each port of the adapter.
45+
Each object contains a status for each port, whether if there is a GameCube&trade; Controller connected or not.
4346

4447
### Request()
45-
Obtains debug information about the current status of the GameCube controllers.
48+
Returns debug information about the current status of the GameCube controllers.
4649

50+
### RawData()
51+
Returns raw binary data of the status of the Adapter.
4752

4853
### Unload()
4954
Releases the interface so that it can be used by other applications.
5055
Returns 0 if succesful.
5156

52-
### Shutdown()
57+
### Stop()
5358
Closes the Nintendo&reg; Wii U GameCube&trade; Adapter so that it can be safely unplugged.
5459
Returns 0 if succesful.
5560

56-
[logo]: http://i.imgur.com/quWt3jK.png
61+
## FAQ
62+
* **What is the difference between gca-node and gca+?**
63+
* gca-node and the upcoming sister project [gca+][1] share almost the same source code. gca-node is designed for NodeJS applications, and gca+ is designed for C++ applications such as Unreal Engine.
64+
* **Will gca-node support rumble?**
65+
* gca-node 2.0 will be able to send rumble commands to the controllers.
66+
* **Will gca-node support third party GameCube Controllers?**
67+
* This has not been tested, but in theory it is very likely that third party GameCube controllers are compatible with gca-node. However, their extra features (i.e. turbo mode) will most likely be not supported due to the adapter's specifications.
68+
* **Will gca-node support third party GameCube USB Adapters?**
69+
* It is very unlikely due to the structure of gca-node as of now.
70+
* **Will gca-node support connection with Game Boy Advance with GBA Link?**
71+
* No. Unfortunately, the specifications of the adapter make it incompatible with the GBA Link. Even if it were to be compatible, remotely interfacing with the Game Boy Advance is currently impossible.
72+
* **When will gca-node be cross-platform?**
73+
* We expect support in Linux in gca-node 1.4.x.
74+
* **Will gca-node br available for 32-bit platforms?**
75+
* gca-node 1.5.x will start experimenting with 32-bit platforms.
76+
* **Will gca-node support [electron][2] and apm?**
77+
* Probably not. Testings with electron have reported problems due to using a different version of NodeJS and incomaptibilities with apm. We will investigate on a workaround during gca-node 2.x.
78+
* **[Windows] Why is it necessary to use just Zadig? Can't I just use [ElMassivo's USB GameCube Adapter][3] instead?**
79+
* *ElMassivo's USB GameCube Adapter must remain inactive while gca-node is running*, as it claims the only interface available of the adapter. Without any other free interfaces, gca-node is unable to use the adapter, and viceversa.
80+
* However, you can install ElMassivo's USB GameCube Adapter and not use it, since Zadig is a component of this program.
81+
* **Why is gca-node better than HTML5 Gamepad API?**
82+
* HTML5 Gamepad API requires ElMassivo's USB GameCube Adapter, which does not bring all native capabilities that gca-node offers, like real-time input or rumble support.
83+
* Chromium's support for Nintendo&reg; Wii U GameCube&trade; Adapter is currently incomplete and glitchy.
84+
85+
[logo]: http://i.imgur.com/quWt3jK.png
86+
[1]: https://github.com/yonicstudios/gca-plus
87+
[2]: https://github.com/electron/electron
88+
[3]: http://m4sv.com/page/wii-u-gcn-usb-driver

test.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1-
exports.gcaInit = function() {
2-
console.log("GCA Node has been succesfully loaded.");
1+
gca_node = require("./build/Release/gca-node.node");
2+
3+
var loop;
4+
5+
loop = gca_node.Setup()
6+
if(loop>0) {
7+
var loop = gca_node.Load();
8+
var count = 0;
9+
console.log(loop);
10+
while(loop===0&&count<10000) {
11+
console.log(gca_node.Process()[0]);
12+
count+=1;
13+
}
14+
console.log(gca_node.Stop());
15+
} else {
16+
console.log("Aaah " + loop)
317
}

0 commit comments

Comments
 (0)