├── .idea
├── .name
├── copyright
│ └── profiles_settings.xml
├── scopes
│ └── scope_settings.xml
├── encodings.xml
├── vcs.xml
├── inspectionProfiles
│ ├── profiles_settings.xml
│ └── Project_Default.xml
├── modules.xml
├── misc.xml
├── gradle.xml
└── compiler.xml
├── app
├── .gitignore
├── app-release.apk
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── drawable-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_action_network_cell.png
│ │ │ ├── drawable-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_action_network_cell.png
│ │ │ ├── drawable-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_action_network_cell.png
│ │ │ ├── drawable-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_action_network_cell.png
│ │ │ ├── drawable-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── values
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── colors.xml
│ │ │ │ ├── strings.xml
│ │ │ │ └── styles.xml
│ │ │ ├── layout
│ │ │ │ ├── toolbar.xml
│ │ │ │ ├── activity_device_scan.xml
│ │ │ │ ├── activity_uartdisplay.xml
│ │ │ │ └── adapter_scan_result.xml
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ ├── menu
│ │ │ │ ├── menu_device_scan.xml
│ │ │ │ └── menu_uartdisplay.xml
│ │ │ └── values-v21
│ │ │ │ └── styles.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── blazingmammothgames
│ │ │ │ └── tools
│ │ │ │ └── btledatalogger
│ │ │ │ ├── BaseActivity.java
│ │ │ │ ├── DeviceScanResultsAdapter.java
│ │ │ │ ├── LogService.java
│ │ │ │ ├── DeviceScanActivity.java
│ │ │ │ ├── UARTService.java
│ │ │ │ └── UARTDisplayActivity.java
│ │ └── AndroidManifest.xml
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── blazingmammothgames
│ │ └── tools
│ │ └── btledatalogger
│ │ └── ApplicationTest.java
├── build.gradle
├── proguard-rules.pro
├── manifest-merger-release-report.txt
└── app.iml
├── settings.gradle
├── bt.png
├── icon.png
├── feature.png
├── feature.psd
├── .gitignore
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitattributes
├── README.md
├── BTLEDataLogger.iml
├── gradle.properties
├── LICENSE
├── gradlew.bat
└── gradlew
/.idea/.name:
--------------------------------------------------------------------------------
1 | BTLEDataLogger
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/bt.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hamaluik/BTLEDataLogger/master/bt.png
--------------------------------------------------------------------------------
/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hamaluik/BTLEDataLogger/master/icon.png
--------------------------------------------------------------------------------
/feature.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hamaluik/BTLEDataLogger/master/feature.png
--------------------------------------------------------------------------------
/feature.psd:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hamaluik/BTLEDataLogger/master/feature.psd
--------------------------------------------------------------------------------
/app/app-release.apk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hamaluik/BTLEDataLogger/master/app/app-release.apk
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | /local.properties
3 | /.idea/workspace.xml
4 | /.idea/libraries
5 | .DS_Store
6 | /build
7 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hamaluik/BTLEDataLogger/master/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hamaluik/BTLEDataLogger/master/app/src/main/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hamaluik/BTLEDataLogger/master/app/src/main/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hamaluik/BTLEDataLogger/master/app/src/main/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hamaluik/BTLEDataLogger/master/app/src/main/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hamaluik/BTLEDataLogger/master/app/src/main/res/drawable-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_action_network_cell.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hamaluik/BTLEDataLogger/master/app/src/main/res/drawable-hdpi/ic_action_network_cell.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_action_network_cell.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hamaluik/BTLEDataLogger/master/app/src/main/res/drawable-mdpi/ic_action_network_cell.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_action_network_cell.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hamaluik/BTLEDataLogger/master/app/src/main/res/drawable-xhdpi/ic_action_network_cell.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_action_network_cell.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hamaluik/BTLEDataLogger/master/app/src/main/res/drawable-xxhdpi/ic_action_network_cell.png
--------------------------------------------------------------------------------
/.idea/scopes/scope_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Apr 10 15:27:10 PDT 2013
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
7 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/toolbar.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_device_scan.xml:
--------------------------------------------------------------------------------
1 |
7 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 |
7 | # Standard to msysgit
8 | *.doc diff=astextplain
9 | *.DOC diff=astextplain
10 | *.docx diff=astextplain
11 | *.DOCX diff=astextplain
12 | *.dot diff=astextplain
13 | *.DOT diff=astextplain
14 | *.pdf diff=astextplain
15 | *.PDF diff=astextplain
16 | *.rtf diff=astextplain
17 | *.RTF diff=astextplain
18 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_uartdisplay.xml:
--------------------------------------------------------------------------------
1 |
8 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # BTLEDataLogger
2 |
3 | This is a simple android app for connecting to and logging data sent over Bluetooth Low Energy serial using [Adafruit's BTLE nRF8001 Breakout](https://www.adafruit.com/product/1697). So far only source code for the iOS BTLE app has been published, and none of the apps offer a convenient method for logging data. This is therefore both a sample app for learning how to write your own BTLE apps as well as a tool for performing simple BTLE logging using an Arduino-like device.
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/blazingmammothgames/tools/btledatalogger/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.blazingmammothgames.tools.btledatalogger;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | @color/material_blue_grey_800
4 | @color/material_blue_grey_900
5 |
6 | @color/material_deep_teal_200
7 | @color/material_deep_teal_500
8 |
9 | #333333
10 | #80000000
11 |
--------------------------------------------------------------------------------
/app/src/main/res/values-v21/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
10 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 21
5 | buildToolsVersion "21.1.2"
6 |
7 | defaultConfig {
8 | applicationId "com.blazingmammothgames.tools.btledatalogger"
9 | minSdkVersion 18
10 | targetSdkVersion 21
11 | versionCode 2
12 | versionName "1.0.1"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | compile 'com.android.support:appcompat-v7:22.0.0'
25 | }
26 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in C:\Users\mfplab\AppData\Local\Android\sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/BTLEDataLogger.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | BTLE Data Logger
5 | Settings
6 | Scan for Devices
7 | Scanning...
8 | Connect
9 | BTLE Log
10 | File name:
11 | btle_log.csv
12 | UART Log:
13 | Status:
14 | Start Logging
15 | Stop Logging
16 | Signal strength icon
17 | UART Devices
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/java/com/blazingmammothgames/tools/btledatalogger/BaseActivity.java:
--------------------------------------------------------------------------------
1 | package com.blazingmammothgames.tools.btledatalogger;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.ActionBarActivity;
5 | import android.support.v7.widget.Toolbar;
6 |
7 | public abstract class BaseActivity extends ActionBarActivity {
8 |
9 | private Toolbar toolbar;
10 |
11 | @Override
12 | protected void onCreate(Bundle savedInstanceState) {
13 | super.onCreate(savedInstanceState);
14 | setContentView(getLayoutResource());
15 | toolbar = (Toolbar) findViewById(R.id.toolbar);
16 | if (toolbar != null) {
17 | setSupportActionBar(toolbar);
18 | getSupportActionBar().setDisplayHomeAsUpEnabled(true);
19 | }
20 | }
21 |
22 | protected abstract int getLayoutResource();
23 |
24 | protected void setActionBarIcon(int iconRes) {
25 | toolbar.setNavigationIcon(iconRes);
26 | }
27 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_device_scan.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
15 |
16 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
12 |
13 |
17 |
18 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 Kenton Hamaluik
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
8 |
9 |
10 |
11 |
12 |
13 |
18 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
31 |
34 |
35 |
36 |
40 |
41 |
45 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/app/src/main/java/com/blazingmammothgames/tools/btledatalogger/DeviceScanResultsAdapter.java:
--------------------------------------------------------------------------------
1 | package com.blazingmammothgames.tools.btledatalogger;
2 |
3 | import android.bluetooth.BluetoothDevice;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.util.Log;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 | import android.widget.BaseAdapter;
11 | import android.widget.Button;
12 | import android.widget.TextView;
13 |
14 | /**
15 | * Created by mfplab on 08/04/2015.
16 | */
17 | public class DeviceScanResultsAdapter extends BaseAdapter {
18 | // tag for logging
19 | private final static String TAG = UARTService.class.getSimpleName();
20 |
21 | private DeviceScanActivity hostActivity;
22 |
23 | public DeviceScanResultsAdapter(DeviceScanActivity hostActivity) {
24 | this.hostActivity = hostActivity;
25 | }
26 |
27 | @Override
28 | public int getCount() {
29 | return hostActivity.bluetoothDevices.size();
30 | }
31 |
32 | @Override
33 | public Object getItem(int i) {
34 | return hostActivity.bluetoothDevices.get(i);
35 | }
36 |
37 | @Override
38 | public long getItemId(int i) {
39 | return i;
40 | }
41 |
42 | @Override
43 | public View getView(int row, View view, ViewGroup group) {
44 | if(view == null) {
45 | LayoutInflater inflater = (LayoutInflater)hostActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
46 | view = inflater.inflate(R.layout.adapter_scan_result, group, false);
47 | }
48 |
49 | TextView rssiIndicator = (TextView)view.findViewById(R.id.rssiIndicator);
50 | TextView deviceName = (TextView)view.findViewById(R.id.deviceName);
51 | TextView deviceDescription = (TextView)view.findViewById(R.id.deviceDescription);
52 | Button connectButton = (Button)view.findViewById(R.id.connectToDevice);
53 |
54 | final BluetoothDevice device = hostActivity.bluetoothDevices.get(row);
55 | rssiIndicator.setText(hostActivity.deviceRSSIs.get(device).toString());
56 | deviceName.setText(device.getName());
57 | deviceDescription.setText(device.getAddress());
58 |
59 | if(!connectButton.hasOnClickListeners()) {
60 | connectButton.setOnClickListener(new View.OnClickListener() {
61 | public void onClick(View v) {
62 | if(device == null) {
63 | Log.e(TAG, "Device was null!");
64 | return;
65 | }
66 |
67 | // create the intent for the new activity
68 | final Intent intent = new Intent(hostActivity, UARTDisplayActivity.class);
69 | intent.putExtra(UARTDisplayActivity.EXTRAS_DEVICE_NAME, device.getName());
70 | intent.putExtra(UARTDisplayActivity.EXTRAS_DEVICE_ADDRESS, device.getAddress());
71 |
72 | // stop any scanning
73 | if(hostActivity.isScanning()) {
74 | hostActivity.scanBTLEDevices(false);
75 | }
76 |
77 | // start the new activity
78 | hostActivity.startActivity(intent);
79 | }
80 | });
81 | }
82 |
83 | return view;
84 | }
85 |
86 | }
87 |
--------------------------------------------------------------------------------
/app/src/main/java/com/blazingmammothgames/tools/btledatalogger/LogService.java:
--------------------------------------------------------------------------------
1 | package com.blazingmammothgames.tools.btledatalogger;
2 |
3 | import android.app.Service;
4 | import android.content.Intent;
5 | import android.os.Binder;
6 | import android.os.IBinder;
7 | import android.os.Environment;
8 | import android.util.Log;
9 |
10 | import java.io.BufferedWriter;
11 | import java.io.File;
12 | import java.io.FileWriter;
13 | import java.io.PrintWriter;
14 |
15 | public class LogService extends Service {
16 | // tag for logging
17 | private final static String TAG = LogService.class.getSimpleName();
18 |
19 | // binder given to clients
20 | private final IBinder binder = new LocalBinder();
21 |
22 | private boolean logging = false;
23 | public boolean isLogging() {
24 | return logging;
25 | }
26 |
27 | // directory of the public documents folder
28 | private File documentsFolder;
29 | private File logFile;
30 | private PrintWriter printWriter;
31 |
32 | public LogService() {
33 | }
34 |
35 | @Override
36 | public IBinder onBind(Intent intent) {
37 | return binder;
38 | }
39 |
40 | @Override
41 | public boolean onUnbind(Intent intent) {
42 | cleanup();
43 | return super.onUnbind(intent);
44 | }
45 |
46 | public class LocalBinder extends Binder {
47 | LogService getService() {
48 | return LogService.this;
49 | }
50 | }
51 |
52 | public boolean initialize(final String filename) {
53 | cleanup();
54 |
55 | if(!isExternalStorageWritable()) {
56 | Log.e(TAG, "Can't initialize as the external storage is not writeable!");
57 | return false;
58 | }
59 |
60 | // get the documents folder
61 | documentsFolder = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS);
62 | if(!documentsFolder.exists()) {
63 | if(!documentsFolder.mkdirs()) {
64 | Log.e(TAG, "Can't initialize as the documents folder doesn't exist!");
65 | return false;
66 | }
67 | }
68 |
69 | // now create the file
70 | logFile = new File(documentsFolder, filename);
71 | /*if(!logFile.exists() || !logFile.canWrite()) {
72 | Log.e(TAG, "Can't initialize file because it is unwriteable!");
73 | return false;
74 | }*/
75 |
76 | // create a print writer for it
77 | try {
78 | printWriter = new PrintWriter(new BufferedWriter(new FileWriter(logFile, true)));
79 | }
80 | catch(Exception e) {
81 | Log.e(TAG, e.toString());
82 | return false;
83 | }
84 |
85 | logging = true;
86 | return true;
87 | }
88 |
89 | public void cleanup() {
90 | logging = false;
91 | Log.d(TAG, "Cleaning up!");
92 | if(printWriter != null) {
93 | printWriter.close();
94 | }
95 | }
96 |
97 | public void appendToLog(String text) {
98 | if(!logging || printWriter == null) {
99 | return;
100 | }
101 |
102 | printWriter.append(text);
103 | }
104 |
105 | /* Checks if external storage is available for read and write */
106 | public boolean isExternalStorageWritable() {
107 | String state = Environment.getExternalStorageState();
108 | if (Environment.MEDIA_MOUNTED.equals(state)) {
109 | return true;
110 | }
111 | return false;
112 | }
113 | }
114 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_uartdisplay.xml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
14 |
15 |
21 |
22 |
35 |
36 |
37 |
38 |
44 |
45 |
51 |
52 |
59 |
60 |
70 |
71 |
78 |
79 |
86 |
87 |
88 |
89 |
--------------------------------------------------------------------------------
/app/manifest-merger-release-report.txt:
--------------------------------------------------------------------------------
1 | -- Merging decision tree log ---
2 | manifest
3 | ADDED from AndroidManifest.xml:2:1
4 | xmlns:android
5 | ADDED from AndroidManifest.xml:2:11
6 | package
7 | ADDED from AndroidManifest.xml:3:5
8 | INJECTED from AndroidManifest.xml:0:0
9 | INJECTED from AndroidManifest.xml:0:0
10 | android:versionName
11 | INJECTED from AndroidManifest.xml:0:0
12 | INJECTED from AndroidManifest.xml:0:0
13 | android:versionCode
14 | INJECTED from AndroidManifest.xml:0:0
15 | INJECTED from AndroidManifest.xml:0:0
16 | uses-feature#android.hardware.bluetooth_le
17 | ADDED from AndroidManifest.xml:5:5
18 | android:required
19 | ADDED from AndroidManifest.xml:7:9
20 | android:name
21 | ADDED from AndroidManifest.xml:6:9
22 | uses-permission#android.permission.BLUETOOTH
23 | ADDED from AndroidManifest.xml:9:5
24 | android:name
25 | ADDED from AndroidManifest.xml:9:22
26 | uses-permission#android.permission.BLUETOOTH_ADMIN
27 | ADDED from AndroidManifest.xml:10:5
28 | android:name
29 | ADDED from AndroidManifest.xml:10:22
30 | uses-permission#android.permission.WRITE_EXTERNAL_STORAGE
31 | ADDED from AndroidManifest.xml:11:5
32 | android:name
33 | ADDED from AndroidManifest.xml:11:22
34 | application
35 | ADDED from AndroidManifest.xml:13:5
36 | MERGED from com.android.support:appcompat-v7:22.0.0:22:5
37 | MERGED from com.android.support:support-v4:22.0.0:22:5
38 | android:label
39 | ADDED from AndroidManifest.xml:16:9
40 | android:allowBackup
41 | ADDED from AndroidManifest.xml:14:9
42 | android:icon
43 | ADDED from AndroidManifest.xml:15:9
44 | android:theme
45 | ADDED from AndroidManifest.xml:17:9
46 | activity#com.blazingmammothgames.tools.btledatalogger.DeviceScanActivity
47 | ADDED from AndroidManifest.xml:18:9
48 | android:label
49 | ADDED from AndroidManifest.xml:20:13
50 | android:name
51 | ADDED from AndroidManifest.xml:19:13
52 | intent-filter#android.intent.action.MAIN+android.intent.category.LAUNCHER
53 | ADDED from AndroidManifest.xml:21:13
54 | action#android.intent.action.MAIN
55 | ADDED from AndroidManifest.xml:22:17
56 | android:name
57 | ADDED from AndroidManifest.xml:22:25
58 | category#android.intent.category.LAUNCHER
59 | ADDED from AndroidManifest.xml:24:17
60 | android:name
61 | ADDED from AndroidManifest.xml:24:27
62 | activity#com.blazingmammothgames.tools.btledatalogger.UARTDisplayActivity
63 | ADDED from AndroidManifest.xml:27:9
64 | android:label
65 | ADDED from AndroidManifest.xml:29:13
66 | android:parentActivityName
67 | ADDED from AndroidManifest.xml:30:13
68 | android:name
69 | ADDED from AndroidManifest.xml:28:13
70 | meta-data#android.support.PARENT_ACTIVITY
71 | ADDED from AndroidManifest.xml:31:13
72 | android:name
73 | ADDED from AndroidManifest.xml:32:17
74 | android:value
75 | ADDED from AndroidManifest.xml:33:17
76 | service#com.blazingmammothgames.tools.btledatalogger.UARTService
77 | ADDED from AndroidManifest.xml:36:9
78 | android:exported
79 | ADDED from AndroidManifest.xml:39:13
80 | android:enabled
81 | ADDED from AndroidManifest.xml:38:13
82 | android:name
83 | ADDED from AndroidManifest.xml:37:13
84 | service#com.blazingmammothgames.tools.btledatalogger.LogService
85 | ADDED from AndroidManifest.xml:41:9
86 | android:exported
87 | ADDED from AndroidManifest.xml:44:13
88 | android:enabled
89 | ADDED from AndroidManifest.xml:43:13
90 | android:name
91 | ADDED from AndroidManifest.xml:42:13
92 | uses-sdk
93 | INJECTED from AndroidManifest.xml:0:0 reason: use-sdk injection requested
94 | MERGED from com.android.support:appcompat-v7:22.0.0:20:5
95 | MERGED from com.android.support:support-v4:22.0.0:20:5
96 | android:targetSdkVersion
97 | INJECTED from AndroidManifest.xml:0:0
98 | INJECTED from AndroidManifest.xml:0:0
99 | android:minSdkVersion
100 | INJECTED from AndroidManifest.xml:0:0
101 | INJECTED from AndroidManifest.xml:0:0
102 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/adapter_scan_result.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
14 |
19 |
20 |
34 |
35 |
47 |
48 |
49 |
50 |
51 |
54 |
55 |
63 |
64 |
72 |
73 |
76 |
77 |
84 |
85 |
86 |
89 |
90 |
101 |
102 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/app/app.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
--------------------------------------------------------------------------------
/app/src/main/java/com/blazingmammothgames/tools/btledatalogger/DeviceScanActivity.java:
--------------------------------------------------------------------------------
1 | package com.blazingmammothgames.tools.btledatalogger;
2 |
3 | import android.app.Activity;
4 | import android.bluetooth.BluetoothAdapter;
5 | import android.bluetooth.BluetoothDevice;
6 | import android.bluetooth.BluetoothManager;
7 | import android.bluetooth.le.ScanCallback;
8 | import android.bluetooth.le.ScanFilter;
9 | import android.bluetooth.le.ScanResult;
10 | import android.bluetooth.le.ScanSettings;
11 | import android.content.Context;
12 | import android.content.Intent;
13 | import android.content.pm.PackageManager;
14 | import android.os.Bundle;
15 | import android.os.Handler;
16 | import android.os.ParcelUuid;
17 | import android.util.Log;
18 | import android.view.View;
19 | import android.widget.Button;
20 | import android.widget.ListView;
21 | import android.widget.Toast;
22 |
23 | import java.util.ArrayList;
24 | import java.util.HashMap;
25 | import java.util.List;
26 |
27 |
28 | public class DeviceScanActivity extends BaseActivity {
29 | private static final int REQUEST_ENABLE_BT = 1;
30 |
31 | private Handler handler = new Handler();
32 |
33 | private boolean scanning = false;
34 | private Button scanButton;
35 |
36 | public List bluetoothDevices;
37 | public HashMap deviceRSSIs;
38 | private DeviceScanResultsAdapter adapter;
39 | private BluetoothAdapter bluetoothAdapter;
40 |
41 | @Override
42 | protected void onCreate(Bundle savedInstanceState) {
43 | super.onCreate(savedInstanceState);
44 |
45 | // first make sure they can use BLE
46 | if(!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
47 | Toast.makeText(this, "BLE is not supported on your phone, sorry!", Toast.LENGTH_SHORT).show();
48 | finish();
49 | }
50 |
51 | // initialize the bluetooth adapter
52 | final BluetoothManager bluetoothManager = (BluetoothManager)getSystemService(Context.BLUETOOTH_SERVICE);
53 | bluetoothAdapter = bluetoothManager.getAdapter();
54 |
55 | // see if bluetooth is supported?
56 | if(bluetoothAdapter == null) {
57 | Toast.makeText(this, "Bluetooth is not supported on your phone, sorry!", Toast.LENGTH_SHORT).show();
58 | finish();
59 | return;
60 | }
61 |
62 | // initialize the device list
63 | bluetoothDevices = new ArrayList();
64 | deviceRSSIs = new HashMap();
65 |
66 | // grab the button
67 | scanButton = (Button)findViewById(R.id.scanDevicesButton);
68 | scanButton.setOnClickListener(new View.OnClickListener() {
69 | public void onClick(View v) {
70 | startScan(v);
71 | }
72 | });
73 | }
74 |
75 | @Override protected int getLayoutResource() {
76 | return R.layout.activity_device_scan;
77 | }
78 |
79 | @Override
80 | protected void onResume() {
81 | super.onResume();
82 |
83 | // make sure bluetooth is still enabled
84 | if(!bluetoothAdapter.isEnabled()) {
85 | Intent enableBTIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
86 | startActivityForResult(enableBTIntent, REQUEST_ENABLE_BT);
87 | }
88 |
89 | // get the listview
90 | final ListView lv = (ListView)findViewById(R.id.scanResultsListView);
91 | // create an adapter for it
92 | adapter = new DeviceScanResultsAdapter(this);
93 | lv.setAdapter(adapter);
94 |
95 | // start scanning
96 | //scanBTLEDevices(true);
97 | }
98 |
99 | @Override
100 | protected void onPause() {
101 | super.onPause();
102 | scanBTLEDevices(false);
103 | }
104 |
105 | // called when the user clicks the scan button
106 | public void startScan(View view) {
107 | if(scanning) {
108 | scanBTLEDevices(false);
109 | }
110 | else {
111 | scanBTLEDevices(true);
112 | }
113 | }
114 |
115 | public boolean isScanning() {
116 | return scanning;
117 | }
118 |
119 | private void setScanning(final boolean enable) {
120 | scanning = enable;
121 | if(scanning) {
122 | runOnUiThread(new Runnable() {
123 | @Override
124 | public void run() {
125 | scanButton.setText(getResources().getString(R.string.stop_scan_for_devices));
126 | }
127 | });
128 | }
129 | else {
130 | runOnUiThread(new Runnable() {
131 | @Override
132 | public void run() {
133 | scanButton.setText(getResources().getString(R.string.start_scan_for_devices));
134 | }
135 | });
136 | }
137 | }
138 |
139 | @Override
140 | protected void onActivityResult(int requestCode, int resultCode, Intent data) {
141 | if(requestCode == REQUEST_ENABLE_BT && resultCode == Activity.RESULT_CANCELED) {
142 | finish();
143 | return;
144 | }
145 | super.onActivityResult(requestCode, resultCode, data);
146 | }
147 |
148 | public void scanBTLEDevices(final boolean enable) {
149 | if(bluetoothAdapter == null || bluetoothAdapter.getBluetoothLeScanner() == null) {
150 | Log.d("BTLE", "Bluetooth adapter or scanner were null!");
151 | return;
152 | }
153 |
154 | if(enable) {
155 | // only scan for 5 seconds
156 | handler.postDelayed(new Runnable() {
157 | @Override
158 | public void run() {
159 | scanBTLEDevices(false);
160 | }
161 | }, 5000);
162 |
163 | //scanning = true;
164 | setScanning(true);
165 |
166 | bluetoothDevices.clear();
167 | deviceRSSIs.clear();
168 | adapter.notifyDataSetChanged();
169 |
170 | // filter explicitly for the UART
171 | List filters = new ArrayList();
172 | filters.add(new ScanFilter.Builder().setServiceUuid(ParcelUuid.fromString("6E400001-B5A3-F393-E0A9-E50E24DCCA9E")).build());
173 |
174 | // setup the scan settings
175 | ScanSettings settings = new ScanSettings.Builder().setReportDelay(0).setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY).build();
176 |
177 | bluetoothAdapter.getBluetoothLeScanner().startScan(filters, settings, scanCallback);
178 | }
179 | else {
180 | //scanning = false;
181 | setScanning(false);
182 | bluetoothAdapter.getBluetoothLeScanner().stopScan(scanCallback);
183 | }
184 | }
185 |
186 | private ScanCallback scanCallback = new ScanCallback() {
187 | @Override
188 | public void onScanResult(int callbackType, ScanResult result) {
189 | BluetoothDevice device = result.getDevice();
190 | if(!bluetoothDevices.contains(device)) {
191 | bluetoothDevices.add(device);
192 | adapter.notifyDataSetChanged();
193 | deviceRSSIs.put(device, result.getRssi());
194 | }
195 | }
196 |
197 | @Override
198 | public void onScanFailed(final int errorCode) {
199 | runOnUiThread(new Runnable() {
200 | @Override
201 | public void run() {
202 | Toast.makeText(DeviceScanActivity.this, "BTLE scan failed!", Toast.LENGTH_SHORT).show();
203 | Log.d("BTLE", "Scan failed (" + errorCode + ")");
204 | finish();
205 | return;
206 | }
207 | });
208 | }
209 | };
210 | }
211 |
--------------------------------------------------------------------------------
/app/src/main/java/com/blazingmammothgames/tools/btledatalogger/UARTService.java:
--------------------------------------------------------------------------------
1 | package com.blazingmammothgames.tools.btledatalogger;
2 |
3 | import android.app.Service;
4 | import android.bluetooth.BluetoothAdapter;
5 | import android.bluetooth.BluetoothDevice;
6 | import android.bluetooth.BluetoothGatt;
7 | import android.bluetooth.BluetoothGattCallback;
8 | import android.bluetooth.BluetoothGattCharacteristic;
9 | import android.bluetooth.BluetoothGattDescriptor;
10 | import android.bluetooth.BluetoothGattService;
11 | import android.bluetooth.BluetoothManager;
12 | import android.bluetooth.BluetoothProfile;
13 | import android.content.Context;
14 | import android.content.Intent;
15 | import android.os.Binder;
16 | import android.os.IBinder;
17 | import android.support.v4.content.LocalBroadcastManager;
18 | import android.util.Log;
19 |
20 | import java.util.UUID;
21 |
22 | public class UARTService extends Service {
23 | // tag for logging
24 | private final static String TAG = UARTService.class.getSimpleName();
25 |
26 | // binder given to clients
27 | private final IBinder binder = new LocalBinder();
28 |
29 | // the state the connection is in
30 | public enum ConnectionState {
31 | CONNECTING, CONNECTED, DISCONNECTED
32 | }
33 | private ConnectionState connectionState = ConnectionState.DISCONNECTED;
34 |
35 | // BTLE actions / events
36 | public final static String ACTION_GATT_CONNECTED = "com.blazingmammothgames.tools.btledatalogger.ACTION_GATT_CONNECTED";
37 | public final static String ACTION_GATT_DISCONNECTED = "com.blazingmammothgames.tools.btledatalogger.ACTION_GATT_DISCONNECTED";
38 | public final static String ACTION_GATT_SERVICES_DISCOVERED = "com.blazingmammothgames.tools.btledatalogger.ACTION_GATT_SERVICES_DISCOVERED";
39 | public final static String ACTION_DATA_AVAILABLE = "com.blazingmammothgames.tools.btledatalogger.ACTION_DATA_AVAILABLE";
40 |
41 | public final static String EXTRA_DATA_RX = "com.blazingmammothgames.tools.btledatalogger.EXTRA_DATA_RX";
42 |
43 | // UUIDs for the BTLE services
44 | public static final UUID TX_POWER_UUID = UUID.fromString("00001804-0000-1000-8000-00805f9b34fb");
45 | public static final UUID TX_POWER_LEVEL_UUID = UUID.fromString("00002a07-0000-1000-8000-00805f9b34fb");
46 | public static final UUID CCCD = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb");
47 | public static final UUID FIRMWARE_REVISON_UUID = UUID.fromString("00002a26-0000-1000-8000-00805f9b34fb");
48 | public static final UUID DIS_UUID = UUID.fromString("0000180a-0000-1000-8000-00805f9b34fb");
49 | public static final UUID RX_SERVICE_UUID = UUID.fromString("6e400001-b5a3-f393-e0a9-e50e24dcca9e");
50 | public static final UUID RX_CHAR_UUID = UUID.fromString("6e400002-b5a3-f393-e0a9-e50e24dcca9e");
51 | public static final UUID TX_CHAR_UUID = UUID.fromString("6e400003-b5a3-f393-e0a9-e50e24dcca9e");
52 |
53 | private BluetoothManager btManager;
54 | private BluetoothAdapter btAdapter;
55 | private String btAddress;
56 | private BluetoothGatt btGatt;
57 |
58 | public UARTService() {
59 | }
60 |
61 | @Override
62 | public IBinder onBind(Intent intent) {
63 | return binder;
64 | }
65 |
66 | @Override
67 | public boolean onUnbind(Intent intent) {
68 | // make sure the BTLE connection gets closed when we unbind
69 | close();
70 | return super.onUnbind(intent);
71 | }
72 |
73 | public boolean initialize() {
74 | if(btManager == null) {
75 | btManager = (BluetoothManager)getSystemService(Context.BLUETOOTH_SERVICE);
76 | if(btManager == null) {
77 | Log.e(TAG, "Unable to initialize BluetoothManager!");
78 | return false;
79 | }
80 | }
81 |
82 | btAdapter = btManager.getAdapter();
83 | if(btAdapter == null) {
84 | Log.e(TAG, "Unable to obtain a BluetoothAdapter!");
85 | return false;
86 | }
87 |
88 | return true;
89 | }
90 |
91 | public boolean connect(final String address) {
92 | if(btAdapter == null || address == null) {
93 | Log.w(TAG, "Bluetooth adapter was not initialized or unspecified address");
94 | return false;
95 | }
96 |
97 | if(address.equals(btAddress) && btGatt != null) {
98 | // attempt to re-use the gatt
99 | Log.d(TAG, "Attempting to re-use an existing GATT");
100 | if(btGatt.connect()) {
101 | connectionState = ConnectionState.CONNECTING;
102 | return true;
103 | }
104 | else {
105 | return false;
106 | }
107 | }
108 |
109 | final BluetoothDevice device = btAdapter.getRemoteDevice(address);
110 | if(device == null) {
111 | Log.w(TAG, "Device wasn't found, unable to connect!");
112 | return false;
113 | }
114 |
115 | btGatt = device.connectGatt(this, false, btGattCallback);
116 | Log.d(TAG, "Connecting to device...");
117 | btAddress = address;
118 | connectionState = ConnectionState.CONNECTING;
119 | return true;
120 | }
121 |
122 | public void disconnect() {
123 | if(btAdapter == null || btGatt == null) {
124 | Log.w(TAG, "Can't disconnect, adapter & gatt were't initialized!");
125 | return;
126 | }
127 | btGatt.disconnect();
128 | }
129 |
130 | private void close() {
131 | if(btGatt == null) {
132 | return;
133 | }
134 | Log.w(TAG, "btGatt closed");
135 | btAddress = null;
136 | btGatt.close();
137 | btGatt = null;
138 | }
139 |
140 | public class LocalBinder extends Binder {
141 | UARTService getService() {
142 | return UARTService.this;
143 | }
144 | }
145 |
146 | private void broadcastUpdate(final String action) {
147 | final Intent intent = new Intent(action);
148 | LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
149 | }
150 |
151 | private void broadcastUpdate(final String action, BluetoothGattCharacteristic characteristic) {
152 | final Intent intent = new Intent(action);
153 | if(TX_CHAR_UUID.equals(characteristic.getUuid())) {
154 | intent.putExtra(EXTRA_DATA_RX, characteristic.getValue());
155 | }
156 | LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
157 | }
158 |
159 | private final BluetoothGattCallback btGattCallback = new BluetoothGattCallback() {
160 | @Override
161 | public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
162 | if(newState == BluetoothProfile.STATE_CONNECTED) {
163 | connectionState = ConnectionState.CONNECTED;
164 | broadcastUpdate(ACTION_GATT_CONNECTED);
165 |
166 | // start service discovery
167 | btGatt.discoverServices();
168 | }
169 | else if(newState == BluetoothProfile.STATE_DISCONNECTED) {
170 | connectionState = ConnectionState.DISCONNECTED;
171 | broadcastUpdate(ACTION_GATT_DISCONNECTED);
172 | }
173 | }
174 |
175 | @Override
176 | public void onServicesDiscovered(BluetoothGatt gatt, int status) {
177 | if(status == BluetoothGatt.GATT_SUCCESS) {
178 | broadcastUpdate(ACTION_GATT_SERVICES_DISCOVERED);
179 | }
180 | else {
181 | Log.w(TAG, "Services discovered a failure: " + status);
182 | }
183 | }
184 |
185 | @Override
186 | public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
187 | if(status == BluetoothGatt.GATT_SUCCESS) {
188 | broadcastUpdate(ACTION_DATA_AVAILABLE, characteristic);
189 | }
190 | }
191 |
192 | @Override
193 | public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
194 | broadcastUpdate(ACTION_DATA_AVAILABLE, characteristic);
195 | }
196 | };
197 |
198 | public void enableRXNotifications() {
199 | if(btGatt == null) {
200 | Log.e(TAG, "Can't enable RX notifications - btGatt is null!");
201 | }
202 |
203 | BluetoothGattService rxService = btGatt.getService(RX_SERVICE_UUID);
204 | if(rxService == null) {
205 | Log.e(TAG, "Device doesn't have an RX service!");
206 | return;
207 | }
208 |
209 | BluetoothGattCharacteristic txChar = rxService.getCharacteristic(TX_CHAR_UUID);
210 | if(txChar == null) {
211 | Log.e(TAG, "Device doesn't have a TX characteristic!");
212 | return;
213 | }
214 |
215 | btGatt.setCharacteristicNotification(txChar, true);
216 |
217 | BluetoothGattDescriptor descriptor = txChar.getDescriptor(CCCD);
218 | descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
219 | btGatt.writeDescriptor(descriptor);
220 | Log.i(TAG, "RX notifications enabled!");
221 | }
222 | }
223 |
--------------------------------------------------------------------------------
/app/src/main/java/com/blazingmammothgames/tools/btledatalogger/UARTDisplayActivity.java:
--------------------------------------------------------------------------------
1 | package com.blazingmammothgames.tools.btledatalogger;
2 |
3 | import android.content.BroadcastReceiver;
4 | import android.content.ComponentName;
5 | import android.content.Context;
6 | import android.content.Intent;
7 | import android.content.IntentFilter;
8 | import android.content.ServiceConnection;
9 | import android.os.IBinder;
10 | import android.support.v4.content.LocalBroadcastManager;
11 | import android.os.Bundle;
12 | import android.text.method.ScrollingMovementMethod;
13 | import android.util.Log;
14 | import android.view.Menu;
15 | import android.view.MenuItem;
16 | import android.view.View;
17 | import android.view.inputmethod.InputMethodManager;
18 | import android.widget.Button;
19 | import android.widget.EditText;
20 | import android.widget.TextView;
21 | import android.widget.Toast;
22 |
23 |
24 | public class UARTDisplayActivity extends BaseActivity {
25 | // tag for logging
26 | private final static String TAG = UARTService.class.getSimpleName();
27 |
28 | private EditText logFileNameEditText;
29 | private Button startStopLogButton;
30 | private TextView logTextView;
31 | private TextView statusTextView;
32 |
33 | public static final String EXTRAS_DEVICE_NAME = "DEVICE_NAME";
34 | public static final String EXTRAS_DEVICE_ADDRESS = "DEVICE_ADDRESS";
35 |
36 | private boolean uartBound = false;
37 | private UARTService uartService;
38 |
39 | private boolean logBound = false;
40 | private LogService logService;
41 |
42 | private String deviceName;
43 | private String deviceAddress;
44 |
45 | @Override protected int getLayoutResource() {
46 | return R.layout.activity_uartdisplay;
47 | }
48 |
49 | @Override
50 | protected void onCreate(Bundle savedInstanceState) {
51 | super.onCreate(savedInstanceState);
52 | setContentView(R.layout.activity_uartdisplay);
53 |
54 | logFileNameEditText = (EditText)findViewById(R.id.logFileNameEditText);
55 | startStopLogButton = (Button)findViewById(R.id.startStopLogButton);
56 | logTextView = (TextView)findViewById(R.id.logTextView);
57 | logTextView.setMovementMethod(new ScrollingMovementMethod());
58 | statusTextView = (TextView)findViewById(R.id.statusTextView);
59 |
60 | // get the extras
61 | final Intent intent = getIntent();
62 | deviceName = intent.getStringExtra(EXTRAS_DEVICE_NAME);
63 | deviceAddress = intent.getStringExtra(EXTRAS_DEVICE_ADDRESS);
64 |
65 | // inform the user of our intentions
66 | statusTextView.setText("Connecting...");
67 |
68 | // start the broadcaster
69 | LocalBroadcastManager.getInstance(this).registerReceiver(uartStatusChangeReceiver, makeGattUpdateIntentFilter());
70 |
71 | // bind to the UART service
72 | Intent uartServiceIntent = new Intent(this, UARTService.class);
73 | bindService(uartServiceIntent, uartServiceConnection, Context.BIND_AUTO_CREATE);
74 |
75 | // bind to the log service
76 | Intent logServiceIntent = new Intent(this, LogService.class);
77 | bindService(logServiceIntent, logServiceConnection, Context.BIND_AUTO_CREATE);
78 | }
79 |
80 | private static IntentFilter makeGattUpdateIntentFilter() {
81 | final IntentFilter intentFilter = new IntentFilter();
82 | intentFilter.addAction(UARTService.ACTION_GATT_CONNECTED);
83 | intentFilter.addAction(UARTService.ACTION_GATT_DISCONNECTED);
84 | intentFilter.addAction(UARTService.ACTION_GATT_SERVICES_DISCOVERED);
85 | intentFilter.addAction(UARTService.ACTION_DATA_AVAILABLE);
86 | return intentFilter;
87 | }
88 |
89 | @Override
90 | protected void onDestroy() {
91 | super.onDestroy();
92 |
93 | // unbind from the uart service when we're done!
94 | if(uartBound) {
95 | unbindService(uartServiceConnection);
96 | }
97 | if(logBound) {
98 | unbindService(logServiceConnection);
99 | }
100 | try {
101 | LocalBroadcastManager.getInstance(this).unregisterReceiver(uartStatusChangeReceiver);
102 | } catch (Exception ignore) {
103 | Log.e(TAG, ignore.toString());
104 | }
105 | }
106 |
107 | @Override
108 | public boolean onCreateOptionsMenu(Menu menu) {
109 | // Inflate the menu; this adds items to the action bar if it is present.
110 | getMenuInflater().inflate(R.menu.menu_uartdisplay, menu);
111 | return true;
112 | }
113 |
114 | @Override
115 | public boolean onOptionsItemSelected(MenuItem item) {
116 | // Handle action bar item clicks here. The action bar will
117 | // automatically handle clicks on the Home/Up button, so long
118 | // as you specify a parent activity in AndroidManifest.xml.
119 | int id = item.getItemId();
120 |
121 | //noinspection SimplifiableIfStatement
122 | if (id == R.id.action_settings) {
123 | return true;
124 | }
125 |
126 | return super.onOptionsItemSelected(item);
127 | }
128 |
129 | private final ServiceConnection uartServiceConnection = new ServiceConnection() {
130 | @Override
131 | public void onServiceConnected(ComponentName className, IBinder iBinder) {
132 | UARTService.LocalBinder binder = (UARTService.LocalBinder)iBinder;
133 | uartService = binder.getService();
134 | uartBound = true;
135 |
136 | // now that the service is bound, initialize it
137 | if(!uartService.initialize()) {
138 | Log.e(TAG, "Unable to initialize Bluetooth!");
139 | runOnUiThread(new Runnable() {
140 | @Override
141 | public void run() {
142 | Toast.makeText(UARTDisplayActivity.this, "Unable to initialize Bluetooth!", Toast.LENGTH_SHORT).show();
143 | finish();
144 | }
145 | });
146 | }
147 | else {
148 | // and connect to the bluetooth!
149 | if(!uartService.connect(deviceAddress)) {
150 | Log.e(TAG, "Unable to connect to '" + deviceName + "' at '" + deviceAddress + "'!");
151 | runOnUiThread(new Runnable() {
152 | @Override
153 | public void run() {
154 | Toast.makeText(UARTDisplayActivity.this, "Unable to connect to '" + deviceName + "' at '" + deviceAddress + "'!", Toast.LENGTH_SHORT).show();
155 | finish();
156 | }
157 | });
158 | }
159 | }
160 | }
161 |
162 | @Override
163 | public void onServiceDisconnected(ComponentName componentName) {
164 | uartBound = false;
165 | }
166 | };
167 |
168 | private final ServiceConnection logServiceConnection = new ServiceConnection() {
169 | @Override
170 | public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
171 | LogService.LocalBinder binder = (LogService.LocalBinder)iBinder;
172 | logService = binder.getService();
173 | logBound = true;
174 | }
175 |
176 | @Override
177 | public void onServiceDisconnected(ComponentName componentName) {
178 | logBound = false;
179 | }
180 | };
181 |
182 | private void addToLog(final String text) {
183 | runOnUiThread(new Runnable() {
184 | @Override
185 | public void run() {
186 | try {
187 | logTextView.append(text);
188 |
189 | // scroll to the bottom
190 | final int scrollAmount = logTextView.getLayout().getLineTop(logTextView.getLineCount()) - logTextView.getHeight();
191 | // if there is no need to scroll, scrollAmount will be <=0
192 | if (scrollAmount > 0)
193 | logTextView.scrollTo(0, scrollAmount);
194 | else
195 | logTextView.scrollTo(0, 0);
196 | }
197 | catch(Exception e) {
198 | Log.e(TAG, e.toString());
199 | }
200 | }
201 | });
202 | if(logService != null && logService.isLogging()) {
203 | logService.appendToLog(text);
204 | }
205 | }
206 |
207 | private void setStatus(final String text) {
208 | runOnUiThread(new Runnable() {
209 | @Override
210 | public void run() {
211 | try {
212 | statusTextView.setText(text);
213 | }
214 | catch(Exception e) {
215 | Log.e(TAG, e.toString());
216 | }
217 | }
218 | });
219 | }
220 |
221 | private final BroadcastReceiver uartStatusChangeReceiver = new BroadcastReceiver() {
222 | @Override
223 | public void onReceive(Context context, Intent intent) {
224 | String action = intent.getAction();
225 |
226 | // figure out what to do based on the action
227 | switch(action) {
228 | case UARTService.ACTION_GATT_CONNECTED: {
229 | Log.d(TAG, "GATT connected!");
230 | setStatus("Connected!");
231 | }
232 | break;
233 |
234 | case UARTService.ACTION_GATT_DISCONNECTED: {
235 | Log.d(TAG, "GATT disconnected!");
236 | setStatus("Disconnected!");
237 | }
238 | break;
239 |
240 | case UARTService.ACTION_GATT_SERVICES_DISCOVERED: {
241 | Log.d(TAG, "GATT services discovered!");
242 | uartService.enableRXNotifications();
243 | }
244 | break;
245 |
246 | case UARTService.ACTION_DATA_AVAILABLE: {
247 | final byte[] rxData = intent.getByteArrayExtra(UARTService.EXTRA_DATA_RX);
248 | try {
249 | String text = new String(rxData, "UTF-8");
250 | addToLog(text);
251 | }
252 | catch(Exception e) {
253 | Log.e(TAG, e.toString());
254 | }
255 | }
256 | break;
257 | }
258 | }
259 | };
260 |
261 | private void updateLoggingButtonText() {
262 | if(logService.isLogging()) {
263 | startStopLogButton.setText(getResources().getString(R.string.stop_logging));
264 | }
265 | else {
266 | startStopLogButton.setText(getResources().getString(R.string.start_logging));
267 | }
268 | }
269 |
270 | public void startStopLogging(View v) {
271 | if(!logBound) {
272 | Log.e(TAG, "Log service hasn't been bound yet!");
273 | return;
274 | }
275 |
276 | if(logService.isLogging()) {
277 | logService.cleanup();
278 | updateLoggingButtonText();
279 |
280 | // enable the edit text
281 | logFileNameEditText.setEnabled(true);
282 | logFileNameEditText.setFocusable(true);
283 | }
284 | else {
285 | // get the filename
286 | String filename = logFileNameEditText.getText().toString().trim();
287 |
288 | if(filename.isEmpty()) {
289 | Toast.makeText(this, "Enter a filename first!", Toast.LENGTH_SHORT).show();
290 | return;
291 | }
292 |
293 | // make sure it's a csv
294 | if(!filename.endsWith(".csv") && !filename.endsWith(".CSV")) {
295 | filename += ".csv";
296 | }
297 |
298 | // try to initialize the service
299 | if(!logService.initialize(filename)) {
300 | Toast.makeText(this, "Couldn't create the log file!", Toast.LENGTH_SHORT).show();
301 | Log.e(TAG, "Failed to create log file, can't log!");
302 | return;
303 | }
304 |
305 | updateLoggingButtonText();
306 |
307 | // update the text to the actual filename
308 | logFileNameEditText.setText(filename);
309 |
310 | // disable the edit text
311 | logFileNameEditText.setEnabled(false);
312 | logFileNameEditText.setFocusable(false);
313 |
314 | // hide the keyboard if it's open
315 | InputMethodManager inputManager = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
316 | inputManager.hideSoftInputFromWindow((null == getCurrentFocus()) ? null : getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
317 | }
318 | }
319 | }
320 |
--------------------------------------------------------------------------------