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

fixed typos #2

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/gradle.xml

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

17 changes: 14 additions & 3 deletions .idea/misc.xml

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

1 change: 1 addition & 0 deletions .idea/modules.xml

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

2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ dependencies {
implementation 'com.google.android.gms:play-services-location:10.0.1'
implementation 'android.arch.lifecycle:extensions:1.0.0'
implementation project(':blewrapper')
implementation files('libs/d2xx.jar')
// implementation files('libs/d2xx.jar')
}
6 changes: 2 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
android:theme="@style/AppTheme">

<activity
android:name=".FragmentLayout"
android:name=".BLEActivity"
android:label="@string/title_activity_main"
android:launchMode="singleTask"
android:configChanges="keyboardHidden|orientation|screenSize"
Expand All @@ -36,8 +36,6 @@
<service
android:name="aqua.blewrapper.service.BLEService"
android:enabled="true" />
<service
android:name="aqua.blewrapper.monitor_test.MBLEService"
android:enabled="true" />

</application>
</manifest>
62 changes: 38 additions & 24 deletions app/src/main/java/aqua30/blewrapper/BLEActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,13 @@
import static aqua.blewrapper.helper.BluetoothController.log;

/**
* Created by Saurabh on 27-12-2017.
* Created by Derouiche elyes on 27-12-2017.
*/
public class BLEActivity extends AppCompatActivity implements EasyPermissions.PermissionCallbacks,
BluetoothViewContract.ConnectionStateCallbacks, BluetoothViewContract.CommunicationCallbacks, BluetoothViewContract.ConnectedDeviceStateCallbacks {
public class BLEActivity extends AppCompatActivity implements
EasyPermissions.PermissionCallbacks,
BluetoothViewContract.ConnectionStateCallbacks,
BluetoothViewContract.CommunicationCallbacks,
BluetoothViewContract.ConnectedDeviceStateCallbacks {

/* Views */
private TextView dataView;
Expand All @@ -53,36 +56,41 @@ public class BLEActivity extends AppCompatActivity implements EasyPermissions.Pe
public static final String mode = "mode";
/* variables */
private StringBuilder dataBuilder;
// private String connectedDeviceName, connectedDeviceAddress;
private String selectedMode;
// private String connectedDeviceName, connectedDeviceAddress;
private String selectedMode = BLE;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
protected void onCreate(@Nullable Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.ac_test);
dataBuilder = new StringBuilder();
dataView = findViewById(R.id.input_text);
button_bleMode = findViewById(R.id.bleMode);
button_manualMode = findViewById(R.id.manualMode);
/* getting any presaved or pre connected device name and address
* This details are automatically saved by the wrapper */
selectedMode = PreferenceClass.getInstance(this).getString(mode, Manual);
/* only for demo */
setMode();

// button_bleMode = findViewById(R.id.bleMode);
// button_manualMode = findViewById(R.id.manualMode);



/* required for ble wrapper */
buildGoogleApiClient();
/* ble wrapper main object via which we'll do all the operations */
bluetoothManager = new BluetoothController(this);
bluetoothManager.setGoogleApiClient(mGoogleApiClient);
/* set this if you want to receive the callbacks related to bluetooth permission, gps state for
* device > M, bluetooth on device is connected or not*/
* device > M, bluetooth on device is connected or not*/
bluetoothManager.setConnectionCallbacks(this);
/* set this callback if you want to received the data from BLE device */
bluetoothManager.setDataCallbacks(this);
/* set this callback if you want to know device is connected or disconnected during runtime */
bluetoothManager.setConnectedDeviceStateCallbacks(this);
/* it checks all the required permission for Bluetooth activation */
bluetoothManager.checkBluetoothRequirements();


bluetoothManager.sendData();


}

private void setMode() {
Expand Down Expand Up @@ -115,7 +123,7 @@ public void onDeviceSelected(BluetoothDevice device) {
public void Connect(View view) {
selectedMode = BLE;
PreferenceClass.getEditor(this).putString(mode, selectedMode).apply();
setMode();
//setMode();
if (!bluetoothManager.getSavedDevice().getDeviceAddress().isEmpty()) {
setDataOnScreen("Connecting to " + bluetoothManager.getSavedDevice().getDeviceName() + "...");
bluetoothManager.connectToDevice(bluetoothManager.getSavedDevice().getDeviceAddress());
Expand All @@ -129,10 +137,11 @@ public void Disconnect(View view) {
selectedMode = Manual;
PreferenceClass.getEditor(this).putString(mode, selectedMode).apply();
setMode();
if (!bluetoothManager.getSavedDevice().getDeviceAddress().isEmpty()){
setDataOnScreen("Manual mode activated. Disconnected "+
if (!bluetoothManager.getSavedDevice().getDeviceAddress().isEmpty()) {
setDataOnScreen("Manual mode activated. Disconnected " +
bluetoothManager.getSavedDevice().getDeviceAddress());
}

bluetoothManager.disconnect();
}

Expand All @@ -150,7 +159,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {

@SuppressLint("LongLogTag")
protected synchronized void buildGoogleApiClient() {
log( "Building GoogleApiClient");
log("Building GoogleApiClient");
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(LocationServices.API)
.build();
Expand Down Expand Up @@ -184,7 +193,8 @@ public void onStop() {
}

@Override
public void onPermissionsGranted(int requestCode, List<String> perms) {}
public void onPermissionsGranted(int requestCode, List<String> perms) {
}

@Override
public void onPermissionsDenied(int requestCode, List<String> perms) {
Expand Down Expand Up @@ -214,8 +224,8 @@ public void afterPermissionGranted() {
} else {
bluetoothManager.checkLocationRequirements();
}
}catch (Exception e) {
Log.e("scan permission error","error: "+e.getMessage());
} catch (Exception e) {
Log.e("scan permission error", "error: " + e.getMessage());
}
}

Expand Down Expand Up @@ -286,6 +296,7 @@ public void onDataReceived(String data) {
setDataOnScreen("Data received: " + temp);
}


@Override
public void connectedDeviceState(int connectedDeviceState) {
switch (connectedDeviceState) {
Expand All @@ -307,6 +318,7 @@ public void connectedDeviceState(int connectedDeviceState) {
/* Checking once the BLE is connected that*/
private void checkPreviousState() {
if (selectedMode.equals(BLE)) {
System.out.println("----------------------------------------- WHAT KIND OF @ IS THIS : " + bluetoothManager.getSavedDevice().getDeviceAddress());
if (!bluetoothManager.getSavedDevice().getDeviceAddress().isEmpty()) {
setDataOnScreen("Last saved device " + bluetoothManager.getSavedDevice().getDeviceName());
bluetoothManager.setDiscoveryCallbacks(new BluetoothViewContract.DiscoveryCallbacks() {
Expand Down Expand Up @@ -342,12 +354,12 @@ private void setDataOnScreen(String message) {
}
}

private String getTemperature(String message){
message = message.replace(" ","").trim();
private String getTemperature(String message) {
message = message.replace(" ", "").trim();
final int msgLength = message.length();
message = message.substring(0, 12) + "0" + message.substring(13, msgLength);
ArrayList<Integer> byteArray = hexStringToByteArray(message, message.length());
return String.valueOf(toInt16_Temp(new int[] {byteArray.get(6), byteArray.get(7)}, 0) * 0.0625);
return String.valueOf(toInt16_Temp(new int[]{byteArray.get(6), byteArray.get(7)}, 0) * 0.0625);
}

public static double toInt16_Temp(int[] bytes, int index) {
Expand Down Expand Up @@ -389,4 +401,6 @@ public static ArrayList<Integer> hexStringToByteArray(String s, int len) {
}
return d;
}


}
13 changes: 13 additions & 0 deletions app/src/main/java/aqua30/blewrapper/util/ByteUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package aqua30.blewrapper.util;

public class ByteUtils {

public static byte[] reverse(byte[] value) {
int length = value.length;
byte[] reversed = new byte[length];
for (int i = 0; i < length; i++) {
reversed[i] = value[length - (i + 1)];
}
return reversed;
}
}
21 changes: 21 additions & 0 deletions app/src/main/java/aqua30/blewrapper/util/Constants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package aqua30.blewrapper.util;

import java.util.UUID;

public class Constants {

public static String SERVICE_STRING = "7D2EA28A-F7BD-485A-BD9D-92AD6ECFE93E";
public static UUID SERVICE_UUID = UUID.fromString(SERVICE_STRING);

public static String CHARACTERISTIC_ECHO_STRING = "7D2EBAAD-F7BD-485A-BD9D-92AD6ECFE93E";
public static UUID CHARACTERISTIC_ECHO_UUID = UUID.fromString(CHARACTERISTIC_ECHO_STRING);

public static String CHARACTERISTIC_TIME_STRING = "7D2EDEAD-F7BD-485A-BD9D-92AD6ECFE93E";
public static UUID CHARACTERISTIC_TIME_UUID = UUID.fromString(CHARACTERISTIC_TIME_STRING);
public static String CLIENT_CONFIGURATION_DESCRIPTOR_STRING = "00002902-0000-1000-8000-00805f9b34fb";
public static UUID CLIENT_CONFIGURATION_DESCRIPTOR_UUID = UUID.fromString(CLIENT_CONFIGURATION_DESCRIPTOR_STRING);

public static final String CLIENT_CONFIGURATION_DESCRIPTOR_SHORT_ID = "2902";

public static final long SCAN_PERIOD = 5000;
}
63 changes: 63 additions & 0 deletions app/src/main/java/aqua30/blewrapper/util/StringUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package aqua30.blewrapper.util;

import android.support.annotation.Nullable;
import android.util.Log;

import java.io.UnsupportedEncodingException;

/**
* This class is meant to be a replacement for TextUtils to allow unit testing
* of files that may want to use common TextUtils methods.
*/
public class StringUtils {

private static final String TAG = "StringUtils";

private static String byteToHex(byte b) {
char char1 = Character.forDigit((b & 0xF0) >> 4, 16);
char char2 = Character.forDigit((b & 0x0F), 16);

return String.format("0x%1$s%2$s", char1, char2);
}

public static String byteArrayInHexFormat(byte[] byteArray) {
if (byteArray == null) {
return null;
}

StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("{ ");
for (int i = 0; i < byteArray.length; i++) {
if (i > 0) {
stringBuilder.append(", ");
}
String hexString = byteToHex(byteArray[i]);
stringBuilder.append(hexString);
}
stringBuilder.append(" }");

return stringBuilder.toString();
}

public static byte[] bytesFromString(String string) {
byte[] stringBytes = new byte[0];
try {
stringBytes = string.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
Log.e(TAG, "Failed to convert message string to byte array");
}

return stringBytes;
}

@Nullable
public static String stringFromBytes(byte[] bytes) {
String byteString = null;
try {
byteString = new String(bytes, "UTF-8");
} catch (UnsupportedEncodingException e) {
Log.e(TAG, "Unable to convert message bytes to string");
}
return byteString;
}
}
9 changes: 5 additions & 4 deletions app/src/main/res/layout/ac_test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,19 @@
android:layout_height="match_parent"
android:layout_weight="1"
android:onClick="Connect"
android:text="BLE Mode"
android:text="Click 2 CONNECT"
android:textSize="16sp" />

<Button
android:id="@+id/manualMode"
android:id="@+id/bleSend"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:onClick="Disconnect"
android:text="Manual Mode"
android:onClick="SendData"
android:text="SEND SHIT"
android:textSize="16sp" />


<Button
android:id="@+id/clear"
android:layout_width="match_parent"
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<resources>
<string name="app_name">FTDI</string>
<string name="app_name">BLEDEMO</string>
<string name="setting">Settings</string>
<string name="ok">OK</string>
<string name="cancel">Cancel</string>
Expand All @@ -8,9 +8,9 @@
<string name="unknown_characteristic">Unknown characteristic</string>
<string name="unknown_service">Unknown service</string>

<string name="title_activity_main">FTDI D2xx Demo</string>
<string name="title_activity_ftdi_mode_fragment">Ftdi Mode Info</string>
<string name="title_activity_ftdi_mode_control">Ftdi Mode Control</string>
<string name="title_activity_main">BLE Demo</string>
<string name="title_activity_ftdi_mode_fragment">BLE Mode Info</string>
<string name="title_activity_ftdi_mode_control">BLE Mode Control</string>
<string name="button_info">Information</string>
<string name="button_configure">Device Configure</string>
<string name="button_eeprom">Device EEPROM API</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ public interface BluetoothManager<T> {
void setGoogleApiClient(GoogleApiClient googleApiClient);
void retryConnection();
Device getSavedDevice();

void sendData();
}
Loading