1
0
mirror of https://github.com/oliexdev/openScale.git synced 2025-08-21 16:02:04 +02:00

Use varargs construct instead of byte array

This commit is contained in:
Erik Johansson
2018-11-20 22:05:32 +01:00
parent 8740d55361
commit 3f3a891271

View File

@@ -55,12 +55,11 @@ public class BluetoothInlife extends BluetoothCommunication {
return 0; return 0;
} }
private void sendCommand(int command, byte[] parameters) { private void sendCommand(int command, byte... parameters) {
byte[] data = {START_BYTE, (byte)command, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, END_BYTE}; byte[] data = {START_BYTE, (byte)command, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, END_BYTE};
if (parameters != null) { int i = 2;
for (int i = 0; i < parameters.length; ++i) { for (byte parameter : parameters) {
data[i + 2] = parameters[i]; data[i++] = parameter;
}
} }
data[data.length - 2] = xorChecksum(data, 1, data.length - 3); data[data.length - 2] = xorChecksum(data, 1, data.length - 3);
writeBytes(WEIGHT_SERVICE, WEIGHT_CMD_CHARACTERISTIC, data); writeBytes(WEIGHT_SERVICE, WEIGHT_CMD_CHARACTERISTIC, data);
@@ -90,7 +89,7 @@ public class BluetoothInlife extends BluetoothCommunication {
byte age = (byte)scaleUser.getAge(); byte age = (byte)scaleUser.getAge();
byte height = (byte)scaleUser.getBodyHeight(); byte height = (byte)scaleUser.getBodyHeight();
sendCommand(0xd2, new byte[] {level, sex, userId, age, height}); sendCommand(0xd2, level, sex, userId, age, height);
break; break;
default: default:
return false; return false;
@@ -151,7 +150,7 @@ public class BluetoothInlife extends BluetoothCommunication {
} }
break; break;
case (byte) 0xdf: case (byte) 0xdf:
Timber.d("Data received by scale: %s", data[2] == 0 ? "OK" : "error"); Timber.d("User data acked by scale: %s", data[2] == 0 ? "OK" : "error");
break; break;
default: default:
Timber.d("Unknown command 0x%02x", data[1]); Timber.d("Unknown command 0x%02x", data[1]);
@@ -231,7 +230,7 @@ public class BluetoothInlife extends BluetoothCommunication {
addScaleData(measurement); addScaleData(measurement);
sendCommand(0xd4, null); sendCommand(0xd4);
} }
void processMeasurementDataNewVersion(byte[] data) { void processMeasurementDataNewVersion(byte[] data) {