From aa6361081ced6e4b6a25dab3a4c871fa61f8cc3b Mon Sep 17 00:00:00 2001 From: Louis-Guillaume DUBOIS Date: Tue, 6 Jun 2017 19:02:28 +0200 Subject: [PATCH] =?UTF-8?q?=C3=89criture=20de=20la=20caract=C3=A9ristique?= =?UTF-8?q?=20idoine.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../students/clientble/GattConstants.java | 1 + .../clientble/SimpleDetailActivity.java | 15 +++++++++++++++ .../main/res/layout/simple_detail_layout.xml | 18 +++++++++++++++++- Application/src/main/res/values/strings.xml | 3 +++ 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/Application/src/main/java/fr/centralesupelec/students/clientble/GattConstants.java b/Application/src/main/java/fr/centralesupelec/students/clientble/GattConstants.java index 7427c43..56414e2 100644 --- a/Application/src/main/java/fr/centralesupelec/students/clientble/GattConstants.java +++ b/Application/src/main/java/fr/centralesupelec/students/clientble/GattConstants.java @@ -45,6 +45,7 @@ public class GattConstants { "c093685d-005f-4d3c-8240-6d3020a2c608"; public static final UUID WRITABLE_CHARACTERISTIC_UUID = UUID.fromString(WRITABLE_CHARACTERISTIC_UUID_STRING); + public static final int WRITABLE_CHARACTERISTIC_MAX_LENGTH = 20; // UUID du descripteur qui donne la configuration client d’une caractérisitique // (notification ou non.) diff --git a/Application/src/main/java/fr/centralesupelec/students/clientble/SimpleDetailActivity.java b/Application/src/main/java/fr/centralesupelec/students/clientble/SimpleDetailActivity.java index 72fd31e..2893e41 100644 --- a/Application/src/main/java/fr/centralesupelec/students/clientble/SimpleDetailActivity.java +++ b/Application/src/main/java/fr/centralesupelec/students/clientble/SimpleDetailActivity.java @@ -11,6 +11,7 @@ import android.content.IntentFilter; import android.content.ServiceConnection; import android.os.IBinder; import android.os.Bundle; +import android.provider.SyncStateContract; import android.util.Log; import android.view.MenuItem; import android.view.View; @@ -26,6 +27,7 @@ public class SimpleDetailActivity extends Activity { private TextView mConnectionStateView; private TextView mSensorValueView; private TextView mWritableValueView; + private TextView mFormView; private String mDeviceName; private String mDeviceAddress; @@ -113,6 +115,7 @@ public class SimpleDetailActivity extends Activity { mDeviceAddressView = (TextView) findViewById(R.id.device_address); mDeviceAddressView.setText(mDeviceAddress); + mFormView = (TextView) findViewById(R.id.form_view); mConnectionStateView = (TextView) findViewById(R.id.connection_state); mSensorValueView = (TextView) findViewById(R.id.sensor_value); mWritableValueView = (TextView) findViewById(R.id.writable_value); @@ -209,6 +212,18 @@ public class SimpleDetailActivity extends Activity { requestWritableValue(); } + public void onSendClick(View view) { + Log.d(TAG, "onSendClick()"); + byte [] text = mFormView.getText().toString().getBytes(); + byte [] data = new byte[20]; + int max = Math.min(text.length, GattConstants.WRITABLE_CHARACTERISTIC_MAX_LENGTH); + for (int i = 0; i < max; i++) { + data[i] = text[i]; + } + Log.d(TAG, "envoi de: " + data.toString()); + mBluetoothLeService.writeCharacterisitic(mWritableValueCharac, data); + } + private void requestWritableValue() { BluetoothGattService privateService = mBluetoothLeService.getPrivateService(); if (privateService == null) { diff --git a/Application/src/main/res/layout/simple_detail_layout.xml b/Application/src/main/res/layout/simple_detail_layout.xml index 2d74f6b..e513453 100644 --- a/Application/src/main/res/layout/simple_detail_layout.xml +++ b/Application/src/main/res/layout/simple_detail_layout.xml @@ -78,5 +78,21 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:onClick="onRefreshClick" - android:text="@string/label_refresh" /> + android:text="@string/label_read" /> + + + +