Skip to content

Commit 92d1e2f

Browse files
Release 1.0.0
Change-Id: Ie57fcac993a8ca166c94b0c84dfff74f751de5e5
2 parents 8ddb8e1 + 0426443 commit 92d1e2f

File tree

17 files changed

+345
-185
lines changed

17 files changed

+345
-185
lines changed

README.md

Lines changed: 62 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public class DeviceStateFragment extends Fragment
110110
* @param device that was connected.
111111
*/
112112
@Override
113-
public void onDeviceConnected(@NonNull final AbstractBleDevice device){
113+
public void onDeviceConnected(@NonNull final BleDevice device){
114114
//Do something.
115115
}
116116

@@ -120,7 +120,7 @@ public class DeviceStateFragment extends Fragment
120120
* @param device that was disconnected.
121121
*/
122122
@Override
123-
public void onDeviceDisconnected(@NonNull final AbstractBleDevice device){
123+
public void onDeviceDisconnected(@NonNull final BleDevice device){
124124
//Do something.
125125
}
126126

@@ -130,50 +130,54 @@ public class DeviceStateFragment extends Fragment
130130
* @param device that was discovered.
131131
*/
132132
@Override
133-
public void onDeviceDiscovered(@NonNull final AbstractBleDevice device){
133+
public void onDeviceDiscovered(@NonNull final BleDevice device){
134134
//Do something.
135135
}
136136

137137
/**
138138
* This method is called when all the device services are discovered.
139139
*/
140140
@Override
141-
public void onDeviceAllServicesDiscovered(@NonNull final AbstractBleDevice device){
141+
public void onDeviceAllServicesDiscovered(@NonNull final BleDevice device){
142142
//Do something.
143143
}
144144
}
145145
```
146146

147147
### STEP 3: Connect to a BLE device (*AbstractBleDevice*)
148148

149-
##### STEP 3.1: Scan for *AbstractBleDevices*
149+
##### STEP 3.1: Scan for *BleDevices*
150150

151151
###### OPTION 1: Scan for all devices
152152
```java
153153
BleManager.getInstance().startScanning()
154154
```
155155

156156
###### OPTION 2: Scan for devices with specific UUIDs
157+
157158
```java
158-
private void scanForBleDevicesUsingUUIDs (@NonNull final UUID [] validDeviceUUIDs) {
159-
BleManager.getInstance().startScanning(validDeviceUUIDs)
160-
}
159+
// Scans for a default period of time. (10 seconds)
160+
BleManager.getInstance().startScanning(deviceUUIDs)
161+
```
162+
or
163+
```java
164+
BleManager.getInstance().startScanning(scanDurationMilliseconds, deviceUUIDs)
161165
```
162166

163167
##### STEP 3.2: Retrieve discovered devices
164168

165169
###### OPTION 1: Retrieve all discovered devices
166170
```java
167171
@NonNull
168-
public Iterable <? extends AbstractBleDevice> getDiscoveredBleDevices() {
172+
public Iterable <? extends BleDevice> getDiscoveredBleDevices() {
169173
return BleManager.getInstance().getDiscoveredBleDevices();
170174
}
171175
```
172176

173177
###### OPTION 2: Retrieve discovered devices with specific advertise names
174178
```java
175179
@NonNull
176-
public Iterable<? extends AbstractBleDevice> getDiscoveredBleDevices(){
180+
public Iterable<? extends BleDevice> getDiscoveredBleDevices(){
177181
final List acceptedAdvertiseNames = new LinkedList();
178182
acceptedAdvertiseNames.add("SHTC1 SmartGadget");
179183
acceptedAdvertiseNames.add("Smart Humigadget");
@@ -185,7 +189,7 @@ public Iterable<? extends AbstractBleDevice> getDiscoveredBleDevices(){
185189

186190
###### OPTION 1: Connect using the *AbstractBleDevice* object
187191
```java
188-
public static void connectDevice (@NonNull AbstractBleDevice device){
192+
public static void connectDevice (@NonNull BleDevice device){
189193
device.connect();
190194
}
191195
```
@@ -206,6 +210,7 @@ registerDeviceListener(deviceAddress, NotificationListener) methods.
206210
```java
207211
import com.sensirion.libble.BleManager;
208212
import com.sensirion.libble.listeners.services.HumidityListener;
213+
import com.sensirion.libble.utils.HumidityUnit;
209214

210215
/**
211216
* Example fragment that listens for humidity notifications.
@@ -229,30 +234,32 @@ public class HumidityListenerFragment extends Fragment implements HumidityListen
229234
/**
230235
* Advices the listeners that a new humidity value was obtained.
231236
*
232-
* @param device {@link AbstractBleDevice} that send the humidity data.
237+
* @param device {@link BleDevice} that send the humidity data.
233238
* @param humidity {@link float} with the humidity value.
234239
* @param sensorName {@link String} with the sensor name.
240+
* @param unit {@link HumidityUnit} with the humidity unit.
235241
*/
236242
public void onNewHumidity(@NonNull final AbstractBleDevice device,
237243
final float humidity,
238244
@NonNull final String sensorName,
239-
@NonNull final String unit){
245+
@NonNull final HumidityUnit unit){
240246
//Do something
241247
}
242248

243249
/**
244250
* Sends to the user the latest historical humidity.
245251
*
246-
* @param device that send the humidity historical value.
247-
* @param relativeHumidity from a moment in the past.
248-
* @param timestamp in milliseconds that determine when the humidity was obtained.
249-
* @param sensorName that send the humidity.
252+
* @param device {@link BleDevice} that send the humidity data.
253+
* @param relativeHumidity {@link float} from a moment in the past.
254+
* @param timestampMillisUTC {@link long} when the humidity was obtained.
255+
* @param sensorName {@link String} with the sensorName.
256+
* @param unit {@link HumidityUnit} with the humidity unit.
250257
*/
251258
public void onNewHistoricalHumidity(@NonNull final AbstractBleDevice device,
252259
final float relativeHumidity,
253260
final long timestamp,
254261
@NonNull final String sensorName,
255-
@NonNull final String unit){
262+
@NonNull final HumidityUnit unit){
256263
//Do something
257264
}
258265
}
@@ -268,17 +275,22 @@ BleManager.getInstance().release(context);
268275
```
269276
## Add new services to the library:
270277

271-
* Create for every new service a new interface in order
272-
to be able to listen for notifications of the new service.
273-
The new interface must extend
274-
com.sensirion.libble.listeners.NotificationListener.
275-
276278
###### Notification interface example:
279+
280+
If we want to receive notifications from a service, we may want
281+
to receive customized notifications. In order to listen for them
282+
we can create a new
283+
com.sensirion.libble.listeners.NotificationListener interface.
284+
285+
For example, if we want to create a service that listens for the
286+
number of steps notifications from an external Bluetooth gadget,
287+
we can implement the following interface:
288+
277289
```java
278290
import com.sensirion.libble.services.NotificationListener;
279291

280292
public interface StepListener extends NotificationListener {
281-
void onNewStep(@NonNull AbstractBleDevice device, int numberSteps);
293+
void onNewStep(@NonNull BleDevice device, int numberSteps);
282294
}
283295
```
284296
After the interface is created, a new service can be built whose
@@ -287,16 +299,6 @@ to extend com.sensirion.libble.services.AbstractBleService. It is possible
287299
to generify the AbstractBleService to manage the listener registration
288300
automatically.
289301

290-
###### Service registration:
291-
292-
```java
293-
/**
294-
* The following command needs to be called before the device connection.
295-
* If a device with this service is connected, the factory will create
296-
* instances of this service class automatically.
297-
*/
298-
BleServiceFactory.registerServiceImplementation(SERVICE_UUID, StepService.class);
299-
```
300302
###### Service example:
301303

302304
```java
@@ -305,17 +307,21 @@ import android.bluetooth.BluetoothGattService;
305307
import com.sensirion.libble.devices.Peripheral;
306308
import static android.bluetooth.BluetoothGattCharacteristic.FORMAT_UINT32;
307309

308-
public class StepService extends AbstractBleService<StepListener> {
310+
/**
311+
* This is an example on how to implement a service that listens for step
312+
* notifications from an external Bluetooth device.
313+
*/
314+
public class StepListener extends AbstractBleService<StepListener> {
309315

310316
//SERVICE UUIDs
311317
public static final String SERVICE_UUID = "0000352f-0000-1000-8000-00805f9b34fb";
312-
private static final String CHARACTERISTIC_UUID = "00002539-0000-1000-8000-00805f9b34fb";
318+
private static final String FOUR_BYTE_CHARACTERISTIC_UUID = "2539";
313319
private final BluetoothGattCharacteristic mStepCharacteristic;
314320

315321
public StepService(@NonNull final Peripheral parent,
316322
@NonNull final BluetoothGattService bluetoothGattService) {
317323
super(parent, bluetoothGattService);
318-
mStepCharacteristic = getCharacteristic(CHARACTERISTIC_UUID);
324+
mStepCharacteristic = getCharacteristic(FOUR_BYTE_CHARACTERISTIC_UUID);
319325
parent.readCharacteristic(mStepCharacteristic);
320326
}
321327

@@ -330,17 +336,17 @@ public class StepService extends AbstractBleService<StepListener> {
330336
/**
331337
* Method called when a characteristic is read.
332338
*
333-
* @param characteristic that was updated.
339+
* @param char updated {@link BluetoothGattCharacteristic}
334340
* @return <code>true</code> if the characteristic was read correctly.
335341
*/
336342
@Override
337-
public boolean onCharacteristicUpdate(@NonNull BluetoothGattCharacteristic characteristic) {
338-
if (mStepCharacteristic.equals(updatedCharacteristic)) {
339-
final int numberSteps = characteristic.getIntValue(FORMAT_UINT32, 0);
343+
public boolean onCharacteristicUpdate(@NonNull BluetoothGattCharacteristic char) {
344+
if (mStepCharacteristic.equals(char)) {
345+
final int numberSteps = char.getIntValue(FORMAT_UINT32, 0);
340346
notifyListeners(numberSteps);
341347
return true;
342348
}
343-
return super.onCharacteristicUpdate(updatedCharacteristic);
349+
return super.onCharacteristicUpdate(char);
344350
}
345351

346352
private void notifyListeners(final int numberSteps) {
@@ -356,7 +362,7 @@ public class StepService extends AbstractBleService<StepListener> {
356362
}
357363

358364
/**
359-
* Checks if a service is ready to use.
365+
* Checks if the service is ready to use.
360366
*
361367
* @return <code>true</code> if the service is synchronized.
362368
*/
@@ -366,12 +372,24 @@ public class StepService extends AbstractBleService<StepListener> {
366372
}
367373

368374
/**
369-
* Tries to synchronize a service in case some of its data is missing.
375+
* This method tries to obtain all the data the service needs and
376+
* it registers for all the missing notitifications.
370377
*/
371378
@Override
372379
public abstract void synchronizeService() {
373380
// If notifications are registered, it won't do anything.
374381
registerDeviceCharacteristicNotifications();
375382
}
376383
}
384+
```
385+
386+
###### Service registration:
387+
388+
```java
389+
/**
390+
* The following command needs to be called before the device connection.
391+
* If a device with this service is connected, the factory will create
392+
* instances of this service class automatically.
393+
*/
394+
BleServiceFactory.registerServiceImplementation(SERVICE_UUID, ExampleService.class);
377395
```

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ buildscript {
44
}
55

66
dependencies {
7-
classpath 'com.android.tools.build:gradle:1.1.0'
7+
classpath 'com.android.tools.build:gradle:1.1.2'
88
}
99
}
1010

contributors.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,20 @@ Authors:
44
- [@xavier-fernandez](https://github.com/xavier-fernandez)
55
- [@AZOM](https://github.com/AZOM)
66

7-
Special Thanks to:
7+
8+
Special thanks to:
89
===
910

11+
- [@erikvido](https://github.com/erikvido)
1012
- [@dhasenfratz](https://github.com/dhasenfratz)
11-
- [@StevenRudenko](https://github.com/StevenRudenko) for his [@BleSensorTag](https://github.com/StevenRudenko/BleSensorTag) contributions
13+
- [@silvanfischer](https://github.com/silvanfischer)
14+
- [@psachs](https://github.com/psachs)
15+
- [@abrauchli](https://github.com/abrauchli)
16+
- [@tpcz](https://github.com/tpcz)
17+
- [@honggoff](https://github.com/honggoff)
18+
- [@StevenRudenko](https://github.com/StevenRudenko) for his [BleSensorTag](https://github.com/StevenRudenko/BleSensorTag) contributions
19+
20+
Third party code:
21+
===
22+
23+
- [@RadiusNetworks](https://github.com/RadiusNetworks) for its [bluetooth_crash_resolver](https://github.com/RadiusNetworks/bluetooth-crash-resolver) project. The crash resolver class is integrated inside the library.

lib/build.gradle

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
apply plugin: 'com.android.library'
22

3+
version = "1.0.0"
4+
def code = 22
5+
36
android {
47
compileSdkVersion 22
58
buildToolsVersion "22.0.1"
69
defaultConfig {
710
minSdkVersion 18
811
targetSdkVersion 22
9-
versionCode 19
10-
versionName "0.11.4"
12+
versionName version
13+
versionCode code
1114
}
1215
buildTypes {
1316
release {
@@ -18,5 +21,24 @@ android {
1821
}
1922

2023
dependencies {
21-
compile 'com.android.support:support-v4:22.0.0'
24+
compile 'com.android.support:support-v4:22.1.1'
25+
}
26+
27+
task sourcesJar(type: Jar) {
28+
from android.sourceSets.main.java.srcDirs
29+
classifier = 'sources'
30+
}
31+
32+
task javadoc(type: Javadoc) {
33+
source = android.sourceSets.main.java.srcDirs
34+
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
35+
}
36+
37+
task javadocJar(type: Jar, dependsOn: javadoc) {
38+
classifier = 'javadoc'
39+
from javadoc.destinationDir
2240
}
41+
artifacts {
42+
archives sourcesJar
43+
archives javadocJar
44+
}

0 commit comments

Comments
 (0)