- 001
- 002
- 003
- 004
- 005
- 006
- 007
- 008
- 009
- 010
- 011
- 012
- 013
- 014
- 015
- 016
- 017
- 018
- 019
- 020
- 021
- 022
- 023
- 024
- 025
- 026
- 027
- 028
- 029
- 030
- 031
- 032
- 033
- 034
- 035
- 036
- 037
- 038
- 039
- 040
- 041
- 042
- 043
- 044
- 045
- 046
- 047
- 048
- 049
- 050
- 051
- 052
- 053
- 054
- 055
- 056
- 057
- 058
- 059
- 060
- 061
- 062
- 063
- 064
- 065
- 066
- 067
- 068
- 069
- 070
- 071
- 072
- 073
- 074
- 075
- 076
- 077
- 078
- 079
- 080
- 081
- 082
- 083
- 084
- 085
- 086
- 087
- 088
- 089
- 090
- 091
- 092
- 093
- 094
- 095
- 096
- 097
- 098
- 099
- 100
/**
* 连接指定的手环
*
* @param callback
*/
public void connect(BluetoothDevice device, final ActionCallback callback) {
this.io.connect(context, device, callback);
}
public void setDisconnectedListener(NotifyListener disconnectedListener) {
this.io.setDisconnectedListener(disconnectedListener);
}
/**
* 和手环配对, 实际用途未知, 不配对也可以做其他的操作
*
* @return data = null
*/
public void pair(final ActionCallback callback) {
ActionCallback ioCallback = new ActionCallback() {
@Override
public void onSuccess(Object data) {
BluetoothGattCharacteristic characteristic = (BluetoothGattCharacteristic) data;
Log.d(TAG, "pair result " + Arrays.toString(characteristic.getValue()));
if (characteristic.getValue().length == 1 && characteristic.getValue()[0] == 2) {
callback.onSuccess(null);
} else {
callback.onFail(-1, "respone values no succ!");
}
}
@Override
public void onFail(int errorCode, String msg) {
callback.onFail(errorCode, msg);
}
};
this.io.writeAndRead(Profile.UUID_CHAR_PAIR, Protocol.PAIR, ioCallback);
}
public BluetoothDevice getDevice() {
return this.io.getDevice();
}
/**
* 读取和连接设备的信号强度RSSI值
*
* @param callback
* @return data : int, rssi值
*/
public void readRssi(ActionCallback callback) {
this.io.readRssi(callback);
}
/**
* 读取手环电池信息
*
* @return {@link BatteryInfo}
*/
public void getBatteryInfo(final ActionCallback callback) {
ActionCallback ioCallback = new ActionCallback() {
@Override
public void onSuccess(Object data) {
BluetoothGattCharacteristic characteristic = (BluetoothGattCharacteristic) data;
Log.d(TAG, "getBatteryInfo result " + Arrays.toString(characteristic.getValue()));
if (characteristic.getValue().length == 10) {
BatteryInfo info = BatteryInfo.fromByteData(characteristic.getValue());
callback.onSuccess(info);
} else {
callback.onFail(-1, "result format wrong!");
}
}
@Override
public void onFail(int errorCode, String msg) {
callback.onFail(errorCode, msg);
}
};
this.io.readCharacteristic(Profile.UUID_CHAR_BATTERY, ioCallback);
}
/**
* 让手环震动
*/
public void startVibration(VibrationMode mode) {
byte[] protocal;
switch (mode) {
case VIBRATION_WITH_LED:
protocal = Protocol.VIBRATION_WITH_LED;
break;
case VIBRATION_10_TIMES_WITH_LED:
protocal = Protocol.VIBRATION_10_TIMES_WITH_LED;
break;
case VIBRATION_WITHOUT_LED:
protocal = Protocol.VIBRATION_WITHOUT_LED;
break;
default:
return;
}