Skip to content

Commit

Permalink
Merge pull request #72 from NordicSemiconductor/new-version
Browse files Browse the repository at this point in the history
New version
  • Loading branch information
philips77 authored Dec 5, 2022
2 parents 279dd79 + d1de817 commit 7d4104e
Show file tree
Hide file tree
Showing 130 changed files with 1,266 additions and 5,453 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/deploy-to-play-store.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ jobs:
fetch-depth: 0
- shell: bash
env:
# The following env variables are used by signing configuration in sample/build.gradle
# The following env variables are used by signing configuration
KEYSTORE_ALIAS: ${{ secrets.KEYSTORE_ALIAS }}
KEYSTORE_KEY_PSWD: ${{ secrets.KEYSTORE_KEY_PSWD }}
KEYSTORE_PSWD: ${{ secrets.KEYSTORE_PSWD }}
# The script decodes keystore (required by sample/build.gradle) and fastlane-api.json
# The script decodes keystore (required by the app signing conf) and fastlane-api.json
# needed by fastlane (see fastlane/Appfile).
run: |
echo "${{ secrets.KEYSTORE_FILE }}" > keystore.asc
Expand Down
80 changes: 62 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,78 @@
# nRF BLINKY
# nRF Blinky for Android

nRF Blinky is an application developed targeting an audience of developers who are new to
nRF Blinky is an application 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 3
on the nRF DK and to receive the Button 1 press event from a nRF DK on the nRF Blinky Application.
The app can be easily converted to work with other devices and may act as a template app.

This very simple application contains two basic features:
* turning on a LED on a connected Bluetooth LE device,
* receiving a Button press and release events from the device.

![Scanner](images/scanner.png) ![Blinky](images/blinky.png)

