wiiuse can read data on osx now

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@3156 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
tmator 2009-05-05 20:25:55 +00:00
parent c70dd2ab0a
commit f2e92a6500
2 changed files with 71 additions and 13 deletions

View File

@ -84,6 +84,29 @@ int wiiuse_poll(struct wiimote_t** wm, int wiimotes) {
int evnt = 0; int evnt = 0;
#ifndef WIN32 #ifndef WIN32
#if defined(__APPLE__)
int i;
if (!wm)
return 0;
for (i = 0; i < wiimotes; ++i) {
wm[i]->event = WIIUSE_NONE;
if (wiiuse_io_read(wm[i])) {
/* propagate the event */
propagate_event(wm[i], wm[i]->event_buf[1], wm[i]->event_buf+2);
evnt += (wm[i]->event != WIIUSE_NONE);
/* clear out the event buffer */
memset(wm[i]->event_buf, 0, sizeof(wm[i]->event_buf));
} else {
idle_cycle(wm[i]);
}
}
#else
/* /*
* *nix * *nix
*/ */
@ -167,6 +190,7 @@ int wiiuse_poll(struct wiimote_t** wm, int wiimotes) {
idle_cycle(wm[i]); idle_cycle(wm[i]);
} }
} }
#endif
#else #else
/* /*
* Windows * Windows

View File

@ -52,6 +52,8 @@ IOBluetoothL2CAPChannel * _cchan;
#include "wiiuse_internal.h" #include "wiiuse_internal.h"
#include "io.h" #include "io.h"
byte DataFromWiimote[MAX_PAYLOAD];
static int wiiuse_connect_single(struct wiimote_t* wm, char* address); static int wiiuse_connect_single(struct wiimote_t* wm, char* address);
@interface SearchBT: NSObject {} @interface SearchBT: NSObject {}
@ -72,6 +74,18 @@ static int wiiuse_connect_single(struct wiimote_t* wm, char* address);
@implementation ConnectBT @implementation ConnectBT
-(void)writeToWiimote: (void *)data length:(UInt16)length
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[_cchan writeSync:data length:length];
usleep(10000);
[pool release];
}
#pragma mark - #pragma mark -
#pragma mark Bluetooth #pragma mark Bluetooth
@ -82,10 +96,16 @@ static int wiiuse_connect_single(struct wiimote_t* wm, char* address);
} }
- (void)l2capChannelData:(IOBluetoothL2CAPChannel *) l2capChannel data:(unsigned char *)buffer length:(NSUInteger)length { - (void)l2capChannelData:(IOBluetoothL2CAPChannel *) l2capChannel data:(byte *)BtData length:(NSUInteger)length {
//data ?
//here we got data from wiimote //here we got data from wiimote
printf("data %d\n",length); for (int o=0; o<MAX_PAYLOAD; o++)
{
DataFromWiimote[o] = BtData[o];
}
//stop the main loop after reading
CFRunLoopStop( CFRunLoopGetCurrent() );
} }
@ -142,11 +162,13 @@ static int wiiuse_connect_single(struct wiimote_t* wm, char* address);
@end @end
@implementation SearchBT @implementation SearchBT
-(void) deviceInquiryComplete: (IOBluetoothDeviceInquiry*) sender -(void) deviceInquiryComplete: (IOBluetoothDeviceInquiry*) sender
error: (IOReturn) error error: (IOReturn) error
aborted: (BOOL) aborted aborted: (BOOL) aborted
{ {
int founded = [[bti foundDevices] count]; //int founded = [[bti foundDevices] count];
CFRunLoopStop( CFRunLoopGetCurrent() ); CFRunLoopStop( CFRunLoopGetCurrent() );
} }
-(void) deviceInquiryDeviceFound: (IOBluetoothDeviceInquiry*) sender -(void) deviceInquiryDeviceFound: (IOBluetoothDeviceInquiry*) sender
@ -204,6 +226,9 @@ void detectWiimote()
*/ */
int wiiuse_find(struct wiimote_t** wm, int max_wiimotes, int timeout) { int wiiuse_find(struct wiimote_t** wm, int max_wiimotes, int timeout) {
int found_devices;
int found_wiimotes;
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
sbt = [[SearchBT alloc] init]; sbt = [[SearchBT alloc] init];
@ -214,6 +239,11 @@ int wiiuse_find(struct wiimote_t** wm, int max_wiimotes, int timeout) {
CFRunLoopRun(); CFRunLoopRun();
found_wiimotes = 0;
WIIUSE_INFO("Found %i bluetooth device(s).", found_devices);
WIIMOTE_ENABLE_STATE(wm[found_wiimotes], WIIMOTE_STATE_DEV_FOUND);
[bti release]; [bti release];
[sbt release]; [sbt release];
@ -281,15 +311,17 @@ static int wiiuse_connect_single(struct wiimote_t* wm, char* address) {
cbt = [[ConnectBT alloc] init]; cbt = [[ConnectBT alloc] init];
//start to connect to the wiimotes //start to connect to the wiimotes
[cbt connectToWiimotes]; [cbt connectToWiimotes];
WIIUSE_INFO("Connected to wiimote [id %i].", wm->unid);
//run the main loop to get bt data
CFRunLoopRun();
/* do the handshake */ /* do the handshake */
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_CONNECTED); WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_CONNECTED);
wiiuse_handshake(wm, NULL, 0); wiiuse_handshake(wm, NULL, 0);
wiiuse_set_report_type(wm); wiiuse_set_report_type(wm);
[pool release]; [pool release];
return 1; return 1;
@ -315,21 +347,23 @@ void wiiuse_disconnect(struct wiimote_t* wm) {
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE); WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE);
} }
int wiiuse_io_read(struct wiimote_t* wm) { int wiiuse_io_read(struct wiimote_t* wm) {
//TODO //run the main loop to get bt data
CFRunLoopRun();
for (int len=0; len<MAX_PAYLOAD; len++)
{
wm->event_buf[len] = DataFromWiimote[len];
}
return 1; return 1;
} }
int wiiuse_io_write(struct wiimote_t* wm, byte* buf, int len) { int wiiuse_io_write(struct wiimote_t* wm, byte* buf, int len) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; [cbt writeToWiimote:buf length:len];
[_cchan writeSync:buf length:len];
usleep (10000);
[pool release];
return 1; return 1;
} }