Skip to content

Commit

Permalink
Version 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
philips77 committed Dec 18, 2017
1 parent f0aafbc commit 6523e5f
Show file tree
Hide file tree
Showing 84 changed files with 19,115 additions and 4,419 deletions.
2 changes: 2 additions & 0 deletions .idea/gradle.xml

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

12 changes: 1 addition & 11 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.

7,311 changes: 7,311 additions & 0 deletions Firmwares/nRF51_SDK11.0.0/ble_app_blinky_s130_pca10028.hex

Large diffs are not rendered by default.

9,940 changes: 9,940 additions & 0 deletions Firmwares/nRF52_SDK14.2/ble_app_blinky_pca10040_s132.hex

Large diffs are not rendered by default.

47 changes: 40 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,47 @@
# nRF BLINKY
nRF Blinky is an application developed targeting an audience of developers who are new to Bluetooth Smart. This is a simple application with two basic features to turn on LED 1 on the nRF DK and to recieve the Button 1 press event from a nRF DK on the nRF Blinky Application.

## Nordic LED Button Service
A simplified LED Button Service proprietary to Nordic Semiconductor, containing two characteristics to turn on the led 1 and to receive the button 1 press event on the nRF Development Kit.
nRF Blinky is an application developed targeting an audience of developers who are new to Bluetooth Low Energy.
This is a very simple application with two basic features to turn on LED 1 on the nRF DK and to recieve the Button 1 press event from a nRF DK on the nRF Blinky Application.
It is a siple example of how to use the **BleManager** class from [Android nRF Blinky](https://github.com/NordicSemiconductor/Android-BLE-Library/) library.

## Nordic LED and Button Service

### Note:
Service UUID: `00001523-1212-EFDE-1523-785FEABCD123`

*Android 4.3 or newer is required.
A simplified proprietary service by Nordic Semiconductor, containing two characteristics one to control LED 3 and Button 1:

*Tested on Samsung S3 with Android 4.3 and on Nexus 5, 6 and 9 with lollipop and Marshmallow.
- First characteristic controls the LED state (On/Off).
- UUID: **`00001525-1212-EFDE-1523-785FEABCD123`**
- Value: **`1`** => LED On
- Value: **`0`** => LED Off

*Location Services need to be enabled for scanning from android 6.0 Marshmallow and in addition, runtime persmission ACCESS_COARSE_LOCATION is also required.
- Second characteristic notifies central of the button state on change (Pressed/Released).
- UUID: **`00001524-1212-EFDE-1523-785FEABCD123`**
- Value: **`1`** => Button Pressed
- Value: **`0`** => Button Released

### Requirements

* In order to compile the project you have to clone [Android BLE Library](https://github.com/NordicSemiconductor/Android-BLE-Library/) to the same root folder (for example into AndroidstudioProjects).

* Android 4.3 or newer is required.

### Installation and usage:

* Prepare your Development kit.
- Plug in the Development Kit to your computer via USB.
- Power On the Development Kit.
- The Development Kit will now appear as a Mass storage device.
- Drag (or copy/paste) the appropriate HEX file onto that new device.
- The Development Kit lEDS will flash and it will disconnect and reconnect.
- The Development Kit is now ready and flashed with the nRFBlinky example firmware.

* For your conveninence, we have bundled two firmwares in this project under the Firmwares directory.

* To get the latest firmwares and check the source code, you may go directly to our [Developers website](http://developer.nordicsemi.com/nRF5_SDK/) and download the SDK version you need, then you can find the source code and hex files to the blinky demo in the directory `/examples/ble_peripheral/ble_app_blinky/`.

* More information about the nRFBlinky example firmware can be found in the [Infocenter](https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v14.2.0%2Fble_sdk_app_blinky.html).

### Note

* In order to scan for Bluetooth LE device the Location permission must be granted and, on some phones, the Location must be enabled. This app will not use the location information in any way.
46 changes: 23 additions & 23 deletions app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,8 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/build-info" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/builds" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/check-manifest" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes-jar" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-runtime-classes" />
Expand All @@ -108,7 +105,6 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/proguard-rules" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/reload-dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/restart-dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/shaders" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/split-apk" />
Expand All @@ -121,27 +117,31 @@
</content>
<orderEntry type="jdk" jdkName="Android API 27 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="com.android.support:appcompat-v7-27.0.0" level="project" />
<orderEntry type="library" name="com.android.support:animated-vector-drawable-27.0.0" level="project" />
<orderEntry type="library" name="com.android.support:design-27.0.0" level="project" />
<orderEntry type="library" name="com.android.support:support-core-ui-27.0.0" level="project" />
<orderEntry type="library" name="android.arch.lifecycle:common:1.0.0@jar" level="project" />
<orderEntry type="library" name="com.android.support:animated-vector-drawable-27.0.2" level="project" />
<orderEntry type="library" name="com.android.support:appcompat-v7-27.0.2" level="project" />
<orderEntry type="library" name="com.android.support:support-annotations:27.0.2@jar" level="project" />
<orderEntry type="library" name="com.android.support:design-27.0.2" level="project" />
<orderEntry type="library" name="com.android.support:transition-27.0.2" level="project" />
<orderEntry type="library" name="android.arch.lifecycle:extensions-1.0.0" level="project" />
<orderEntry type="library" name="com.android.support:recyclerview-v7-27.0.2" level="project" />
<orderEntry type="library" name="com.android.support.constraint:constraint-layout-solver:1.0.2@jar" level="project" />
<orderEntry type="library" name="com.android.support.constraint:constraint-layout-1.0.2" level="project" />
<orderEntry type="library" name="android.arch.lifecycle:runtime-1.0.3" level="project" />
<orderEntry type="library" name="com.android.support:support-vector-drawable-27.0.2" level="project" />
<orderEntry type="library" name="com.android.support:cardview-v7-27.0.2" level="project" />
<orderEntry type="library" name="android.arch.lifecycle:common:1.0.3@jar" level="project" />
<orderEntry type="library" name="com.jakewharton:butterknife-8.8.1" level="project" />
<orderEntry type="library" name="com.jakewharton:butterknife-annotations:8.8.1@jar" level="project" />
<orderEntry type="library" name="android.arch.core:common:1.0.0@jar" level="project" />
<orderEntry type="library" name="com.android.support:support-core-utils-27.0.0" level="project" />
<orderEntry type="library" name="com.google.android.gms:play-services-maps-8.4.0" level="project" />
<orderEntry type="library" name="com.android.support:transition-27.0.0" level="project" />
<orderEntry type="library" name="com.google.android.gms:play-services-base-8.4.0" level="project" />
<orderEntry type="library" name="android.arch.lifecycle:runtime-1.0.0" level="project" />
<orderEntry type="library" name="com.android.support:support-media-compat-27.0.0" level="project" />
<orderEntry type="library" name="com.android.support:support-compat-27.0.0" level="project" />
<orderEntry type="library" name="com.android.support:support-core-ui-27.0.2" level="project" />
<orderEntry type="library" name="com.android.support:support-compat-27.0.2" level="project" />
<orderEntry type="library" name="com.android.support:support-core-utils-27.0.2" level="project" />
<orderEntry type="library" name="no.nordicsemi.android.support.v18:scanner-1.0.0" level="project" />
<orderEntry type="library" name="com.android.support:recyclerview-v7-27.0.0" level="project" />
<orderEntry type="library" name="com.android.support:support-annotations:27.0.0@jar" level="project" />
<orderEntry type="library" name="com.android.support:support-vector-drawable-27.0.0" level="project" />
<orderEntry type="library" name="com.android.support:support-v4-27.0.0" level="project" />
<orderEntry type="library" name="com.android.support:support-fragment-27.0.2" level="project" />
<orderEntry type="library" name="no.nordicsemi.android:log-2.1.1" level="project" />
<orderEntry type="library" name="com.android.support:support-fragment-27.0.0" level="project" />
<orderEntry type="library" name="com.google.android.gms:play-services-location-8.4.0" level="project" />
<orderEntry type="library" name="com.google.android.gms:play-services-basement-8.4.0" level="project" />
<orderEntry type="library" name="com.android.support:support-media-compat-27.0.2" level="project" />
<orderEntry type="library" name="android.arch.core:runtime-1.0.0" level="project" />
<orderEntry type="library" name="com.android.support:support-v4-27.0.2" level="project" />
<orderEntry type="module" module-name="ble" />
</component>
</module>
27 changes: 18 additions & 9 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ apply plugin: 'com.android.application'

android {
compileSdkVersion 27
buildToolsVersion "26.0.2"
buildToolsVersion "27.0.1"

defaultConfig {
applicationId "no.nordicsemi.android.nrfblinky"
minSdkVersion 18
targetSdkVersion 27
versionCode 2
versionName "1.0"
versionCode 3
versionName "2.0"
}

buildTypes {
debug {
minifyEnabled true
Expand All @@ -23,21 +24,29 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

compileOptions {
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.0.0'
implementation 'com.android.support:design:27.0.0'
// Required to enable Location on Android Marshmallow or newer systems. Location permission and service are required in order to scan for Bluetooth Smart devices.
implementation 'com.google.android.gms:play-services-location:8.4.0'

implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:27.0.2'
implementation 'com.android.support:design:27.0.2'
implementation 'com.android.support:recyclerview-v7:27.0.2'
implementation 'com.android.support:cardview-v7:27.0.2'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
// Butter Knife
implementation 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
// Brings the new BluetoothLeScanner API to older platforms
implementation 'no.nordicsemi.android.support.v18:scanner:1.0.0'
// Log Bluetooth LE events in nRF Logger
implementation 'no.nordicsemi.android:log:2.1.1'
// Lifecycle extensions
implementation 'android.arch.lifecycle:extensions:1.0.0'
// BLE library
implementation project(':ble')
}
20 changes: 12 additions & 8 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,35 @@
-->

<manifest package="no.nordicsemi.android.blinky"
xmlns:android="http://schemas.android.com/apk/res/android">
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="no.nordicsemi.android.LOG" />

<uses-feature
android:name="android.hardware.bluetooth_le"
android:required="true"/>

<application
android:fullBackupContent="true"
android:allowBackup="true"
android:fullBackupContent="true"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:label="@string/app_name"
android:theme="@style/AppTheme">
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity
android:name=".SplashScreenActivity"
android:label="@string/app_name"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:name=".ScannerActivity"
android:icon="@drawable/ic_blinky_feature"
android:label="@string/feature_name"
android:launchMode="singleTop">
Expand All @@ -64,11 +69,10 @@
</intent-filter>
</activity>
<activity
android:name=".ControlBlinkyActivity"
android:name=".BlinkyActivity"
android:launchMode="singleTop">
</activity>

<service android:name=".service.BlinkyService"/>
</application>

</manifest>
105 changes: 105 additions & 0 deletions app/src/main/java/no/nordicsemi/android/blinky/BlinkyActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
* Copyright (c) 2015, Nordic Semiconductor
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package no.nordicsemi.android.blinky;

import android.arch.lifecycle.ViewModelProviders;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.Switch;
import android.widget.TextView;

import no.nordicsemi.android.blinky.adapter.ExtendedBluetoothDevice;
import no.nordicsemi.android.blinky.viewmodels.BlinkyViewModel;

public class BlinkyActivity extends AppCompatActivity {
public static final String EXTRA_DEVICE = "no.nordicsemi.android.blinky.EXTRA_DEVICE";

@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_blinky);

final Intent intent = getIntent();
final ExtendedBluetoothDevice device = intent.getParcelableExtra(EXTRA_DEVICE);
final String deviceName = device.getName();
final String deviceAddress = device.getAddress();

final Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle(deviceName);
getSupportActionBar().setSubtitle(deviceAddress);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

// Configure the view model
final BlinkyViewModel viewModel = ViewModelProviders.of(this).get(BlinkyViewModel.class);
viewModel.connect(device);

// Set up views
final TextView ledState = findViewById(R.id.led_state);
final Switch led = findViewById(R.id.led_switch);
final TextView buttonState = findViewById(R.id.button_state);
final LinearLayout progressContainer = findViewById(R.id.progress_container);
final TextView connectionState = findViewById(R.id.connection_state);
final View content = findViewById(R.id.device_container);

led.setOnClickListener(view -> viewModel.toggleLED(led.isChecked()));
viewModel.isDeviceReady().observe(this, deviceReady -> {
progressContainer.setVisibility(View.GONE);
content.setVisibility(View.VISIBLE);
});
viewModel.getConnectionState().observe(this, connectionState::setText);
viewModel.isConnected().observe(this, connected -> {
if (!connected) {
finish();
}
});
viewModel.getLEDState().observe(this, isOn -> {
ledState.setText(isOn ? R.string.turn_on : R.string.turn_off);
led.setChecked(isOn);
});
viewModel.getButtonState().observe(this, pressed -> buttonState.setText(pressed ? R.string.button_pressed : R.string.button_released));
}

@Override
public boolean onOptionsItemSelected(final MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
onBackPressed();
return true;
}
return false;
}
}
Loading

0 comments on commit 6523e5f

Please sign in to comment.