Android Open Source - BleSensorTag Ti Keys Sensor

From Project

Back to project page BleSensorTag.


The source code is released under:

MIT License

If you think the Android project BleSensorTag listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package sample.ble.sensortag.sensor;
/*  w ww.j a  va 2s. c  o  m*/
import static android.bluetooth.BluetoothGattCharacteristic.FORMAT_UINT8;

import android.bluetooth.BluetoothGattCharacteristic;

import sample.ble.sensortag.ble.BleGattExecutor;

 * Created by steven on 9/3/13.
public class TiKeysSensor extends TiSensor<TiKeysSensor.SimpleKeysStatus> {

    private static final String UUID_SERVICE = "0000ffe0-0451-4000-b000-000000000000";
    private static final String UUID_DATA = "0000ffe1-0451-4000-b000-000000000000";
    private static final String UUID_CONFIG = null;

    public enum SimpleKeysStatus {
        // Warning: The order in which these are defined matters.

    TiKeysSensor() {

    public String getName() {
        return "Simple Keys";

    public String getServiceUUID() {
        return UUID_SERVICE;

    public String getDataUUID() {
        return UUID_DATA;

    public String getConfigUUID() {
        return UUID_CONFIG;

    public BleGattExecutor.ServiceAction[] enable(boolean enable) {
        return new BleGattExecutor.ServiceAction[] {

    public String getDataString() {
        final SimpleKeysStatus data = getData();

    public SimpleKeysStatus parse(BluetoothGattCharacteristic c) {
     * The key state is encoded into 1 unsigned byte.
     * bit 0 designates the right key.
     * bit 1 designates the left key.
     * bit 2 designates the side key.
     * Weird, in the userguide left and right are opposite.
        int encodedInteger = c.getIntValue(FORMAT_UINT8, 0);
        return SimpleKeysStatus.values()[encodedInteger % 4];

Java Source Code List