Écriture de la caractéristique idoine.
This commit is contained in:
parent
51aa931b68
commit
aa6361081c
4 changed files with 36 additions and 1 deletions
|
@ -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.)
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/form_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:ems="10"
|
||||
android:hint="@string/hint_writable_value"
|
||||
android:inputType="text"
|
||||
android:maxLength="20" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/button2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="onSendClick"
|
||||
android:text="@string/label_write" />
|
||||
</LinearLayout>
|
|
@ -35,4 +35,7 @@
|
|||
<string name="menu_scan">Scan</string>
|
||||
<string name="menu_stop">Stop</string>
|
||||
<string name="label_refresh">Update</string>
|
||||
<string name="label_write">Write</string>
|
||||
<string name="hint_writable_value">String to send… (max. 20 bytes)</string>
|
||||
<string name="label_read">Read</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue