Skip to content

Commit cce2215

Browse files
author
Brandyn A. White
committed
Fixed bluetooth
Signed-off-by: Brandyn A. White <[email protected]>
1 parent 12fb850 commit cce2215

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

WearScript/src/main/assets/init.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -906,10 +906,10 @@ function WearScript() {
906906
}
907907
this.bluetoothRead = function (address, callback) {
908908
callback = this._funcfix(callback);
909-
WSRAW.bluetoothRead(address, this._funcwrap(callback));
909+
WSRAW.bluetoothRead(address, this._funcwrap(function (x) {callback(atob(x))}));
910910
}
911911
this.bluetoothWrite = function (address, data) {
912-
WSRAW.bluetoothWrite(address, data);
912+
WSRAW.bluetoothWrite(address, btoa(data));
913913
}
914914
}
915915
WS = new WearScript();

WearScript/src/main/assets/init.js.min

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ function(a){WSRAW.log(a)};this.displayWebView=function(){WSRAW.displayWebView()}
2121
"";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))):
2222
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,
2323
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))}))};
24-
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;
24+
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;

WearScript/src/main/java/com/dappervision/wearscript/managers/BluetoothManager.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import android.bluetooth.BluetoothSocket;
66
import android.os.AsyncTask;
77
import android.os.ParcelUuid;
8+
import android.util.Base64;
89

910
import com.dappervision.wearscript.BackgroundService;
1011
import com.dappervision.wearscript.Log;
@@ -41,9 +42,18 @@ private class BluetoothReadTask extends AsyncTask<String, Void, Void> {
4142
protected Void doInBackground(String... addresses) {
4243
String address = addresses[0];
4344
String read = READ + address;
45+
byte data[] = new byte[1];
4446
while (true) {
47+
if (!mSockets.containsKey(address)) {
48+
try {
49+
Thread.sleep(250);
50+
} catch (InterruptedException e) {
51+
// TODO(brandyn): Handle
52+
}
53+
}
4554
try {
46-
makeCall(read, "'" + (char) mSockets.get(address).getInputStream().read() + "'");
55+
data[0] = (byte)mSockets.get(address).getInputStream().read();
56+
makeCall(read, "'" + Base64.encodeToString(data, Base64.NO_WRAP) + "'");
4757
} catch (IOException e) {
4858
Log.w(TAG, "Could not read");
4959
closeDevice(address);
@@ -155,7 +165,7 @@ public void onEventBackgroundThread(BluetoothWriteEvent e) {
155165
}
156166
Log.d(TAG, "Size:" + mSockets.size());
157167
try {
158-
mSockets.get(e.getAddress()).getOutputStream().write(e.getBuffer());
168+
mSockets.get(e.getAddress()).getOutputStream().write(Base64.decode(e.getBuffer(), Base64.NO_WRAP));
159169
} catch (IOException e1) {
160170
closeDevice(e.getAddress());
161171
Log.e(TAG, "Cannot write");

0 commit comments

Comments
 (0)