Skip to content

Commit

Permalink
Fixed bluetooth
Browse files Browse the repository at this point in the history
Signed-off-by: Brandyn A. White <[email protected]>
  • Loading branch information
Brandyn A. White committed Mar 23, 2014
1 parent 12fb850 commit cce2215
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
4 changes: 2 additions & 2 deletions WearScript/src/main/assets/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -906,10 +906,10 @@ function WearScript() {
}
this.bluetoothRead = function (address, callback) {
callback = this._funcfix(callback);
WSRAW.bluetoothRead(address, this._funcwrap(callback));
WSRAW.bluetoothRead(address, this._funcwrap(function (x) {callback(atob(x))}));
}
this.bluetoothWrite = function (address, data) {
WSRAW.bluetoothWrite(address, data);
WSRAW.bluetoothWrite(address, btoa(data));
}
}
WS = new WearScript();
2 changes: 1 addition & 1 deletion WearScript/src/main/assets/init.js.min
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ function(a){WSRAW.log(a)};this.displayWebView=function(){WSRAW.displayWebView()}
"";WSRAW.warpPreviewSampleGlass(a)};this.displayCardTree=function(){WSRAW.displayCardTree()};this.cardTree=function(a){WSRAW.cardTree(JSON.stringify(a.cards))};this.cameraOn=function(a,e,g,k){e||(e=0);g||(maxwidth=0);k?(k=this._funcfix(k),WSRAW.cameraOn(a,e,g,!1,this._funcwrap(k))):WSRAW.cameraOn(a,e,g,!1)};this.cameraPhoto=function(a){a?(a=this._funcfix(a),WSRAW.cameraPhoto(this._funcwrap(a))):WSRAW.cameraPhoto()};this.cameraPhotoData=function(a){a?(a=this._funcfix(a),WSRAW.cameraPhotoData(this._funcwrap(a))):
WSRAW.cameraPhoto()};this.cameraVideo=function(a){a?(a=this._funcfix(a),WSRAW.cameraVideo(this._funcwrap(a))):WSRAW.cameraVideo()};this.cameraOff=function(){WSRAW.cameraOff()};this.activityCreate=function(){WSRAW.activityCreate()};this.activityDestroy=function(){WSRAW.activityDestroy()};this.wifiOn=function(a){a=this._funcfix(a);WSRAW.wifiOn(this._funcwrap(a))};this.wifiOff=function(){WSRAW.wifiOff()};this.wifiScan=function(){WSRAW.wifiScan()};this.serverConnect=function(a,e){e=this._funcfix(e);WSRAW.serverConnect(a,
this._funcwrap(e))};this.wake=function(){WSRAW.wake()};this.sound=function(a){WSRAW.sound(a)};this.gestureCallback=function(a,e){e=this._funcfix(e);WSRAW.gestureCallback(a,this._funcwrap(e))};this.speechRecognize=function(a,e){e=this._funcfix(e);WSRAW.speechRecognize(a,this._funcwrap(function(a){e(atob(a))}))};this.liveCardCreate=function(a,e){WSRAW.liveCardCreate(a,e)};this.liveCardDestroy=function(){WSRAW.liveCardDestroy()};this.bluetoothList=function(a){a=this._funcfix(a);WSRAW.bluetoothList(this._funcwrap(function(e){a(JSON.parse(e))}))};
this.bluetoothRead=function(a,e){e=this._funcfix(e);WSRAW.bluetoothRead(a,this._funcwrap(e))};this.bluetoothWrite=function(a,e){WSRAW.bluetoothWrite(a,e)}}WS=new WearScript;
this.bluetoothRead=function(a,e){e=this._funcfix(e);WSRAW.bluetoothRead(a,this._funcwrap(function(a){e(atob(a))}))};this.bluetoothWrite=function(a,e){WSRAW.bluetoothWrite(a,btoa(e))}}WS=new WearScript;
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.bluetooth.BluetoothSocket;
import android.os.AsyncTask;
import android.os.ParcelUuid;
import android.util.Base64;

import com.dappervision.wearscript.BackgroundService;
import com.dappervision.wearscript.Log;
Expand Down Expand Up @@ -41,9 +42,18 @@ private class BluetoothReadTask extends AsyncTask<String, Void, Void> {
protected Void doInBackground(String... addresses) {
String address = addresses[0];
String read = READ + address;
byte data[] = new byte[1];
while (true) {
if (!mSockets.containsKey(address)) {
try {
Thread.sleep(250);
} catch (InterruptedException e) {
// TODO(brandyn): Handle
}
}
try {
makeCall(read, "'" + (char) mSockets.get(address).getInputStream().read() + "'");
data[0] = (byte)mSockets.get(address).getInputStream().read();
makeCall(read, "'" + Base64.encodeToString(data, Base64.NO_WRAP) + "'");
} catch (IOException e) {
Log.w(TAG, "Could not read");
closeDevice(address);
Expand Down Expand Up @@ -155,7 +165,7 @@ public void onEventBackgroundThread(BluetoothWriteEvent e) {
}
Log.d(TAG, "Size:" + mSockets.size());
try {
mSockets.get(e.getAddress()).getOutputStream().write(e.getBuffer());
mSockets.get(e.getAddress()).getOutputStream().write(Base64.decode(e.getBuffer(), Base64.NO_WRAP));
} catch (IOException e1) {
closeDevice(e.getAddress());
Log.e(TAG, "Cannot write");
Expand Down

0 comments on commit cce2215

Please sign in to comment.