Affichage de la date de dernière mesure
This commit is contained in:
parent
f1c24ea3e7
commit
5e53e8fd85
3 changed files with 14 additions and 28 deletions
|
@ -33,7 +33,10 @@ import android.os.Binder;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import java.text.DateFormat;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@ -127,35 +130,16 @@ public class BluetoothLeService extends Service {
|
||||||
final BluetoothGattCharacteristic characteristic) {
|
final BluetoothGattCharacteristic characteristic) {
|
||||||
final Intent intent = new Intent(action);
|
final Intent intent = new Intent(action);
|
||||||
Log.d(TAG, "broadcastUpdate(String, BluetoothGattChar.) appelé.");
|
Log.d(TAG, "broadcastUpdate(String, BluetoothGattChar.) appelé.");
|
||||||
/* TODO
|
|
||||||
// This is special handling for the Heart Rate Measurement profile. Data parsing is
|
|
||||||
// carried out as per profile specifications:
|
|
||||||
// http://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.heart_rate_measurement.xml
|
|
||||||
if (UUID_HEART_RATE_MEASUREMENT.equals(characteristic.getUuid())) {
|
|
||||||
int flag = characteristic.getProperties();
|
|
||||||
int format = -1;
|
|
||||||
if ((flag & 0x01) != 0) {
|
|
||||||
format = BluetoothGattCharacteristic.FORMAT_UINT16;
|
|
||||||
Log.d(TAG, "Heart rate format UINT16.");
|
|
||||||
} else {
|
|
||||||
format = BluetoothGattCharacteristic.FORMAT_UINT8;
|
|
||||||
Log.d(TAG, "Heart rate format UINT8.");
|
|
||||||
}
|
|
||||||
final int heartRate = characteristic.getIntValue(format, 1);
|
|
||||||
Log.d(TAG, String.format("Received heart rate: %d", heartRate));
|
|
||||||
intent.putExtra(EXTRA_DATA, String.valueOf(heartRate));
|
|
||||||
} else {
|
|
||||||
*/
|
|
||||||
// For all other profiles, writes the data formatted in HEX.
|
|
||||||
final byte[] data = characteristic.getValue();
|
final byte[] data = characteristic.getValue();
|
||||||
if (data != null && data.length > 0) {
|
if (data != null && data.length > 0) {
|
||||||
if (SampleGattAttributes.SENSOR_CHARACTERISTIC_UUID.equals(characteristic.getUuid())) {
|
if (SampleGattAttributes.SENSOR_CHARACTERISTIC_UUID.equals(characteristic.getUuid())) {
|
||||||
long value =
|
final long value =
|
||||||
(data.length == 2) ? (data[0] << 8) & 0x0000ff00 | (data[1] << 0) & 0x000000ff
|
(data.length == 2) ? (data[0] << 8) & 0x0000ff00 | (data[1] << 0) & 0x000000ff
|
||||||
: (data[0] << 0) & 0x000000ff;
|
: (data[0] << 0) & 0x000000ff;
|
||||||
long max = 65535; // 2^16 - 1
|
final long max = 65535; // 2^16 - 1
|
||||||
double percent = ((double) (100 * value)) / ((double) max);
|
final double percent = ((double) (100 * value)) / ((double) max);
|
||||||
intent.putExtra(EXTRA_DATA, String.format("%.3f %%", percent));
|
final String date = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.LONG).format(new Date());
|
||||||
|
intent.putExtra(EXTRA_DATA, String.format("%.3f %%\n(%s)", percent, date));
|
||||||
} else {
|
} else {
|
||||||
final StringBuilder stringBuilder = new StringBuilder(data.length);
|
final StringBuilder stringBuilder = new StringBuilder(data.length);
|
||||||
//stringBuilder.append(String.format("%d", data));/
|
//stringBuilder.append(String.format("%d", data));/
|
||||||
|
@ -166,9 +150,6 @@ public class BluetoothLeService extends Service {
|
||||||
intent.putExtra(EXTRA_DATA, new String(data) + "\n" + stringBuilder.toString());
|
intent.putExtra(EXTRA_DATA, new String(data) + "\n" + stringBuilder.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* TODO
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
sendBroadcast(intent);
|
sendBroadcast(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ public class SampleGattAttributes {
|
||||||
attributes.put("00002a04-0000-1000-8000-00805f9b34fb", "Peripheral Preferred Connection Parameters");
|
attributes.put("00002a04-0000-1000-8000-00805f9b34fb", "Peripheral Preferred Connection Parameters");
|
||||||
attributes.put("00002a29-0000-1000-8000-00805f9b34fb", "Manufacturer Name");
|
attributes.put("00002a29-0000-1000-8000-00805f9b34fb", "Manufacturer Name");
|
||||||
|
|
||||||
attributes.put(SENSOR_CHARACTERISTIC_UUID_STRING, "5-byte r notif. sensor value");
|
attributes.put(SENSOR_CHARACTERISTIC_UUID_STRING, "Sensor value");
|
||||||
attributes.put("ff020304-0506-0708-0900-0a0b0c0d0e0f", "3-byte rw notif. char.");
|
attributes.put("ff020304-0506-0708-0900-0a0b0c0d0e0f", "3-byte rw notif. char.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
5
TODO.md
5
TODO.md
|
@ -4,10 +4,15 @@
|
||||||
Par ordre décroissant d’urgence :
|
Par ordre décroissant d’urgence :
|
||||||
|
|
||||||
- prise en charge de l’écriture des caractéristiques ;
|
- prise en charge de l’écriture des caractéristiques ;
|
||||||
|
- ...
|
||||||
|
- bouton « presse-papier »
|
||||||
|
- bouton « partager » avec date, description etc.
|
||||||
|
- historique ou graphe des mesures.
|
||||||
|
|
||||||
Fait
|
Fait
|
||||||
-----
|
-----
|
||||||
|
|
||||||
|
- affichage de la date de la dernière mesure ;
|
||||||
- prise en charge des notifications des caractéristiques ;
|
- prise en charge des notifications des caractéristiques ;
|
||||||
- filtrage des services et caractéristiques dans l’activité « DeviceControl » ;
|
- filtrage des services et caractéristiques dans l’activité « DeviceControl » ;
|
||||||
- filtrage des appareils avec notre service dans l’activité « DeviceScan ».
|
- filtrage des appareils avec notre service dans l’activité « DeviceScan ».
|
Loading…
Reference in a new issue