It demonstrates how to the **BleManager** class from
It demonstrates how the `BleManager` class from
[Android BLE Library](https://github.com/NordicSemiconductor/Android-BLE-Library/)
library can be used from View Model
library can be used from a View Model
(see [Architecture Components](https://developer.android.com/topic/libraries/architecture/index.html)).

## Nordic LED and Button Service
## Structure

The new version of nRF Blinky application has been created in Jetpack Compose.

### Dependencies

It is using the following libraries:
* [Android BLE Library](https://github.com/NordicSemiconductor/Android-BLE-Library/) - handles Bluetooth LE connectivity
* [Nordic Common Library for Android](https://github.com/NordicPlayground/Android-Common-Libraries) - theme and common UI components, e.g. scanner screen
* [nRF Logger tree for Timber](https://github.com/NordicSemiconductor/nRF-Logger-API) - logs to nRF Logger app using [Timber](https://github.com/JakeWharton/timber)
* [Android Gradle Plugins](https://github.com/NordicSemiconductor/Android-Gradle-Plugins) - set of Gradle plugins

The gradle script was written in Kotlin Script (*gradle.kts*) and is using version catalog for
dependency management.

### Modules

The application consists of the following modules:

* **:app** - the main module, contains the application code
* **:scanner** - contains the scanner screen destination
* **:blinky:spec** - contains the Blinky device specification, e.g. [`Blinky`](https://github.com/NordicSemiconductor/Android-nRF-Blinky/blob/b23b0252fe14bd0961c1edafa973f7da2768feb9/blinky/spec/src/main/java/no/nordicsemi/android/blinky/spec/Blinky.kt) API or the Service UUID
* **:blinky:ble** - contains the BLE related code, e.g. [`BlinkyManager`](https://github.com/NordicSemiconductor/Android-nRF-Blinky/blob/b23b0252fe14bd0961c1edafa973f7da2768feb9/blinky/ble/src/main/java/no/nordicsemi/android/blinky/ble/BlinkyManager.kt) implementation
* **:blinky:ui** - contains the UI related code, e.g. [`BlinkyScreen`](https://github.com/NordicSemiconductor/Android-nRF-Blinky/blob/b23b0252fe14bd0961c1edafa973f7da2768feb9/blinky/ui/src/main/java/no/nordicsemi/android/blinky/control/view/BlinkyScreen.kt)
or [`BlinkyViewModel`](https://github.com/NordicSemiconductor/Android-nRF-Blinky/blob/b23b0252fe14bd0961c1edafa973f7da2768feb9/blinky/ui/src/main/java/no/nordicsemi/android/blinky/control/viewmodel/BlinkyViewModel.kt) implementation

The **:blinky:ui** and **:blinky:spec** modules are transport agnostic. The Bluetooth LE transport
is set using Hilt `@Binds` dependency injection [here](https://github.com/NordicSemiconductor/Android-nRF-Blinky/blob/b23b0252fe14bd0961c1edafa973f7da2768feb9/app/src/main/java/no/nordicsemi/android/blinky/di/BlinkyModule.kt#L59).

The app is based on **:navigation** module from the Nordic Common Library, which is using
[`NavHost`](https://developer.android.com/jetpack/compose/navigation) under the hood, and adds
type-safety to the navigation graph.

Each screen defines a `DestinationId` (with input and output types) and `NavigationDestination`,
which declares the composable, inner navigation or a dialog target. See [`BlinkyDestination`](https://github.com/NordicSemiconductor/Android-nRF-Blinky/blob/b23b0252fe14bd0961c1edafa973f7da2768feb9/blinky/ui/src/main/java/no/nordicsemi/android/blinky/control/BlinkyDestination.kt) for an example.

Navigation between destinations is done using [`Navigator`](https://github.com/NordicPlayground/Android-Common-Libraries/blob/d8e60628a877eccf8592da4889cf12afdbc08e44/navigation/src/main/java/no/nordicsemi/android/common/navigation/Navigator.kt) object,
available using Hilt form a `ViewModel`. When a new destination is selected, the input parameters
are available from `SavedStateHandle` (see [`BlinkyModule`](https://github.com/NordicSemiconductor/Android-nRF-Blinky/blob/b23b0252fe14bd0961c1edafa973f7da2768feb9/app/src/main/java/no/nordicsemi/android/blinky/di/BlinkyModule.kt) class).

## Nordic LED and Button Service (LBS)

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

A simplified proprietary service by Nordic Semiconductor, containing two characteristics one to
control LED 3 and Button 1:
A simplified proprietary service by Nordic Semiconductor, containing two characteristics:

- First characteristic controls the LED state (On/Off).
- LED state (On/Off).
- UUID: **`00001525-1212-EFDE-1523-785FEABCD123`**
- Value: **`1`** => LED On
- Value: **`0`** => LED Off
- Properties: **Write** or **Write Without Response**
- Value: **`0x01`** => LED On
- Value: **`0x00`** => LED Off

- Second characteristic notifies central of the button state on change (Pressed/Released).
- Button state (Pressed/Released).
- UUID: **`00001524-1212-EFDE-1523-785FEABCD123`**
- Value: **`1`** => Button Pressed
- Value: **`0`** => Button Released
- Properties: **Notify**
- Value: **`0x01`** => Button Pressed
- Value: **`0x00`** => Button Released

For documentation for nRF5 SDK, check out
[this link](https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/ble_sdk_app_blinky.html?cp=8_1_4_2_2_3)
Expand All @@ -39,12 +83,12 @@ and for one based on nRF Connect SDK

* This application depends on [Android BLE Library](https://github.com/NordicSemiconductor/Android-BLE-Library/).
* Android 4.3 or newer is required.
* Any nRF5 DK is required in order to test the BLE Blinky service. The service can also be emulated
using nRF Connect for Android, iOS or Desktop.
* Any nRF5 DK or another device is required in order to test the BLE Blinky service. The service
can also be emulated using nRF Connect for Android, iOS or Desktop.

## Installation and usage

Flash your device with LED Button sample from nRF5 SDK or nRF Connect SDK.
Program your device with LED Button sample from nRF5 SDK (blinky sample) or nRF Connect SDK (LBS sample).

The device should appear on the scanner screen after granting required permissions.

Expand Down
2 changes: 1 addition & 1 deletion app/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/build
/build
66 changes: 0 additions & 66 deletions app/build.gradle

This file was deleted.

28 changes: 28 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
plugins {
// https://github.com/NordicSemiconductor/Android-Gradle-Plugins/blob/main/plugins/src/main/kotlin/AndroidApplicationComposeConventionPlugin.kt
alias(libs.plugins.nordic.application.compose)
// https://github.com/NordicSemiconductor/Android-Gradle-Plugins/blob/main/plugins/src/main/kotlin/AndroidHiltConventionPlugin.kt
alias(libs.plugins.nordic.hilt)
}

android {
namespace = "no.nordicsemi.android.blinky"
defaultConfig {
applicationId = "no.nordicsemi.android.nrfblinky"
resourceConfigurations.add("en")
}
}

dependencies {
implementation(project(":scanner"))
implementation(project(":blinky:spec"))
implementation(project(":blinky:ui"))
implementation(project(":blinky:ble"))

implementation(libs.nordic.theme)
implementation(libs.nordic.navigation)

implementation(libs.timber)

implementation(libs.androidx.activity.compose)
}
24 changes: 20 additions & 4 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
-keep class com.google.android.gms.**
-dontwarn com.google.android.gms.**
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.kts.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

-keep class no.nordicsemi.android.blinky.** { *; }
-keep class android.arch.lifecycle.** {*;}
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Loading

0 comments on commit 7d4104e

Please sign in to comment.