Skip to content

Commit

Permalink
Merge branch 'master' of github.com:tenderlove/ruby-bluetooth
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Jul 4, 2010
2 parents 474efec + 28c3d2e commit 15ad551
Show file tree
Hide file tree
Showing 12 changed files with 520 additions and 20 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/ext/bluetooth/Makefile
/tmp
/pkg
/doc
*.swp
*.bundle
*.dll
Expand Down
4 changes: 4 additions & 0 deletions Manifest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ ext/bluetooth/extconf.rb
ext/bluetooth/linux/ruby_bluetooth.c
ext/bluetooth/linux/ruby_bluetooth.h
ext/bluetooth/macosx/device.m
ext/bluetooth/macosx/error.m
ext/bluetooth/macosx/host_controller.m
ext/bluetooth/macosx/ruby_bluetooth.h
ext/bluetooth/macosx/ruby_bluetooth.m
ext/bluetooth/macosx/scan.m
Expand All @@ -14,4 +16,6 @@ ext/bluetooth/win32/ruby_bluetooth.h
lib/bluetooth.rb
lib/bluetooth/device.rb
sample/name.rb
sample/pair.rb
sample/quality.rb
sample/scan.rb
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ require 'rubygems'
require 'hoe'
#require 'rake/extensiontask'

hoe = Hoe.spec 'ruby-bluetooth' do
hoe = Hoe.spec 'bluetooth' do
developer 'Eric Hodel', 'drbrain@segment7.net'
developer 'Jeremie Castagna', ''
developer 'Esteve Fernandez', ''
Expand Down
109 changes: 100 additions & 9 deletions ext/bluetooth/macosx/device.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,74 @@
return device;
}

VALUE rbt_device_link_quality(VALUE self) {
HCIDelegate *delegate;
IOBluetoothDevice *device;
IOBluetoothHostController *controller;
IOReturn status;
NSAutoreleasePool *pool;

pool = [[NSAutoreleasePool alloc] init];

device = rbt_device_get(self);

delegate = [[HCIDelegate alloc] init];
delegate.device = self;

controller = [IOBluetoothHostController defaultController];
[controller setDelegate: delegate];

status = [controller readLinkQualityForDevice: device];

if (status != noErr) {
[pool release];
return Qfalse;
}

CFRunLoopRun();

[pool release];

status = (IOReturn)NUM2INT(rb_iv_get(self, "@link_quality_error"));

rbt_check_status(status, nil);

return rb_iv_get(self, "@link_quality");
}

VALUE rbt_device_open_connection(VALUE self) {
IOBluetoothDevice *device;
IOReturn status;
NSAutoreleasePool *pool;
VALUE result;

pool = [[NSAutoreleasePool alloc] init];

device = rbt_device_get(self);

if (![device isConnected]) {
status = [device openConnection];

rbt_check_status(status, pool);
}

result = rb_yield(Qundef);

status = [device closeConnection];

[pool release];

rbt_check_status(status, nil);

return result;
}

VALUE rbt_device_pair(VALUE self) {
PairingDelegate *delegate;
IOBluetoothDevice *device;
IOBluetoothDevicePair *device_pair;
IOReturn status;
NSAutoreleasePool *pool;
char * tmp = NULL;

pool = [[NSAutoreleasePool alloc] init];

Expand All @@ -45,19 +106,15 @@ VALUE rbt_device_pair(VALUE self) {

status = [device_pair start];

if (status != kIOReturnSuccess) {
[pool release];
return Qfalse;
}
rbt_check_status(status, pool);

CFRunLoopRun();

[pool release];

status = (IOReturn)NUM2INT(rb_iv_get(self, "@pair_error"));

if (status != kIOReturnSuccess)
return Qfalse;
rbt_check_status(status, nil);

return Qtrue;
}
Expand All @@ -74,8 +131,7 @@ VALUE rbt_device_request_name(VALUE self) {

status = [device remoteNameRequest: nil];

if (status != kIOReturnSuccess)
return Qnil;
rbt_check_status(status, pool);

name = rb_str_new2([[device name] UTF8String]);

Expand All @@ -84,6 +140,41 @@ VALUE rbt_device_request_name(VALUE self) {
return name;
}

VALUE rbt_device_rssi(VALUE self) {
HCIDelegate *delegate;
IOBluetoothDevice *device;
IOBluetoothHostController *controller;
IOReturn status;
NSAutoreleasePool *pool;

pool = [[NSAutoreleasePool alloc] init];

device = rbt_device_get(self);

delegate = [[HCIDelegate alloc] init];
delegate.device = self;

controller = [IOBluetoothHostController defaultController];
[controller setDelegate: delegate];

status = [controller readRSSIForDevice: device];

if (status != noErr) {
[pool release];
return Qfalse;
}

CFRunLoopRun();

[pool release];

status = (IOReturn)NUM2INT(rb_iv_get(self, "@rssi_error"));

rbt_check_status(status, nil);

return rb_iv_get(self, "@rssi");
}

@implementation PairingDelegate

- (VALUE) device {
Expand Down
Loading

0 comments on commit 15ad551

Please sign in to comment.