Skip to content

Commit

Permalink
Merge pull request #1 from GedaliaR/master
Browse files Browse the repository at this point in the history
1. A method or two to read data from the Arduino. This makes debugging from the Arduino side easier.

2. A simple way to connect with paired devices. The method that establishes the connection with the Bluetooth device assumes that it is not yet paired (and if it is already paired the user would have to forget that device and re-pair with it).
  • Loading branch information
giuseppebrb authored May 14, 2020
2 parents 577190b + 6ca5eb7 commit 5e2559f
Show file tree
Hide file tree
Showing 10 changed files with 365 additions and 57 deletions.
116 changes: 116 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 18 additions & 16 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 8 additions & 7 deletions ardutooth/build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
compileSdkVersion 29
buildToolsVersion '29.0.2'
defaultConfig {
minSdkVersion 14
targetSdkVersion 25
targetSdkVersion 29
versionCode 2
versionName "2.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
Expand All @@ -19,10 +19,11 @@ android {
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
api fileTree(dir: 'libs', include: ['*.jar'])
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
testCompile 'junit:junit:4.12'
//noinspection GradleCompatible
api 'com.android.support:appcompat-v7:25.3.1'
testImplementation 'junit:junit:4.13'
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@
import android.app.Activity;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.util.Log;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.UUID;

/**
* This singleton class represents the main component of the library.
* It can be used to easily set a stable connection with an Arduino and to send data to it using the Serial Monitor.
* It can be used to easily set a stable connection with an Arduino and to send/receive data to/from it using the Serial Monitor.
*
* <p>The first thing you need is to create or get an instance of {@link Ardutooth} using something like
* {@code Ardutooth mArdutooth = Ardutooth.getInstance(this)} where parameter represents the instance of
Expand Down Expand Up @@ -65,7 +70,7 @@ public boolean isConnected() {
} catch (Exception e) {
Log.d(Ardutooth.TAG, "An error occurred while retrieving connection", e);
}
return mBtHandler.connected;
return BluetoothHandler.connected;
}

/**
Expand Down Expand Up @@ -206,4 +211,38 @@ public void sendBoolean(boolean value) {
e.printStackTrace();
}
}

/**
* Reads a single character, as defined by {@link BufferedReader}'s readLine method,
* from the Arduino, casts it into a {@link char}, and returns it.
*
* @return char value read
*/
public char receiveChar(){
char c = 0;
if (mBtHandler.getSocket() != null)
try {
c = (char) mBtHandler.getInputReader().read();
} catch (IOException e) {
e.printStackTrace();
}
return c;
}

/**
* Reads a line, as defined by {@link BufferedReader}'s readLine method, from the Arduino.
*
* @return {@link String} line read
*/
public String receiveLine(){
String result = "";
if (mBtHandler.getSocket() != null)
try {
result = mBtHandler.getInputReader().readLine();
} catch (IOException ex) {
ex.printStackTrace();
}
return result;
}

}
Loading

0 comments on commit 5e2559f

Please sign in to comment.