Skip to content

Commit

Permalink
add bluetooth support
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielHindi committed Feb 1, 2016
1 parent aca604d commit e466a83
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
6 changes: 5 additions & 1 deletion scripts/buildfire.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,11 @@ var buildfire = {
, "auth.triggerOnLogout"
, "logger.showHistory"
, "logger.attachRemoteLogger"
, "appearance.triggerOnUpdate"]
, "appearance.triggerOnUpdate"
, "services.bluetooth.ble.onConnect"
, "services.bluetooth.ble.onDisconnect"
, "services.bluetooth.ble._onSubscribeData"
]
, _postMessageHandler: function (e) {
if (e.source === window) {
console.log(' >>>> IGNORE MESSAGE <<<< ');
Expand Down
54 changes: 54 additions & 0 deletions scripts/buildfire/services/bluetooth/ble.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* Created by danielhindi on 1/30/16.
*/

if (typeof (buildfire) == "undefined") throw ("please add buildfire.js first to use BuildFire services");

if (typeof (buildfire.services) == "undefined") buildfire.services = {};

if (typeof (buildfire.services.bluetooth) == "undefined") buildfire.services.bluetooth = {};


buildfire.services.bluetooth.ble = {

onConnect:function(){},
onDisconnect:function(){},
connect: function (deviceId, callback) {
buildfire._sendPacket(new Packet(null,"bluetooth.connect",{deviceId:deviceId}),callback);
},
disconnect: function (callback) {
buildfire._sendPacket(new Packet(null,"bluetooth.disconnect"),callback);
},
listPairedDevices:function(callback){
buildfire._sendPacket(new Packet(null,"bluetooth.listPairedDevices"),callback);
},
write: function (data, callback) {
buildfire._sendPacket(new Packet(null,"bluetooth.write",{data:data}),callback);
},
available: function (callback) {
buildfire._sendPacket(new Packet(null,"bluetooth.available",{deviceId:deviceId}),callback);
},
read: function (callback) {
buildfire._sendPacket(new Packet(null,"bluetooth.read"),callback);
},
readUntil: function (terminator,callback) {
buildfire._sendPacket(new Packet(null,"bluetooth.readUntil",{terminator:terminator}),callback);
},
_onSubscribeData: null,
subscribe: function (delimiter,callback) {
this._onSubscribeData = callback;
buildfire._sendPacket(new Packet(null,"bluetooth.subscribe",{delimiter:delimiter}));
},
unsubscribe: function (callback) {
buildfire._sendPacket(new Packet(null,"bluetooth.unsubscribe"),callback);
},
clear: function (callback) {
buildfire._sendPacket(new Packet(null,"bluetooth.clear"),callback);
},
isConnected: function (callback) {
buildfire._sendPacket(new Packet(null,"bluetooth.isConnected"),callback);
},
isEnabled: function (callback) {
buildfire._sendPacket(new Packet(null,"bluetooth.isEnabled"),callback);
}
};

0 comments on commit e466a83

Please sign in to comment.