Affichage de la date de dernière mesure

This commit is contained in:
Louis-Guillaume DUBOIS 2017-06-02 18:58:02 +02:00
parent f1c24ea3e7
commit 5e53e8fd85
No known key found for this signature in database
GPG key ID: 96472D986598B31E
3 changed files with 14 additions and 28 deletions

View file

@ -33,7 +33,10 @@ import android.os.Binder;
import android.os.IBinder;
import android.util.Log;
import java.text.DateFormat;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.StringTokenizer;
import java.util.UUID;
@ -127,35 +130,16 @@ public class BluetoothLeService extends Service {
final BluetoothGattCharacteristic characteristic) {
final Intent intent = new Intent(action);
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();
if (data != null && data.length > 0) {
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[0] << 0) & 0x000000ff;
long max = 65535; // 2^16 - 1
double percent = ((double) (100 * value)) / ((double) max);
intent.putExtra(EXTRA_DATA, String.format("%.3f %%", percent));
final long max = 65535; // 2^16 - 1
final double percent = ((double) (100 * value)) / ((double) max);
final String date = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.LONG).format(new Date());
intent.putExtra(EXTRA_DATA, String.format("%.3f %%\n(%s)", percent, date));
} else {
final StringBuilder stringBuilder = new StringBuilder(data.length);
//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());
}
}
/* TODO
}
*/
sendBroadcast(intent);
}

View file

@ -54,7 +54,7 @@ public class SampleGattAttributes {
attributes.put("00002a04-0000-1000-8000-00805f9b34fb", "Peripheral Preferred Connection Parameters");
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.");
}

View file

@ -4,10 +4,15 @@
Par ordre décroissant durgence :
- prise en charge de lécriture des caractéristiques ;
- ...
- bouton « presse-papier »
- bouton « partager » avec date, description etc.
- historique ou graphe des mesures.
Fait
-----
- affichage de la date de la dernière mesure ;
- prise en charge des notifications des caractéristiques ;
- filtrage des services et caractéristiques dans lactivité « DeviceControl » ;
- filtrage des appareils avec notre service dans lactivité « DeviceScan ».