mirror of
https://github.com/oliexdev/openScale.git
synced 2025-08-14 04:34:18 +02:00
@@ -426,6 +426,14 @@ public abstract class BluetoothCommunication {
|
|||||||
return checksum;
|
return checksum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected byte sumChecksum(byte[] data, int offset, int length) {
|
||||||
|
byte checksum = 0;
|
||||||
|
for (int i = offset; i < offset + length; ++i) {
|
||||||
|
checksum += data[i];
|
||||||
|
}
|
||||||
|
return checksum;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test in a byte if a bit is set (1) or not (0)
|
* Test in a byte if a bit is set (1) or not (0)
|
||||||
*
|
*
|
||||||
|
@@ -95,8 +95,19 @@ public class BluetoothQNScale extends BluetoothCommunication {
|
|||||||
setIndicationOn(CUSTOM2_MEASUREMENT_CHARACTERISTIC);
|
setIndicationOn(CUSTOM2_MEASUREMENT_CHARACTERISTIC);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
// write magicnumber 0x130915011000000042 to 0xffe3
|
final ScaleUser scaleUser = OpenScale.getInstance().getSelectedScaleUser();
|
||||||
byte[] ffe3magicBytes = new byte[]{(byte) 0x13, (byte) 0x09, (byte) 0x15, (byte) 0x01, (byte) 0x10, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x42};
|
final Converters.WeightUnit scaleUserWeightUnit = scaleUser.getScaleUnit();
|
||||||
|
// Value of 0x01 = KG. 0x02 = LB. Requests with stones unit are sent as LB, with post-processing in vendor app.
|
||||||
|
byte weightUnitByte = (byte) 0x01;
|
||||||
|
// Default weight unit KG. If user config set to LB or ST, scale will show LB units, consistent with vendor app
|
||||||
|
if (scaleUserWeightUnit == Converters.WeightUnit.LB || scaleUserWeightUnit == Converters.WeightUnit.ST){
|
||||||
|
weightUnitByte = (byte) 0x02;
|
||||||
|
}
|
||||||
|
// write magicnumber 0x130915[WEIGHT_BYTE]10000000[CHECK_SUM] to 0xffe3
|
||||||
|
// 0x01 weight byte = KG. 0x02 weight byte = LB.
|
||||||
|
byte[] ffe3magicBytes = new byte[]{(byte) 0x13, (byte) 0x09, (byte) 0x15, weightUnitByte, (byte) 0x10, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00};
|
||||||
|
// Set last byte to be checksum
|
||||||
|
ffe3magicBytes[ffe3magicBytes.length -1] = sumChecksum(ffe3magicBytes, 0, ffe3magicBytes.length - 1);
|
||||||
writeBytes(CUSTOM3_MEASUREMENT_CHARACTERISTIC, ffe3magicBytes);
|
writeBytes(CUSTOM3_MEASUREMENT_CHARACTERISTIC, ffe3magicBytes);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
|
Reference in New Issue
Block a user