Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gatt - enable service changed characteristic #128

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
15 changes: 12 additions & 3 deletions examples/pizza/peripheral.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var PizzaService = require('./pizza-service');
//
var name = 'PizzaSquat';
var pizzaService = new PizzaService(new pizza.Pizza());
var pizzaService2 = new PizzaService(new pizza.Pizza());

//
// Wait until the BLE radio powers on before attempting to advertise.
Expand Down Expand Up @@ -53,8 +54,16 @@ bleno.on('advertisingStart', function(err) {
// Once we are advertising, it's time to set up our services,
// along with our characteristics.
//
bleno.setServices([
pizzaService
]);
bleno.setServices([ pizzaService ], function (){
var flip = false;
setInterval(function (){
if(flip){
bleno.removeService(pizzaService2);
} else {
bleno.addService(pizzaService2);
}
flip = !flip;
}, 1500);
});
}
});
25 changes: 25 additions & 0 deletions lib/bleno.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,35 @@ Bleno.prototype.onAdvertisingStop = function() {
this.emit('advertisingStop');
};

Bleno.prototype.addService = function(service, callback) {
if(callback){
this.once('servicesChanged', callback);
}

this._bindings.addService(service);
};

Bleno.prototype.removeAllServices = function(callback) {
if(callback){
this.once('removedAllServices', callback);
}

this._bindings.removeAllServices();
}

Bleno.prototype.removeService = function(service, callback) {
if(callback){
this.once('removedService', callback);
}

this._bindings.removeService(service);
};

Bleno.prototype.setServices = function(services, callback) {
if (callback) {
this.once('servicesSet', callback);
}

this._bindings.setServices(services);
};

Expand Down
20 changes: 19 additions & 1 deletion lib/hci-socket/bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,25 @@ BlenoBindings.prototype.stopAdvertising = function() {
this._gap.stopAdvertising();
};

BlenoBindings.prototype.setServices = function(services) {
BlenoBindings.prototype.addService = function(service) {
this._gatt.addService(service);

this.emit('servicesChanged');
};

BlenoBindings.prototype.removeAllServices = function() {
this._gatt.removeAllServices();

this.emit('removedAllServices');
}

BlenoBindings.prototype.removeService = function(service){
this._gatt.removeService(service);

this.emit('removedService');
}

BlenoBindings.prototype.setServices = function(services, deviceName) {
this._gatt.setServices(services);

this.emit('servicesSet');
Expand Down
Loading